Skip to content

[ECTM-104] Pivot block selection algorithm #711

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 8, 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
14 changes: 7 additions & 7 deletions src/it/scala/io/iohk/ethereum/sync/FastSyncItSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ class FastSyncItSpec extends FlatSpecBase with Matchers with BeforeAndAfter {
_ <- peer1.startFastSync().delayExecution(50.milliseconds)
_ <- peer1.waitForFastSyncFinish()
} yield {
assert(peer1.bl.getBestBlockNumber() == peer2.bl.getBestBlockNumber() - peer2.testSyncConfig.targetBlockOffset)
assert(peer1.bl.getBestBlockNumber() == peer3.bl.getBestBlockNumber() - peer3.testSyncConfig.targetBlockOffset)
assert(peer1.bl.getBestBlockNumber() == peer2.bl.getBestBlockNumber() - peer2.testSyncConfig.pivotBlockOffset)
assert(peer1.bl.getBestBlockNumber() == peer3.bl.getBestBlockNumber() - peer3.testSyncConfig.pivotBlockOffset)
}
}

Expand All @@ -81,13 +81,13 @@ class FastSyncItSpec extends FlatSpecBase with Matchers with BeforeAndAfter {
val trie = peer1.getBestBlockTrie()
// due to the fact that function generating state is deterministic both peer2 and peer3 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.targetBlockOffset)
assert(peer1.bl.getBestBlockNumber() == peer3.bl.getBestBlockNumber() - peer3.testSyncConfig.targetBlockOffset)
assert(peer1.bl.getBestBlockNumber() == peer2.bl.getBestBlockNumber() - peer2.testSyncConfig.pivotBlockOffset)
assert(peer1.bl.getBestBlockNumber() == peer3.bl.getBestBlockNumber() - peer3.testSyncConfig.pivotBlockOffset)
assert(trie.isDefined)
}
}

it should "should update target block" in customTestCaseResourceM(FakePeer.start2FakePeersRes()) {
it should "should update pivot block" in customTestCaseResourceM(FakePeer.start2FakePeersRes()) {
case (peer1, peer2) =>
for {
_ <- peer2.importBlocksUntil(1000)(IdentityUpdate)
Expand All @@ -96,7 +96,7 @@ class FastSyncItSpec extends FlatSpecBase with Matchers with BeforeAndAfter {
_ <- peer1.startFastSync().delayExecution(50.milliseconds)
_ <- peer1.waitForFastSyncFinish()
} yield {
assert(peer1.bl.getBestBlockNumber() == peer2.bl.getBestBlockNumber() - peer2.testSyncConfig.targetBlockOffset)
assert(peer1.bl.getBestBlockNumber() == peer2.bl.getBestBlockNumber() - peer2.testSyncConfig.pivotBlockOffset)
}
}
}
Expand Down Expand Up @@ -308,7 +308,7 @@ object FastSyncItSpec {
lazy val validators = new MockValidatorsAlwaysSucceed

val testSyncConfig = syncConfig.copy(
minPeersToChooseTargetBlock = 1,
minPeersToChoosePivotBlock = 1,
peersScanInterval = 5.milliseconds,
blockHeadersPerRequest = 200,
blockBodiesPerRequest = 50,
Expand Down
10 changes: 7 additions & 3 deletions src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,16 @@ mantis {
# Requested number of MPT nodes when syncing from other peers
nodes-per-request = 384

# Minimum number of peers required to start fast-sync (by determining the target block)
min-peers-to-choose-target-block = 2
# Minimum number of peers required to start fast-sync (by determining the pivot block)
min-peers-to-choose-pivot-block = 3

# Number of additional peers used to determine pivot block during fast-sync
# Number of peers used to reach consensus = min-peers-to-choose-pivot-block + peers-to-choose-pivot-block-margin
peers-to-choose-pivot-block-margin = 1

# During fast-sync when most up to date block is determined from peers, the actual target block number
# will be decreased by this value
target-block-offset = 128
pivot-block-offset = 128

# How often to query peers for new blocks after the top of the chain has been reached
check-for-new-block-interval = 10.seconds
Expand Down
414 changes: 251 additions & 163 deletions src/main/scala/io/iohk/ethereum/blockchain/sync/FastSync.scala

Large diffs are not rendered by default.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ trait PeerListSupport {

var handshakedPeers: PeersMap = Map.empty

scheduler.scheduleWithFixedDelay(0.seconds, syncConfig.peersScanInterval, etcPeerManager, EtcPeerManagerActor.GetHandshakedPeers)(global, context.self)
scheduler.scheduleWithFixedDelay(
0.seconds,
syncConfig.peersScanInterval,
etcPeerManager,
EtcPeerManagerActor.GetHandshakedPeers
)(global, context.self)

def removePeer(peerId: PeerId): Unit = {
peerEventBus ! Unsubscribe(PeerDisconnectedClassifier(PeerSelector.WithId(peerId)))
Expand Down
Loading