@@ -119,25 +119,26 @@ trait RegularSync {
119
119
blockchain.getBlockHeaderByHash(blocks.head.header.parentHash)
120
120
.flatMap(b => blockchain.getTotalDifficultyByHash(b.hash)) match {
121
121
case Some (blockParentTd) =>
122
- val (newBlocks, error ) = processBlocks(blocks, blockParentTd)
122
+ val (newBlocks, errorOpt ) = processBlocks(blocks, blockParentTd)
123
123
124
124
if (newBlocks.nonEmpty){
125
125
context.self ! BroadcastBlocks (newBlocks)
126
126
log.info(s " got new blocks up till block: ${newBlocks.last.block.header.number} " +
127
127
s " with hash ${Hex .toHexString(newBlocks.last.block.header.hash.toArray[Byte ])}" )
128
128
}
129
129
130
- if (error.isDefined){
131
- val numberBlockFailed = blocks.head.header.number + newBlocks.length
132
- resumeWithDifferentPeer(peer, reason = s " a block execution error: ${error.get.toString}, in block $numberBlockFailed" )
133
- } else {
134
- headersQueue = headersQueue.drop(blocks.length)
135
- if (headersQueue.nonEmpty) {
136
- val hashes = headersQueue.take(blockBodiesPerRequest).map(_.hash)
137
- waitingForActor = Some (context.actorOf(SyncBlockBodiesRequestHandler .props(peer, hashes)))
138
- } else {
139
- context.self ! ResumeRegularSync
140
- }
130
+ errorOpt match {
131
+ case Some (error) =>
132
+ val numberBlockFailed = blocks.head.header.number + newBlocks.length
133
+ resumeWithDifferentPeer(peer, reason = s " a block execution error: ${error.toString}, in block $numberBlockFailed" )
134
+ case None =>
135
+ headersQueue = headersQueue.drop(blocks.length)
136
+ if (headersQueue.nonEmpty) {
137
+ val hashes = headersQueue.take(blockBodiesPerRequest).map(_.hash)
138
+ waitingForActor = Some (context.actorOf(SyncBlockBodiesRequestHandler .props(peer, hashes)))
139
+ } else {
140
+ context.self ! ResumeRegularSync
141
+ }
141
142
}
142
143
case None =>
143
144
// TODO: Investigate if we can recover from this error (EC-165)
0 commit comments