Add tx-granular ledger snapshot source using meta, RPC, and archives - #1657
Add tx-granular ledger snapshot source using meta, RPC, and archives#1657leighmcculloch wants to merge 79 commits into
Conversation
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
42f37c9 to
598ad4c
Compare
0a8ae20 to
19904da
Compare
19904da to
cdc7199
Compare
|
is it possible to set it so the timestamp is also set after the snapshot has been loaded? Currently we need to manually set it after the |
|
This seems like an interesting way of handling a simulation locally. Or at least doing a read call locally. |
|
Looks awesome. Thanks, Leigh! ❤️ |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
I've pushed a change to this that drastically reduces a first run. Some of the cached data wasn't made available until a second pass, but was actually useful to have on the next step in the first pass, so just added an additional level of caching there. |
This comment has been minimized.
This comment has been minimized.
### What Add a CI workflow that forks a local stellar/quickstart network, reading state from the SEP-54 ledger meta store and the history archive that quickstart runs alongside core and rpc, three times over: with no cache, with only the system cache, and with the system and workspace caches. ### Why Everything the snapshot source does has so far only been exercised against mainnet fixtures, so a break in the meta store or history archive lookups only surfaces against live networks and data that can't be produced on demand; quickstart runs both stores locally, and this also caught `Network::local()` pointing at `/meta-archive` rather than the `/ledger-meta` path quickstart serves. ### Known limitations The workflow uses the floating `stellar/quickstart:testing` tag because galexie support is not in a released quickstart tag yet, and the test asserts only native Stellar Asset Contract balances, not other entry types. ### SemVer Change - [ ] Major (`vX._._`) - Breaking change to the public API. - [ ] Minor (`v_.Y._`) - Additive change to the public API. - [x] Patch (`v_._.Z`) - No change to the public API.
|
semver:minor — this PR adds a new published crate,
This classification is advisory; the author and reviewer decide the release type.
|
What
Add new crates for fetching ledger entries from multiple data sources to enable more seamless and built-in fork testing in the sdk. Add
soroban-ledger-snapshot-source-txfor transaction-level snapshot sources.sequenceDiagram autonumber actor App as participant SelTxMeta as Query<br/>Ledger<br/>Tx Meta participant LedgerMeta as Query<br/>Ledger – 1..N<br/>Tx Meta participant Archive as History<br/>Archive participant RPC as RPC App->>SelTxMeta: Lookup with key Note over App,SelTxMeta: If found → use it.<br/>If not → continue. App->>SelTxMeta: Look in prior txs in same ledger Note over App,SelTxMeta: If found → use it.<br/>If not → continue. opt Optionally use RPC App->>RPC: getLedgerEntries([key]) Note over App,RPC: Use if (lastModified < queryLedger)<br/>AND (rpcLatestSeen >= queryLedger).<br/>Otherwise continue. end App->>LedgerMeta: Look in prior ledger meta Note over App,LedgerMeta: If found → use it.<br/>If checkpoint ledger not reached → continue to next ledger meta<br/>If checkpoint ledger is reached → continue to archive. App->>Archive: Download checkpoint from history archive and search Note over App,Archive: If found → use it.<br/>If not → does not exist.Why
The current fork testing experience utilising the stellar-cli has low granularity only at the boundaries of ledgers, and requires downloading full history archives and manually identifying footprints ahead of time, which is difficult to do well and a poor developer experience. This change enables the SDK to lazily fetch ledger entries on-demand from the most efficient source available, caching results locally for subsequent runs. Developers will be able to fork test against any ledger and transaction without pre-identifying the footprint.
The change uses a Ledger Meta Storage (SEP-54), an RPC, and a History Archive to collect ledger entries.
The change caches results in three layers. All raw files downloaded are cached in the system cache directory and reused across tests, across workspaces. All ledger entries found are cached in the system cache directory. All ledger entries found for the current workspace are cached in the
tests-snapshot-sourcedirectory intended to be committed so that CI runs reproducibly without needing to collect entries. Note that the format of that cache is not a ledger snapshot json file because for many tests running concurrently one file per ledger entry is easier to manage.Close #1448
Try it out
Add the following dependencies to your
Cargo.toml:Note: Requires
soroban-sdkv23.4.0or later.Example
Observing State Changes
The
TxSnapshotSourcelooks up state with transaction-level granularity when a transaction hash is provided allowing developers to debug a transaction by starting at the point just before the transaction. For example:Before a specific tx: Pass the tx hash to get state just before that tx executed:
End of ledger (after all txs): Use
Nonefor the tx_hash to get state at the end of the ledger:Different ledgers/txs: Update the test to investigate the state of the balance at each of the following ledgers and transactions to see how the transactions affected the balance. Check out the links to see the operations the transactions performed and how they align with the changes in balances observed.
Debugging with RUST_LOG
Enable logging to see which data sources are being queried and what entries are found:
Example output:
TODO
Thanks
Thanks @orbitlens for sharing the idea of using transaction meta as a way to collect recent state. Thanks to all the people who provided feedback to me about how they use the existing
stellar snapshot createfunctionality.