File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed
main/scala/io/iohk/ethereum/blockchain/sync/regular
test/scala/io/iohk/ethereum/blockchain/sync/regular Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -113,7 +113,7 @@ case class BlockFetcherState(
113
113
}
114
114
115
115
/**
116
- * Validates received headers consistency and their compatibilty with the state
116
+ * Validates received headers consistency and their compatibility with the state
117
117
* TODO ETCM-370: This needs to be more fine-grained and detailed so blacklisting can be re-enabled
118
118
*/
119
119
private def validatedHeaders (headers : Seq [BlockHeader ]): Either [String , Seq [BlockHeader ]] =
@@ -123,11 +123,18 @@ case class BlockFetcherState(
123
123
headers
124
124
.asRight[String ]
125
125
.ensure(" Given headers should form a sequence without gaps" )(HeadersSeq .areChain)
126
+ .ensure(" Given headers should form a sequence with ready blocks" )(checkConsistencyWithReadyBlocks)
126
127
.ensure(" Given headers do not form a chain with already stored ones" )(headers =>
127
128
(waitingHeaders.lastOption, headers.headOption).mapN(_ isParentOf _).getOrElse(true )
128
129
)
129
130
}
130
131
132
+ private def checkConsistencyWithReadyBlocks (headers : Seq [BlockHeader ]): Boolean = {
133
+ if (waitingHeaders.isEmpty) {
134
+ (readyBlocks.lastOption.map(_.header), headers.headOption).mapN(_ isParentOf _).getOrElse(true )
135
+ } else true
136
+ }
137
+
131
138
def validateNewBlockHashes (hashes : Seq [BlockHash ]): Either [String , Seq [BlockHash ]] =
132
139
hashes
133
140
.asRight[String ]
Original file line number Diff line number Diff line change @@ -60,6 +60,17 @@ class BlockFetcherStateSpec
60
60
}
61
61
assert(result.map(_.knownTop) === Right (blocks.last.number))
62
62
}
63
+
64
+ " enqueue requested blocks fails when ready blocks is not forming a sequence with given headers" in {
65
+
66
+ val result = BlockFetcherState
67
+ .initial(importer, validators.blockValidator, 0 )
68
+ .copy(readyBlocks = Queue (blocks.head))
69
+ .appendHeaders(blocks.map(_.header))
70
+ .map(_.handleRequestedBlocks(blocks, peer))
71
+
72
+ assert(result.map(_.waitingHeaders) === Left (" Given headers should form a sequence with ready blocks" ))
73
+ }
63
74
}
64
75
65
76
" trying to insert block into the queues" should {
You can’t perform that action at this time.
0 commit comments