@@ -24,16 +24,14 @@ type BlockWebhook struct {
2424}
2525
2626type BlockWatcher struct {
27- trackedValidators []TrackedValidator
28- metrics * metrics.Metrics
29- writer io.Writer
30- blockChan chan * BlockInfo
31- validatorSet atomic.Value // []*types.Validator
32- latestBlockHeight int64
33- latestBlockProposer string
34- latestBlockTransactions int
35- webhook * webhook.Webhook
36- customWebhooks []BlockWebhook
27+ trackedValidators []TrackedValidator
28+ metrics * metrics.Metrics
29+ writer io.Writer
30+ blockChan chan * BlockInfo
31+ validatorSet atomic.Value // []*types.Validator
32+ latestBlock BlockInfo
33+ webhook * webhook.Webhook
34+ customWebhooks []BlockWebhook
3735}
3836
3937func NewBlockWatcher (validators []TrackedValidator , metrics * metrics.Metrics , writer io.Writer , webhook * webhook.Webhook , customWebhooks []BlockWebhook ) * BlockWatcher {
@@ -173,7 +171,7 @@ func (w *BlockWatcher) syncValidatorSet(ctx context.Context, n *rpc.Node) error
173171func (w * BlockWatcher ) handleBlockInfo (ctx context.Context , block * BlockInfo ) {
174172 chainId := block .ChainID
175173
176- if w .latestBlockHeight >= block .Height {
174+ if w .latestBlock . Height >= block .Height {
177175 // Skip already processed blocks
178176 return
179177 }
@@ -188,8 +186,8 @@ func (w *BlockWatcher) handleBlockInfo(ctx context.Context, block *BlockInfo) {
188186 }
189187 w .metrics .SkippedBlocks .WithLabelValues (chainId )
190188
191- blockDiff := block .Height - w .latestBlockHeight
192- if w .latestBlockHeight > 0 && blockDiff > 1 {
189+ blockDiff := block .Height - w .latestBlock . Height
190+ if w .latestBlock . Height > 0 && blockDiff > 1 {
193191 log .Warn ().Msgf ("skipped %d unknown blocks" , blockDiff - 1 )
194192 w .metrics .SkippedBlocks .WithLabelValues (chainId ).Add (float64 (blockDiff ))
195193 }
@@ -203,9 +201,9 @@ func (w *BlockWatcher) handleBlockInfo(ctx context.Context, block *BlockInfo) {
203201 validatorStatus := []string {}
204202 for _ , res := range block .ValidatorStatus {
205203 icon := "⚪️"
206- if w .latestBlockProposer == res .Address {
204+ if w .latestBlock . ProposerAddress == res .Address {
207205 // Check if this is an empty block
208- if w .latestBlockTransactions == 0 {
206+ if w .latestBlock . Transactions == 0 {
209207 icon = "🟡"
210208 w .metrics .EmptyBlocks .WithLabelValues (block .ChainID , res .Address , res .Label ).Inc ()
211209 } else {
@@ -241,9 +239,8 @@ func (w *BlockWatcher) handleBlockInfo(ctx context.Context, block *BlockInfo) {
241239 // Handle webhooks
242240 w .handleWebhooks (ctx , block )
243241
244- w .latestBlockHeight = block .Height
245- w .latestBlockProposer = block .ProposerAddress
246- w .latestBlockTransactions = block .Transactions
242+ // Save latest block
243+ w .latestBlock = * block
247244}
248245
249246func (w * BlockWatcher ) computeValidatorStatus (block * types.Block ) []ValidatorStatus {
0 commit comments