feat(lotus-sim): expose StateManager from Simulation
This commit is contained in:
parent
0faacbe154
commit
5f6733fe44
@ -47,7 +47,7 @@ func (sim *Simulation) nextTicket() *types.Ticket {
|
|||||||
// This method does _not_ mutate local state (although it does add blocks to the datastore).
|
// This method does _not_ mutate local state (although it does add blocks to the datastore).
|
||||||
func (sim *Simulation) makeTipSet(ctx context.Context, messages []*types.Message) (*types.TipSet, error) {
|
func (sim *Simulation) makeTipSet(ctx context.Context, messages []*types.Message) (*types.TipSet, error) {
|
||||||
parentTs := sim.head
|
parentTs := sim.head
|
||||||
parentState, parentRec, err := sim.sm.TipSetState(ctx, parentTs)
|
parentState, parentRec, err := sim.StateManager.TipSetState(ctx, parentTs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("failed to compute parent tipset: %w", err)
|
return nil, xerrors.Errorf("failed to compute parent tipset: %w", err)
|
||||||
}
|
}
|
||||||
@ -80,7 +80,7 @@ func (sim *Simulation) makeTipSet(ctx context.Context, messages []*types.Message
|
|||||||
return nil, xerrors.Errorf("failed to create new tipset: %w", err)
|
return nil, xerrors.Errorf("failed to create new tipset: %w", err)
|
||||||
}
|
}
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
_, _, err = sim.sm.TipSetState(ctx, newTipSet)
|
_, _, err = sim.StateManager.TipSetState(ctx, newTipSet)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("failed to compute new tipset: %w", err)
|
return nil, xerrors.Errorf("failed to compute new tipset: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@ func (nd *Node) LoadSim(ctx context.Context, name string) (*Simulation, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("failed to create upgrade schedule for simulation %s: %w", name, err)
|
return nil, xerrors.Errorf("failed to create upgrade schedule for simulation %s: %w", name, err)
|
||||||
}
|
}
|
||||||
sim.sm, err = stmgr.NewStateManagerWithUpgradeSchedule(nd.Chainstore, us)
|
sim.StateManager, err = stmgr.NewStateManagerWithUpgradeSchedule(nd.Chainstore, us)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("failed to create state manager for simulation %s: %w", name, err)
|
return nil, xerrors.Errorf("failed to create state manager for simulation %s: %w", name, err)
|
||||||
}
|
}
|
||||||
@ -114,9 +114,9 @@ func (nd *Node) CreateSim(ctx context.Context, name string, head *types.TipSet)
|
|||||||
return nil, xerrors.Errorf("simulation name %q cannot contain a '/'", name)
|
return nil, xerrors.Errorf("simulation name %q cannot contain a '/'", name)
|
||||||
}
|
}
|
||||||
sim := &Simulation{
|
sim := &Simulation{
|
||||||
name: name,
|
name: name,
|
||||||
Node: nd,
|
Node: nd,
|
||||||
sm: stmgr.NewStateManager(nd.Chainstore),
|
StateManager: stmgr.NewStateManager(nd.Chainstore),
|
||||||
}
|
}
|
||||||
if has, err := nd.MetadataDS.Has(sim.key("head")); err != nil {
|
if has, err := nd.MetadataDS.Has(sim.key("head")); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -22,7 +22,7 @@ func (sim *Simulation) loadClaims(ctx context.Context, height abi.ChainEpoch) (m
|
|||||||
return nil, xerrors.Errorf("when projecting growth, failed to lookup lookback epoch: %w", err)
|
return nil, xerrors.Errorf("when projecting growth, failed to lookup lookback epoch: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
powerActor, err := sim.sm.LoadActor(ctx, power.Address, ts)
|
powerActor, err := sim.StateManager.LoadActor(ctx, power.Address, ts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,7 @@ func (ss *simulationState) packPreCommits(ctx context.Context, cb packFunc) (ful
|
|||||||
func (ss *simulationState) packPreCommitsMiner(ctx context.Context, cb packFunc, minerAddr address.Address, count int) (int, bool, error) {
|
func (ss *simulationState) packPreCommitsMiner(ctx context.Context, cb packFunc, minerAddr address.Address, count int) (int, bool, error) {
|
||||||
// Load everything.
|
// Load everything.
|
||||||
epoch := ss.nextEpoch()
|
epoch := ss.nextEpoch()
|
||||||
nv := ss.sm.GetNtwkVersion(ctx, epoch)
|
nv := ss.StateManager.GetNtwkVersion(ctx, epoch)
|
||||||
actor, minerState, err := ss.getMinerState(ctx, minerAddr)
|
actor, minerState, err := ss.getMinerState(ctx, minerAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, false, err
|
return 0, false, err
|
||||||
|
@ -111,7 +111,7 @@ func (ss *simulationState) packProveCommitsMiner(
|
|||||||
return res, false, err
|
return res, false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
nv := ss.sm.GetNtwkVersion(ctx, ss.nextEpoch())
|
nv := ss.StateManager.GetNtwkVersion(ctx, ss.nextEpoch())
|
||||||
for sealType, snos := range pending {
|
for sealType, snos := range pending {
|
||||||
if nv >= network.Version13 {
|
if nv >= network.Version13 {
|
||||||
for len(snos) > minProveCommitBatchSize {
|
for len(snos) > minProveCommitBatchSize {
|
||||||
@ -260,7 +260,7 @@ func (ss *simulationState) loadProveCommitsMiner(ctx context.Context, addr addre
|
|||||||
// Find all pending prove commits and group by proof type. Really, there should never
|
// Find all pending prove commits and group by proof type. Really, there should never
|
||||||
// (except during upgrades be more than one type.
|
// (except during upgrades be more than one type.
|
||||||
nextEpoch := ss.nextEpoch()
|
nextEpoch := ss.nextEpoch()
|
||||||
nv := ss.sm.GetNtwkVersion(ctx, nextEpoch)
|
nv := ss.StateManager.GetNtwkVersion(ctx, nextEpoch)
|
||||||
av := actors.VersionForNetwork(nv)
|
av := actors.VersionForNetwork(nv)
|
||||||
|
|
||||||
var total, dropped int
|
var total, dropped int
|
||||||
@ -294,7 +294,7 @@ func (ss *simulationState) filterProveCommits(ctx context.Context, minerAddr add
|
|||||||
}
|
}
|
||||||
|
|
||||||
nextEpoch := ss.nextEpoch()
|
nextEpoch := ss.nextEpoch()
|
||||||
nv := ss.sm.GetNtwkVersion(ctx, nextEpoch)
|
nv := ss.StateManager.GetNtwkVersion(ctx, nextEpoch)
|
||||||
av := actors.VersionForNetwork(nv)
|
av := actors.VersionForNetwork(nv)
|
||||||
|
|
||||||
good := make([]abi.SectorNumber, 0, len(snos))
|
good := make([]abi.SectorNumber, 0, len(snos))
|
||||||
|
@ -79,11 +79,11 @@ func (c *config) upgradeSchedule() (stmgr.UpgradeSchedule, error) {
|
|||||||
// Simulation specifies a lotus-sim simulation.
|
// Simulation specifies a lotus-sim simulation.
|
||||||
type Simulation struct {
|
type Simulation struct {
|
||||||
*Node
|
*Node
|
||||||
|
StateManager *stmgr.StateManager
|
||||||
|
|
||||||
name string
|
name string
|
||||||
config config
|
config config
|
||||||
start *types.TipSet
|
start *types.TipSet
|
||||||
sm *stmgr.StateManager
|
|
||||||
|
|
||||||
// head
|
// head
|
||||||
st *state.StateTree
|
st *state.StateTree
|
||||||
@ -125,11 +125,11 @@ func (sim *Simulation) saveConfig() error {
|
|||||||
// The state-tree is cached until the head is changed.
|
// The state-tree is cached until the head is changed.
|
||||||
func (sim *Simulation) stateTree(ctx context.Context) (*state.StateTree, error) {
|
func (sim *Simulation) stateTree(ctx context.Context) (*state.StateTree, error) {
|
||||||
if sim.st == nil {
|
if sim.st == nil {
|
||||||
st, _, err := sim.sm.TipSetState(ctx, sim.head)
|
st, _, err := sim.StateManager.TipSetState(ctx, sim.head)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
sim.st, err = sim.sm.StateTree(st)
|
sim.st, err = sim.StateManager.StateTree(st)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -204,7 +204,7 @@ func (sim *Simulation) GetStart() *types.TipSet {
|
|||||||
|
|
||||||
// GetNetworkVersion returns the current network version for the simulation.
|
// GetNetworkVersion returns the current network version for the simulation.
|
||||||
func (sim *Simulation) GetNetworkVersion() network.Version {
|
func (sim *Simulation) GetNetworkVersion() network.Version {
|
||||||
return sim.sm.GetNtwkVersion(context.TODO(), sim.head.Height())
|
return sim.StateManager.GetNtwkVersion(context.TODO(), sim.head.Height())
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetHead updates the current head of the simulation and stores it in the metadata store. This is
|
// SetHead updates the current head of the simulation and stores it in the metadata store. This is
|
||||||
@ -256,7 +256,7 @@ func (sim *Simulation) SetUpgradeHeight(nv network.Version, epoch abi.ChainEpoch
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
sim.sm = sm
|
sim.StateManager = sm
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,8 +78,8 @@ func (ss *simulationState) popNextMessages(ctx context.Context) ([]*types.Messag
|
|||||||
// This isn't what the network does, but it makes things easier. Otherwise, we'd need to run
|
// This isn't what the network does, but it makes things easier. Otherwise, we'd need to run
|
||||||
// migrations before this epoch and I'd rather not deal with that.
|
// migrations before this epoch and I'd rather not deal with that.
|
||||||
nextHeight := parentTs.Height() + 1
|
nextHeight := parentTs.Height() + 1
|
||||||
prevVer := ss.sm.GetNtwkVersion(ctx, nextHeight-1)
|
prevVer := ss.StateManager.GetNtwkVersion(ctx, nextHeight-1)
|
||||||
nextVer := ss.sm.GetNtwkVersion(ctx, nextHeight)
|
nextVer := ss.StateManager.GetNtwkVersion(ctx, nextHeight)
|
||||||
if nextVer != prevVer {
|
if nextVer != prevVer {
|
||||||
log.Warnw("packing no messages for version upgrade block",
|
log.Warnw("packing no messages for version upgrade block",
|
||||||
"old", prevVer,
|
"old", prevVer,
|
||||||
@ -91,7 +91,7 @@ func (ss *simulationState) popNextMessages(ctx context.Context) ([]*types.Messag
|
|||||||
|
|
||||||
// Next, we compute the state for the parent tipset. In practice, this will likely be
|
// Next, we compute the state for the parent tipset. In practice, this will likely be
|
||||||
// cached.
|
// cached.
|
||||||
parentState, _, err := ss.sm.TipSetState(ctx, parentTs)
|
parentState, _, err := ss.StateManager.TipSetState(ctx, parentTs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -102,17 +102,17 @@ func (ss *simulationState) popNextMessages(ctx context.Context) ([]*types.Messag
|
|||||||
// 1. We don't charge a fee.
|
// 1. We don't charge a fee.
|
||||||
// 2. The runtime has "fake" proof logic.
|
// 2. The runtime has "fake" proof logic.
|
||||||
// 3. We don't actually save any of the results.
|
// 3. We don't actually save any of the results.
|
||||||
r := store.NewChainRand(ss.sm.ChainStore(), parentTs.Cids())
|
r := store.NewChainRand(ss.StateManager.ChainStore(), parentTs.Cids())
|
||||||
vmopt := &vm.VMOpts{
|
vmopt := &vm.VMOpts{
|
||||||
StateBase: parentState,
|
StateBase: parentState,
|
||||||
Epoch: nextHeight,
|
Epoch: nextHeight,
|
||||||
Rand: r,
|
Rand: r,
|
||||||
Bstore: ss.sm.ChainStore().StateBlockstore(),
|
Bstore: ss.StateManager.ChainStore().StateBlockstore(),
|
||||||
Syscalls: ss.sm.ChainStore().VMSys(),
|
Syscalls: ss.StateManager.ChainStore().VMSys(),
|
||||||
CircSupplyCalc: ss.sm.GetVMCirculatingSupply,
|
CircSupplyCalc: ss.StateManager.GetVMCirculatingSupply,
|
||||||
NtwkVersion: ss.sm.GetNtwkVersion,
|
NtwkVersion: ss.StateManager.GetNtwkVersion,
|
||||||
BaseFee: abi.NewTokenAmount(0), // FREE!
|
BaseFee: abi.NewTokenAmount(0), // FREE!
|
||||||
LookbackState: stmgr.LookbackStateGetterForTipset(ss.sm, parentTs),
|
LookbackState: stmgr.LookbackStateGetterForTipset(ss.StateManager, parentTs),
|
||||||
}
|
}
|
||||||
vmi, err := vm.NewVM(ctx, vmopt)
|
vmi, err := vm.NewVM(ctx, vmopt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user