-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Filecoin Virtual Machine integration #8293
Changes from all commits
2a669b9
fc74a6c
04092f3
279cdd0
32b3618
e8d771f
e8bdf81
7438628
0d6eb7f
7ef1513
ee69899
4767f3d
d835cad
393479e
5be125a
562c59b
6e1d5c5
aad3762
420c5fb
9bb936b
b6682f4
d58babe
2ba34ad
755ce8c
dd91857
0a67b6e
d2054e8
6d4fb88
05fa9c8
67889b4
1bf40ad
6c51adc
673f558
e6117c4
9ea623e
16128a0
37539cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,12 +95,13 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal | |
Syscalls: mkFakedSigSyscalls(sys), | ||
CircSupplyCalc: csc, | ||
NetworkVersion: nv, | ||
BaseFee: types.NewInt(0), | ||
BaseFee: big.Zero(), | ||
FilVested: big.Zero(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're only passing these opts into legacy VMs from here correct? So this is just nice zero value setting for clarity and won't cause v14 devnets to read bad values for the vested fil? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct, yeah. Also Vested fil is equal to zero at genesis, so should be consistent. |
||
} | ||
|
||
vm, err := vm.NewVM(ctx, vmopt) | ||
vm, err := vm.NewLegacyVM(ctx, vmopt) | ||
if err != nil { | ||
return cid.Undef, xerrors.Errorf("failed to create NewVM: %w", err) | ||
return cid.Undef, xerrors.Errorf("failed to create NewLegacyVM: %w", err) | ||
} | ||
|
||
if len(miners) == 0 { | ||
|
@@ -520,7 +521,7 @@ func (fr *fakeRand) GetBeaconRandomness(ctx context.Context, personalization cry | |
return out, nil | ||
} | ||
|
||
func currentTotalPower(ctx context.Context, vm *vm.VM, maddr address.Address) (*power0.CurrentTotalPowerReturn, error) { | ||
func currentTotalPower(ctx context.Context, vm *vm.LegacyVM, maddr address.Address) (*power0.CurrentTotalPowerReturn, error) { | ||
pwret, err := doExecValue(ctx, vm, power.Address, maddr, big.Zero(), builtin0.MethodsPower.CurrentTotalPower, nil) | ||
if err != nil { | ||
return nil, err | ||
|
@@ -533,7 +534,7 @@ func currentTotalPower(ctx context.Context, vm *vm.VM, maddr address.Address) (* | |
return &pwr, nil | ||
} | ||
|
||
func dealWeight(ctx context.Context, vm *vm.VM, maddr address.Address, dealIDs []abi.DealID, sectorStart, sectorExpiry abi.ChainEpoch, av actors.Version) (abi.DealWeight, abi.DealWeight, error) { | ||
func dealWeight(ctx context.Context, vm *vm.LegacyVM, maddr address.Address, dealIDs []abi.DealID, sectorStart, sectorExpiry abi.ChainEpoch, av actors.Version) (abi.DealWeight, abi.DealWeight, error) { | ||
// TODO: This hack should move to market actor wrapper | ||
if av <= actors.Version2 { | ||
params := &market0.VerifyDealsForActivationParams{ | ||
|
@@ -593,7 +594,7 @@ func dealWeight(ctx context.Context, vm *vm.VM, maddr address.Address, dealIDs [ | |
return dealWeights.Sectors[0].DealWeight, dealWeights.Sectors[0].VerifiedDealWeight, nil | ||
} | ||
|
||
func currentEpochBlockReward(ctx context.Context, vm *vm.VM, maddr address.Address, av actors.Version) (abi.StoragePower, builtin.FilterEstimate, error) { | ||
func currentEpochBlockReward(ctx context.Context, vm *vm.LegacyVM, maddr address.Address, av actors.Version) (abi.StoragePower, builtin.FilterEstimate, error) { | ||
rwret, err := doExecValue(ctx, vm, reward.Address, maddr, big.Zero(), reward.Methods.ThisEpochReward, nil) | ||
if err != nil { | ||
return big.Zero(), builtin.FilterEstimate{}, err | ||
|
@@ -628,7 +629,7 @@ func currentEpochBlockReward(ctx context.Context, vm *vm.VM, maddr address.Addre | |
return epochReward.ThisEpochBaselinePower, builtin.FilterEstimate(epochReward.ThisEpochRewardSmoothed), nil | ||
} | ||
|
||
func circSupply(ctx context.Context, vmi *vm.VM, maddr address.Address) abi.TokenAmount { | ||
func circSupply(ctx context.Context, vmi *vm.LegacyVM, maddr address.Address) abi.TokenAmount { | ||
unsafeVM := &vm.UnsafeVM{VM: vmi} | ||
rt := unsafeVM.MakeRuntime(ctx, &types.Message{ | ||
GasLimit: 1_000_000_000, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,12 @@ import ( | |
"errors" | ||
"fmt" | ||
|
||
cbor "github.com/ipfs/go-ipld-cbor" | ||
|
||
"github.com/filecoin-project/lotus/chain/state" | ||
|
||
"github.com/filecoin-project/lotus/blockstore" | ||
|
||
"github.com/filecoin-project/lotus/chain/rand" | ||
|
||
"github.com/filecoin-project/go-address" | ||
|
@@ -64,6 +70,8 @@ func (sm *StateManager) Call(ctx context.Context, msg *types.Message, ts *types. | |
pheight = ts.Height() - 1 | ||
} | ||
|
||
// Since we're simulating a future message, pretend we're applying it in the "next" tipset | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is a current message and we're executing it for real. "Current message is applied at parent height + 1" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clarifying, thanks. |
||
vmHeight := pheight + 1 | ||
arajasek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
bstate := ts.ParentState() | ||
|
||
// Run the (not expensive) migration. | ||
|
@@ -72,16 +80,22 @@ func (sm *StateManager) Call(ctx context.Context, msg *types.Message, ts *types. | |
return nil, fmt.Errorf("failed to handle fork: %w", err) | ||
} | ||
|
||
filVested, err := sm.GetFilVested(ctx, vmHeight) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
vmopt := &vm.VMOpts{ | ||
StateBase: bstate, | ||
Epoch: pheight + 1, | ||
Epoch: vmHeight, | ||
Rand: rand.NewStateRand(sm.cs, ts.Cids(), sm.beacon, sm.GetNetworkVersion), | ||
Bstore: sm.cs.StateBlockstore(), | ||
Actors: sm.tsExec.NewActorRegistry(), | ||
Syscalls: sm.Syscalls, | ||
CircSupplyCalc: sm.GetVMCirculatingSupply, | ||
NetworkVersion: sm.GetNetworkVersion(ctx, pheight+1), | ||
BaseFee: types.NewInt(0), | ||
FilVested: filVested, | ||
LookbackState: LookbackStateGetterForTipset(sm, ts), | ||
} | ||
|
||
|
@@ -112,7 +126,12 @@ func (sm *StateManager) Call(ctx context.Context, msg *types.Message, ts *types. | |
) | ||
} | ||
|
||
fromActor, err := vmi.StateTree().GetActor(msg.From) | ||
stTree, err := sm.StateTree(bstate) | ||
if err != nil { | ||
return nil, xerrors.Errorf("failed to load state tree: %w", err) | ||
} | ||
|
||
fromActor, err := stTree.GetActor(msg.From) | ||
if err != nil { | ||
return nil, xerrors.Errorf("call raw get actor: %s", err) | ||
} | ||
|
@@ -175,13 +194,16 @@ func (sm *StateManager) CallWithGas(ctx context.Context, msg *types.Message, pri | |
} | ||
} | ||
|
||
state, _, err := sm.TipSetState(ctx, ts) | ||
// Since we're simulating a future message, pretend we're applying it in the "next" tipset | ||
vmHeight := ts.Height() + 1 | ||
|
||
stateCid, _, err := sm.TipSetState(ctx, ts) | ||
if err != nil { | ||
return nil, xerrors.Errorf("computing tipset state: %w", err) | ||
} | ||
|
||
// Technically, the tipset we're passing in here should be ts+1, but that may not exist. | ||
state, err = sm.HandleStateForks(ctx, state, ts.Height(), nil, ts) | ||
stateCid, err = sm.HandleStateForks(ctx, stateCid, ts.Height(), nil, ts) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to handle fork: %w", err) | ||
} | ||
|
@@ -196,16 +218,23 @@ func (sm *StateManager) CallWithGas(ctx context.Context, msg *types.Message, pri | |
) | ||
} | ||
|
||
filVested, err := sm.GetFilVested(ctx, vmHeight) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
buffStore := blockstore.NewBuffered(sm.cs.StateBlockstore()) | ||
vmopt := &vm.VMOpts{ | ||
StateBase: state, | ||
Epoch: ts.Height() + 1, | ||
StateBase: stateCid, | ||
Epoch: vmHeight, | ||
Rand: r, | ||
Bstore: sm.cs.StateBlockstore(), | ||
Bstore: buffStore, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait, was this method writing directly into the state store without any buffering? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nah, the Lotus VM wraps the store you give it in a buffered store, so this was going into a buffer there (that then got thrown away cuz we never flushed, while still being accessible for determining the state of the sender in between messages). |
||
Actors: sm.tsExec.NewActorRegistry(), | ||
Syscalls: sm.Syscalls, | ||
CircSupplyCalc: sm.GetVMCirculatingSupply, | ||
NetworkVersion: sm.GetNetworkVersion(ctx, ts.Height()+1), | ||
BaseFee: ts.Blocks()[0].ParentBaseFee, | ||
FilVested: filVested, | ||
LookbackState: LookbackStateGetterForTipset(sm, ts), | ||
} | ||
vmi, err := sm.newVM(ctx, vmopt) | ||
|
@@ -219,7 +248,19 @@ func (sm *StateManager) CallWithGas(ctx context.Context, msg *types.Message, pri | |
} | ||
} | ||
|
||
fromActor, err := vmi.StateTree().GetActor(msg.From) | ||
// We flush to get the VM's view of the state tree after applying the above messages | ||
// This is needed to get the correct nonce from the actor state to match the VM | ||
stateCid, err = vmi.Flush(ctx) | ||
if err != nil { | ||
return nil, xerrors.Errorf("flushing vm: %w", err) | ||
} | ||
|
||
stTree, err := state.LoadStateTree(cbor.NewCborStore(buffStore), stateCid) | ||
if err != nil { | ||
return nil, xerrors.Errorf("loading state tree: %w", err) | ||
} | ||
Comment on lines
+253
to
+261
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
fromActor, err := stTree.GetActor(msg.From) | ||
if err != nil { | ||
return nil, xerrors.Errorf("call raw get actor: %s", err) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What changed in v15 so that this would not be needed by FVM?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First Protocol Improvement / Bugfix mentioned here
(also adding a link in the comment)