Skip to content

Commit

Permalink
catchup: Fix empty cert if ledger already has a block
Browse files Browse the repository at this point in the history
  • Loading branch information
algorandskiy committed Nov 27, 2023
1 parent 3abe5c8 commit c54901e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
6 changes: 4 additions & 2 deletions catchup/catchpointService.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Check failure on line 376 in catchup/catchpointService.go

View workflow job for this annotation

GitHub Actions / reviewdog-errors

[Lint Errors] reported by reviewdog 🐶 shadow: declaration of "err" shadows declaration at line 366 (govet) Raw Output: catchup/catchpointService.go:376:30: shadow: declaration of "err" shadows declaration at line 366 (govet) if ledgerBlock, ledgerCert, err := cs.ledger.BlockCert(blockRound); err == nil { ^
blk = &ledgerBlock
cert = &ledgerCert
}
var protoParams config.ConsensusParams
var ok bool
Expand Down Expand Up @@ -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 {

Check failure on line 556 in catchup/catchpointService.go

View workflow job for this annotation

GitHub Actions / reviewdog-errors

[Lint Errors] reported by reviewdog 🐶 shadow: declaration of "err" shadows declaration at line 510 (govet) Raw Output: catchup/catchpointService.go:556:31: shadow: declaration of "err" shadows declaration at line 510 (govet) if ledgerBlock, ledgerCert, err := cs.ledger.BlockCert(topBlock.Round() - basics.Round(blocksFetched)); err == nil { ^

Check warning on line 556 in catchup/catchpointService.go

View check run for this annotation

Codecov / codecov/patch

catchup/catchpointService.go#L556

Added line #L556 was not covered by tests
blk = &ledgerBlock
cert = &ledgerCert

Check warning on line 558 in catchup/catchpointService.go

View check run for this annotation

Codecov / codecov/patch

catchup/catchpointService.go#L558

Added line #L558 was not covered by tests
} else {
switch err.(type) {
case ledgercore.ErrNoEntry:
Expand Down
8 changes: 5 additions & 3 deletions catchup/catchpointService_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -35,21 +36,22 @@ 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{
CurrentProtocol: protocol.ConsensusCurrentVersion,
},
},
}
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) {
Expand Down
2 changes: 1 addition & 1 deletion ledger/catchupaccessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c54901e

Please sign in to comment.