From c54901e634c9744dc36c1e227d922f2089b37884 Mon Sep 17 00:00:00 2001 From: Pavel Zbitskiy Date: Mon, 27 Nov 2023 13:47:46 -0500 Subject: [PATCH] catchup: Fix empty cert if ledger already has a block --- catchup/catchpointService.go | 6 ++++-- catchup/catchpointService_test.go | 8 +++++--- ledger/catchupaccessor.go | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/catchup/catchpointService.go b/catchup/catchpointService.go index a5175aff4c..e9b91266d6 100644 --- a/catchup/catchpointService.go +++ b/catchup/catchpointService.go @@ -373,8 +373,9 @@ func (cs *CatchpointCatchupService) processStageLatestBlockDownload() (err error var blk *bookkeeping.Block var cert *agreement.Certificate // check to see if the current ledger might have this block. If so, we should try this first instead of downloading anything. - if ledgerBlock, err := cs.ledger.Block(blockRound); err == nil { + if ledgerBlock, ledgerCert, err := cs.ledger.BlockCert(blockRound); err == nil { blk = &ledgerBlock + cert = &ledgerCert } var protoParams config.ConsensusParams var ok bool @@ -552,8 +553,9 @@ func (cs *CatchpointCatchupService) processStageBlocksDownload() (err error) { blk = nil // check to see if the current ledger might have this block. If so, we should try this first instead of downloading anything. - if ledgerBlock, err := cs.ledger.Block(topBlock.Round() - basics.Round(blocksFetched)); err == nil { + if ledgerBlock, ledgerCert, err := cs.ledger.BlockCert(topBlock.Round() - basics.Round(blocksFetched)); err == nil { blk = &ledgerBlock + cert = &ledgerCert } else { switch err.(type) { case ledgercore.ErrNoEntry: diff --git a/catchup/catchpointService_test.go b/catchup/catchpointService_test.go index 48cea110d7..dd8e469163 100644 --- a/catchup/catchpointService_test.go +++ b/catchup/catchpointService_test.go @@ -22,6 +22,7 @@ import ( "github.com/stretchr/testify/require" + "github.com/algorand/go-algorand/agreement" "github.com/algorand/go-algorand/components/mocks" "github.com/algorand/go-algorand/crypto" "github.com/algorand/go-algorand/data/basics" @@ -35,7 +36,7 @@ import ( type catchpointCatchupLedger struct { } -func (l *catchpointCatchupLedger) Block(rnd basics.Round) (blk bookkeeping.Block, err error) { +func (l *catchpointCatchupLedger) BlockCert(rnd basics.Round) (blk bookkeeping.Block, cert agreement.Certificate, err error) { blk = bookkeeping.Block{ BlockHeader: bookkeeping.BlockHeader{ UpgradeState: bookkeeping.UpgradeState{ @@ -43,13 +44,14 @@ func (l *catchpointCatchupLedger) Block(rnd basics.Round) (blk bookkeeping.Block }, }, } + cert = agreement.Certificate{} commitments, err := blk.PaysetCommit() if err != nil { - return blk, err + return blk, cert, err } blk.TxnCommitments = commitments - return blk, nil + return blk, cert, nil } func (l *catchpointCatchupLedger) GenesisHash() (d crypto.Digest) { diff --git a/ledger/catchupaccessor.go b/ledger/catchupaccessor.go index 64ada07a08..3661c60057 100644 --- a/ledger/catchupaccessor.go +++ b/ledger/catchupaccessor.go @@ -238,7 +238,7 @@ const ( // CatchupAccessorClientLedger represents ledger interface needed for catchpoint accessor clients type CatchupAccessorClientLedger interface { - Block(rnd basics.Round) (blk bookkeeping.Block, err error) + BlockCert(rnd basics.Round) (blk bookkeeping.Block, cert agreement.Certificate, err error) GenesisHash() crypto.Digest BlockHdr(rnd basics.Round) (blk bookkeeping.BlockHeader, err error) Latest() (rnd basics.Round)