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

local ledger fixes #1042

Merged
merged 1 commit into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions cmd/algorand-indexer/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"time"

"github.com/algorand/go-algorand/data/bookkeeping"
"github.com/algorand/go-algorand/ledger/ledgercore"
"github.com/algorand/go-algorand/logging"
"github.com/algorand/go-algorand/protocol"
"github.com/algorand/go-algorand/rpcs"
Expand Down Expand Up @@ -240,8 +241,17 @@ var daemonCmd = &cobra.Command{
maybeFail(err, "Error getting DB round")
if nextDBRound > 0 {
if catchpoint != "" {
err = localledger.RunMigrationFastCatchup(logging.NewLogger(), catchpoint, &opts)
maybeFail(err, "Error running ledger migration in fast catchup mode")
round, _, err := ledgercore.ParseCatchpointLabel(catchpoint)
if err != nil {
maybeFail(err, "catchpoint error")
}
if uint64(round) >= nextDBRound {
logger.Warnf("round for given catchpoint is ahead of db round. skip fast catchup")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: They technically could be equal here since it's not strictly greater than.

} else {
err = localledger.RunMigrationFastCatchup(logging.NewLogger(), catchpoint, &opts)
maybeFail(err, "Error running ledger migration in fast catchup mode")
}

}
err = localledger.RunMigrationSimple(nextDBRound-1, &opts)
maybeFail(err, "Error running ledger migration")
Expand Down
4 changes: 4 additions & 0 deletions migrations/local_ledger/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ func RunMigrationSimple(round uint64, opts *idb.IndexerDbOptions) error {
if err != nil {
return fmt.Errorf("RunMigration() err: %w", err)
}
// ledger and db states are in sync
if proc.NextRoundToProcess()-1 == round {
return nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: You can just return err here since it should be nil if we haven't errored out already.

}
bot.SetNextRound(proc.NextRoundToProcess())
handler := blockHandler(round, proc, cf, 1*time.Second)
bot.SetBlockHandler(handler)
Expand Down
7 changes: 3 additions & 4 deletions migrations/local_ledger/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package localledger
import (
"fmt"
"os"
"path"
"path/filepath"
"testing"

Expand Down Expand Up @@ -59,7 +58,7 @@ func TestRunMigration(t *testing.T) {
dname, err := os.MkdirTemp("", "indexer")
defer os.RemoveAll(dname)
opts := idb.IndexerDbOptions{
IndexerDatadir: dname + "/",
IndexerDatadir: dname,
AlgodAddr: "localhost",
AlgodToken: "AAAAA",
}
Expand All @@ -69,7 +68,7 @@ func TestRunMigration(t *testing.T) {
assert.NoError(t, err)
initState, err := util.CreateInitState(&genesis)
assert.NoError(t, err)
l, err := ledger.OpenLedger(logging.NewLogger(), filepath.Join(path.Dir(opts.IndexerDatadir), "ledger"), false, initState, algodConfig.GetDefaultLocal())
l, err := ledger.OpenLedger(logging.NewLogger(), filepath.Join(opts.IndexerDatadir, "ledger"), false, initState, algodConfig.GetDefaultLocal())
assert.NoError(t, err)
// check 3 rounds written to ledger
assert.Equal(t, uint64(3), uint64(l.Latest()))
Expand All @@ -79,7 +78,7 @@ func TestRunMigration(t *testing.T) {
err = RunMigrationSimple(6, &opts)
assert.NoError(t, err)

l, err = ledger.OpenLedger(logging.NewLogger(), filepath.Join(path.Dir(opts.IndexerDatadir), "ledger"), false, initState, algodConfig.GetDefaultLocal())
l, err = ledger.OpenLedger(logging.NewLogger(), filepath.Join(opts.IndexerDatadir, "ledger"), false, initState, algodConfig.GetDefaultLocal())
assert.NoError(t, err)
assert.Equal(t, uint64(6), uint64(l.Latest()))
l.Close()
Expand Down
3 changes: 1 addition & 2 deletions processor/blockprocessor/block_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package blockprocessor

import (
"fmt"
"path"
"path/filepath"

"github.com/algorand/go-algorand/config"
Expand Down Expand Up @@ -45,7 +44,7 @@ func MakeProcessor(genesis *bookkeeping.Genesis, dbRound uint64, datadir string,
if err != nil {
return nil, fmt.Errorf("MakeProcessor() err: %w", err)
}
l, err := ledger.OpenLedger(logging.NewLogger(), filepath.Join(path.Dir(datadir), prefix), false, initState, algodConfig.GetDefaultLocal())
l, err := ledger.OpenLedger(logging.NewLogger(), filepath.Join(datadir, prefix), false, initState, algodConfig.GetDefaultLocal())
if err != nil {
return nil, fmt.Errorf("MakeProcessor() err: %w", err)
}
Expand Down