fix(lib): copy OrderId in DexLimitOrder.Copy - #588
Open
Alicepoltora wants to merge 1 commit into
Open
Conversation
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
DexLimitOrderhas four fields (amountForSale,requestedAmount,address,OrderId), butDexLimitOrder.Copy()only copies the first three -OrderIdis silently dropped.DexBatch.CopyOrdersbuilds both order slices viaorder.Copy(), so every consumer downstream of it seesOrderId == nil. Infsm/dex.gothat value is passed straight into the emitted swap event:The
OrderIdis populated correctly upstream (fsm/transaction.gosets it to the first 20 bytes of the tx hash, andfsm/message.gocarries it into the batch), so the local-origin settlement path reads it off the batch directly and works. Only the remote-origin path goes throughCopy()and loses it.The result is that cross-chain DEX swap events are emitted with an empty
orderIdwhile local ones carry the correct value. SinceorderIdis part of the public event JSON, off-chain indexers and API consumers cannot correlate a remote swap back to its originating order.This is deterministic across nodes and does not affect consensus - events are not part of the state root or
TransactionRoot- so the impact is observability/indexing correctness rather than funds or liveness.Related Issues
None found - I searched open and closed issues and PRs for
DexLimitOrder/OrderId/ dex copy semantics and found nothing covering this.Changes Made
DexLimitOrder.Copy()now copiesOrderIdviabytes.Clone, matching howAddressis already handled.TestDexLimitOrder_Copy: it now setsOrderId, asserts bothAddressandOrderIdround-trip, and asserts the copy is genuinely deep by mutating the original's slices afterwards.The existing test never set
OrderId, which is why the omission went unnoticed.Checklist
issue-#<issue-number>. (No issue exists for this; happy to rename if you'd like one opened first.)npm run prettierto format the web-wallet and/or block explorer (if applicable). (Not applicable.)Additional Notes
Verification on
development:expected orderId 6f726465722d69642d32302d62797465732d3030, got- empty) and passes after it.go test ./lib/passes in full.go test $(go list ./... | grep -v cmd/auto-update)- the CI test command - passes across the repository.go build ./...succeeds;gofmtreports no changes for either touched file.One adjacent observation I deliberately left out to keep this PR single-purpose:
DexBatch.Copy()is shallow -Orders/Deposits/Withdrawals/Receiptsalias the original slices. I traced the current processing paths and found no in-place mutation of those slices today, so it is latent fragility rather than a live bug. Happy to follow up separately if you'd like it hardened.