From 85447abe7f6d8fbdcad0eb69b621aa10c74f8356 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ra=C3=BAl=20Kripalani?= <raul@protocol.ai>
Date: Mon, 24 Jan 2022 19:43:16 +0000
Subject: [PATCH 1/2] tvx: supply network version when extracting messages.

---
 cmd/tvx/extract_message.go | 34 ++++++++++++++++++++--------------
 cmd/tvx/simulate.go        |  1 +
 2 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/cmd/tvx/extract_message.go b/cmd/tvx/extract_message.go
index 71035867f29..68376654af8 100644
--- a/cmd/tvx/extract_message.go
+++ b/cmd/tvx/extract_message.go
@@ -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"
@@ -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 {
@@ -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)
 
@@ -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)
@@ -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)
@@ -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.
diff --git a/cmd/tvx/simulate.go b/cmd/tvx/simulate.go
index da9a034e923..5428e16ee31 100644
--- a/cmd/tvx/simulate.go
+++ b/cmd/tvx/simulate.go
@@ -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)

From 3aab77af8d91ad022e54f155803817d1f2bb3a0d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ra=C3=BAl=20Kripalani?= <raul@protocol.ai>
Date: Mon, 24 Jan 2022 20:13:04 +0000
Subject: [PATCH 2/2] tvx: add missing network upgrade names.

---
 cmd/tvx/codenames.go | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/cmd/tvx/codenames.go b/cmd/tvx/codenames.go
index f8da07e8d88..81143c85ce0 100644
--- a/cmd/tvx/codenames.go
+++ b/cmd/tvx/codenames.go
@@ -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.