node: support for heartbeat spying fixes #1768

This commit is contained in:
Evan Gray 2022-09-06 23:36:02 +00:00 committed by Evan Gray
parent 61454a39bd
commit 9fa943eecd
4 changed files with 15 additions and 6 deletions

View File

@ -782,7 +782,7 @@ func runNode(cmd *cobra.Command, args []string) {
injectC := make(chan *vaa.VAA) injectC := make(chan *vaa.VAA)
// Guardian set state managed by processor // Guardian set state managed by processor
gst := common.NewGuardianSetState() gst := common.NewGuardianSetState(nil)
// Per-chain observation requests // Per-chain observation requests
chainObsvReqC := make(map[vaa.ChainID]chan *gossipv1.ObservationRequest) chainObsvReqC := make(map[vaa.ChainID]chan *gossipv1.ObservationRequest)

View File

@ -257,7 +257,7 @@ func runSpy(cmd *cobra.Command, args []string) {
signedInC := make(chan *gossipv1.SignedVAAWithQuorum, 50) signedInC := make(chan *gossipv1.SignedVAAWithQuorum, 50)
// Guardian set state managed by processor // Guardian set state managed by processor
gst := common.NewGuardianSetState() gst := common.NewGuardianSetState(nil)
// RPC server // RPC server
s := newSpyServer(logger) s := newSpyServer(logger)

View File

@ -82,11 +82,17 @@ type GuardianSetState struct {
// Last heartbeat message received per guardian per p2p node. Maintained // Last heartbeat message received per guardian per p2p node. Maintained
// across guardian set updates - these values don't change. // across guardian set updates - these values don't change.
lastHeartbeats map[common.Address]map[peer.ID]*gossipv1.Heartbeat 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{ return &GuardianSetState{
lastHeartbeats: map[common.Address]map[peer.ID]*gossipv1.Heartbeat{}, 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 v[peerId] = hb
if st.updateC != nil {
st.updateC <- hb
}
return nil return nil
} }

View File

@ -57,7 +57,7 @@ func TestKeysAsHexStrings(t *testing.T) {
} }
func TestNewGuardianSetState(t *testing.T) { func TestNewGuardianSetState(t *testing.T) {
gss := NewGuardianSetState() gss := NewGuardianSetState(nil)
assert.NotNil(t, gss) assert.NotNil(t, gss)
assert.Nil(t, gss.current) assert.Nil(t, gss.current)
assert.Nil(t, gss.Get()) assert.Nil(t, gss.Get())
@ -72,7 +72,7 @@ func TestSet(t *testing.T) {
Index: 1, Index: 1,
} }
gss := NewGuardianSetState() gss := NewGuardianSetState(nil)
assert.Nil(t, gss.current) assert.Nil(t, gss.current)
gss.Set(&gs) gss.Set(&gs)
assert.Equal(t, gss.current, &gs) assert.Equal(t, gss.current, &gs)
@ -87,7 +87,7 @@ func TestGet(t *testing.T) {
Index: 1, Index: 1,
} }
gss := NewGuardianSetState() gss := NewGuardianSetState(nil)
assert.Nil(t, gss.Get()) assert.Nil(t, gss.Get())
gss.Set(&gs) gss.Set(&gs)
assert.Equal(t, gss.Get(), &gs) assert.Equal(t, gss.Get(), &gs)