Skip to content

Commit

Permalink
rpcv05 update transaction trace types (#432)
Browse files Browse the repository at this point in the history
* rpcv05 update transaction trace types

* fix rpc workflow error

* update traceTransaction name

* update trace test data to pass test

* add rever reason to execution trace

---------

Co-authored-by: Carmen Cabrera <[email protected]>
Co-authored-by: Carmen Irene Cabrera Rodríguez <[email protected]>
  • Loading branch information
3 people authored Oct 25, 2023
1 parent 16be43f commit ee0d99d
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 44 deletions.
4 changes: 2 additions & 2 deletions account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,8 @@ func (account *Account) TransactionReceipt(ctx context.Context, transactionHash
return account.provider.TransactionReceipt(ctx, transactionHash)
}

func (account *Account) TransactionTrace(ctx context.Context, transactionHash *felt.Felt) (rpc.TxnTrace, error) {
return account.provider.TransactionTrace(ctx, transactionHash)
func (account *Account) TraceTransaction(ctx context.Context, transactionHash *felt.Felt) (rpc.TxnTrace, error) {
return account.provider.TraceTransaction(ctx, transactionHash)
}

func (account *Account) TransactionByBlockIdAndIndex(ctx context.Context, blockID rpc.BlockID, index uint64) (rpc.Transaction, error) {
Expand Down
30 changes: 15 additions & 15 deletions mocks/mock_rpc_provider.go

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

2 changes: 1 addition & 1 deletion rpc/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type RpcProvider interface {
TransactionByBlockIdAndIndex(ctx context.Context, blockID BlockID, index uint64) (Transaction, error)
TransactionByHash(ctx context.Context, hash *felt.Felt) (Transaction, error)
TransactionReceipt(ctx context.Context, transactionHash *felt.Felt) (TransactionReceipt, error)
TransactionTrace(ctx context.Context, transactionHash *felt.Felt) (TxnTrace, error)
TraceTransaction(ctx context.Context, transactionHash *felt.Felt) (TxnTrace, error)
}

var _ RpcProvider = &Provider{}
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@
"calls": [],
"events": [
{
"order": 0,
"keys": [
"0x134692b230b9e1ffa39098904722134159652b09c5bc41d88d6698779d228ff"
],
Expand Down Expand Up @@ -287,6 +288,7 @@
"calls": [],
"events": [
{
"order": 1,
"keys": [
"0x134692b230b9e1ffa39098904722134159652b09c5bc41d88d6698779d228ff"
],
Expand All @@ -298,6 +300,7 @@
]
},
{
"order": 2,
"keys": [
"0x99cd8bde557814842a3121e8ddfd433a539b8c9f14bf31ebf108d12e6196e9"
],
Expand Down Expand Up @@ -345,6 +348,7 @@
"calls": [],
"events": [
{
"order": 3,
"keys": [
"0x99cd8bde557814842a3121e8ddfd433a539b8c9f14bf31ebf108d12e6196e9"
],
Expand Down Expand Up @@ -396,6 +400,7 @@
"calls": [],
"events": [
{
"order": 4,
"keys": [
"0x99cd8bde557814842a3121e8ddfd433a539b8c9f14bf31ebf108d12e6196e9"
],
Expand Down Expand Up @@ -424,6 +429,7 @@
],
"events": [
{
"order": 5,
"keys": [
"0x5ad857f66a5b55f1301ff1ed7e098ac6d4433148f0b72ebc4a2945ab85ad53"
],
Expand Down Expand Up @@ -482,6 +488,7 @@
"calls": [],
"events": [
{
"order": 0,
"keys": [
"0x99cd8bde557814842a3121e8ddfd433a539b8c9f14bf31ebf108d12e6196e9"
],
Expand All @@ -498,6 +505,77 @@
],
"events": [],
"messages": []
},
"type": "INVOKE",
"state_diff": {
"storage_diffs": [
{
"address": "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
"storage_entries": [
{
"key": "0x49a8ef79cab313360767015d427d0307368eff5c2c81b019aff018ec638eef2",
"value": "0x763b821506b19086e9"
},
{
"key": "0x625da4622cb73a56b1f10ac489e48b4e8af830a368fb3e21db8b7868c315ff0",
"value": "0x19094ba60d592b"
},
{
"key": "0x5496768776e3db30053404f18067d81a6e06f5a2b0de326e21298fd9d569a9a",
"value": "0x11e93b002a1d5c717d"
}
]
},
{
"address": "0x10884171baf1914edc28d7afb619b40a4051cfae78a094a55d230f19e944a28",
"storage_entries": [
{
"key": "0x2487f67598912d31ab84d8fa97c9e78332d00795ecdad092ea09f9c9c14a9a3",
"value": "0x1e226129b7e"
},
{
"key": "0x2487f67598912d31ab84d8fa97c9e78332d00795ecdad092ea09f9c9c14a9a0",
"value": "0x4477606da4ac2b7bef"
}
]
},
{
"address": "0x22b05f9396d2c48183f6deaf138a57522bcc8b35b67dee919f76403d1783136",
"storage_entries": [
{
"key": "0x110e2f729c9c2b988559994a3daccd838cf52faf88e18101373e67dd061455a",
"value": "0x7743be9a9d8fae"
},
{
"key": "0x625da4622cb73a56b1f10ac489e48b4e8af830a368fb3e21db8b7868c315ff0",
"value": "0x631cb839"
}
]
},
{
"address": "0x53c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8",
"storage_entries": [
{
"key": "0x625da4622cb73a56b1f10ac489e48b4e8af830a368fb3e21db8b7868c315ff0",
"value": "0x17fc5"
},
{
"key": "0x49a8ef79cab313360767015d427d0307368eff5c2c81b019aff018ec638eef2",
"value": "0x257875e1c11"
}
]
}
],
"nonces": [
{
"contract_address": "0x61d862eb8baf0dc8e14159d0dd16abcff933c798ecf252ce81685d74c237516",
"nonce": "0x58"
}
],
"deployed_contracts": [],
"deprecated_declared_classes": [],
"declared_classes": [],
"replaced_classes": []
}
},
"id": 1
Expand Down
32 changes: 14 additions & 18 deletions rpc/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package rpc
import (
"context"
"encoding/json"
"errors"

"github.com/NethermindEth/juno/core/felt"
)

// For a given executed transaction, return the trace of its execution, including internal calls
func (provider *Provider) TransactionTrace(ctx context.Context, transactionHash *felt.Felt) (TxnTrace, error) {
func (provider *Provider) TraceTransaction(ctx context.Context, transactionHash *felt.Felt) (TxnTrace, error) {
var rawTxnTrace map[string]any
if err := do(ctx, provider.c, "starknet_traceTransaction", &rawTxnTrace, transactionHash); err != nil {
if noTraceAvailableError, ok := isErrNoTraceAvailableError(err); ok {
Expand All @@ -22,43 +23,38 @@ func (provider *Provider) TransactionTrace(ctx context.Context, transactionHash
return nil, err
}

// if execute_invocation exists, then it's an InvokeTxnTrace type
if _, exists := rawTxnTrace["execute_invocation"]; exists {
switch rawTxnTrace["type"] {
case string(TransactionType_Invoke):
var trace InvokeTxnTrace
err = json.Unmarshal(rawTraceByte, &trace)
if err != nil {
return nil, err
}
return trace, nil
}

// if constructor_invocation exists, then it's a DeployAccountTxnTrace type
if _, exists := rawTxnTrace["constructor_invocation"]; exists {
case string(TransactionType_Declare):
var trace DeclareTxnTrace
err = json.Unmarshal(rawTraceByte, &trace)
if err != nil {
return nil, err
}
return trace, nil
case string(TransactionType_DeployAccount):
var trace DeployAccountTxnTrace
err = json.Unmarshal(rawTraceByte, &trace)
if err != nil {
return nil, err
}
return trace, nil
}

// if function_invocation exists, then it's an L1HandlerTxnTrace type
if _, exists := rawTxnTrace["function_invocation"]; exists {
case string(TransactionType_L1Handler):
var trace L1HandlerTxnTrace
err = json.Unmarshal(rawTraceByte, &trace)
if err != nil {
return nil, err
}
return trace, nil
}
return nil, errors.New("Unknown transaction type")

// the other possible choice is for it to be a DeclareTxnTrace type
var trace DeclareTxnTrace
err = json.Unmarshal(rawTraceByte, &trace)
if err != nil {
return nil, err
}
return trace, nil
}

// Retrieve traces for all transactions in the given block
Expand Down
2 changes: 1 addition & 1 deletion rpc/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestTransactionTrace(t *testing.T) {
}[testEnv]

for _, test := range testSet {
resp, err := testConfig.provider.TransactionTrace(context.Background(), test.TransactionHash)
resp, err := testConfig.provider.TraceTransaction(context.Background(), test.TransactionHash)
if err != nil {
require.Equal(t, test.ExpectedError, err)
} else {
Expand Down
26 changes: 19 additions & 7 deletions rpc/types_trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,35 @@ var _ TxnTrace = L1HandlerTxnTrace{}
type InvokeTxnTrace struct {
ValidateInvocation FnInvocation `json:"validate_invocation"`
//the trace of the __execute__ call or constructor call, depending on the transaction type (none for declare transactions)
ExecuteInvocation FnInvocation `json:"execute_invocation"`
FeeTransferInvocation FnInvocation `json:"fee_transfer_invocation"`
ExecuteInvocation ExecInvocation `json:"execute_invocation"`
FeeTransferInvocation FnInvocation `json:"fee_transfer_invocation"`
StateDiff StateDiff `json:"state_diff"`
Type TransactionType `json:"type"`
}

// the execution trace of a declare transaction
type DeclareTxnTrace struct {
ValidateInvocation FnInvocation `json:"validate_invocation"`
FeeTransferInvocation FnInvocation `json:"fee_transfer_invocation"`
ValidateInvocation FnInvocation `json:"validate_invocation"`
FeeTransferInvocation FnInvocation `json:"fee_transfer_invocation"`
StateDiff StateDiff `json:"state_diff"`
Type TransactionType `json:"type"`
}

// the execution trace of a deploy account transaction
type DeployAccountTxnTrace struct {
ValidateInvocation FnInvocation `json:"validate_invocation"`
//the trace of the __execute__ call or constructor call, depending on the transaction type (none for declare transactions)
ConstructorInvocation FnInvocation `json:"constructor_invocation"`
FeeTransferInvocation FnInvocation `json:"fee_transfer_invocation"`
ConstructorInvocation FnInvocation `json:"constructor_invocation"`
FeeTransferInvocation FnInvocation `json:"fee_transfer_invocation"`
StateDiff StateDiff `json:"state_diff"`
Type TransactionType `json:"type"`
}

// the execution trace of an L1 handler transaction
type L1HandlerTxnTrace struct {
//the trace of the __execute__ call or constructor call, depending on the transaction type (none for declare transactions)
FunctionInvocation FnInvocation `json:"function_invocation"`
FunctionInvocation FnInvocation `json:"function_invocation"`
Type TransactionType `json:"type"`
}

type EntryPointType string
Expand Down Expand Up @@ -107,3 +114,8 @@ type Trace struct {
TraceRoot TxnTrace `json:"trace_root,omitempty"`
TxnHash *felt.Felt `json:"transaction_hash,omitempty"`
}

type ExecInvocation struct {
FunctionInvocation FnInvocation `json:"function_invocation,omitempty"`
RevertReason string `json:"revert_reason,omitempty"`
}

0 comments on commit ee0d99d

Please sign in to comment.