Skip to content

Commit e3e4d1f

Browse files
Bhargavasomupipermerriam
authored andcommitted
Change inheritance order for chain_class_without_seal_validation (#1723)
* Change inheritance order for chain_class_without_seal_validation to prevent MRO errors * Add tests for disabling an already pow disabled chain
1 parent 100b8c7 commit e3e4d1f

File tree

2 files changed

+41
-10
lines changed

2 files changed

+41
-10
lines changed

eth/tools/builder/chain/builders.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,15 @@ def validate_seal(cls, header: BlockHeader) -> None:
290290
@to_tuple
291291
def _mix_in_disable_seal_validation(vm_configuration: VMConfiguration) -> Iterable[VMFork]:
292292
for fork_block, vm_class in vm_configuration:
293-
vm_class_without_seal_validation = type(
294-
vm_class.__name__,
295-
(NoVMSealValidationMixin, vm_class),
296-
{},
297-
)
293+
if issubclass(vm_class, NoVMSealValidationMixin):
294+
# Seal validation already disabled, hence nothing to change
295+
vm_class_without_seal_validation = vm_class
296+
else:
297+
vm_class_without_seal_validation = type(
298+
vm_class.__name__,
299+
(NoVMSealValidationMixin, vm_class),
300+
{},
301+
)
298302
yield fork_block, vm_class_without_seal_validation
299303

300304

@@ -312,11 +316,15 @@ def disable_pow_check(chain_class: Type[BaseChain]) -> Type[BaseChain]:
312316
if not chain_class.vm_configuration:
313317
raise ValidationError("Chain class has no vm_configuration")
314318

315-
chain_class_without_seal_validation = type(
316-
chain_class.__name__,
317-
(NoChainSealValidationMixin, chain_class),
318-
{},
319-
)
319+
if issubclass(chain_class, NoChainSealValidationMixin):
320+
# Seal validation already disabled, hence nothing to change
321+
chain_class_without_seal_validation = chain_class
322+
else:
323+
chain_class_without_seal_validation = type(
324+
chain_class.__name__,
325+
(chain_class, NoChainSealValidationMixin),
326+
{},
327+
)
320328
return chain_class_without_seal_validation.configure( # type: ignore
321329
vm_configuration=_mix_in_disable_seal_validation(
322330
chain_class_without_seal_validation.vm_configuration # type: ignore

tests/core/builder-tools/test_chain_builder.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
from eth_utils import ValidationError
44

5+
from eth.chains import (
6+
MainnetChain,
7+
MainnetTesterChain,
8+
RopstenChain,
9+
)
510
from eth.chains.base import (
611
Chain,
712
MiningChain,
@@ -19,6 +24,9 @@
1924
mine_block,
2025
mine_blocks,
2126
)
27+
from eth.tools.builder.chain.builders import (
28+
NoChainSealValidationMixin,
29+
)
2230

2331

2432
MINING_CHAIN_PARAMS = (
@@ -229,3 +237,18 @@ def test_chain_builder_chain_split(mining_chain):
229237

230238
head_b = chain_b.get_canonical_head()
231239
assert head_b.block_number == 3
240+
241+
242+
@pytest.mark.parametrize(
243+
"chain",
244+
(
245+
MainnetChain,
246+
MainnetTesterChain,
247+
RopstenChain,
248+
)
249+
)
250+
def test_disabling_pow_for_already_pow_disabled_chain(chain):
251+
pow_disabled_chain = disable_pow_check(chain)
252+
assert issubclass(pow_disabled_chain, NoChainSealValidationMixin)
253+
again_pow_disabled_chain = disable_pow_check(pow_disabled_chain)
254+
assert issubclass(again_pow_disabled_chain, NoChainSealValidationMixin)

0 commit comments

Comments
 (0)