From 0bbf38141a6498f661d6c956c9f45066c312d90e Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Fri, 20 Oct 2017 21:19:25 -0400 Subject: [PATCH] blockchain/pool: some comments and small changes --- blockchain/pool.go | 23 ++++++++++++++++++++--- blockchain/reactor.go | 4 ++-- p2p/pex_reactor.go | 1 + 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/blockchain/pool.go b/blockchain/pool.go index aac4c77c3..348ba09b3 100644 --- a/blockchain/pool.go +++ b/blockchain/pool.go @@ -11,11 +11,25 @@ import ( "github.com/tendermint/tmlibs/log" ) +/* + +eg, L = latency = 0.1s + P = num peers = 10 + FN = num full nodes + BS = 1kB block size + CB = 1 Mbit/s = 128 kB/s + CB/P = 12.8 kB + B/S = CB/P/BS = 12.8 blocks/s + + 12.8 * 0.1 = 1.28 blocks on conn + +*/ + const ( requestIntervalMS = 250 maxTotalRequesters = 300 maxPendingRequests = maxTotalRequesters - maxPendingRequestsPerPeer = 75 + maxPendingRequestsPerPeer = 10 minRecvRate = 10240 // 10Kb/s ) @@ -186,15 +200,16 @@ func (pool *BlockPool) PopRequest() { // Remove the peer and redo request from others. func (pool *BlockPool) RedoRequest(height int) { pool.mtx.Lock() + defer pool.mtx.Unlock() + request := pool.requesters[height] - pool.mtx.Unlock() if request.block == nil { cmn.PanicSanity("Expected block to be non-nil") } // RemovePeer will redo all requesters associated with this peer. // TODO: record this malfeasance - pool.RemovePeer(request.peerID) + pool.removePeer(request.peerID) } // TODO: ensure that blocks come in order for each peer. @@ -204,6 +219,8 @@ func (pool *BlockPool) AddBlock(peerID string, block *types.Block, blockSize int requester := pool.requesters[block.Height] if requester == nil { + // a block we didn't expect. + // TODO:if height is too far ahead, punish peer return } diff --git a/blockchain/reactor.go b/blockchain/reactor.go index 6ff010038..b46ad40fa 100644 --- a/blockchain/reactor.go +++ b/blockchain/reactor.go @@ -221,9 +221,9 @@ FOR_LOOP: // ask for status updates go bcR.BroadcastStatusRequest() case <-switchToConsensusTicker.C: - height, numPending, _ := bcR.pool.GetStatus() + height, numPending, lenRequesters := bcR.pool.GetStatus() outbound, inbound, _ := bcR.Switch.NumPeers() - bcR.Logger.Info("Consensus ticker", "numPending", numPending, "total", len(bcR.pool.requesters), + bcR.Logger.Info("Consensus ticker", "numPending", numPending, "total", lenRequesters, "outbound", outbound, "inbound", inbound) if bcR.pool.IsCaughtUp() { bcR.Logger.Info("Time to switch to consensus reactor!", "height", height) diff --git a/p2p/pex_reactor.go b/p2p/pex_reactor.go index 69ab55cc9..54c2d06b5 100644 --- a/p2p/pex_reactor.go +++ b/p2p/pex_reactor.go @@ -139,6 +139,7 @@ func (r *PEXReactor) Receive(chID byte, src Peer, msgBytes []byte) { switch msg := msg.(type) { case *pexRequestMessage: // src requested some peers. + // NOTE: we might send an empty selection r.SendAddrs(src, r.book.GetSelection()) case *pexAddrsMessage: // We received some peer addresses from src.