From 0b06de2bd3524bcdfff3a84d8dd628e666ad5bfc Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 21 Jun 2021 11:41:06 -0700 Subject: [PATCH] fix(lotus-sim): unembed Node from Simulation I wanted to expose the node's _fields_, but this also exposed the methods. That got rather confusing. (probably could have used a new type, but eh) foo --- cmd/lotus-sim/info.go | 2 +- cmd/lotus-sim/info_capacity.go | 2 +- cmd/lotus-sim/info_state.go | 2 +- cmd/lotus-sim/simulation/block.go | 2 +- cmd/lotus-sim/simulation/messages.go | 6 +++--- cmd/lotus-sim/simulation/simulation.go | 20 ++++++++++---------- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/cmd/lotus-sim/info.go b/cmd/lotus-sim/info.go index 759f2d815..864adb3bc 100644 --- a/cmd/lotus-sim/info.go +++ b/cmd/lotus-sim/info.go @@ -42,7 +42,7 @@ func printInfo(ctx context.Context, sim *simulation.Simulation, out io.Writer) e if powerLookbackEpoch < start.Height() { powerLookbackEpoch = start.Height() } - lookbackTs, err := sim.Chainstore.GetTipsetByHeight(ctx, powerLookbackEpoch, head, false) + lookbackTs, err := sim.Node.Chainstore.GetTipsetByHeight(ctx, powerLookbackEpoch, head, false) if err != nil { return err } diff --git a/cmd/lotus-sim/info_capacity.go b/cmd/lotus-sim/info_capacity.go index 8ba603c20..4372ee34a 100644 --- a/cmd/lotus-sim/info_capacity.go +++ b/cmd/lotus-sim/info_capacity.go @@ -39,7 +39,7 @@ var infoCapacityGrowthSimCommand = &cli.Command{ lastHeight := ts.Height() for ts.Height() > firstEpoch && cctx.Err() == nil { - ts, err = sim.Chainstore.LoadTipSet(ts.Parents()) + ts, err = sim.Node.Chainstore.LoadTipSet(ts.Parents()) if err != nil { return err } diff --git a/cmd/lotus-sim/info_state.go b/cmd/lotus-sim/info_state.go index 19a31e19f..5c9541513 100644 --- a/cmd/lotus-sim/info_state.go +++ b/cmd/lotus-sim/info_state.go @@ -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.Chainstore.LoadTipSet(ts.Parents()) + ts, err = sim.Node.Chainstore.LoadTipSet(ts.Parents()) if err != nil { return err } diff --git a/cmd/lotus-sim/simulation/block.go b/cmd/lotus-sim/simulation/block.go index 47d482f4e..93e6a3191 100644 --- a/cmd/lotus-sim/simulation/block.go +++ b/cmd/lotus-sim/simulation/block.go @@ -73,7 +73,7 @@ func (sim *Simulation) makeTipSet(ctx context.Context, messages []*types.Message Timestamp: uts, ElectionProof: &types.ElectionProof{WinCount: 1}, }} - err = sim.Chainstore.PersistBlockHeaders(blks...) + err = sim.Node.Chainstore.PersistBlockHeaders(blks...) if err != nil { return nil, xerrors.Errorf("failed to persist block headers: %w", err) } diff --git a/cmd/lotus-sim/simulation/messages.go b/cmd/lotus-sim/simulation/messages.go index 08e4c12d2..5bed27436 100644 --- a/cmd/lotus-sim/simulation/messages.go +++ b/cmd/lotus-sim/simulation/messages.go @@ -25,19 +25,19 @@ func toArray(store blockadt.Store, cids []cid.Cid) (cid.Cid, error) { // storeMessages packs a set of messages into a types.MsgMeta and returns the resulting CID. The // resulting CID is valid for the BlocKHeader's Messages field. -func (nd *Node) storeMessages(ctx context.Context, messages []*types.Message) (cid.Cid, error) { +func (sim *Simulation) storeMessages(ctx context.Context, messages []*types.Message) (cid.Cid, error) { // We store all messages as "bls" messages so they're executed in-order. This ensures // accurate gas accounting. It also ensures we don't, e.g., try to fund a miner after we // fail a pre-commit... var msgCids []cid.Cid for _, msg := range messages { - c, err := nd.Chainstore.PutMessage(msg) + c, err := sim.Node.Chainstore.PutMessage(msg) if err != nil { return cid.Undef, err } msgCids = append(msgCids, c) } - adtStore := nd.Chainstore.ActorStore(ctx) + adtStore := sim.Node.Chainstore.ActorStore(ctx) blsMsgArr, err := toArray(adtStore, msgCids) if err != nil { return cid.Undef, err diff --git a/cmd/lotus-sim/simulation/simulation.go b/cmd/lotus-sim/simulation/simulation.go index c75be3261..d91d30eda 100644 --- a/cmd/lotus-sim/simulation/simulation.go +++ b/cmd/lotus-sim/simulation/simulation.go @@ -71,7 +71,7 @@ func (c *config) upgradeSchedule() (stmgr.UpgradeSchedule, error) { // Simulation specifies a lotus-sim simulation. type Simulation struct { - *Node + Node *Node StateManager *stmgr.StateManager name string @@ -87,7 +87,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.MetadataDS.Get(sim.key("config")) + configBytes, err := sim.Node.MetadataDS.Get(sim.key("config")) if err == nil { err = json.Unmarshal(configBytes, &sim.config) } @@ -108,7 +108,7 @@ func (sim *Simulation) saveConfig() error { if err != nil { return err } - return sim.MetadataDS.Put(sim.key("config"), buf) + return sim.Node.MetadataDS.Put(sim.key("config"), buf) } var simulationPrefix = datastore.NewKey("/simulation") @@ -121,7 +121,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.MetadataDS.Get(sim.key(name)) + tskBytes, err := sim.Node.MetadataDS.Get(sim.key(name)) if err != nil { return nil, xerrors.Errorf("failed to load tipset %s/%s: %w", sim.name, name, err) } @@ -129,7 +129,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.Chainstore.LoadTipSet(tsk) + ts, err := sim.Node.Chainstore.LoadTipSet(tsk) if err != nil { return nil, xerrors.Errorf("failed to load tipset %s (%s/%s): %w", tsk, sim.name, name, err) } @@ -138,7 +138,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.MetadataDS.Put(sim.key(name), ts.Key().Bytes()); err != nil { + if err := sim.Node.MetadataDS.Put(sim.key(name), ts.Key().Bytes()); err != nil { return xerrors.Errorf("failed to store tipset (%s/%s): %w", sim.name, name, err) } return nil @@ -198,7 +198,7 @@ func (sim *Simulation) SetUpgradeHeight(nv network.Version, epoch abi.ChainEpoch if err != nil { return err } - sm, err := stmgr.NewStateManagerWithUpgradeSchedule(sim.Chainstore, newUpgradeSchedule) + sm, err := stmgr.NewStateManagerWithUpgradeSchedule(sim.Node.Chainstore, newUpgradeSchedule) if err != nil { return err } @@ -241,7 +241,7 @@ func (sim *Simulation) Walk( stCid cid.Cid, messages []*AppliedMessage) error, ) error { - store := sim.Chainstore.ActorStore(ctx) + store := sim.Node.Chainstore.ActorStore(ctx) minEpoch := sim.start.Height() if lookback != 0 { minEpoch = sim.head.Height() - abi.ChainEpoch(lookback) @@ -305,7 +305,7 @@ func (sim *Simulation) Walk( stCid = ts.MinTicketBlock().ParentStateRoot recCid = ts.MinTicketBlock().ParentMessageReceipts - ts, err = sim.Chainstore.LoadTipSet(ts.Parents()) + ts, err = sim.Node.Chainstore.LoadTipSet(ts.Parents()) if err != nil { return xerrors.Errorf("loading parent: %w", err) } @@ -339,7 +339,7 @@ func (sim *Simulation) Walk( break } - msgs, err := sim.Chainstore.MessagesForTipset(job.ts) + msgs, err := sim.Node.Chainstore.MessagesForTipset(job.ts) if err != nil { return err }