Skip to content

feat!(store): "ideal" key layout#1814

Closed
melekes wants to merge 24 commits intomainfrom
anton/1041-ideal-key-layout
Closed

feat!(store): "ideal" key layout#1814
melekes wants to merge 24 commits intomainfrom
anton/1041-ideal-key-layout

Conversation

@melekes
Copy link
Collaborator

@melekes melekes commented Dec 13, 2023

#1041 (comment)

Most keys are now grouped by height except for block hash's key (-1)
and pending evidence (-2):

header: 11/0
block part: 11/1/0
block part 2: 11/1/1
...
commit: 11/2
seen commit: 11/3
ext commit: 11/4

validator set: 11/5
consensus params: 11/6
abci responses: 11/7

committed evidence: 11/8
block hash: -1/{hash}
pending evidence: -2/11/{ev.Hash}
light block: {chainID}/9/11
size: {chainID}/10

Refs #1041
Fixes #1857


PR checklist

  • Tests written/updated
  • Changelog entry added in .changelog (we use unclog to manage our changelog)
  • Updated relevant documentation (docs/ or spec/) and code comments

melekes and others added 6 commits December 7, 2023 13:51
Co-authored-by: Callum Waters <cmwaters19@gmail.com>
#1041 (comment)

Most keys are now grouped by height with the exception of block hash's key (-1)
and pending evidence (-2):

```
header: 11/0
block part: 11/1/0
block part 2: 11/1/1
...
commit: 11/2
seen commit: 11/3
ext commit: 11/4

validator set: 11/5
consensus params: 11/6
abci responses: 11/7

committed evidence: 11/8
```

```
block hash: -1/{hash}
pending evidence: -2/11/{ev.Hash}
```

```
light block: {chainID}/9/11
size: {chainID}/10
```

Refs #1041
@melekes
Copy link
Collaborator Author

melekes commented Dec 13, 2023

TODO:

  • write a migration script
  • write a guide for migration (if needed)

@melekes melekes self-assigned this Dec 19, 2023
}

func validatorsKey(height int64) []byte {
// Since CometBFT requests block H and validators H+1 on every height, we
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the most controversial change. But this is undoubtedly an improvement because the access pattern is clear (block H, parts H, validators H+1). Any thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it should be fine although there are places where we fetch the validators info explicitly (like RPC status and pruning). But those are less frequent than block validation. Another frequent access pattern is loading the lastCommit (validators from height -1 ) which is called on every ApplyBlock

@melekes melekes marked this pull request as ready for review December 19, 2023 04:58
@melekes melekes requested a review from a team as a code owner December 19, 2023 04:58
@melekes melekes requested a review from a team December 19, 2023 04:58
}

func validatorsKey(height int64) []byte {
// Since CometBFT requests block H and validators H+1 on every height, we
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it should be fine although there are places where we fetch the validators info explicitly (like RPC status and pruning). But those are less frequent than block validation. Another frequent access pattern is loading the lastCommit (validators from height -1 ) which is called on every ApplyBlock

@melekes melekes added the wip Work in progress label Dec 25, 2023
@melekes melekes mentioned this pull request Jan 4, 2024
keys are now grouped by height and lexicographically sorted using the
[orderedcode](https://github.com/google/orderedcode) library.

To upgrade, run `cometbft migrate-db`. **Before doing so, it's highly
Copy link
Contributor

Choose a reason for hiding this comment

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

saw this pr on my feed, the title intrigued me. This step would prevent the sdk from adopting this change. This will cause downtime when users upgrade, there should be a way to make it lazy so users dont experience this downtime

Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be fine to live migrate the latest {N} blocks which hopefully happened quickly, and then migrate the rest in the background?

Copy link
Contributor

Choose a reason for hiding this comment

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

im not sure there needs to be a migration at the point of upgrade, the node could be able to tell what is the old format vs new, then migrate in the background. Potentially causing 0 donwtime

Copy link
Contributor

Choose a reason for hiding this comment

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

Hey Marko, Dave! Just dropping a note here that migration is on our mind and we're considering different approaches (making it optional / online migration / offline / partial migration). Getting input from operators also to weigh the pros and cons. Will follow-up here w/ progress -- #2057

@melekes
Copy link
Collaborator Author

melekes commented Jan 31, 2024

Closing in favor of #1764

@jmalicevic: "Based on the experiments, this change performs worse than #1764. The only improvement compared to #1764 is in the IO stats, but for compaction and general impact on the blockchain performance when it is on, it underperforms."

@melekes melekes closed this Jan 31, 2024
@adizere adizere added this to the 2024-Q1 milestone Feb 1, 2024
@zrbecker zrbecker deleted the anton/1041-ideal-key-layout branch February 7, 2025 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wip Work in progress

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

light: a single db key size is used for all light clients

5 participants