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

Use main logger in handler and fetcher. #1077

Merged
merged 1 commit into from
Jun 29, 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: 6 additions & 8 deletions processor/blockprocessor/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func InitializeLedgerSimple(ctx context.Context, logger *log.Logger, round uint6
return fmt.Errorf("InitializeLedgerSimple() err: indexer data directory missing")
}
// create algod client
bot, err = getFetcher(opts)
bot, err = getFetcher(logger, opts)
if err != nil {
return fmt.Errorf("InitializeLedgerSimple() err: %w", err)
}
Expand All @@ -52,7 +52,7 @@ func InitializeLedgerSimple(ctx context.Context, logger *log.Logger, round uint6
return nil
}
bot.SetNextRound(proc.NextRoundToProcess())
handler := blockHandler(round, proc, cf, 1*time.Second)
handler := blockHandler(logger, round, proc, cf, 1*time.Second)
bot.SetBlockHandler(handler)

logger.Info("Starting ledger migration.")
Expand Down Expand Up @@ -156,10 +156,10 @@ func InitializeLedgerFastCatchup(ctx context.Context, logger *log.Logger, catchp

// blockHandler creates a handler complying to the fetcher block handler interface. In case of a failure it keeps
// attempting to add the block until the fetcher shuts down.
func blockHandler(dbRound uint64, proc processor.Processor, cancel context.CancelFunc, retryDelay time.Duration) func(context.Context, *rpcs.EncodedBlockCert) error {
func blockHandler(logger *log.Logger, dbRound uint64, proc processor.Processor, cancel context.CancelFunc, retryDelay time.Duration) func(context.Context, *rpcs.EncodedBlockCert) error {
return func(ctx context.Context, block *rpcs.EncodedBlockCert) error {
for {
err := handleBlock(block, proc)
err := handleBlock(logger, block, proc)
if err == nil {
if uint64(block.Block.Round()) == dbRound {
// migration completes
Expand All @@ -180,8 +180,7 @@ func blockHandler(dbRound uint64, proc processor.Processor, cancel context.Cance
}
}

func handleBlock(block *rpcs.EncodedBlockCert, proc processor.Processor) error {
logger := log.New()
func handleBlock(logger *log.Logger, block *rpcs.EncodedBlockCert, proc processor.Processor) error {
err := proc.Process(block)
if err != nil {
logger.WithError(err).Errorf(
Expand All @@ -205,8 +204,7 @@ func getGenesis(client *algod.Client) (bookkeeping.Genesis, error) {

return res, nil
}
func getFetcher(opts *idb.IndexerDbOptions) (fetcher.Fetcher, error) {
logger := log.New()
func getFetcher(logger *log.Logger, opts *idb.IndexerDbOptions) (fetcher.Fetcher, error) {
var err error
var bot fetcher.Fetcher
if opts.AlgodDataDir != "" {
Expand Down
7 changes: 3 additions & 4 deletions processor/blockprocessor/initialize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"testing"

"github.com/jarcoal/httpmock"
"github.com/sirupsen/logrus"
test2 "github.com/sirupsen/logrus/hooks/test"
"github.com/stretchr/testify/assert"

Expand Down Expand Up @@ -65,17 +64,17 @@ func TestRunMigration(t *testing.T) {
}

// migrate 3 rounds
err = InitializeLedgerSimple(context.Background(), logrus.New(), 3, &opts)
assert.NoError(t, err)
log, _ := test2.NewNullLogger()
err = InitializeLedgerSimple(context.Background(), log, 3, &opts)
assert.NoError(t, err)
l, err := util.MakeLedger(log, false, &genesis, opts.IndexerDatadir)
assert.NoError(t, err)
// check 3 rounds written to ledger
assert.Equal(t, uint64(3), uint64(l.Latest()))
l.Close()

// migration continues from last round
err = InitializeLedgerSimple(context.Background(), logrus.New(), 6, &opts)
err = InitializeLedgerSimple(context.Background(), log, 6, &opts)
assert.NoError(t, err)

l, err = util.MakeLedger(log, false, &genesis, opts.IndexerDatadir)
Expand Down