mirror of
https://github.com/fluencelabs/tendermint
synced 2025-05-08 21:12:13 +00:00
change to int for max number of pending requests
This commit is contained in:
parent
7e5e167066
commit
bceb15e91a
@ -25,7 +25,7 @@ type bpPeer struct {
|
|||||||
ID p2p.ID
|
ID p2p.ID
|
||||||
|
|
||||||
Height int64 // the peer reported height
|
Height int64 // the peer reported height
|
||||||
NumPendingBlockRequests int32 // number of requests still waiting for block responses
|
NumPendingBlockRequests int // number of requests still waiting for block responses
|
||||||
blocks map[int64]*types.Block // blocks received or expected to be received from this peer
|
blocks map[int64]*types.Block // blocks received or expected to be received from this peer
|
||||||
blockResponseTimer *time.Timer
|
blockResponseTimer *time.Timer
|
||||||
recvMonitor *flow.Monitor
|
recvMonitor *flow.Monitor
|
||||||
@ -70,7 +70,7 @@ func (peer *bpPeer) Cleanup() {
|
|||||||
if peer.NumPendingBlockRequests != 0 {
|
if peer.NumPendingBlockRequests != 0 {
|
||||||
peer.logger.Info("peer with pending requests is being cleaned")
|
peer.logger.Info("peer with pending requests is being cleaned")
|
||||||
}
|
}
|
||||||
if int32(len(peer.blocks))-peer.NumPendingBlockRequests != 0 {
|
if len(peer.blocks)-peer.NumPendingBlockRequests != 0 {
|
||||||
peer.logger.Info("peer with pending blocks is being cleaned")
|
peer.logger.Info("peer with pending blocks is being cleaned")
|
||||||
}
|
}
|
||||||
for h := range peer.blocks {
|
for h := range peer.blocks {
|
||||||
|
@ -84,12 +84,12 @@ func TestPeerRequestSent(t *testing.T) {
|
|||||||
peer.RequestSent(1)
|
peer.RequestSent(1)
|
||||||
assert.NotNil(t, peer.recvMonitor)
|
assert.NotNil(t, peer.recvMonitor)
|
||||||
assert.NotNil(t, peer.blockResponseTimer)
|
assert.NotNil(t, peer.blockResponseTimer)
|
||||||
assert.Equal(t, int32(1), peer.NumPendingBlockRequests)
|
assert.Equal(t, 1, peer.NumPendingBlockRequests)
|
||||||
|
|
||||||
peer.RequestSent(1)
|
peer.RequestSent(1)
|
||||||
assert.NotNil(t, peer.recvMonitor)
|
assert.NotNil(t, peer.recvMonitor)
|
||||||
assert.NotNil(t, peer.blockResponseTimer)
|
assert.NotNil(t, peer.blockResponseTimer)
|
||||||
assert.Equal(t, int32(2), peer.NumPendingBlockRequests)
|
assert.Equal(t, 2, peer.NumPendingBlockRequests)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPeerGetAndRemoveBlock(t *testing.T) {
|
func TestPeerGetAndRemoveBlock(t *testing.T) {
|
||||||
|
@ -168,7 +168,7 @@ func (pool *blockPool) removeBadPeers() {
|
|||||||
|
|
||||||
// Makes a batch of requests sorted by height up to a specified maximum.
|
// Makes a batch of requests sorted by height up to a specified maximum.
|
||||||
// The parameter 'maxNumRequests' includes the number of block requests already made.
|
// The parameter 'maxNumRequests' includes the number of block requests already made.
|
||||||
func (pool *blockPool) makeRequestBatch(maxNumRequests int32) []int {
|
func (pool *blockPool) makeRequestBatch(maxNumRequests int) []int {
|
||||||
pool.removeBadPeers()
|
pool.removeBadPeers()
|
||||||
// At this point pool.requests may include heights for requests to be redone due to removal of peers:
|
// At this point pool.requests may include heights for requests to be redone due to removal of peers:
|
||||||
// - peers timed out or were removed by switch
|
// - peers timed out or were removed by switch
|
||||||
@ -191,7 +191,7 @@ func (pool *blockPool) makeRequestBatch(maxNumRequests int32) []int {
|
|||||||
return heights
|
return heights
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pool *blockPool) MakeNextRequests(maxNumRequests int32) {
|
func (pool *blockPool) MakeNextRequests(maxNumRequests int) {
|
||||||
heights := pool.makeRequestBatch(maxNumRequests)
|
heights := pool.makeRequestBatch(maxNumRequests)
|
||||||
pool.logger.Info("makeNextRequests will make following requests", "number", len(heights), "heights", heights)
|
pool.logger.Info("makeNextRequests will make following requests", "number", len(heights), "heights", heights)
|
||||||
|
|
||||||
@ -208,7 +208,7 @@ func (pool *blockPool) MakeNextRequests(maxNumRequests int32) {
|
|||||||
|
|
||||||
func (pool *blockPool) sendRequest(height int64) bool {
|
func (pool *blockPool) sendRequest(height int64) bool {
|
||||||
for _, peer := range pool.peers {
|
for _, peer := range pool.peers {
|
||||||
if peer.NumPendingBlockRequests >= int32(maxRequestsPerPeer) {
|
if peer.NumPendingBlockRequests >= maxRequestsPerPeer {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if peer.Height < height {
|
if peer.Height < height {
|
||||||
|
@ -21,7 +21,7 @@ type testBcR struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type testValues struct {
|
type testValues struct {
|
||||||
numRequestsSent int32
|
numRequestsSent int
|
||||||
}
|
}
|
||||||
|
|
||||||
var testResults testValues
|
var testResults testValues
|
||||||
@ -283,7 +283,7 @@ func TestBlockPoolRemoveShortPeers(t *testing.T) {
|
|||||||
func TestBlockPoolSendRequestBatch(t *testing.T) {
|
func TestBlockPoolSendRequestBatch(t *testing.T) {
|
||||||
type testPeerResult struct {
|
type testPeerResult struct {
|
||||||
id p2p.ID
|
id p2p.ID
|
||||||
numPendingBlockRequests int32
|
numPendingBlockRequests int
|
||||||
}
|
}
|
||||||
|
|
||||||
testBcR := newTestBcR()
|
testBcR := newTestBcR()
|
||||||
@ -291,10 +291,10 @@ func TestBlockPoolSendRequestBatch(t *testing.T) {
|
|||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
pool *blockPool
|
pool *blockPool
|
||||||
maxRequestsPerPeer int32
|
maxRequestsPerPeer int
|
||||||
expRequests map[int64]bool
|
expRequests map[int64]bool
|
||||||
expPeerResults []testPeerResult
|
expPeerResults []testPeerResult
|
||||||
expnumPendingBlockRequests int32
|
expnumPendingBlockRequests int
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "one peer - send up to maxRequestsPerPeer block requests",
|
name: "one peer - send up to maxRequestsPerPeer block requests",
|
||||||
@ -321,16 +321,16 @@ func TestBlockPoolSendRequestBatch(t *testing.T) {
|
|||||||
resetPoolTestResults()
|
resetPoolTestResults()
|
||||||
|
|
||||||
var pool = tt.pool
|
var pool = tt.pool
|
||||||
maxRequestsPerPeer = int32(tt.maxRequestsPerPeer)
|
maxRequestsPerPeer = tt.maxRequestsPerPeer
|
||||||
pool.MakeNextRequests(10)
|
pool.MakeNextRequests(10)
|
||||||
assert.Equal(t, testResults.numRequestsSent, maxRequestsPerPeer*int32(len(pool.peers)))
|
assert.Equal(t, testResults.numRequestsSent, maxRequestsPerPeer*len(pool.peers))
|
||||||
|
|
||||||
for _, tPeer := range tt.expPeerResults {
|
for _, tPeer := range tt.expPeerResults {
|
||||||
var peer = pool.peers[tPeer.id]
|
var peer = pool.peers[tPeer.id]
|
||||||
assert.NotNil(t, peer)
|
assert.NotNil(t, peer)
|
||||||
assert.Equal(t, tPeer.numPendingBlockRequests, peer.NumPendingBlockRequests)
|
assert.Equal(t, tPeer.numPendingBlockRequests, peer.NumPendingBlockRequests)
|
||||||
}
|
}
|
||||||
assert.Equal(t, testResults.numRequestsSent, maxRequestsPerPeer*int32(len(pool.peers)))
|
assert.Equal(t, testResults.numRequestsSent, maxRequestsPerPeer*len(pool.peers))
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -35,9 +35,9 @@ const (
|
|||||||
var (
|
var (
|
||||||
// Maximum number of requests that can be pending per peer, i.e. for which requests have been sent but blocks
|
// Maximum number of requests that can be pending per peer, i.e. for which requests have been sent but blocks
|
||||||
// have not been received.
|
// have not been received.
|
||||||
maxRequestsPerPeer int32 = 20
|
maxRequestsPerPeer int = 20
|
||||||
// Maximum number of block requests for the reactor, pending or for which blocks have been received.
|
// Maximum number of block requests for the reactor, pending or for which blocks have been received.
|
||||||
maxNumRequests int32 = 64
|
maxNumRequests int = 64
|
||||||
)
|
)
|
||||||
|
|
||||||
type consensusReactor interface {
|
type consensusReactor interface {
|
||||||
|
@ -61,7 +61,7 @@ type bReactorEventData struct {
|
|||||||
block *types.Block // for block response
|
block *types.Block // for block response
|
||||||
stateName string // for state timeout events
|
stateName string // for state timeout events
|
||||||
length int // for block response event, length of received block, used to detect slow peers
|
length int // for block response event, length of received block, used to detect slow peers
|
||||||
maxNumRequests int32 // for request needed event, maximum number of pending requests
|
maxNumRequests int // for request needed event, maximum number of pending requests
|
||||||
}
|
}
|
||||||
|
|
||||||
// Blockchain Reactor Events (the input to the state machine)
|
// Blockchain Reactor Events (the input to the state machine)
|
||||||
@ -405,7 +405,7 @@ func (fsm *bReactorFSM) isCaughtUp() bool {
|
|||||||
return fsm.state == finished
|
return fsm.state == finished
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fsm *bReactorFSM) makeNextRequests(maxNumRequests int32) {
|
func (fsm *bReactorFSM) makeNextRequests(maxNumRequests int) {
|
||||||
fsm.pool.MakeNextRequests(maxNumRequests)
|
fsm.pool.MakeNextRequests(maxNumRequests)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ type testReactor struct {
|
|||||||
logger log.Logger
|
logger log.Logger
|
||||||
fsm *bReactorFSM
|
fsm *bReactorFSM
|
||||||
numStatusRequests int
|
numStatusRequests int
|
||||||
numBlockRequests int32
|
numBlockRequests int
|
||||||
lastBlockRequest lastBlockRequestT
|
lastBlockRequest lastBlockRequestT
|
||||||
lastPeerError lastPeerErrorT
|
lastPeerError lastPeerErrorT
|
||||||
stateTimerStarts map[string]int
|
stateTimerStarts map[string]int
|
||||||
@ -109,7 +109,7 @@ func makeStepStatusEv(current, expected string, peerID p2p.ID, height int64, err
|
|||||||
errWanted: err}
|
errWanted: err}
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeStepMakeRequestsEv(current, expected string, maxPendingRequests int32) fsmStepTestValues {
|
func makeStepMakeRequestsEv(current, expected string, maxPendingRequests int) fsmStepTestValues {
|
||||||
return fsmStepTestValues{
|
return fsmStepTestValues{
|
||||||
currentState: current,
|
currentState: current,
|
||||||
event: makeRequestsEv,
|
event: makeRequestsEv,
|
||||||
@ -120,7 +120,7 @@ func makeStepMakeRequestsEv(current, expected string, maxPendingRequests int32)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func makeStepMakeRequestsEvErrored(current, expected string,
|
func makeStepMakeRequestsEvErrored(current, expected string,
|
||||||
maxPendingRequests int32, err error, peersRemoved []p2p.ID) fsmStepTestValues {
|
maxPendingRequests int, err error, peersRemoved []p2p.ID) fsmStepTestValues {
|
||||||
return fsmStepTestValues{
|
return fsmStepTestValues{
|
||||||
currentState: current,
|
currentState: current,
|
||||||
event: makeRequestsEv,
|
event: makeRequestsEv,
|
||||||
@ -204,8 +204,8 @@ func fixBlockResponseEvStep(step *fsmStepTestValues, testBcR *testReactor) {
|
|||||||
type testFields struct {
|
type testFields struct {
|
||||||
name string
|
name string
|
||||||
startingHeight int64
|
startingHeight int64
|
||||||
maxRequestsPerPeer int32
|
maxRequestsPerPeer int
|
||||||
maxPendingRequests int32
|
maxPendingRequests int
|
||||||
steps []fsmStepTestValues
|
steps []fsmStepTestValues
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -785,7 +785,7 @@ func TestFSMPeerStateTimeoutEvent(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func makeCorrectTransitionSequence(startingHeight int64, numBlocks int64, numPeers int, randomPeerHeights bool,
|
func makeCorrectTransitionSequence(startingHeight int64, numBlocks int64, numPeers int, randomPeerHeights bool,
|
||||||
maxRequestsPerPeer int32, maxPendingRequests int32) testFields {
|
maxRequestsPerPeer int, maxPendingRequests int) testFields {
|
||||||
|
|
||||||
// Generate numPeers peers with random or numBlocks heights according to the randomPeerHeights flag.
|
// Generate numPeers peers with random or numBlocks heights according to the randomPeerHeights flag.
|
||||||
peerHeights := make([]int64, numPeers)
|
peerHeights := make([]int64, numPeers)
|
||||||
@ -888,10 +888,10 @@ func makeCorrectTransitionSequenceWithRandomParameters() testFields {
|
|||||||
startingHeight := int64(cmn.RandIntn(maxStartingHeightTest) + 1)
|
startingHeight := int64(cmn.RandIntn(maxStartingHeightTest) + 1)
|
||||||
|
|
||||||
// Generate the number of requests per peer.
|
// Generate the number of requests per peer.
|
||||||
maxRequestsPerPeer := int32(cmn.RandIntn(maxRequestsPerPeerTest) + 1)
|
maxRequestsPerPeer := cmn.RandIntn(maxRequestsPerPeerTest) + 1
|
||||||
|
|
||||||
// Generate the maximum number of total pending requests, >= maxRequestsPerPeer.
|
// Generate the maximum number of total pending requests, >= maxRequestsPerPeer.
|
||||||
maxPendingRequests := int32(cmn.RandIntn(maxTotalPendingRequestsTest-int(maxRequestsPerPeer))) + maxRequestsPerPeer
|
maxPendingRequests := cmn.RandIntn(maxTotalPendingRequestsTest-int(maxRequestsPerPeer)) + maxRequestsPerPeer
|
||||||
|
|
||||||
// Generate the number of blocks to be synced.
|
// Generate the number of blocks to be synced.
|
||||||
numBlocks := int64(cmn.RandIntn(maxNumBlocksInChainTest)) + startingHeight
|
numBlocks := int64(cmn.RandIntn(maxNumBlocksInChainTest)) + startingHeight
|
||||||
|
Loading…
x
Reference in New Issue
Block a user