tvx: widen 'sender' precursor strategy to match against both participants.

And also use inclusion tipset to run the message, which is more correct
than the execution tipset.
This commit is contained in:
Raúl Kripalani 2022-03-10 22:13:08 +00:00
parent ba408cc2be
commit 92c9716595
3 changed files with 45 additions and 22 deletions

View File

@ -13,8 +13,8 @@ import (
) )
const ( const (
PrecursorSelectAll = "all" PrecursorSelectAll = "all"
PrecursorSelectSender = "sender" PrecursorSelectParticipants = "participants"
) )
type extractOpts struct { type extractOpts struct {
@ -86,12 +86,12 @@ var extractCmd = &cli.Command{
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: "precursor-select", Name: "precursor-select",
Usage: "precursors to apply; values: 'all', 'sender'; 'all' selects all preceding " + Usage: "precursors to apply; values: 'all', 'participants'; 'all' selects all preceding " +
"messages in the canonicalised tipset, 'sender' selects only preceding messages from the same " + "messages in the canonicalised tipset, 'participants' selects only preceding messages from the same " +
"sender. Usually, 'sender' is a good tradeoff and gives you sufficient accuracy. If the receipt sanity " + "participants. Usually, 'participants' is a good tradeoff and gives you sufficient accuracy. If the receipt sanity " +
"check fails due to gas reasons, switch to 'all', as previous messages in the tipset may have " + "check fails due to gas reasons, switch to 'all', as previous messages in the tipset may have " +
"affected state in a disruptive way", "affected state in a disruptive way",
Value: "sender", Value: "participants",
Destination: &extractFlags.precursor, Destination: &extractFlags.precursor,
}, },
&cli.BoolFlag{ &cli.BoolFlag{

View File

@ -13,11 +13,12 @@ import (
"github.com/fatih/color" "github.com/fatih/color"
"github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/exitcode" "github.com/filecoin-project/go-state-types/exitcode"
"github.com/filecoin-project/lotus/chain/consensus/filcns"
"github.com/hashicorp/go-multierror" "github.com/hashicorp/go-multierror"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
"github.com/multiformats/go-multihash" "github.com/multiformats/go-multihash"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
"github.com/filecoin-project/lotus/chain/consensus/filcns"
) )
var extractManyFlags struct { var extractManyFlags struct {
@ -176,7 +177,7 @@ func runExtractMany(c *cli.Context) error {
// Vector filename, using a base of outdir. // Vector filename, using a base of outdir.
file := filepath.Join(outdir, actorcodename, methodname, exitcodename, id) + ".json" file := filepath.Join(outdir, actorcodename, methodname, exitcodename, id) + ".json"
log.Println(color.YellowString("processing message cid with 'sender' precursor mode: %s", id)) log.Println(color.YellowString("processing message cid with 'participants' precursor mode: %s", id))
opts := extractOpts{ opts := extractOpts{
id: id, id: id,
@ -185,7 +186,7 @@ func runExtractMany(c *cli.Context) error {
cid: mcid, cid: mcid,
file: file, file: file,
retain: "accessed-cids", retain: "accessed-cids",
precursor: PrecursorSelectSender, precursor: PrecursorSelectParticipants,
} }
if err := doExtractMessage(opts); err != nil { if err := doExtractMessage(opts); err != nil {
@ -199,7 +200,7 @@ func runExtractMany(c *cli.Context) error {
generated = append(generated, file) generated = append(generated, file)
} }
log.Printf("extractions to try with canonical precursor selection mode: %d", len(retry)) log.Printf("extractions to try with 'all' precursor selection mode: %d", len(retry))
for _, r := range retry { for _, r := range retry {
log.Printf("retrying %s: %s", r.cid, r.id) log.Printf("retrying %s: %s", r.cid, r.id)

View File

@ -71,7 +71,7 @@ func doExtractMessage(opts extractOpts) error {
return fmt.Errorf("failed to fetch messages in canonical order from inclusion tipset: %w", err) return fmt.Errorf("failed to fetch messages in canonical order from inclusion tipset: %w", err)
} }
related, found, err := findMsgAndPrecursors(opts.precursor, mcid, msg.From, msgs) related, found, err := findMsgAndPrecursors(ctx, opts.precursor, mcid, msg.From, msg.To, msgs)
if err != nil { if err != nil {
return fmt.Errorf("failed while finding message and precursors: %w", err) return fmt.Errorf("failed while finding message and precursors: %w", err)
} }
@ -114,7 +114,7 @@ func doExtractMessage(opts extractOpts) error {
log.Printf("applying precursor %d, cid: %s", i, m.Cid()) log.Printf("applying precursor %d, cid: %s", i, m.Cid())
_, root, err = driver.ExecuteMessage(pst.Blockstore, conformance.ExecuteMessageParams{ _, root, err = driver.ExecuteMessage(pst.Blockstore, conformance.ExecuteMessageParams{
Preroot: root, Preroot: root,
Epoch: execTs.Height(), Epoch: incTs.Height(),
Message: m, Message: m,
CircSupply: circSupplyDetail.FilCirculating, CircSupply: circSupplyDetail.FilCirculating,
BaseFee: basefee, BaseFee: basefee,
@ -139,6 +139,7 @@ func doExtractMessage(opts extractOpts) error {
) )
log.Printf("using state retention strategy: %s", retention) log.Printf("using state retention strategy: %s", retention)
log.Printf("now applying requested message: %s", msg.Cid())
switch retention { switch retention {
case "accessed-cids": case "accessed-cids":
tbs, ok := pst.Blockstore.(TracingBlockstore) tbs, ok := pst.Blockstore.(TracingBlockstore)
@ -151,7 +152,7 @@ func doExtractMessage(opts extractOpts) error {
preroot = root preroot = root
applyret, postroot, err = driver.ExecuteMessage(pst.Blockstore, conformance.ExecuteMessageParams{ applyret, postroot, err = driver.ExecuteMessage(pst.Blockstore, conformance.ExecuteMessageParams{
Preroot: preroot, Preroot: preroot,
Epoch: execTs.Height(), Epoch: incTs.Height(),
Message: msg, Message: msg,
CircSupply: circSupplyDetail.FilCirculating, CircSupply: circSupplyDetail.FilCirculating,
BaseFee: basefee, BaseFee: basefee,
@ -184,7 +185,7 @@ func doExtractMessage(opts extractOpts) error {
} }
applyret, postroot, err = driver.ExecuteMessage(pst.Blockstore, conformance.ExecuteMessageParams{ applyret, postroot, err = driver.ExecuteMessage(pst.Blockstore, conformance.ExecuteMessageParams{
Preroot: preroot, Preroot: preroot,
Epoch: execTs.Height(), Epoch: incTs.Height(),
Message: msg, Message: msg,
CircSupply: circSupplyDetail.FilCirculating, CircSupply: circSupplyDetail.FilCirculating,
BaseFee: basefee, BaseFee: basefee,
@ -299,7 +300,7 @@ func doExtractMessage(opts extractOpts) error {
CAR: out.Bytes(), CAR: out.Bytes(),
Pre: &schema.Preconditions{ Pre: &schema.Preconditions{
Variants: []schema.Variant{ Variants: []schema.Variant{
{ID: codename, Epoch: int64(execTs.Height()), NetworkVersion: uint(nv)}, {ID: codename, Epoch: int64(incTs.Height()), NetworkVersion: uint(nv)},
}, },
CircSupply: circSupply.Int, CircSupply: circSupply.Int,
BaseFee: basefee.Int, BaseFee: basefee.Int,
@ -403,19 +404,40 @@ func fetchThisAndPrevTipset(ctx context.Context, api v0api.FullNode, target type
// findMsgAndPrecursors ranges through the canonical messages slice, locating // findMsgAndPrecursors ranges through the canonical messages slice, locating
// the target message and returning precursors in accordance to the supplied // the target message and returning precursors in accordance to the supplied
// mode. // mode.
func findMsgAndPrecursors(mode string, msgCid cid.Cid, sender address.Address, msgs []api.Message) (related []*types.Message, found bool, err error) { func findMsgAndPrecursors(ctx context.Context, mode string, msgCid cid.Cid, sender address.Address, recipient address.Address, msgs []api.Message) (related []*types.Message, found bool, err error) {
// Range through canonicalised messages, selecting only the precursors based // Resolve addresses to IDs for canonicality.
// on selection mode. senderID, err := FullAPI.StateLookupID(ctx, sender, types.EmptyTSK)
for _, other := range msgs { if err != nil {
return nil, false, err
}
recipientID, err := FullAPI.StateLookupID(ctx, recipient, types.EmptyTSK)
if err != nil {
return nil, false, err
}
// Range through messages, selecting only the precursors based on selection mode.
for _, m := range msgs {
msgSenderID, err := FullAPI.StateLookupID(ctx, m.Message.From, types.EmptyTSK)
if err != nil {
return nil, false, err
}
msgRecipientID, err := FullAPI.StateLookupID(ctx, m.Message.To, types.EmptyTSK)
if err != nil {
return nil, false, err
}
switch { switch {
case mode == PrecursorSelectAll: case mode == PrecursorSelectAll:
fallthrough fallthrough
case mode == PrecursorSelectSender && other.Message.From == sender: case mode == PrecursorSelectParticipants &&
related = append(related, other.Message) msgSenderID == senderID ||
msgRecipientID == recipientID ||
msgSenderID == recipientID ||
msgRecipientID == senderID:
related = append(related, m.Message)
} }
// this message is the target; we're done. // this message is the target; we're done.
if other.Cid == msgCid { if m.Cid == msgCid {
return related, true, nil return related, true, nil
} }
} }