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

Frrist/parse vm message codec #1150

Merged
merged 1 commit into from
Mar 2, 2023
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
5 changes: 3 additions & 2 deletions commands/util/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os"
"strings"

"github.com/filecoin-project/lotus/chain/consensus"
"github.com/filecoin-project/lotus/chain/consensus/filcns"
"github.com/filecoin-project/lotus/chain/stmgr"
"github.com/filecoin-project/lotus/chain/store"
Expand Down Expand Up @@ -69,7 +70,7 @@ func ImportFromFsFile(ctx context.Context, r repo.Repo, fs fs.File, snapshot boo
return err
}

stm, err := stmgr.NewStateManager(cst, filcns.NewTipSetExecutor(), vm.Syscalls(ffiwrapper.ProofVerifier), filcns.DefaultUpgradeSchedule(), nil)
stm, err := stmgr.NewStateManager(cst, consensus.NewTipSetExecutor(filcns.RewardFunc), vm.Syscalls(ffiwrapper.ProofVerifier), filcns.DefaultUpgradeSchedule(), nil)
if err != nil {
return err
}
Expand Down Expand Up @@ -183,7 +184,7 @@ func ImportChain(ctx context.Context, r repo.Repo, fname string, snapshot bool)
return err
}

stm, err := stmgr.NewStateManager(cst, filcns.NewTipSetExecutor(), vm.Syscalls(ffiwrapper.ProofVerifier), filcns.DefaultUpgradeSchedule(), nil)
stm, err := stmgr.NewStateManager(cst, consensus.NewTipSetExecutor(filcns.RewardFunc), vm.Syscalls(ffiwrapper.ProofVerifier), filcns.DefaultUpgradeSchedule(), nil)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion extern/filecoin-ffi
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/filecoin-project/go-jsonrpc v0.2.1
github.com/filecoin-project/go-paramfetch v0.0.4
github.com/filecoin-project/go-state-types v0.10.0
github.com/filecoin-project/lotus v1.20.0
github.com/filecoin-project/lotus v1.20.1-0.20230302000218-dbbcf4b2ee96
github.com/filecoin-project/specs-actors v0.9.15
github.com/filecoin-project/specs-actors/v2 v2.3.6
github.com/filecoin-project/specs-actors/v3 v3.1.2
Expand Down Expand Up @@ -130,18 +130,16 @@ require (
github.com/filecoin-project/go-ds-versioning v0.1.2 // indirect
github.com/filecoin-project/go-fil-commcid v0.1.0 // indirect
github.com/filecoin-project/go-fil-commp-hashhash v0.1.0 // indirect
github.com/filecoin-project/go-fil-markets v1.25.2 // indirect
github.com/filecoin-project/go-fil-markets v1.26.0 // indirect
github.com/filecoin-project/go-hamt-ipld v0.1.5 // indirect
github.com/filecoin-project/go-hamt-ipld/v2 v2.0.0 // indirect
github.com/filecoin-project/go-legs v0.4.4 // indirect
github.com/filecoin-project/go-padreader v0.0.1 // indirect
github.com/filecoin-project/go-statemachine v1.0.2 // indirect
github.com/filecoin-project/go-statestore v0.2.0 // indirect
github.com/filecoin-project/go-storedcounter v0.1.0 // indirect
github.com/filecoin-project/index-provider v0.9.1 // indirect
github.com/filecoin-project/pubsub v1.0.0 // indirect
github.com/filecoin-project/specs-actors/v8 v8.0.1 // indirect
github.com/filecoin-project/storetheindex v0.4.30-0.20221114113647-683091f8e893 // indirect
github.com/flynn/noise v1.0.0 // indirect
github.com/francoispqt/gojay v1.2.13 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
Expand Down Expand Up @@ -220,6 +218,8 @@ require (
github.com/ipld/go-ipld-adl-hamt v0.0.0-20220616142416-9004dbd839e0 // indirect
github.com/ipld/go-ipld-prime v0.20.0 // indirect
github.com/ipld/go-ipld-selector-text-lite v0.0.1 // indirect
github.com/ipni/index-provider v0.10.0 // indirect
github.com/ipni/storetheindex v0.5.3-0.20221203123030-16745cb63f15 // indirect
github.com/ipsn/go-secp256k1 v0.0.0-20180726113642-9d62b9f0bc52 // indirect
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
github.com/jbenet/go-random v0.0.0-20190219211222-123a90aedc0c // indirect
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ github.com/filecoin-project/go-fil-commcid v0.1.0 h1:3R4ds1A9r6cr8mvZBfMYxTS88Oq
github.com/filecoin-project/go-fil-commcid v0.1.0/go.mod h1:Eaox7Hvus1JgPrL5+M3+h7aSPHc0cVqpSxA+TxIEpZQ=
github.com/filecoin-project/go-fil-commp-hashhash v0.1.0 h1:imrrpZWEHRnNqqv0tN7LXep5bFEVOVmQWHJvl2mgsGo=
github.com/filecoin-project/go-fil-commp-hashhash v0.1.0/go.mod h1:73S8WSEWh9vr0fDJVnKADhfIv/d6dCbAGaAGWbdJEI8=
github.com/filecoin-project/go-fil-markets v1.25.2 h1:kVfgaamTC7dkn8KwS5zRJBNEBSNvVqdG3BCoDaUYuCI=
github.com/filecoin-project/go-fil-markets v1.25.2/go.mod h1:dc2oTPU6GH3Qk1nA+Er+hSX64rg+NVykkPIWFBYxcZU=
github.com/filecoin-project/go-fil-markets v1.26.0 h1:uNtt1UAxX2C/Q8tlWD00oF2Zma3CVGxhZmBc2ljYhkk=
github.com/filecoin-project/go-fil-markets v1.26.0/go.mod h1:eOIYHfPwyqc64O1HiapvcelfnrTfU7gLQgBf55IYleQ=
github.com/filecoin-project/go-hamt-ipld v0.1.5 h1:uoXrKbCQZ49OHpsTCkrThPNelC4W3LPEk0OrS/ytIBM=
github.com/filecoin-project/go-hamt-ipld v0.1.5/go.mod h1:6Is+ONR5Cd5R6XZoCse1CWaXZc0Hdb/JeX+EQCQzX24=
github.com/filecoin-project/go-hamt-ipld/v2 v2.0.0 h1:b3UDemBYN2HNfk3KOXNuxgTTxlWi3xVvbQP0IT38fvM=
Expand Down Expand Up @@ -356,10 +356,8 @@ github.com/filecoin-project/go-statestore v0.2.0 h1:cRRO0aPLrxKQCZ2UOQbzFGn4WDNd
github.com/filecoin-project/go-statestore v0.2.0/go.mod h1:8sjBYbS35HwPzct7iT4lIXjLlYyPor80aU7t7a/Kspo=
github.com/filecoin-project/go-storedcounter v0.1.0 h1:Mui6wSUBC+cQGHbDUBcO7rfh5zQkWJM/CpAZa/uOuus=
github.com/filecoin-project/go-storedcounter v0.1.0/go.mod h1:4ceukaXi4vFURIoxYMfKzaRF5Xv/Pinh2oTnoxpv+z8=
github.com/filecoin-project/index-provider v0.9.1 h1:Jnh9dviIHvQxZ2baNoYu3n8z6F9O62ksnVlyREgPyyM=
github.com/filecoin-project/index-provider v0.9.1/go.mod h1:NlHxQcy2iMGfUoUGUzrRxntcpiC50QSnvp68u2VTT40=
github.com/filecoin-project/lotus v1.20.0 h1:Jm08hHbqjXFieNluVQL/SXWrqXnW2RP6b9bxKJ/GQig=
github.com/filecoin-project/lotus v1.20.0/go.mod h1:dprpVaiQezI8Jl4tWcPNIYGGAAo31feZlGAOk8D7bJU=
github.com/filecoin-project/lotus v1.20.1-0.20230302000218-dbbcf4b2ee96 h1:qtyxiKpJcsktp2EeL/OscVNbw1fRy8C5j9yeguA8AZY=
github.com/filecoin-project/lotus v1.20.1-0.20230302000218-dbbcf4b2ee96/go.mod h1:IgwxSgrL1HgkSexOjTHOIdaTUIvPOetuAjAqFQgHkSc=
github.com/filecoin-project/pubsub v1.0.0 h1:ZTmT27U07e54qV1mMiQo4HDr0buo8I1LDHBYLXlsNXM=
github.com/filecoin-project/pubsub v1.0.0/go.mod h1:GkpB33CcUtUNrLPhJgfdy4FDx4OMNR9k+46DHx/Lqrg=
github.com/filecoin-project/specs-actors v0.9.13/go.mod h1:TS1AW/7LbG+615j4NsjMK1qlpAwaFsG9w0V2tg2gSao=
Expand All @@ -380,8 +378,6 @@ github.com/filecoin-project/specs-actors/v7 v7.0.1 h1:w72xCxijK7xs1qzmJiw+WYJaVt
github.com/filecoin-project/specs-actors/v7 v7.0.1/go.mod h1:tPLEYXoXhcpyLh69Ccq91SOuLXsPWjHiY27CzawjUEk=
github.com/filecoin-project/specs-actors/v8 v8.0.1 h1:4u0tIRJeT5G7F05lwLRIsDnsrN+bJ5Ixj6h49Q7uE2Y=
github.com/filecoin-project/specs-actors/v8 v8.0.1/go.mod h1:UYIPg65iPWoFw5NEftREdJwv9b/5yaLKdCgTvNI/2FA=
github.com/filecoin-project/storetheindex v0.4.30-0.20221114113647-683091f8e893 h1:6GCuzxLVHBzlz7y+FkbHh6n0UyoEGWqDwJKQPJoz7bE=
github.com/filecoin-project/storetheindex v0.4.30-0.20221114113647-683091f8e893/go.mod h1:S7590oDimBvXMUtzWsBXoshu9HtYKwtXl47zAK9rcP8=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/flynn/noise v0.0.0-20180327030543-2492fe189ae6/go.mod h1:1i71OnUq3iUe1ma7Lr6yG6/rjvM3emb6yoL7xLFzcVQ=
github.com/flynn/noise v1.0.0 h1:DlTHqmzmvcEiKj+4RYo/imoswx/4r6iBlCMfVtrMXpQ=
Expand Down Expand Up @@ -882,6 +878,10 @@ github.com/ipld/go-ipld-prime/storage/bsadapter v0.0.0-20211210234204-ce2a1c70cd
github.com/ipld/go-ipld-prime/storage/bsadapter v0.0.0-20211210234204-ce2a1c70cd73/go.mod h1:2PJ0JgxyB08t0b2WKrcuqI3di0V+5n6RS/LTUJhkoxY=
github.com/ipld/go-ipld-selector-text-lite v0.0.1 h1:lNqFsQpBHc3p5xHob2KvEg/iM5dIFn6iw4L/Hh+kS1Y=
github.com/ipld/go-ipld-selector-text-lite v0.0.1/go.mod h1:U2CQmFb+uWzfIEF3I1arrDa5rwtj00PrpiwwCO+k1RM=
github.com/ipni/index-provider v0.10.0 h1:nu8YBxzRopdjwZHsgCUuC4AHpq88VVHJYrbkqUDx7eg=
github.com/ipni/index-provider v0.10.0/go.mod h1:InSXbZp2p/ZhAwiDElG/wzjnA1ea1iJ3hhyiAHrD+Vo=
github.com/ipni/storetheindex v0.5.3-0.20221203123030-16745cb63f15 h1:qJq6QtLk+9nQi3CDBhNfJ1cjZ4pghjCHcQUZ1mWbF0k=
github.com/ipni/storetheindex v0.5.3-0.20221203123030-16745cb63f15/go.mod h1:c/NS640Iu2NrCCIErnUhsUM5KVEyeXymgtNnx6eDwMU=
github.com/ipsn/go-secp256k1 v0.0.0-20180726113642-9d62b9f0bc52 h1:QG4CGBqCeuBo6aZlGAamSkxWdgWfZGeE49eUOWJPA4c=
github.com/ipsn/go-secp256k1 v0.0.0-20180726113642-9d62b9f0bc52/go.mod h1:fdg+/X9Gg4AsAIzWpEHwnqd+QY3b7lajxyjE1m4hkq4=
github.com/jackpal/gateway v1.0.5/go.mod h1:lTpwd4ACLXmpyiCTRtfiNyVnUmqT9RivzCDQetPfnjA=
Expand Down
4 changes: 2 additions & 2 deletions lens/lily/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/filecoin-project/go-state-types/exitcode"
network2 "github.com/filecoin-project/go-state-types/network"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/chain/consensus/filcns"
"github.com/filecoin-project/lotus/chain/consensus"
"github.com/filecoin-project/lotus/chain/events"
"github.com/filecoin-project/lotus/chain/state"
"github.com/filecoin-project/lotus/chain/stmgr"
Expand Down Expand Up @@ -701,7 +701,7 @@ func (m *LilyNodeAPI) BurnFundsFn(ctx context.Context, ts *types.TipSet) (lens.S
StateBase: ts.ParentState(),
Epoch: ts.Height(),
Bstore: m.ChainAPI.Chain.StateBlockstore(),
Actors: filcns.NewActorRegistry(),
Actors: consensus.NewActorRegistry(),
Syscalls: m.StateManager.Syscalls,
CircSupplyCalc: m.StateManager.GetVMCirculatingSupply,
NetworkVersion: util.DefaultNetwork.Version(ctx, ts.Height()),
Expand Down
57 changes: 48 additions & 9 deletions lens/util/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"fmt"
"reflect"
"strings"
"time"

"github.com/filecoin-project/go-bitfield"
"github.com/filecoin-project/lotus/chain/consensus"
"github.com/ipfs/go-cid"
logging "github.com/ipfs/go-log/v2"
cbg "github.com/whyrusleeping/cbor-gen"
Expand All @@ -19,7 +19,6 @@ import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
builtin "github.com/filecoin-project/lotus/chain/actors/builtin"
"github.com/filecoin-project/lotus/chain/consensus/filcns"
"github.com/filecoin-project/lotus/chain/state"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/vm"
Expand All @@ -31,11 +30,55 @@ import (
var ActorRegistry *vm.ActorRegistry

func init() {
ActorRegistry = filcns.NewActorRegistry()
ActorRegistry = consensus.NewActorRegistry()
}

var log = logging.Logger("lily/lens")

func ParseVmMessageParams(params []byte, paramsCodec uint64, method abi.MethodNum, actCode cid.Cid) (string, string, error) {
m, found := ActorRegistry.Methods[actCode][method]
if !found {
// if the method wasn't found it is likely the case the method was one of:
// https://github.com/filecoin-project/builtin-actors/blob/f5311fe735df4d9baf5f82d4b3db10f3c51688c4/actors/docs/README.md?plain=1#L31
// so we just marshal the raw value to json and bail with a warning
paramj, err := json.Marshal(params)
if err != nil {
return "", "", err
}
err = fmt.Errorf("unknown method %d with codec %d for actorCode %s name %s", method, paramsCodec, actCode, builtin.ActorNameByCode(actCode))
log.Warnw("parsing vm message params", "error", err)
return string(paramj), builtin.ActorNameByCode(actCode), nil
}
// If the codec is 0, the parameters/return value are "empty".
// If the codec is 0x55, it's bytes.
if paramsCodec == 0 || paramsCodec == 0x55 {
return string(params), m.Name, nil
}
return ParseParams(params, method, actCode)
}

func ParseVmMessageReturn(ret []byte, retCodec uint64, method abi.MethodNum, actCode cid.Cid) (string, string, error) {
m, found := ActorRegistry.Methods[actCode][method]
if !found {
// if the method wasn't found it is likely the case the method was one of:
// https://github.com/filecoin-project/builtin-actors/blob/f5311fe735df4d9baf5f82d4b3db10f3c51688c4/actors/docs/README.md?plain=1#L31
// so we just marshal the raw value to json and bail with a warning
retJ, err := json.Marshal(ret)
if err != nil {
return "", "", err
}
err = fmt.Errorf("unknown method %d with codec %d for actorCode %s name %s", method, retCodec, actCode, builtin.ActorNameByCode(actCode))
log.Warnw("parsing vm message return", "error", err)
return string(retJ), builtin.ActorNameByCode(actCode), nil
}
// If the codec is 0, the parameters/return value are "empty".
// If the codec is 0x55, it's bytes.
if retCodec == 0 || retCodec == 0x55 {
return string(ret), m.Name, nil
}
return ParseReturn(ret, method, actCode)
}

Comment on lines +38 to +81
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Special handling for vm message params and returns please review this section, other changes are mechanical

func ParseParams(params []byte, method abi.MethodNum, actCode cid.Cid) (_ string, _ string, err error) {
m, found := ActorRegistry.Methods[actCode][method]
if !found {
Expand Down Expand Up @@ -141,10 +184,8 @@ type MessageParamsReturn struct {
}

type MessageTrace struct {
Message *types.Message
Receipt *types.MessageReceipt
Error string
Duration time.Duration
Message types.MessageTrace
Receipt types.ReturnTrace
GasCharge []*types.GasTrace
Index uint64
}
Expand All @@ -161,8 +202,6 @@ func walkExecutionTrace(et *types.ExecutionTrace, trace *[]*MessageTrace, index
*trace = append(*trace, &MessageTrace{
Message: sub.Msg,
Receipt: sub.MsgRct,
Error: sub.Error,
Duration: sub.Duration,
GasCharge: sub.GasCharges,
Index: *index,
})
Expand Down
22 changes: 18 additions & 4 deletions tasks/messageexecutions/vm/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/lotus/chain/types"
"github.com/ipfs/go-cid"
logging "github.com/ipfs/go-log/v2"
Expand Down Expand Up @@ -98,7 +99,20 @@ func (t *Task) ProcessTipSets(ctx context.Context, current *types.TipSet, execut
// NB: the getActorCode method is the expensive call since it resolves addresses and may load the statetree.
for _, child := range util.GetChildMessagesOf(parentMsg) {
// Cid() computes a CID, so only call it once
childCid := child.Message.Cid()
childMsg := &types.Message{
To: child.Message.To,
From: child.Message.From,
Value: child.Message.Value,
Method: child.Message.Method,
Params: child.Message.Params,
// these fields were deprecated in https://github.com/filecoin-project/lotus/commit/dbbcf4b2ee9626796e23a096c66e67ff350810e4
Version: 0,
GasLimit: 0,
Nonce: 0,
GasFeeCap: abi.NewTokenAmount(0),
GasPremium: abi.NewTokenAmount(0),
}
childCid := childMsg.Cid()

toCode, found := getActorCode(ctx, child.Message.To)
if !found && child.Receipt.ExitCode == 0 {
Expand Down Expand Up @@ -129,7 +143,7 @@ func (t *Task) ProcessTipSets(ctx context.Context, current *types.TipSet, execut
From: child.Message.From.String(),
To: child.Message.To.String(),
Value: child.Message.Value.String(),
GasUsed: child.Receipt.GasUsed,
GasUsed: 0,
ExitCode: int64(child.Receipt.ExitCode),
ActorCode: toActorCode,
Method: uint64(child.Message.Method),
Expand All @@ -142,7 +156,7 @@ func (t *Task) ProcessTipSets(ctx context.Context, current *types.TipSet, execut
// As an example: a message may return ErrForbidden, it will have valid params, but will not contain a
// parsable return value in its receipt.
if child.Receipt.ExitCode.IsSuccess() {
params, _, err := util.ParseParams(child.Message.Params, child.Message.Method, toCode)
params, _, err := util.ParseVmMessageParams(child.Message.Params, child.Message.ParamsCodec, child.Message.Method, toCode)
if err != nil {
// a failure here indicates an error in message param parsing, or in exitcode checks above.
errorsDetected = append(errorsDetected, &messages.MessageError{
Expand All @@ -156,7 +170,7 @@ func (t *Task) ProcessTipSets(ctx context.Context, current *types.TipSet, execut
vmMsg.Params = params
}

ret, _, err := util.ParseReturn(child.Receipt.Return, child.Message.Method, toCode)
ret, _, err := util.ParseVmMessageReturn(child.Receipt.Return, child.Receipt.ReturnCodec, child.Message.Method, toCode)
if err != nil {
errorsDetected = append(errorsDetected, &messages.MessageError{
Cid: parentMsg.Cid,
Expand Down