chainstore: new ForceHeadSilent to support benchmarks.
This commit is contained in:
parent
fd1439f284
commit
370ef93db6
@ -44,10 +44,10 @@ import (
|
|||||||
"github.com/ipfs/go-datastore/query"
|
"github.com/ipfs/go-datastore/query"
|
||||||
cbor "github.com/ipfs/go-ipld-cbor"
|
cbor "github.com/ipfs/go-ipld-cbor"
|
||||||
logging "github.com/ipfs/go-log/v2"
|
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"
|
carutil "github.com/ipld/go-car/util"
|
||||||
cbg "github.com/whyrusleeping/cbor-gen"
|
cbg "github.com/whyrusleeping/cbor-gen"
|
||||||
pubsub "github.com/whyrusleeping/pubsub"
|
"github.com/whyrusleeping/pubsub"
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -362,6 +362,26 @@ func (cs *ChainStore) MaybeTakeHeavierTipSet(ctx context.Context, ts *types.TipS
|
|||||||
return nil
|
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 {
|
type reorg struct {
|
||||||
old *types.TipSet
|
old *types.TipSet
|
||||||
new *types.TipSet
|
new *types.TipSet
|
||||||
|
@ -424,7 +424,8 @@ var importBenchCmd = &cli.Command{
|
|||||||
|
|
||||||
if start != nil {
|
if start != nil {
|
||||||
startEpoch = start.Height()
|
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
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user