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

fix(chainindexer): backfilling should halt when chain state data is missing and not backfill parents #12619

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
22 changes: 6 additions & 16 deletions chain/index/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"

"github.com/ipfs/go-cid"
ipld "github.com/ipfs/go-ipld-format"
"golang.org/x/xerrors"

"github.com/filecoin-project/go-state-types/abi"
Expand Down Expand Up @@ -285,33 +286,22 @@ func (si *SqliteIndexer) verifyIndexedData(ctx context.Context, ts *types.TipSet
}

func (si *SqliteIndexer) backfillMissingTipset(ctx context.Context, ts *types.TipSet) (*types.IndexValidation, error) {
// backfill the tipset in the Index
parentTs, err := si.cs.GetTipSetFromKey(ctx, ts.Parents())
if err != nil {
return nil, xerrors.Errorf("failed to get parent tipset at height %d: %w", ts.Height(), err)
}

executionTs, err := si.getNextTipset(ctx, ts)
if err != nil {
return nil, xerrors.Errorf("failed to get next tipset at height %d: %w", ts.Height(), err)
}

backfillFunc := func() error {
return withTx(ctx, si.db, func(tx *sql.Tx) error {
if err := si.indexTipsetWithParentEvents(ctx, tx, ts, executionTs); err != nil {
return xerrors.Errorf("error indexing (ts, executionTs): %w", err)
}

if err := si.indexTipsetWithParentEvents(ctx, tx, parentTs, ts); err != nil {
return xerrors.Errorf("error indexing (parentTs, ts): %w", err)
}

return nil
return si.indexTipsetWithParentEvents(ctx, tx, ts, executionTs)
})
}

if err := backfillFunc(); err != nil {
return nil, xerrors.Errorf("failed to backfill tipset: %w", err)
if ipld.IsNotFound(err) {
return nil, xerrors.Errorf("failed to backfill tipset at epoch %d: chain store does not contain data: %w", ts.Height(), err)
}
return nil, xerrors.Errorf("failed to backfill tipset at epoch %d; err: %w", ts.Height(), err)
}

indexedData, err := si.getIndexedTipSetData(ctx, ts)
Expand Down
13 changes: 11 additions & 2 deletions cmd/lotus-shed/chain_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"encoding/json"
"fmt"
"strings"
"time"

"github.com/urfave/cli/v2"
Expand Down Expand Up @@ -135,8 +136,9 @@ number of failed RPC calls. Otherwise, it will exit with a zero status.
_, _ = fmt.Fprintf(cctx.App.Writer, "%s starting chainindex validation; from epoch: %d; to epoch: %d; backfill: %t; log-good: %t\n", currentTimeString(),
fromEpoch, toEpoch, backfill, logGood)
}

totalEpochs := fromEpoch - toEpoch + 1
haltHeight := -1

for epoch := fromEpoch; epoch >= toEpoch; epoch-- {
if ctx.Err() != nil {
return ctx.Err()
Expand All @@ -153,6 +155,11 @@ number of failed RPC calls. Otherwise, it will exit with a zero status.

indexValidateResp, err := api.ChainValidateIndex(ctx, abi.ChainEpoch(epoch), backfill)
if err != nil {
if strings.Contains(err.Error(), "chain store does not contain data") {
haltHeight = epoch
break
}

_, _ = fmt.Fprintf(cctx.App.Writer, "%s ✗ Epoch %d; failure: %s\n", currentTimeString(), epoch, err)
failedRPCs++
continue
Expand Down Expand Up @@ -190,7 +197,9 @@ number of failed RPC calls. Otherwise, it will exit with a zero status.
_, _ = fmt.Fprintf(cctx.App.Writer, "Total successful Null round validations: %d\n", successfulNullRounds)
}

if failedRPCs > 0 {
if haltHeight >= 0 {
return fmt.Errorf("chain index validation and backfilled halted at height %d as chain state does contain data for that height", haltHeight)
} else if failedRPCs > 0 {
return fmt.Errorf("chain index validation failed with %d RPC errors", failedRPCs)
}

Expand Down
Loading