Skip to content

Commit

Permalink
remove function NetworkVersionGetter
Browse files Browse the repository at this point in the history
  • Loading branch information
simlecode committed Jan 19, 2022
1 parent c30ec4e commit c0c9e08
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 84 deletions.
21 changes: 10 additions & 11 deletions pkg/consensus/expected.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,17 +207,16 @@ func (c *Expected) RunStateTransition(ctx context.Context, ts *types.TipSet) (ci
}
return dertail.FilCirculating, nil
},
LookbackStateGetter: vmcontext.LookbackStateGetterForTipset(ctx, c.chainState, c.fork, ts),
NetworkVersion: c.fork.GetNetworkVersion(ctx, ts.At(0).Height),
NetworkVersionGetter: c.fork.GetNetworkVersion,
Rnd: NewHeadRandomness(c.rnd, ts.Key()),
BaseFee: ts.At(0).ParentBaseFee,
Fork: c.fork,
Epoch: ts.At(0).Height,
GasPriceSchedule: c.gasPirceSchedule,
Bsstore: c.bstore,
PRoot: ts.At(0).ParentStateRoot,
SysCallsImpl: c.syscallsImpl,
LookbackStateGetter: vmcontext.LookbackStateGetterForTipset(ctx, c.chainState, c.fork, ts),
NetworkVersion: c.fork.GetNetworkVersion(ctx, ts.At(0).Height),
Rnd: NewHeadRandomness(c.rnd, ts.Key()),
BaseFee: ts.At(0).ParentBaseFee,
Fork: c.fork,
Epoch: ts.At(0).Height,
GasPriceSchedule: c.gasPirceSchedule,
Bsstore: c.bstore,
PRoot: ts.At(0).ParentStateRoot,
SysCallsImpl: c.syscallsImpl,
}
root, receipts, err := c.processor.ProcessTipSet(ctx, pts, ts, blockMessageInfo, vmOption)
if err != nil {
Expand Down
17 changes: 7 additions & 10 deletions pkg/gen/genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,16 +493,13 @@ func VerifyPreSealedData(ctx context.Context, cs *chain.Store, stateroot cid.Cid
vmopt := vm.VmOption{
CircSupplyCalculator: csc,
NetworkVersion: nv,
NetworkVersionGetter: func(ctx context.Context, height abi.ChainEpoch) network.Version {
return nv
},
Rnd: &fakeRand{},
BaseFee: big.NewInt(0),
Epoch: 0,
PRoot: stateroot,
Bsstore: cs.Blockstore(),
SysCallsImpl: mkFakedSigSyscalls(syscalls),
GasPriceSchedule: gasPriceSchedule,
Rnd: &fakeRand{},
BaseFee: big.NewInt(0),
Epoch: 0,
PRoot: stateroot,
Bsstore: cs.Blockstore(),
SysCallsImpl: mkFakedSigSyscalls(syscalls),
GasPriceSchedule: gasPriceSchedule,
}

vm, err := vm.NewVM(ctx, vmopt)
Expand Down
18 changes: 7 additions & 11 deletions pkg/gen/genesis/miners.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,13 @@ func SetupStorageMiners(ctx context.Context, cs *chain.Store, sroot cid.Cid, min
gasPirceSchedule := gas.NewPricesSchedule(para)
vmopt := vm.VmOption{
CircSupplyCalculator: csc,
NetworkVersion: nv,
NetworkVersionGetter: func(ctx context.Context, height abi.ChainEpoch) network.Version {
return nv
},
Rnd: &fakeRand{},
BaseFee: big.NewInt(0),
Epoch: 0,
PRoot: sroot,
Bsstore: cs.Blockstore(),
SysCallsImpl: mkFakedSigSyscalls(syscalls),
GasPriceSchedule: gasPirceSchedule,
Rnd: &fakeRand{},
BaseFee: big.NewInt(0),
Epoch: 0,
PRoot: sroot,
Bsstore: cs.Blockstore(),
SysCallsImpl: mkFakedSigSyscalls(syscalls),
GasPriceSchedule: gasPirceSchedule,
}

vmi, err := vm.NewVM(ctx, vmopt)
Expand Down
42 changes: 20 additions & 22 deletions pkg/statemanger/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,16 @@ func (s *Stmgr) CallWithGas(ctx context.Context, msg *types.Message, priorMsgs [
}
return cs.FilCirculating, nil
},
LookbackStateGetter: vmcontext.LookbackStateGetterForTipset(ctx, s.cs, s.fork, ts),
NetworkVersion: s.fork.GetNetworkVersion(ctx, ts.Height()+1),
NetworkVersionGetter: s.fork.GetNetworkVersion,
Rnd: consensus.NewHeadRandomness(s.rnd, ts.Key()),
BaseFee: ts.At(0).ParentBaseFee,
Epoch: ts.Height() + 1,
GasPriceSchedule: s.gasSchedule,
PRoot: stateRoot,
Bsstore: s.cs.Blockstore(),
SysCallsImpl: s.syscallsImpl,
Fork: s.fork,
LookbackStateGetter: vmcontext.LookbackStateGetterForTipset(ctx, s.cs, s.fork, ts),
NetworkVersion: s.fork.GetNetworkVersion(ctx, ts.Height()+1),
Rnd: consensus.NewHeadRandomness(s.rnd, ts.Key()),
BaseFee: ts.At(0).ParentBaseFee,
Epoch: ts.Height() + 1,
GasPriceSchedule: s.gasSchedule,
PRoot: stateRoot,
Bsstore: s.cs.Blockstore(),
SysCallsImpl: s.syscallsImpl,
Fork: s.fork,
}

vmi, err := vm.NewVM(ctx, vmOption)
Expand Down Expand Up @@ -197,17 +196,16 @@ func (s *Stmgr) Call(ctx context.Context, msg *types.Message, ts *types.TipSet)
}
return dertail.FilCirculating, nil
},
LookbackStateGetter: vmcontext.LookbackStateGetterForTipset(ctx, s.cs, s.fork, ts),
NetworkVersion: s.fork.GetNetworkVersion(ctx, pheight+1),
NetworkVersionGetter: s.fork.GetNetworkVersion,
Rnd: consensus.NewHeadRandomness(s.rnd, ts.Key()),
BaseFee: ts.At(0).ParentBaseFee,
Epoch: pheight + 1,
GasPriceSchedule: s.gasSchedule,
Fork: s.fork,
PRoot: ts.At(0).ParentStateRoot,
Bsstore: s.cs.Blockstore(),
SysCallsImpl: s.syscallsImpl,
LookbackStateGetter: vmcontext.LookbackStateGetterForTipset(ctx, s.cs, s.fork, ts),
NetworkVersion: s.fork.GetNetworkVersion(ctx, pheight+1),
Rnd: consensus.NewHeadRandomness(s.rnd, ts.Key()),
BaseFee: ts.At(0).ParentBaseFee,
Epoch: pheight + 1,
GasPriceSchedule: s.gasSchedule,
Fork: s.fork,
PRoot: ts.At(0).ParentStateRoot,
Bsstore: s.cs.Blockstore(),
SysCallsImpl: s.syscallsImpl,
}

v, err := vm.NewVM(ctx, vmOption)
Expand Down
2 changes: 0 additions & 2 deletions pkg/vm/vmcontext/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ import (
type ExecCallBack func(cid.Cid, VmMessage, *Ret) error
type CircSupplyCalculator func(context.Context, abi.ChainEpoch, tree.Tree) (abi.TokenAmount, error)
type LookbackStateGetter func(context.Context, abi.ChainEpoch) (*state.View, error)
type NetworkVersionGetter func(ctx context.Context, height abi.ChainEpoch) network.Version

type VmOption struct { //nolint
CircSupplyCalculator CircSupplyCalculator
LookbackStateGetter LookbackStateGetter
NetworkVersion network.Version
NetworkVersionGetter NetworkVersionGetter
Rnd HeadChainRandomness
BaseFee abi.TokenAmount
Fork fork.IFork
Expand Down
4 changes: 2 additions & 2 deletions pkg/vm/vmcontext/vmcontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func (vm *VM) ApplyTipSetMessages(blocks []types.BlockMessagesInfo, ts *types.Ti
for i := parentEpoch; i < epoch; i++ {
if i > parentEpoch {
// fix: https://github.com/filecoin-project/lotus/pull/7966
vm.vmOption.NetworkVersion = vm.vmOption.NetworkVersionGetter(vm.context, i)
vm.vmOption.NetworkVersion = vm.vmOption.Fork.GetNetworkVersion(vm.context, i)
// run cron for null rounds if any
cronMessage := makeCronTickMessage()
ret, err := vm.applyImplicitMessage(cronMessage)
Expand Down Expand Up @@ -252,7 +252,7 @@ func (vm *VM) ApplyTipSetMessages(blocks []types.BlockMessagesInfo, ts *types.Ti
}
}
// as above
vm.vmOption.NetworkVersion = vm.vmOption.NetworkVersionGetter(vm.context, epoch)
vm.vmOption.NetworkVersion = vm.vmOption.Fork.GetNetworkVersion(vm.context, epoch)

vmlog.Debugf("process tipset fork: %v\n", time.Since(toProcessTipset).Milliseconds())
// create message tracker
Expand Down
44 changes: 21 additions & 23 deletions tools/conformance/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,16 @@ func (d *Driver) ExecuteTipset(bs blockstore.Blockstore, chainDs ds.Batching, pr
CircSupplyCalculator: func(context.Context, abi.ChainEpoch, tree.Tree) (abi.TokenAmount, error) {
return big.Zero(), nil
},
LookbackStateGetter: vmcontext.LookbackStateGetterForTipset(ctx, chainStore, chainFork, nil),
NetworkVersion: chainFork.GetNetworkVersion(ctx, execEpoch),
NetworkVersionGetter: chainFork.GetNetworkVersion,
Rnd: NewFixedRand(),
BaseFee: big.NewFromGo(&tipset.BaseFee),
Fork: chainFork,
Epoch: execEpoch,
GasPriceSchedule: gas.NewPricesSchedule(mainNetParams.Network.ForkUpgradeParam),
PRoot: preroot,
Bsstore: bs,
SysCallsImpl: syscalls,
LookbackStateGetter: vmcontext.LookbackStateGetterForTipset(ctx, chainStore, chainFork, nil),
NetworkVersion: chainFork.GetNetworkVersion(ctx, execEpoch),
Rnd: NewFixedRand(),
BaseFee: big.NewFromGo(&tipset.BaseFee),
Fork: chainFork,
Epoch: execEpoch,
GasPriceSchedule: gas.NewPricesSchedule(mainNetParams.Network.ForkUpgradeParam),
PRoot: preroot,
Bsstore: bs,
SysCallsImpl: syscalls,
}
)

Expand Down Expand Up @@ -303,18 +302,17 @@ func (d *Driver) ExecuteMessage(bs blockstore.Blockstore, params ExecuteMessageP
CircSupplyCalculator: func(ctx context.Context, epoch abi.ChainEpoch, tree tree.Tree) (abi.TokenAmount, error) {
return params.CircSupply, nil
},
LookbackStateGetter: vmcontext.LookbackStateGetterForTipset(ctx, chainStore, chainFork, nil),
NetworkVersion: params.NetworkVersion,
NetworkVersionGetter: chainFork.GetNetworkVersion,
Rnd: params.Rand,
BaseFee: params.BaseFee,
Fork: chainFork,
ActorCodeLoader: &coderLoader,
Epoch: params.Epoch,
GasPriceSchedule: gas.NewPricesSchedule(mainNetParams.Network.ForkUpgradeParam),
PRoot: params.Preroot,
Bsstore: bs,
SysCallsImpl: syscalls,
LookbackStateGetter: vmcontext.LookbackStateGetterForTipset(ctx, chainStore, chainFork, nil),
NetworkVersion: params.NetworkVersion,
Rnd: params.Rand,
BaseFee: params.BaseFee,
Fork: chainFork,
ActorCodeLoader: &coderLoader,
Epoch: params.Epoch,
GasPriceSchedule: gas.NewPricesSchedule(mainNetParams.Network.ForkUpgradeParam),
PRoot: params.Preroot,
Bsstore: bs,
SysCallsImpl: syscalls,
}
)

Expand Down
3 changes: 0 additions & 3 deletions tools/gengen/util/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,6 @@ func NewGenesisGenerator(bs blockstore.Blockstore) *GenesisGenerator {
SysCallsImpl: syscallImpl,
Fork: chainFork,
}
vmOption.NetworkVersionGetter = func(ctx context.Context, height abi.ChainEpoch) network.Version {
return vmOption.NetworkVersion
}
vm, err := vm.NewVM(context.Background(), vmOption)
if err != nil {
panic(xerrors.Errorf("create state error, should never come here"))
Expand Down

0 comments on commit c0c9e08

Please sign in to comment.