Skip to content

Commit

Permalink
Automation - Lock reads and writes from and to the ConfigDigest (#14313)
Browse files Browse the repository at this point in the history
* Lock reads and writes from and to the ConfigDigest

* Add a changeset

* Update core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/autotelemetry21/custom_telemetry.go

Co-authored-by: Jordan Krage <[email protected]>

* Lock the config digest check

---------

Co-authored-by: Jordan Krage <[email protected]>
  • Loading branch information
ferglor and jmank88 authored Sep 4, 2024
1 parent 0befa70 commit b71e692
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/curvy-months-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

Use a lock to sync access to the ConfigDigest #internal
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package autotelemetry21
import (
"context"
"encoding/hex"
"sync"
"time"

"google.golang.org/protobuf/proto"
Expand All @@ -29,6 +30,7 @@ type AutomationCustomTelemetryService struct {
lggr logger.Logger
configDigest [32]byte
contractConfigTracker types.ContractConfigTracker
mu sync.RWMutex
}

// NewAutomationCustomTelemetryService creates a telemetry service for new blocks and node version
Expand Down Expand Up @@ -66,8 +68,15 @@ func (e *AutomationCustomTelemetryService) Start(ctx context.Context) error {
if err != nil {
e.lggr.Errorf("Error occurred while getting newestConfigDetails in configDigest loop %s", err)
}
configChanged := false
e.mu.Lock()
if newConfigDigest != e.configDigest {
e.configDigest = newConfigDigest
configChanged = true
}
e.mu.Unlock()

if configChanged {
e.sendNodeVersionMsg()
}
case <-hourTicker.C:
Expand Down Expand Up @@ -121,10 +130,14 @@ func (e *AutomationCustomTelemetryService) Close() error {
}

func (e *AutomationCustomTelemetryService) sendNodeVersionMsg() {
e.mu.RLock()
configDigest := e.configDigest
e.mu.RUnlock()

vMsg := &telem.NodeVersion{
Timestamp: uint64(time.Now().UTC().UnixMilli()),
NodeVersion: static.Version,
ConfigDigest: e.configDigest[:],
ConfigDigest: configDigest[:],
}
wrappedVMsg := &telem.AutomationTelemWrapper{
Msg: &telem.AutomationTelemWrapper_NodeVersion{
Expand All @@ -141,11 +154,15 @@ func (e *AutomationCustomTelemetryService) sendNodeVersionMsg() {
}

func (e *AutomationCustomTelemetryService) sendBlockNumberMsg(blockKey ocr2keepers.BlockKey) {
e.mu.RLock()
configDigest := e.configDigest
e.mu.RUnlock()

blockNumMsg := &telem.BlockNumber{
Timestamp: uint64(time.Now().UTC().UnixMilli()),
BlockNumber: uint64(blockKey.Number),
BlockHash: hex.EncodeToString(blockKey.Hash[:]),
ConfigDigest: e.configDigest[:],
ConfigDigest: configDigest[:],
}
wrappedBlockNumMsg := &telem.AutomationTelemWrapper{
Msg: &telem.AutomationTelemWrapper_BlockNumber{
Expand Down

0 comments on commit b71e692

Please sign in to comment.