@@ -304,6 +304,62 @@ func TestProcessHeightEvent_SyncsAndUpdatesState(t *testing.T) {
304304 assert .Equal (t , uint64 (1 ), st1 .LastBlockHeight )
305305}
306306
307+ func TestProcessHeightEvent_UnexpectedProposerFromDAIsNotCriticalStateError (t * testing.T ) {
308+ ds := dssync .MutexWrap (datastore .NewMapDatastore ())
309+ st := store .New (ds )
310+
311+ cm , err := cache .NewManager (config .DefaultConfig (), st , zerolog .Nop ())
312+ require .NoError (t , err )
313+
314+ expectedAddr , _ , _ := buildSyncTestSigner (t )
315+ wrongAddr , wrongPub , wrongSigner := buildSyncTestSigner (t )
316+
317+ cfg := config .DefaultConfig ()
318+ gen := genesis.Genesis {ChainID : "tchain" , InitialHeight : 1 , StartTime : time .Now ().Add (- time .Second ), ProposerAddress : expectedAddr }
319+
320+ mockExec := testmocks .NewMockExecutor (t )
321+ mockExec .EXPECT ().InitChain (mock .Anything , mock .Anything , uint64 (1 ), "tchain" ).Return ([]byte ("app0" ), nil ).Once ()
322+
323+ mockHeaderStore := extmocks.NewMockStore [* types.P2PSignedHeader ](t )
324+ mockHeaderStore .EXPECT ().Height ().Return (uint64 (0 )).Maybe ()
325+ mockDataStore := extmocks.NewMockStore [* types.P2PData ](t )
326+ mockDataStore .EXPECT ().Height ().Return (uint64 (0 )).Maybe ()
327+
328+ errChan := make (chan error , 1 )
329+ s := NewSyncer (
330+ st ,
331+ mockExec ,
332+ nil ,
333+ cm ,
334+ common .NopMetrics (),
335+ cfg ,
336+ gen ,
337+ mockHeaderStore ,
338+ mockDataStore ,
339+ zerolog .Nop (),
340+ common .DefaultBlockOptions (),
341+ errChan ,
342+ nil ,
343+ )
344+
345+ require .NoError (t , s .initializeState ())
346+ s .ctx = t .Context ()
347+
348+ lastState := s .getLastState ()
349+ data := makeData (gen .ChainID , 1 , 0 )
350+ _ , hdr := makeSignedHeaderBytes (t , gen .ChainID , 1 , wrongAddr , wrongPub , wrongSigner , lastState .AppHash , data , nil )
351+
352+ evt := common.DAHeightEvent {Header : hdr , Data : data , Source : common .SourceDA , DaHeight : 1 }
353+ s .processHeightEvent (t .Context (), & evt )
354+
355+ requireEmptyChan (t , errChan )
356+ assert .False (t , s .hasCriticalError .Load (), "unexpected proposer from DA should be treated as an invalid external block" )
357+
358+ h , err := st .Height (t .Context ())
359+ require .NoError (t , err )
360+ assert .Equal (t , uint64 (0 ), h )
361+ }
362+
307363func TestSequentialBlockSync (t * testing.T ) {
308364 ds := dssync .MutexWrap (datastore .NewMapDatastore ())
309365 st := store .New (ds )
0 commit comments