Skip to content

Commit

Permalink
[bugfix][protocol] make funding payment event ordering deterministic (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-dydx committed Jan 3, 2024
1 parent 3e2c518 commit b1cbf42
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion protocol/x/subaccounts/keeper/subaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,10 @@ func (k Keeper) UpdateSubaccounts(
// Emit an event indicating a funding payment was paid / received for each settled funding
// payment. Note that `fundingPaid` is positive if the subaccount paid funding,
// and negative if the subaccount received funding.
for perpetualId, fundingPaid := range fundingPayments {
// Note the perpetual IDs are sorted first to ensure event emission determinism.
sortedPerpIds := lib.GetSortedKeys[lib.Sortable[uint32]](fundingPayments)
for _, perpetualId := range sortedPerpIds {
fundingPaid := fundingPayments[perpetualId]
ctx.EventManager().EmitEvent(
types.NewCreateSettledFundingEvent(
*u.SettledSubaccount.Id,
Expand Down

0 comments on commit b1cbf42

Please sign in to comment.