chore(RPC): Environment stores only one in-memory copy of the Genesis#4235
Conversation
- return an error if ptr to GenesisDoc is nil - return early without chunking if GenesisDoc is <= 16MB - initialize the chunks slice with a size hint for better performance - set the ptr to GenesisDoc to nil if GenesisDoc > 16MB, that is, we compute and cache the genesis's chunks.
…nesisChunks() fails.
…e chunks slice rather than checking if it's nil.
… 0, rather than bigger than 1
Additional ContextThe changes we want to introduce in this PR would break the behavior of the First a reminder of how our RPC APIs that return the genesis work:
In the current implementation, the Theoretically, when the genesis file is smaller than the threshold, it should be retrieved using the In contrast, our PR's changes prevent the creation of a slice of chunks if the genesis file is smaller than the threshold (see #4234 for reasons why). This would break the The changes are here. To maintain compatibility, if the chunks are absent but the given chunk ID is 0, we encode the genesis file to base64 and send it to the user. However, if the chunks are absent and the given chunk ID is greater than 0, we return the standard error as usual. |
…RPC API after the changes to the Environment struct
The linter was autocorrecting it for some reasons.
…is (#4235) Closes #4234. ### Changes The [`Environment`](https://github.com/cometbft/cometbft/blob/8273634cdefb2fb22765a14f9acb9fca608e9982/rpc/core/env.go#L72) type will: - Store a pointer to a `GenesisDoc` if the genesis file size is below a threshold currently set to 16 MB. - If the genesis file exceeds this threshold, it will split it into 16 MB chunks and store the hashes of each chunk in memory in a slice. In this case, the pointer to the `GenesisDoc` will be `nil`. Because the `InitGenesisChunks` method of `Environment` is responsible for creating the chunks, most of the changes of this PR focus on refactoring this method and adding unit tests for it. --- #### PR checklist - [x] Tests written/updated - [x] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog) - [x] Updated relevant documentation (`docs/` or `spec/`) and code comments
…e operation (#4247) Closes #1290. This PR tracks the work we are doing for #1290. For details, please refer to #1290 discussion. ### ToDo - [x] Environment stores either a pointer to a GenesisDoc or the genesis' chunks, but not both. Merged to this branch with #4235. - [x] [Node](https://github.com/cometbft/cometbft/blob/87a8c8948bf9926aff37f344b4120163f12cb4ad/node/node.go#L50) does not keep a pointer to a GenesisDoc after initialization. Merged to this branch with #4250. --- #### PR checklist - [x] Tests written/updated - [x] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog) - [x] Updated relevant documentation (`docs/` or `spec/`) and code comments --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
…e operation (cometbft#4247) Closes cometbft#1290. This PR tracks the work we are doing for cometbft#1290. For details, please refer to cometbft#1290 discussion. ### ToDo - [x] Environment stores either a pointer to a GenesisDoc or the genesis' chunks, but not both. Merged to this branch with cometbft#4235. - [x] [Node](https://github.com/cometbft/cometbft/blob/87a8c8948bf9926aff37f344b4120163f12cb4ad/node/node.go#L50) does not keep a pointer to a GenesisDoc after initialization. Merged to this branch with cometbft#4250. --- #### PR checklist - [x] Tests written/updated - [x] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog) - [x] Updated relevant documentation (`docs/` or `spec/`) and code comments --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
Closes #4234.
Changes
The
Environmenttype will:GenesisDocif the genesis file size is below a threshold currently set to 16 MB.GenesisDocwill benil.Because the
InitGenesisChunksmethod ofEnvironmentis responsible for creating the chunks, most of the changes of this PR focus on refactoring this method and adding unit tests for it.PR checklist
.changelog(we use unclog to manage our changelog)docs/orspec/) and code comments