diff --git a/aggsender/aggsender.go b/aggsender/aggsender.go index 851dd3f4..eea9f125 100644 --- a/aggsender/aggsender.go +++ b/aggsender/aggsender.go @@ -637,6 +637,11 @@ func (a *AggSender) checkLastCertificateFromAgglayer(ctx context.Context) error } return nil } + // CASE 2.1: certificate in storage but not in agglayer + // this is a non-sense, so thrown an error + if localLastCert != nil && aggLayerLastCert == nil { + return fmt.Errorf("recovery: certificate in storage but not in agglayer. Inconsistency") + } // CASE 3: aggsender stopped between sending to agglayer and storing on DB if aggLayerLastCert.Height == localLastCert.Height+1 { a.log.Infof("recovery: AggLayer have next cert (height:%d), so is a recovery case: storing cert: %s", diff --git a/aggsender/aggsender_test.go b/aggsender/aggsender_test.go index 6d84c683..9185050f 100644 --- a/aggsender/aggsender_test.go +++ b/aggsender/aggsender_test.go @@ -1717,6 +1717,19 @@ func TestCheckLastCertificateFromAgglayer_Case2NoCertLocalCertRemoteErrorStorage require.Error(t, err) } +// CASE 2.1: certificate in storage but not in agglayer +// sub case of previous one that fails to update local storage +func TestCheckLastCertificateFromAgglayer_Case2_1NoCertRemoteButCertLocal(t *testing.T) { + testData := newAggsenderTestData(t, testDataFlagMockStorage) + testData.l2syncerMock.EXPECT().OriginNetwork().Return(networkIDTest).Once() + testData.agglayerClientMock.EXPECT().GetLatestKnownCertificateHeader(networkIDTest). + Return(nil, nil).Once() + testData.storageMock.EXPECT().GetLastSentCertificate().Return(&testData.testCerts[0], nil) + err := testData.sut.checkLastCertificateFromAgglayer(testData.ctx) + + require.Error(t, err) +} + // CASE 3: AggSender and AggLayer not same certificateID. AggLayer has a new certificate func TestCheckLastCertificateFromAgglayer_Case3Mismatch(t *testing.T) { testData := newAggsenderTestData(t, testDataFlagMockStorage)