Skip to content

feat(checkpoint): read hot-archive entries so archived wasm hashes are stored - #694

Open
aditya1702 wants to merge 1 commit into
main-blendfrom
checkpoint-hot-archive-wasms
Open

feat(checkpoint): read hot-archive entries so archived wasm hashes are stored#694
aditya1702 wants to merge 1 commit into
main-blendfrom
checkpoint-hot-archive-wasms

Conversation

@aditya1702

@aditya1702 aditya1702 commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

TL;DR: checkpoint load now also reads the protocol-23 hot archive. Evicted wasm hashes and contract instances land in protocol_wasms / protocol_contracts / contract_tokens instead of vanishing.

The bug

  1. Checkpoint load read only the live bucket list.
  2. Contract code evicted to the hot archive → hash missing from protocol_wasms.
  3. Missing hash → every instance pointing at it dropped from protocol_contracts.
  4. Dropped instance → SEP-41 contract never classified → wrong balances after restore.

The fix

One new pass in the same load transaction, right before finalize. It streams ingest.NewHotArchiveIterator.

Archived entry Result
Contract code hash → protocol_wasms
Wasm contract instance contract_tokens (UNKNOWN) + protocol_contracts mapping
Balance entry skipped — restore/live ingest folds it, no double count
SAC instance skipped — no wasm to map; row recreated on restore

Entries restored before the checkpoint never appear: the SDK's hot-archive tombstones suppress them.

Why the code looks the way it does

  • No WithFilter. A key filter breaks tombstone suppression and resurrects restored entries.
  • The iterator loop's only early exit is a yielded error. Any other break deadlocks on the SDK iterator's internal WaitGroup.
  • Pre-protocol-23 checkpoints (HAS version < 2) skip the pass instead of crashing on the missing bucket list.

Classification: zero changes needed

stellar-rpc (protocol 23+) getLedgerEntries returns archived entries with bytecode (verified in v28 source, internal/ledgerentries/main.go). The existing RPC classify pass resolves archived hashes as-is.

Testing

  • 8 new tests. The key one: live instance + archived code → protocol_contracts mapping present (silently dropped before this PR).
  • Mutation-checked: emptying the hot-archive iterator fails the tests on the exact expected inserts.
  • Full internal/services suite green. make check green.

No schema changes. No migrations (wallet-backend is pre-release).

…e stored

PopulateFromCheckpoint reads only the live bucket list, so contract code and
contract instances evicted under protocol-23 state archival never reached
protocol_wasms/protocol_contracts. Archived SEP-41 contracts therefore stayed
unclassified and their current state was never computed, producing wrong
balances once those contracts were restored.

Add a hot-archive pass (ingest.NewHotArchiveIterator) inside the same load
transaction, before finalize: archived ContractCode joins wasmClassifications
and archived wasm-executable contract instances land in contract_tokens and
protocol_contracts. Archived balance entries and SAC instances are skipped;
live ingestion recreates their rows on restore. Checkpoints predating
protocol 23 (HAS version < 2) skip the pass instead of failing on the absent
hot-archive bucket list.

Classification needs no changes: stellar-rpc (protocol 23+) getLedgerEntries
returns archived entries with bytecode, so the RPC-based setup pass resolves
archived wasm hashes as-is.
@aditya1702
aditya1702 force-pushed the checkpoint-hot-archive-wasms branch from 781ed46 to 16cc934 Compare August 21, 2026 17:18
@aditya1702
aditya1702 requested review from aristidesstaffieri and a balanced review from Copilot August 21, 2026 18:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Extends checkpoint restoration to preserve Soroban contracts and WASM hashes held in the protocol-23 hot archive.

Changes:

  • Streams hot-archive entries during checkpoint loading.
  • Persists archived WASM code and contract-instance mappings.
  • Adds coverage for ingestion, skipping rules, legacy checkpoints, and iterator failures.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
internal/services/checkpoint.go Integrates hot-archive processing into checkpoint restoration.
internal/services/checkpoint_test.go Tests archived-entry handling and error paths.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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.

2 participants