statesync: broadcast snapshot request to all peers on startup (#5320)

On startup, the peer-to-peer stack may have peers connected before the state sync process begins, causing these to not trigger `AddPeer` events and thus not be used for snapshot discovery. Broadcasting a snapshot request to these explicitly makes sure we discover snapshots from existing peers as well.
This commit is contained in:
Erik Grinaker
2020-09-02 10:16:08 +02:00
committed by GitHub
parent 82011ee7ab
commit 2f4c1f60c7
2 changed files with 6 additions and 0 deletions

View File

@@ -40,4 +40,6 @@ Friendly reminder, we have a [bug bounty program](https://hackerone.com/tendermi
- [statesync] \#5311 Fix validator set off-by-one causing consensus failures (@erikgrinaker)
- [statesync] \#5320 Broadcast snapshot request to all pre-connected peers on start (@erikgrinaker)
- [light] [\#5307](https://github.com/tendermint/tendermint/pull/5307) Persist correct proposer priority in light client validator sets (@cmwaters)

View File

@@ -254,6 +254,10 @@ func (r *Reactor) Sync(stateProvider StateProvider) (sm.State, *types.Commit, er
r.syncer = newSyncer(r.Logger, r.conn, r.connQuery, stateProvider, r.tempDir)
r.mtx.Unlock()
// Request snapshots from all currently connected peers
r.Logger.Debug("Requesting snapshots from known peers")
r.Switch.Broadcast(SnapshotChannel, mustEncodeMsg(&ssproto.SnapshotsRequest{}))
state, commit, err := r.syncer.SyncAny(defaultDiscoveryTime)
r.mtx.Lock()
r.syncer = nil