node: support for heartbeat spying fixes #1768
This commit is contained in:
parent
61454a39bd
commit
9fa943eecd
|
@ -782,7 +782,7 @@ func runNode(cmd *cobra.Command, args []string) {
|
|||
injectC := make(chan *vaa.VAA)
|
||||
|
||||
// Guardian set state managed by processor
|
||||
gst := common.NewGuardianSetState()
|
||||
gst := common.NewGuardianSetState(nil)
|
||||
|
||||
// Per-chain observation requests
|
||||
chainObsvReqC := make(map[vaa.ChainID]chan *gossipv1.ObservationRequest)
|
||||
|
|
|
@ -257,7 +257,7 @@ func runSpy(cmd *cobra.Command, args []string) {
|
|||
signedInC := make(chan *gossipv1.SignedVAAWithQuorum, 50)
|
||||
|
||||
// Guardian set state managed by processor
|
||||
gst := common.NewGuardianSetState()
|
||||
gst := common.NewGuardianSetState(nil)
|
||||
|
||||
// RPC server
|
||||
s := newSpyServer(logger)
|
||||
|
|
|
@ -82,11 +82,17 @@ type GuardianSetState struct {
|
|||
// Last heartbeat message received per guardian per p2p node. Maintained
|
||||
// across guardian set updates - these values don't change.
|
||||
lastHeartbeats map[common.Address]map[peer.ID]*gossipv1.Heartbeat
|
||||
updateC chan *gossipv1.Heartbeat
|
||||
}
|
||||
|
||||
func NewGuardianSetState() *GuardianSetState {
|
||||
// NewGuardianSetState returns a new GuardianSetState.
|
||||
//
|
||||
// The provided channel will be pushed heartbeat updates as they are set,
|
||||
// but be aware that the channel will block guardian set updates if full.
|
||||
func NewGuardianSetState(guardianSetStateUpdateC chan *gossipv1.Heartbeat) *GuardianSetState {
|
||||
return &GuardianSetState{
|
||||
lastHeartbeats: map[common.Address]map[peer.ID]*gossipv1.Heartbeat{},
|
||||
updateC: guardianSetStateUpdateC,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -136,6 +142,9 @@ func (st *GuardianSetState) SetHeartbeat(addr common.Address, peerId peer.ID, hb
|
|||
}
|
||||
|
||||
v[peerId] = hb
|
||||
if st.updateC != nil {
|
||||
st.updateC <- hb
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ func TestKeysAsHexStrings(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestNewGuardianSetState(t *testing.T) {
|
||||
gss := NewGuardianSetState()
|
||||
gss := NewGuardianSetState(nil)
|
||||
assert.NotNil(t, gss)
|
||||
assert.Nil(t, gss.current)
|
||||
assert.Nil(t, gss.Get())
|
||||
|
@ -72,7 +72,7 @@ func TestSet(t *testing.T) {
|
|||
Index: 1,
|
||||
}
|
||||
|
||||
gss := NewGuardianSetState()
|
||||
gss := NewGuardianSetState(nil)
|
||||
assert.Nil(t, gss.current)
|
||||
gss.Set(&gs)
|
||||
assert.Equal(t, gss.current, &gs)
|
||||
|
@ -87,7 +87,7 @@ func TestGet(t *testing.T) {
|
|||
Index: 1,
|
||||
}
|
||||
|
||||
gss := NewGuardianSetState()
|
||||
gss := NewGuardianSetState(nil)
|
||||
assert.Nil(t, gss.Get())
|
||||
gss.Set(&gs)
|
||||
assert.Equal(t, gss.Get(), &gs)
|
||||
|
|
Loading…
Reference in New Issue