Skip to content

Commit 31c2a93

Browse files
roy-dydxlucas-dydx
andauthored
[bugfix][protocol] make funding payment event ordering deterministic (#921) (#1166)
Co-authored-by: lucas-dydx <76970939+lucas-dydx@users.noreply.github.com>
1 parent 9681762 commit 31c2a93

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

protocol/x/subaccounts/keeper/subaccount.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,10 @@ func (k Keeper) UpdateSubaccounts(
324324
// Emit an event indicating a funding payment was paid / received for each settled funding
325325
// payment. Note that `fundingPaid` is positive if the subaccount paid funding,
326326
// and negative if the subaccount received funding.
327-
for perpetualId, fundingPaid := range fundingPayments {
327+
// Note the perpetual IDs are sorted first to ensure event emission determinism.
328+
sortedPerpIds := lib.GetSortedKeys[lib.Sortable[uint32]](fundingPayments)
329+
for _, perpetualId := range sortedPerpIds {
330+
fundingPaid := fundingPayments[perpetualId]
328331
ctx.EventManager().EmitEvent(
329332
types.NewCreateSettledFundingEvent(
330333
*u.SettledSubaccount.Id,

0 commit comments

Comments
 (0)