diff --git a/chain/store/store.go b/chain/store/store.go index 00a78500e..2787c146e 100644 --- a/chain/store/store.go +++ b/chain/store/store.go @@ -44,10 +44,10 @@ import ( "github.com/ipfs/go-datastore/query" cbor "github.com/ipfs/go-ipld-cbor" logging "github.com/ipfs/go-log/v2" - car "github.com/ipld/go-car" + "github.com/ipld/go-car" carutil "github.com/ipld/go-car/util" cbg "github.com/whyrusleeping/cbor-gen" - pubsub "github.com/whyrusleeping/pubsub" + "github.com/whyrusleeping/pubsub" "golang.org/x/xerrors" ) @@ -362,6 +362,26 @@ func (cs *ChainStore) MaybeTakeHeavierTipSet(ctx context.Context, ts *types.TipS return nil } +// ForceHeadSilent forces a chain head tipset without triggering a reorg +// operation. +// +// CAUTION: Use it only for testing, such as to teleport the chain to a +// particular tipset to carry out a benchmark, verification, etc. on a chain +// segment. +func (cs *ChainStore) ForceHeadSilent(_ context.Context, ts *types.TipSet) error { + log.Warnf("(!!!) forcing a new head silently; only use this only for testing; new head: %s", ts) + + cs.heaviestLk.Lock() + defer cs.heaviestLk.Unlock() + cs.heaviest = ts + + err := cs.writeHead(ts) + if err != nil { + err = xerrors.Errorf("failed to write chain head: %s", err) + } + return err +} + type reorg struct { old *types.TipSet new *types.TipSet diff --git a/cmd/lotus-bench/import.go b/cmd/lotus-bench/import.go index 0aa4d1c4b..742f470f8 100644 --- a/cmd/lotus-bench/import.go +++ b/cmd/lotus-bench/import.go @@ -424,7 +424,8 @@ var importBenchCmd = &cli.Command{ if start != nil { startEpoch = start.Height() - if err := cs.SetHead(start); err != nil { + if err := cs.ForceHeadSilent(context.Background(), start); err != nil { + // if err := cs.SetHead(start); err != nil { return err } }