`VM.validate_header()` is called twice during `Chain.import_block()`?
See original GitHub issueWhat is wrong?
The current calling route:
class Chain(BaseChain):
def import_block(self,
block: BaseBlock,
perform_validation: bool=True
) -> Tuple[BaseBlock, Tuple[BaseBlock, ...], Tuple[BaseBlock, ...]]:
....
base_header_for_import = self.create_header_from_parent(parent_header)
imported_block = self.get_vm(base_header_for_import).import_block(block)
# ^^^^^^ dive into VM.import_block()
# Validate the imported block.
if perform_validation:
# ^^^^^^ perform_validation is True by default.
validate_imported_block_unchanged(imported_block, block)
self.validate_block(imported_block)
....
def validate_block(self, block: BaseBlock) -> None:
if block.is_genesis:
raise ValidationError("Cannot validate genesis block this way")
VM = self.get_vm_class_for_block_number(BlockNumber(block.number))
parent_block = self.get_block_by_hash(block.header.parent_hash)
VM.validate_header(block.header, parent_block.header, check_seal=True)
# ^^^^^^ second time call VM.validate_header!
....
class VM(BaseVM):
def import_block(self, block):
....
return self.mine_block()
def mine_block(self, *args, **kwargs):
....
# Perform validation
self.validate_block(final_block)
return final_block
def validate_block(self, block):
....
if block.is_genesis:
validate_length_lte(block.header.extra_data, 32, title="BlockHeader.extra_data")
else:
parent_header = get_parent_header(block.header, self.chaindb)
self.validate_header(block.header, parent_header)
# ^^^^^^ first time calling VM.validate_header! check_seal is True by default.
....
How can it be fixed
Is Chain.import_block
the main API for syncing?
I guess perform_validation
is for testing. Can we remove the second call and set the first call check_seal=True
?
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Service functions is called twice - Stack Overflow
You set function onSubmit() on two events: Button (click) and form (submit). It will call this twice. <div class="container"> <form ...
Read more >prepareForDML method called twice - Oracle Communities
Have concentrated business validation logic within the prepareForDML() of the updatable entity implementation. Under normal conditions, it works ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@pipermerriam whoops sorry, my question was do I have to extract the block validation from
BeaconStateMachine.import_block
andBeaconStateMachine.process_block
, and makeBeaconChain
trigger the block validation. Your second response answered my question. 👍@hwwhww 1) I’m not sure I understand your question and 2)
BeaconChain
should not try to be shaped likeChain
in any case where it doesn’t fit well. It’s better forBeaconChain
to be properly architected than for it to have API parity withChain
.