Repository navigation
fix: atomic, concurrency-safe contract_addresses.json writes - #242
Closed
OzzyHelper wants to merge 2 commits into
Closed
OzzyHelper wants to merge 2 commits into
OzzyHelper wants to merge 2 commits into
Conversation
Parallel startup steps (MockUSDFC, Multicall3, FOC deploy) each did an unlocked read-modify-write of the shared contract_addresses.json. Two can run in the same epoch, so one step's entries could be silently lost; the non-atomic write also let concurrent readers (PDP registration, Curio env setup, status) observe truncated JSON. All writers now go through ContractAddresses::update, which holds a process-wide mutex for the whole read-modify-write and writes via a temporary file renamed into place. Corrupt files are rejected instead of being replaced, so a bad write cannot erase deployed addresses. Tests cover concurrent writers merging, section merges, readers never seeing partial JSON, and corrupt-file refusal.
Its save_contract_address was never called and duplicated the racy JSON writer from usdfc_deploy. Multicall3 now writes through the shared ContractAddresses::update path.
Collaborator
|
too complicated for what it is worth right now |
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.
What
Route every write to
contract_addresses.jsonthrough one locked, atomic read-modify-write, and drop the unused duplicate writer.Why
Startup epochs run steps as parallel threads. Epoch 5 deploys MockUSDFC and Multicall3 concurrently; both did an unlocked read-modify-write of the same JSON file, so one deployment's address could be lost. Writes also truncated the file in place, so readers in later steps (PDP SP registration, Curio env setup, status) could observe partial JSON and fail.
How
ContractAddresses::update(run_id, f)holds a process-wide mutex across load → mutate → write.persisted (atomic rename), so readers see old or new content, never a truncated file.update; the never-calledmulticall3_deploy::contract_storageduplicate is removed.#[serde(default)]on the two maps so older/partial files still parse.Testing
cargo test --lib contract_addresses: 4 new tests (concurrent writers merge, section merge, readers never see partial JSON, corrupt-file refusal) — pass.cargo clippy --all-targets --all-features -- -D warnings— clean.cargo test --all-targets --all-features: 55 passed; 2 pre-existing Docker-dependent status tests fail in this sandbox (no Docker CLI).Quality Report
Changes: 6 files changed, 250 insertions(+), 128 deletions(-)
Code scan: clean
Tests: skipped
Branch hygiene: 1 issue(s)