Skip to content

Commit c5df37c

Browse files
authored
eth: accept leading zeros for nonce parameter of submitWork (ethereum#3558)
1 parent e0ceeab commit c5df37c

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

core/types/block.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,9 @@ func CalcUncleHash(uncles []*Header) common.Hash {
423423

424424
// WithMiningResult returns a new block with the data from b
425425
// where nonce and mix digest are set to the provided values.
426-
func (b *Block) WithMiningResult(nonce uint64, mixDigest common.Hash) *Block {
426+
func (b *Block) WithMiningResult(nonce BlockNonce, mixDigest common.Hash) *Block {
427427
cpy := *b.header
428-
binary.BigEndian.PutUint64(cpy.Nonce[:], nonce)
428+
cpy.Nonce = nonce
429429
cpy.MixDigest = mixDigest
430430
return &Block{
431431
header: &cpy,

eth/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ func (s *PublicMinerAPI) Mining() bool {
9696

9797
// SubmitWork can be used by external miner to submit their POW solution. It returns an indication if the work was
9898
// accepted. Note, this is not an indication if the provided work was valid!
99-
func (s *PublicMinerAPI) SubmitWork(nonce hexutil.Uint64, solution, digest common.Hash) bool {
100-
return s.agent.SubmitWork(uint64(nonce), digest, solution)
99+
func (s *PublicMinerAPI) SubmitWork(nonce types.BlockNonce, solution, digest common.Hash) bool {
100+
return s.agent.SubmitWork(nonce, digest, solution)
101101
}
102102

103103
// GetWork returns a work package for external miner. The work package consists of 3 strings

miner/agent.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"sync/atomic"
2323

2424
"github.com/ethereum/go-ethereum/common"
25+
"github.com/ethereum/go-ethereum/core/types"
2526
"github.com/ethereum/go-ethereum/logger"
2627
"github.com/ethereum/go-ethereum/logger/glog"
2728
"github.com/ethereum/go-ethereum/pow"
@@ -112,7 +113,7 @@ func (self *CpuAgent) mine(work *Work, stop <-chan struct{}) {
112113
// Mine
113114
nonce, mixDigest := self.pow.Search(work.Block, stop, self.index)
114115
if nonce != 0 {
115-
block := work.Block.WithMiningResult(nonce, common.BytesToHash(mixDigest))
116+
block := work.Block.WithMiningResult(types.EncodeNonce(nonce), common.BytesToHash(mixDigest))
116117
self.returnCh <- &Result{work, block}
117118
} else {
118119
self.returnCh <- nil

miner/remote_agent.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525

2626
"github.com/ethereum/ethash"
2727
"github.com/ethereum/go-ethereum/common"
28+
"github.com/ethereum/go-ethereum/core/types"
2829
"github.com/ethereum/go-ethereum/logger"
2930
"github.com/ethereum/go-ethereum/logger/glog"
3031
"github.com/ethereum/go-ethereum/pow"
@@ -132,7 +133,7 @@ func (a *RemoteAgent) GetWork() ([3]string, error) {
132133
// SubmitWork tries to inject a PoW solution tinto the remote agent, returning
133134
// whether the solution was acceted or not (not can be both a bad PoW as well as
134135
// any other error, like no work pending).
135-
func (a *RemoteAgent) SubmitWork(nonce uint64, mixDigest, hash common.Hash) bool {
136+
func (a *RemoteAgent) SubmitWork(nonce types.BlockNonce, mixDigest, hash common.Hash) bool {
136137
a.mu.Lock()
137138
defer a.mu.Unlock()
138139

0 commit comments

Comments
 (0)