soroban-rpc: getLedgerEntries
may interleave incorrect keys and values.
#1084
Labels
bug
Something isn't working
Milestone
Bug Report
What version are you using?
Testnet, which I believe is
v20.0.0-rc.4.1
.What did you do?
I requested two ledger entries: a
ContractData
key alongside its correspondingExpirationData
key. Here is a bash script:What did you expect to see?
I expected to see two returned
entries
: one withkey
as the same key andxdr
as the correspondingLedgerDataEntry
.What did you see instead?
On occasion (approx. one in a dozen runs), the values would interleave incorrectly with the keys. In other words, the
LedgerKeyContractData
inkey
would have theExpirationData
inxdr
and vice-versa. Observe:The first and third execution are correct. However, in the second execution, the
xdr
fields do not match theirkey
fields. Again, this happens sporadically.Additional Investigation
I believe the culprit lies in these lines of code:
https://github.com/stellar/soroban-tools/blob/3fcab5b4d46c441548c78b003c2c0c2513aa070f/cmd/soroban-rpc/internal/methods/get_ledger_entries.go#L111-L115
There is an inherent assumption that the earlier call to
tx.GetLedgerEntries(ledgerKeys...)
(line 90) will return the entries in the same order as they were requested. However, this empirically does not appear to be the case. Instead, we should encode the key the same way we encode the XDR when building the entry rather than relying on thei
index.I believe this should also be backported to the current testnet release (i.e. some
rc.4.2
), which should not be difficult because that file has not changed since then, so there shouldn't be conflicts.The text was updated successfully, but these errors were encountered: