From 4dbdd1e64dcad6a1e74e99b9a947e926244fc167 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) --- cmd/lotus-sim/simulation/block.go | 2 +- cmd/lotus-sim/simulation/messages.go | 6 +++--- cmd/lotus-sim/simulation/node.go | 4 ++-- cmd/lotus-sim/simulation/simulation.go | 20 ++++++++++---------- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/cmd/lotus-sim/simulation/block.go b/cmd/lotus-sim/simulation/block.go index 47d482f4e55..7f3a9719bac 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 08e4c12d21a..884e6e803a7 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/node.go b/cmd/lotus-sim/simulation/node.go index acd63955d9f..8ba2298f8fc 100644 --- a/cmd/lotus-sim/simulation/node.go +++ b/cmd/lotus-sim/simulation/node.go @@ -82,7 +82,7 @@ func (nd *Node) LoadSim(ctx context.Context, name string) (*Simulation, error) { return nil, err } sim := &Simulation{ - Node: nd, + node: nd, name: name, stages: stages, } @@ -126,7 +126,7 @@ func (nd *Node) CreateSim(ctx context.Context, name string, head *types.TipSet) } sim := &Simulation{ name: name, - Node: nd, + node: nd, StateManager: stmgr.NewStateManager(nd.Chainstore), stages: stages, } diff --git a/cmd/lotus-sim/simulation/simulation.go b/cmd/lotus-sim/simulation/simulation.go index c75be3261fd..c77d7375c0e 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 }