Skip to content

Commit 54855d9

Browse files
Merge pull request #7890 from multiversx/request-missing-proof
when transitioning to Andromeda, request missing proofs
2 parents 0bbb167 + 235f405 commit 54855d9

2 files changed

Lines changed: 91 additions & 17 deletions

File tree

process/block/baseProcess.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,8 @@ func (bp *baseProcessor) requestMissingFinalityAttestingHeaders(
12201220
hdr: headers[index],
12211221
usedInBlock: false,
12221222
}
1223+
1224+
bp.requestProofIfNeeded(headersHashes[index], headers[index])
12231225
}
12241226
}
12251227

process/block/baseProcess_test.go

Lines changed: 89 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2515,23 +2515,34 @@ func TestBaseProcessor_CheckScheduledData(t *testing.T) {
25152515

25162516
createProcessorAndHeader := func(t *testing.T) (interface {
25172517
CheckScheduledData(data.HeaderHandler) error
2518-
}, *block.HeaderV2) { t.Helper(); coreComponents, dataComponents, bootstrapComponents, statusComponents := createComponentHolderMocks(); coreComponents.EnableEpochsHandlerField = enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.ScheduledMiniBlocksFlag); arguments := CreateMockArguments(coreComponents, dataComponents, bootstrapComponents, statusComponents); arguments.ArgBaseProcessor.AccountsDB[state.UserAccountsState] = &stateMock.AccountsStub{
2519-
RootHashCalled: func() ([]byte, error) {
2520-
return []byte("scheduled-root"), nil
2521-
},
2522-
}; arguments.ArgBaseProcessor.ScheduledTxsExecutionHandler = &testscommon.ScheduledTxsExecutionStub{
2523-
GetScheduledGasAndFeesCalled: func() scheduled.GasAndFees {
2524-
return scheduledGasAndFees
2525-
},
2526-
}; processor, err := blproc.NewShardProcessor(arguments); require.NoError(t, err); header := &block.HeaderV2{
2527-
Header: &block.Header{},
2528-
ScheduledRootHash: []byte("scheduled-root"),
2529-
ScheduledAccumulatedFees: big.NewInt(11),
2530-
ScheduledDeveloperFees: big.NewInt(12),
2531-
ScheduledGasProvided: 13,
2532-
ScheduledGasPenalized: 14,
2533-
ScheduledGasRefunded: 15,
2534-
}; return processor, header }
2518+
}, *block.HeaderV2) {
2519+
t.Helper()
2520+
coreComponents, dataComponents, bootstrapComponents, statusComponents := createComponentHolderMocks()
2521+
coreComponents.EnableEpochsHandlerField = enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.ScheduledMiniBlocksFlag)
2522+
arguments := CreateMockArguments(coreComponents, dataComponents, bootstrapComponents, statusComponents)
2523+
arguments.ArgBaseProcessor.AccountsDB[state.UserAccountsState] = &stateMock.AccountsStub{
2524+
RootHashCalled: func() ([]byte, error) {
2525+
return []byte("scheduled-root"), nil
2526+
},
2527+
}
2528+
arguments.ArgBaseProcessor.ScheduledTxsExecutionHandler = &testscommon.ScheduledTxsExecutionStub{
2529+
GetScheduledGasAndFeesCalled: func() scheduled.GasAndFees {
2530+
return scheduledGasAndFees
2531+
},
2532+
}
2533+
processor, err := blproc.NewShardProcessor(arguments)
2534+
require.NoError(t, err)
2535+
header := &block.HeaderV2{
2536+
Header: &block.Header{},
2537+
ScheduledRootHash: []byte("scheduled-root"),
2538+
ScheduledAccumulatedFees: big.NewInt(11),
2539+
ScheduledDeveloperFees: big.NewInt(12),
2540+
ScheduledGasProvided: 13,
2541+
ScheduledGasPenalized: 14,
2542+
ScheduledGasRefunded: 15,
2543+
}
2544+
return processor, header
2545+
}
25352546

25362547
t.Run("should work when scheduled data matches", func(t *testing.T) {
25372548
t.Parallel()
@@ -3818,3 +3829,64 @@ func TestBaseProcessor_DisplayHeader(t *testing.T) {
38183829
require.Equal(t, 23, len(lines))
38193830
})
38203831
}
3832+
3833+
func TestMetaProcessor_requestMissingFinalityAttestingShardHeaders_AttestationHeaderPresentProofMissingShouldRequestProof(t *testing.T) {
3834+
t.Parallel()
3835+
3836+
noOfShards := uint32(2)
3837+
td := createTestData()
3838+
proofRequests := make(chan requestedProof, 1)
3839+
3840+
arguments := createMetaProcessorArguments(t, noOfShards)
3841+
coreComponents, ok := arguments.CoreComponents.(*mock.CoreComponentsMock)
3842+
require.True(t, ok)
3843+
coreComponents.EnableEpochsHandlerField = &enableEpochsHandlerMock.EnableEpochsHandlerStub{
3844+
IsFlagEnabledInEpochCalled: func(flag core.EnableEpochFlag, epoch uint32) bool {
3845+
return flag == common.AndromedaFlag
3846+
},
3847+
}
3848+
3849+
poolsHolder, ok := arguments.DataComponents.Datapool().(*dataRetrieverMock.PoolsHolderMock)
3850+
require.True(t, ok)
3851+
poolsHolder.SetHeadersPool(createPoolsHolderForHeaderRequests())
3852+
3853+
requestHandler, ok := arguments.ArgBaseProcessor.RequestHandler.(*testscommon.RequestHandlerStub)
3854+
require.True(t, ok)
3855+
requestHandler.RequestEquivalentProofByHashCalled = func(headerShard uint32, headerHash []byte) {
3856+
proofRequests <- requestedProof{shardID: headerShard, hash: append([]byte(nil), headerHash...)}
3857+
}
3858+
3859+
mp, err := blproc.NewMetaProcessor(*arguments)
3860+
require.NoError(t, err)
3861+
3862+
referenced := td[0].referencedHeaderData
3863+
attestation := td[0].attestationHeaderData
3864+
3865+
mp.SetShardBlockFinality(1)
3866+
mp.SetHighestHdrNonceForCurrentBlock(referenced.header.GetShardID(), referenced.header.GetNonce())
3867+
mp.SetLastNotarizedHeaderForShard(referenced.header.GetShardID(), &blproc.LastNotarizedHeaderInfo{
3868+
Header: referenced.header,
3869+
Hash: referenced.headerHash,
3870+
NotarizedBasedOnProof: false,
3871+
HasProof: false,
3872+
})
3873+
3874+
mp.GetDataPool().Headers().AddHeader(attestation.headerHash, attestation.header)
3875+
3876+
missingFinalityHeaders := mp.RequestMissingFinalityAttestingShardHeaders()
3877+
3878+
require.Equal(t, uint32(0), missingFinalityHeaders)
3879+
3880+
select {
3881+
case requested := <-proofRequests:
3882+
require.Equal(t, attestation.header.GetShardID(), requested.shardID)
3883+
require.Equal(t, attestation.headerHash, requested.hash)
3884+
case <-time.After(100 * time.Millisecond):
3885+
require.Fail(t, "missing equivalent proof request for attestation header")
3886+
}
3887+
}
3888+
3889+
type requestedProof struct {
3890+
shardID uint32
3891+
hash []byte
3892+
}

0 commit comments

Comments
 (0)