Skip to content

Commit 1d7076a

Browse files
author
Nicolás Tallar
authored
[ETCM-415] Fix random subset of peers where block is broadcasted; removed unnecesary broadcast-new-block-hashes config (#814)
1 parent 0bcd288 commit 1d7076a

File tree

5 files changed

+2
-26
lines changed

5 files changed

+2
-26
lines changed

src/main/resources/application.conf

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,10 +388,6 @@ mantis {
388388
# Maximum number of hashes processed form NewBlockHashes packet
389389
max-new-hashes = 64
390390

391-
# Set to false to disable broadcasting the NewBlockHashes message, as its usefulness is debatable,
392-
# especially in the context of private networks
393-
broadcast-new-block-hashes = true
394-
395391
# This a recovery mechanism for the issue of missing state nodes during blocks execution:
396392
# off - missing state node will result in an exception
397393
# on - missing state node will be redownloaded from a peer and block execution will be retried. This can repeat

src/main/scala/io/iohk/ethereum/blockchain/sync/regular/BlockBroadcast.scala

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ class BlockBroadcast(val etcPeerManager: ActorRef, syncConfig: SyncConfig) {
2828

2929
broadcastNewBlock(newBlock, peersWithoutBlock)
3030

31-
if (syncConfig.broadcastNewBlockHashes) {
32-
// NOTE: the usefulness of this message is debatable, especially in private networks
33-
broadcastNewBlockHash(newBlock, peersWithoutBlock)
34-
}
31+
broadcastNewBlockHash(newBlock, peersWithoutBlock)
3532
}
3633

3734
private def shouldSendNewBlock(newBlock: NewBlock, peerInfo: PeerInfo): Boolean =
@@ -58,6 +55,6 @@ class BlockBroadcast(val etcPeerManager: ActorRef, syncConfig: SyncConfig) {
5855
*/
5956
private[sync] def obtainRandomPeerSubset(peers: Set[Peer]): Set[Peer] = {
6057
val numberOfPeersToSend = Math.sqrt(peers.size).toInt
61-
Random.shuffle(peers).take(numberOfPeersToSend)
58+
Random.shuffle(peers.toSeq).take(numberOfPeersToSend).toSet
6259
}
6360
}

src/main/scala/io/iohk/ethereum/utils/Config.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ object Config {
116116
fastSyncThrottle: FiniteDuration,
117117
maxQueuedBlockNumberAhead: Int,
118118
maxQueuedBlockNumberBehind: Int,
119-
broadcastNewBlockHashes: Boolean,
120119
maxNewBlockHashAge: Int,
121120
maxNewHashes: Int,
122121
redownloadMissingStateNodes: Boolean,
@@ -161,7 +160,6 @@ object Config {
161160
maxQueuedBlockNumberAhead = syncConfig.getInt("max-queued-block-number-ahead"),
162161
maxNewBlockHashAge = syncConfig.getInt("max-new-block-hash-age"),
163162
maxNewHashes = syncConfig.getInt("max-new-hashes"),
164-
broadcastNewBlockHashes = syncConfig.getBoolean("broadcast-new-block-hashes"),
165163
redownloadMissingStateNodes = syncConfig.getBoolean("redownload-missing-state-nodes"),
166164
fastSyncBlockValidationK = syncConfig.getInt("fast-sync-block-validation-k"),
167165
fastSyncBlockValidationN = syncConfig.getInt("fast-sync-block-validation-n"),

src/test/scala/io/iohk/ethereum/blockchain/sync/BlockBroadcastSpec.scala

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import io.iohk.ethereum.network.p2p.messages.PV62.NewBlockHashes
1414
import io.iohk.ethereum.network.p2p.messages.{PV62, Versions}
1515
import io.iohk.ethereum.utils.Config
1616

17-
import scala.concurrent.duration._
1817
import org.scalatest.flatspec.AnyFlatSpecLike
1918
import org.scalatest.matchers.should.Matchers
2019

@@ -122,19 +121,6 @@ class BlockBroadcastSpec
122121
etcPeerManagerProbe.expectNoMessage()
123122
}
124123

125-
it should "not broadcast NewBlockHashes message when disable by configuration" in new TestSetup {
126-
val updatedConfig = syncConfig.copy(broadcastNewBlockHashes = false)
127-
override val blockBroadcast = new BlockBroadcast(etcPeerManagerProbe.ref, updatedConfig)
128-
129-
val blockHeader: BlockHeader = baseBlockHeader.copy(number = initialPeerInfo.maxBlockNumber + 1)
130-
val newBlock = NewBlock(Block(blockHeader, BlockBody(Nil, Nil)), initialPeerInfo.chainWeight.increase(blockHeader))
131-
132-
blockBroadcast.broadcastBlock(newBlock, Map(peer -> initialPeerInfo))
133-
134-
etcPeerManagerProbe.expectMsg(EtcPeerManagerActor.SendMessage(newBlock, peer.id))
135-
etcPeerManagerProbe.expectNoMessage(100.millis)
136-
}
137-
138124
class TestSetup(implicit system: ActorSystem) {
139125
val etcPeerManagerProbe = TestProbe()
140126

src/test/scala/io/iohk/ethereum/blockchain/sync/TestSyncConfig.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ trait TestSyncConfig extends SyncConfigBuilder {
3333
maxQueuedBlockNumberBehind = 10,
3434
maxNewBlockHashAge = 20,
3535
maxNewHashes = 64,
36-
broadcastNewBlockHashes = true,
3736
redownloadMissingStateNodes = true,
3837
fastSyncBlockValidationK = 100,
3938
fastSyncBlockValidationN = 2048,

0 commit comments

Comments
 (0)