Skip to content

chore(Node): Node does not keep a pointer to a GenesisDoc after initialization#4250

Merged
alesforz merged 10 commits intoalesforz/genesis-in-memoryfrom
alesforz/node-no-genesis
Oct 14, 2024
Merged

chore(Node): Node does not keep a pointer to a GenesisDoc after initialization#4250
alesforz merged 10 commits intoalesforz/genesis-in-memoryfrom
alesforz/node-no-genesis

Conversation

@alesforz
Copy link
Collaborator

@alesforz alesforz commented Oct 4, 2024

Closes #4248.

Changes

The Node type will:

  • create a singleton instance of Environment when setting up the RPC APIs.
  • set the pointer to the GenesisDoc to nil once startup is complete so that the GC can collect the in-memory GenesisDoc object.
  • store a GenesisTime field.

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

@alesforz alesforz added backlog A prioritized task in the team's backlog P:tech-debt Priority: Technical debt that needs to be paid off to enable us to move faster, reliably P:storage-optimization Priority: Give operators greater control over storage and storage optimization labels Oct 4, 2024
@alesforz alesforz self-assigned this Oct 4, 2024
Alessandro added 5 commits October 4, 2024 17:22
…ct that it returns as a singleton.

The purpose of these changes is to set the `Node`'s pointer to the genesis
to `nil` after initialization, allowing the garbage collector to deallocate
the genesis struct from memory. In future work, we plan to remove this
pointer entirely.

Currently, different parts of the code call the `ConfigureRPC()` method to
create an `Environment` object for their own purposes. However, this is
wasteful because each `Environment` instance stores a copy of the genesis
file: either as a single pointer or as a collection of chunks.
Therefore, creating multiple, independent `Environment` objects results in
multiple copies of the genesis being loaded into memory. For large genesis
files, this can lead to large memory usage. By treating `Environment` as a
singleton within `ConfigureRPC()`, we prevent multiple copies of the
genesis from being loaded into memory simultaneously.
The `Node` does not need to access the genesis after starting up.
If the genesis is small (<=16MB) then the `Environment` object serving the RPC
APIs will retaing a pointer to the genesis at runtime.
If the genesis is big (>16MB) then the `Environment` object will split the
genesis into multiple chunks and keep them in memory.
@alesforz alesforz marked this pull request as ready for review October 10, 2024 13:59
@alesforz alesforz requested a review from a team as a code owner October 10, 2024 13:59
@alesforz alesforz requested review from a team, andynog and jmalicevic October 10, 2024 13:59
This reverts commit 7613068.

The method `GenesisDoc` is unexported, therefore some users might be using it. Deleting it might be a breaking change for them.
Copy link
Collaborator

@jmalicevic jmalicevic left a comment

Choose a reason for hiding this comment

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

Needs a changelog ,entry, great work otherwise !

…error)`.

Because `Node` does not store the genesis in memory anymore, this method now
must retrieve the genesis from disk and unmarshal it into a `*types.GenesisDoc`.

Note that this is a breaking, but necessary, change to ensure the correct
behavior of `GenesisDoc()`.
@alesforz alesforz merged commit ded7da6 into alesforz/genesis-in-memory Oct 14, 2024
@alesforz alesforz deleted the alesforz/node-no-genesis branch October 14, 2024 13:15
alesforz pushed a commit that referenced this pull request Oct 14, 2024
alesforz pushed a commit that referenced this pull request Oct 16, 2024
…alization (#4250)

Closes #4248.

### Changes
The `Node` type will:
- create a singleton instance of `Environment` when setting up the RPC
APIs.
- set the pointer to the `GenesisDoc` to `nil` once startup is complete
so that the GC can collect the in-memory `GenesisDoc` object.
 - store a `GenesisTime` field.

---

#### PR checklist

- [x] Tests written/updated
- [ ] 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
alesforz pushed a commit that referenced this pull request Oct 16, 2024
github-merge-queue bot pushed a commit that referenced this pull request Oct 25, 2024
…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>
Eric-Warehime pushed a commit to Eric-Warehime/cometbft that referenced this pull request Oct 28, 2024
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backlog A prioritized task in the team's backlog P:storage-optimization Priority: Give operators greater control over storage and storage optimization P:tech-debt Priority: Technical debt that needs to be paid off to enable us to move faster, reliably

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants