Skip to content

Commit

Permalink
fix: certificate on local DB but AggLayer have none certificate (CDK-…
Browse files Browse the repository at this point in the history
…604)
  • Loading branch information
joanestebanr committed Nov 25, 2024
1 parent 2729a27 commit 4ae00e5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions aggsender/aggsender.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 13 additions & 0 deletions aggsender/aggsender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4ae00e5

Please sign in to comment.