Repository navigation
feat(config): a replay: section, and state: decides the state manager (#880, #881) - #907
Merged
Merged
Conversation
`substrate replay` built a zero-value ReplayConfig, so speed_multiplier, stop_on_error, validate_state, use_snapshots and random_seed were unreachable from configuration (#880). Config.State was validated and read by nowhere: both the server and the replay wiring constructed a MemoryStateManager unconditionally, so `state.backend: sqlite` was accepted at load and silently answered with memory (#881). Adds ReplayCfg with a struct conversion to ReplayConfig, NewStateManager as the one constructor both call sites use, refusal (not fallback) for an unimplemented or unknown backend, refusal of a state.path no backend reads, and refusal of a negative replay.speed_multiplier. Also populates ReplayResults.StateErrors, which was documented and never appended to, and distinguishes "state not checked" from "state valid" in the replay summary. Closes #880. Closes #881.
scttfrdmn
force-pushed
the
feat/replay-and-state-config
branch
from
September 15, 2026 23:06
db07703 to
f659a9d
Compare
# Conflicts: # CHANGELOG.md
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
# Conflicts: # CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two configuration sections that turned nothing, fixed together because they share
emulator/config.goandcmd/substrate/main.go.What was broken
#880 —
substrate replaybuilt a zero-valueReplayConfig.Confighad noReplayfield and there was noReplayCfgtype, sospeed_multiplier,stop_on_error,validate_state,use_snapshotsandrandom_seedwere unreachable fromsubstrate.yaml. The consequence that matters: state-hash validation — the thing that turns "re-executed 100 events" into "re-executed 100 events and reached the same state" — was off with no way to switch it on.#881 —
Config.Statewas validated and read by nothing. Both non-test construction sites (cmd/substrate/main.go:234in the server,:320in the replay wiring #855 extracted) calledsubstrate.NewMemoryStateManager()unconditionally, whileValidateacceptedstate.backend: sqlite. A config asking for persistence loaded clean and got a manager that forgets everything at exit.state.pathwas read by nothing at all.Found while implementing (#880).
ReplayResults.StateErrorsis documented to carry "descriptions of any state hash mismatches" and was never appended to: a mismatch flippedStateValidto false and left the slice empty, so the CLI could report a state failure it could not describe. Fixed here because #880's acceptance criterion — that a configuredvalidate_state: true"reportsStateValid/StateErrorsmeaningfully" — is not satisfiable without it.Design decisions
Refuse, don't fall back (#881).
emulator.NewStateManager(StateCfg) (StateManager, error)is the single constructor both call sites use, and an unhandled backend is an error. A caller who asked for persistence and was handed memory has been given a wrong answer, and it surfaces much later as absent state rather than here as a refused config.Validaterefuses the same set at load time, distinguishingsqliteas not implemented (naming #2) from an unknown value as not valid — asking for the backend this project has an open issue for deserves "unbuilt", not "misspelled". An emptyBackendselects memory, matchingDefaultConfig: it means the section was not written, not that something else was requested.This makes
state.backend: sqlite— previously accepted — a load-time error. Nothing shipped in the repo sets it (substrate.yaml.example,configs/substrate-local.yaml,deploy/k8s/configmap.yamlall leavestateunset or atmemory), and anyone who did set it was silently getting memory, so the change is from a wrong answer to an error, never from working persistence to an error.state.pathis kept and refused — a third answer to #881's AC 3. Neither listed option is right yet. No implemented backend keeps files, soPathcannot be honoured until #2. But deleting the field does not makestate: {path: …}an error — viper ignores an unknown key — so removal converts today's silent ignore into a permanent one, which is the very defect being fixed.Validatetherefore refuses a non-emptystate.path, and the field stays for #2 to give meaning to.ReplayCfgconverts by struct conversion, not field-by-field.ToReplayConfigisreturn ReplayConfig(c), following theTracingCfg→TracingConfigprecedent: the two types are identical but for tags, so a field added toReplayConfigand forgotten here fails to compile instead of silently defaulting to zero — exactly the failure mode #880 is about.Only fields the engine reads are exposed. All five
ReplayConfigfields are genuinely consumed byReplayEngine; no knob was invented.RandomSeedreaches the engine'sRandFloat64/RandInt64, which have no non-test callers today, and the doc comment says so rather than implying plugin-level determinism it does not yet deliver.Defaults are the previous zero values. This section makes existing behaviour configurable rather than changing it;
cfg.Replay.ToReplayConfig()on a default config is asserted equal tosubstrate.ReplayConfig{}so that stays true.validate_statestays off with the reason written inDefaultConfig: it only means something for a stream recorded withevent_store.include_state_hashes: true, so defaulting it on would make the common case fail on absent data. Onlyspeed_multiplieris bounded — refused below zero — since the four booleans and the seed have no invalid values, and validating them would be theatre.The replay summary now distinguishes three verdicts, not two. It reported
validfor a stream carrying no recorded hashes at all, which is the same class of wrong answer as the two issues: with nothing to compare, "not checked (no event in the stream carries a recorded state hash; record withevent_store.include_state_hashes: true)" is the honest verdict.streamHasStateHashesdecides it.Wiring stays extracted, per the
newFaultController/newCredentialWiringprecedent.newReplayEngineWiring,replayStateSummaryandstreamHasStateHashesare functions a test can call; nothing new went inline into aRunEclosure.Premise corrections
Recorded on the issues (#880, #881) rather than implemented silently:
StateCfgisconfig.go:204;Validate's check was:773-775;main.go:164is:234, and a second call site exists at:320).Pathas "validated and ignored". It was never validated — onlySetDefault-ed inLoadConfig— so the field was purely ignored, which is marginally worse than described.ReplayCfghas no enumerated field, so onlyspeed_multiplieris checked.Files
emulator/config.go—ReplayCfg+ToReplayConfig,Config.Replay,DefaultConfigandLoadConfigdefaults for all five keys,Validaterefusing an unimplemented/unknownstate.backend, a non-emptystate.path, and a negativereplay.speed_multiplier; rewrittenStateCfgdoc comments.emulator/state.go—NewStateManager.emulator/replay.go—StateErrorspopulated at both comparison sites via a newstateHashErrorhelper.cmd/substrate/main.go— both state-manager sites go throughNewStateManager;newReplayEngineWiringusescfg.Replay.ToReplayConfig();streamHasStateHashes;replayStateSummarygains the "not comparable" verdict.substrate.yaml.example— newstate:andreplay:sections.docs/testing-guide.md— "Replaying from the command line", with the yaml and the four possible state verdicts.CHANGELOG.md, plus tests inemulator/config_test.go,emulator/state_test.go,emulator/replay_reporting_test.go,cmd/substrate/replay_wiring_test.go.Tests
Added, all table-driven where there is more than one case, none touching the network or the wall clock:
TestNewStateManager— memory, an unwritten section,sqliterefused andpostgresrefused with exact messages; the success cases Put/Get through the returned manager.TestValidate— five new cases:postgresmessage,sqliterefused rather than falling back,state.pathrefused, negativereplay.speed_multiplierrefused, zero multiplier valid.TestReplayCfg_Defaults,TestReplayCfg_ToReplayConfig,TestLoadConfig_ReplaySection(all five keys from yaml, and a bare file keeping defaults),TestLoadConfig_UnsupportedStateBackend.TestReplayReporting_StateErrorsDescribeEveryMismatch— one description per mismatch, each naming the field, the recorded hash and the replayed one.TestNewReplayEngineWiring_UsesTheConfiguredReplaySection,TestStreamHasStateHashes,TestReplayStateSummary(4 verdicts),TestReplayCmd_StateVerdictFollowsTheConfiguredSection(3 subtests throughrun([]string{"replay", …})),TestNewReplayEngineWiring_RefusesAnUnsupportedStateBackend,TestReplayCmd_RefusesAnUnsupportedStateBackend,TestServerCmd_RefusesAnUnsupportedStateBackend.Mutation test
Each production change was reverted in place (files copied aside and restored — no
git stash) to prove the tests catch the original defect.A — the #881 silent fallback (
NewStateManagerreturns memory for every backend;Validateback to the oldmemory/sqlitemap;state.pathignored):B — the #880 zero value (
replayCfg := substrate.ReplayConfig{}):C —
StateErrorsnever appended (both appends removed):All files restored afterwards;
go test ./emulator/ ./cmd/substrate/ -count=1green.Verification
Run from the worktree root, in this order, all after the final restore:
gofmt -l . && go build ./... && go vet ./...— rc=0, no output.golangci-lint run ./...—0 issues.make test— rc=0 (checked separately from the redirected log, not through a pipe).GOTOOLCHAIN=go1.26.6 make test— rc=0.GOTOOLCHAIN=go1.26.6 make coverage— rc=0;emulator 83.9%,total 83.4%(baseline held),cmd/substrate 47.3%.make docs-reference docs-reference-check docs-versions authz-reference-check— rc=0,docs/services.md already up to date (67 plugins).go vet -C test/e2e ./... && go test -C test/e2e ./...— rc=0,ok … 0.728s.npm --prefix docs run build— rc=0,build complete in 1.90s(node_modules symlinked in for the build, removed before committing).Compatibility
state.backend: sqlitenow fails at load withstate.backend "sqlite" is not implemented; choose memory. It previously loaded and silently used memory; feat: SQLite StateManager #2 will make it real.state.path, and a negativereplay.speed_multiplier.replay:default is the zero value the CLI used before, asserted by test, so an existing config without the section replays identically. A config without astate:section gets memory as before.substrate replay'sState:line has two new readings.not checked (state validation is off)is nownot checked (replay.validate_state is off), naming the key a user can set, and a stream withvalidate_state: truebut no recorded hashes now readsnot checked (no event in the stream carries a recorded state hash; …)where it previously reportedvalid.validandMISMATCH (n error(s))are unchanged — but aMISMATCHis now accompanied bynprinted descriptions, where before it printed a count with nothing behind it.Closes #880.
Closes #881.