Skip to content

Commit

Permalink
Multisig parser (#196)
Browse files Browse the repository at this point in the history
* Multisig parser

* linting issues

* minor fixes

* get tipsetkey by cids

* fixes and test

* add log to debug

* multisig tests

* multisig tests

* minor changes
  • Loading branch information
lucaslopezf authored Jun 14, 2024
1 parent f162c2e commit 23cfd93
Show file tree
Hide file tree
Showing 88 changed files with 652 additions and 24 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,5 @@ fabric.properties
# Ignore all local history of files
.history
.ionide

cmd/tracedl/tracedl
16 changes: 12 additions & 4 deletions cmd/tracedl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
Helper tool to download raw logs from a node for testing purposes.

### Usage
Replace values in `config.yaml` with desired values.

Replace values in `config.yaml` with desired values.

```
go build
Expand All @@ -18,12 +18,20 @@ go build

Download native logs and store as gzip.

`./tracedl get --type nativelog --compress gz --height 3897964`
`./tracedl get --type nativelog --compress gz --height 3897964 --outPath ../../data/heights`

Download eth logs and store as gzip.

`./tracedl get --type ethlog --compress gz --height 3897964`
`./tracedl get --type ethlog --compress gz --height 3897964 --outPath ../../data/heights`

Download tipset and store as gzip.

`./tracedl get --type tipset --compress gz --height 3897964`
`./tracedl get --type tipset --compress gz --height 3897964 --outPath ../../data/heights`

---
You can use the `script.sh` to automate the download of traces, native logs, eth logs, and tipsets for specified heights.

1. Open `script.sh` and modify the heights array with the desired heights.
2. Run the script:

`./script.sh`
4 changes: 2 additions & 2 deletions cmd/tracedl/config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
network_name: "mainnet"
network_name: "calibration"
symbol: "fil"
node_url: "wss://node-fil-mainnet-next.zondax.ch/rpc/v1"
node_url: "wss://node-fil-calibration-next.zondax.ch/rpc/v1"
node_token: ""
18 changes: 18 additions & 0 deletions cmd/tracedl/script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# Heights to download traces, native logs, eth logs, and tipsets
heights=(1698055 1576593 1572087 1552242 1352134 1334035 1289201 1258459 1256171)

# Function to download files
download_files() {
local height=$1
./tracedl get --type traces --compress gz --height "$height" --outPath ../../data/heights
./tracedl get --type nativelog --compress gz --height "$height" --outPath ../../data/heights
./tracedl get --type ethlog --compress gz --height "$height" --outPath ../../data/heights
./tracedl get --type tipset --compress gz --height "$height" --outPath ../../data/heights
}

# Download files for each height
for height in "${heights[@]}"; do
download_files "$height"
done
Binary file added data/heights/ethlog_1162295.json.gz
Binary file not shown.
Binary file added data/heights/ethlog_1256171.json.gz
Binary file not shown.
Binary file added data/heights/ethlog_1258459.json.gz
Binary file not shown.
Binary file added data/heights/ethlog_1289201.json.gz
Binary file not shown.
Binary file added data/heights/ethlog_1334035.json.gz
Binary file not shown.
Binary file added data/heights/ethlog_1352134.json.gz
Binary file not shown.
Binary file added data/heights/ethlog_14107.json.gz
Binary file not shown.
Binary file added data/heights/ethlog_1467665.json.gz
Binary file not shown.
Binary file added data/heights/ethlog_1552242.json.gz
Binary file not shown.
Binary file added data/heights/ethlog_1572087.json.gz
Binary file not shown.
Binary file added data/heights/ethlog_1576593.json.gz
Binary file not shown.
Binary file added data/heights/ethlog_1698055.json.gz
Binary file not shown.
Binary file added data/heights/ethlog_197673.json.gz
Binary file not shown.
Binary file added data/heights/ethlog_38895.json.gz
Binary file not shown.
Binary file added data/heights/ethlog_38940.json.gz
Binary file not shown.
Binary file added data/heights/ethlog_39035.json.gz
Binary file not shown.
Binary file added data/heights/ethlog_47635.json.gz
Binary file not shown.
Binary file added data/heights/ethlog_47645.json.gz
Binary file not shown.
Binary file added data/heights/ethlog_78689.json.gz
Binary file not shown.
Binary file added data/heights/nativelog_1162295.json.gz
Binary file not shown.
Binary file added data/heights/nativelog_1256171.json.gz
Binary file not shown.
Binary file added data/heights/nativelog_1258459.json.gz
Binary file not shown.
Binary file added data/heights/nativelog_1289201.json.gz
Binary file not shown.
Binary file added data/heights/nativelog_1334035.json.gz
Binary file not shown.
Binary file added data/heights/nativelog_1352134.json.gz
Binary file not shown.
Binary file added data/heights/nativelog_14107.json.gz
Binary file not shown.
Binary file added data/heights/nativelog_1467665.json.gz
Binary file not shown.
Binary file added data/heights/nativelog_1552242.json.gz
Binary file not shown.
Binary file added data/heights/nativelog_1572087.json.gz
Binary file not shown.
Binary file added data/heights/nativelog_1576593.json.gz
Binary file not shown.
Binary file added data/heights/nativelog_1698055.json.gz
Binary file not shown.
Binary file added data/heights/nativelog_197673.json.gz
Binary file not shown.
Binary file added data/heights/nativelog_38895.json.gz
Binary file not shown.
Binary file added data/heights/nativelog_38940.json.gz
Binary file not shown.
Binary file added data/heights/nativelog_39035.json.gz
Binary file not shown.
Binary file added data/heights/nativelog_47635.json.gz
Binary file not shown.
Binary file added data/heights/nativelog_47645.json.gz
Binary file not shown.
Binary file added data/heights/nativelog_78689.json.gz
Binary file not shown.
Binary file added data/heights/tipset_1162295.json.gz
Binary file not shown.
Binary file added data/heights/tipset_1256171.json.gz
Binary file not shown.
Binary file added data/heights/tipset_1258459.json.gz
Binary file not shown.
Binary file added data/heights/tipset_1289201.json.gz
Binary file not shown.
Binary file added data/heights/tipset_1334035.json.gz
Binary file not shown.
Binary file added data/heights/tipset_1352134.json.gz
Binary file not shown.
Binary file added data/heights/tipset_14107.json.gz
Binary file not shown.
Binary file added data/heights/tipset_1467665.json.gz
Binary file not shown.
Binary file added data/heights/tipset_1552242.json.gz
Binary file not shown.
Binary file added data/heights/tipset_1572087.json.gz
Binary file not shown.
Binary file added data/heights/tipset_1576593.json.gz
Binary file not shown.
Binary file added data/heights/tipset_1698055.json.gz
Binary file not shown.
Binary file added data/heights/tipset_197673.json.gz
Binary file not shown.
Binary file added data/heights/tipset_38895.json.gz
Binary file not shown.
Binary file added data/heights/tipset_38940.json.gz
Binary file not shown.
Binary file added data/heights/tipset_39035.json.gz
Binary file not shown.
Binary file added data/heights/tipset_47635.json.gz
Binary file not shown.
Binary file added data/heights/tipset_47645.json.gz
Binary file not shown.
Binary file added data/heights/tipset_78689.json.gz
Binary file not shown.
Binary file added data/heights/traces_1162295.json.gz
Binary file not shown.
Binary file added data/heights/traces_1256171.json.gz
Binary file not shown.
Binary file added data/heights/traces_1258459.json.gz
Binary file not shown.
Binary file added data/heights/traces_1289201.json.gz
Binary file not shown.
Binary file added data/heights/traces_1334035.json.gz
Binary file not shown.
Binary file added data/heights/traces_1352134.json.gz
Binary file not shown.
Binary file added data/heights/traces_14107.json.gz
Binary file not shown.
Binary file added data/heights/traces_1467665.json.gz
Binary file not shown.
Binary file added data/heights/traces_1552242.json.gz
Binary file not shown.
Binary file added data/heights/traces_1572087.json.gz
Binary file not shown.
Binary file added data/heights/traces_1576593.json.gz
Binary file not shown.
Binary file added data/heights/traces_1698055.json.gz
Binary file not shown.
Binary file added data/heights/traces_197673.json.gz
Binary file not shown.
Binary file added data/heights/traces_38895.json.gz
Binary file not shown.
Binary file added data/heights/traces_38940.json.gz
Binary file not shown.
Binary file added data/heights/traces_39035.json.gz
Binary file not shown.
Binary file added data/heights/traces_47635.json.gz
Binary file not shown.
Binary file added data/heights/traces_47645.json.gz
Binary file not shown.
Binary file added data/heights/traces_78689.json.gz
Binary file not shown.
10 changes: 10 additions & 0 deletions factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/go-state-types/manifest"
types2 "github.com/filecoin-project/lotus/chain/types"
"github.com/google/uuid"
"github.com/zondax/fil-parser/actors/cache"
Expand Down Expand Up @@ -40,6 +41,7 @@ type Parser interface {
NodeVersionsSupported() []string
ParseTransactions(ctx context.Context, txsData types.TxsData) (*types.TxsParsedResult, error)
ParseNativeEvents(ctx context.Context, eventsData types.EventsData) (*types.EventsParsedResult, error)
ParseMultisigEvents(ctx context.Context, multisigTxs []*types.Transaction, tipsetCid string, tipsetKey types2.TipSetKey) (*types.MultisigEvents, error)
ParseEthLogs(ctx context.Context, eventsData types.EventsData) (*types.EventsParsedResult, error)
GetBaseFee(traces []byte, tipset *types.ExtendedTipSet) (uint64, error)
IsNodeVersionSupported(ver string) bool
Expand Down Expand Up @@ -141,6 +143,14 @@ func (p *FilecoinParser) ParseEthLogs(ctx context.Context, eventsData types.Even
return parsedResult, nil
}

func (p *FilecoinParser) ParseMultisigEvents(ctx context.Context, txs []*types.Transaction, tipsetCid string, tipsetKey types2.TipSetKey) (*types.MultisigEvents, error) {
multisigTxs, err := p.Helper.FilterTxsByActorType(ctx, txs, manifest.MultisigKey, tipsetKey)
if err != nil {
return nil, err
}
return p.parserV2.ParseMultisigEvents(ctx, multisigTxs, tipsetCid, tipsetKey)
}

func (p *FilecoinParser) translateParserVersionFromMetadata(metadata types.BlockMetadata) (string, error) {
switch {
// The empty string is for backwards compatibility with older traces versions
Expand Down
2 changes: 2 additions & 0 deletions parser/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ const (
MethodBurnFromExported = "BurnFromExported" // MethodsDatacap
MethodAllowanceExported = "AllowanceExported" // MethodsDatacap
MethodGranularityExported = "GranularityExported" // MethodsDatacap

MethodUnknown = "Unknown" // Common
)

// SupportedOperations operations that will be parsed
Expand Down
43 changes: 43 additions & 0 deletions parser/helper/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package helper
import (
"context"
"errors"
"strings"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
Expand Down Expand Up @@ -172,3 +173,45 @@ func (h *Helper) GetMethodName(msg *parser.LotusMessage, height int64, key filTy
func (h *Helper) GetEVMSelectorSig(ctx context.Context, selectorID string) (string, error) {
return h.actorCache.GetEVMSelectorSig(ctx, selectorID)
}

func (h *Helper) FilterTxsByActorType(ctx context.Context, txs []*types.Transaction, actorType string, tipsetKey filTypes.TipSetKey) ([]*types.Transaction, error) {
var result []*types.Transaction
for _, tx := range txs {
addrTo, err := address.NewFromString(tx.TxTo)
if err != nil {
h.logger.Sugar().Errorf("could not parse address. Err: %s", err)
continue
}
addrFrom, err := address.NewFromString(tx.TxFrom)
if err != nil {
h.logger.Sugar().Errorf("could not parse address. Err: %s", err)
continue
}

isType, err := h.isAnyAddressOfType(ctx, []address.Address{addrTo, addrFrom}, int64(tx.Height), tipsetKey, actorType)
if err != nil {
h.logger.Sugar().Errorf("could not get actor type from address. Err: %s", err)
continue
}
if !isType {
continue
}

result = append(result, tx)
}

return result, nil
}

func (h *Helper) isAnyAddressOfType(_ context.Context, addresses []address.Address, height int64, key filTypes.TipSetKey, actorType string) (bool, error) {
for _, addr := range addresses {
actorName, err := h.GetActorNameFromAddress(addr, height, key)
if err != nil {
return false, err
}
if strings.EqualFold(actorName, actorType) {
return true, nil
}
}
return false, nil
}
25 changes: 16 additions & 9 deletions parser/v1/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/zondax/fil-parser/parser/helper"
typesV1 "github.com/zondax/fil-parser/parser/v1/types"
"github.com/zondax/fil-parser/tools"
multisigTools "github.com/zondax/fil-parser/tools/multisig"
"github.com/zondax/fil-parser/types"
"go.uber.org/zap"
)
Expand All @@ -26,19 +27,21 @@ const Version = "v1"
var NodeVersionsSupported = []string{"v1.21", "v1.22"}

type Parser struct {
actorParser *actors.ActorParser
addresses *types.AddressInfoMap
txCidEquivalents []types.TxCidTranslation
helper *helper.Helper
logger *zap.Logger
actorParser *actors.ActorParser
addresses *types.AddressInfoMap
txCidEquivalents []types.TxCidTranslation
helper *helper.Helper
logger *zap.Logger
multisigEventGenerator multisigTools.EventGenerator
}

func NewParser(helper *helper.Helper, logger *zap.Logger) *Parser {
return &Parser{
actorParser: actors.NewActorParser(helper, logger),
addresses: types.NewAddressInfoMap(),
helper: helper,
logger: logger2.GetSafeLogger(logger),
actorParser: actors.NewActorParser(helper, logger),
addresses: types.NewAddressInfoMap(),
helper: helper,
logger: logger2.GetSafeLogger(logger),
multisigEventGenerator: multisigTools.NewEventGenerator(helper, logger2.GetSafeLogger(logger)),
}
}

Expand Down Expand Up @@ -165,6 +168,10 @@ func (p *Parser) ParseTransactions(ctx context.Context, txsData types.TxsData) (
}, nil
}

func (p *Parser) ParseMultisigEvents(ctx context.Context, multisigTxs []*types.Transaction, tipsetCid string, tipsetKey filTypes.TipSetKey) (*types.MultisigEvents, error) {
return nil, errors.New("unimplimented")
}

func (p *Parser) ParseNativeEvents(_ context.Context, _ types.EventsData) (*types.EventsParsedResult, error) {
return nil, errors.New("unimplimented")
}
Expand Down
25 changes: 16 additions & 9 deletions parser/v2/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
typesV2 "github.com/zondax/fil-parser/parser/v2/types"
"github.com/zondax/fil-parser/tools"
eventTools "github.com/zondax/fil-parser/tools/events"
multisigTools "github.com/zondax/fil-parser/tools/multisig"
"github.com/zondax/fil-parser/types"

"github.com/bytedance/sonic"
Expand All @@ -30,19 +31,21 @@ const Version = "v2"
var NodeVersionsSupported = []string{"v1.23", "v1.24", "v1.25", "v1.26"}

type Parser struct {
actorParser *actors.ActorParser
addresses *types.AddressInfoMap
txCidEquivalents []types.TxCidTranslation
helper *helper.Helper
logger *zap.Logger
actorParser *actors.ActorParser
addresses *types.AddressInfoMap
txCidEquivalents []types.TxCidTranslation
helper *helper.Helper
logger *zap.Logger
multisigEventGenerator multisigTools.EventGenerator
}

func NewParser(helper *helper.Helper, logger *zap.Logger) *Parser {
return &Parser{
actorParser: actors.NewActorParser(helper, logger),
addresses: types.NewAddressInfoMap(),
helper: helper,
logger: logger2.GetSafeLogger(logger),
actorParser: actors.NewActorParser(helper, logger),
addresses: types.NewAddressInfoMap(),
helper: helper,
logger: logger2.GetSafeLogger(logger),
multisigEventGenerator: multisigTools.NewEventGenerator(helper, logger2.GetSafeLogger(logger)),
}
}

Expand Down Expand Up @@ -179,6 +182,10 @@ func (p *Parser) ParseEthLogs(_ context.Context, eventsData types.EventsData) (*
return &types.EventsParsedResult{EVMEvents: len(parsed), ParsedEvents: parsed}, nil
}

func (p *Parser) ParseMultisigEvents(ctx context.Context, multisigTxs []*types.Transaction, tipsetCid string, tipsetKey filTypes.TipSetKey) (*types.MultisigEvents, error) {
return p.multisigEventGenerator.GenerateMultisigEvents(ctx, multisigTxs, tipsetCid, tipsetKey)
}

func (p *Parser) GetBaseFee(traces []byte, tipset *types.ExtendedTipSet) (uint64, error) {
// Unmarshal into vComputeState
computeState := &typesV2.ComputeStateOutputV2{}
Expand Down
Loading

0 comments on commit 23cfd93

Please sign in to comment.