46
46
height uint64
47
47
finalized bool
48
48
dock protocol.Dock
49
+ receipts []* action.Receipt
49
50
commitFunc func (uint64 ) error
50
51
readviewFunc func (name string ) (uint64 , interface {}, error )
51
52
writeviewFunc func (name string , v interface {}) error
@@ -72,6 +73,13 @@ func (ws *workingSet) digest() (hash.Hash256, error) {
72
73
return ws .digestFunc (), nil
73
74
}
74
75
76
+ func (ws * workingSet ) Receipts () ([]* action.Receipt , error ) {
77
+ if ! ws .finalized {
78
+ return nil , errors .New ("workingset has not been finalized yet" )
79
+ }
80
+ return ws .receipts , nil
81
+ }
82
+
75
83
// Height returns the Height of the block being worked on
76
84
func (ws * workingSet ) Height () (uint64 , error ) {
77
85
return ws .height , nil
@@ -316,50 +324,51 @@ func (ws *workingSet) validateNonce(blk *block.Block) error {
316
324
return nil
317
325
}
318
326
319
- func (ws * workingSet ) Process (ctx context.Context , actions []action.SealedEnvelope ) ([] * action. Receipt , error ) {
327
+ func (ws * workingSet ) Process (ctx context.Context , actions []action.SealedEnvelope ) error {
320
328
return ws .process (ctx , actions )
321
329
}
322
330
323
- func (ws * workingSet ) process (ctx context.Context , actions []action.SealedEnvelope ) ([] * action. Receipt , error ) {
331
+ func (ws * workingSet ) process (ctx context.Context , actions []action.SealedEnvelope ) error {
324
332
var err error
325
333
reg := protocol .MustGetRegistry (ctx )
326
334
for _ , act := range actions {
327
335
if ctx , err = withActionCtx (ctx , act ); err != nil {
328
- return nil , err
336
+ return err
329
337
}
330
338
for _ , p := range reg .All () {
331
339
if validator , ok := p .(protocol.ActionValidator ); ok {
332
340
if err := validator .Validate (ctx , act .Action (), ws ); err != nil {
333
- return nil , err
341
+ return err
334
342
}
335
343
}
336
344
}
337
345
}
338
346
for _ , p := range protocol .MustGetRegistry (ctx ).All () {
339
347
if pp , ok := p .(protocol.PreStatesCreator ); ok {
340
348
if err := pp .CreatePreStates (ctx , ws ); err != nil {
341
- return nil , err
349
+ return err
342
350
}
343
351
}
344
352
}
345
353
// TODO: verify whether the post system actions are appended tail
346
354
347
355
receipts , err := ws .runActions (ctx , actions )
348
356
if err != nil {
349
- return nil , err
357
+ return err
350
358
}
351
- return receipts , ws .finalize ()
359
+ ws .receipts = receipts
360
+ return ws .finalize ()
352
361
}
353
362
354
363
func (ws * workingSet ) pickAndRunActions (
355
364
ctx context.Context ,
356
365
ap actpool.ActPool ,
357
366
postSystemActions []action.SealedEnvelope ,
358
367
allowedBlockGasResidue uint64 ,
359
- ) ([]* action. Receipt , [] action.SealedEnvelope , error ) {
368
+ ) ([]action.SealedEnvelope , error ) {
360
369
err := ws .validate (ctx )
361
370
if err != nil {
362
- return nil , nil , err
371
+ return nil , err
363
372
}
364
373
receipts := make ([]* action.Receipt , 0 )
365
374
executedActions := make ([]action.SealedEnvelope , 0 )
@@ -368,7 +377,7 @@ func (ws *workingSet) pickAndRunActions(
368
377
for _ , p := range reg .All () {
369
378
if pp , ok := p .(protocol.PreStatesCreator ); ok {
370
379
if err := pp .CreatePreStates (ctx , ws ); err != nil {
371
- return nil , nil , err
380
+ return nil , err
372
381
}
373
382
}
374
383
}
@@ -398,7 +407,7 @@ func (ws *workingSet) pickAndRunActions(
398
407
if err != nil {
399
408
caller , err := address .FromBytes (nextAction .SrcPubkey ().Hash ())
400
409
if err != nil {
401
- return nil , nil , err
410
+ return nil , err
402
411
}
403
412
ap .DeleteAction (caller )
404
413
actionIterator .PopAccount ()
@@ -412,7 +421,7 @@ func (ws *workingSet) pickAndRunActions(
412
421
actionIterator .PopAccount ()
413
422
continue
414
423
default :
415
- return nil , nil , errors .Wrapf (err , "Failed to update state changes for selp %x" , nextAction .Hash ())
424
+ return nil , errors .Wrapf (err , "Failed to update state changes for selp %x" , nextAction .Hash ())
416
425
}
417
426
if receipt != nil {
418
427
blkCtx .GasLimit -= receipt .GasConsumed
@@ -431,27 +440,27 @@ func (ws *workingSet) pickAndRunActions(
431
440
432
441
for _ , selp := range postSystemActions {
433
442
if ctx , err = withActionCtx (ctx , selp ); err != nil {
434
- return nil , nil , err
443
+ return nil , err
435
444
}
436
445
receipt , err := ws .runAction (ctx , selp )
437
446
if err != nil {
438
- return nil , nil , err
447
+ return nil , err
439
448
}
440
449
if receipt != nil {
441
450
receipts = append (receipts , receipt )
442
451
}
443
452
executedActions = append (executedActions , selp )
444
453
}
454
+ ws .receipts = receipts
445
455
446
- return receipts , executedActions , ws .finalize ()
456
+ return executedActions , ws .finalize ()
447
457
}
448
458
449
459
func (ws * workingSet ) ValidateBlock (ctx context.Context , blk * block.Block ) error {
450
460
if err := ws .validateNonce (blk ); err != nil {
451
461
return errors .Wrap (err , "failed to validate nonce" )
452
462
}
453
- receipts , err := ws .process (ctx , blk .RunnableActions ().Actions ())
454
- if err != nil {
463
+ if err := ws .process (ctx , blk .RunnableActions ().Actions ()); err != nil {
455
464
log .L ().Error ("Failed to update state." , zap .Uint64 ("height" , ws .height ), zap .Error (err ))
456
465
return err
457
466
}
@@ -463,11 +472,10 @@ func (ws *workingSet) ValidateBlock(ctx context.Context, blk *block.Block) error
463
472
if err = blk .VerifyDeltaStateDigest (digest ); err != nil {
464
473
return errors .Wrap (err , "failed to verify delta state digest" )
465
474
}
466
- if err = blk .VerifyReceiptRoot (calculateReceiptRoot (receipts )); err != nil {
475
+ if err = blk .VerifyReceiptRoot (calculateReceiptRoot (ws . receipts )); err != nil {
467
476
return errors .Wrap (err , "Failed to verify receipt root" )
468
477
}
469
478
470
- blk .Receipts = receipts
471
479
return nil
472
480
}
473
481
@@ -477,7 +485,7 @@ func (ws *workingSet) CreateBuilder(
477
485
postSystemActions []action.SealedEnvelope ,
478
486
allowedBlockGasResidue uint64 ,
479
487
) (* block.Builder , error ) {
480
- rc , actions , err := ws .pickAndRunActions (ctx , ap , postSystemActions , allowedBlockGasResidue )
488
+ actions , err := ws .pickAndRunActions (ctx , ap , postSystemActions , allowedBlockGasResidue )
481
489
if err != nil {
482
490
return nil , err
483
491
}
@@ -504,8 +512,8 @@ func (ws *workingSet) CreateBuilder(
504
512
SetTimestamp (blkCtx .BlockTimeStamp ).
505
513
SetPrevBlockHash (prevBlkHash ).
506
514
SetDeltaStateDigest (digest ).
507
- SetReceipts (rc ).
508
- SetReceiptRoot (calculateReceiptRoot (rc )).
509
- SetLogsBloom (calculateLogsBloom (ctx , rc ))
515
+ SetReceipts (ws . receipts ).
516
+ SetReceiptRoot (calculateReceiptRoot (ws . receipts )).
517
+ SetLogsBloom (calculateLogsBloom (ctx , ws . receipts ))
510
518
return blkBuilder , nil
511
519
}
0 commit comments