Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.

Commit ad33442

Browse files
authored
Merge pull request #1940 from veox/add-python3.8-testing-take2
Add Python 3.8 testing (take 2)
2 parents eda5cb0 + d7af77e commit ad33442

File tree

29 files changed

+177
-105
lines changed

29 files changed

+177
-105
lines changed

.circleci/config.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,37 @@ jobs:
168168
environment:
169169
TOXENV: py37-lint
170170

171+
py38-core:
172+
<<: *common
173+
docker:
174+
- image: circleci/python:3.8
175+
environment:
176+
TOXENV: py38-core
177+
py38-database:
178+
<<: *common
179+
docker:
180+
- image: circleci/python:3.8
181+
environment:
182+
TOXENV: py38-database
183+
py38-transactions:
184+
<<: *common
185+
docker:
186+
- image: circleci/python:3.8
187+
environment:
188+
TOXENV: py38-transactions
189+
py38-vm:
190+
<<: *common
191+
docker:
192+
- image: circleci/python:3.8
193+
environment:
194+
TOXENV: py38-vm
195+
py38-lint:
196+
<<: *common
197+
docker:
198+
- image: circleci/python:3.8
199+
environment:
200+
TOXENV: py38-lint
201+
171202
workflows:
172203
version: 2
173204
test:
@@ -184,12 +215,17 @@ workflows:
184215
- py36-native-blockchain-transition
185216
- py36-vm
186217
- py37-vm
218+
- py38-vm
187219
- py36-core
188220
- py37-core
221+
- py38-core
189222
- py36-transactions
190223
- py37-transactions
224+
- py38-transactions
191225
- py36-database
192226
- py37-database
227+
- py38-database
193228
- py36-docs
194229
- py36-lint
195230
- py37-lint
231+
- py38-lint

eth/_utils/transactions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ def calculate_intrinsic_gas(
136136
else:
137137
create_cost = 0
138138
return (
139-
gas_schedule.gas_tx +
140-
num_zero_bytes * gas_schedule.gas_txdatazero +
141-
num_non_zero_bytes * gas_schedule.gas_txdatanonzero +
142-
create_cost
139+
gas_schedule.gas_tx
140+
+ num_zero_bytes * gas_schedule.gas_txdatazero
141+
+ num_non_zero_bytes * gas_schedule.gas_txdatanonzero
142+
+ create_cost
143143
)

eth/abc.py

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
TypeVar,
2121
Union,
2222
)
23-
from uuid import UUID
2423

2524
import rlp
2625

@@ -886,9 +885,9 @@ def __call__(self, computation: 'ComputationAPI') -> None:
886885
def as_opcode(cls: Type[T],
887886
logic_fn: Callable[['ComputationAPI'], None],
888887
mnemonic: str,
889-
gas_cost: int) -> Type[T]:
888+
gas_cost: int) -> T:
890889
"""
891-
Class factory method for turning vanilla functions into Opcode classes.
890+
Class factory method for turning vanilla functions into Opcodes.
892891
"""
893892
...
894893

@@ -1769,6 +1768,16 @@ def state_root(self) -> Hash32:
17691768
"""
17701769
...
17711770

1771+
@state_root.setter
1772+
def state_root(self, value: Hash32) -> None:
1773+
"""
1774+
Force-set the state root hash.
1775+
"""
1776+
# See: https://github.com/python/mypy/issues/4165
1777+
# Since we can't also decorate this with abstract method we want to be
1778+
# sure that the setter doesn't actually get used as a noop.
1779+
raise NotImplementedError
1780+
17721781
@abstractmethod
17731782
def has_root(self, state_root: bytes) -> bool:
17741783
"""
@@ -1935,6 +1944,22 @@ def commit(self, checkpoint: JournalDBCheckpoint) -> None:
19351944
"""
19361945
...
19371946

1947+
@abstractmethod
1948+
def lock_changes(self) -> None:
1949+
"""
1950+
Locks in changes across all accounts' storage databases.
1951+
1952+
This is typically used at the end of a transaction, to make sure that
1953+
a revert doesn't roll back through the previous transaction, and to
1954+
be able to look up the "original" value of any account storage, where
1955+
"original" is the beginning of a transaction (instead of the beginning
1956+
of a block).
1957+
1958+
See :meth:`eth.abc.AccountStorageDatabaseAPI.lock_changes` for
1959+
what is called on each account's storage database.
1960+
"""
1961+
...
1962+
19381963
@abstractmethod
19391964
def make_state_root(self) -> Hash32:
19401965
"""
@@ -2275,7 +2300,7 @@ def account_is_empty(self, address: Address) -> bool:
22752300
# Access self._chaindb
22762301
#
22772302
@abstractmethod
2278-
def snapshot(self) -> Tuple[Hash32, UUID]:
2303+
def snapshot(self) -> Tuple[Hash32, JournalDBCheckpoint]:
22792304
"""
22802305
Perform a full snapshot of the current state.
22812306
@@ -2285,14 +2310,14 @@ def snapshot(self) -> Tuple[Hash32, UUID]:
22852310
...
22862311

22872312
@abstractmethod
2288-
def revert(self, snapshot: Tuple[Hash32, UUID]) -> None:
2313+
def revert(self, snapshot: Tuple[Hash32, JournalDBCheckpoint]) -> None:
22892314
"""
22902315
Revert the VM to the state at the snapshot
22912316
"""
22922317
...
22932318

22942319
@abstractmethod
2295-
def commit(self, snapshot: Tuple[Hash32, UUID]) -> None:
2320+
def commit(self, snapshot: Tuple[Hash32, JournalDBCheckpoint]) -> None:
22962321
"""
22972322
Commit the journal to the point where the snapshot was taken. This
22982323
merges in any changes that were recorded since the snapshot.
@@ -2481,6 +2506,7 @@ class VirtualMachineAPI(ConfigurableAPI):
24812506
def __init__(self,
24822507
header: BlockHeaderAPI,
24832508
chaindb: ChainDatabaseAPI,
2509+
chain_context: ChainContextAPI,
24842510
consensus_context: ConsensusContextAPI) -> None:
24852511
"""
24862512
Initialize the virtual machine.

eth/chains/base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ def from_genesis(cls,
244244
# the computed state from the initialized state database.
245245
raise ValidationError(
246246
"The provided genesis state root does not match the computed "
247-
f"genesis state root. Got {state.state_root}. "
248-
f"Expected {genesis_params['state_root']}"
247+
f"genesis state root. Got {state.state_root!r}. "
248+
f"Expected {genesis_params['state_root']!r}"
249249
)
250250

251251
genesis_header = BlockHeader(**genesis_params)
@@ -463,8 +463,8 @@ def import_block(self,
463463
except HeaderNotFound:
464464
raise ValidationError(
465465
f"Attempt to import block #{block.number}. "
466-
f"Cannot import block {block.hash} before importing "
467-
f"its parent block at {block.header.parent_hash}"
466+
f"Cannot import block {block.hash!r} before importing "
467+
f"its parent block at {block.header.parent_hash!r}"
468468
)
469469

470470
base_header_for_import = self.create_header_from_parent(parent_header)

eth/consensus/clique/_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@ def validate_header_integrity(header: BlockHeaderAPI, epoch_length: int) -> None
139139
)
140140

141141
if header.nonce != NONCE_AUTH and header.nonce != NONCE_DROP:
142-
raise ValidationError(f"Invalid nonce: {header.nonce}")
142+
raise ValidationError(f"Invalid nonce: {header.nonce!r}")
143143

144144
if at_checkpoint and header.nonce != NONCE_DROP:
145-
raise ValidationError(f"Invalid checkpoint nonce: {header.nonce}")
145+
raise ValidationError(f"Invalid checkpoint nonce: {header.nonce!r}")
146146

147147
if len(header.extra_data) < VANITY_LENGTH:
148148
raise ValidationError("Missing vanity bytes in extra data")
@@ -159,7 +159,7 @@ def validate_header_integrity(header: BlockHeaderAPI, epoch_length: int) -> None
159159
raise ValidationError("Checkpoint header must contain list of signers")
160160

161161
if header.mix_hash != ZERO_HASH32:
162-
raise ValidationError(f"Invalid mix hash: {header.mix_hash}")
162+
raise ValidationError(f"Invalid mix hash: {header.mix_hash!r}")
163163

164164
if header.uncles_hash != EMPTY_UNCLE_HASH:
165165
raise ValidationError(f"Invalid uncle hash: {header.uncle_hash}")

eth/consensus/clique/datatypes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def validate_for(self,
4646
if not signer_is_kicked and not signer_is_nominated:
4747
raise ValidationError(
4848
"Must either kick an existing signer or nominate a new signer"
49-
f"Subject: {subject} Current signers: {signers}"
49+
f"Subject: {subject!r} Current signers: {signers}"
5050
)
5151

5252

eth/consensus/clique/snapshot_manager.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def create_snapshot_for(self,
182182
try:
183183
new_snapshot = self.get_snapshot(
184184
current_header.block_number, current_header.parent_hash)
185-
except SnapshotNotFound as e:
185+
except SnapshotNotFound:
186186
current_header = self._lookup_header(current_header.parent_hash, cached_parents)
187187

188188
if is_checkpoint(current_header.block_number, self._epoch_length):
@@ -225,16 +225,16 @@ def get_snapshot(self, block_number: int, block_hash: Hash32) -> Snapshot:
225225
# Otherwise, we can retrieve it on the fly
226226
header = self._chain_db.get_block_header_by_hash(block_hash)
227227
except HeaderNotFound:
228-
raise SnapshotNotFound(f"Can not get snapshot for {block_hash} at {block_number}")
228+
raise SnapshotNotFound(f"Can not get snapshot for {block_hash!r} at {block_number}")
229229
else:
230230
if header.block_number != block_number:
231231
raise SnapshotNotFound(
232-
f"Can not get snapshot for {block_hash} at {block_number}"
232+
f"Can not get snapshot for {block_hash!r} at {block_number}"
233233
)
234234
else:
235235
return self._create_snapshot_from_checkpoint_header(header)
236236

237-
raise SnapshotNotFound(f"Can not get snapshot for {block_hash} at {block_number}")
237+
raise SnapshotNotFound(f"Can not get snapshot for {block_hash!r} at {block_number}")
238238

239239
def add_snapshot(self, mutable_snapshot: MutableSnapshot) -> Snapshot:
240240
"""
@@ -261,8 +261,8 @@ def get_snapshot_from_db(self, block_hash: Hash32) -> Snapshot:
261261
encoded_key = self._chain_db.db[key]
262262
except KeyError as e:
263263
raise SnapshotNotFound(
264-
f"Can not get on-disk snapshot for {block_hash}"
265-
)
264+
f"Can not get on-disk snapshot for {block_hash!r}"
265+
) from e
266266
else:
267267
return decode_snapshot(encoded_key)
268268

eth/db/chain.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def get_block_uncles(self, uncles_hash: Hash32) -> Tuple[BlockHeaderAPI, ...]:
8686
encoded_uncles = self.db[uncles_hash]
8787
except KeyError:
8888
raise HeaderNotFound(
89-
f"No uncles found for hash {uncles_hash}"
89+
f"No uncles found for hash {uncles_hash!r}"
9090
)
9191
else:
9292
return tuple(rlp.decode(encoded_uncles, sedes=rlp.sedes.CountableList(BlockHeader)))
@@ -141,16 +141,16 @@ def persist_unexecuted_block(self,
141141

142142
if tx_root_hash != block.header.transaction_root:
143143
raise ValidationError(
144-
f"Block's transaction_root ({block.header.transaction_root}) "
145-
f"does not match expected value: {tx_root_hash}"
144+
f"Block's transaction_root ({block.header.transaction_root!r}) "
145+
f"does not match expected value: {tx_root_hash!r}"
146146
)
147147

148148
receipt_root_hash, receipt_kv_nodes = make_trie_root_and_nodes(receipts)
149149

150150
if receipt_root_hash != block.header.receipt_root:
151151
raise ValidationError(
152-
f"Block's receipt_root ({block.header.receipt_root}) "
153-
f"does not match expected value: {receipt_root_hash}"
152+
f"Block's receipt_root ({block.header.receipt_root!r}) "
153+
f"does not match expected value: {receipt_root_hash!r}"
154154
)
155155

156156
with self.db.atomic_batch() as db:

eth/db/header.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,23 @@ def _update_header_chain_gaps(
7979
cls,
8080
db: DatabaseAPI,
8181
persisted_header: BlockHeaderAPI,
82-
base_gaps: ChainGaps = None) -> GapInfo:
82+
base_gaps: ChainGaps = None
83+
) -> GapInfo:
8384

84-
# If we make many updates in a row, we can avoid reloading the integrity info by
85-
# continuously caching it and providing it as a parameter to this API
86-
if base_gaps is None:
87-
base_gaps = cls._get_header_chain_gaps(db)
85+
# If we make many updates in a row, we can avoid reloading the integrity info by
86+
# continuously caching it and providing it as a parameter to this API
87+
if base_gaps is None:
88+
base_gaps = cls._get_header_chain_gaps(db)
8889

89-
gap_change, gaps = fill_gap(persisted_header.block_number, base_gaps)
90+
gap_change, gaps = fill_gap(persisted_header.block_number, base_gaps)
9091

91-
if gap_change is not GapChange.NoChange:
92-
db.set(
93-
SchemaV1.make_header_chain_gaps_lookup_key(),
94-
rlp.encode(gaps, sedes=chain_gaps)
95-
)
92+
if gap_change is not GapChange.NoChange:
93+
db.set(
94+
SchemaV1.make_header_chain_gaps_lookup_key(),
95+
rlp.encode(gaps, sedes=chain_gaps)
96+
)
9697

97-
return gap_change, gaps
98+
return gap_change, gaps
9899

99100
#
100101
# Canonical Chain API
@@ -260,7 +261,7 @@ def _persist_checkpoint_header(
260261
# True parent should have already been canonicalized during
261262
# _set_as_canonical_chain_head()
262263
raise ValidationError(
263-
f"Why was a non-matching parent header {parent_hash} left as canonical "
264+
f"Why was a non-matching parent header {parent_hash!r} left as canonical "
264265
f"after _set_as_canonical_chain_head() and {true_parent} is available?"
265266
)
266267

eth/precompiles/modexp.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ def _compute_adjusted_exponent_length(exponent_length: int,
3434
else:
3535
first_32_bytes_as_int = big_endian_to_int(first_32_exponent_bytes)
3636
return (
37-
8 * (exponent_length - 32) +
38-
get_highest_bit_index(first_32_bytes_as_int)
37+
8 * (exponent_length - 32)
38+
+ get_highest_bit_index(first_32_bytes_as_int)
3939
)
4040

4141

@@ -78,9 +78,9 @@ def _compute_modexp_gas_fee(data: bytes) -> int:
7878
complexity = _compute_complexity(max(modulus_length, base_length))
7979

8080
gas_fee = (
81-
complexity *
82-
max(adjusted_exponent_length, 1) //
83-
constants.GAS_MOD_EXP_QUADRATIC_DENOMINATOR
81+
complexity
82+
* max(adjusted_exponent_length, 1)
83+
// constants.GAS_MOD_EXP_QUADRATIC_DENOMINATOR
8484
)
8585
return gas_fee
8686

0 commit comments

Comments
 (0)