Skip to content
Closed
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
10 changes: 0 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,6 @@ $(toolspath)/bin/golangci-lint: $(toolspath)/go.mod
@mkdir -p $(dir $@)
(cd $(toolspath); go build -tags tools -o $(@:$(toolspath)/%=%) github.com/golangci/golangci-lint/cmd/golangci-lint)

$(toolspath)/bin/gen: $(toolspath)/go.mod
@mkdir -p $(dir $@)
(cd $(toolspath); go build -tags tools -o $(@:$(toolspath)/%=%) github.com/filecoin-project/statediff/types/gen)


.PHONY: lint
lint: $(toolspath)/bin/golangci-lint
$(toolspath)/bin/golangci-lint run ./...
Expand All @@ -131,11 +126,6 @@ actors-gen:
go fmt ./...


.PHONY: types-gen
types-gen: $(toolspath)/bin/gen
$(toolspath)/bin/gen ./tasks/messages/types
go fmt ./tasks/messages/types/...

# dev-nets
2k: GOFLAGS+=-tags=2k
2k: build
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ require (
github.com/ipfs/go-log/v2 v2.3.0
github.com/ipfs/go-metrics-prometheus v0.0.2
github.com/ipld/go-car v0.3.2-0.20211001225732-32d0d9933823
github.com/ipld/go-ipld-prime v0.12.3
github.com/kr/text v0.2.0 // indirect
github.com/lib/pq v1.9.0
github.com/libp2p/go-libp2p-core v0.9.0
Expand All @@ -43,7 +42,6 @@ require (
github.com/mitchellh/go-homedir v1.1.0
github.com/multiformats/go-multiaddr v0.4.0
github.com/multiformats/go-multihash v0.0.15
github.com/polydawn/refmt v0.0.0-20201211092308-30ac6d18308e
github.com/prometheus/client_golang v1.11.0
github.com/raulk/clock v1.1.0
github.com/russross/blackfriday/v2 v2.1.0 // indirect
Expand Down
75 changes: 52 additions & 23 deletions lens/util/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,37 @@ package util
import (
"bytes"
"context"
"go.opentelemetry.io/otel"
"encoding/json"
"fmt"
"reflect"
"strings"

"github.com/ipfs/go-cid"
logging "github.com/ipfs/go-log/v2"
cbg "github.com/whyrusleeping/cbor-gen"
"go.opentelemetry.io/otel"
"golang.org/x/xerrors"

"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/store"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/vm"
"github.com/filecoin-project/specs-actors/actors/util/adt"
"github.com/ipfs/go-cid"
logging "github.com/ipfs/go-log/v2"
"github.com/ipld/go-ipld-prime"
"golang.org/x/xerrors"

builtininit "github.com/filecoin-project/lily/chain/actors/builtin/init"
"github.com/filecoin-project/lily/lens"
"github.com/filecoin-project/lily/tasks/messages"
"github.com/filecoin-project/lily/tasks/messages/fcjson"
)

var ActorRegistry *vm.ActorRegistry

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

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

// GetMessagesForTipset returns a list of messages sent as part of pts (parent) with receipts found in ts (child).
Expand Down Expand Up @@ -205,33 +215,52 @@ func GetExecutedAndBlockMessagesForTipset(ctx context.Context, cs *store.ChainSt
}, nil
}

func ParseParams(params []byte, method abi.MethodNum, actCode cid.Cid) (string, string, error) {
m, found := ActorRegistry.Methods[actCode][method]
if !found {
return "", "", fmt.Errorf("unknown method %d for actor %s", method, actCode)
}

// if the actor method doesn't expect params don't parse them
// messages can contain unexpected params and remain valid, we need to ignore this case for parsing.
if m.Params == reflect.TypeOf(new(abi.EmptyValue)) {
return "", m.Name, nil
}

p := reflect.New(m.Params.Elem()).Interface().(cbg.CBORUnmarshaler)
if err := p.UnmarshalCBOR(bytes.NewReader(params)); err != nil {
actorName := builtin.ActorNameByCode(actCode)
return "", m.Name, fmt.Errorf("cbor decode into %s %s:(%s.%d) failed: %v", m.Name, actorName, actCode, method, err)
}

b, err := json.Marshal(p)
return string(b), m.Name, err
}

func MethodAndParamsForMessage(m *types.Message, destCode cid.Cid) (string, string, error) {
var params ipld.Node
var method string
var err error
// Method is optional, zero means a plain value transfer
if m.Method == 0 {
return "Send", "", nil
}

if !destCode.Defined() {
return "Unknown", "", xerrors.Errorf("missing actor code")
}

// fall back to generic cbor->json conversion.
params, method, err = messages.ParseParams(m.Params, int64(m.Method), destCode)
params, method, err := ParseParams(m.Params, m.Method, destCode)
if method == "Unknown" {
return "", "", xerrors.Errorf("unknown method for actor type %s: %d", destCode.String(), int64(m.Method))
}
if err != nil {
log.Warnf("failed to parse parameters of message %s: %v", m.Cid(), err)
log.Warnf("failed to parse parameters of message %s: %v", m.Cid, err)
// this can occur when the message is not valid cbor
return method, "", xerrors.Errorf("failed to parse parameters of message %s: %w", m.Cid(), err)
return method, "", err
}
if params == nil {
if params == "" {
return method, "", nil
}

buf := bytes.NewBuffer(nil)
if err := fcjson.Encoder(params, buf); err != nil {
return "", "", xerrors.Errorf("json encode message params: %w", err)
}

encoded := string(bytes.ReplaceAll(bytes.ToValidUTF8(buf.Bytes(), []byte{}), []byte{0x00}, []byte{}))

return method, encoded, nil
return method, params, nil
}

func ActorNameAndFamilyFromCode(c cid.Cid) (name string, family string, err error) {
Expand Down
5 changes: 1 addition & 4 deletions support/tools/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,4 @@ module github.com/filecoin-project/sentinel-lily/support/tools

go 1.16

require (
github.com/Kubuxu/go-no-map-range v0.0.1
github.com/filecoin-project/statediff v0.0.26
)
require github.com/Kubuxu/go-no-map-range v0.0.1
Loading