Skip to content
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

conformance: record and feed circulating supply. #4078

Merged
merged 2 commits into from
Sep 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions cmd/tvx/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,17 @@ func doExtract(ctx context.Context, fapi api.FullNode, opts extractOpts) error {
return fmt.Errorf("failed to resolve message and tipsets from chain: %w", err)
}

// get the circulating supply before the message was executed.
circSupplyDetail, err := fapi.StateCirculatingSupply(ctx, incTs.Key())
if err != nil {
return fmt.Errorf("failed while fetching circulating supply: %w", err)
}

circSupply := circSupplyDetail.FilCirculating.Int64()

log.Printf("message was executed in tipset: %s", execTs.Key())
log.Printf("message was included in tipset: %s", incTs.Key())
log.Printf("circulating supply at inclusion tipset: %d", circSupply)
log.Printf("finding precursor messages")

// Iterate through blocks, finding the one that contains the message and its
Expand Down Expand Up @@ -174,7 +183,7 @@ func doExtract(ctx context.Context, fapi api.FullNode, opts extractOpts) error {
log.Printf("number of precursors to apply: %d", len(precursors))
for i, m := range precursors {
log.Printf("applying precursor %d, cid: %s", i, m.Cid())
_, root, err = driver.ExecuteMessage(pst.Blockstore, root, execTs.Height(), m)
_, root, err = driver.ExecuteMessage(pst.Blockstore, root, execTs.Height(), m, &circSupplyDetail.FilCirculating)
if err != nil {
return fmt.Errorf("failed to execute precursor message: %w", err)
}
Expand All @@ -199,7 +208,7 @@ func doExtract(ctx context.Context, fapi api.FullNode, opts extractOpts) error {
tbs.StartTracing()

preroot = root
applyret, postroot, err = driver.ExecuteMessage(pst.Blockstore, preroot, execTs.Height(), msg)
applyret, postroot, err = driver.ExecuteMessage(pst.Blockstore, preroot, execTs.Height(), msg, &circSupplyDetail.FilCirculating)
if err != nil {
return fmt.Errorf("failed to execute message: %w", err)
}
Expand All @@ -224,7 +233,7 @@ func doExtract(ctx context.Context, fapi api.FullNode, opts extractOpts) error {
if err != nil {
return err
}
applyret, postroot, err = driver.ExecuteMessage(pst.Blockstore, preroot, execTs.Height(), msg)
applyret, postroot, err = driver.ExecuteMessage(pst.Blockstore, preroot, execTs.Height(), msg, &circSupplyDetail.FilCirculating)
if err != nil {
return fmt.Errorf("failed to execute message: %w", err)
}
Expand Down Expand Up @@ -302,7 +311,8 @@ func doExtract(ctx context.Context, fapi api.FullNode, opts extractOpts) error {
},
CAR: out.Bytes(),
Pre: &schema.Preconditions{
Epoch: int64(execTs.Height()),
Epoch: int64(execTs.Height()),
CircSupply: &circSupply,
StateTree: &schema.StateTree{
RootCID: preroot,
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/tvx/extract_many.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var extractManyFlags struct {

var extractManyCmd = &cli.Command{
Name: "extract-many",
Description: `generate many test vectors by repeateadly calling tvx extract, using a csv file as input.
Description: `generate many test vectors by repeatedly calling tvx extract, using a csv file as input.

The CSV file must have a format just like the following:

Expand Down
34 changes: 22 additions & 12 deletions conformance/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package conformance
import (
"context"

"github.com/filecoin-project/go-state-types/crypto"

"github.com/filecoin-project/lotus/chain/state"
"github.com/filecoin-project/lotus/chain/stmgr"
"github.com/filecoin-project/lotus/chain/store"
Expand All @@ -15,6 +13,7 @@ import (
"github.com/filecoin-project/lotus/lib/blockstore"

"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/crypto"

"github.com/filecoin-project/test-vectors/schema"

Expand All @@ -24,6 +23,11 @@ import (
ds "github.com/ipfs/go-datastore"
)

// DefaultCirculatingSupply is the fallback circulating supply returned by
// the driver's CircSupplyCalculator function, used if the vector specifies
// no circulating supply.
var DefaultCirculatingSupply = types.TotalFilecoinInt

var (
// BaseFee to use in the VM.
// TODO make parametrisable through vector.
Expand Down Expand Up @@ -136,18 +140,24 @@ func (d *Driver) ExecuteTipset(bs blockstore.Blockstore, ds ds.Batching, preroot
}

// ExecuteMessage executes a conformance test vector message in a temporary VM.
func (d *Driver) ExecuteMessage(bs blockstore.Blockstore, preroot cid.Cid, epoch abi.ChainEpoch, msg *types.Message) (*vm.ApplyRet, cid.Cid, error) {
// dummy state manager; only to reference the GetNetworkVersion method, which does not depend on state.
func (d *Driver) ExecuteMessage(bs blockstore.Blockstore, preroot cid.Cid, epoch abi.ChainEpoch, msg *types.Message, circSupply *abi.TokenAmount) (*vm.ApplyRet, cid.Cid, error) {
// dummy state manager; only to reference the GetNetworkVersion method,
// which does not depend on state.
sm := new(stmgr.StateManager)
vmOpts := &vm.VMOpts{
StateBase: preroot,
Epoch: epoch,
Rand: &testRand{}, // TODO always succeeds; need more flexibility.
Bstore: bs,
Syscalls: mkFakedSigSyscalls(vm.Syscalls(ffiwrapper.ProofVerifier)), // TODO always succeeds; need more flexibility.
CircSupplyCalc: nil,
BaseFee: BaseFee,
NtwkVersion: sm.GetNtwkVersion,
StateBase: preroot,
Epoch: epoch,
Rand: &testRand{}, // TODO always succeeds; need more flexibility.
Bstore: bs,
Syscalls: mkFakedSigSyscalls(vm.Syscalls(ffiwrapper.ProofVerifier)), // TODO always succeeds; need more flexibility.
CircSupplyCalc: func(_ context.Context, _ abi.ChainEpoch, _ *state.StateTree) (abi.TokenAmount, error) {
if circSupply != nil {
return *circSupply, nil
}
return DefaultCirculatingSupply, nil
},
BaseFee: BaseFee,
NtwkVersion: sm.GetNtwkVersion,
}

lvm, err := vm.NewVM(context.TODO(), vmOpts)
Expand Down
8 changes: 7 additions & 1 deletion conformance/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ func ExecuteMessageVector(r Reporter, vector *schema.TestVector) {
// Create a new Driver.
driver := NewDriver(ctx, vector.Selector, DriverOpts{})

var circSupply *abi.TokenAmount
if cs := vector.Pre.CircSupply; cs != nil {
ta := abi.NewTokenAmount(*cs)
circSupply = &ta
}

// Apply every message.
for i, m := range vector.ApplyMessages {
msg, err := types.DecodeMessage(m.Bytes)
Expand All @@ -59,7 +65,7 @@ func ExecuteMessageVector(r Reporter, vector *schema.TestVector) {

// Execute the message.
var ret *vm.ApplyRet
ret, root, err = driver.ExecuteMessage(bs, root, abi.ChainEpoch(epoch), msg)
ret, root, err = driver.ExecuteMessage(bs, root, abi.ChainEpoch(epoch), msg, circSupply)
if err != nil {
r.Fatalf("fatal failure when executing message: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ require (
github.com/filecoin-project/go-storedcounter v0.0.0-20200421200003-1c99c62e8a5b
github.com/filecoin-project/specs-actors v0.9.11
github.com/filecoin-project/specs-storage v0.1.1-0.20200907031224-ed2e5cd13796
github.com/filecoin-project/test-vectors/schema v0.0.1
github.com/filecoin-project/test-vectors/schema v0.0.2
github.com/gbrlsnchs/jwt/v3 v3.0.0-beta.1
github.com/go-kit/kit v0.10.0
github.com/go-ole/go-ole v1.2.4 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ github.com/filecoin-project/specs-actors v0.9.11 h1:TnpG7HAeiUrfj0mJM7UaPW0P2137
github.com/filecoin-project/specs-actors v0.9.11/go.mod h1:czlvLQGEX0fjLLfdNHD7xLymy6L3n7aQzRWzsYGf+ys=
github.com/filecoin-project/specs-storage v0.1.1-0.20200907031224-ed2e5cd13796 h1:dJsTPWpG2pcTeojO2pyn0c6l+x/3MZYCBgo/9d11JEk=
github.com/filecoin-project/specs-storage v0.1.1-0.20200907031224-ed2e5cd13796/go.mod h1:nJRRM7Aa9XVvygr3W9k6xGF46RWzr2zxF/iGoAIfA/g=
github.com/filecoin-project/test-vectors/schema v0.0.1 h1:5fNF76nl4qolEvcIsjc0kUADlTMVHO73tW4kXXPnsus=
github.com/filecoin-project/test-vectors/schema v0.0.1/go.mod h1:iQ9QXLpYWL3m7warwvK1JC/pTri8mnfEmKygNDqqY6E=
github.com/filecoin-project/test-vectors/schema v0.0.2 h1:/Pp//88WBXe0h+ksntdL2HpEgAmbwXrftAfeVG39zdY=
github.com/filecoin-project/test-vectors/schema v0.0.2/go.mod h1:iQ9QXLpYWL3m7warwvK1JC/pTri8mnfEmKygNDqqY6E=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/flynn/noise v0.0.0-20180327030543-2492fe189ae6 h1:u/UEqS66A5ckRmS4yNpjmVH56sVtS/RfclBAYocb4as=
github.com/flynn/noise v0.0.0-20180327030543-2492fe189ae6/go.mod h1:1i71OnUq3iUe1ma7Lr6yG6/rjvM3emb6yoL7xLFzcVQ=
Expand Down