Skip to content

Commit

Permalink
fix(lotus-sim): unembed Node from Simulation
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
Stebalien committed Jun 21, 2021
1 parent b7c36bc commit 4dbdd1e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion cmd/lotus-sim/simulation/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/lotus-sim/simulation/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cmd/lotus-sim/simulation/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
}
Expand Down
20 changes: 10 additions & 10 deletions cmd/lotus-sim/simulation/simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
Expand All @@ -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")
Expand All @@ -121,15 +121,15 @@ 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)
}
tsk, err := types.TipSetKeyFromBytes(tskBytes)
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)
}
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 4dbdd1e

Please sign in to comment.