From cdfa869ea642e96df41bc304947cd5a501dbd9ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Kripalani?= Date: Sat, 24 Oct 2020 20:12:23 +0100 Subject: [PATCH 1/2] tvx extract: make it work with secp messages. Unfortunately ChainGetMessage returns a *types.Message, which in the case of secp messages is lacking the signature. The signature is part of the input to calculate the CID on secp messages. Therefore, calling `.Cid()` on the result of ChainGetMessage for this kind of message will lead to an incorrect CID. tvx was relying on that call to return the correct CID. Since this is not the case (and this is a footgun that needs to be corrected, ideally together with the *types.{,Signed}Message duality mess), I'm replacing the comparison. --- cmd/tvx/extract.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/cmd/tvx/extract.go b/cmd/tvx/extract.go index 3dfec37d88..2e4aa3b50b 100644 --- a/cmd/tvx/extract.go +++ b/cmd/tvx/extract.go @@ -12,6 +12,7 @@ import ( "path/filepath" "github.com/fatih/color" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/chain/actors/builtin" @@ -70,6 +71,11 @@ var extractCmd = &cli.Command{ Usage: "optionally, the block CID the message was included in, to avoid expensive chain scanning", Destination: &extractFlags.block, }, + &cli.StringFlag{ + Name: "exec-block", + Usage: "optionally, the block CID of a block where this message was executed, to aovid", + Destination: &extractFlags.block, + }, &cli.StringFlag{ Name: "cid", Usage: "message CID to generate test vector from", @@ -143,7 +149,7 @@ func doExtract(opts extractOpts) error { return fmt.Errorf("failed to fetch messages in canonical order from inclusion tipset: %w", err) } - related, found, err := findMsgAndPrecursors(opts.precursor, msg, msgs) + related, found, err := findMsgAndPrecursors(opts.precursor, mcid, msg.From, msgs) if err != nil { return fmt.Errorf("failed while finding message and precursors: %w", err) } @@ -496,19 +502,19 @@ func fetchThisAndPrevTipset(ctx context.Context, api api.FullNode, target types. // findMsgAndPrecursors ranges through the canonical messages slice, locating // the target message and returning precursors in accordance to the supplied // mode. -func findMsgAndPrecursors(mode string, target *types.Message, msgs []api.Message) (related []*types.Message, found bool, err error) { +func findMsgAndPrecursors(mode string, msgCid cid.Cid, sender address.Address, msgs []api.Message) (related []*types.Message, found bool, err error) { // Range through canonicalised messages, selecting only the precursors based // on selection mode. for _, other := range msgs { switch { case mode == PrecursorSelectAll: fallthrough - case mode == PrecursorSelectSender && other.Message.From == target.From: + case mode == PrecursorSelectSender && other.Message.From == sender: related = append(related, other.Message) } // this message is the target; we're done. - if other.Cid == target.Cid() { + if other.Cid == msgCid { return related, true, nil } } From bb9d2b5af4ec7dc1b3406c4f25669202e97ded20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Kripalani?= Date: Fri, 20 Nov 2020 14:05:50 +0000 Subject: [PATCH 2/2] finish comment. --- cmd/tvx/extract.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/tvx/extract.go b/cmd/tvx/extract.go index 2e4aa3b50b..894fa0fbc3 100644 --- a/cmd/tvx/extract.go +++ b/cmd/tvx/extract.go @@ -73,7 +73,7 @@ var extractCmd = &cli.Command{ }, &cli.StringFlag{ Name: "exec-block", - Usage: "optionally, the block CID of a block where this message was executed, to aovid", + Usage: "optionally, the block CID of a block where this message was executed, to avoid expensive chain scanning", Destination: &extractFlags.block, }, &cli.StringFlag{