Skip to content

Commit 0c80251

Browse files
committed
[ETCM-103] Move hardcoded values to configuration
1 parent a898ebb commit 0c80251

File tree

9 files changed

+40
-21
lines changed

9 files changed

+40
-21
lines changed

src/main/resources/application.conf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,17 @@ mantis {
392392
# Sets max number of blocks that can be stored in queue to import on fetcher side
393393
# Warning! This setting affects ability to go back in case of branch resolution so it should not be too low
394394
max-fetcher-queue-size = 1000
395+
396+
# Expected size fo state sync bloom filter.
397+
# Current Size of ETC state trie is aroud 150M Nodes, so 200M is set to have some reserve
398+
# If the number of elements inserted into bloom filter would be significally higher that expected, then number
399+
# of false positives would rise which would degrade performance of state sync
400+
state-sync-bloomFilter-size = 200000000
401+
402+
403+
# Max number of mpt nodes held in memory in state sync, before saving them into database
404+
# 100k is around 60mb (each key-value pair has around 600bytes)
405+
state-sync-persistBatch-size = 100000
395406
}
396407

397408
pruning {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ class FastSync(
144144
"state-downloader"
145145
)
146146
private val syncStateScheduler = context.actorOf(
147-
SyncStateSchedulerActor.props(syncStateDownloader, SyncStateScheduler(blockchain)),
147+
SyncStateSchedulerActor
148+
.props(syncStateDownloader, SyncStateScheduler(blockchain, syncConfig.stateSyncBloomFilterSize), syncConfig),
148149
"state-scheduler"
149150
)
150151

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -279,15 +279,13 @@ object SyncStateScheduler {
279279
}
280280
}
281281

282-
val mptTrieSize = 200000000
283-
284-
def getEmptyFilter: BloomFilter[ByteString] = {
285-
BloomFilter.create[ByteString](ByteStringFunnel, mptTrieSize)
282+
def getEmptyFilter(expectedFilterSize: Int): BloomFilter[ByteString] = {
283+
BloomFilter.create[ByteString](ByteStringFunnel, expectedFilterSize)
286284
}
287285
// TODO add method to load bloom filter after node restart. Perfect way to do it would be to expose Observable
288286
// in RocksDBDataSource which underneath would use RockDbIterator which would traverse whole namespace.
289-
def apply(blockchain: Blockchain): SyncStateScheduler = {
290-
new SyncStateScheduler(blockchain, getEmptyFilter)
287+
def apply(blockchain: Blockchain, expectedBloomFilterSize: Int): SyncStateScheduler = {
288+
new SyncStateScheduler(blockchain, getEmptyFilter(expectedBloomFilterSize))
291289
}
292290

293291
final case class StateNodeRequest(

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ import io.iohk.ethereum.blockchain.sync.SyncStateSchedulerActor.{
1212
RestartRequested,
1313
StartSyncingTo,
1414
StateSyncFinished,
15-
WaitingForNewTargetBlock,
16-
maxMembatchSize
15+
WaitingForNewTargetBlock
1716
}
1817
import io.iohk.ethereum.utils.ByteStringUtils
18+
import io.iohk.ethereum.utils.Config.SyncConfig
1919

2020
import scala.concurrent.duration._
2121

22-
class SyncStateSchedulerActor(downloader: ActorRef, sync: SyncStateScheduler)
22+
class SyncStateSchedulerActor(downloader: ActorRef, sync: SyncStateScheduler, syncConfig: SyncConfig)
2323
extends Actor
2424
with ActorLogging
2525
with Timers {
@@ -87,7 +87,7 @@ class SyncStateSchedulerActor(downloader: ActorRef, sync: SyncStateScheduler)
8787
downloader ! GetMissingNodes(missing)
8888
}
8989

90-
if (state2.memBatch.size >= maxMembatchSize) {
90+
if (state2.memBatch.size >= syncConfig.stateSyncPersistBatchSize) {
9191
log.debug("Current membatch size is {}, persisting nodes to database", state2.memBatch.size)
9292
val state3 = sync.persistBatch(state2, targetBlock)
9393
context.become(
@@ -126,8 +126,8 @@ class SyncStateSchedulerActor(downloader: ActorRef, sync: SyncStateScheduler)
126126
}
127127

128128
object SyncStateSchedulerActor {
129-
def props(downloader: ActorRef, sync: SyncStateScheduler): Props = {
130-
Props(new SyncStateSchedulerActor(downloader, sync))
129+
def props(downloader: ActorRef, sync: SyncStateScheduler, syncConfig: SyncConfig): Props = {
130+
Props(new SyncStateSchedulerActor(downloader, sync, syncConfig))
131131
}
132132

133133
final case object PrintInfo
@@ -141,9 +141,6 @@ object SyncStateSchedulerActor {
141141

142142
case object StateSyncFinished
143143

144-
// TODO determine this number of maybe it should be put to config
145-
val maxMembatchSize = 100000
146-
147144
case object RestartRequested
148145
case object WaitingForNewTargetBlock
149146

src/main/scala/io/iohk/ethereum/utils/Config.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ object Config {
123123
fastSyncBlockValidationN: Int,
124124
fastSyncBlockValidationX: Int,
125125
maxTargetDifference: Int,
126-
maximumTargetUpdateFailures: Int
126+
maximumTargetUpdateFailures: Int,
127+
stateSyncBloomFilterSize: Int,
128+
stateSyncPersistBatchSize: Int,
127129
)
128130

129131
object SyncConfig {
@@ -162,7 +164,9 @@ object Config {
162164
fastSyncBlockValidationN = syncConfig.getInt("fast-sync-block-validation-n"),
163165
fastSyncBlockValidationX = syncConfig.getInt("fast-sync-block-validation-x"),
164166
maxTargetDifference = syncConfig.getInt("max-target-difference"),
165-
maximumTargetUpdateFailures = syncConfig.getInt("maximum-target-update-failures")
167+
maximumTargetUpdateFailures = syncConfig.getInt("maximum-target-update-failures"),
168+
stateSyncBloomFilterSize = syncConfig.getInt("state-sync-bloomFilter-size"),
169+
stateSyncPersistBatchSize = syncConfig.getInt("state-sync-persistBatch-size")
166170
)
167171
}
168172
}

src/test/resources/application.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ mantis {
118118
min-peers-to-choose-pivot-block = 2
119119
peers-to-choose-pivot-block-margin = 1
120120
pivot-block-offset = 500
121+
state-sync-bloomFilter-size = 20000
122+
123+
state-sync-persistBatch-size = 10000
121124
}
122125

123126
keyStore {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ class StateSyncSpec
176176
lazy val scheduler = system.actorOf(
177177
SyncStateSchedulerActor.props(
178178
downloader,
179-
new SyncStateScheduler(buildBlockChain(), SyncStateScheduler.getEmptyFilter)
179+
new SyncStateScheduler(buildBlockChain(), SyncStateScheduler.getEmptyFilter(syncConfig.stateSyncBloomFilterSize)),
180+
syncConfig
180181
)
181182
)
182183
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ class SyncSchedulerSpec extends AnyFlatSpec with Matchers with EitherValues with
222222
val freshBlockchain = BlockchainImpl(freshStorage.storages)
223223
new TrieProvider(freshBlockchain, blockchainConfig)
224224
}
225+
val bloomFilterSize = 1000
225226

226227
def buildScheduler(): (
227228
SyncStateScheduler,
@@ -230,7 +231,7 @@ class SyncSchedulerSpec extends AnyFlatSpec with Matchers with EitherValues with
230231
) = {
231232
val freshStorage = getNewStorages
232233
val freshBlockchain = BlockchainImpl(freshStorage.storages)
233-
(SyncStateScheduler(freshBlockchain), freshBlockchain, freshStorage)
234+
(SyncStateScheduler(freshBlockchain, bloomFilterSize), freshBlockchain, freshStorage)
234235
}
235236

236237
def exchangeSingleNode(

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ trait TestSyncConfig extends SyncConfigBuilder {
3939
fastSyncBlockValidationN = 2048,
4040
fastSyncBlockValidationX = 50,
4141
maxTargetDifference = 5,
42-
maximumTargetUpdateFailures = 1
42+
maximumTargetUpdateFailures = 1,
43+
stateSyncBloomFilterSize = 1000,
44+
stateSyncPersistBatchSize = 1000
45+
4346
)
4447

4548
override lazy val syncConfig: SyncConfig = defaultSyncConfig

0 commit comments

Comments
 (0)