Skip to content

ledger: extract Wasm state from UTXO snapshots - #239

Merged
rvolosatovs merged 8 commits into
LFDT-Nightstream:mainfrom
rvolosatovs:ledger/snapshot-split
Sep 25, 2026
Merged

rvolosatovs merged 8 commits into
LFDT-Nightstream:mainfrom
rvolosatovs:ledger/snapshot-split

Conversation

@rvolosatovs

@rvolosatovs rvolosatovs commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Rather than uploading the whole Wasm snapshot as part of the transaction, extract the snapshot state and store that in the transaction instead.

Also added some ledger CLI getter subcommands

I had to switch the runtime to do string lookups at call time, since the contract's compiled component might not correspond to the UTXO's compiled component

The ledger now serves UTXO methods over wRPC at starstream:ledger/utxo

$ ./starstream wasm -c ./examples/require_hash_preimage.star --output-component hash.wasm
$ starstream-ledger-cli digest ./hash.wasm 
bciqknicpvzese3thpr4c7tmpsyk7qgnlhwoaoxpvj5dtsgmfclxjbqa
$ cat genesis.toml
[[scripts]]
contract = "bciqknicpvzese3thpr4c7tmpsyk7qgnlhwoaoxpvj5dtsgmfclxjbqa"
script = "create-hash"
args = ["42"]
$ cargo run --bin starstream-ledger-node -- --genesis genesis.toml --import hash.wasm
$ starstream-ledger-cli contract script call --simulate --import ./hash.wasm --output-transaction tx.cbor bciqknicpvzese3thpr4c7tmpsyk7qgnlhwoaoxpvj5dtsgmfclxjbqa consume-hash :0 41
Error: failed to call function

Caused by:
    0: failed to call function
    1: error while executing at wasm backtrace:
           0:    0x7f6 - <unknown>!<wasm function 16>
           1:    0x86d - <unknown>!<wasm function 21>
           2:    0x876 - <unknown>!<wasm function 22>
    2: wasm trap: wasm `unreachable` instruction executed
1 $ starstream-ledger-cli contract script call --simulate --import ./hash.wasm --output-transaction tx.cbor bciqknicpvzese3thpr4c7tmpsyk7qgnlhwoaoxpvj5dtsgmfclxjbqa consume-hash :0 42
()
$ starstream-ledger-cli transaction show tx.cbor  
context = "starstream:transaction"
network = "dev"

[payload]
outputs = []
events = []
proof = ""

[[payload.inputs]]
transaction = ""
index = 1
$ printf admin | sha256sum | cut -d' ' -f1 > admin.key
$ starstream-ledger-cli contract script call --key admin.key --import ./hash.wasm bciqknicpvzese3thpr4c7tmpsyk7qgnlhwoaoxpvj5dtsgmfclxjbqa consume-hash :0 42
()
$ starstream-ledger-cli contract script call --key admin.key --import ./hash.wasm bciqknicpvzese3thpr4c7tmpsyk7qgnlhwoaoxpvj5dtsgmfclxjbqa consume-hash :0 42
Error: input not found

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
Assisted-by: anthropic:claude-fable-5-1
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
UTXOs are not necessarily originating from the component corresponding
to the contract in the method call case due to snapshotting

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
The UTXO RPC used to be addressed as `starstream:utxo/<instance>` and the
server rejected calls whose instance name did not match the referenced
output. The output already records which UTXO instance it belongs to, so
the ledger now infers it from the stored state and callers no longer pass
it: the RPC lives on the `starstream:ledger/utxo` instance next to `block`.

Assisted-by: anthropic:claude-fable-5-1
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
@rvolosatovs
rvolosatovs marked this pull request as ready for review September 24, 2026 21:16

@SpaceManiac SpaceManiac 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.

Played with it a little, didn't notice anything suspicious

@rvolosatovs
rvolosatovs merged commit 4cc14e2 into LFDT-Nightstream:main Sep 25, 2026
4 checks passed
@rvolosatovs
rvolosatovs deleted the ledger/snapshot-split branch September 25, 2026 14:03
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