Skip to content

Commit

Permalink
reduce events len
Browse files Browse the repository at this point in the history
  • Loading branch information
neitdung committed Feb 13, 2025
1 parent 8b2c59b commit f4d5764
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions modules/bank/handle_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ import (
func (m *Module) HandleBlock(
block *tmctypes.ResultBlock, res *tmctypes.ResultBlockResults, _ []*juno.Transaction, _ *tmctypes.ResultValidators,
) error {
m.updateBalanceByTxEvent(block.Block.Height, res.TxsResults)

err := m.updateBalanceByEvent(block.Block.Height, res.FinalizeBlockEvents)
events := res.FinalizeBlockEvents
for _, tx := range res.TxsResults {
events = append(events, tx.Events...)
}
err := m.updateBalanceByEvent(block.Block.Height, events)
if err != nil {
fmt.Printf("Error when update balance by end block: %s", err)
}
Expand Down Expand Up @@ -83,20 +85,6 @@ func (m *Module) updateBalanceByEvent(height int64, events []abci.Event) error {
return m.UpdateBalance(addresses, height)
}

// removeExpiredFeeGrantAllowances removes fee grant allowances in database that have expired
func (m *Module) updateBalanceByTxEvent(height int64, txs []*abci.ExecTxResult) {
log.Debug().Str("module", "bank").Int64("height", height).
Msg("updating balance by tx event")

for _, tx := range txs {
events := tx.Events
err := m.updateBalanceByEvent(height, events)
if err != nil {
fmt.Printf("Error when update balance inside tx events: %s", err)
}
}
}

func (m *Module) UpdateBalance(addresses []string, height int64) error {
log.Trace().Str("module", "bank").Str("operation", "account balance").
Msg("updating account balance")
Expand Down

0 comments on commit f4d5764

Please sign in to comment.