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

Add new tracing API #11100

Merged
merged 25 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1b0f54a
Add new tracing API
fridrik01 Jul 24, 2023
c1eaa2f
Translate call input/output into Solidity ABI
fridrik01 Aug 1, 2023
2c902db
Handle more edge cases
fridrik01 Aug 3, 2023
392ef1b
Handle delegatecall
fridrik01 Aug 3, 2023
abeb842
Address lint errors
fridrik01 Aug 4, 2023
fd69f8b
Check all errors
fridrik01 Aug 8, 2023
7f99d15
Small refactor and cleanup
fridrik01 Aug 8, 2023
ba1ee60
Refactor eth.go
fridrik01 Aug 16, 2023
ebb54bc
fix naming lint
fridrik01 Aug 21, 2023
4068e07
Do not return interface{} from trace api methods
fridrik01 Aug 22, 2023
a1b890c
return wrapped errors
fridrik01 Aug 22, 2023
ef7bcfe
Do not compute message index as traces should be in message execution…
fridrik01 Aug 22, 2023
8d8891a
Moved tracing types to ethtypes to address circular dependencies
fridrik01 Aug 22, 2023
cb5e6e0
The From/To address should be in eth format
fridrik01 Aug 23, 2023
cf25512
Decode eth param/return values and change them to ethbytes type
fridrik01 Aug 24, 2023
ee3cdf0
Fix use filecoin addr + other small refactor
fridrik01 Aug 25, 2023
10a5480
Decode output using top level trace
fridrik01 Aug 25, 2023
029a4a7
Address most recent comments
fridrik01 Aug 25, 2023
ed40768
Parse input/output for delegate call + other smaller things
fridrik01 Aug 25, 2023
aef0ecf
Run make gen
fridrik01 Aug 28, 2023
57e8259
Update FFI
fridrik01 Aug 28, 2023
930e9b9
fix lint
fridrik01 Aug 28, 2023
13e1b4b
Added todo to support native actors calling another when created
fridrik01 Aug 29, 2023
144bbdf
Added trace api as experimental feature to changelog
fridrik01 Aug 29, 2023
0096d52
fix decoding toplevel output in trace_replayBlockTransactions
fridrik01 Aug 29, 2023
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

# UNRELEASED

## New features
- feat: Added new tracing API (**HIGHLY EXPERIMENTAL**) supporting two RPC methods: `trace_block` and `trace_replayBlockTransactions` ([filecoin-project/lotus#11100](https://github.com/filecoin-project/lotus/pull/11100))

# v1.23.3 / 2023-08-01

This feature release of Lotus includes numerous improvements and enhancements for node operators, ETH RPC-providers and storage providers.
Expand Down
7 changes: 7 additions & 0 deletions api/api_full.go
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,13 @@ type FullNode interface {
// Returns the client version
Web3ClientVersion(ctx context.Context) (string, error) //perm:read

// TraceAPI related methods
//
// Returns traces created at given block
EthTraceBlock(ctx context.Context, blkNum string) ([]*ethtypes.EthTraceBlock, error) //perm:read
// Replays all transactions in a block returning the requested traces for each transaction
EthTraceReplayBlockTransactions(ctx context.Context, blkNum string, traceTypes []string) ([]*ethtypes.EthTraceReplayBlockTransaction, error) //perm:read

// CreateBackup creates node backup onder the specified file name. The
// method requires that the lotus daemon is running with the
// LOTUS_BACKUP_BASE_PATH environment variable set to some path, and that
Expand Down
2 changes: 2 additions & 0 deletions api/api_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,6 @@ type Gateway interface {
EthSubscribe(ctx context.Context, params jsonrpc.RawParams) (ethtypes.EthSubscriptionID, error)
EthUnsubscribe(ctx context.Context, id ethtypes.EthSubscriptionID) (bool, error)
Web3ClientVersion(ctx context.Context) (string, error)
EthTraceBlock(ctx context.Context, blkNum string) ([]*ethtypes.EthTraceBlock, error)
EthTraceReplayBlockTransactions(ctx context.Context, blkNum string, traceTypes []string) ([]*ethtypes.EthTraceReplayBlockTransaction, error)
}
3 changes: 3 additions & 0 deletions api/eth_aliases.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ func CreateEthRPCAliases(as apitypes.Aliaser) {
as.AliasMethod("eth_subscribe", "Filecoin.EthSubscribe")
as.AliasMethod("eth_unsubscribe", "Filecoin.EthUnsubscribe")

as.AliasMethod("trace_block", "Filecoin.EthTraceBlock")
as.AliasMethod("trace_replayBlockTransactions", "Filecoin.EthTraceReplayBlockTransactions")

as.AliasMethod("net_version", "Filecoin.NetVersion")
as.AliasMethod("net_listening", "Filecoin.NetListening")

Expand Down
30 changes: 30 additions & 0 deletions api/mocks/mock_full.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions api/proxy_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified build/openrpc/full.json.gz
Binary file not shown.
Binary file modified build/openrpc/gateway.json.gz
Binary file not shown.
Binary file modified build/openrpc/miner.json.gz
Binary file not shown.
Binary file modified build/openrpc/worker.json.gz
Binary file not shown.
64 changes: 62 additions & 2 deletions chain/types/cbor_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions chain/types/ethtypes/eth_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"golang.org/x/xerrors"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"
builtintypes "github.com/filecoin-project/go-state-types/builtin"

Expand Down Expand Up @@ -929,3 +930,57 @@ func (e *EthBlockNumberOrHash) UnmarshalJSON(b []byte) error {

return errors.New("invalid block param")
}

type EthTrace struct {
Action EthTraceAction `json:"action"`
Result EthTraceResult `json:"result"`
Subtraces int `json:"subtraces"`
TraceAddress []int `json:"traceAddress"`
Type string `json:"Type"`

Parent *EthTrace `json:"-"`

// if a subtrace makes a call to GetBytecode, we store a pointer to that subtrace here
// which we then lookup when checking for delegatecall (InvokeContractDelegate)
LastByteCode *EthTrace `json:"-"`
fridrik01 marked this conversation as resolved.
Show resolved Hide resolved
}

func (t *EthTrace) SetCallType(callType string) {
t.Action.CallType = callType
t.Type = callType
}

type EthTraceBlock struct {
*EthTrace
BlockHash EthHash `json:"blockHash"`
BlockNumber int64 `json:"blockNumber"`
TransactionHash EthHash `json:"transactionHash"`
TransactionPosition int `json:"transactionPosition"`
}

type EthTraceReplayBlockTransaction struct {
Output EthBytes `json:"output"`
StateDiff *string `json:"stateDiff"`
Trace []*EthTrace `json:"trace"`
TransactionHash EthHash `json:"transactionHash"`
VmTrace *string `json:"vmTrace"`
}

type EthTraceAction struct {
CallType string `json:"callType"`
From EthAddress `json:"from"`
To EthAddress `json:"to"`
Gas EthUint64 `json:"gas"`
Input EthBytes `json:"input"`
Value EthBigInt `json:"value"`

FilecoinMethod abi.MethodNum `json:"-"`
FilecoinCodeCid cid.Cid `json:"-"`
FilecoinFrom address.Address `json:"-"`
FilecoinTo address.Address `json:"-"`
}

type EthTraceResult struct {
GasUsed EthUint64 `json:"gasUsed"`
Output EthBytes `json:"output"`
}
5 changes: 5 additions & 0 deletions chain/types/execresult.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"encoding/json"
"time"

"github.com/ipfs/go-cid"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/exitcode"
Expand All @@ -24,6 +26,9 @@ type MessageTrace struct {
Method abi.MethodNum
Params []byte
ParamsCodec uint64
GasLimit uint64
ReadOnly bool
CodeCid cid.Cid
}

type ReturnTrace struct {
Expand Down
Loading