Skip to content

Commit e9911e6

Browse files
committed
Run isort and black
1 parent dc3a3e4 commit e9911e6

File tree

14 files changed

+534
-478
lines changed

14 files changed

+534
-478
lines changed

src/ethereum/osaka/block_access_lists/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@
4848
"track_storage_read",
4949
"track_storage_write",
5050
"validate_bal_against_execution",
51-
]
51+
]

src/ethereum/osaka/block_access_lists/builder.py

Lines changed: 83 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -38,32 +38,35 @@
3838
class AccountData:
3939
"""
4040
Account data stored in the builder during block execution.
41-
41+
4242
This dataclass tracks all changes made to a single account throughout
4343
the execution of a block, organized by the type of change and the
4444
transaction index where it occurred.
4545
"""
46-
storage_changes: Dict[Bytes, List[StorageChange]] = field(default_factory=dict)
46+
47+
storage_changes: Dict[Bytes, List[StorageChange]] = field(
48+
default_factory=dict
49+
)
4750
"""
4851
Mapping from storage slot to list of changes made to that slot.
4952
Each change includes the transaction index and new value.
5053
"""
51-
54+
5255
storage_reads: Set[Bytes] = field(default_factory=set)
5356
"""
5457
Set of storage slots that were read but not modified.
5558
"""
56-
59+
5760
balance_changes: List[BalanceChange] = field(default_factory=list)
5861
"""
5962
List of balance changes for this account, ordered by transaction index.
6063
"""
61-
64+
6265
nonce_changes: List[NonceChange] = field(default_factory=list)
6366
"""
6467
List of nonce changes for this account, ordered by transaction index.
6568
"""
66-
69+
6770
code_changes: List[CodeChange] = field(default_factory=list)
6871
"""
6972
List of code changes (contract deployments) for this account,
@@ -76,14 +79,15 @@ class BlockAccessListBuilder:
7679
"""
7780
Builder for constructing [`BlockAccessList`] efficiently during transaction
7881
execution.
79-
82+
8083
The builder accumulates all account and storage accesses during block
8184
execution and constructs a deterministic access list. Changes are tracked
8285
by address, field type, and transaction index to enable efficient
8386
reconstruction of state changes.
84-
87+
8588
[`BlockAccessList`]: ref:ethereum.osaka.ssz_types.BlockAccessList
8689
"""
90+
8791
accounts: Dict[Address, AccountData] = field(default_factory=dict)
8892
"""
8993
Mapping from account address to its tracked changes during block execution.
@@ -93,18 +97,18 @@ class BlockAccessListBuilder:
9397
def ensure_account(builder: BlockAccessListBuilder, address: Address) -> None:
9498
"""
9599
Ensure an account exists in the builder's tracking structure.
96-
100+
97101
Creates an empty [`AccountData`] entry for the given address if it
98102
doesn't already exist. This function is idempotent and safe to call
99103
multiple times for the same address.
100-
104+
101105
Parameters
102106
----------
103107
builder :
104108
The block access list builder instance.
105109
address :
106110
The account address to ensure exists.
107-
111+
108112
[`AccountData`]: ref:ethereum.osaka.block_access_lists.builder.AccountData
109113
"""
110114
if address not in builder.accounts:
@@ -113,18 +117,18 @@ def ensure_account(builder: BlockAccessListBuilder, address: Address) -> None:
113117

114118
def add_storage_write(
115119
builder: BlockAccessListBuilder,
116-
address: Address,
117-
slot: Bytes,
118-
tx_index: U32,
119-
new_value: Bytes
120+
address: Address,
121+
slot: Bytes,
122+
tx_index: U32,
123+
new_value: Bytes,
120124
) -> None:
121125
"""
122126
Add a storage write operation to the block access list.
123-
127+
124128
Records a storage slot modification for a given address at a specific
125129
transaction index. Multiple writes to the same slot are tracked
126130
separately, maintaining the order and transaction index of each change.
127-
131+
128132
Parameters
129133
----------
130134
builder :
@@ -139,26 +143,24 @@ def add_storage_write(
139143
The new value being written to the storage slot.
140144
"""
141145
ensure_account(builder, address)
142-
146+
143147
if slot not in builder.accounts[address].storage_changes:
144148
builder.accounts[address].storage_changes[slot] = []
145-
149+
146150
change = StorageChange(tx_index=tx_index, new_value=new_value)
147151
builder.accounts[address].storage_changes[slot].append(change)
148152

149153

150154
def add_storage_read(
151-
builder: BlockAccessListBuilder,
152-
address: Address,
153-
slot: Bytes
155+
builder: BlockAccessListBuilder, address: Address, slot: Bytes
154156
) -> None:
155157
"""
156158
Add a storage read operation to the block access list.
157-
159+
158160
Records that a storage slot was read during execution. Storage slots
159161
that are both read and written will only appear in the storage changes
160162
list, not in the storage reads list, as per [EIP-7928].
161-
163+
162164
Parameters
163165
----------
164166
builder :
@@ -167,7 +169,7 @@ def add_storage_read(
167169
The account address whose storage is being read.
168170
slot :
169171
The storage slot being read.
170-
172+
171173
[EIP-7928]: https://eips.ethereum.org/EIPS/eip-7928
172174
"""
173175
ensure_account(builder, address)
@@ -176,17 +178,17 @@ def add_storage_read(
176178

177179
def add_balance_change(
178180
builder: BlockAccessListBuilder,
179-
address: Address,
180-
tx_index: U32,
181-
post_balance: Bytes
181+
address: Address,
182+
tx_index: U32,
183+
post_balance: Bytes,
182184
) -> None:
183185
"""
184186
Add a balance change to the block access list.
185-
187+
186188
Records the post-transaction balance for an account after it has been
187189
modified. This includes changes from transfers, gas fees, block rewards,
188190
and any other balance-affecting operations.
189-
191+
190192
Parameters
191193
----------
192194
builder :
@@ -199,24 +201,24 @@ def add_balance_change(
199201
The account balance after the change, encoded as bytes.
200202
"""
201203
ensure_account(builder, address)
202-
204+
203205
change = BalanceChange(tx_index=tx_index, post_balance=post_balance)
204206
builder.accounts[address].balance_changes.append(change)
205207

206208

207209
def add_nonce_change(
208210
builder: BlockAccessListBuilder,
209-
address: Address,
210-
tx_index: U32,
211-
new_nonce: U64
211+
address: Address,
212+
tx_index: U32,
213+
new_nonce: U64,
212214
) -> None:
213215
"""
214216
Add a nonce change to the block access list.
215-
217+
216218
Records a nonce increment for an account. This occurs when an EOA sends
217219
a transaction or when a contract performs [`CREATE`] or [`CREATE2`]
218220
operations.
219-
221+
220222
Parameters
221223
----------
222224
builder :
@@ -227,29 +229,29 @@ def add_nonce_change(
227229
The index of the transaction causing this change.
228230
new_nonce :
229231
The new nonce value after the change.
230-
232+
231233
[`CREATE`]: ref:ethereum.osaka.vm.instructions.system.create
232234
[`CREATE2`]: ref:ethereum.osaka.vm.instructions.system.create2
233235
"""
234236
ensure_account(builder, address)
235-
237+
236238
change = NonceChange(tx_index=tx_index, new_nonce=new_nonce)
237239
builder.accounts[address].nonce_changes.append(change)
238240

239241

240242
def add_code_change(
241243
builder: BlockAccessListBuilder,
242-
address: Address,
243-
tx_index: U32,
244-
new_code: Bytes
244+
address: Address,
245+
tx_index: U32,
246+
new_code: Bytes,
245247
) -> None:
246248
"""
247249
Add a code change to the block access list.
248-
250+
249251
Records contract code deployment or modification. This typically occurs
250252
during contract creation via [`CREATE`], [`CREATE2`], or [`SETCODE`]
251253
operations.
252-
254+
253255
Parameters
254256
----------
255257
builder :
@@ -260,33 +262,35 @@ def add_code_change(
260262
The index of the transaction deploying the code.
261263
new_code :
262264
The deployed contract bytecode.
263-
265+
264266
[`CREATE`]: ref:ethereum.osaka.vm.instructions.system.create
265267
[`CREATE2`]: ref:ethereum.osaka.vm.instructions.system.create2
266268
[`SETCODE`]: ref:ethereum.osaka.vm.instructions.system.setcode
267269
"""
268270
ensure_account(builder, address)
269-
271+
270272
change = CodeChange(tx_index=tx_index, new_code=new_code)
271273
builder.accounts[address].code_changes.append(change)
272274

273275

274-
def add_touched_account(builder: BlockAccessListBuilder, address: Address) -> None:
276+
def add_touched_account(
277+
builder: BlockAccessListBuilder, address: Address
278+
) -> None:
275279
"""
276280
Add an account that was accessed but not modified.
277-
281+
278282
Records that an account was accessed during execution without any state
279283
changes. This is used for operations like [`EXTCODEHASH`], [`BALANCE`],
280284
[`EXTCODESIZE`], and [`EXTCODECOPY`] that read account data without
281285
modifying it.
282-
286+
283287
Parameters
284288
----------
285289
builder :
286290
The block access list builder instance.
287291
address :
288292
The account address that was accessed.
289-
293+
290294
[`EXTCODEHASH`]: ref:ethereum.osaka.vm.instructions.environment.extcodehash
291295
[`BALANCE`]: ref:ethereum.osaka.vm.instructions.environment.balance
292296
[`EXTCODESIZE`]: ref:ethereum.osaka.vm.instructions.environment.extcodesize
@@ -298,58 +302,68 @@ def add_touched_account(builder: BlockAccessListBuilder, address: Address) -> No
298302
def build(builder: BlockAccessListBuilder) -> BlockAccessList:
299303
"""
300304
Build the final [`BlockAccessList`] from accumulated changes.
301-
305+
302306
Constructs a deterministic block access list by sorting all accumulated
303307
changes. The resulting list is ordered by:
304-
308+
305309
1. Account addresses (lexicographically)
306310
2. Within each account:
307311
- Storage slots (lexicographically)
308312
- Transaction indices (numerically) for each change type
309-
313+
310314
Parameters
311315
----------
312316
builder :
313317
The block access list builder containing all tracked changes.
314-
318+
315319
Returns
316320
-------
317321
block_access_list :
318322
The final sorted and encoded block access list.
319-
323+
320324
[`BlockAccessList`]: ref:ethereum.osaka.ssz_types.BlockAccessList
321325
"""
322326
account_changes_list = []
323-
327+
324328
for address, changes in builder.accounts.items():
325329
storage_changes = []
326330
for slot, slot_changes in changes.storage_changes.items():
327-
sorted_changes = tuple(sorted(slot_changes, key=lambda x: x.tx_index))
328-
storage_changes.append(SlotChanges(slot=slot, changes=sorted_changes))
329-
331+
sorted_changes = tuple(
332+
sorted(slot_changes, key=lambda x: x.tx_index)
333+
)
334+
storage_changes.append(
335+
SlotChanges(slot=slot, changes=sorted_changes)
336+
)
337+
330338
storage_reads = []
331339
for slot in changes.storage_reads:
332340
if slot not in changes.storage_changes:
333341
storage_reads.append(slot)
334-
335-
balance_changes = tuple(sorted(changes.balance_changes, key=lambda x: x.tx_index))
336-
nonce_changes = tuple(sorted(changes.nonce_changes, key=lambda x: x.tx_index))
337-
code_changes = tuple(sorted(changes.code_changes, key=lambda x: x.tx_index))
338-
342+
343+
balance_changes = tuple(
344+
sorted(changes.balance_changes, key=lambda x: x.tx_index)
345+
)
346+
nonce_changes = tuple(
347+
sorted(changes.nonce_changes, key=lambda x: x.tx_index)
348+
)
349+
code_changes = tuple(
350+
sorted(changes.code_changes, key=lambda x: x.tx_index)
351+
)
352+
339353
storage_changes.sort(key=lambda x: x.slot)
340354
storage_reads.sort()
341-
355+
342356
account_change = AccountChanges(
343357
address=address,
344358
storage_changes=tuple(storage_changes),
345359
storage_reads=tuple(storage_reads),
346360
balance_changes=balance_changes,
347361
nonce_changes=nonce_changes,
348-
code_changes=code_changes
362+
code_changes=code_changes,
349363
)
350-
364+
351365
account_changes_list.append(account_change)
352-
366+
353367
account_changes_list.sort(key=lambda x: x.address)
354-
355-
return BlockAccessList(account_changes=tuple(account_changes_list))
368+
369+
return BlockAccessList(account_changes=tuple(account_changes_list))

0 commit comments

Comments
 (0)