Skip to content

core/rawdb: integrate eradb backend for RPC #31604

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

Merged
merged 47 commits into from
Jun 3, 2025
Merged

core/rawdb: integrate eradb backend for RPC #31604

merged 47 commits into from
Jun 3, 2025

Conversation

s1na
Copy link
Contributor

@s1na s1na commented Apr 10, 2025

Implements #31279

@fjl fjl added this to the 1.15.9 milestone Apr 15, 2025
@rjl493456442 rjl493456442 self-assigned this Apr 15, 2025
@s1na s1na marked this pull request as ready for review April 17, 2025 08:28
@s1na s1na changed the title WIP: integrate eradb backend for RPC core/rawdb: integrate eradb backend for RPC Apr 17, 2025
@@ -237,7 +237,7 @@ func initGenesis(ctx *cli.Context) error {
overrides.OverrideVerkle = &v
}

chaindb, err := stack.OpenDatabaseWithFreezer("chaindata", 0, 0, ctx.String(utils.AncientFlag.Name), "", false)
chaindb, err := stack.OpenDatabaseWithFreezer("chaindata", 0, 0, ctx.String(utils.AncientFlag.Name), "", false, "")
Copy link
Member

Choose a reason for hiding this comment

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

We should probably make this a config struct

@rjl493456442
Copy link
Member

Twist the era path resolution a bit:

  • use ancient/chain/era if era is not explicitly specified;
  • use ancient/chain/relative-path if era is specified;
  • use itself if the specified path is an absolute path

return f.eradb.GetRawReceipts(number)
}
return nil, errUnknownTable
}
Copy link
Member

Choose a reason for hiding this comment

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

TODO (sina and gary)

We should support AncientRange as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created a ticket for it for a future PR

rjl493456442
rjl493456442 previously approved these changes Apr 18, 2025
@MariusVanDerWijden MariusVanDerWijden modified the milestones: 1.15.9, 1.15.10 Apr 23, 2025
@fjl fjl modified the milestones: 1.15.10, 1.15.11 Apr 25, 2025
@fjl fjl modified the milestones: 1.15.11, 1.15.12 May 5, 2025
}

// Add3 adds a value to the cache. If an item was evicted to store the new one, it returns the evicted item.
func (c *BasicLRU[K, V]) Add3(key K, value V) (ek K, ev V, evicted bool) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can we at least use Add2 for name? :))

Name: "datadir.era",
Usage: "Root directory for era1 history (default = inside ancient/chain)",
Category: flags.EthCategory,
}
Copy link
Member

Choose a reason for hiding this comment

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

Should we also check Era flag isn't used with --datadir="" since it will silently disregard the era directory?

Copy link
Member

@lightclient lightclient left a comment

Choose a reason for hiding this comment

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

Overall this looks really great. I was able to prune my mainnet node, download the era files with the downloader, then pass the workload tests.

--

One question is this PR is trying to load Era files from ancient/chain/era, but the downloaded stores them in ancient/era. Which is best?

I also pushed one small commit to remove some old uses of the non-pass through accessors on ancients.

@@ -111,6 +111,11 @@ var (
Usage: "Root directory for ancient data (default = inside chaindata)",
Category: flags.EthCategory,
}
EraFlag = &flags.DirectoryFlag{
Name: "datadir.era",
Copy link
Member

Choose a reason for hiding this comment

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

Also, do you think in the future this flag will also work for full era or e2hs files? If not, maybe we should be more specific with the name as "era1"? Otherwise Era is good.

@@ -111,6 +111,11 @@ var (
Usage: "Root directory for ancient data (default = inside chaindata)",
Category: flags.EthCategory,
}
EraFlag = &flags.DirectoryFlag{
Name: "datadir.era",
Usage: "Root directory for era1 history (default = inside ancient/chain)",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Usage: "Root directory for era1 history (default = inside ancient/chain)",
Usage: "Root directory for era1 history (default = inside ancient)",

It looks like the root directory actually ends up being ancient when you run geth download-era, is this okay or should we actually fix it put the era files in ancient/chain/era ?

entry.err = err
}

func (db *Store) openEraFile(epoch uint64) (*era.Era, error) {
Copy link
Member

Choose a reason for hiding this comment

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

docs

}
}

func (entry *fileCacheEntry) derefAndClose(epoch uint64) (closed bool) {
Copy link
Member

Choose a reason for hiding this comment

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

docs

s1na and others added 26 commits May 29, 2025 15:28
It's best to avoid callbacks, especially in the locked variant of the LRU, since it
can lead to weird bugs.
This changes the file cache to avoid some issues around file closing. With the new logic,
a file will never be closed while it is still in use on any goroutine accessing the era
store. To do this, we maintain a reference counter for each file.

The new cache also explicitly tracks files which are being opened. This ensures that
'replacing' a file in the cache cannot happen.
This removes the use of atomic reference counters in favor of using a scheme where all
changes to reference counters are done while holding the Store mutex. Store.Close now
synchronizes with all running accesses and waits until all files have been closed
before returning.
We don't use it anywhere.
This adds a new constructor for the database+freezer that takes named parameters
via a struct. Calls to NewDatabaseWithFreezer are replaced across the codebase.
@fjl fjl merged commit a7d9b52 into ethereum:master Jun 3, 2025
3 of 4 checks passed
jsvisa pushed a commit to jsvisa/go-ethereum that referenced this pull request Jun 5, 2025
This implements a backing store for chain history based on era1 files.
The new store is integrated with the freezer. Queries for blocks and receipts
below the current freezer tail are handled by the era store.

---------

Co-authored-by: Gary Rong <[email protected]>
Co-authored-by: Felix Lange <[email protected]>
Co-authored-by: lightclient <[email protected]>
Signed-off-by: jsvisa <[email protected]>
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.

5 participants