Skip to content

Commit

Permalink
hum: fix test
Browse files Browse the repository at this point in the history
Signed-off-by: bingyuyap <bingyu.yap.21@gmail.com>
  • Loading branch information
bingyuyap committed Sep 4, 2024
1 parent 6c3eab4 commit 8847633
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions fly/cmd/historical_uptime/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ func main() {

// Add channel capacity checks
go monitorChannelCapacity(rootCtx, logger, "obsvC", obsvC)
go monitorChannelCapacity(rootCtx, logger, "batchObsvC", batchObsvC)

// Heartbeat updates
heartbeatC := make(chan *gossipv1.Heartbeat, 50)
Expand Down
9 changes: 5 additions & 4 deletions fly/pkg/historical_uptime/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func InitializeMissingObservationsCount(logger *zap.Logger, messages []*types.Me

func DecrementMissingObservationsCount(logger *zap.Logger, guardianMissingObservations map[string]map[string]int, messageObservations map[types.MessageID][]*types.Observation) {
// Keep track of processed observations to avoid duplicates
processed := make(map[string]map[string]bool)
processed := make(map[string]map[string]struct{})

for messageID, observations := range messageObservations {
chainID, err := messageID.ChainID()
Expand All @@ -63,15 +63,16 @@ func DecrementMissingObservationsCount(logger *zap.Logger, guardianMissingObserv

// Check if we've already processed this guardian for this message
if processed[string(messageID)] == nil {
processed[string(messageID)] = make(map[string]bool)
processed[string(messageID)] = make(map[string]struct{})
}
if processed[string(messageID)][guardianName] {

if _, exists := processed[string(messageID)][guardianName]; exists {
logger.Warn("Duplicate observation", zap.String("messageID", string(messageID)), zap.String("guardian", guardianName))
continue
}

// Mark as processed
processed[string(messageID)][guardianName] = true
processed[string(messageID)][guardianName] = struct{}{}

// Safely decrement the count
if guardianMissingObservations[guardianName] == nil {
Expand Down
7 changes: 6 additions & 1 deletion fly/pkg/historical_uptime/process_observation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ func processObservation(t *testing.T, observations []node_common.MsgWithTimeStam

// Process each observation
for _, o := range observations {
err := ProcessObservation(*database, logger, o)
err := ProcessObservation(*database, logger, o.Timestamp, o.Msg.Addr, &gossipv1.Observation{
Hash: o.Msg.Hash,
Signature: o.Msg.Signature,
TxHash: o.Msg.TxHash,
MessageId: o.Msg.MessageId,
})
if err != nil {
t.Errorf("failed to process observation: %v", err)
}
Expand Down

0 comments on commit 8847633

Please sign in to comment.