aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Lange <fjl@users.noreply.github.com>2017-01-13 07:37:23 +0800
committerGitHub <noreply@github.com>2017-01-13 07:37:23 +0800
commitc5df37c1119107ddcc517127b3bd7c2ab4e3649f (patch)
tree22b72545e83ab83ddab5c531d46bdcffc8b8ae59
parente0ceeab0d111ada7d847c83992d2ff3128bfb959 (diff)
downloadgo-tangerine-c5df37c1119107ddcc517127b3bd7c2ab4e3649f.tar
go-tangerine-c5df37c1119107ddcc517127b3bd7c2ab4e3649f.tar.gz
go-tangerine-c5df37c1119107ddcc517127b3bd7c2ab4e3649f.tar.bz2
go-tangerine-c5df37c1119107ddcc517127b3bd7c2ab4e3649f.tar.lz
go-tangerine-c5df37c1119107ddcc517127b3bd7c2ab4e3649f.tar.xz
go-tangerine-c5df37c1119107ddcc517127b3bd7c2ab4e3649f.tar.zst
go-tangerine-c5df37c1119107ddcc517127b3bd7c2ab4e3649f.zip
eth: accept leading zeros for nonce parameter of submitWork (#3558)
-rw-r--r--core/types/block.go4
-rw-r--r--eth/api.go4
-rw-r--r--miner/agent.go3
-rw-r--r--miner/remote_agent.go3
4 files changed, 8 insertions, 6 deletions
diff --git a/core/types/block.go b/core/types/block.go
index 2034bb0ff..1a2a1f2bd 100644
--- a/core/types/block.go
+++ b/core/types/block.go
@@ -423,9 +423,9 @@ func CalcUncleHash(uncles []*Header) common.Hash {
// WithMiningResult returns a new block with the data from b
// where nonce and mix digest are set to the provided values.
-func (b *Block) WithMiningResult(nonce uint64, mixDigest common.Hash) *Block {
+func (b *Block) WithMiningResult(nonce BlockNonce, mixDigest common.Hash) *Block {
cpy := *b.header
- binary.BigEndian.PutUint64(cpy.Nonce[:], nonce)
+ cpy.Nonce = nonce
cpy.MixDigest = mixDigest
return &Block{
header: &cpy,
diff --git a/eth/api.go b/eth/api.go
index d798c196e..023e9a9bb 100644
--- a/eth/api.go
+++ b/eth/api.go
@@ -96,8 +96,8 @@ func (s *PublicMinerAPI) Mining() bool {
// SubmitWork can be used by external miner to submit their POW solution. It returns an indication if the work was
// accepted. Note, this is not an indication if the provided work was valid!
-func (s *PublicMinerAPI) SubmitWork(nonce hexutil.Uint64, solution, digest common.Hash) bool {
- return s.agent.SubmitWork(uint64(nonce), digest, solution)
+func (s *PublicMinerAPI) SubmitWork(nonce types.BlockNonce, solution, digest common.Hash) bool {
+ return s.agent.SubmitWork(nonce, digest, solution)
}
// GetWork returns a work package for external miner. The work package consists of 3 strings
diff --git a/miner/agent.go b/miner/agent.go
index 16f2a7723..697e3971b 100644
--- a/miner/agent.go
+++ b/miner/agent.go
@@ -22,6 +22,7 @@ import (
"sync/atomic"
"github.com/ethereum/go-ethereum/common"
+ "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/pow"
@@ -112,7 +113,7 @@ func (self *CpuAgent) mine(work *Work, stop <-chan struct{}) {
// Mine
nonce, mixDigest := self.pow.Search(work.Block, stop, self.index)
if nonce != 0 {
- block := work.Block.WithMiningResult(nonce, common.BytesToHash(mixDigest))
+ block := work.Block.WithMiningResult(types.EncodeNonce(nonce), common.BytesToHash(mixDigest))
self.returnCh <- &Result{work, block}
} else {
self.returnCh <- nil
diff --git a/miner/remote_agent.go b/miner/remote_agent.go
index f99f38b36..23277bac8 100644
--- a/miner/remote_agent.go
+++ b/miner/remote_agent.go
@@ -25,6 +25,7 @@ import (
"github.com/ethereum/ethash"
"github.com/ethereum/go-ethereum/common"
+ "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/pow"
@@ -132,7 +133,7 @@ func (a *RemoteAgent) GetWork() ([3]string, error) {
// SubmitWork tries to inject a PoW solution tinto the remote agent, returning
// whether the solution was acceted or not (not can be both a bad PoW as well as
// any other error, like no work pending).
-func (a *RemoteAgent) SubmitWork(nonce uint64, mixDigest, hash common.Hash) bool {
+func (a *RemoteAgent) SubmitWork(nonce types.BlockNonce, mixDigest, hash common.Hash) bool {
a.mu.Lock()
defer a.mu.Unlock()