Skip to content

[ETCM-415] Fix random subset of peers where block is broadcasted #814

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Nov 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,6 @@ mantis {
# Maximum number of hashes processed form NewBlockHashes packet
max-new-hashes = 64

# Set to false to disable broadcasting the NewBlockHashes message, as its usefulness is debatable,
# especially in the context of private networks
broadcast-new-block-hashes = true

# This a recovery mechanism for the issue of missing state nodes during blocks execution:
# off - missing state node will result in an exception
# on - missing state node will be redownloaded from a peer and block execution will be retried. This can repeat
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ class BlockBroadcast(val etcPeerManager: ActorRef, syncConfig: SyncConfig) {

broadcastNewBlock(newBlock, peersWithoutBlock)

if (syncConfig.broadcastNewBlockHashes) {
// NOTE: the usefulness of this message is debatable, especially in private networks
broadcastNewBlockHash(newBlock, peersWithoutBlock)
}
broadcastNewBlockHash(newBlock, peersWithoutBlock)
}

private def shouldSendNewBlock(newBlock: NewBlock, peerInfo: PeerInfo): Boolean =
Expand All @@ -58,6 +55,6 @@ class BlockBroadcast(val etcPeerManager: ActorRef, syncConfig: SyncConfig) {
*/
private[sync] def obtainRandomPeerSubset(peers: Set[Peer]): Set[Peer] = {
val numberOfPeersToSend = Math.sqrt(peers.size).toInt
Random.shuffle(peers).take(numberOfPeersToSend)
Random.shuffle(peers.toSeq).take(numberOfPeersToSend).toSet
}
}
2 changes: 0 additions & 2 deletions src/main/scala/io/iohk/ethereum/utils/Config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ object Config {
fastSyncThrottle: FiniteDuration,
maxQueuedBlockNumberAhead: Int,
maxQueuedBlockNumberBehind: Int,
broadcastNewBlockHashes: Boolean,
maxNewBlockHashAge: Int,
maxNewHashes: Int,
redownloadMissingStateNodes: Boolean,
Expand Down Expand Up @@ -161,7 +160,6 @@ object Config {
maxQueuedBlockNumberAhead = syncConfig.getInt("max-queued-block-number-ahead"),
maxNewBlockHashAge = syncConfig.getInt("max-new-block-hash-age"),
maxNewHashes = syncConfig.getInt("max-new-hashes"),
broadcastNewBlockHashes = syncConfig.getBoolean("broadcast-new-block-hashes"),
redownloadMissingStateNodes = syncConfig.getBoolean("redownload-missing-state-nodes"),
fastSyncBlockValidationK = syncConfig.getInt("fast-sync-block-validation-k"),
fastSyncBlockValidationN = syncConfig.getInt("fast-sync-block-validation-n"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import io.iohk.ethereum.network.p2p.messages.PV62.NewBlockHashes
import io.iohk.ethereum.network.p2p.messages.{PV62, Versions}
import io.iohk.ethereum.utils.Config

import scala.concurrent.duration._
import org.scalatest.flatspec.AnyFlatSpecLike
import org.scalatest.matchers.should.Matchers

Expand Down Expand Up @@ -122,19 +121,6 @@ class BlockBroadcastSpec
etcPeerManagerProbe.expectNoMessage()
}

it should "not broadcast NewBlockHashes message when disable by configuration" in new TestSetup {
val updatedConfig = syncConfig.copy(broadcastNewBlockHashes = false)
override val blockBroadcast = new BlockBroadcast(etcPeerManagerProbe.ref, updatedConfig)

val blockHeader: BlockHeader = baseBlockHeader.copy(number = initialPeerInfo.maxBlockNumber + 1)
val newBlock = NewBlock(Block(blockHeader, BlockBody(Nil, Nil)), initialPeerInfo.chainWeight.increase(blockHeader))

blockBroadcast.broadcastBlock(newBlock, Map(peer -> initialPeerInfo))

etcPeerManagerProbe.expectMsg(EtcPeerManagerActor.SendMessage(newBlock, peer.id))
etcPeerManagerProbe.expectNoMessage(100.millis)
}

class TestSetup(implicit system: ActorSystem) {
val etcPeerManagerProbe = TestProbe()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ trait TestSyncConfig extends SyncConfigBuilder {
maxQueuedBlockNumberBehind = 10,
maxNewBlockHashAge = 20,
maxNewHashes = 64,
broadcastNewBlockHashes = true,
redownloadMissingStateNodes = true,
fastSyncBlockValidationK = 100,
fastSyncBlockValidationN = 2048,
Expand Down