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
b24f16fa
Commit
b24f16fa
authored
May 14, 2015
by
Gustav Simonsson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make read of ethash hashrate atomic and update ethash godep
parent
f7fdb4df
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
48 additions
and
116 deletions
+48
-116
Godeps.json
Godeps/Godeps.json
+2
-2
ethash.go
Godeps/_workspace/src/github.com/ethereum/ethash/ethash.go
+15
-7
core.c
...orkspace/src/github.com/ethereum/ethash/src/python/core.c
+28
-99
miner.go
miner/miner.go
+1
-1
worker.go
miner/worker.go
+2
-7
No files found.
Godeps/Godeps.json
View file @
b24f16fa
...
...
@@ -17,8 +17,8 @@
},
{
"ImportPath"
:
"github.com/ethereum/ethash"
,
"Comment"
:
"v23.1-20
4-g0401fdf
"
,
"Rev"
:
"
0401fdf56a3bc8679f9560e542c3d1cf83020efe
"
"Comment"
:
"v23.1-20
6-gf0e6321
"
,
"Rev"
:
"
f0e63218b721dc2f696920a92d5de1f6364e9bf7
"
},
{
"ImportPath"
:
"github.com/howeyc/fsnotify"
,
...
...
Godeps/_workspace/src/github.com/ethereum/ethash/ethash.go
View file @
b24f16fa
...
...
@@ -18,6 +18,7 @@ import (
"path/filepath"
"runtime"
"sync"
"sync/atomic"
"time"
"unsafe"
...
...
@@ -235,7 +236,7 @@ type Full struct {
test
bool
// if set use a smaller DAG size
turbo
bool
hashRate
int
64
hashRate
int
32
mu
sync
.
Mutex
// protects dag
current
*
dag
// current full DAG
...
...
@@ -265,6 +266,7 @@ func (pow *Full) Search(block pow.Block, stop <-chan struct{}) (nonce uint64, mi
i
:=
int64
(
0
)
starti
:=
i
start
:=
time
.
Now
()
.
UnixNano
()
previousHashrate
:=
int32
(
0
)
nonce
=
uint64
(
r
.
Int63
())
hash
:=
hashToH256
(
block
.
HashNoNonce
())
...
...
@@ -272,14 +274,20 @@ func (pow *Full) Search(block pow.Block, stop <-chan struct{}) (nonce uint64, mi
for
{
select
{
case
<-
stop
:
pow
.
hashRate
=
0
atomic
.
AddInt32
(
&
pow
.
hashRate
,
-
previousHashrate
)
return
0
,
nil
default
:
i
++
elapsed
:=
time
.
Now
()
.
UnixNano
()
-
start
hashes
:=
((
float64
(
1e9
)
/
float64
(
elapsed
))
*
float64
(
i
-
starti
))
/
1000
pow
.
hashRate
=
int64
(
hashes
)
// we don't have to update hash rate on every nonce, so update after
// first nonce check and then after 2^X nonces
if
i
==
2
||
((
i
%
(
1
<<
16
))
==
0
)
{
elapsed
:=
time
.
Now
()
.
UnixNano
()
-
start
hashes
:=
(
float64
(
1e9
)
/
float64
(
elapsed
))
*
float64
(
i
-
starti
)
hashrateDiff
:=
int32
(
hashes
)
-
previousHashrate
previousHashrate
=
int32
(
hashes
)
atomic
.
AddInt32
(
&
pow
.
hashRate
,
hashrateDiff
)
}
ret
:=
C
.
ethash_full_compute
(
dag
.
ptr
,
hash
,
C
.
uint64_t
(
nonce
))
result
:=
h256ToHash
(
ret
.
result
)
.
Big
()
...
...
@@ -287,6 +295,7 @@ func (pow *Full) Search(block pow.Block, stop <-chan struct{}) (nonce uint64, mi
// TODO: disagrees with the spec https://github.com/ethereum/wiki/wiki/Ethash#mining
if
ret
.
success
&&
result
.
Cmp
(
target
)
<=
0
{
mixDigest
=
C
.
GoBytes
(
unsafe
.
Pointer
(
&
ret
.
mix_hash
),
C
.
int
(
32
))
atomic
.
AddInt32
(
&
pow
.
hashRate
,
-
previousHashrate
)
return
nonce
,
mixDigest
}
nonce
+=
1
...
...
@@ -299,8 +308,7 @@ func (pow *Full) Search(block pow.Block, stop <-chan struct{}) (nonce uint64, mi
}
func
(
pow
*
Full
)
GetHashrate
()
int64
{
// TODO: this needs to use an atomic operation.
return
pow
.
hashRate
return
int64
(
atomic
.
LoadInt32
(
&
pow
.
hashRate
))
}
func
(
pow
*
Full
)
Turbo
(
on
bool
)
{
...
...
Godeps/_workspace/src/github.com/ethereum/ethash/src/python/core.c
View file @
b24f16fa
This diff is collapsed.
Click to expand it.
miner/miner.go
View file @
b24f16fa
...
...
@@ -70,7 +70,7 @@ func (self *Miner) Register(agent Agent) {
}
func
(
self
*
Miner
)
HashRate
()
int64
{
return
self
.
worker
.
HashR
ate
()
return
self
.
pow
.
GetHashr
ate
()
}
func
(
self
*
Miner
)
SetExtra
(
extra
[]
byte
)
{
...
...
miner/worker.go
View file @
b24f16fa
...
...
@@ -173,7 +173,6 @@ func (self *worker) stop() {
func
(
self
*
worker
)
register
(
agent
Agent
)
{
self
.
mu
.
Lock
()
defer
self
.
mu
.
Unlock
()
self
.
agents
=
append
(
self
.
agents
,
agent
)
agent
.
SetReturnCh
(
self
.
recv
)
}
...
...
@@ -453,13 +452,9 @@ func (self *worker) commitTransaction(tx *types.Transaction) error {
return
nil
}
// TODO: remove or use
func
(
self
*
worker
)
HashRate
()
int64
{
var
tot
int64
for
_
,
agent
:=
range
self
.
agents
{
tot
+=
agent
.
GetHashRate
()
}
return
tot
return
0
}
// gasprice calculates a reduced gas price based on the pct
...
...
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