good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
d895f831
Commit
d895f831
authored
Jan 9, 2014
by
Jeffrey Wilcke
Browse files
Options
Downloads
Patches
Plain Diff
Dagger improvements
parent
d2b3071b
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
dagger.go
+40
-12
40 additions, 12 deletions
dagger.go
dagger_test.go
+17
-0
17 additions, 0 deletions
dagger_test.go
ethereum.go
+7
-6
7 additions, 6 deletions
ethereum.go
vm_test.go
+2
-1
2 additions, 1 deletion
vm_test.go
with
66 additions
and
19 deletions
dagger.go
+
40
−
12
View file @
d895f831
...
@@ -14,7 +14,33 @@ type Dagger struct {
...
@@ -14,7 +14,33 @@ type Dagger struct {
xn
*
big
.
Int
xn
*
big
.
Int
}
}
var
Found
bool
func
(
dag
*
Dagger
)
Find
(
obj
*
big
.
Int
,
resChan
chan
int64
)
{
r
:=
rand
.
New
(
rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
for
i
:=
0
;
i
<
1000
;
i
++
{
rnd
:=
r
.
Int63
()
if
dag
.
Eval
(
big
.
NewInt
(
rnd
))
.
Cmp
(
obj
)
<
0
{
// Post back result on the channel
resChan
<-
rnd
// Notify other threads we've found a valid nonce
Found
=
true
}
else
{
fmt
.
Printf
(
"."
)
}
// Break out if found
if
Found
{
break
}
}
resChan
<-
0
}
func
(
dag
*
Dagger
)
Search
(
diff
*
big
.
Int
)
*
big
.
Int
{
func
(
dag
*
Dagger
)
Search
(
diff
*
big
.
Int
)
*
big
.
Int
{
// TODO fix multi threading. Somehow it results in the wrong nonce
amountOfRoutines
:=
1
dag
.
hash
=
big
.
NewInt
(
0
)
dag
.
hash
=
big
.
NewInt
(
0
)
obj
:=
BigPow
(
2
,
256
)
obj
:=
BigPow
(
2
,
256
)
...
@@ -22,23 +48,25 @@ func (dag *Dagger) Search(diff *big.Int) *big.Int {
...
@@ -22,23 +48,25 @@ func (dag *Dagger) Search(diff *big.Int) *big.Int {
fmt
.
Println
(
"diff"
,
diff
,
"< objective"
,
obj
)
fmt
.
Println
(
"diff"
,
diff
,
"< objective"
,
obj
)
r
:=
rand
.
New
(
rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
Found
=
false
r
nd
:=
big
.
NewInt
(
r
.
Int63
()
)
r
esChan
:=
make
(
chan
int64
,
3
)
fmt
.
Println
(
"init rnd ="
,
rnd
)
var
res
int64
for
i
:=
0
;
i
<
1000
;
i
++
{
for
k
:=
0
;
k
<
amountOfRoutines
;
k
++
{
if
dag
.
Eval
(
rnd
)
.
Cmp
(
obj
)
<
0
{
go
dag
.
Find
(
obj
,
resChan
)
fmt
.
Println
(
"Found result! nonce = "
,
rnd
)
return
rnd
}
else
{
fmt
.
Println
(
"Not found :( nonce = "
,
rnd
)
}
}
rnd
=
rnd
.
Add
(
rnd
,
big
.
NewInt
(
1
))
// Wait for each go routine to finish
for
k
:=
0
;
k
<
amountOfRoutines
;
k
++
{
// Get the result from the channel. 0 = quit
if
r
:=
<-
resChan
;
r
!=
0
{
res
=
r
}
}
}
fmt
.
Println
(
"
\n
"
)
return
big
.
NewInt
(
0
)
return
big
.
NewInt
(
res
)
}
}
func
DaggerVerify
(
hash
,
diff
,
nonce
*
big
.
Int
)
bool
{
func
DaggerVerify
(
hash
,
diff
,
nonce
*
big
.
Int
)
bool
{
...
...
This diff is collapsed.
Click to expand it.
dagger_test.go
0 → 100644
+
17
−
0
View file @
d895f831
package
main
import
(
"testing"
"math/big"
)
func
BenchmarkDaggerSearch
(
b
*
testing
.
B
)
{
hash
:=
big
.
NewInt
(
0
)
diff
:=
BigPow
(
2
,
36
)
o
:=
big
.
NewInt
(
0
)
// nonce doesn't matter. We're only testing against speed, not validity
// Reset timer so the big generation isn't included in the benchmark
b
.
ResetTimer
()
// Validate
DaggerVerify
(
hash
,
diff
,
o
)
}
This diff is collapsed.
Click to expand it.
ethereum.go
+
7
−
6
View file @
d895f831
...
@@ -11,10 +11,10 @@ import (
...
@@ -11,10 +11,10 @@ import (
const
Debug
=
true
const
Debug
=
true
var
Start
DBQueryInterfac
e
bool
var
Start
Consol
e
bool
var
StartMining
bool
var
StartMining
bool
func
Init
()
{
func
Init
()
{
flag
.
BoolVar
(
&
Start
DBQueryInterfac
e
,
"c"
,
false
,
"
console interfac
e"
)
flag
.
BoolVar
(
&
Start
Consol
e
,
"c"
,
false
,
"
debug and testing consol
e"
)
flag
.
BoolVar
(
&
StartMining
,
"mine"
,
false
,
"start dagger mining"
)
flag
.
BoolVar
(
&
StartMining
,
"mine"
,
false
,
"start dagger mining"
)
flag
.
Parse
()
flag
.
Parse
()
...
@@ -42,12 +42,13 @@ func main() {
...
@@ -42,12 +42,13 @@ func main() {
Init
()
Init
()
if
Start
DBQueryInterfac
e
{
if
Start
Consol
e
{
dbInterface
:=
NewDBInterfac
e
()
console
:=
NewConsol
e
()
dbInterfac
e
.
Start
()
consol
e
.
Start
()
}
else
if
StartMining
{
}
else
if
StartMining
{
dagger
:=
&
Dagger
{}
dagger
:=
&
Dagger
{}
dagger
.
Search
(
BigPow
(
2
,
36
))
res
:=
dagger
.
Search
(
BigPow
(
2
,
36
))
fmt
.
Println
(
"nonce ="
,
res
)
}
else
{
}
else
{
fmt
.
Println
(
"[DBUG]: Starting Ethereum"
)
fmt
.
Println
(
"[DBUG]: Starting Ethereum"
)
server
,
err
:=
NewServer
()
server
,
err
:=
NewServer
()
...
...
This diff is collapsed.
Click to expand it.
vm_test.go
+
2
−
1
View file @
d895f831
package
main
package
main
/*
import (
import (
_"fmt"
_"fmt"
"testing"
"testing"
...
@@ -72,4 +73,4 @@ func TestVm(t *testing.T) {
...
@@ -72,4 +73,4 @@ func TestVm(t *testing.T) {
bm := NewBlockManager()
bm := NewBlockManager()
bm.ProcessBlock( block )
bm.ProcessBlock( block )
}
}
*/
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment