Skip to content

Commit 7688810

Browse files
author
Lukasz Gasior
committed
Merge remote-tracking branch 'origin/phase/3/blockSync' into feature/privateChain
2 parents 617c066 + c497892 commit 7688810

12 files changed

+38
-36
lines changed

src/main/resources/reference.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ etc-client {
7171
max-concurrent-requests = 50
7272
block-headers-per-request = 2048
7373
block-bodies-per-request = 128
74-
receipts-per-request = 128
74+
receipts-per-request = 60
7575
nodes-per-request = 1000
7676
min-peers-to-choose-target-block = 2
7777
target-block-offset = 500

src/main/scala/io/iohk/ethereum/blockchain/sync/BlacklistSupport.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@ package io.iohk.ethereum.blockchain.sync
22

33
import scala.concurrent.duration.FiniteDuration
44
import scala.concurrent.ExecutionContext.Implicits.global
5-
6-
import akka.actor.{Scheduler, Cancellable, ActorRef, Actor}
5+
import akka.actor.{Actor, ActorLogging, ActorRef, Cancellable, Scheduler}
76

87
trait BlacklistSupport {
9-
selfActor: Actor =>
8+
selfActor: Actor with ActorLogging =>
109

1110
import BlacklistSupport._
1211

1312
def scheduler: Scheduler
1413

1514
var blacklistedPeers: Seq[(ActorRef, Cancellable)] = Nil
1615

17-
def blacklist(peer: ActorRef, duration: FiniteDuration): Unit = {
16+
def blacklist(peer: ActorRef, duration: FiniteDuration, reason: String): Unit = {
1817
undoBlacklist(peer)
18+
log.info(s"Blacklisting peer (${peer.path.name}), $reason")
1919
val unblacklistCancellable = scheduler.scheduleOnce(duration, self, UnblacklistPeer(peer))
2020
blacklistedPeers :+= (peer, unblacklistCancellable)
2121
}
@@ -30,6 +30,6 @@ trait BlacklistSupport {
3030
}
3131

3232
object BlacklistSupport {
33-
case class BlacklistPeer(peer: ActorRef)
33+
case class BlacklistPeer(peer: ActorRef, reason: String)
3434
case class UnblacklistPeer(peer: ActorRef)
3535
}

src/main/scala/io/iohk/ethereum/blockchain/sync/FastSync.scala

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,15 @@ trait FastSync {
6565
tryStartFastSync(newReceived)
6666
} else context become waitingForBlockHeaders(newWaitingFor, newReceived, timeout)
6767

68-
case PeerActor.MessageReceived(BlockHeaders(_)) =>
68+
case PeerActor.MessageReceived(BlockHeaders(blockHeaders)) =>
6969
sender() ! PeerActor.Unsubscribe
70-
blacklist(sender(), blacklistDuration)
70+
blacklist(sender(), blacklistDuration,s"did not respond with 1 header but with ${blockHeaders.size}, blacklisting for $blacklistDuration")
7171
context become waitingForBlockHeaders(waitingFor - sender(), received, timeout)
7272

7373
case BlockHeadersTimeout =>
7474
waitingFor.foreach { peer =>
7575
peer ! PeerActor.Unsubscribe
76-
blacklist(peer, blacklistDuration)
76+
blacklist(peer, blacklistDuration, s"did not respond within required time with block header, blacklisting for $blacklistDuration")
7777
}
7878
tryStartFastSync(received)
7979
}
@@ -120,21 +120,13 @@ trait FastSync {
120120
startFastSync(initialSyncState)
121121

122122
case None =>
123-
log.info("Peer ({}) did not respond with target block header, blacklisting and scheduling retry in {}",
124-
sender().path.name,
125-
startRetryInterval)
126-
127-
blacklist(sender(), blacklistDuration)
123+
blacklist(sender(), blacklistDuration,s"did not respond with target block header, blacklisting and scheduling retry in $startRetryInterval")
128124
scheduleStartRetry(startRetryInterval)
129125
context become startingFastSync
130126
}
131127

132128
case TargetBlockTimeout =>
133-
log.info("Peer ({}) did not respond with target block header (timeout), blacklisting and scheduling retry in {}",
134-
sender().path.name,
135-
startRetryInterval)
136-
137-
blacklist(sender(), blacklistDuration)
129+
blacklist(sender(), blacklistDuration, s"did not respond with target block header (timeout), blacklisting and scheduling retry in $startRetryInterval")
138130
peer ! PeerActor.Unsubscribe
139131
scheduleStartRetry(startRetryInterval)
140132
context become startingFastSync

src/main/scala/io/iohk/ethereum/blockchain/sync/FastSyncNodesRequestHandler.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ class FastSyncNodesRequestHandler(
1919
import FastSyncNodesRequestHandler._
2020

2121
override val requestMsg = GetNodeData(requestedHashes.map(_.v))
22-
override val responseMsgCode = NodeData.code
22+
override val responseMsgCode: Int = NodeData.code
2323

2424
override def handleResponseMsg(nodeData: NodeData): Unit = {
2525
if (nodeData.values.isEmpty) {
26-
syncController ! BlacklistSupport.BlacklistPeer(peer)
26+
val reason = s"got empty mpt node response for known hashes: ${requestedHashes.map(h => Hex.toHexString(h.v.toArray[Byte]))}"
27+
syncController ! BlacklistSupport.BlacklistPeer(peer, reason)
2728
}
2829

2930
val receivedHashes = nodeData.values.map(v => ByteString(kec256(v.toArray[Byte])))
@@ -59,7 +60,8 @@ class FastSyncNodesRequestHandler(
5960
}
6061

6162
override def handleTimeout(): Unit = {
62-
syncController ! BlacklistSupport.BlacklistPeer(peer)
63+
val reason = s"time out on mpt node response for known hashes: ${requestedHashes.map(h => Hex.toHexString(h.v.toArray[Byte]))}"
64+
syncController ! BlacklistSupport.BlacklistPeer(peer, reason)
6365
syncController ! FastSync.EnqueueNodes(requestedHashes)
6466
cleanupAndStop()
6567
}

src/main/scala/io/iohk/ethereum/blockchain/sync/FastSyncReceiptsRequestHandler.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import akka.util.ByteString
55
import io.iohk.ethereum.db.storage.AppStateStorage
66
import io.iohk.ethereum.domain.Blockchain
77
import io.iohk.ethereum.network.p2p.messages.PV63.{GetReceipts, Receipts}
8+
import org.spongycastle.util.encoders.Hex
89

910
class FastSyncReceiptsRequestHandler(
1011
peer: ActorRef,
@@ -14,7 +15,7 @@ class FastSyncReceiptsRequestHandler(
1415
extends SyncRequestHandler[GetReceipts, Receipts](peer) {
1516

1617
override val requestMsg = GetReceipts(requestedHashes)
17-
override val responseMsgCode = Receipts.code
18+
override val responseMsgCode: Int = Receipts.code
1819

1920
override def handleResponseMsg(receipts: Receipts): Unit = {
2021
(requestedHashes zip receipts.receiptsForBlocks).foreach { case (hash, receiptsForBlock) =>
@@ -25,7 +26,8 @@ class FastSyncReceiptsRequestHandler(
2526
updateBestBlockIfNeeded(receivedHashes)
2627

2728
if (receipts.receiptsForBlocks.isEmpty) {
28-
syncController ! BlacklistSupport.BlacklistPeer(peer)
29+
val reason = s"got empty receipts for known hashes: ${requestedHashes.map(h => Hex.toHexString(h.toArray[Byte]))}"
30+
syncController ! BlacklistSupport.BlacklistPeer(peer, reason)
2931
}
3032

3133
val remainingReceipts = requestedHashes.drop(receipts.receiptsForBlocks.size)
@@ -54,7 +56,8 @@ class FastSyncReceiptsRequestHandler(
5456
}
5557

5658
override def handleTimeout(): Unit = {
57-
syncController ! BlacklistSupport.BlacklistPeer(peer)
59+
val reason = s"time out on receipts response for known hashes: ${requestedHashes.map(h => Hex.toHexString(h.toArray[Byte]))}"
60+
syncController ! BlacklistSupport.BlacklistPeer(peer, reason)
5861
syncController ! FastSync.EnqueueReceipts(requestedHashes)
5962
cleanupAndStop()
6063
}

src/main/scala/io/iohk/ethereum/blockchain/sync/RegularSync.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ trait RegularSync {
162162
}
163163

164164
private def resumeWithDifferentPeer(currentPeer: ActorRef) = {
165-
self ! BlacklistPeer(currentPeer)
165+
self ! BlacklistPeer(currentPeer, "because of error in response")
166166
headersQueue = Seq.empty
167167
context.self ! ResumeRegularSync
168168
}

src/main/scala/io/iohk/ethereum/blockchain/sync/SyncBlockBodiesRequestHandler.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import akka.util.ByteString
55
import io.iohk.ethereum.blockchain.sync.SyncController.BlockBodiesReceived
66
import io.iohk.ethereum.db.storage.AppStateStorage
77
import io.iohk.ethereum.network.p2p.messages.PV62.{BlockBodies, GetBlockBodies}
8+
import org.spongycastle.util.encoders.Hex
89

910
class SyncBlockBodiesRequestHandler(
1011
peer: ActorRef,
@@ -17,7 +18,8 @@ class SyncBlockBodiesRequestHandler(
1718

1819
override def handleResponseMsg(blockBodies: BlockBodies): Unit = {
1920
if (blockBodies.bodies.isEmpty) {
20-
syncController ! BlacklistSupport.BlacklistPeer(peer)
21+
val reason = s"got empty block bodies response for known hashes: ${requestedHashes.map(h => Hex.toHexString(h.toArray[Byte]))}"
22+
syncController ! BlacklistSupport.BlacklistPeer(peer, reason)
2123
} else {
2224
syncController ! BlockBodiesReceived(peer, requestedHashes, blockBodies.bodies)
2325
}
@@ -27,7 +29,8 @@ class SyncBlockBodiesRequestHandler(
2729
}
2830

2931
override def handleTimeout(): Unit = {
30-
syncController ! BlacklistSupport.BlacklistPeer(peer)
32+
val reason = s"time out on block bodies response for known hashes: ${requestedHashes.map(h => Hex.toHexString(h.toArray[Byte]))}"
33+
syncController ! BlacklistSupport.BlacklistPeer(peer, reason)
3134
syncController ! FastSync.EnqueueBlockBodies(requestedHashes)
3235
cleanupAndStop()
3336
}

src/main/scala/io/iohk/ethereum/blockchain/sync/SyncBlockHeadersRequestHandler.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,16 @@ class SyncBlockHeadersRequestHandler(
3232
log.info("Received {} block headers in {} ms", headers.size, timeTakenSoFar())
3333
}
3434
} else {
35-
syncController ! BlacklistSupport.BlacklistPeer(peer)
35+
val reason = s"got error in block headers response for requested: ${requestMsg.block}"
36+
syncController ! BlacklistSupport.BlacklistPeer(peer, reason)
3637
}
3738

3839
cleanupAndStop()
3940
}
4041

4142
override def handleTimeout(): Unit = {
42-
syncController ! BlacklistSupport.BlacklistPeer(peer)
43+
val reason = s"got time out waiting for block headers response for requested: ${requestMsg.block}"
44+
syncController ! BlacklistSupport.BlacklistPeer(peer, reason)
4345
cleanupAndStop()
4446
}
4547

src/main/scala/io/iohk/ethereum/blockchain/sync/SyncController.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ class SyncController(
8080
case Terminated(ref) if handshakedPeers.contains(ref) =>
8181
removePeer(ref)
8282

83-
case BlacklistPeer(ref) =>
84-
blacklist(ref, blacklistDuration)
83+
case BlacklistPeer(ref, reason) =>
84+
blacklist(ref, blacklistDuration, reason)
8585

8686
case UnblacklistPeer(ref) =>
8787
undoBlacklist(ref)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class FastSyncBlockBodiesRequestHandlerSpec extends FlatSpec with Matchers {
3232
val responseBodies = Nil
3333
peer.reply(PeerActor.MessageReceived(BlockBodies(responseBodies)))
3434

35-
parent.expectMsg(BlacklistSupport.BlacklistPeer(peer.ref))
35+
parent.expectMsg(BlacklistSupport.BlacklistPeer(peer.ref, "got empty block bodies response for known hashes: List(31, 32)"))
3636
parent.expectMsg(SyncRequestHandler.Done)
3737

3838
peer.expectMsg(PeerActor.Unsubscribe)
@@ -44,7 +44,7 @@ class FastSyncBlockBodiesRequestHandlerSpec extends FlatSpec with Matchers {
4444

4545
time.advance(10.seconds)
4646

47-
parent.expectMsg(BlacklistSupport.BlacklistPeer(peer.ref))
47+
parent.expectMsg(BlacklistSupport.BlacklistPeer(peer.ref, "time out on block bodies response for known hashes: List(31, 32)"))
4848
parent.expectMsg(FastSync.EnqueueBlockBodies(requestedHashes))
4949
parent.expectMsg(SyncRequestHandler.Done)
5050

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class FastSyncBlockHeadersRequestHandlerSpec extends FlatSpec with Matchers {
7070

7171
time.advance(10.seconds)
7272

73-
parent.expectMsg(BlacklistSupport.BlacklistPeer(peer.ref))
73+
parent.expectMsg(BlacklistSupport.BlacklistPeer(peer.ref, "got time out waiting for block headers response for requested: Left(1)"))
7474
parent.expectMsg(SyncRequestHandler.Done)
7575

7676
peer.expectMsg(PeerActor.Unsubscribe)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class FastSyncReceiptsRequestHandlerSpec extends FlatSpec with Matchers {
3434

3535
time.advance(10.seconds)
3636

37-
parent.expectMsg(BlacklistSupport.BlacklistPeer(peer.ref))
37+
parent.expectMsg(BlacklistSupport.BlacklistPeer(peer.ref, "time out on receipts response for known hashes: List(31, 32)"))
3838
parent.expectMsg(FastSync.EnqueueReceipts(requestedHashes))
3939
parent.expectMsg(SyncRequestHandler.Done)
4040

0 commit comments

Comments
 (0)