Skip to content

Commit

Permalink
Merge pull request #7996 from filecoin-project/raulk/tvx-network-version
Browse files Browse the repository at this point in the history
tvx: supply network version when extracting messages.
  • Loading branch information
raulk authored Jan 24, 2022
2 parents 6080431 + 3aab77a commit a246865
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
9 changes: 9 additions & 0 deletions cmd/tvx/codenames.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ var ProtocolCodenames = []struct {
{build.UpgradeTapeHeight + 1, "tape"},
{build.UpgradeLiftoffHeight + 1, "liftoff"},
{build.UpgradeKumquatHeight + 1, "postliftoff"},
{build.UpgradeCalicoHeight + 1, "calico"},
{build.UpgradePersianHeight + 1, "persian"},
{build.UpgradeOrangeHeight + 1, "orange"},
{build.UpgradeTrustHeight + 1, "trust"},
{build.UpgradeNorwegianHeight + 1, "norwegian"},
{build.UpgradeTurboHeight + 1, "turbo"},
{build.UpgradeHyperdriveHeight + 1, "hyperdrive"},
{build.UpgradeChocolateHeight + 1, "chocolate"},
{build.UpgradeOhSnapHeight + 1, "ohsnap"},
}

// GetProtocolCodename gets the protocol codename associated with a height.
Expand Down
34 changes: 20 additions & 14 deletions cmd/tvx/extract_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ import (
"io"
"log"

"github.com/filecoin-project/lotus/api/v0api"

"github.com/fatih/color"
"github.com/filecoin-project/go-address"

"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/api/v0api"
"github.com/filecoin-project/lotus/chain/actors/builtin"
init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init"
"github.com/filecoin-project/lotus/chain/actors/builtin/reward"
Expand Down Expand Up @@ -43,6 +42,15 @@ func doExtractMessage(opts extractOpts) error {
return fmt.Errorf("failed to resolve message and tipsets from chain: %w", err)
}

// Assumes that the desired message isn't at the boundary of network versions.
// Otherwise this will be inaccurate. But it's such a tiny edge case that
// it's not worth spending the time to support boundary messages unless
// actually needed.
nv, err := FullAPI.StateNetworkVersion(ctx, incTs.Key())
if err != nil {
return fmt.Errorf("failed to resolve network version from inclusion height: %w", err)
}

// get the circulating supply before the message was executed.
circSupplyDetail, err := FullAPI.StateVMCirculatingSupplyInternal(ctx, incTs.Key())
if err != nil {
Expand All @@ -53,6 +61,7 @@ func doExtractMessage(opts extractOpts) error {

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

Expand Down Expand Up @@ -110,7 +119,8 @@ func doExtractMessage(opts extractOpts) error {
CircSupply: circSupplyDetail.FilCirculating,
BaseFee: basefee,
// recorded randomness will be discarded.
Rand: conformance.NewRecordingRand(new(conformance.LogReporter), FullAPI),
Rand: conformance.NewRecordingRand(new(conformance.LogReporter), FullAPI),
NetworkVersion: nv,
})
if err != nil {
return fmt.Errorf("failed to execute precursor message: %w", err)
Expand Down Expand Up @@ -140,12 +150,13 @@ func doExtractMessage(opts extractOpts) error {

preroot = root
applyret, postroot, err = driver.ExecuteMessage(pst.Blockstore, conformance.ExecuteMessageParams{
Preroot: preroot,
Epoch: execTs.Height(),
Message: msg,
CircSupply: circSupplyDetail.FilCirculating,
BaseFee: basefee,
Rand: recordingRand,
Preroot: preroot,
Epoch: execTs.Height(),
Message: msg,
CircSupply: circSupplyDetail.FilCirculating,
BaseFee: basefee,
Rand: recordingRand,
NetworkVersion: nv,
})
if err != nil {
return fmt.Errorf("failed to execute message: %w", err)
Expand Down Expand Up @@ -263,11 +274,6 @@ func doExtractMessage(opts extractOpts) error {
return err
}

nv, err := FullAPI.StateNetworkVersion(ctx, execTs.Key())
if err != nil {
return err
}

codename := GetProtocolCodename(execTs.Height())

// Write out the test vector.
Expand Down
1 change: 1 addition & 0 deletions cmd/tvx/simulate.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ func runSimulateCmd(_ *cli.Context) error {
CircSupply: circSupply.FilCirculating,
BaseFee: baseFee,
Rand: rand,
// TODO NetworkVersion
})
if err != nil {
return fmt.Errorf("failed to apply message: %w", err)
Expand Down

0 comments on commit a246865

Please sign in to comment.