feat: implement simulateTransaction#36
Open
RaoulSchaffranek wants to merge 4 commits into
Open
Conversation
Cover the spec-required response shape: latestLedger as a JSON number,
minResourceFee as a stringified number, results[0].xdr carrying the host
function return value as base64 SCVal XDR, results[0].auth as an array of
base64 strings, and transactionData as valid SorobanTransactionData XDR.
Optional fields must be omitted rather than null, matching the omitempty
serialization of real stellar-rpc.
Also assert that simulation never commits (no ledger bump, no receipt, no
trace), that failures are reported as a result-level {error, latestLedger}
object without the success-only fields, that non-InvokeHostFunction
transactions are rejected with a result-level error, and that missing or
malformed transaction params return JSON-RPC error -32602.
All six tests currently fail with -32601 because the method is not
implemented yet.
Dispatch a simulateTransaction request through the K semantics like a
regular invocation, but discard the resulting configuration
(interpreter.run gains a commit flag) and write no receipt, trace, or
ledger bump. The semantics report the invocation's return value as a
JSON-encoded ScVal; the server serializes it to base64 SCVal XDR
(json_to_scval) and fills in a synthetic minResourceFee and an
empty-footprint SorobanTransactionData, since K cannot build XDR.
Failures (trapped call, unknown contract, non-invoke transaction) are
reported in the result body as {error, latestLedger}, matching real
stellar-rpc; only undecodable transaction XDR is a -32602 error.
Both errors predate this branch: komet's SCVec.val annotation is tuple[SCValue] (a 1-tuple) rather than tuple[SCValue, ...], so the call in scvalue_from_xdr needs a targeted ignore, and the server test fixture was missing its return type annotation. make check now passes.
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
Implements the
simulateTransactionRPC method as a non-committing dry run of a contract invocation, per the Stellar RPC specification.The server decodes the base64 transaction envelope (which may be unsigned) and requires exactly one
InvokeHostFunctionoperation with an invoke-contract host function. The invocation is dispatched through the K semantics like a regularsendTransaction, but nothing is committed:interpreter.rungains acommitflag that discards the resulting configuration, and no receipt, trace, or ledger bump is written.On success the response contains:
latestLedgeras a JSON number,minResourceFeeas a stringified constant (the semantics do not meter resources),results[0].xdr— the host function's return value as base64 SCVal XDR, withauth: [],transactionData— a minimal validSorobanTransactionData(empty footprint, zero resources).Failures (trapped call, unknown contract, non-invoke transaction, upload/deploy host functions) are reported in the result body as
{error, latestLedger}, matching real stellar-rpc; only an undecodabletransactionparameter is a JSON-RPC-32602error. Optional fields are omitted rather than set tonull, matching theomitemptyserialization of the Go structs.How
Following the repo architecture, dispatch and response content live in the K semantics (
node.md): asimulateTransactionrule runs the invocation and reports the return value from the<hostStack>as a JSON-encoded ScVal, or a result-level error when the call trapped. The final XDR serialization is the one part done in Python, since K has no XDR encoder or base64 hook:json_to_scval(scval.py) converts the JSON ScVal to base64 SCVal XDR, andserver.pyfills inminResourceFeeandtransactionData. Docs (server.md,architecture.md,notes.md) describe the method and its current limitations (no auth recording, no resource metering, noevents/restorePreamble/stateChanges,ScMapreturn values not yet encoded).Testing
src/tests/integration/test_server.pycover the response shape (number/string types, base64 XDR round-trips), the no-commit guarantee (no ledger bump, no receipt, no trace), result-level errors for failed simulations and non-invoke transactions, and-32602for missing/malformed params.test_server.pysuite passes (32 tests), andmake checkis clean (including two mypy findings that predate this branch).