diff --git a/pkg/consensus/expected.go b/pkg/consensus/expected.go index 17cdc8913f..b97fb89950 100644 --- a/pkg/consensus/expected.go +++ b/pkg/consensus/expected.go @@ -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 { diff --git a/pkg/gen/genesis/genesis.go b/pkg/gen/genesis/genesis.go index 362a7ca5a1..cd90b3c545 100644 --- a/pkg/gen/genesis/genesis.go +++ b/pkg/gen/genesis/genesis.go @@ -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) diff --git a/pkg/gen/genesis/miners.go b/pkg/gen/genesis/miners.go index dd04bed5be..eed90c7589 100644 --- a/pkg/gen/genesis/miners.go +++ b/pkg/gen/genesis/miners.go @@ -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) diff --git a/pkg/statemanger/call.go b/pkg/statemanger/call.go index 3f7e597dd7..103b364b8d 100644 --- a/pkg/statemanger/call.go +++ b/pkg/statemanger/call.go @@ -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) @@ -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) diff --git a/pkg/vm/vmcontext/invocation_context.go b/pkg/vm/vmcontext/invocation_context.go index f7f2b2dd0a..127c9c8032 100644 --- a/pkg/vm/vmcontext/invocation_context.go +++ b/pkg/vm/vmcontext/invocation_context.go @@ -218,8 +218,7 @@ func (ctx *invocationContext) invoke() (ret []byte, errcode exitcode.ExitCode) { // 2. load target actor // 3. transfer optional funds // 4. short-circuit _Send_ Method - // 5. load target actor code - // 6. create target stateView handle + // 5. create target stateView handle // assert From address is an ID address. if ctx.msg.From.Protocol() != address.ID { panic("bad code: sender address MUST be an ID address at invocation time") @@ -227,7 +226,7 @@ func (ctx *invocationContext) invoke() (ret []byte, errcode exitcode.ExitCode) { // 1. load target actor // Note: we replace the "To" address with the normalized version - _, toIDAddr := ctx.resolveTarget(ctx.originMsg.To) + toActor, toIDAddr := ctx.resolveTarget(ctx.originMsg.To) if ctx.vm.NetworkVersion() > network.Version3 { ctx.msg.To = toIDAddr } @@ -237,9 +236,7 @@ func (ctx *invocationContext) invoke() (ret []byte, errcode exitcode.ExitCode) { // 3. transfer funds carried by the msg if !ctx.originMsg.Value.Nil() && !ctx.originMsg.Value.IsZero() { - if ctx.msg.From != toIDAddr { - ctx.vm.transfer(ctx.msg.From, toIDAddr, ctx.originMsg.Value, ctx.vm.NetworkVersion()) - } + ctx.vm.transfer(ctx.msg.From, toIDAddr, ctx.originMsg.Value, ctx.vm.NetworkVersion()) } // 4. if we are just sending funds, there is nothing else To do. @@ -247,14 +244,9 @@ func (ctx *invocationContext) invoke() (ret []byte, errcode exitcode.ExitCode) { return nil, exitcode.Ok } - // 5. load target actor code - toActor, found, err := ctx.vm.State.GetActor(ctx.vm.context, ctx.originMsg.To) - if err != nil || !found { - panic(xerrors.Errorf("cannt find to actor %v", err)) - } actorImpl := ctx.vm.getActorImpl(toActor.Code, ctx.Runtime()) - // 6. create target stateView handle + // 5. create target stateView handle stateHandle := newActorStateHandle((*stateHandleContext)(ctx)) ctx.stateHandle = &stateHandle diff --git a/pkg/vm/vmcontext/types.go b/pkg/vm/vmcontext/types.go index a7d9b6f7a5..e94c152546 100644 --- a/pkg/vm/vmcontext/types.go +++ b/pkg/vm/vmcontext/types.go @@ -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 diff --git a/pkg/vm/vmcontext/vmcontext.go b/pkg/vm/vmcontext/vmcontext.go index 05bd139b7c..1d542506ee 100644 --- a/pkg/vm/vmcontext/vmcontext.go +++ b/pkg/vm/vmcontext/vmcontext.go @@ -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) @@ -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 diff --git a/tools/conformance/driver.go b/tools/conformance/driver.go index 95d12cee31..82640298c5 100644 --- a/tools/conformance/driver.go +++ b/tools/conformance/driver.go @@ -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, } ) @@ -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, } ) diff --git a/tools/gengen/util/generator.go b/tools/gengen/util/generator.go index 803769f4cd..9dd19f3887 100644 --- a/tools/gengen/util/generator.go +++ b/tools/gengen/util/generator.go @@ -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"))