Loading
Test deterministic consensus replay and upgrade
Consensus changes need repeatable evidence across replay, export/restart, divergence detection, and the 18-to-19 upgrade path. This change adds a deterministic app test suite (app/consensus_determinism_test.go), a bounded runner script, a standalone CI job, and documentation.
- Simulation scope:
TestConsensusDeterminismSimulationScoperecords which modules the SDK simulation manager covers (auth,bank,denom,params,scheduler,wasm). It shows that THORChain'sAppModuleregisters no weighted operations, soTestAppStateDeterminismnever exercises THORChain state. - Replay:
TestConsensusDeterminismReplayimports a sanitized, fixed-time THORChain genesis fixture into independent app instances, eight times per seed. The fixture has four funded pools (BTC/ETH/DOGE/LTC), observed inbounds, a swap queue item, a scheduled outbound, network fees and a nonzero Reserve. Each run finalizes and commits a block and compares the app hash and the exported THORChain state. Every second run reverses pool order so that writes depending on map order show up as mismatches. - Divergence detection:
TestConsensusDeterminismDetectsDivergencechecks that changing a pool by one unit produces a different committed app hash. - Export/restart:
TestConsensusDeterminismRestartAndExportexports state, reopens the committed DB and imports the export into a fresh app. It checks the THORChain records, the Reserve balance and the BTC pool at import. It then commits another block on two independent imports and compares their hashes and exported state. - 18→19 migration:
TestConsensusDeterminismMigration18To19seeds two legacy owner-keyed affiliate collector records (one owner with a THORName, one without) and funds the collector module to match. It runs the 3.20.0 upgrade handler starting from module version 18 and checks that the version reaches the currentConsensusVersion(). After the commit it checks:- the active validator version is 3.20.0;
- Reserve and BTC pool balances are unchanged;
- the named collector holds the first balance and the second owner received its RUNE;
- the legacy keys are gone;
- two independent runs produce the same hash and state.
- Runner and CI:
scripts/test-consensus-determinism.shpins Go 1.26.9, uses the caller'sGOCACHE(falling back to a/tmpcache when unset), takes the shared build lock and runsgo test -p 2 -timeout 15m ./app -run '^TestConsensusDeterminism'. The newconsensus-determinismjob in thelong-teststage runs this script on the small runner with a 25m timeout and saves the log as an artifact. - Docs:
docs/test-consensus-determinism.md(linked fromSUMMARY.md) describes the method and its limits. The fixture does not submit signed user transactions, so it does not prove swap execution or outbound signing.
Validation: The integrated consensus-determinism CI job passed; the local runner tests also passed (five tests, no skips). This topic is also included in draft !5181 (closed). This MR will run its own CI against develop; review and merge coordination should avoid landing the same change twice.
Edited by Huginn Ai