Skip to content

Commit db371eb

Browse files
authored
Merge branch 'feat/supernova-async-exec' into chain-handler-last-execution-info
2 parents 5443792 + b47470c commit db371eb

48 files changed

Lines changed: 2251 additions & 184 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

common/common.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ const (
2727
nonceIndex = 0
2828
)
2929

30+
type executionResultHandler interface {
31+
GetMiniBlockHeadersHandlers() []data.MiniBlockHeaderHandler
32+
}
33+
3034
type chainParametersHandler interface {
3135
CurrentChainParameters() config.ChainParametersByEpochConfig
3236
ChainParametersForEpoch(epoch uint32) (config.ChainParametersByEpochConfig, error)
@@ -409,6 +413,23 @@ func ExtractBaseExecutionResultHandler(lastExecResultsHandler data.LastExecution
409413
return baseExecutionResultsHandler, nil
410414
}
411415

416+
// GetMiniBlocksHeaderHandlersFromExecResult returns miniblock handlers based on execution result
417+
func GetMiniBlocksHeaderHandlersFromExecResult(
418+
baseExecResult data.BaseExecutionResultHandler,
419+
headerShard uint32,
420+
) ([]data.MiniBlockHeaderHandler, error) {
421+
if check.IfNil(baseExecResult) {
422+
return nil, ErrNilBaseExecutionResult
423+
}
424+
425+
execResult, ok := baseExecResult.(executionResultHandler)
426+
if !ok {
427+
return nil, ErrWrongTypeAssertion
428+
}
429+
430+
return execResult.GetMiniBlockHeadersHandlers(), nil
431+
}
432+
412433
// GetLastExecutionResultNonce returns last execution result nonce if header v3 enable, otherwise it returns provided header nonce
413434
func GetLastExecutionResultNonce(
414435
header data.HeaderHandler,

common/common_test.go

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,86 @@ func TestGetLastBaseExecutionResultHandler(t *testing.T) {
578578
})
579579
}
580580

581+
func TestGetMiniBlockHeaderHandlersFromExecResults(t *testing.T) {
582+
t.Parallel()
583+
584+
t.Run("should fail if nil base execution result", func(t *testing.T) {
585+
t.Parallel()
586+
587+
retExecResult, err := common.GetMiniBlocksHeaderHandlersFromExecResult(nil, 1)
588+
require.Equal(t, common.ErrNilBaseExecutionResult, err)
589+
require.Nil(t, retExecResult)
590+
})
591+
592+
t.Run("should fail if wrong type for shard", func(t *testing.T) {
593+
t.Parallel()
594+
595+
execResult := &block.BaseExecutionResult{}
596+
597+
retExecResult, err := common.GetMiniBlocksHeaderHandlersFromExecResult(execResult, 1)
598+
require.Equal(t, common.ErrWrongTypeAssertion, err)
599+
require.Nil(t, retExecResult)
600+
})
601+
602+
t.Run("should work for shard", func(t *testing.T) {
603+
t.Parallel()
604+
605+
mbh1 := block.MiniBlockHeader{
606+
Hash: []byte("hash1"),
607+
}
608+
mbh2 := block.MiniBlockHeader{
609+
Hash: []byte("hash1"),
610+
}
611+
612+
miniBlockHeaders := []block.MiniBlockHeader{
613+
mbh1,
614+
mbh2,
615+
}
616+
617+
execResult := &block.ExecutionResult{
618+
MiniBlockHeaders: miniBlockHeaders,
619+
}
620+
621+
expMiniBlockHandlers := []data.MiniBlockHeaderHandler{
622+
&mbh1,
623+
&mbh2,
624+
}
625+
626+
retExecResult, err := common.GetMiniBlocksHeaderHandlersFromExecResult(execResult, 1)
627+
require.Nil(t, err)
628+
require.Equal(t, expMiniBlockHandlers, retExecResult)
629+
})
630+
631+
t.Run("should work for meta", func(t *testing.T) {
632+
t.Parallel()
633+
634+
mbh1 := block.MiniBlockHeader{
635+
Hash: []byte("hash1"),
636+
}
637+
mbh2 := block.MiniBlockHeader{
638+
Hash: []byte("hash1"),
639+
}
640+
641+
miniBlockHeaders := []block.MiniBlockHeader{
642+
mbh1,
643+
mbh2,
644+
}
645+
646+
execResult := &block.MetaExecutionResult{
647+
MiniBlockHeaders: miniBlockHeaders,
648+
}
649+
650+
expMiniBlockHandlers := []data.MiniBlockHeaderHandler{
651+
&mbh1,
652+
&mbh2,
653+
}
654+
655+
retExecResult, err := common.GetMiniBlocksHeaderHandlersFromExecResult(execResult, core.MetachainShardId)
656+
require.Nil(t, err)
657+
require.Equal(t, expMiniBlockHandlers, retExecResult)
658+
})
659+
}
660+
581661
func TestPrepareLogEventsKey(t *testing.T) {
582662
t.Parallel()
583663

consensus/spos/worker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ func (wrk *Worker) Extend(subroundId int) {
863863
}
864864

865865
wrk.scheduledProcessor.ForceStopScheduledExecutionBlocking()
866-
wrk.blockProcessor.RevertCurrentBlock()
866+
wrk.blockProcessor.RevertCurrentBlock(wrk.consensusState.GetHeader())
867867
wrk.removeConsensusHeaderFromPool()
868868

869869
log.Debug("current block is reverted")

consensus/spos/worker_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func createDefaultWorkerArgs(appStatusHandler core.AppStatusHandler) *spos.Worke
5858
DecodeBlockHeaderCalled: func(dta []byte) data.HeaderHandler {
5959
return nil
6060
},
61-
RevertCurrentBlockCalled: func() {
61+
RevertCurrentBlockCalled: func(_ data.HeaderHandler) {
6262
},
6363
DecodeBlockBodyCalled: func(dta []byte) data.BodyHandler {
6464
return nil
@@ -796,7 +796,7 @@ func testWorkerProcessReceivedMessageComputeReceivedProposedBlockMetric(
796796

797797
return header
798798
},
799-
RevertCurrentBlockCalled: func() {
799+
RevertCurrentBlockCalled: func(_ data.HeaderHandler) {
800800
},
801801
DecodeBlockBodyCalled: func(dta []byte) data.BodyHandler {
802802
return nil
@@ -1210,7 +1210,7 @@ func TestWorker_ProcessReceivedMessageWrongChainIDInProposedBlockShouldError(t *
12101210
},
12111211
}
12121212
},
1213-
RevertCurrentBlockCalled: func() {
1213+
RevertCurrentBlockCalled: func(_ data.HeaderHandler) {
12141214
},
12151215
},
12161216
)
@@ -1263,7 +1263,7 @@ func TestWorker_ProcessReceivedMessageWithABadOriginatorShouldErr(t *testing.T)
12631263
},
12641264
}
12651265
},
1266-
RevertCurrentBlockCalled: func() {
1266+
RevertCurrentBlockCalled: func(_ data.HeaderHandler) {
12671267
},
12681268
DecodeBlockBodyCalled: func(dta []byte) data.BodyHandler {
12691269
return nil
@@ -1323,7 +1323,7 @@ func TestWorker_ProcessReceivedMessageWithHeaderAndWrongHash(t *testing.T) {
13231323
},
13241324
}
13251325
},
1326-
RevertCurrentBlockCalled: func() {
1326+
RevertCurrentBlockCalled: func(_ data.HeaderHandler) {
13271327
},
13281328
DecodeBlockBodyCalled: func(dta []byte) data.BodyHandler {
13291329
return nil
@@ -1394,7 +1394,7 @@ func TestWorker_ProcessReceivedMessageOkValsShouldWork(t *testing.T) {
13941394
},
13951395
}
13961396
},
1397-
RevertCurrentBlockCalled: func() {
1397+
RevertCurrentBlockCalled: func(_ data.HeaderHandler) {
13981398
},
13991399
DecodeBlockBodyCalled: func(dta []byte) data.BodyHandler {
14001400
return nil
@@ -2028,7 +2028,7 @@ func TestWorker_ExtendShouldWorkAfterAWhile(t *testing.T) {
20282028
wrk := *initWorker(&statusHandlerMock.AppStatusHandlerStub{})
20292029
executed := int32(0)
20302030
blockProcessor := &testscommon.BlockProcessorStub{
2031-
RevertCurrentBlockCalled: func() {
2031+
RevertCurrentBlockCalled: func(_ data.HeaderHandler) {
20322032
atomic.AddInt32(&executed, 1)
20332033
},
20342034
}
@@ -2053,7 +2053,7 @@ func TestWorker_ExtendShouldWork(t *testing.T) {
20532053
wrk := *initWorker(&statusHandlerMock.AppStatusHandlerStub{})
20542054
executed := int32(0)
20552055
blockProcessor := &testscommon.BlockProcessorStub{
2056-
RevertCurrentBlockCalled: func() {
2056+
RevertCurrentBlockCalled: func(_ data.HeaderHandler) {
20572057
atomic.AddInt32(&executed, 1)
20582058
},
20592059
}

0 commit comments

Comments
 (0)