Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure new blocks are marked complete only when strict finality is reached #3549

Merged
merged 5 commits into from
Jan 11, 2023

Conversation

Fraser999
Copy link
Contributor

This PR introduces a small collection of state flags which are carried around with blocks being executed and accumulated.

The state is held in a type named HotBlock - i.e. a new block which is currently being worked upon. The state is primarily used in the reactor's dispatch_event via the HotBlockAnnouncement. This announcement is made by the ContractRuntime after executing a FinalizedBlock and by the BlockAccumulator after storing a block which has just reached sufficient finality.

The introduction of this state has allowed for the removal of some state from the BlockAccumulator and also should ensure that actions such as executing a block, storing a block or marking it complete are all done only once per block.

It also has allowed the node to avoid needlessly gossiping new immediate switch blocks (all nodes going through an upgrade create the immediate switch block, not just the validators).

Closes #3520.

Copy link
Contributor

@georgepisaltu georgepisaltu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lookgs good overall

node/src/types/block/hot_block/state.rs Outdated Show resolved Hide resolved
Comment on lines 95 to 98
// We don't gossip immediate switch blocks
if self.is_immediate_switch_block_for_current_protocol_version {
return StateChange::AlreadySet;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be handled outside the State logic? To keep it simple and compact, I think we should only do basic stuff here like offering getters and setters, let other parts of the code deal with specific logic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather keep it here. The logic isn't complicated and to move it outside would require a getter for is_immediate_switch_block_for_current_protocol_version. If other reviewers agree with you though, I can do the change.

node/src/types/validator_matrix.rs Outdated Show resolved Hide resolved
node/src/components/block_accumulator.rs Outdated Show resolved Hide resolved
node/src/components/block_synchronizer.rs Outdated Show resolved Hide resolved
node/src/components/contract_runtime.rs Show resolved Hide resolved
node/src/reactor/main_reactor.rs Outdated Show resolved Hide resolved
node/src/components/block_accumulator/block_acceptor.rs Outdated Show resolved Hide resolved
node/src/components/block_accumulator/block_acceptor.rs Outdated Show resolved Hide resolved
node/src/components/shutdown_trigger.rs Outdated Show resolved Hide resolved
node/src/reactor/main_reactor.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@rafal-ch rafal-ch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 with just a few nits.
Nice job!

node/src/types/block/hot_block/state.rs Outdated Show resolved Hide resolved
node/src/types/block/hot_block/state.rs Outdated Show resolved Hide resolved
node/src/types/block/hot_block.rs Outdated Show resolved Hide resolved
node/src/components/block_accumulator/block_acceptor.rs Outdated Show resolved Hide resolved
@Fraser999
Copy link
Contributor Author

bors merge

@casperlabs-bors-ng
Copy link
Contributor

Build succeeded:

@casperlabs-bors-ng casperlabs-bors-ng bot merged commit b45ff43 into casper-network:dev Jan 11, 2023
@Fraser999 Fraser999 deleted the 3520-hot-block branch January 11, 2023 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Avoid marking blocks complete prematurely while validating
4 participants