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

[Consensus] verify block timestamp invariant and genesis ancestors #16439

Merged
merged 2 commits into from
Mar 1, 2024

Conversation

mwtian
Copy link
Contributor

@mwtian mwtian commented Feb 28, 2024

Description

Verify that max ancestors timestamp <= block timestamp.

Since this check requires all ancestors block to be available, it needs to be done after a block has complete causal history but before the block is accepted.

Also,

  • Verify genesis ancestors are valid.
  • Refactor genesis block creation.

Test Plan

Unit test.


If your changes are not user-facing and do not break anything, you can skip the following section. Otherwise, please briefly describe what has changed under the Release Notes section.

Type of Change (Check all that apply)

  • protocol change
  • user-visible impact
  • breaking change for a client SDKs
  • breaking change for FNs (FN binary must upgrade)
  • breaking change for validators or node operators (must upgrade binaries)
  • breaking change for on-chain data layout
  • necessitate either a data wipe or data migration

Release notes

Copy link

vercel bot commented Feb 28, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
mysten-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 29, 2024 5:01am
sui-core ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 29, 2024 5:01am
sui-typescript-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 29, 2024 5:01am
3 Ignored Deployments
Name Status Preview Comments Updated (UTC)
explorer ⬜️ Ignored (Inspect) Visit Preview Feb 29, 2024 5:01am
multisig-toolkit ⬜️ Ignored (Inspect) Visit Preview Feb 29, 2024 5:01am
sui-kiosk ⬜️ Ignored (Inspect) Visit Preview Feb 29, 2024 5:01am

@mwtian mwtian changed the base branch from main to consensus-write February 28, 2024 05:45
@mwtian mwtian changed the title [Consensus] verify timestamp invariant [Consensus] verify block timestamp invariant Feb 28, 2024
@vercel vercel bot temporarily deployed to Preview – mysten-ui February 28, 2024 05:48 Inactive
@vercel vercel bot temporarily deployed to Preview – mysten-ui February 28, 2024 05:51 Inactive
Base automatically changed from consensus-write to main February 28, 2024 17:28
@vercel vercel bot temporarily deployed to Preview – mysten-ui February 28, 2024 18:55 Inactive
@mwtian mwtian changed the title [Consensus] verify block timestamp invariant [Consensus] verify block timestamp invariant and genesis ancestors Feb 28, 2024
@@ -98,7 +152,7 @@ impl BlockManager {
/// Tries to accept the provided block. To accept a block its ancestors must have been already successfully accepted. If
/// block is accepted then Some result is returned. None is returned when either the block is suspended or the block
/// has been already accepted before.
fn try_accept_block(&mut self, block: VerifiedBlock) -> Option<VerifiedBlock> {
fn try_accept_one_block(&mut self, block: VerifiedBlock) -> Option<VerifiedBlock> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the name change? try_accept_block already reads as it will accept one block.

Copy link
Contributor Author

@mwtian mwtian Feb 29, 2024

Choose a reason for hiding this comment

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

I want to make it clearer that children blocks will not be unsuspended in try_accept_block(), unlike try_accept_blocks(). I can definitely revert if this is not helping.


// Accept the state in DAG here so the next block to be processed can find in DAG/store any accepted blocks.
// TODO: report blocks_to_reject to peers.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the purpose of reporting these blocks to peers as a method for reporting suspected byzantine behavior. The peers would have to revalidate these blocks anyways right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, and these are not just suspected but verifiable byzantine behaviors, because of block signature. Only the block without a rejected ancestor can be reported though.

if !committee.is_valid_index(ancestor.author) {
return Err(ConsensusError::InvalidAuthorityIndex {
index: ancestor.author,
max: committee.size() - 1,
});
}
if ancestor.author == block.author() {
own_ancestor = true;
if (i == 0 && ancestor.author != block.author())
Copy link
Contributor

Choose a reason for hiding this comment

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

ooc why is it important that the block.author has its ancestor as the first ancestor in the list?

Copy link
Contributor Author

@mwtian mwtian Feb 29, 2024

Choose a reason for hiding this comment

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

Each block is required to include the latest own ancestor. It seems good to have a convention on where it is placed. In future we may run more validations on the consistency between a block and its own ancestor. Instead of a separate field, own ancestor is stored at the 1st element of the ancestors Vec.

@mwtian
Copy link
Contributor Author

mwtian commented Mar 1, 2024

Merging. Will address any comment via followup PRs.

@mwtian mwtian merged commit e0aa6df into main Mar 1, 2024
41 checks passed
@mwtian mwtian deleted the consensus-verify branch March 1, 2024 21:54
@akichidis
Copy link
Contributor

Merging. Will address any comment via followup PRs.

@mwtian apologies for not having a look on this yet, I'll leave any comments in the weekend so you can address in follow up PRs as you said

tx-tomcat pushed a commit to tx-tomcat/sui-network that referenced this pull request May 30, 2024
…ystenLabs#16439)

## Description 

Verify that max ancestors timestamp <= block timestamp.

Since this check requires all ancestors block to be available, it needs
to be done after a block has complete causal history but before the
block is accepted.

Also,
- Verify genesis ancestors are valid.
- Refactor genesis block creation.

## Test Plan 

Unit test.

---
If your changes are not user-facing and do not break anything, you can
skip the following section. Otherwise, please briefly describe what has
changed under the Release Notes section.

### Type of Change (Check all that apply)

- [ ] protocol change
- [ ] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [ ] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [ ] necessitate either a data wipe or data migration

### Release notes
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.

3 participants