You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

415 lines
12 KiB

cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
blockchain: Reorg reactor (#3561) * go routines in blockchain reactor * Added reference to the go routine diagram * Initial commit * cleanup * Undo testing_logger change, committed by mistake * Fix the test loggers * pulled some fsm code into pool.go * added pool tests * changes to the design added block requests under peer moved the request trigger in the reactor poolRoutine, triggered now by a ticker in general moved everything required for making block requests smarter in the poolRoutine added a simple map of heights to keep track of what will need to be requested next added a few more tests * send errors to FSM in a different channel than blocks send errors (RemovePeer) from switch on a different channel than the one receiving blocks renamed channels added more pool tests * more pool tests * lint errors * more tests * more tests * switch fast sync to new implementation * fixed data race in tests * cleanup * finished fsm tests * address golangci comments :) * address golangci comments :) * Added timeout on next block needed to advance * updating docs and cleanup * fix issue in test from previous cleanup * cleanup * Added termination scenarios, tests and more cleanup * small fixes to adr, comments and cleanup * Fix bug in sendRequest() If we tried to send a request to a peer not present in the switch, a missing continue statement caused the request to be blackholed in a peer that was removed and never retried. While this bug was manifesting, the reactor kept asking for other blocks that would be stored and never consumed. Added the number of unconsumed blocks in the math for requesting blocks ahead of current processing height so eventually there will be no more blocks requested until the already received ones are consumed. * remove bpPeer's didTimeout field * Use distinct err codes for peer timeout and FSM timeouts * Don't allow peers to update with lower height * review comments from Ethan and Zarko * some cleanup, renaming, comments * Move block execution in separate goroutine * Remove pool's numPending * review comments * fix lint, remove old blockchain reactor and duplicates in fsm tests * small reorg around peer after review comments * add the reactor spec * verify block only once * review comments * change to int for max number of pending requests * cleanup and godoc * Add configuration flag fast sync version * golangci fixes * fix config template * move both reactor versions under blockchain * cleanup, golint, renaming stuff * updated documentation, fixed more golint warnings * integrate with behavior package * sync with master * gofmt * add changelog_pending entry * move to improvments * suggestion to changelog entry
5 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
  1. package blocksync
  2. import (
  3. "context"
  4. "os"
  5. "testing"
  6. "time"
  7. "github.com/fortytw2/leaktest"
  8. "github.com/stretchr/testify/mock"
  9. "github.com/stretchr/testify/require"
  10. dbm "github.com/tendermint/tm-db"
  11. abciclient "github.com/tendermint/tendermint/abci/client"
  12. abci "github.com/tendermint/tendermint/abci/types"
  13. "github.com/tendermint/tendermint/config"
  14. "github.com/tendermint/tendermint/internal/consensus"
  15. "github.com/tendermint/tendermint/internal/eventbus"
  16. mpmocks "github.com/tendermint/tendermint/internal/mempool/mocks"
  17. "github.com/tendermint/tendermint/internal/p2p"
  18. "github.com/tendermint/tendermint/internal/p2p/p2ptest"
  19. "github.com/tendermint/tendermint/internal/proxy"
  20. sm "github.com/tendermint/tendermint/internal/state"
  21. sf "github.com/tendermint/tendermint/internal/state/test/factory"
  22. "github.com/tendermint/tendermint/internal/store"
  23. "github.com/tendermint/tendermint/internal/test/factory"
  24. "github.com/tendermint/tendermint/libs/log"
  25. bcproto "github.com/tendermint/tendermint/proto/tendermint/blocksync"
  26. "github.com/tendermint/tendermint/types"
  27. )
  28. type reactorTestSuite struct {
  29. network *p2ptest.Network
  30. logger log.Logger
  31. nodes []types.NodeID
  32. reactors map[types.NodeID]*Reactor
  33. app map[types.NodeID]abciclient.Client
  34. blockSyncChannels map[types.NodeID]*p2p.Channel
  35. peerChans map[types.NodeID]chan p2p.PeerUpdate
  36. peerUpdates map[types.NodeID]*p2p.PeerUpdates
  37. blockSync bool
  38. }
  39. func setup(
  40. ctx context.Context,
  41. t *testing.T,
  42. genDoc *types.GenesisDoc,
  43. privVal types.PrivValidator,
  44. maxBlockHeights []int64,
  45. chBuf uint,
  46. ) *reactorTestSuite {
  47. t.Helper()
  48. var cancel context.CancelFunc
  49. ctx, cancel = context.WithCancel(ctx)
  50. numNodes := len(maxBlockHeights)
  51. require.True(t, numNodes >= 1,
  52. "must specify at least one block height (nodes)")
  53. rts := &reactorTestSuite{
  54. logger: log.NewNopLogger().With("module", "block_sync", "testCase", t.Name()),
  55. network: p2ptest.MakeNetwork(ctx, t, p2ptest.NetworkOptions{NumNodes: numNodes}),
  56. nodes: make([]types.NodeID, 0, numNodes),
  57. reactors: make(map[types.NodeID]*Reactor, numNodes),
  58. app: make(map[types.NodeID]abciclient.Client, numNodes),
  59. blockSyncChannels: make(map[types.NodeID]*p2p.Channel, numNodes),
  60. peerChans: make(map[types.NodeID]chan p2p.PeerUpdate, numNodes),
  61. peerUpdates: make(map[types.NodeID]*p2p.PeerUpdates, numNodes),
  62. blockSync: true,
  63. }
  64. chDesc := &p2p.ChannelDescriptor{ID: BlockSyncChannel, MessageType: new(bcproto.Message)}
  65. rts.blockSyncChannels = rts.network.MakeChannelsNoCleanup(ctx, t, chDesc)
  66. i := 0
  67. for nodeID := range rts.network.Nodes {
  68. rts.addNode(ctx, t, nodeID, genDoc, privVal, maxBlockHeights[i])
  69. i++
  70. }
  71. t.Cleanup(func() {
  72. cancel()
  73. for _, nodeID := range rts.nodes {
  74. if rts.reactors[nodeID].IsRunning() {
  75. rts.reactors[nodeID].Wait()
  76. rts.app[nodeID].Wait()
  77. require.False(t, rts.reactors[nodeID].IsRunning())
  78. }
  79. }
  80. })
  81. t.Cleanup(leaktest.Check(t))
  82. return rts
  83. }
  84. func (rts *reactorTestSuite) addNode(
  85. ctx context.Context,
  86. t *testing.T,
  87. nodeID types.NodeID,
  88. genDoc *types.GenesisDoc,
  89. privVal types.PrivValidator,
  90. maxBlockHeight int64,
  91. ) {
  92. t.Helper()
  93. logger := log.NewNopLogger()
  94. rts.nodes = append(rts.nodes, nodeID)
  95. rts.app[nodeID] = proxy.New(abciclient.NewLocalClient(logger, &abci.BaseApplication{}), logger, proxy.NopMetrics())
  96. require.NoError(t, rts.app[nodeID].Start(ctx))
  97. blockDB := dbm.NewMemDB()
  98. stateDB := dbm.NewMemDB()
  99. stateStore := sm.NewStore(stateDB)
  100. blockStore := store.NewBlockStore(blockDB)
  101. state, err := sm.MakeGenesisState(genDoc)
  102. require.NoError(t, err)
  103. require.NoError(t, stateStore.Save(state))
  104. mp := &mpmocks.Mempool{}
  105. mp.On("Lock").Return()
  106. mp.On("Unlock").Return()
  107. mp.On("FlushAppConn", mock.Anything).Return(nil)
  108. mp.On("Update",
  109. mock.Anything,
  110. mock.Anything,
  111. mock.Anything,
  112. mock.Anything,
  113. mock.Anything,
  114. mock.Anything).Return(nil)
  115. eventbus := eventbus.NewDefault(logger)
  116. require.NoError(t, eventbus.Start(ctx))
  117. blockExec := sm.NewBlockExecutor(
  118. stateStore,
  119. log.NewNopLogger(),
  120. rts.app[nodeID],
  121. mp,
  122. sm.EmptyEvidencePool{},
  123. blockStore,
  124. eventbus,
  125. )
  126. for blockHeight := int64(1); blockHeight <= maxBlockHeight; blockHeight++ {
  127. lastCommit := types.NewCommit(blockHeight-1, 0, types.BlockID{}, nil)
  128. if blockHeight > 1 {
  129. lastBlockMeta := blockStore.LoadBlockMeta(blockHeight - 1)
  130. lastBlock := blockStore.LoadBlock(blockHeight - 1)
  131. vote, err := factory.MakeVote(
  132. ctx,
  133. privVal,
  134. lastBlock.Header.ChainID, 0,
  135. lastBlock.Header.Height, 0, 2,
  136. lastBlockMeta.BlockID,
  137. time.Now(),
  138. )
  139. require.NoError(t, err)
  140. lastCommit = types.NewCommit(
  141. vote.Height,
  142. vote.Round,
  143. lastBlockMeta.BlockID,
  144. []types.CommitSig{vote.CommitSig()},
  145. )
  146. }
  147. thisBlock := sf.MakeBlock(state, blockHeight, lastCommit)
  148. thisParts, err := thisBlock.MakePartSet(types.BlockPartSizeBytes)
  149. require.NoError(t, err)
  150. blockID := types.BlockID{Hash: thisBlock.Hash(), PartSetHeader: thisParts.Header()}
  151. state, err = blockExec.ApplyBlock(ctx, state, blockID, thisBlock)
  152. require.NoError(t, err)
  153. blockStore.SaveBlock(thisBlock, thisParts, lastCommit)
  154. }
  155. rts.peerChans[nodeID] = make(chan p2p.PeerUpdate)
  156. rts.peerUpdates[nodeID] = p2p.NewPeerUpdates(rts.peerChans[nodeID], 1)
  157. rts.network.Nodes[nodeID].PeerManager.Register(ctx, rts.peerUpdates[nodeID])
  158. chCreator := func(ctx context.Context, chdesc *p2p.ChannelDescriptor) (*p2p.Channel, error) {
  159. return rts.blockSyncChannels[nodeID], nil
  160. }
  161. rts.reactors[nodeID], err = NewReactor(
  162. ctx,
  163. rts.logger.With("nodeID", nodeID),
  164. stateStore,
  165. blockExec,
  166. blockStore,
  167. nil,
  168. chCreator,
  169. rts.peerUpdates[nodeID],
  170. rts.blockSync,
  171. consensus.NopMetrics(),
  172. nil, // eventbus, can be nil
  173. )
  174. require.NoError(t, err)
  175. require.NoError(t, rts.reactors[nodeID].Start(ctx))
  176. require.True(t, rts.reactors[nodeID].IsRunning())
  177. }
  178. func (rts *reactorTestSuite) start(ctx context.Context, t *testing.T) {
  179. t.Helper()
  180. rts.network.Start(ctx, t)
  181. require.Len(t,
  182. rts.network.RandomNode().PeerManager.Peers(),
  183. len(rts.nodes)-1,
  184. "network does not have expected number of nodes")
  185. }
  186. func TestReactor_AbruptDisconnect(t *testing.T) {
  187. ctx, cancel := context.WithCancel(context.Background())
  188. defer cancel()
  189. cfg, err := config.ResetTestRoot(t.TempDir(), "block_sync_reactor_test")
  190. require.NoError(t, err)
  191. defer os.RemoveAll(cfg.RootDir)
  192. valSet, privVals := factory.ValidatorSet(ctx, t, 1, 30)
  193. genDoc := factory.GenesisDoc(cfg, time.Now(), valSet.Validators, factory.ConsensusParams())
  194. maxBlockHeight := int64(64)
  195. rts := setup(ctx, t, genDoc, privVals[0], []int64{maxBlockHeight, 0}, 0)
  196. require.Equal(t, maxBlockHeight, rts.reactors[rts.nodes[0]].store.Height())
  197. rts.start(ctx, t)
  198. secondaryPool := rts.reactors[rts.nodes[1]].pool
  199. require.Eventually(
  200. t,
  201. func() bool {
  202. height, _, _ := secondaryPool.GetStatus()
  203. return secondaryPool.MaxPeerHeight() > 0 && height > 0 && height < 10
  204. },
  205. 10*time.Second,
  206. 10*time.Millisecond,
  207. "expected node to be partially synced",
  208. )
  209. // Remove synced node from the syncing node which should not result in any
  210. // deadlocks or race conditions within the context of poolRoutine.
  211. rts.peerChans[rts.nodes[1]] <- p2p.PeerUpdate{
  212. Status: p2p.PeerStatusDown,
  213. NodeID: rts.nodes[0],
  214. }
  215. rts.network.Nodes[rts.nodes[1]].PeerManager.Disconnected(ctx, rts.nodes[0])
  216. }
  217. func TestReactor_SyncTime(t *testing.T) {
  218. ctx, cancel := context.WithCancel(context.Background())
  219. defer cancel()
  220. cfg, err := config.ResetTestRoot(t.TempDir(), "block_sync_reactor_test")
  221. require.NoError(t, err)
  222. defer os.RemoveAll(cfg.RootDir)
  223. valSet, privVals := factory.ValidatorSet(ctx, t, 1, 30)
  224. genDoc := factory.GenesisDoc(cfg, time.Now(), valSet.Validators, factory.ConsensusParams())
  225. maxBlockHeight := int64(101)
  226. rts := setup(ctx, t, genDoc, privVals[0], []int64{maxBlockHeight, 0}, 0)
  227. require.Equal(t, maxBlockHeight, rts.reactors[rts.nodes[0]].store.Height())
  228. rts.start(ctx, t)
  229. require.Eventually(
  230. t,
  231. func() bool {
  232. return rts.reactors[rts.nodes[1]].GetRemainingSyncTime() > time.Nanosecond &&
  233. rts.reactors[rts.nodes[1]].pool.getLastSyncRate() > 0.001
  234. },
  235. 10*time.Second,
  236. 10*time.Millisecond,
  237. "expected node to be partially synced",
  238. )
  239. }
  240. func TestReactor_NoBlockResponse(t *testing.T) {
  241. ctx, cancel := context.WithCancel(context.Background())
  242. defer cancel()
  243. cfg, err := config.ResetTestRoot(t.TempDir(), "block_sync_reactor_test")
  244. require.NoError(t, err)
  245. defer os.RemoveAll(cfg.RootDir)
  246. valSet, privVals := factory.ValidatorSet(ctx, t, 1, 30)
  247. genDoc := factory.GenesisDoc(cfg, time.Now(), valSet.Validators, factory.ConsensusParams())
  248. maxBlockHeight := int64(65)
  249. rts := setup(ctx, t, genDoc, privVals[0], []int64{maxBlockHeight, 0}, 0)
  250. require.Equal(t, maxBlockHeight, rts.reactors[rts.nodes[0]].store.Height())
  251. rts.start(ctx, t)
  252. testCases := []struct {
  253. height int64
  254. existent bool
  255. }{
  256. {maxBlockHeight + 2, false},
  257. {10, true},
  258. {1, true},
  259. {100, false},
  260. }
  261. secondaryPool := rts.reactors[rts.nodes[1]].pool
  262. require.Eventually(
  263. t,
  264. func() bool { return secondaryPool.MaxPeerHeight() > 0 && secondaryPool.IsCaughtUp() },
  265. 10*time.Second,
  266. 10*time.Millisecond,
  267. "expected node to be fully synced",
  268. )
  269. for _, tc := range testCases {
  270. block := rts.reactors[rts.nodes[1]].store.LoadBlock(tc.height)
  271. if tc.existent {
  272. require.True(t, block != nil)
  273. } else {
  274. require.Nil(t, block)
  275. }
  276. }
  277. }
  278. func TestReactor_BadBlockStopsPeer(t *testing.T) {
  279. // Ultimately, this should be refactored to be less integration test oriented
  280. // and more unit test oriented by simply testing channel sends and receives.
  281. // See: https://github.com/tendermint/tendermint/issues/6005
  282. t.SkipNow()
  283. ctx, cancel := context.WithCancel(context.Background())
  284. defer cancel()
  285. cfg, err := config.ResetTestRoot(t.TempDir(), "block_sync_reactor_test")
  286. require.NoError(t, err)
  287. defer os.RemoveAll(cfg.RootDir)
  288. maxBlockHeight := int64(48)
  289. valSet, privVals := factory.ValidatorSet(ctx, t, 1, 30)
  290. genDoc := factory.GenesisDoc(cfg, time.Now(), valSet.Validators, factory.ConsensusParams())
  291. rts := setup(ctx, t, genDoc, privVals[0], []int64{maxBlockHeight, 0, 0, 0, 0}, 1000)
  292. require.Equal(t, maxBlockHeight, rts.reactors[rts.nodes[0]].store.Height())
  293. rts.start(ctx, t)
  294. require.Eventually(
  295. t,
  296. func() bool {
  297. caughtUp := true
  298. for _, id := range rts.nodes[1 : len(rts.nodes)-1] {
  299. if rts.reactors[id].pool.MaxPeerHeight() == 0 || !rts.reactors[id].pool.IsCaughtUp() {
  300. caughtUp = false
  301. }
  302. }
  303. return caughtUp
  304. },
  305. 10*time.Minute,
  306. 10*time.Millisecond,
  307. "expected all nodes to be fully synced",
  308. )
  309. for _, id := range rts.nodes[:len(rts.nodes)-1] {
  310. require.Len(t, rts.reactors[id].pool.peers, 3)
  311. }
  312. // Mark testSuites[3] as an invalid peer which will cause newSuite to disconnect
  313. // from this peer.
  314. //
  315. // XXX: This causes a potential race condition.
  316. // See: https://github.com/tendermint/tendermint/issues/6005
  317. valSet, otherPrivVals := factory.ValidatorSet(ctx, t, 1, 30)
  318. otherGenDoc := factory.GenesisDoc(cfg, time.Now(), valSet.Validators, factory.ConsensusParams())
  319. newNode := rts.network.MakeNode(ctx, t, p2ptest.NodeOptions{
  320. MaxPeers: uint16(len(rts.nodes) + 1),
  321. MaxConnected: uint16(len(rts.nodes) + 1),
  322. })
  323. rts.addNode(ctx, t, newNode.NodeID, otherGenDoc, otherPrivVals[0], maxBlockHeight)
  324. // add a fake peer just so we do not wait for the consensus ticker to timeout
  325. rts.reactors[newNode.NodeID].pool.SetPeerRange("00ff", 10, 10)
  326. // wait for the new peer to catch up and become fully synced
  327. require.Eventually(
  328. t,
  329. func() bool {
  330. return rts.reactors[newNode.NodeID].pool.MaxPeerHeight() > 0 && rts.reactors[newNode.NodeID].pool.IsCaughtUp()
  331. },
  332. 10*time.Minute,
  333. 10*time.Millisecond,
  334. "expected new node to be fully synced",
  335. )
  336. require.Eventuallyf(
  337. t,
  338. func() bool { return len(rts.reactors[newNode.NodeID].pool.peers) < len(rts.nodes)-1 },
  339. 10*time.Minute,
  340. 10*time.Millisecond,
  341. "invalid number of peers; expected < %d, got: %d",
  342. len(rts.nodes)-1,
  343. len(rts.reactors[newNode.NodeID].pool.peers),
  344. )
  345. }