From 3f4eaa99d5c4c13c38308f677f39bbbd4290af98 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Fri, 17 Dec 2021 18:43:39 -0500 Subject: [PATCH] Refactor: State: Rename stmgr::GetNtwkVersion to GetNetworkVersion --- chain/consensus/filcns/compute_state.go | 2 +- chain/consensus/filcns/filecoin.go | 8 ++++---- chain/stmgr/actors.go | 4 ++-- chain/stmgr/call.go | 4 ++-- chain/stmgr/stmgr.go | 6 +++--- chain/stmgr/utils.go | 4 ++-- cmd/lotus-sim/simulation/blockbuilder/blockbuilder.go | 4 ++-- cmd/lotus-sim/simulation/simulation.go | 2 +- cmd/lotus-sim/simulation/step.go | 4 ++-- conformance/driver.go | 2 +- node/impl/full/state.go | 4 ++-- 11 files changed, 22 insertions(+), 22 deletions(-) diff --git a/chain/consensus/filcns/compute_state.go b/chain/consensus/filcns/compute_state.go index 7000af303..6a25e6df2 100644 --- a/chain/consensus/filcns/compute_state.go +++ b/chain/consensus/filcns/compute_state.go @@ -101,7 +101,7 @@ func (t *TipSetExecutor) ApplyBlocks(ctx context.Context, sm *stmgr.StateManager Actors: NewActorRegistry(), Syscalls: sm.Syscalls, CircSupplyCalc: sm.GetVMCirculatingSupply, - NtwkVersion: sm.GetNtwkVersion, + NtwkVersion: sm.GetNetworkVersion, BaseFee: baseFee, LookbackState: stmgr.LookbackStateGetterForTipset(sm, ts), } diff --git a/chain/consensus/filcns/filecoin.go b/chain/consensus/filcns/filecoin.go index 328fc8ec1..6d4c8da64 100644 --- a/chain/consensus/filcns/filecoin.go +++ b/chain/consensus/filcns/filecoin.go @@ -95,7 +95,7 @@ func (filec *FilecoinEC) ValidateBlock(ctx context.Context, b *types.FullBlock) return xerrors.Errorf("load parent tipset failed (%s): %w", h.Parents, err) } - winPoStNv := filec.sm.GetNtwkVersion(ctx, baseTs.Height()) + winPoStNv := filec.sm.GetNetworkVersion(ctx, baseTs.Height()) lbts, lbst, err := stmgr.GetLookbackTipSetForRound(ctx, filec.sm, baseTs, h.Height) if err != nil { @@ -457,7 +457,7 @@ func (filec *FilecoinEC) checkBlockMessages(ctx context.Context, b *types.FullBl return xerrors.Errorf("failed to load base state tree: %w", err) } - nv := filec.sm.GetNtwkVersion(ctx, b.Header.Height) + nv := filec.sm.GetNetworkVersion(ctx, b.Header.Height) pl := vm.PricelistByEpoch(baseTs.Height()) var sumGasLimit int64 checkMsg := func(msg types.ChainMsg) error { @@ -479,7 +479,7 @@ func (filec *FilecoinEC) checkBlockMessages(ctx context.Context, b *types.FullBl // Phase 2: (Partial) semantic validation: // the sender exists and is an account actor, and the nonces make sense var sender address.Address - if filec.sm.GetNtwkVersion(ctx, b.Header.Height) >= network.Version13 { + if filec.sm.GetNetworkVersion(ctx, b.Header.Height) >= network.Version13 { sender, err = st.LookupID(m.From) if err != nil { return err @@ -532,7 +532,7 @@ func (filec *FilecoinEC) checkBlockMessages(ctx context.Context, b *types.FullBl smArr := blockadt.MakeEmptyArray(tmpstore) for i, m := range b.SecpkMessages { - if filec.sm.GetNtwkVersion(ctx, b.Header.Height) >= network.Version14 { + if filec.sm.GetNetworkVersion(ctx, b.Header.Height) >= network.Version14 { if m.Signature.Type != crypto.SigTypeSecp256k1 { return xerrors.Errorf("block had invalid secpk message at index %d: %w", i, err) } diff --git a/chain/stmgr/actors.go b/chain/stmgr/actors.go index 6804b8126..a8958ee4c 100644 --- a/chain/stmgr/actors.go +++ b/chain/stmgr/actors.go @@ -358,7 +358,7 @@ func MinerGetBaseInfo(ctx context.Context, sm *StateManager, bcs beacon.Schedule return nil, xerrors.Errorf("failed to get randomness for winning post: %w", err) } - nv := sm.GetNtwkVersion(ctx, ts.Height()) + nv := sm.GetNetworkVersion(ctx, ts.Height()) sectors, err := GetSectorsForWinningPoSt(ctx, nv, pv, sm, lbst, maddr, prand) if err != nil { @@ -420,7 +420,7 @@ func MinerEligibleToMine(ctx context.Context, sm *StateManager, addr address.Add hmp, err := minerHasMinPower(ctx, sm, addr, lookbackTs) // TODO: We're blurring the lines between a "runtime network version" and a "Lotus upgrade epoch", is that unavoidable? - if sm.GetNtwkVersion(ctx, baseTs.Height()) <= network.Version3 { + if sm.GetNetworkVersion(ctx, baseTs.Height()) <= network.Version3 { return hmp, err } diff --git a/chain/stmgr/call.go b/chain/stmgr/call.go index ef29e1659..2d5d64ae7 100644 --- a/chain/stmgr/call.go +++ b/chain/stmgr/call.go @@ -80,7 +80,7 @@ func (sm *StateManager) Call(ctx context.Context, msg *types.Message, ts *types. Actors: sm.tsExec.NewActorRegistry(), Syscalls: sm.Syscalls, CircSupplyCalc: sm.GetVMCirculatingSupply, - NtwkVersion: sm.GetNtwkVersion, + NtwkVersion: sm.GetNetworkVersion, BaseFee: types.NewInt(0), LookbackState: LookbackStateGetterForTipset(sm, ts), } @@ -204,7 +204,7 @@ func (sm *StateManager) CallWithGas(ctx context.Context, msg *types.Message, pri Actors: sm.tsExec.NewActorRegistry(), Syscalls: sm.Syscalls, CircSupplyCalc: sm.GetVMCirculatingSupply, - NtwkVersion: sm.GetNtwkVersion, + NtwkVersion: sm.GetNetworkVersion, BaseFee: ts.Blocks()[0].ParentBaseFee, LookbackState: LookbackStateGetterForTipset(sm, ts), } diff --git a/chain/stmgr/stmgr.go b/chain/stmgr/stmgr.go index 06b363733..b19dd62c4 100644 --- a/chain/stmgr/stmgr.go +++ b/chain/stmgr/stmgr.go @@ -356,7 +356,7 @@ func (sm *StateManager) VMConstructor() func(context.Context, *vm.VMOpts) (*vm.V } } -func (sm *StateManager) GetNtwkVersion(ctx context.Context, height abi.ChainEpoch) network.Version { +func (sm *StateManager) GetNetworkVersion(ctx context.Context, height abi.ChainEpoch) network.Version { // The epochs here are the _last_ epoch for every version, or -1 if the // version is disabled. for _, spec := range sm.networkVersions { @@ -378,7 +378,7 @@ func (sm *StateManager) GetRandomnessFromBeacon(ctx context.Context, personaliza } r := rand.NewStateRand(sm.ChainStore(), pts.Cids(), sm.beacon) - rnv := sm.GetNtwkVersion(ctx, randEpoch) + rnv := sm.GetNetworkVersion(ctx, randEpoch) return r.GetBeaconRandomness(ctx, rnv, personalization, randEpoch, entropy) @@ -391,7 +391,7 @@ func (sm *StateManager) GetRandomnessFromTickets(ctx context.Context, personaliz } r := rand.NewStateRand(sm.ChainStore(), pts.Cids(), sm.beacon) - rnv := sm.GetNtwkVersion(ctx, randEpoch) + rnv := sm.GetNetworkVersion(ctx, randEpoch) return r.GetChainRandomness(ctx, rnv, personalization, randEpoch, entropy) } diff --git a/chain/stmgr/utils.go b/chain/stmgr/utils.go index 8b0f8daeb..5f23ce630 100644 --- a/chain/stmgr/utils.go +++ b/chain/stmgr/utils.go @@ -88,7 +88,7 @@ func ComputeState(ctx context.Context, sm *StateManager, height abi.ChainEpoch, Actors: sm.tsExec.NewActorRegistry(), Syscalls: sm.Syscalls, CircSupplyCalc: sm.GetVMCirculatingSupply, - NtwkVersion: sm.GetNtwkVersion, + NtwkVersion: sm.GetNetworkVersion, BaseFee: ts.Blocks()[0].ParentBaseFee, LookbackState: LookbackStateGetterForTipset(sm, ts), } @@ -128,7 +128,7 @@ func LookbackStateGetterForTipset(sm *StateManager, ts *types.TipSet) vm.Lookbac func GetLookbackTipSetForRound(ctx context.Context, sm *StateManager, ts *types.TipSet, round abi.ChainEpoch) (*types.TipSet, cid.Cid, error) { var lbr abi.ChainEpoch - lb := policy.GetWinningPoStSectorSetLookback(sm.GetNtwkVersion(ctx, round)) + lb := policy.GetWinningPoStSectorSetLookback(sm.GetNetworkVersion(ctx, round)) if round > lb { lbr = round - lb } diff --git a/cmd/lotus-sim/simulation/blockbuilder/blockbuilder.go b/cmd/lotus-sim/simulation/blockbuilder/blockbuilder.go index a6353e4f4..c656a8208 100644 --- a/cmd/lotus-sim/simulation/blockbuilder/blockbuilder.go +++ b/cmd/lotus-sim/simulation/blockbuilder/blockbuilder.go @@ -88,7 +88,7 @@ func NewBlockBuilder(ctx context.Context, logger *zap.SugaredLogger, sm *stmgr.S Actors: filcns.NewActorRegistry(), Syscalls: sm.VMSys(), CircSupplyCalc: sm.GetVMCirculatingSupply, - NtwkVersion: sm.GetNtwkVersion, + NtwkVersion: sm.GetNetworkVersion, BaseFee: abi.NewTokenAmount(0), LookbackState: stmgr.LookbackStateGetterForTipset(sm, parentTs), } @@ -265,7 +265,7 @@ func (bb *BlockBuilder) Height() abi.ChainEpoch { // NetworkVersion returns the network version for the target block. func (bb *BlockBuilder) NetworkVersion() network.Version { - return bb.sm.GetNtwkVersion(bb.ctx, bb.Height()) + return bb.sm.GetNetworkVersion(bb.ctx, bb.Height()) } // StateManager returns the stmgr.StateManager. diff --git a/cmd/lotus-sim/simulation/simulation.go b/cmd/lotus-sim/simulation/simulation.go index 5747afe4d..21e8bff71 100644 --- a/cmd/lotus-sim/simulation/simulation.go +++ b/cmd/lotus-sim/simulation/simulation.go @@ -159,7 +159,7 @@ func (sim *Simulation) GetStart() *types.TipSet { // GetNetworkVersion returns the current network version for the simulation. func (sim *Simulation) GetNetworkVersion() network.Version { - return sim.StateManager.GetNtwkVersion(context.TODO(), sim.head.Height()) + return sim.StateManager.GetNetworkVersion(context.TODO(), sim.head.Height()) } // SetHead updates the current head of the simulation and stores it in the metadata store. This is diff --git a/cmd/lotus-sim/simulation/step.go b/cmd/lotus-sim/simulation/step.go index 902f2ad6c..f9d58529e 100644 --- a/cmd/lotus-sim/simulation/step.go +++ b/cmd/lotus-sim/simulation/step.go @@ -41,8 +41,8 @@ func (sim *Simulation) popNextMessages(ctx context.Context) ([]*types.Message, e // 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. nextHeight := parentTs.Height() + 1 - prevVer := sim.StateManager.GetNtwkVersion(ctx, nextHeight-1) - nextVer := sim.StateManager.GetNtwkVersion(ctx, nextHeight) + prevVer := sim.StateManager.GetNetworkVersion(ctx, nextHeight-1) + nextVer := sim.StateManager.GetNetworkVersion(ctx, nextHeight) if nextVer != prevVer { log.Warnw("packing no messages for version upgrade block", "old", prevVer, diff --git a/conformance/driver.go b/conformance/driver.go index c6a20e359..9bca9c1fb 100644 --- a/conformance/driver.go +++ b/conformance/driver.go @@ -227,7 +227,7 @@ func (d *Driver) ExecuteMessage(bs blockstore.Blockstore, params ExecuteMessageP }, Rand: params.Rand, BaseFee: params.BaseFee, - NtwkVersion: sm.GetNtwkVersion, + NtwkVersion: sm.GetNetworkVersion, } lvm, err := vm.NewVM(context.TODO(), vmOpts) diff --git a/node/impl/full/state.go b/node/impl/full/state.go index 24cc08c8c..dfd1c69d9 100644 --- a/node/impl/full/state.go +++ b/node/impl/full/state.go @@ -1365,7 +1365,7 @@ func (m *StateModule) StateDealProviderCollateralBounds(ctx context.Context, siz powClaim.QualityAdjPower, rewPow, circ.FilCirculating, - m.StateManager.GetNtwkVersion(ctx, ts.Height())) + m.StateManager.GetNetworkVersion(ctx, ts.Height())) if err != nil { return api.DealCollateralBounds{}, xerrors.Errorf("getting deal provider coll bounds: %w", err) } @@ -1418,7 +1418,7 @@ func (m *StateModule) StateNetworkVersion(ctx context.Context, tsk types.TipSetK // TODO: Height-1 to be consistent with the rest of the APIs? // But that's likely going to break a bunch of stuff. - return m.StateManager.GetNtwkVersion(ctx, ts.Height()), nil + return m.StateManager.GetNetworkVersion(ctx, ts.Height()), nil } func (a *StateAPI) StateGetRandomnessFromTickets(ctx context.Context, personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte, tsk types.TipSetKey) (abi.Randomness, error) {