Skip to content

Commit 144c1c6

Browse files
rjl493456442karalabe
authored andcommitted
consensus: extend getWork API with block number (#18038)
1 parent b16cc50 commit 144c1c6

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

consensus/ethash/api.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,28 @@ type API struct {
3737
// result[0] - 32 bytes hex encoded current block header pow-hash
3838
// result[1] - 32 bytes hex encoded seed hash used for DAG
3939
// result[2] - 32 bytes hex encoded boundary condition ("target"), 2^256/difficulty
40-
func (api *API) GetWork() ([3]string, error) {
40+
// result[3] - hex encoded block number
41+
func (api *API) GetWork() ([4]string, error) {
4142
if api.ethash.config.PowMode != ModeNormal && api.ethash.config.PowMode != ModeTest {
42-
return [3]string{}, errors.New("not supported")
43+
return [4]string{}, errors.New("not supported")
4344
}
4445

4546
var (
46-
workCh = make(chan [3]string, 1)
47+
workCh = make(chan [4]string, 1)
4748
errc = make(chan error, 1)
4849
)
4950

5051
select {
5152
case api.ethash.fetchWorkCh <- &sealWork{errc: errc, res: workCh}:
5253
case <-api.ethash.exitCh:
53-
return [3]string{}, errEthashStopped
54+
return [4]string{}, errEthashStopped
5455
}
5556

5657
select {
5758
case work := <-workCh:
5859
return work, nil
5960
case err := <-errc:
60-
return [3]string{}, err
61+
return [4]string{}, err
6162
}
6263
}
6364

consensus/ethash/ethash.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ type hashrate struct {
432432
// sealWork wraps a seal work package for remote sealer.
433433
type sealWork struct {
434434
errc chan error
435-
res chan [3]string
435+
res chan [4]string
436436
}
437437

438438
// Ethash is a consensus engine based on proof-of-work implementing the ethash

consensus/ethash/ethash_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func TestRemoteSealer(t *testing.T) {
107107
ethash.Seal(nil, block, results, nil)
108108

109109
var (
110-
work [3]string
110+
work [4]string
111111
err error
112112
)
113113
if work, err = api.GetWork(); err != nil || work[0] != sealhash.Hex() {

consensus/ethash/sealer.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"time"
3131

3232
"github.com/ethereum/go-ethereum/common"
33+
"github.com/ethereum/go-ethereum/common/hexutil"
3334
"github.com/ethereum/go-ethereum/consensus"
3435
"github.com/ethereum/go-ethereum/core/types"
3536
"github.com/ethereum/go-ethereum/log"
@@ -193,7 +194,7 @@ func (ethash *Ethash) remote(notify []string, noverify bool) {
193194

194195
results chan<- *types.Block
195196
currentBlock *types.Block
196-
currentWork [3]string
197+
currentWork [4]string
197198

198199
notifyTransport = &http.Transport{}
199200
notifyClient = &http.Client{
@@ -234,12 +235,14 @@ func (ethash *Ethash) remote(notify []string, noverify bool) {
234235
// result[0], 32 bytes hex encoded current block header pow-hash
235236
// result[1], 32 bytes hex encoded seed hash used for DAG
236237
// result[2], 32 bytes hex encoded boundary condition ("target"), 2^256/difficulty
238+
// result[3], hex encoded block number
237239
makeWork := func(block *types.Block) {
238240
hash := ethash.SealHash(block.Header())
239241

240242
currentWork[0] = hash.Hex()
241243
currentWork[1] = common.BytesToHash(SeedHash(block.NumberU64())).Hex()
242244
currentWork[2] = common.BytesToHash(new(big.Int).Div(two256, block.Difficulty()).Bytes()).Hex()
245+
currentWork[3] = hexutil.EncodeBig(block.Number())
243246

244247
// Trace the seal work fetched by remote sealer.
245248
currentBlock = block

0 commit comments

Comments
 (0)