Skip to content

Commit

Permalink
fix stake balance update priority
Browse files Browse the repository at this point in the history
  • Loading branch information
cryi committed Sep 2, 2024
1 parent 81ea434 commit 1c51919
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion constants/version.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package constants

const (
VERSION = "0.1.2"
VERSION = "0.1.3"
CODENAME = "ogun"
)
25 changes: 14 additions & 11 deletions core/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,25 +417,28 @@ func (engine *rpcCollector) fetchInitialDelegationState(ctx context.Context, del
return state, nil
}

func makeBurnBalanceUpdatesLast(updates []PRBalanceUpdate) []PRBalanceUpdate {
notBurns := make([]PRBalanceUpdate, 0, len(updates))
burns := make([]PRBalanceUpdate, 0, len(updates))
func makeBurnAndStakeBalanceUpdatesLast(updates []PRBalanceUpdate) []PRBalanceUpdate {
regular := make([]PRBalanceUpdate, 0, len(updates))
toBeLast := make([]PRBalanceUpdate, 0, len(updates))

for i := 1; i < len(updates); i += 2 {
current := updates[i]
previous := updates[i-1]
if current.Kind == "burned" && current.Category == "storage fees" {
burns = append(burns, previous, current)
} else {
notBurns = append(notBurns, previous, current)
switch {
case current.Kind == "freezer" && current.Category == "deposits":
fallthrough
case current.Kind == "burned" && current.Category == "storage fees":
toBeLast = append(toBeLast, previous, current)
default:
regular = append(regular, previous, current)
}
}

if len(notBurns)+len(burns) != len(updates) {
if len(regular)+len(toBeLast) != len(updates) {
panic("invalid balance updates")
}

return append(notBurns, burns...)
return append(regular, toBeLast...)
}

func (engine *rpcCollector) getBlockBalanceUpdates(ctx context.Context, state *common.DelegationState, blockLevelWithMinimumBalance rpc.BlockLevel) (PRBalanceUpdates, error) {
Expand Down Expand Up @@ -494,7 +497,7 @@ func (engine *rpcCollector) getBlockBalanceUpdates(ctx context.Context, state *c
continue
}

allBalanceUpdates = allBalanceUpdates.Add(makeBurnBalanceUpdatesLast(lo.Map(content.Result().BalanceUpdates, func(bu rpc.BalanceUpdate, _ int) PRBalanceUpdate {
allBalanceUpdates = allBalanceUpdates.Add(makeBurnAndStakeBalanceUpdatesLast(lo.Map(content.Result().BalanceUpdates, func(bu rpc.BalanceUpdate, _ int) PRBalanceUpdate {
return PRBalanceUpdate{
Address: bu.Address(),
Amount: bu.Amount(),
Expand Down Expand Up @@ -531,7 +534,7 @@ func (engine *rpcCollector) getBlockBalanceUpdates(ctx context.Context, state *c
// no other updates nor internal results for delegation
continue
}
allBalanceUpdates = allBalanceUpdates.Add(makeBurnBalanceUpdatesLast(lo.Map(internalResult.Result.BalanceUpdates, func(bu rpc.BalanceUpdate, _ int) PRBalanceUpdate {
allBalanceUpdates = allBalanceUpdates.Add(makeBurnAndStakeBalanceUpdatesLast(lo.Map(internalResult.Result.BalanceUpdates, func(bu rpc.BalanceUpdate, _ int) PRBalanceUpdate {
return PRBalanceUpdate{
Address: bu.Address(),
Amount: bu.Amount(),
Expand Down

0 comments on commit 1c51919

Please sign in to comment.