Skip to content

Commit

Permalink
Optimize reward sync
Browse files Browse the repository at this point in the history
  • Loading branch information
kacpersaw committed Jan 22, 2024
1 parent 131d1dd commit a5ce4b7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type Listener interface {
GetEpochNumLayers() uint32
GetTransactions(parent context.Context, query *bson.D, opts ...*options.FindOptions) ([]model.Transaction, error)
UpdateTransactionState(parent context.Context, id string, state int32) error
UpdateEpochStats(layer uint32)
}

type Collector struct {
Expand Down
2 changes: 2 additions & 0 deletions collector/mesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ func (c *Collector) syncLayer(lid types.LayerID) error {
c.listener.OnReward(r)
}

c.listener.UpdateEpochStats(layer.Number.Number)

return nil
}

Expand Down
7 changes: 5 additions & 2 deletions storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,11 @@ func (s *Storage) OnReward(in *pb.Reward) {
}

s.requestBalanceUpdate(reward.Layer, reward.Coinbase)
s.setChangedEpoch(reward.Layer)
s.updateEpochs() // trigger epoch stat recalculation todo: optimize this
}

func (s *Storage) UpdateEpochStats(layer uint32) {
s.setChangedEpoch(layer)
s.updateEpochs()
}

func (s *Storage) OnTransactionResult(res *pb.TransactionResult, state *pb.TransactionState) {
Expand Down

0 comments on commit a5ce4b7

Please sign in to comment.