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 1 commit
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", ts.Height())
aarshkshah1992 marked this conversation as resolved.
Show resolved Hide resolved
}
return nil, xerrors.Errorf("failed to backfill tipset at epoch %d; err: %w", ts.Height(), err)
}

indexedData, err := si.getIndexedTipSetData(ctx, ts)
Expand Down
15 changes: 13 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,10 @@ 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
haltNoData := false
haltHeight := -1
Copy link
Member

Choose a reason for hiding this comment

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

we could just use haltHeight as the signal without haltNoData by checking for -1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


for epoch := fromEpoch; epoch >= toEpoch; epoch-- {
if ctx.Err() != nil {
return ctx.Err()
Expand All @@ -153,6 +156,12 @@ 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
haltNoData = true
break
}

_, _ = fmt.Fprintf(cctx.App.Writer, "%s ✗ Epoch %d; failure: %s\n", currentTimeString(), epoch, err)
failedRPCs++
continue
Expand Down Expand Up @@ -190,7 +199,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 haltNoData {
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