Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
d895f831
Commit
d895f831
authored
Jan 09, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Dagger improvements
parent
d2b3071b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
66 additions
and
19 deletions
+66
-19
dagger.go
dagger.go
+40
-12
dagger_test.go
dagger_test.go
+17
-0
ethereum.go
ethereum.go
+7
-6
vm_test.go
vm_test.go
+2
-1
No files found.
dagger.go
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
// Wait for each go routine to finish
}
else
{
for
k
:=
0
;
k
<
amountOfRoutines
;
k
++
{
fmt
.
Println
(
"Not found :( nonce = "
,
rnd
)
// Get the result from the channel. 0 = quit
if
r
:=
<-
resChan
;
r
!=
0
{
res
=
r
}
}
rnd
=
rnd
.
Add
(
rnd
,
big
.
NewInt
(
1
))
}
}
return
big
.
NewInt
(
0
)
fmt
.
Println
(
"
\n
"
)
return
big
.
NewInt
(
res
)
}
}
func
DaggerVerify
(
hash
,
diff
,
nonce
*
big
.
Int
)
bool
{
func
DaggerVerify
(
hash
,
diff
,
nonce
*
big
.
Int
)
bool
{
...
...
dagger_test.go
0 → 100644
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
)
}
ethereum.go
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
DBQueryInterface
,
"c"
,
false
,
"console interfac
e"
)
flag
.
BoolVar
(
&
Start
Console
,
"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
()
...
...
vm_test.go
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 )
}
}
*/
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment