@@ -5870,3 +5870,94 @@ func TestMetaProcessor_CheckShardHeadersValidityContendedGate(t *testing.T) {
58705870 assert .Nil (t , err )
58715871 })
58725872}
5873+
5874+ func TestMetaProcessor_UpdateStateSignalsNewlyFinalBlocksUnderSupernova (t * testing.T ) {
5875+ t .Parallel ()
5876+
5877+ hash4 , hash5 , hash6 , hash7 , hash8 := []byte ("hash4" ), []byte ("hash5" ), []byte ("hash6" ), []byte ("hash7" ), []byte ("hash8" )
5878+ newMetaBlock := func (nonce uint64 , round uint64 , prevHash []byte ) * block.MetaBlock {
5879+ return & block.MetaBlock {
5880+ Nonce : nonce ,
5881+ Round : round ,
5882+ PrevHash : prevHash ,
5883+ RootHash : append ([]byte ("rootHash" ), byte (nonce )),
5884+ ValidatorStatsRootHash : append ([]byte ("validatorRootHash" ), byte (nonce )),
5885+ }
5886+ }
5887+ hdr4 := newMetaBlock (4 , 4 , []byte ("hash3" ))
5888+ hdr5 := newMetaBlock (5 , 5 , hash4 )
5889+ contendedHdr6 := newMetaBlock (6 , 8 , hash5 )
5890+ contendedHdr7 := newMetaBlock (7 , 11 , hash6 )
5891+ cleanHdr8 := newMetaBlock (8 , 12 , hash7 )
5892+ headersByHash := map [string ]data.HeaderHandler {
5893+ string (hash4 ): hdr4 ,
5894+ string (hash5 ): hdr5 ,
5895+ string (hash6 ): contendedHdr6 ,
5896+ string (hash7 ): contendedHdr7 ,
5897+ }
5898+
5899+ coreComponents , dataComponents , bootstrapComponents , statusComponents := createMockComponentHolders ()
5900+ coreComponents .EnableEpochsHandlerField = & enableEpochsHandlerMock.EnableEpochsHandlerStub {
5901+ IsFlagEnabledInEpochCalled : func (flag core.EnableEpochFlag , epoch uint32 ) bool {
5902+ return flag == common .AndromedaFlag || flag == common .SupernovaFlag
5903+ },
5904+ }
5905+
5906+ dataPool := initDataPool ()
5907+ dataPool .HeadersCalled = func () dataRetriever.HeadersPool {
5908+ return & mock.HeadersCacherStub {
5909+ GetHeaderByHashCalled : func (hash []byte ) (data.HeaderHandler , error ) {
5910+ header , ok := headersByHash [string (hash )]
5911+ if ! ok {
5912+ return nil , errors .New ("header not found" )
5913+ }
5914+ return header , nil
5915+ },
5916+ }
5917+ }
5918+ dataComponents .DataPool = dataPool
5919+
5920+ setFinalBlockInfos := make ([]uint64 , 0 )
5921+ dataComponents .BlockChain = & testscommon.ChainHandlerStub {
5922+ GetGenesisHeaderCalled : func () data.HeaderHandler {
5923+ return & block.Header {Nonce : 0 }
5924+ },
5925+ SetFinalBlockInfoCalled : func (nonce uint64 , headerHash []byte , rootHash []byte ) {
5926+ setFinalBlockInfos = append (setFinalBlockInfos , nonce )
5927+ },
5928+ }
5929+
5930+ outportCapture := & finalizedBlocksCapture {OutportStub : & outport.OutportStub {}}
5931+ statusComponents .Outport = outportCapture
5932+
5933+ finalNonce := uint64 (5 )
5934+ arguments := createMockMetaArguments (coreComponents , dataComponents , bootstrapComponents , statusComponents )
5935+ arguments .ForkDetector = & mock.ForkDetectorMock {
5936+ GetHighestFinalBlockNonceCalled : func () uint64 {
5937+ return finalNonce
5938+ },
5939+ }
5940+ mp , _ := processBlock .NewMetaProcessor (arguments )
5941+
5942+ // clean committed block is final and signaled at once
5943+ mp .UpdateState (hdr5 , hash5 )
5944+ require .Equal (t , [][]byte {hash4 , hash5 }, outportCapture .finalizedHashes )
5945+ require .Equal (t , []uint64 {5 }, setFinalBlockInfos )
5946+
5947+ // contended committed block is not signaled while unsettled
5948+ mp .UpdateState (contendedHdr6 , hash6 )
5949+ require .Equal (t , [][]byte {hash4 , hash5 }, outportCapture .finalizedHashes )
5950+ require .Equal (t , []uint64 {5 }, setFinalBlockInfos )
5951+
5952+ // the committed child settles its parent: the parent is signaled, the contended child is not
5953+ finalNonce = 6
5954+ mp .UpdateState (contendedHdr7 , hash7 )
5955+ require .Equal (t , [][]byte {hash4 , hash5 , hash6 }, outportCapture .finalizedHashes )
5956+ require .Equal (t , []uint64 {5 , 6 }, setFinalBlockInfos )
5957+
5958+ // clean child settles its parent and is instantly final: both signaled exactly once
5959+ finalNonce = 8
5960+ mp .UpdateState (cleanHdr8 , hash8 )
5961+ require .Equal (t , [][]byte {hash4 , hash5 , hash6 , hash7 , hash8 }, outportCapture .finalizedHashes )
5962+ require .Equal (t , []uint64 {5 , 6 , 8 }, setFinalBlockInfos )
5963+ }
0 commit comments