4848
4949// Seal implements consensus.Engine, attempting to find a nonce that satisfies
5050// the block's difficulty requirements.
51- func (ethash * Ethash ) Seal (chain consensus.ChainHeaderReader , block * types.Block , results chan <- * types.Block , stop <- chan struct {}) error {
51+ func (ethash * Ethash ) Seal (chain consensus.ChainHeaderReader , block * types.Block , profit * big. Int , results chan <- * types.Block , stop <- chan struct {}) error {
5252 // If we're running a fake PoW, simply return a 0 nonce immediately
5353 if ethash .config .PowMode == ModeFake || ethash .config .PowMode == ModeFullFake {
5454 header := block .Header ()
@@ -62,7 +62,7 @@ func (ethash *Ethash) Seal(chain consensus.ChainHeaderReader, block *types.Block
6262 }
6363 // If we're running a shared PoW, delegate sealing to it
6464 if ethash .shared != nil {
65- return ethash .shared .Seal (chain , block , results , stop )
65+ return ethash .shared .Seal (chain , block , profit , results , stop )
6666 }
6767 // Create a runner and the multiple search threads it directs
6868 abort := make (chan struct {})
@@ -86,7 +86,7 @@ func (ethash *Ethash) Seal(chain consensus.ChainHeaderReader, block *types.Block
8686 }
8787 // Push new work to remote sealer
8888 if ethash .remote != nil {
89- ethash .remote .workCh <- & sealTask {block : block , results : results }
89+ ethash .remote .workCh <- & sealTask {block : block , profit : profit , results : results }
9090 }
9191 var (
9292 pend sync.WaitGroup
@@ -117,7 +117,7 @@ func (ethash *Ethash) Seal(chain consensus.ChainHeaderReader, block *types.Block
117117 case <- ethash .update :
118118 // Thread count was changed on user request, restart
119119 close (abort )
120- if err := ethash .Seal (chain , block , results , stop ); err != nil {
120+ if err := ethash .Seal (chain , block , profit , results , stop ); err != nil {
121121 ethash .config .Log .Error ("Failed to restart sealing after update" , "err" , err )
122122 }
123123 }
@@ -194,7 +194,7 @@ type remoteSealer struct {
194194 works map [common.Hash ]* types.Block
195195 rates map [common.Hash ]hashrate
196196 currentBlock * types.Block
197- currentWork [4 ]string
197+ currentWork [5 ]string
198198 notifyCtx context.Context
199199 cancelNotify context.CancelFunc // cancels all notification requests
200200 reqWG sync.WaitGroup // tracks notification request goroutines
@@ -215,6 +215,7 @@ type remoteSealer struct {
215215// sealTask wraps a seal block with relative result channel for remote sealer thread.
216216type sealTask struct {
217217 block * types.Block
218+ profit * big.Int
218219 results chan <- * types.Block
219220}
220221
@@ -239,7 +240,7 @@ type hashrate struct {
239240// sealWork wraps a seal work package for remote sealer.
240241type sealWork struct {
241242 errc chan error
242- res chan [4 ]string
243+ res chan [5 ]string
243244}
244245
245246func startRemoteSealer (ethash * Ethash , urls []string , noverify bool ) * remoteSealer {
@@ -281,7 +282,7 @@ func (s *remoteSealer) loop() {
281282 // Update current work with new received block.
282283 // Note same work can be past twice, happens when changing CPU threads.
283284 s .results = work .results
284- s .makeWork (work .block )
285+ s .makeWork (work .block , work . profit )
285286 s .notifyWork ()
286287
287288 case work := <- s .fetchWorkCh :
@@ -338,18 +339,23 @@ func (s *remoteSealer) loop() {
338339
339340// makeWork creates a work package for external miner.
340341//
341- // The work package consists of 3 strings:
342+ // The work package consists of 5 strings:
342343// result[0], 32 bytes hex encoded current block header pow-hash
343344// result[1], 32 bytes hex encoded seed hash used for DAG
344345// result[2], 32 bytes hex encoded boundary condition ("target"), 2^256/difficulty
345346// result[3], hex encoded block number
346- func (s * remoteSealer ) makeWork (block * types.Block ) {
347+ // result[4], hex encoded profit generated from this block, if present
348+ func (s * remoteSealer ) makeWork (block * types.Block , profit * big.Int ) {
347349 hash := s .ethash .SealHash (block .Header ())
348350 s .currentWork [0 ] = hash .Hex ()
349351 s .currentWork [1 ] = common .BytesToHash (SeedHash (block .NumberU64 ())).Hex ()
350352 s .currentWork [2 ] = common .BytesToHash (new (big.Int ).Div (two256 , block .Difficulty ()).Bytes ()).Hex ()
351353 s .currentWork [3 ] = hexutil .EncodeBig (block .Number ())
352354
355+ if profit != nil {
356+ s .currentWork [4 ] = hexutil .EncodeBig (profit )
357+ }
358+
353359 // Trace the seal work fetched by remote sealer.
354360 s .currentBlock = block
355361 s .works [hash ] = block
@@ -375,7 +381,7 @@ func (s *remoteSealer) notifyWork() {
375381 }
376382}
377383
378- func (s * remoteSealer ) sendNotification (ctx context.Context , url string , json []byte , work [4 ]string ) {
384+ func (s * remoteSealer ) sendNotification (ctx context.Context , url string , json []byte , work [5 ]string ) {
379385 defer s .reqWG .Done ()
380386
381387 req , err := http .NewRequest ("POST" , url , bytes .NewReader (json ))
0 commit comments