From f67c73f3c1e68ed10bd7d99b42f7b49dff7d265a Mon Sep 17 00:00:00 2001 From: Thiago Ribeiro <62709592+thiagodeev@users.noreply.github.com> Date: Thu, 19 Dec 2024 23:10:28 -0300 Subject: [PATCH] Thiagodeev/rpcv08 final changes (#644) * Adjusts TransactionStatus * Adjusts EstimateFee * Fixes blockTest error * Adds GetStorageProof method (#635) * implement rpcv8 GetStorageProof method * Adds GetMessagesStatus method (#634) * Added GetMessagesStatus method * PR comment fixes * Fix MerkleNode type * Updates PendingBlockReader type * Updates ExecutionResources and remove ComputationResources * Fixes failing tests and improves Error() resp * Adds TODO comments and set a pointer to Marshal method * Thiagodeev/rpcv08 write methods, blockHeader and error 53 (#626) Update write methods, error 53 and block header for rpc08 * Adjusts EstimateFee --- rpc/contract.go | 12 ++++++++- rpc/trace.go | 12 ++++++++- rpc/types_block.go | 2 ++ rpc/types_contract.go | 9 ++++--- rpc/types_executables.go | 4 +-- rpc/types_trace.go | 11 ++++++-- rpc/types_transaction.go | 3 +++ rpc/types_transaction_receipt.go | 43 +++----------------------------- 8 files changed, 48 insertions(+), 48 deletions(-) diff --git a/rpc/contract.go b/rpc/contract.go index 5653b59b..88ff3b67 100644 --- a/rpc/contract.go +++ b/rpc/contract.go @@ -135,6 +135,15 @@ func (provider *Provider) Nonce(ctx context.Context, blockID BlockID, contractAd // Estimates the resources required by a given sequence of transactions when applied on a given state. // If one of the transactions reverts or fails due to any reason (e.g. validation failure or an internal error), // a TRANSACTION_EXECUTION_ERROR is returned. For v0-2 transactions the estimate is given in wei, and for v3 transactions it is given in fri. +// +// Parameters: +// - ctx: The context of the function call +// - requests: A sequence of transactions to estimate, running each transaction on the state resulting from applying all the previous ones +// - simulationFlags: Describes what parts of the transaction should be executed +// - blockID: The hash of the requested block, or number (height) of the requested block, or a block tag, for the block referencing the state or call the transaction on +// Returns: +// - []FeeEstimation: A sequence of fee estimation where the i'th estimate corresponds to the i'th transaction +// - error: An error if any occurred during the execution func (provider *Provider) EstimateFee(ctx context.Context, requests []BroadcastTxn, simulationFlags []SimulationFlag, blockID BlockID) ([]FeeEstimation, error) { var raw []FeeEstimation if err := do(ctx, provider.c, "starknet_estimateFee", &raw, requests, simulationFlags, blockID); err != nil { @@ -168,7 +177,8 @@ func (provider *Provider) EstimateMessageFee(ctx context.Context, msg MsgFromL1, // - ctx: The context of the function call // - storageProofInput: an input containing at least one of the fields filled // Returns: -// - *StorageProofResult: the proofs of the field passed in the input +// - *StorageProofResult: The requested storage proofs. Note that if a requested leaf has the default value, +// the path to it may end in an edge node whose path is not a prefix of the requested leaf, thus effectively proving non-membership // - error: an error if any occurred during the execution func (provider *Provider) GetStorageProof(ctx context.Context, storageProofInput StorageProofInput) (*StorageProofResult, error) { var raw StorageProofResult diff --git a/rpc/trace.go b/rpc/trace.go index ad1d189e..d637866d 100644 --- a/rpc/trace.go +++ b/rpc/trace.go @@ -81,7 +81,17 @@ func (provider *Provider) TraceBlockTransactions(ctx context.Context, blockID Bl // SimulateTransactions simulates transactions on the blockchain. // Simulate a given sequence of transactions on the requested state, and generate the execution traces. // Note that some of the transactions may revert, in which case no error is thrown, but revert details can be seen on the returned trace object. -// Note that some of the transactions may revert, this will be reflected by the revert_error property in the trace. Other types of failures (e.g. unexpected error or failure in the validation phase) will result in TRANSACTION_EXECUTION_ERROR. +// Note that some of the transactions may revert, this will be reflected by the revert_error property in the trace. Other +// types of failures (e.g. unexpected error or failure in the validation phase) will result in TRANSACTION_EXECUTION_ERROR. +// +// Parameters: +// - ctx: The context of the function call +// - blockID: The hash of the requested block, or number (height) of the requested block, or a block tag, for the block referencing the state or call the transaction on. +// - txns: A sequence of transactions to simulate, running each transaction on the state resulting from applying all the previous ones +// - simulationFlags: Describes what parts of the transaction should be executed +// Returns: +// - []SimulatedTransaction: The execution trace and consumed resources of the required transactions +// - error: An error if any occurred during the execution func (provider *Provider) SimulateTransactions(ctx context.Context, blockID BlockID, txns []BroadcastTxn, simulationFlags []SimulationFlag) ([]SimulatedTransaction, error) { var output []SimulatedTransaction diff --git a/rpc/types_block.go b/rpc/types_block.go index d54a63f3..c8acb86c 100644 --- a/rpc/types_block.go +++ b/rpc/types_block.go @@ -227,6 +227,8 @@ type PendingBlockHeader struct { SequencerAddress *felt.Felt `json:"sequencer_address"` // The price of l1 gas in the block L1GasPrice ResourcePrice `json:"l1_gas_price"` + // The price of l2 gas in the block + L2GasPrice ResourcePrice `json:"l2_gas_price"` // Semver of the current Starknet protocol StarknetVersion string `json:"starknet_version"` // The price of l1 data gas in the block diff --git a/rpc/types_contract.go b/rpc/types_contract.go index affc336c..09e8c180 100644 --- a/rpc/types_contract.go +++ b/rpc/types_contract.go @@ -127,7 +127,10 @@ type NodeHashToNode struct { } // A node in the Merkle-Patricia tree, can be a leaf, binary node, or an edge node -type MerkleNode interface{} // it should be an EdgeNode or BinaryNode +type MerkleNode struct { + EdgeNode `json:",omitempty"` + BinaryNode `json:",omitempty"` +} // Represents a path to the highest non-zero descendant node type EdgeNode struct { @@ -263,9 +266,9 @@ func (nodeHashToNode *NodeHashToNode) UnmarshalJSON(bytes []byte) error { var merkleNode MerkleNode switch nodeT := node.(type) { case BinaryNode: - merkleNode = nodeT + merkleNode = MerkleNode{BinaryNode: nodeT} case EdgeNode: - merkleNode = nodeT + merkleNode = MerkleNode{EdgeNode: nodeT} default: return fmt.Errorf("'node' should be an EdgeNode or BinaryNode") } diff --git a/rpc/types_executables.go b/rpc/types_executables.go index b320e4f9..b7d23a5a 100644 --- a/rpc/types_executables.go +++ b/rpc/types_executables.go @@ -10,7 +10,7 @@ type CasmCompiledContractClass struct { Prime NumAsHex `json:"prime"` CompilerVersion string `json:"compiler_version"` Hints []Hints `json:"hints"` - // a list of sizes of segments in the bytecode, each segment is hashed invidually when computing the bytecode hash + // a list of sizes of segments in the bytecode, each segment is hashed individually when computing the bytecode hash BytecodeSegmentLengths []int `json:"bytecode_segment_lengths,omitempty"` } @@ -152,7 +152,7 @@ type ResOperand struct { type Deref CellRef -// A (CellRef, offsest) tuple, but adapted to a golang struct +// A (CellRef, offset) tuple, but adapted to a golang struct type DoubleDeref struct { CellRef CellRef Offset int diff --git a/rpc/types_trace.go b/rpc/types_trace.go index 0cc44807..6c833730 100644 --- a/rpc/types_trace.go +++ b/rpc/types_trace.go @@ -122,8 +122,15 @@ type FnInvocation struct { L1Messages []OrderedMsg `json:"messages"` // Resources consumed by the internal call - // https://github.com/starkware-libs/starknet-specs/blob/v0.7.0-rc0/api/starknet_trace_api_openrpc.json#L374C1-L374C29 - ComputationResources ComputationResources `json:"execution_resources"` + ExecutionResources InnerCallExecutionResources `json:"execution_resources"` +} + +// the resources consumed by an inner call (does not account for state diffs since data is squashed across the transaction) +type InnerCallExecutionResources struct { + // l1 gas consumed by this transaction, used for l2-->l1 messages and state updates if blobs are not used + L1Gas uint `json:"l1_gas"` + // l2 gas consumed by this transaction, used for computation and calldata + L2Gas uint `json:"l2_gas"` } // A single pair of transaction hash and corresponding trace diff --git a/rpc/types_transaction.go b/rpc/types_transaction.go index b36627e9..3235f9ae 100644 --- a/rpc/types_transaction.go +++ b/rpc/types_transaction.go @@ -145,10 +145,13 @@ type DeclareTxnV3 struct { type ResourceBoundsMapping struct { // The max amount and max price per unit of L1 gas used in this tx L1Gas ResourceBounds `json:"l1_gas"` + // The max amount and max price per unit of L1 blob gas used in this tx + L1DataGas ResourceBounds `json:"l1_data_gas"` // The max amount and max price per unit of L2 gas used in this tx L2Gas ResourceBounds `json:"l2_gas"` } +// DA_MODE: Specifies a storage domain in Starknet. Each domain has different guarantees regarding availability type DataAvailabilityMode string const ( diff --git a/rpc/types_transaction_receipt.go b/rpc/types_transaction_receipt.go index 969c4fbd..7a6e9e33 100644 --- a/rpc/types_transaction_receipt.go +++ b/rpc/types_transaction_receipt.go @@ -131,48 +131,13 @@ func (tt TransactionType) MarshalJSON() ([]byte, error) { return []byte(strconv.Quote(string(tt))), nil } -type ComputationResources struct { - // The number of Cairo steps used - Steps int `json:"steps"` - // The number of unused memory cells (each cell is roughly equivalent to a step) - MemoryHoles int `json:"memory_holes,omitempty"` - // The number of RANGE_CHECK builtin instances - RangeCheckApps int `json:"range_check_builtin_applications,omitempty"` - // The number of Pedersen builtin instances - PedersenApps int `json:"pedersen_builtin_applications,omitempty"` - // The number of Poseidon builtin instances - PoseidonApps int `json:"poseidon_builtin_applications,omitempty"` - // The number of EC_OP builtin instances - ECOPApps int `json:"ec_op_builtin_applications,omitempty"` - // The number of ECDSA builtin instances - ECDSAApps int `json:"ecdsa_builtin_applications,omitempty"` - // The number of BITWISE builtin instances - BitwiseApps int `json:"bitwise_builtin_applications,omitempty"` - // The number of KECCAK builtin instances - KeccakApps int `json:"keccak_builtin_applications,omitempty"` - // The number of accesses to the segment arena - SegmentArenaBuiltin int `json:"segment_arena_builtin,omitempty"` -} - -func (er *ComputationResources) Validate() bool { - if er.Steps == 0 || er.MemoryHoles == 0 || er.RangeCheckApps == 0 || er.PedersenApps == 0 || - er.PoseidonApps == 0 || er.ECOPApps == 0 || er.ECDSAApps == 0 || er.BitwiseApps == 0 || - er.KeccakApps == 0 || er.SegmentArenaBuiltin == 0 { - return false - } - return true -} - type ExecutionResources struct { - ComputationResources - DataAvailability `json:"data_availability"` -} - -type DataAvailability struct { - // the gas consumed by this transaction's data, 0 if it uses data gas for DA + // l1 gas consumed by this transaction, used for l2-->l1 messages and state updates if blobs are not used L1Gas uint `json:"l1_gas"` - // the data gas consumed by this transaction's data, 0 if it uses gas for DA + // data gas consumed by this transaction, 0 if blobs are not used L1DataGas uint `json:"l1_data_gas"` + // l2 gas consumed by this transaction, used for computation and calldata + L2Gas uint `json:"l2_gas"` } type TxnStatus string