Skip to content

Commit

Permalink
fix backfilling UX
Browse files Browse the repository at this point in the history
  • Loading branch information
aarshkshah1992 committed Oct 21, 2024
1 parent 70aaef4 commit 2656b44
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
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())
}
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

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

0 comments on commit 2656b44

Please sign in to comment.