Skip to content

Commit 15722ca

Browse files
authored
Ship 3971 update sentinel (#1522)
* Adds Sentinel Coordinator * Adjusts logging * Adds changeset
1 parent 302cf1e commit 15722ca

File tree

3 files changed

+43
-10
lines changed

3 files changed

+43
-10
lines changed

sentinel/.changeset/v0.1.1.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Add SentinelCoordinator Struct
2+
- Minor logging fix

sentinel/internal/subscription_manager/subscription_manager.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ func (sm *SubscriptionManager) Subscribe(address common.Address, topic common.Ha
6565

6666
sm.logger.Info().
6767
Int64("ChainID", sm.chainID).
68-
Hex("Address", []byte(address.Hex())).
69-
Hex("Topic", []byte(topic.Hex())).
68+
Str("Address", address.Hex()).
69+
Str("Topic", topic.Hex()).
7070
Int64("SubscriberCount", int64(len(sm.registry[eventKey]))).
7171
Msg("New subscription added")
7272

@@ -82,8 +82,8 @@ func (sm *SubscriptionManager) Unsubscribe(address common.Address, topic common.
8282
if !exists {
8383
sm.logger.Warn().
8484
Int64("ChainID", sm.chainID).
85-
Hex("Address", []byte(address.Hex())).
86-
Hex("Topic", []byte(topic.Hex())).
85+
Str("Address", address.Hex()).
86+
Str("Topic", topic.Hex()).
8787
Msg("Attempted to unsubscribe from a non-existent EventKey")
8888
return errors.New("event key does not exist")
8989
}
@@ -99,8 +99,8 @@ func (sm *SubscriptionManager) Unsubscribe(address common.Address, topic common.
9999
sm.mu.Unlock()
100100
sm.logger.Info().
101101
Int64("ChainID", sm.chainID).
102-
Hex("Address", []byte(address.Hex())).
103-
Hex("Topic", []byte(topic.Hex())).
102+
Str("Address", address.Hex()).
103+
Str("Topic", topic.Hex()).
104104
Int64("RemainingSubscribers", int64(len(sm.registry[eventKey]))).
105105
Msg("Subscription removed")
106106
found = true
@@ -124,8 +124,8 @@ func (sm *SubscriptionManager) Unsubscribe(address common.Address, topic common.
124124
delete(sm.registry, eventKey)
125125
sm.logger.Debug().
126126
Int64("ChainID", sm.chainID).
127-
Hex("Address", []byte(address.Hex())).
128-
Hex("Topic", []byte(topic.Hex())).
127+
Str("Address", address.Hex()).
128+
Str("Topic", topic.Hex()).
129129
Msg("No remaining subscribers, removing EventKey from registry")
130130
}
131131
sm.mu.Unlock()
@@ -173,8 +173,8 @@ func (sm *SubscriptionManager) BroadcastLog(eventKey internal.EventKey, log api.
173173
sm.logger.Debug().
174174
Int64("ChainID", sm.chainID).
175175
Int("Subscribers", len(subscribers)).
176-
Hex("Address", []byte(eventKey.Address.Hex())).
177-
Hex("Topic", []byte(eventKey.Topic.Hex())).
176+
Str("Address", eventKey.Address.Hex()).
177+
Str("Topic", eventKey.Topic.Hex()).
178178
Msg("Log broadcasted to all subscribers")
179179
}
180180

sentinel/sentinel_coordinator.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// File: sentinel.go
2+
package sentinel
3+
4+
import (
5+
"context"
6+
"sync"
7+
8+
"github.com/rs/zerolog"
9+
)
10+
11+
type SentinelCoordinator struct {
12+
Sentinel *Sentinel
13+
wg *sync.WaitGroup
14+
Ctx context.Context
15+
cancel context.CancelFunc
16+
log zerolog.Logger
17+
}
18+
19+
func NewSentinelCoordinator(log zerolog.Logger) *SentinelCoordinator {
20+
ctx, cancel := context.WithCancel(context.Background())
21+
wg := &sync.WaitGroup{}
22+
s := NewSentinel(SentinelConfig{})
23+
24+
return &SentinelCoordinator{
25+
Sentinel: s,
26+
wg: wg,
27+
Ctx: ctx,
28+
cancel: cancel,
29+
log: log,
30+
}
31+
}

0 commit comments

Comments
 (0)