Skip to content

db/state, snapcfg: download erigondb.toml via torrent; move settings resolution out of Open()#19587

Merged
AskAlexSharov merged 6 commits intomainfrom
wmitsuda/download-erigon-torrent
Mar 4, 2026
Merged

db/state, snapcfg: download erigondb.toml via torrent; move settings resolution out of Open()#19587
AskAlexSharov merged 6 commits intomainfrom
wmitsuda/download-erigon-torrent

Conversation

@wmitsuda
Copy link
Member

@wmitsuda wmitsuda commented Mar 3, 2026

Summary

  • Move ResolveErigonDBSettings out of Aggregator.Open() so callers resolve settings explicitly before constructing the aggregator, enabling the downloader to provide the real erigondb.toml before domains are configured.
  • Whitelist erigondb.toml in the header-chain download phase so the torrent downloader delivers it alongside headers/bodies.
  • After the header-chain download completes, ReloadErigonDBSettings() re-reads the file and propagates any stepSize changes to all Domain/InvertedIndex instances.
  • Add WithErigonDBSettings() builder on AggOpts so all call sites pass pre-resolved settings.

Three runtime scenarios handled:

  1. Legacy datadir (has preverified.toml, no erigondb.toml): writes erigondb.toml with legacy settings (step_size=1,562,500) on startup.
  2. Fresh sync with downloader: starts with defaults, downloader delivers real erigondb.toml during header-chain phase, settings are reloaded and propagated.
  3. Fresh sync with --no-downloader: writes defaults to disk immediately since no downloader will provide the file.

Test plan

  • Scenario 1 (legacy datadir): confirmed log Creating erigondb.toml with LEGACY settings step_size=1562500 and file written on startup
  • Scenario 2 (fresh + downloader): confirmed log erigondb stepSize changed, propagating after header-chain download delivers erigondb.toml with step_size=390625
  • Scenario 3 (fresh + --no-downloader): confirmed log Initializing erigondb.toml with DEFAULT settings (nodownloader) and file written immediately

wmitsuda and others added 2 commits March 2, 2026 20:35
…ut of Open()

Move the ResolveErigonDBSettings call from inside Open() to each caller,
making settings resolution explicit at each call site. This lets the
node/eth/backend.go caller pass the real noDownloader flag, while all
other callers pass false.

Add a pure setter builder WithErigonDBSettings(*ErigonDBSettings) on
AggOpts that assigns the resolved settings to opts.stepSize and
opts.stepsInFrozenFile.

Open() no longer does settings I/O — it just uses whatever is on opts.
If a caller forgets the builder, stepSize=0 causes ConfigureDomains to
fail fast.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
wmitsuda added 3 commits March 3, 2026 12:17
- Remove ReloadErigonDBSettings/ConfigureDomains from OpenFolder() since
  they overwrote test-specified stepSize with disk defaults; initial setup
  is done in Open(), live reload is explicit in stage_snapshots.go
- Add StepSize default to NewTest() so callers without explicit .StepSize()
  get a valid value
- Move AdjustReceiptCurrentVersionIfNeeded to Open() before capturing schema,
  so savedSchema reflects the adjusted receipt versions
- Delegate execctx NewTest() to state.NewTest() to avoid divergence
All consumers of statecfg.Schema read the global directly.
The savedSchema copy on Aggregator created an illusion of isolation
that didn't exist. Move AdjustReceiptCurrentVersionIfNeeded into
ConfigureDomains() right before Configure() where the schema is consumed.
Reusable test plan for verifying erigondb.toml settings resolution
across 3 scenarios: legacy datadir, fresh sync with downloader, and
fresh sync with --no-downloader.
… use fsync

Remove dead CreateOrReadErigonDBSettings (replaced by ResolveErigonDBSettings
in step_cmd.go with noDownloader=true). Extract readErigonDBSettings and
writeErigonDBSettings helpers to consolidate the TOML marshal/unmarshal
patterns. Use dir.WriteFileWithFsync for durable writes, consistent with
salt and registry files. Reorder ResolveErigonDBSettings to return early
when erigondb.toml exists, skipping the unnecessary preverified.toml stat.
@wmitsuda wmitsuda requested a review from anacrolix March 3, 2026 23:01
@wmitsuda
Copy link
Member Author

wmitsuda commented Mar 3, 2026

@anacrolix I'd appreciate your review on this one as well, since it touches some codepaths involving the sync process

@AskAlexSharov AskAlexSharov merged commit 2fad07d into main Mar 4, 2026
40 of 54 checks passed
@AskAlexSharov AskAlexSharov deleted the wmitsuda/download-erigon-torrent branch March 4, 2026 02:45
return nil, err
return err
}
return dir.WriteFileWithFsync(path, data, 0644)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there's a const for this somewhere to avoid inconsistencies

Copy link
Member Author

Choose a reason for hiding this comment

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

can't find it, actually I see plenty of 0644 hardcoded in the code

@anacrolix
Copy link
Contributor

I put some questions in Discord

sudeepdino008 pushed a commit that referenced this pull request Mar 4, 2026
…resolution out of Open() (#19587)

## Summary

- Move `ResolveErigonDBSettings` out of `Aggregator.Open()` so callers
resolve settings explicitly before constructing the aggregator, enabling
the downloader to provide the real `erigondb.toml` before domains are
configured.
- Whitelist `erigondb.toml` in the header-chain download phase so the
torrent downloader delivers it alongside headers/bodies.
- After the header-chain download completes, `ReloadErigonDBSettings()`
re-reads the file and propagates any stepSize changes to all
Domain/InvertedIndex instances.
- Add `WithErigonDBSettings()` builder on `AggOpts` so all call sites
pass pre-resolved settings.

Three runtime scenarios handled:
1. **Legacy datadir** (has `preverified.toml`, no `erigondb.toml`):
writes `erigondb.toml` with legacy settings (step_size=1,562,500) on
startup.
2. **Fresh sync with downloader**: starts with defaults, downloader
delivers real `erigondb.toml` during header-chain phase, settings are
reloaded and propagated.
3. **Fresh sync with `--no-downloader`**: writes defaults to disk
immediately since no downloader will provide the file.

## Test plan

- [x] Scenario 1 (legacy datadir): confirmed log `Creating erigondb.toml
with LEGACY settings step_size=1562500` and file written on startup
- [x] Scenario 2 (fresh + downloader): confirmed log `erigondb stepSize
changed, propagating` after header-chain download delivers
`erigondb.toml` with step_size=390625
- [x] Scenario 3 (fresh + `--no-downloader`): confirmed log
`Initializing erigondb.toml with DEFAULT settings (nodownloader)` and
file written immediately

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
sudeepdino008 pushed a commit that referenced this pull request Mar 4, 2026
…resolution out of Open() (#19587)

## Summary

- Move `ResolveErigonDBSettings` out of `Aggregator.Open()` so callers
resolve settings explicitly before constructing the aggregator, enabling
the downloader to provide the real `erigondb.toml` before domains are
configured.
- Whitelist `erigondb.toml` in the header-chain download phase so the
torrent downloader delivers it alongside headers/bodies.
- After the header-chain download completes, `ReloadErigonDBSettings()`
re-reads the file and propagates any stepSize changes to all
Domain/InvertedIndex instances.
- Add `WithErigonDBSettings()` builder on `AggOpts` so all call sites
pass pre-resolved settings.

Three runtime scenarios handled:
1. **Legacy datadir** (has `preverified.toml`, no `erigondb.toml`):
writes `erigondb.toml` with legacy settings (step_size=1,562,500) on
startup.
2. **Fresh sync with downloader**: starts with defaults, downloader
delivers real `erigondb.toml` during header-chain phase, settings are
reloaded and propagated.
3. **Fresh sync with `--no-downloader`**: writes defaults to disk
immediately since no downloader will provide the file.

## Test plan

- [x] Scenario 1 (legacy datadir): confirmed log `Creating erigondb.toml
with LEGACY settings step_size=1562500` and file written on startup
- [x] Scenario 2 (fresh + downloader): confirmed log `erigondb stepSize
changed, propagating` after header-chain download delivers
`erigondb.toml` with step_size=390625
- [x] Scenario 3 (fresh + `--no-downloader`): confirmed log
`Initializing erigondb.toml with DEFAULT settings (nodownloader)` and
file written immediately

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
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