Skip to content

Commit

Permalink
[bugfix][protocol] make funding payment event ordering deterministic (#…
Browse files Browse the repository at this point in the history
…921) (#1166)

Co-authored-by: lucas-dydx <76970939+lucas-dydx@users.noreply.github.com>
  • Loading branch information
roy-dydx and lucas-dydx committed Mar 12, 2024
1 parent 9681762 commit 31c2a93
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion protocol/x/subaccounts/keeper/subaccount.go
Expand Up @@ -324,7 +324,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 31c2a93

Please sign in to comment.