[ANCHOR-1242]: Contract sub invocation transfers are skipped#1971
Draft
amandagonsalves wants to merge 2 commits into
Draft
[ANCHOR-1242]: Contract sub invocation transfers are skipped#1971amandagonsalves wants to merge 2 commits into
amandagonsalves wants to merge 2 commits into
Conversation
* add `buildsubinvocationoperation` to create synthetic operations for contract sub-invocation transfers. * update `processtransferevent` to credit sub-invocation transfers that lack a direct top-level operation. * update `buildpaymenttransferevent` to conditionally map sac to asset. * add tests to verify the crediting of sub-invocation transfers. * add tests to verify skipping sub-invocation transfers with malformed asset data.
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.
Description
Follow-up: credit Variant B instead of skipping it. The first pass logged an
errorFand skipped when no matching operation was found. The Sorobantransferevent's 4th topic is already the SEP-11 asset string -shouldProcess()already decodes it intoShouldProcessResult.sep11Asset, unused.org.stellar.sdk.Asset.create(String)parses that exact format back into anAsset, then.toXdr()- the same methodSacToAssetMapper.getAssetFromSacitself already uses for the same conversion, just from a different source string.Changes
StellarRpcPaymentObserver.processTransferEvent: replacedtxn.getOperations().get(operationIndex)with a TOID-based identity lookup - deriveswantedOpIdfromnew TOID(sequenceNumber, applicationOrder, operationIndex + 1).toInt64(), then stream-filterstxn.getOperations()bygetOperationId(o).equals(wantedOpId). Addsimport org.stellar.sdk.TOID.StellarRpcPaymentObserver.getOperationId: new private helper that extracts theidfield from whichever sub-operation (paymentOperation,pathPaymentOperation, orinvokeHostFunctionOperation) is set on aLedgerOperation.StellarRpcPaymentObserver.buildSubInvocationOperation: new private helper - when the TOID lookup finds no match, builds a syntheticLedgerInvokeHostFunctionOperationdirectly from the transfer event's already-decodedfromAddr/toAddr/amount/sep11Assetfields.processTransferEventreplacestxn's (filtered-empty) operations list with this single synthetic operation and falls through toprocessOperationunchanged, so the synthetic payment flows through the exact same SEP-6/24/31 matching and crediting pipeline as any other payment. LogsinfoFon success; only logserrorF/skips if the event's asset string can't be parsed at all (not expected for a protocol-compliant event).StellarRpcPaymentObserver.processOperation: guarded theINVOKE_HOST_FUNCTIONcase's SAC lookup (if (invokeOp.getAsset(false) == null)) so it doesn't discard the asset already resolved from the event, mirroring the guardDefaultPaymentListener.validate()already uses for the same call.StellarRpcPaymentObserverTest: rewrote the sub-invocation "skip" test into a "credit" test (assertshandleEventis called with the correct from/to/amount/operationId); added a new test for the genuine give-up path (malformed event asset string → skipped, no throw).StellarRpcObserverIndexDomainTest: updated the dedicated sub-invocation test and the mixed-batch test to assert crediting instead of skipping.Acceptance Criteria
[MANAGE_DATA, PAYMENT→dist]withtransferevent atoperationIndex=1is credited with the correct from/to/amount/operationId.transferevent whose corresponding full-list operation is absent from the compacted list (contract sub-invocation) is credited via a synthetic operation built from the event's own fields, with the correct from/to/amount/operationId.transferevent with an unparseable asset string is skipped without throwing, and the observer staysRUNNING.RUNNINGafter any of the above scenarios.StellarRpcPaymentObserverTestandStellarRpcObserverPoisonResilienceTesttests continue to pass unchanged.HorizonPaymentObserver) is unaffected.Context
#3791580
Testing
./gradlew :platform:test --tests "org.stellar.anchor.platform.observer.stellar.StellarRpcPaymentObserverTest"./gradlew :platform:test --tests "org.stellar.anchor.platform.observer.stellar.StellarRpcObserverIndexDomainTest"Documentation
N/A
Known limitations
N/A