Skip to content

Commit

Permalink
tvx and conformance: use precondition state tree as the lookback tree.
Browse files Browse the repository at this point in the history
  • Loading branch information
raulk committed Mar 11, 2022
1 parent 5434cfd commit 9eb8103
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions conformance/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"

"github.com/filecoin-project/go-state-types/network"
cbor "github.com/ipfs/go-ipld-cbor"

"github.com/filecoin-project/lotus/blockstore"
"github.com/filecoin-project/lotus/chain/consensus/filcns"
Expand Down Expand Up @@ -199,6 +200,9 @@ type ExecuteMessageParams struct {
// Rand is an optional vm.Rand implementation to use. If nil, the driver
// will use a vm.Rand that returns a fixed value for all calls.
Rand vm.Rand

// Lookback is the LookbackStateGetter; returns the state tree at a given epoch.
Lookback vm.LookbackStateGetter
}

// ExecuteMessage executes a conformance test vector message in a temporary VM.
Expand All @@ -213,6 +217,17 @@ func (d *Driver) ExecuteMessage(bs blockstore.Blockstore, params ExecuteMessageP
params.Rand = NewFixedRand()
}

// TODO: This lookback state returns the supplied precondition state tree, unconditionally.
// This is obviously not correct, but the lookback state tree is only used to validate the
// worker key when verifying a consensus fault. If the worker key hasn't changed in the
// current finality window, this workaround is enough.
// The correct solutions are documented in https://github.com/filecoin-project/ref-fvm/issues/381,
// but they're much harder to implement, and the tradeoffs aren't clear.
var lookback vm.LookbackStateGetter = func(ctx context.Context, epoch abi.ChainEpoch) (*state.StateTree, error) {
cst := cbor.NewCborStore(bs)
return state.LoadStateTree(cst, params.Preroot)
}

vmOpts := &vm.VMOpts{
StateBase: params.Preroot,
Epoch: params.Epoch,
Expand All @@ -224,6 +239,7 @@ func (d *Driver) ExecuteMessage(bs blockstore.Blockstore, params ExecuteMessageP
Rand: params.Rand,
BaseFee: params.BaseFee,
NetworkVersion: params.NetworkVersion,
LookbackState: lookback,
}

lvm, err := vm.NewVM(context.TODO(), vmOpts)
Expand Down

0 comments on commit 9eb8103

Please sign in to comment.