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

Support RPC 0.7.0 #1307

Merged
merged 20 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
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
4 changes: 1 addition & 3 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
name: Checks

env:
STARKNET_VERSION: "0.13.0"
RPC_SPEC_VERSION: "0.6.0"
DEVNET_SHA: "1bd447d"
DEVNET_SHA: "79a90fd"
ddoktorski marked this conversation as resolved.
Show resolved Hide resolved

on:
push:
Expand Down
3 changes: 1 addition & 2 deletions docs/development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ Below is the command you can use to do this, designed for compatibility with the

.. code-block:: bash

STARKNET_VERSION="0.13.0" RPC_SPEC_VERSION="0.6.0" \
cargo install \
--locked \
--git https://github.com/0xSpaceShard/starknet-devnet-rs.git \
--rev 1bd447d
--rev 79a90fd

If you choose to install `starknet-devnet-rs <https://github.com/0xSpaceShard/starknet-devnet-rs>`_ using a different method, please make sure to add the executable ``starknet-devnet`` to your ``PATH`` environment variable.

Expand Down
4 changes: 1 addition & 3 deletions docs/guide/account_and_client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ To enable auto estimation, set the ``auto_estimate`` parameter to ``True``.

It is strongly discouraged to use automatic fee estimation in production code as it may lead to an unexpectedly high fee.

The returned estimated fee is multiplied by ``1.5`` for V1 and V2 transactions to mitigate fluctuations in price.
For V3 transactions, ``max_amount`` and ``max_price_per_unit`` are scaled by ``1.1`` and ``1.5`` respectively.

The returned estimated fee is multiplied by ``1.5`` to mitigate fluctuations in price.
ddoktorski marked this conversation as resolved.
Show resolved Hide resolved

.. note::
It is possible to configure the value by which the estimated fee is multiplied,
Expand Down
26 changes: 26 additions & 0 deletions docs/migration_guide.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
Migration guide
===============

**********************
0.21.0 Migration guide
**********************

Version 0.21.0 of **starknet.py** comes with support for RPC 0.7.0!
ddoktorski marked this conversation as resolved.
Show resolved Hide resolved

0.21.0 Targeted versions
------------------------

- Starknet - `0.13.1 <https://docs.starknet.io/documentation/starknet_versions/version_notes/#version0.13.1>`_
- RPC - `0.7.0 <https://github.com/starkware-libs/starknet-specs/releases/tag/v0.7.0>`_

0.21.0 Breaking changes
-----------------------

.. currentmodule:: starknet_py.net.client_models

1. :class:`ExecutionResources` has a new required field ``data_availability``
2. :class:`InvokeTransactionTrace`, :class:`DeclareTransactionTrace` and :class:`DeployAccountTransactionTrace` have a new required field ``execution_resources``
ddoktorski marked this conversation as resolved.
Show resolved Hide resolved
3. :class:`PendingStarknetBlock` and :class:`PendingStarknetBlockWithTxHashes` field ``parent_block_hash`` has been renamed to ``parent_hash``
4. :class:`StarknetBlockCommon` has been renamed to :class:`BlockHeader`
5. :class:`StarknetBlock` and :class:`StarknetBlockWithTxHashes` fields ``parent_block_hash`` and ``root`` have been renamed to ``parent_hash`` and ``new_root`` respectively
6. :class:`EstimatedFee` has new required fields ``data_gas_consumed`` and ``data_gas_price``
7. :class:`FunctionInvocation` field ``execution_resources`` has been renamed to ``computation_resources``
8. :class:`StarknetBlock`, :class:`PendingStarknetBlock`, :class:`StarknetBlockWithTxHashes`, :class:`PendingStarknetBlockWithTxHashes` have new required fields ``l1_data_gas_price`` and ``l1_da_mode``

**********************
0.20.0 Migration guide
**********************
Expand Down
5 changes: 3 additions & 2 deletions starknet_py/net/account/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Account(BaseAccount):
ESTIMATED_FEE_MULTIPLIER: float = 1.5
"""Amount by which each estimated fee is multiplied when using `auto_estimate`."""

ESTIMATED_AMOUNT_MULTIPLIER: float = 1.1
ESTIMATED_AMOUNT_MULTIPLIER: float = 1.5
ESTIMATED_UNIT_PRICE_MULTIPLIER: float = 1.5
"""Values by which each estimated `max_amount` and `max_price_per_unit` are multiplied when using
`auto_estimate`. Used only for V3 transactions"""
Expand Down Expand Up @@ -165,7 +165,8 @@ async def _get_resource_bounds(

l1_resource_bounds = ResourceBounds(
max_amount=int(
estimated_fee.gas_consumed * Account.ESTIMATED_AMOUNT_MULTIPLIER
(estimated_fee.overall_fee / estimated_fee.gas_price)
ddoktorski marked this conversation as resolved.
Show resolved Hide resolved
* Account.ESTIMATED_AMOUNT_MULTIPLIER
),
max_price_per_unit=int(
estimated_fee.gas_price * Account.ESTIMATED_UNIT_PRICE_MULTIPLIER
Expand Down
121 changes: 88 additions & 33 deletions starknet_py/net/client_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ class DAMode(Enum):
L2 = 1


class L1DAMode(Enum):
BLOB = "BLOB"
CALLDATA = "CALLDATA"


class TransactionType(Enum):
"""
Enum representing transaction types.
Expand Down Expand Up @@ -347,23 +352,42 @@ class TransactionFinalityStatus(Enum):


@dataclass
class ExecutionResources:
class DataResources:
"""
Dataclass representing the data-availability resources of the transaction
"""

l1_gas: int
l1_data_gas: int


@dataclass
class ComputationResources:
"""
Dataclass representing the resources consumed by the transaction.
Dataclass representing the resources consumed by the VM.
"""

# pylint: disable=too-many-instance-attributes

steps: int
range_check_builtin_applications: Optional[int] = None
pedersen_builtin_applications: Optional[int] = None
poseidon_builtin_applications: Optional[int] = None
ec_op_builtin_applications: Optional[int] = None
ecdsa_builtin_applications: Optional[int] = None
bitwise_builtin_applications: Optional[int] = None
keccak_builtin_applications: Optional[int] = None
memory_holes: Optional[int] = None
segment_arena_builtin: Optional[int] = None
memory_holes: Optional[int]
range_check_builtin_applications: Optional[int]
pedersen_builtin_applications: Optional[int]
poseidon_builtin_applications: Optional[int]
ec_op_builtin_applications: Optional[int]
ecdsa_builtin_applications: Optional[int]
bitwise_builtin_applications: Optional[int]
keccak_builtin_applications: Optional[int]
segment_arena_builtin: Optional[int]


@dataclass
class ExecutionResources(ComputationResources):
"""
Dataclass representing the resources consumed by the transaction, includes both computation and data.
"""

data_availability: DataResources


# TODO (#1219): split into PendingTransactionReceipt and TransactionReceipt
Expand Down Expand Up @@ -395,6 +419,12 @@ class TransactionReceipt:
revert_reason: Optional[str] = None


@dataclass
class TransactionWithReceipt:
transaction: Transaction
receipt: TransactionReceipt


@dataclass
class SentTransactionResponse:
"""
Expand Down Expand Up @@ -432,58 +462,68 @@ class BlockStatus(Enum):
REJECTED = "REJECTED"
ACCEPTED_ON_L2 = "ACCEPTED_ON_L2"
ACCEPTED_ON_L1 = "ACCEPTED_ON_L1"
PROVEN = "PROVEN"


@dataclass
class PendingStarknetBlock:
class PendingBlockHeader:
parent_hash: int
timestamp: int
sequencer_address: int
l1_gas_price: ResourcePrice
l1_data_gas_price: ResourcePrice
l1_da_mode: L1DAMode
starknet_version: str


@dataclass
class PendingStarknetBlock(PendingBlockHeader):
"""
Dataclass representing a pending block on Starknet.
"""

transactions: List[Transaction]
parent_block_hash: int
timestamp: int
sequencer_address: int
l1_gas_price: ResourcePrice
starknet_version: str


@dataclass
class PendingStarknetBlockWithTxHashes:
class PendingStarknetBlockWithTxHashes(PendingBlockHeader):
"""
Dataclass representing a pending block on Starknet containing transaction hashes.
"""

transactions: List[int]
parent_block_hash: int
timestamp: int
sequencer_address: int
l1_gas_price: ResourcePrice
starknet_version: str


@dataclass
class StarknetBlockCommon:
class PendingStarknetBlockWithReceipts(PendingBlockHeader):
"""
Dataclass representing a pending block on Starknet with txs and receipts result
"""

transactions: List[TransactionWithReceipt]


@dataclass
class BlockHeader:
"""
Dataclass representing a block header.
"""

# TODO (#1219): change that into composition
# pylint: disable=too-many-instance-attributes

block_hash: int
parent_block_hash: int
parent_hash: int
block_number: int
root: int
new_root: int
timestamp: int
sequencer_address: int
l1_gas_price: ResourcePrice
l1_data_gas_price: ResourcePrice
l1_da_mode: L1DAMode
starknet_version: str


@dataclass
class StarknetBlock(StarknetBlockCommon):
class StarknetBlock(BlockHeader):
"""
Dataclass representing a block on Starknet.
"""
Expand All @@ -493,7 +533,7 @@ class StarknetBlock(StarknetBlockCommon):


@dataclass
class StarknetBlockWithTxHashes(StarknetBlockCommon):
class StarknetBlockWithTxHashes(BlockHeader):
"""
Dataclass representing a block on Starknet containing transaction hashes.
"""
Expand All @@ -502,6 +542,16 @@ class StarknetBlockWithTxHashes(StarknetBlockCommon):
transactions: List[int]


@dataclass
class StarknetBlockWithReceipts(BlockHeader):
"""
Dataclass representing a block on Starknet with txs and receipts result
"""

status: BlockStatus
transactions: List[TransactionWithReceipt]


@dataclass
class BlockHashAndNumber:
block_hash: int
Expand Down Expand Up @@ -544,9 +594,11 @@ class EstimatedFee:
Dataclass representing estimated fee.
"""

overall_fee: int
gas_price: int
gas_consumed: int
gas_price: int
data_gas_consumed: int
data_gas_price: int
overall_fee: int
unit: PriceUnit


Expand Down Expand Up @@ -831,7 +883,7 @@ class FunctionInvocation:
calls: List["FunctionInvocation"]
events: List[OrderedEvent]
messages: List[OrderedMessage]
execution_resources: ExecutionResources
computation_resources: ComputationResources


@dataclass
Expand All @@ -850,6 +902,7 @@ class InvokeTransactionTrace:
"""

execute_invocation: Union[FunctionInvocation, RevertedFunctionInvocation]
execution_resources: ExecutionResources
validate_invocation: Optional[FunctionInvocation] = None
fee_transfer_invocation: Optional[FunctionInvocation] = None
state_diff: Optional[StateDiff] = None
Expand All @@ -861,6 +914,7 @@ class DeclareTransactionTrace:
Dataclass representing a transaction trace of an DECLARE transaction.
"""

execution_resources: ExecutionResources
validate_invocation: Optional[FunctionInvocation] = None
fee_transfer_invocation: Optional[FunctionInvocation] = None
state_diff: Optional[StateDiff] = None
Expand All @@ -873,6 +927,7 @@ class DeployAccountTransactionTrace:
"""

constructor_invocation: FunctionInvocation
execution_resources: ExecutionResources
validate_invocation: Optional[FunctionInvocation] = None
fee_transfer_invocation: Optional[FunctionInvocation] = None
state_diff: Optional[StateDiff] = None
Expand Down
28 changes: 28 additions & 0 deletions starknet_py/net/full_node_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
L1HandlerTransaction,
PendingBlockStateUpdate,
PendingStarknetBlock,
PendingStarknetBlockWithReceipts,
PendingStarknetBlockWithTxHashes,
SentTransactionResponse,
SierraContractClass,
SimulatedTransaction,
SimulationFlag,
StarknetBlock,
StarknetBlockWithReceipts,
StarknetBlockWithTxHashes,
SyncStatus,
Tag,
Expand Down Expand Up @@ -60,11 +62,13 @@
EventsChunkSchema,
PendingBlockStateUpdateSchema,
PendingStarknetBlockSchema,
PendingStarknetBlockWithReceiptsSchema,
PendingStarknetBlockWithTxHashesSchema,
SentTransactionSchema,
SierraContractClassSchema,
SimulatedTransactionSchema,
StarknetBlockSchema,
StarknetBlockWithReceiptsSchema,
StarknetBlockWithTxHashesSchema,
SyncStatusSchema,
TransactionReceiptSchema,
Expand Down Expand Up @@ -146,6 +150,30 @@ async def get_block_with_tx_hashes(
StarknetBlockWithTxHashesSchema().load(res, unknown=EXCLUDE),
)

async def get_block_with_receipts(
self,
block_hash: Optional[Union[Hash, Tag]] = None,
block_number: Optional[Union[int, Tag]] = None,
):
block_identifier = get_block_identifier(
block_hash=block_hash, block_number=block_number
)

res = await self._client.call(
method_name="getBlockWithReceipts",
params=block_identifier,
)

if block_identifier == {"block_id": "pending"}:
return cast(
PendingStarknetBlockWithReceipts,
PendingStarknetBlockWithReceiptsSchema().load(res, unknown=EXCLUDE),
)
return cast(
StarknetBlockWithReceipts,
StarknetBlockWithReceiptsSchema().load(res, unknown=EXCLUDE),
)

# TODO (#809): add tests with multiple emitted keys
async def get_events(
self,
Expand Down
Loading
Loading