Skip to content

Commit

Permalink
Merge ETCM-313 into branch
Browse files Browse the repository at this point in the history
  • Loading branch information
1015bit committed Mar 2, 2021
2 parents 921ccab + 6d918a9 commit 7672baa
Show file tree
Hide file tree
Showing 22 changed files with 572 additions and 152 deletions.
Expand Up @@ -15,7 +15,7 @@ class EthashTestBlockHeaderValidator(blockchainConfig: BlockchainConfig) extends

protected def difficulty: DifficultyCalculator = DifficultyCalculator(blockchainConfig)

def validateEvenMore(blockHeader: BlockHeader, parentHeader: BlockHeader): Either[BlockHeaderError, BlockHeaderValid] =
override def validateEvenMore(blockHeader: BlockHeader): Either[BlockHeaderError, BlockHeaderValid] =
Right(BlockHeaderValid)

}
24 changes: 14 additions & 10 deletions src/it/scala/io/iohk/ethereum/sync/FastSyncItSpec.scala
Expand Up @@ -59,49 +59,53 @@ class FastSyncItSpec extends FlatSpecBase with Matchers with BeforeAndAfterAll {

it should "sync blockchain with state nodes when peer do not response with full responses" in
customTestCaseResourceM(
FakePeer.start3FakePeersRes(
FakePeer.start4FakePeersRes(
fakePeerCustomConfig2 = FakePeerCustomConfig(HostConfig()),
fakePeerCustomConfig3 = FakePeerCustomConfig(HostConfig())
)
) { case (peer1, peer2, peer3) =>
) { case (peer1, peer2, peer3, peer4) =>
for {
_ <- peer2.importBlocksUntil(1000)(updateStateAtBlock(500))
_ <- peer3.importBlocksUntil(1000)(updateStateAtBlock(500))
_ <- peer1.connectToPeers(Set(peer2.node, peer3.node))
_ <- peer4.importBlocksUntil(1000)(updateStateAtBlock(500))

_ <- peer1.connectToPeers(Set(peer2.node, peer3.node, peer4.node))
_ <- peer1.startFastSync().delayExecution(50.milliseconds)
_ <- peer1.waitForFastSyncFinish()
} yield {
val trie = peer1.getBestBlockTrie()
val synchronizingPeerHaveAllData = peer1.containsExpectedDataUpToAccountAtBlock(1000, 500)
// due to the fact that function generating state is deterministic both peer2 and peer3 ends up with exactly same
// due to the fact that function generating state is deterministic both peer3 and peer4 ends up with exactly same
// state, so peer1 can get whole trie from both of them.
assert(peer1.bl.getBestBlockNumber() == peer2.bl.getBestBlockNumber() - peer2.testSyncConfig.pivotBlockOffset)
assert(peer1.bl.getBestBlockNumber() == peer3.bl.getBestBlockNumber() - peer3.testSyncConfig.pivotBlockOffset)
assert(peer1.bl.getBestBlockNumber() == peer4.bl.getBestBlockNumber() - peer4.testSyncConfig.pivotBlockOffset)
assert(trie.isDefined)
assert(synchronizingPeerHaveAllData)
}
}

it should "sync blockchain with state nodes when one of the peers send empty state responses" in
customTestCaseResourceM(
FakePeer.start3FakePeersRes(
FakePeer.start4FakePeersRes(
fakePeerCustomConfig2 = FakePeerCustomConfig(HostConfig()),
fakePeerCustomConfig3 = FakePeerCustomConfig(HostConfig().copy(maxMptComponentsPerMessage = 0))
)
) { case (peer1, peer2, peer3) =>
) { case (peer1, peer2, peer3, peer4) =>
for {
_ <- peer2.importBlocksUntil(1000)(updateStateAtBlock(500))
_ <- peer3.importBlocksUntil(1000)(updateStateAtBlock(500))
_ <- peer1.connectToPeers(Set(peer2.node, peer3.node))
_ <- peer4.importBlocksUntil(1000)(updateStateAtBlock(500))

_ <- peer1.connectToPeers(Set(peer2.node, peer3.node, peer4.node))
_ <- peer1.startFastSync().delayExecution(50.milliseconds)
_ <- peer1.waitForFastSyncFinish()
} yield {
val trie = peer1.getBestBlockTrie()
val synchronizingPeerHaveAllData = peer1.containsExpectedDataUpToAccountAtBlock(1000, 500)
// due to the fact that function generating state is deterministic both peer2 and peer3 ends up with exactly same
// due to the fact that function generating state is deterministic both peer3 and peer4 ends up with exactly same
// state, so peer1 can get whole trie from both of them.
assert(peer1.bl.getBestBlockNumber() == peer2.bl.getBestBlockNumber() - peer2.testSyncConfig.pivotBlockOffset)
assert(peer1.bl.getBestBlockNumber() == peer3.bl.getBestBlockNumber() - peer3.testSyncConfig.pivotBlockOffset)
assert(peer1.bl.getBestBlockNumber() == peer4.bl.getBestBlockNumber() - peer4.testSyncConfig.pivotBlockOffset)
assert(trie.isDefined)
assert(synchronizingPeerHaveAllData)
}
Expand Down
3 changes: 2 additions & 1 deletion src/it/scala/io/iohk/ethereum/sync/util/CommonFakePeer.scala
Expand Up @@ -222,7 +222,8 @@ abstract class CommonFakePeer(peerName: String, fakePeerCustomConfig: FakePeerCu
startRetryInterval = 50.milliseconds,
nodesPerRequest = 200,
maxTargetDifference = 1,
syncRetryInterval = 50.milliseconds
syncRetryInterval = 50.milliseconds,
blacklistDuration = 100.seconds
)

lazy val broadcaster = new BlockBroadcast(etcPeerManager)
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/application.conf
Expand Up @@ -469,6 +469,10 @@ mantis {
# (peer.bestKnownBlock - pivot-block-offset) - node.curentPivotBlock > max-pivot-age
# it fast sync pivot block has become stale and it needs update
max-pivot-block-age = 96

# Maximum number of retries performed by fast sync when the master peer sends invalid block headers.
# On reaching this limit, it will perform branch resolving.
fast-sync-max-batch-retries = 5
}

pruning {
Expand Down

0 comments on commit 7672baa

Please sign in to comment.