Skip to content

Commit

Permalink
Thiagodeev/rpcv08 final changes (#644)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
thiagodeev committed Dec 20, 2024
1 parent f9d13d8 commit f67c73f
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 48 deletions.
12 changes: 11 additions & 1 deletion rpc/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion rpc/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions rpc/types_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions rpc/types_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
}
Expand Down
4 changes: 2 additions & 2 deletions rpc/types_executables.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions rpc/types_trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions rpc/types_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
43 changes: 4 additions & 39 deletions rpc/types_transaction_receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f67c73f

Please sign in to comment.