Skip to content

Commit

Permalink
No need to compare from address and to address (#4716)
Browse files Browse the repository at this point in the history
* No need to compare from address and to address

* vmoption remove NetworkVersionGetter
  • Loading branch information
simlecode authored Jan 19, 2022
1 parent 96f29da commit a886f66
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 96 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
16 changes: 4 additions & 12 deletions pkg/vm/vmcontext/invocation_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,16 +218,15 @@ 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")
}

// 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
}
Expand All @@ -237,24 +236,17 @@ 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.
if ctx.originMsg.Method == builtin.MethodSend {
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

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 a886f66

Please sign in to comment.