Skip to content

Commit 0e1d230

Browse files
Support RPC 0.7.0 (#1307)
* Merge changes from the initial PR * Add `BlockHeader` and `PendingBlockHeader` * Add tests for `get_block_with_receipt` * Update client models and schemas * Update docs and workflow * Increase max fee for devnet tests * Add more tests * Update devnet sha in the workflow * Fix failing docs test * Update estimated fee multiplier description in docs * Update devnet sha * Enhance asserts in block tests * Cover case when `estimated_fee.gas_price` equals 0 * Update migration guide * Fix `trace_transaction` * Reorder fields in `TransactionReceipt` * Run trace api tests on integration * Add alpha information to migration guide * Update docs/migration_guide.rst Co-authored-by: Maksim Zdobnikau <43750648+DelevoXDG@users.noreply.github.com> --------- Co-authored-by: Maksim Zdobnikau <43750648+DelevoXDG@users.noreply.github.com>
1 parent f3e3d3f commit 0e1d230

File tree

18 files changed

+422
-146
lines changed

18 files changed

+422
-146
lines changed

.github/workflows/checks.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
name: Checks
22

33
env:
4-
STARKNET_VERSION: "0.13.0"
5-
RPC_SPEC_VERSION: "0.6.0"
6-
DEVNET_SHA: "1bd447d"
4+
DEVNET_SHA: "c6ffb99"
75

86
on:
97
push:

docs/development.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@ Below is the command you can use to do this, designed for compatibility with the
2424

2525
.. code-block:: bash
2626
27-
STARKNET_VERSION="0.13.0" RPC_SPEC_VERSION="0.6.0" \
2827
cargo install \
2928
--locked \
3029
--git https://github.com/0xSpaceShard/starknet-devnet-rs.git \
31-
--rev 1bd447d
30+
--rev c6ffb99
3231
3332
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.
3433

docs/guide/account_and_client.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ To enable auto estimation, set the ``auto_estimate`` parameter to ``True``.
2828
It is strongly discouraged to use automatic fee estimation in production code as it may lead to an unexpectedly high fee.
2929

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

3433
.. note::
3534
It is possible to configure the value by which the estimated fee is multiplied,

docs/migration_guide.rst

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,36 @@
11
Migration guide
22
===============
33

4-
**********************
5-
0.21.0 Migration guide
6-
**********************
4+
******************************
5+
0.21.0 (alpha) Migration guide
6+
******************************
77

8-
0.21.0 Minor changes
8+
Version 0.21.0 of **starknet.py** comes with support for RPC 0.7.0-rc2!
9+
10+
0.21.0 Targeted versions
11+
------------------------
12+
13+
- Starknet - `0.13.1 <https://docs.starknet.io/documentation/starknet_versions/version_notes/#version0.13.1>`_
14+
- RPC - `0.7.0-rc2 <https://github.com/starkware-libs/starknet-specs/releases/tag/v0.7.0-rc2>`_
15+
16+
0.21.0 Breaking changes
917
-----------------------
1018

1119
.. currentmodule:: starknet_py.net.client_models
1220

21+
1. :class:`PendingStarknetBlock` and :class:`PendingStarknetBlockWithTxHashes` field ``parent_block_hash`` has been renamed to ``parent_hash``
22+
2. :class:`StarknetBlockCommon` has been renamed to :class:`BlockHeader`
23+
3. :class:`StarknetBlock` and :class:`StarknetBlockWithTxHashes` fields ``parent_block_hash`` and ``root`` have been renamed to ``parent_hash`` and ``new_root`` respectively
24+
4. :class:`FunctionInvocation` field ``execution_resources`` has been renamed to ``computation_resources``
25+
26+
0.21.0 Minor changes
27+
-----------------------
28+
1329
1. :class:`EventsChunk` field ``events`` is now a list of :class:`EmittedEvent` instead of :class:`Event`
30+
2. :class:`ExecutionResources` has a new required field ``data_availability``
31+
3. :class:`InvokeTransactionTrace`, :class:`DeclareTransactionTrace` and :class:`DeployAccountTransactionTrace` have a new required field ``execution_resources``
32+
4. :class:`EstimatedFee` has new required fields ``data_gas_consumed`` and ``data_gas_price``
33+
5. :class:`StarknetBlock`, :class:`PendingStarknetBlock`, :class:`StarknetBlockWithTxHashes`, :class:`PendingStarknetBlockWithTxHashes` have new required fields ``l1_data_gas_price`` and ``l1_da_mode``
1434

1535
**********************
1636
0.20.0 Migration guide

starknet_py/net/account/account.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class Account(BaseAccount):
6060
ESTIMATED_FEE_MULTIPLIER: float = 1.5
6161
"""Amount by which each estimated fee is multiplied when using `auto_estimate`."""
6262

63-
ESTIMATED_AMOUNT_MULTIPLIER: float = 1.1
63+
ESTIMATED_AMOUNT_MULTIPLIER: float = 1.5
6464
ESTIMATED_UNIT_PRICE_MULTIPLIER: float = 1.5
6565
"""Values by which each estimated `max_amount` and `max_price_per_unit` are multiplied when using
6666
`auto_estimate`. Used only for V3 transactions"""
@@ -165,7 +165,10 @@ async def _get_resource_bounds(
165165

166166
l1_resource_bounds = ResourceBounds(
167167
max_amount=int(
168-
estimated_fee.gas_consumed * Account.ESTIMATED_AMOUNT_MULTIPLIER
168+
(estimated_fee.overall_fee / estimated_fee.gas_price)
169+
* Account.ESTIMATED_AMOUNT_MULTIPLIER
170+
if estimated_fee.gas_price != 0
171+
else 0
169172
),
170173
max_price_per_unit=int(
171174
estimated_fee.gas_price * Account.ESTIMATED_UNIT_PRICE_MULTIPLIER

starknet_py/net/client_models.py

Lines changed: 90 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ class DAMode(Enum):
142142
L2 = 1
143143

144144

145+
class L1DAMode(Enum):
146+
BLOB = "BLOB"
147+
CALLDATA = "CALLDATA"
148+
149+
145150
class TransactionType(Enum):
146151
"""
147152
Enum representing transaction types.
@@ -358,23 +363,42 @@ class TransactionFinalityStatus(Enum):
358363

359364

360365
@dataclass
361-
class ExecutionResources:
366+
class DataResources:
367+
"""
368+
Dataclass representing the data-availability resources of the transaction
369+
"""
370+
371+
l1_gas: int
372+
l1_data_gas: int
373+
374+
375+
@dataclass
376+
class ComputationResources:
362377
"""
363-
Dataclass representing the resources consumed by the transaction.
378+
Dataclass representing the resources consumed by the VM.
364379
"""
365380

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

368383
steps: int
369-
range_check_builtin_applications: Optional[int] = None
370-
pedersen_builtin_applications: Optional[int] = None
371-
poseidon_builtin_applications: Optional[int] = None
372-
ec_op_builtin_applications: Optional[int] = None
373-
ecdsa_builtin_applications: Optional[int] = None
374-
bitwise_builtin_applications: Optional[int] = None
375-
keccak_builtin_applications: Optional[int] = None
376-
memory_holes: Optional[int] = None
377-
segment_arena_builtin: Optional[int] = None
384+
memory_holes: Optional[int]
385+
range_check_builtin_applications: Optional[int]
386+
pedersen_builtin_applications: Optional[int]
387+
poseidon_builtin_applications: Optional[int]
388+
ec_op_builtin_applications: Optional[int]
389+
ecdsa_builtin_applications: Optional[int]
390+
bitwise_builtin_applications: Optional[int]
391+
keccak_builtin_applications: Optional[int]
392+
segment_arena_builtin: Optional[int]
393+
394+
395+
@dataclass
396+
class ExecutionResources(ComputationResources):
397+
"""
398+
Dataclass representing the resources consumed by the transaction, includes both computation and data.
399+
"""
400+
401+
data_availability: DataResources
378402

379403

380404
# TODO (#1219): split into PendingTransactionReceipt and TransactionReceipt
@@ -396,16 +420,21 @@ class TransactionReceipt:
396420
events: List[Event] = field(default_factory=list)
397421
messages_sent: List[L2toL1Message] = field(default_factory=list)
398422

399-
contract_address: Optional[int] = None
400-
401423
block_number: Optional[int] = None
402424
block_hash: Optional[int] = None
403425

404-
message_hash: Optional[int] = None # L1_HANDLER_TXN_RECEIPT-only
426+
contract_address: Optional[int] = None # DEPLOY_ACCOUNT_TXN_RECEIPT only
427+
message_hash: Optional[int] = None # L1_HANDLER_TXN_RECEIPT only
405428

406429
revert_reason: Optional[str] = None
407430

408431

432+
@dataclass
433+
class TransactionWithReceipt:
434+
transaction: Transaction
435+
receipt: TransactionReceipt
436+
437+
409438
@dataclass
410439
class SentTransactionResponse:
411440
"""
@@ -443,58 +472,68 @@ class BlockStatus(Enum):
443472
REJECTED = "REJECTED"
444473
ACCEPTED_ON_L2 = "ACCEPTED_ON_L2"
445474
ACCEPTED_ON_L1 = "ACCEPTED_ON_L1"
446-
PROVEN = "PROVEN"
447475

448476

449477
@dataclass
450-
class PendingStarknetBlock:
478+
class PendingBlockHeader:
479+
parent_hash: int
480+
timestamp: int
481+
sequencer_address: int
482+
l1_gas_price: ResourcePrice
483+
l1_data_gas_price: ResourcePrice
484+
l1_da_mode: L1DAMode
485+
starknet_version: str
486+
487+
488+
@dataclass
489+
class PendingStarknetBlock(PendingBlockHeader):
451490
"""
452491
Dataclass representing a pending block on Starknet.
453492
"""
454493

455494
transactions: List[Transaction]
456-
parent_block_hash: int
457-
timestamp: int
458-
sequencer_address: int
459-
l1_gas_price: ResourcePrice
460-
starknet_version: str
461495

462496

463497
@dataclass
464-
class PendingStarknetBlockWithTxHashes:
498+
class PendingStarknetBlockWithTxHashes(PendingBlockHeader):
465499
"""
466500
Dataclass representing a pending block on Starknet containing transaction hashes.
467501
"""
468502

469503
transactions: List[int]
470-
parent_block_hash: int
471-
timestamp: int
472-
sequencer_address: int
473-
l1_gas_price: ResourcePrice
474-
starknet_version: str
475504

476505

477506
@dataclass
478-
class StarknetBlockCommon:
507+
class PendingStarknetBlockWithReceipts(PendingBlockHeader):
508+
"""
509+
Dataclass representing a pending block on Starknet with txs and receipts result
510+
"""
511+
512+
transactions: List[TransactionWithReceipt]
513+
514+
515+
@dataclass
516+
class BlockHeader:
479517
"""
480518
Dataclass representing a block header.
481519
"""
482520

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

486523
block_hash: int
487-
parent_block_hash: int
524+
parent_hash: int
488525
block_number: int
489-
root: int
526+
new_root: int
490527
timestamp: int
491528
sequencer_address: int
492529
l1_gas_price: ResourcePrice
530+
l1_data_gas_price: ResourcePrice
531+
l1_da_mode: L1DAMode
493532
starknet_version: str
494533

495534

496535
@dataclass
497-
class StarknetBlock(StarknetBlockCommon):
536+
class StarknetBlock(BlockHeader):
498537
"""
499538
Dataclass representing a block on Starknet.
500539
"""
@@ -504,7 +543,7 @@ class StarknetBlock(StarknetBlockCommon):
504543

505544

506545
@dataclass
507-
class StarknetBlockWithTxHashes(StarknetBlockCommon):
546+
class StarknetBlockWithTxHashes(BlockHeader):
508547
"""
509548
Dataclass representing a block on Starknet containing transaction hashes.
510549
"""
@@ -513,6 +552,16 @@ class StarknetBlockWithTxHashes(StarknetBlockCommon):
513552
transactions: List[int]
514553

515554

555+
@dataclass
556+
class StarknetBlockWithReceipts(BlockHeader):
557+
"""
558+
Dataclass representing a block on Starknet with txs and receipts result
559+
"""
560+
561+
status: BlockStatus
562+
transactions: List[TransactionWithReceipt]
563+
564+
516565
@dataclass
517566
class BlockHashAndNumber:
518567
block_hash: int
@@ -555,9 +604,11 @@ class EstimatedFee:
555604
Dataclass representing estimated fee.
556605
"""
557606

558-
overall_fee: int
559-
gas_price: int
560607
gas_consumed: int
608+
gas_price: int
609+
data_gas_consumed: int
610+
data_gas_price: int
611+
overall_fee: int
561612
unit: PriceUnit
562613

563614

@@ -842,7 +893,7 @@ class FunctionInvocation:
842893
calls: List["FunctionInvocation"]
843894
events: List[OrderedEvent]
844895
messages: List[OrderedMessage]
845-
execution_resources: ExecutionResources
896+
computation_resources: ComputationResources
846897

847898

848899
@dataclass
@@ -861,6 +912,7 @@ class InvokeTransactionTrace:
861912
"""
862913

863914
execute_invocation: Union[FunctionInvocation, RevertedFunctionInvocation]
915+
execution_resources: ExecutionResources
864916
validate_invocation: Optional[FunctionInvocation] = None
865917
fee_transfer_invocation: Optional[FunctionInvocation] = None
866918
state_diff: Optional[StateDiff] = None
@@ -872,6 +924,7 @@ class DeclareTransactionTrace:
872924
Dataclass representing a transaction trace of an DECLARE transaction.
873925
"""
874926

927+
execution_resources: ExecutionResources
875928
validate_invocation: Optional[FunctionInvocation] = None
876929
fee_transfer_invocation: Optional[FunctionInvocation] = None
877930
state_diff: Optional[StateDiff] = None
@@ -884,6 +937,7 @@ class DeployAccountTransactionTrace:
884937
"""
885938

886939
constructor_invocation: FunctionInvocation
940+
execution_resources: ExecutionResources
887941
validate_invocation: Optional[FunctionInvocation] = None
888942
fee_transfer_invocation: Optional[FunctionInvocation] = None
889943
state_diff: Optional[StateDiff] = None

0 commit comments

Comments
 (0)