Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

catchup: Fix empty cert if ledger already has a block #5846

Merged
merged 4 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@
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 { ^
algorandskiy marked this conversation as resolved.
Show resolved Hide resolved
blk = &ledgerBlock
cert = &ledgerCert
}
var protoParams config.ConsensusParams
var ok bool
Expand Down Expand Up @@ -552,8 +553,9 @@

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) {
jannotti marked this conversation as resolved.
Show resolved Hide resolved
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)
jannotti marked this conversation as resolved.
Show resolved Hide resolved
GenesisHash() crypto.Digest
BlockHdr(rnd basics.Round) (blk bookkeeping.BlockHeader, err error)
Latest() (rnd basics.Round)
Expand Down