Skip to content

Commit f97c6bf

Browse files
author
Leonor Boga
authored
ETCM-985 Remove method saveNode from Blockchain class and use StateStorage directly (#1042)
1 parent 98ccd69 commit f97c6bf

File tree

17 files changed

+43
-16
lines changed

17 files changed

+43
-16
lines changed

src/it/scala/io/iohk/ethereum/ledger/BlockImporterItSpec.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import io.iohk.ethereum.consensus.pow.validators.StdOmmersValidator
3434
import io.iohk.ethereum.consensus.validators.Validators
3535
import io.iohk.ethereum.crypto
3636
import io.iohk.ethereum.domain._
37-
import io.iohk.ethereum.ledger.BlockResult
3837
import io.iohk.ethereum.mpt.MerklePatriciaTrie
3938
import io.iohk.ethereum.utils.Config
4039
import io.iohk.ethereum.utils.Config.SyncConfig
@@ -123,6 +122,7 @@ class BlockImporterItSpec
123122
blockImport,
124123
blockchain,
125124
blockchainReader,
125+
storagesInstance.storages.stateStorage,
126126
new BranchResolution(blockchain, blockchainReader),
127127
syncConfig,
128128
ommersPoolProbe.ref,
@@ -167,6 +167,7 @@ class BlockImporterItSpec
167167
mkBlockImport(validators = successValidators),
168168
blockchain,
169169
blockchainReader,
170+
storagesInstance.storages.stateStorage,
170171
new BranchResolution(blockchain, blockchainReader),
171172
syncConfig,
172173
ommersPoolProbe.ref,
@@ -280,6 +281,7 @@ class BlockImporterItSpec
280281
mkBlockImport(validators = successValidators),
281282
blockchain,
282283
blockchainReader,
284+
storagesInstance.storages.stateStorage,
283285
new BranchResolution(blockchain, blockchainReader),
284286
syncConfig,
285287
ommersPoolProbe.ref,

src/it/scala/io/iohk/ethereum/sync/util/FastSyncItSpecUtils.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ object FastSyncItSpecUtils {
3838
blockchainReader,
3939
blockchainWriter,
4040
storagesInstance.storages.evmCodeStorage,
41+
storagesInstance.storages.stateStorage,
4142
storagesInstance.storages.nodeStorage,
4243
validators,
4344
peerEventBus,

src/it/scala/io/iohk/ethereum/sync/util/RegularSyncItSpecUtils.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ object RegularSyncItSpecUtils {
147147
blockImport,
148148
bl,
149149
blockchainReader,
150+
storagesInstance.storages.stateStorage,
150151
new BranchResolution(bl, blockchainReader),
151152
syncConfig,
152153
ommersPool,
@@ -164,6 +165,7 @@ object RegularSyncItSpecUtils {
164165
blockImport,
165166
bl,
166167
blockchainReader,
168+
storagesInstance.storages.stateStorage,
167169
new BranchResolution(bl, blockchainReader),
168170
validators.blockValidator,
169171
blacklist,

src/it/scala/io/iohk/ethereum/txExecTest/util/DumpChainApp.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import io.iohk.ethereum.db.components.Storages
2020
import io.iohk.ethereum.db.components.Storages.PruningModeComponent
2121
import io.iohk.ethereum.db.storage.AppStateStorage
2222
import io.iohk.ethereum.db.storage.MptStorage
23-
import io.iohk.ethereum.db.storage.NodeStorage.NodeEncoded
2423
import io.iohk.ethereum.db.storage.NodeStorage.NodeHash
2524
import io.iohk.ethereum.db.storage.pruning.ArchivePruning
2625
import io.iohk.ethereum.db.storage.pruning.PruningMode
@@ -184,8 +183,6 @@ class BlockchainMock(genesisHash: ByteString) extends Blockchain {
184183
ethCompatibleStorage: Boolean
185184
): StorageProof = EmptyStorageValueProof(StorageProofKey(position))
186185

187-
override def saveNode(nodeHash: NodeHash, nodeEncoded: NodeEncoded, blockNumber: BigInt): Unit = ???
188-
189186
override def removeBlock(hash: ByteString, withState: Boolean = true): Unit = ???
190187

191188
override def getChainWeightByHash(blockhash: ByteString): Option[ChainWeight] = ???

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import io.iohk.ethereum.db.storage.AppStateStorage
1414
import io.iohk.ethereum.db.storage.EvmCodeStorage
1515
import io.iohk.ethereum.db.storage.FastSyncStateStorage
1616
import io.iohk.ethereum.db.storage.NodeStorage
17+
import io.iohk.ethereum.db.storage.StateStorage
1718
import io.iohk.ethereum.domain.Blockchain
1819
import io.iohk.ethereum.domain.BlockchainReader
1920
import io.iohk.ethereum.domain.BlockchainWriter
@@ -27,6 +28,7 @@ class SyncController(
2728
blockchainReader: BlockchainReader,
2829
blockchainWriter: BlockchainWriter,
2930
evmCodeStorage: EvmCodeStorage,
31+
stateStorage: StateStorage,
3032
nodeStorage: NodeStorage,
3133
fastSyncStateStorage: FastSyncStateStorage,
3234
blockImport: BlockImport,
@@ -96,6 +98,7 @@ class SyncController(
9698
blockchainReader,
9799
blockchainWriter,
98100
evmCodeStorage,
101+
stateStorage,
99102
nodeStorage,
100103
validators,
101104
peerEventBus,
@@ -121,6 +124,7 @@ class SyncController(
121124
blockImport,
122125
blockchain,
123126
blockchainReader,
127+
stateStorage,
124128
new BranchResolution(blockchain, blockchainReader),
125129
validators.blockValidator,
126130
blacklist,
@@ -145,6 +149,7 @@ object SyncController {
145149
blockchainReader: BlockchainReader,
146150
blockchainWriter: BlockchainWriter,
147151
evmCodeStorage: EvmCodeStorage,
152+
stateStorage: StateStorage,
148153
nodeStorage: NodeStorage,
149154
syncStateStorage: FastSyncStateStorage,
150155
blockImport: BlockImport,
@@ -163,6 +168,7 @@ object SyncController {
163168
blockchainReader,
164169
blockchainWriter,
165170
evmCodeStorage,
171+
stateStorage,
166172
nodeStorage,
167173
syncStateStorage,
168174
blockImport,

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import io.iohk.ethereum.db.storage.AppStateStorage
3838
import io.iohk.ethereum.db.storage.EvmCodeStorage
3939
import io.iohk.ethereum.db.storage.FastSyncStateStorage
4040
import io.iohk.ethereum.db.storage.NodeStorage
41+
import io.iohk.ethereum.db.storage.StateStorage
4142
import io.iohk.ethereum.domain._
4243
import io.iohk.ethereum.mpt.MerklePatriciaTrie
4344
import io.iohk.ethereum.network.EtcPeerManagerActor.PeerInfo
@@ -56,6 +57,7 @@ class FastSync(
5657
val blockchainReader: BlockchainReader,
5758
blockchainWriter: BlockchainWriter,
5859
evmCodeStorage: EvmCodeStorage,
60+
stateStorage: StateStorage,
5961
nodeStorage: NodeStorage,
6062
val validators: Validators,
6163
val peerEventBus: ActorRef,
@@ -176,6 +178,7 @@ class FastSync(
176178
blockchain,
177179
blockchainReader,
178180
evmCodeStorage,
181+
stateStorage,
179182
nodeStorage,
180183
syncConfig.stateSyncBloomFilterSize
181184
),
@@ -1150,6 +1153,7 @@ object FastSync {
11501153
blockchainReader: BlockchainReader,
11511154
blockchainWriter: BlockchainWriter,
11521155
evmCodeStorage: EvmCodeStorage,
1156+
stateStorage: StateStorage,
11531157
nodeStorage: NodeStorage,
11541158
validators: Validators,
11551159
peerEventBus: ActorRef,
@@ -1166,6 +1170,7 @@ object FastSync {
11661170
blockchainReader,
11671171
blockchainWriter,
11681172
evmCodeStorage,
1173+
stateStorage,
11691174
nodeStorage,
11701175
validators,
11711176
peerEventBus,

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import io.iohk.ethereum.blockchain.sync.fast.SyncStateScheduler._
2121
import io.iohk.ethereum.db.dataSource.RocksDbDataSource.IterationError
2222
import io.iohk.ethereum.db.storage.EvmCodeStorage
2323
import io.iohk.ethereum.db.storage.NodeStorage
24+
import io.iohk.ethereum.db.storage.StateStorage
2425
import io.iohk.ethereum.domain.Account
2526
import io.iohk.ethereum.domain.Blockchain
2627
import io.iohk.ethereum.domain.BlockchainReader
@@ -59,9 +60,9 @@ import io.iohk.ethereum.network.p2p.messages.ETH63.MptNodeEncoders.MptNodeDec
5960
* Important part is that nodes retrieved by getMissingNodes, must eventually be provided for scheduler to make progress
6061
*/
6162
class SyncStateScheduler(
62-
blockchain: Blockchain,
6363
blockchainReader: BlockchainReader,
6464
evmCodeStorage: EvmCodeStorage,
65+
stateStorage: StateStorage,
6566
bloomFilter: LoadableBloomFilter[ByteString]
6667
) {
6768

@@ -133,7 +134,7 @@ class SyncStateScheduler(
133134
bloomFilter.put(hash)
134135
reqType match {
135136
case _: CodeRequest => evmCodeStorage.put(hash, data).commit()
136-
case _: NodeRequest => blockchain.saveNode(hash, data.toArray, targetBlockNumber)
137+
case _: NodeRequest => stateStorage.saveNode(hash, data.toArray, targetBlockNumber)
137138
}
138139
}
139140
newState
@@ -294,6 +295,7 @@ object SyncStateScheduler {
294295
blockchain: Blockchain,
295296
blockchainReader: BlockchainReader,
296297
evmCodeStorage: EvmCodeStorage,
298+
stateStorage: StateStorage,
297299
nodeStorage: NodeStorage,
298300
expectedBloomFilterSize: Int
299301
): SyncStateScheduler = {
@@ -304,9 +306,9 @@ object SyncStateScheduler {
304306
.takeWhileInclusive(_.isRight)
305307

306308
new SyncStateScheduler(
307-
blockchain,
308309
blockchainReader,
309310
evmCodeStorage,
311+
stateStorage,
310312
LoadableBloomFilter[ByteString](expectedBloomFilterSize, mptStateSavedKeys)
311313
)
312314
}

src/main/scala/io/iohk/ethereum/blockchain/sync/regular/BlockImporter.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import io.iohk.ethereum.blockchain.sync.regular.BlockBroadcast.BlockToBroadcast
2121
import io.iohk.ethereum.blockchain.sync.regular.BlockBroadcasterActor.BroadcastBlocks
2222
import io.iohk.ethereum.blockchain.sync.regular.RegularSync.ProgressProtocol
2323
import io.iohk.ethereum.crypto.kec256
24+
import io.iohk.ethereum.db.storage.StateStorage
2425
import io.iohk.ethereum.domain._
2526
import io.iohk.ethereum.ledger._
2627
import io.iohk.ethereum.mpt.MerklePatriciaTrie.MissingNodeException
@@ -38,6 +39,7 @@ class BlockImporter(
3839
blockImport: BlockImport,
3940
blockchain: Blockchain,
4041
blockchainReader: BlockchainReader,
42+
stateStorage: StateStorage,
4143
branchResolution: BranchResolution,
4244
syncConfig: SyncConfig,
4345
ommersPool: ActorRef,
@@ -116,7 +118,7 @@ class BlockImporter(
116118
state: ImporterState
117119
): Receive = { case BlockFetcher.FetchedStateNode(nodeData) =>
118120
val node = nodeData.values.head
119-
blockchain.saveNode(kec256(node), node.toArray, blocksToRetry.head.number)
121+
stateStorage.saveNode(kec256(node), node.toArray, blocksToRetry.head.number)
120122
importBlocks(blocksToRetry, blockImportType)(state)
121123
}
122124

@@ -328,6 +330,7 @@ object BlockImporter {
328330
blockImport: BlockImport,
329331
blockchain: Blockchain,
330332
blockchainReader: BlockchainReader,
333+
stateStorage: StateStorage,
331334
branchResolution: BranchResolution,
332335
syncConfig: SyncConfig,
333336
ommersPool: ActorRef,
@@ -341,6 +344,7 @@ object BlockImporter {
341344
blockImport,
342345
blockchain,
343346
blockchainReader,
347+
stateStorage,
344348
branchResolution,
345349
syncConfig,
346350
ommersPool,

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import io.iohk.ethereum.blockchain.sync.regular.RegularSync.NewCheckpoint
2020
import io.iohk.ethereum.blockchain.sync.regular.RegularSync.ProgressProtocol
2121
import io.iohk.ethereum.blockchain.sync.regular.RegularSync.ProgressState
2222
import io.iohk.ethereum.consensus.validators.BlockValidator
23+
import io.iohk.ethereum.db.storage.StateStorage
2324
import io.iohk.ethereum.domain.Block
2425
import io.iohk.ethereum.domain.Blockchain
2526
import io.iohk.ethereum.domain.BlockchainReader
@@ -35,6 +36,7 @@ class RegularSync(
3536
blockImport: BlockImport,
3637
blockchain: Blockchain,
3738
blockchainReader: BlockchainReader,
39+
stateStorage: StateStorage,
3840
branchResolution: BranchResolution,
3941
blockValidator: BlockValidator,
4042
blacklist: Blacklist,
@@ -65,6 +67,7 @@ class RegularSync(
6567
blockImport,
6668
blockchain,
6769
blockchainReader,
70+
stateStorage,
6871
branchResolution,
6972
syncConfig,
7073
ommersPool,
@@ -137,6 +140,7 @@ object RegularSync {
137140
blockImport: BlockImport,
138141
blockchain: Blockchain,
139142
blockchainReader: BlockchainReader,
143+
stateStorage: StateStorage,
140144
branchResolution: BranchResolution,
141145
blockValidator: BlockValidator,
142146
blacklist: Blacklist,
@@ -153,6 +157,7 @@ object RegularSync {
153157
blockImport,
154158
blockchain,
155159
blockchainReader,
160+
stateStorage,
156161
branchResolution,
157162
blockValidator,
158163
blacklist,

src/main/scala/io/iohk/ethereum/domain/Blockchain.scala

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import cats.syntax.flatMap._
88
import scala.annotation.tailrec
99

1010
import io.iohk.ethereum.db.dataSource.DataSourceBatchUpdate
11-
import io.iohk.ethereum.db.storage.NodeStorage.NodeEncoded
12-
import io.iohk.ethereum.db.storage.NodeStorage.NodeHash
1311
import io.iohk.ethereum.db.storage._
1412
import io.iohk.ethereum.domain
1513
import io.iohk.ethereum.jsonrpc.ProofService.StorageProof
@@ -80,8 +78,6 @@ trait Blockchain {
8078

8179
def saveBestKnownBlocks(bestBlockNumber: BigInt, latestCheckpointNumber: Option[BigInt] = None): Unit
8280

83-
def saveNode(nodeHash: NodeHash, nodeEncoded: NodeEncoded, blockNumber: BigInt): Unit
84-
8581
/** Strict check if given block hash is in chain
8682
* Using any of getXXXByHash is not always accurate - after restart the best block is often lower than before restart
8783
* The result of that is returning data of blocks which we don't consider as a part of the chain anymore
@@ -203,9 +199,6 @@ class BlockchainImpl(
203199
BestBlockLatestCheckpointNumbers(number, latestCheckpointNumber)
204200
)
205201

206-
def saveNode(nodeHash: NodeHash, nodeEncoded: NodeEncoded, blockNumber: BigInt): Unit =
207-
stateStorage.saveNode(nodeHash, nodeEncoded, blockNumber)
208-
209202
private def removeBlockNumberMapping(number: BigInt): DataSourceBatchUpdate =
210203
blockNumberMappingStorage.remove(number)
211204

src/main/scala/io/iohk/ethereum/nodebuilder/NodeBuilder.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,7 @@ trait SyncControllerBuilder {
796796
blockchainReader,
797797
blockchainWriter,
798798
storagesInstance.storages.evmCodeStorage,
799+
storagesInstance.storages.stateStorage,
799800
storagesInstance.storages.nodeStorage,
800801
storagesInstance.storages.fastSyncStateStorage,
801802
blockImport,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class FastSyncSpec
8383
blockchainWriter = blockchainWriter,
8484
evmCodeStorage = storagesInstance.storages.evmCodeStorage,
8585
nodeStorage = storagesInstance.storages.nodeStorage,
86+
stateStorage = storagesInstance.storages.stateStorage,
8687
validators = validators,
8788
peerEventBus = peerEventBus.ref,
8889
etcPeerManager = etcPeerManager.ref,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ class StateSyncSpec
257257
blockchain,
258258
blockchainReader,
259259
getNewStorages.storages.evmCodeStorage,
260+
getNewStorages.storages.stateStorage,
260261
getNewStorages.storages.nodeStorage,
261262
syncConfig.stateSyncBloomFilterSize
262263
),

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ class SyncControllerSpec
546546
blockchainReader,
547547
blockchainWriter,
548548
storagesInstance.storages.evmCodeStorage,
549+
storagesInstance.storages.stateStorage,
549550
storagesInstance.storages.nodeStorage,
550551
storagesInstance.storages.fastSyncStateStorage,
551552
blockImport,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ class SyncStateSchedulerSpec
308308
freshBlockchain,
309309
freshBlockchainReader,
310310
freshStorage.storages.evmCodeStorage,
311+
freshStorage.storages.stateStorage,
311312
freshStorage.storages.nodeStorage,
312313
bloomFilterSize
313314
),

src/test/scala/io/iohk/ethereum/blockchain/sync/regular/RegularSyncFixtures.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import org.scalatest.matchers.should.Matchers
3333
import io.iohk.ethereum.BlockHelpers
3434
import io.iohk.ethereum.blockchain.sync._
3535
import io.iohk.ethereum.consensus.blocks.CheckpointBlockGenerator
36+
import io.iohk.ethereum.db.storage.StateStorage
3637
import io.iohk.ethereum.domain.BlockHeaderImplicits._
3738
import io.iohk.ethereum.domain._
3839
import io.iohk.ethereum.ledger._
@@ -75,6 +76,8 @@ trait RegularSyncFixtures { self: Matchers with AsyncMockFactory =>
7576
val blacklist: CacheBasedBlacklist = CacheBasedBlacklist.empty(100)
7677
lazy val branchResolution = new BranchResolution(blockchain, blockchainReader)
7778

79+
val stateStorage: StateStorage = stub[StateStorage]
80+
7881
lazy val regularSync: ActorRef = system.actorOf(
7982
RegularSync
8083
.props(
@@ -84,6 +87,7 @@ trait RegularSyncFixtures { self: Matchers with AsyncMockFactory =>
8487
blockImport,
8588
blockchain,
8689
blockchainReader,
90+
stateStorage,
8791
branchResolution,
8892
validators.blockValidator,
8993
blacklist,

src/test/scala/io/iohk/ethereum/blockchain/sync/regular/RegularSyncSpec.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ class RegularSyncSpec
473473
val failingBlock: Block = testBlocksChunked.head.head
474474
peersClient.setAutoPilot(new PeersClientAutoPilot)
475475
override lazy val branchResolution: BranchResolution = stub[BranchResolution]
476+
(blockchainReader.getBestBlockNumber _).when().returns(0)
476477
(branchResolution.resolveBranch _).when(*).returns(NewBetterBranch(Nil)).repeat(10)
477478
(blockImport
478479
.importBlock(_: Block)(_: Scheduler))
@@ -483,7 +484,7 @@ class RegularSyncSpec
483484
val nodeData = List(ByteString(failingBlock.header.toBytes: Array[Byte]))
484485
(blockchainReader.getBestBlockNumber _).when().returns(0)
485486
(blockchainReader.getBlockHeaderByNumber _).when(*).returns(Some(BlockHelpers.genesis.header))
486-
(blockchain.saveNode _)
487+
(stateStorage.saveNode _)
487488
.when(*, *, *)
488489
.onCall { (hash, encoded, totalDifficulty) =>
489490
val expectedNode = nodeData.head

0 commit comments

Comments
 (0)