plumb contexts in lotus-sim

This commit is contained in:
vyzo 2021-12-13 15:15:38 +02:00 committed by Jennifer Wang
parent 16a37036b5
commit fa7fa8c199
6 changed files with 18 additions and 18 deletions

View File

@ -26,7 +26,7 @@ var createSimCommand = &cli.Command{
var ts *types.TipSet
switch cctx.NArg() {
case 0:
if err := node.Chainstore.Load(); err != nil {
if err := node.Chainstore.Load(cctx.Context); err != nil {
return err
}
ts = node.Chainstore.GetHeaviestTipSet()
@ -36,7 +36,7 @@ var createSimCommand = &cli.Command{
return err
}
tsk := types.NewTipSetKey(cids...)
ts, err = node.Chainstore.LoadTipSet(tsk)
ts, err = node.Chainstore.LoadTipSet(cctx.Context, tsk)
if err != nil {
return err
}

View File

@ -39,7 +39,7 @@ var infoCapacityGrowthSimCommand = &cli.Command{
lastHeight := ts.Height()
for ts.Height() > firstEpoch && cctx.Err() == nil {
ts, err = sim.Node.Chainstore.LoadTipSet(ts.Parents())
ts, err = sim.Node.Chainstore.LoadTipSet(cctx.Context, ts.Parents())
if err != nil {
return err
}

View File

@ -60,7 +60,7 @@ var infoStateGrowthSimCommand = &cli.Command{
var links []cid.Cid
var totalSize uint64
if err := store.View(c, func(data []byte) error {
if err := store.View(cctx.Context, c, func(data []byte) error {
totalSize += uint64(len(data))
return cbg.ScanForLinks(bytes.NewReader(data), func(c cid.Cid) {
if c.Prefix().Codec != cid.DagCBOR {
@ -131,7 +131,7 @@ var infoStateGrowthSimCommand = &cli.Command{
fmt.Fprintf(cctx.App.Writer, "%d: %s\n", ts.Height(), types.SizeStr(types.NewInt(parentStateSize)))
}
ts, err = sim.Node.Chainstore.LoadTipSet(ts.Parents())
ts, err = sim.Node.Chainstore.LoadTipSet(cctx.Context, ts.Parents())
if err != nil {
return err
}

View File

@ -73,7 +73,7 @@ func (sim *Simulation) makeTipSet(ctx context.Context, messages []*types.Message
Timestamp: uts,
ElectionProof: &types.ElectionProof{WinCount: 1},
}}
err = sim.Node.Chainstore.PersistBlockHeaders(blks...)
err = sim.Node.Chainstore.PersistBlockHeaders(ctx, blks...)
if err != nil {
return nil, xerrors.Errorf("failed to persist block headers: %w", err)
}

View File

@ -135,7 +135,7 @@ func (nd *Node) CreateSim(ctx context.Context, name string, head *types.TipSet)
StateManager: sm,
stages: stages,
}
if has, err := nd.MetadataDS.Has(sim.key("head")); err != nil {
if has, err := nd.MetadataDS.Has(ctx, sim.key("head")); err != nil {
return nil, err
} else if has {
return nil, xerrors.Errorf("simulation named %s already exists", name)
@ -155,7 +155,7 @@ func (nd *Node) CreateSim(ctx context.Context, name string, head *types.TipSet)
// ListSims lists all simulations.
func (nd *Node) ListSims(ctx context.Context) ([]string, error) {
prefix := simulationPrefix.ChildString("head").String()
items, err := nd.MetadataDS.Query(query.Query{
items, err := nd.MetadataDS.Query(ctx, query.Query{
Prefix: prefix,
KeysOnly: true,
Orders: []query.Order{query.OrderByKey{}},
@ -192,7 +192,7 @@ func (nd *Node) DeleteSim(ctx context.Context, name string) error {
var err error
for _, field := range simFields {
key := simulationPrefix.ChildString(field).ChildString(name)
err = multierr.Append(err, nd.MetadataDS.Delete(key))
err = multierr.Append(err, nd.MetadataDS.Delete(ctx, key))
}
return err
}
@ -209,7 +209,7 @@ func (nd *Node) CopySim(ctx context.Context, oldName, newName string) error {
values := make(map[string][]byte)
for _, field := range simFields {
key := simulationPrefix.ChildString(field).ChildString(oldName)
value, err := nd.MetadataDS.Get(key)
value, err := nd.MetadataDS.Get(ctx, key)
if err == datastore.ErrNotFound {
continue
} else if err != nil {
@ -226,9 +226,9 @@ func (nd *Node) CopySim(ctx context.Context, oldName, newName string) error {
key := simulationPrefix.ChildString(field).ChildString(newName)
var err error
if value, ok := values[field]; ok {
err = nd.MetadataDS.Put(key, value)
err = nd.MetadataDS.Put(ctx, key, value)
} else {
err = nd.MetadataDS.Delete(key)
err = nd.MetadataDS.Delete(ctx, key)
}
if err != nil {
return err

View File

@ -90,7 +90,7 @@ type Simulation struct {
// loadConfig loads a simulation's config from the datastore. This must be called on startup and may
// be called to restore the config from-disk.
func (sim *Simulation) loadConfig() error {
configBytes, err := sim.Node.MetadataDS.Get(sim.key("config"))
configBytes, err := sim.Node.MetadataDS.Get(context.Background(), sim.key("config"))
if err == nil {
err = json.Unmarshal(configBytes, &sim.config)
}
@ -111,7 +111,7 @@ func (sim *Simulation) saveConfig() error {
if err != nil {
return err
}
return sim.Node.MetadataDS.Put(sim.key("config"), buf)
return sim.Node.MetadataDS.Put(context.Background(), sim.key("config"), buf)
}
var simulationPrefix = datastore.NewKey("/simulation")
@ -124,7 +124,7 @@ func (sim *Simulation) key(subkey string) datastore.Key {
// loadNamedTipSet the tipset with the given name (for this simulation)
func (sim *Simulation) loadNamedTipSet(name string) (*types.TipSet, error) {
tskBytes, err := sim.Node.MetadataDS.Get(sim.key(name))
tskBytes, err := sim.Node.MetadataDS.Get(context.Background(), sim.key(name))
if err != nil {
return nil, xerrors.Errorf("failed to load tipset %s/%s: %w", sim.name, name, err)
}
@ -132,7 +132,7 @@ func (sim *Simulation) loadNamedTipSet(name string) (*types.TipSet, error) {
if err != nil {
return nil, xerrors.Errorf("failed to parse tipste %v (%s/%s): %w", tskBytes, sim.name, name, err)
}
ts, err := sim.Node.Chainstore.LoadTipSet(tsk)
ts, err := sim.Node.Chainstore.LoadTipSet(context.Background(), tsk)
if err != nil {
return nil, xerrors.Errorf("failed to load tipset %s (%s/%s): %w", tsk, sim.name, name, err)
}
@ -141,7 +141,7 @@ func (sim *Simulation) loadNamedTipSet(name string) (*types.TipSet, error) {
// storeNamedTipSet stores the tipset at name (relative to the simulation).
func (sim *Simulation) storeNamedTipSet(name string, ts *types.TipSet) error {
if err := sim.Node.MetadataDS.Put(sim.key(name), ts.Key().Bytes()); err != nil {
if err := sim.Node.MetadataDS.Put(context.Background(), sim.key(name), ts.Key().Bytes()); err != nil {
return xerrors.Errorf("failed to store tipset (%s/%s): %w", sim.name, name, err)
}
return nil
@ -308,7 +308,7 @@ func (sim *Simulation) Walk(
stCid = ts.MinTicketBlock().ParentStateRoot
recCid = ts.MinTicketBlock().ParentMessageReceipts
ts, err = sim.Node.Chainstore.LoadTipSet(ts.Parents())
ts, err = sim.Node.Chainstore.LoadTipSet(ctx, ts.Parents())
if err != nil {
return xerrors.Errorf("loading parent: %w", err)
}