discovery: add new gossipSyncer struct to manage sync state for each peer

In this commit, introduce a new struct, the gossipSyncer. The role of
this struct is to encapsulate the state machine required to implement
the new gossip query range feature recently added to the spec. With this
change, each peer that knows of this new feature will have a new
goroutine that will be managed by the gossiper.

Once created and started, the gossipSyncer will start to progress
through each possible state, finally ending at the chansSynced stage. In
this stage, it has synchronized state with the remote peer, and is
simply awaiting any new messages from the gossiper to send directly to
the peer. Each message will only be sent if the remote peer actually has
a set update horizon, and the message isn't before or after that
horizon.

A set of unit tests has been added to ensure that two state machines
properly terminate and synchronize channel state.
This commit is contained in:
Olaoluwa Osuntokun
2018-04-16 18:54:53 -07:00
parent 62df3cbbb8
commit 5789ef7c10
3 changed files with 2497 additions and 0 deletions

View File

@@ -1009,6 +1009,20 @@ func (d *AuthenticatedGossiper) networkHandler() {
// If we have new things to announce then broadcast
// them to all our immediately connected peers.
for _, msgChunk := range announcementBatch {
// We'll first attempt to filter out this new
// message for all peers that have active
// gossip syncers active.
d.syncerMtx.RLock()
for _, syncer := range d.peerSyncers {
syncer.FilterGossipMsgs(msgChunk)
}
d.syncerMtx.RUnlock()
// With the syncers taken care of, we'll merge
// the sender map with the set of syncers, so
// we don't send out duplicate messages.
msgChunk.mergeSyncerMap(syncerPeers)
err := d.cfg.Broadcast(
msgChunk.senders, msgChunk.msg,
)