Skip to content

Commit f340fc5

Browse files
author
Aurélien Richez
authored
[ETCM-940] remove get transaction location from blockchain (#1016)
* remove unused blockchain parameters * remove getTransactionLocation from blockchain it is used only by EthTxService so EthTxService can directly use the storage * remove getChainWeightByNumber as it is unused * remove getStateStorage
1 parent b51076e commit f340fc5

File tree

12 files changed

+35
-43
lines changed

12 files changed

+35
-43
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,6 @@ class BlockchainMock(genesisHash: ByteString) extends Blockchain {
189189
override def getAccountStorageAt(rootHash: ByteString, position: BigInt, ethCompatibleStorage: Boolean): ByteString =
190190
???
191191

192-
override def getTransactionLocation(txHash: ByteString): Option[TransactionLocation] = ???
193-
194192
override type S = InMemoryWorldStateProxyStorage
195193
override type WS = InMemoryWorldStateProxy
196194

@@ -220,8 +218,6 @@ class BlockchainMock(genesisHash: ByteString) extends Blockchain {
220218

221219
override def save(block: Block, receipts: Seq[Receipt], weight: ChainWeight, saveAsBestBlock: Boolean): Unit = ???
222220

223-
override def getStateStorage: StateStorage = ???
224-
225221
override def getLatestCheckpointBlockNumber(): BigInt = ???
226222

227223
override def mptStateSavedKeys(): Observable[Either[RocksDbDataSource.IterationError, NodeHash]] = ???

src/main/scala/io/iohk/ethereum/blockchain/data/GenesisDataLoader.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import io.iohk.ethereum.blockchain.data.GenesisDataLoader.JsonSerializers.{
77
UInt256JsonSerializer
88
}
99
import io.iohk.ethereum.db.dataSource.EphemDataSource
10-
import io.iohk.ethereum.db.storage.{ArchiveNodeStorage, MptStorage, NodeStorage, SerializingMptStorage}
10+
import io.iohk.ethereum.db.storage.{ArchiveNodeStorage, MptStorage, NodeStorage, SerializingMptStorage, StateStorage}
1111
import io.iohk.ethereum.db.storage.StateStorage.GenesisDataLoad
1212
import io.iohk.ethereum.rlp.RLPList
1313
import io.iohk.ethereum.utils.BlockchainConfig
@@ -23,7 +23,8 @@ import org.bouncycastle.util.encoders.Hex
2323
import scala.io.Source
2424
import scala.util.{Failure, Success, Try}
2525

26-
class GenesisDataLoader(blockchain: Blockchain, blockchainConfig: BlockchainConfig) extends Logger {
26+
class GenesisDataLoader(blockchain: Blockchain, stateStorage: StateStorage, blockchainConfig: BlockchainConfig)
27+
extends Logger {
2728

2829
private val bloomLength = 512
2930
private val hashLength = 64
@@ -90,7 +91,6 @@ class GenesisDataLoader(blockchain: Blockchain, blockchainConfig: BlockchainConf
9091
def loadGenesisData(genesisData: GenesisData): Try[Unit] = {
9192
import MerklePatriciaTrie.defaultByteArraySerializable
9293

93-
val stateStorage = blockchain.getStateStorage
9494
val storage = stateStorage.getReadOnlyStorage
9595
val initalRootHash = MerklePatriciaTrie.EmptyRootHash
9696

src/main/scala/io/iohk/ethereum/db/components/StoragesComponent.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,5 @@ trait StoragesComponent {
3434

3535
val pruningMode: PruningMode
3636

37-
val cachedNodeStorage: CachedNodeStorage
3837
}
3938
}

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,6 @@ trait Blockchain {
135135
*/
136136
def getChainWeightByHash(blockhash: ByteString): Option[ChainWeight]
137137

138-
def getChainWeightByNumber(blockNumber: BigInt): Option[ChainWeight] =
139-
getHashByBlockNumber(blockNumber).flatMap(getChainWeightByHash)
140-
141-
def getTransactionLocation(txHash: ByteString): Option[TransactionLocation]
142-
143138
def getBestBlockNumber(): BigInt
144139

145140
def getBestBlock(): Option[Block]
@@ -212,8 +207,6 @@ trait Blockchain {
212207
ethCompatibleStorage: Boolean
213208
): WS
214209

215-
def getStateStorage: StateStorage
216-
217210
def mptStateSavedKeys(): Observable[Either[IterationError, ByteString]]
218211

219212
/**
@@ -237,18 +230,14 @@ class BlockchainImpl(
237230
protected val blockNumberMappingStorage: BlockNumberMappingStorage,
238231
protected val receiptStorage: ReceiptStorage,
239232
protected val evmCodeStorage: EvmCodeStorage,
240-
protected val pruningMode: PruningMode,
241233
protected val nodeStorage: NodeStorage,
242-
protected val cachedNodeStorage: CachedNodeStorage,
243234
protected val chainWeightStorage: ChainWeightStorage,
244235
protected val transactionMappingStorage: TransactionMappingStorage,
245236
protected val appStateStorage: AppStateStorage,
246237
protected val stateStorage: StateStorage
247238
) extends Blockchain
248239
with Logger {
249240

250-
override def getStateStorage: StateStorage = stateStorage
251-
252241
// There is always only one writer thread (ensured by actor), but can by many readers (api calls)
253242
// to ensure visibility of writes, needs to be volatile or atomic ref
254243
// Laziness required for mocking BlockchainImpl on tests
@@ -399,9 +388,6 @@ class BlockchainImpl(
399388
override def getMptNodeByHash(hash: ByteString): Option[MptNode] =
400389
stateStorage.getNode(hash)
401390

402-
override def getTransactionLocation(txHash: ByteString): Option[TransactionLocation] =
403-
transactionMappingStorage.get(txHash)
404-
405391
override def storeBlockBody(blockHash: ByteString, blockBody: BlockBody): DataSourceBatchUpdate = {
406392
blockBodiesStorage.put(blockHash, blockBody).and(saveTxsLocations(blockHash, blockBody))
407393
}
@@ -625,9 +611,7 @@ object BlockchainImpl {
625611
blockNumberMappingStorage = storages.blockNumberMappingStorage,
626612
receiptStorage = storages.receiptStorage,
627613
evmCodeStorage = storages.evmCodeStorage,
628-
pruningMode = storages.pruningMode,
629614
nodeStorage = storages.nodeStorage,
630-
cachedNodeStorage = storages.cachedNodeStorage,
631615
chainWeightStorage = storages.chainWeightStorage,
632616
transactionMappingStorage = storages.transactionMappingStorage,
633617
appStateStorage = storages.appStateStorage,

src/main/scala/io/iohk/ethereum/jsonrpc/EthTxService.scala

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ import io.iohk.ethereum.db.storage.TransactionMappingStorage.TransactionLocation
99
import io.iohk.ethereum.domain.Block
1010
import io.iohk.ethereum.domain.Receipt
1111
import io.iohk.ethereum.transactions.PendingTransactionsManager
12+
import io.iohk.ethereum.transactions.TransactionPicker
13+
import io.iohk.ethereum.ledger.Ledger
14+
import io.iohk.ethereum.db.storage.TransactionMappingStorage
15+
1216
import scala.util.Try
1317
import scala.util.Success
1418
import scala.util.Failure
1519
import akka.actor.ActorRef
1620
import scala.concurrent.duration.FiniteDuration
17-
import io.iohk.ethereum.transactions.TransactionPicker
18-
import io.iohk.ethereum.ledger.Ledger
1921

2022
object EthTxService {
2123
case class GetTransactionByHashRequest(txHash: ByteString) //rename to match request
@@ -39,7 +41,8 @@ class EthTxService(
3941
val blockchain: Blockchain,
4042
val ledger: Ledger,
4143
val pendingTransactionsManager: ActorRef,
42-
val getTransactionFromPoolTimeout: FiniteDuration
44+
val getTransactionFromPoolTimeout: FiniteDuration,
45+
transactionMappingStorage: TransactionMappingStorage
4346
) extends TransactionPicker
4447
with ResolveBlock {
4548
import EthTxService._
@@ -90,7 +93,7 @@ class EthTxService(
9093
maybeTxPendingResponse.map { txPending =>
9194
txPending.orElse {
9295
for {
93-
TransactionLocation(blockHash, txIndex) <- blockchain.getTransactionLocation(txHash)
96+
TransactionLocation(blockHash, txIndex) <- transactionMappingStorage.get(txHash)
9497
Block(header, body) <- blockchain.getBlockByHash(blockHash)
9598
stx <- body.transactionList.lift(txIndex)
9699
} yield TransactionData(stx, Some(header), Some(txIndex))
@@ -101,7 +104,7 @@ class EthTxService(
101104
def getTransactionReceipt(req: GetTransactionReceiptRequest): ServiceResponse[GetTransactionReceiptResponse] =
102105
Task {
103106
val result: Option[TransactionReceiptResponse] = for {
104-
TransactionLocation(blockHash, txIndex) <- blockchain.getTransactionLocation(req.txHash)
107+
TransactionLocation(blockHash, txIndex) <- transactionMappingStorage.get(req.txHash)
105108
Block(header, body) <- blockchain.getBlockByHash(blockHash)
106109
stx <- body.transactionList.lift(txIndex)
107110
receipts <- blockchain.getReceiptsByHash(blockHash)

src/main/scala/io/iohk/ethereum/jsonrpc/TestService.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import io.iohk.ethereum.blockchain.data.{GenesisAccount, GenesisData, GenesisDat
66
import io.iohk.ethereum.consensus.ConsensusConfig
77
import io.iohk.ethereum.consensus.blocks._
88
import io.iohk.ethereum.crypto.kec256
9+
import io.iohk.ethereum.db.storage.{StateStorage, TransactionMappingStorage}
910
import io.iohk.ethereum.{crypto, domain, rlp}
1011
import io.iohk.ethereum.domain.Block._
1112
import io.iohk.ethereum.domain.{Account, Address, Block, BlockchainImpl, UInt256}
@@ -110,10 +111,12 @@ object TestService {
110111

111112
class TestService(
112113
blockchain: BlockchainImpl,
114+
stateStorage: StateStorage,
113115
pendingTransactionsManager: ActorRef,
114116
consensusConfig: ConsensusConfig,
115117
testModeComponentsProvider: TestModeComponentsProvider,
116118
initialConfig: BlockchainConfig,
119+
transactionMappingStorage: TransactionMappingStorage,
117120
preimageCache: collection.concurrent.Map[ByteString, UInt256]
118121
)(implicit
119122
scheduler: Scheduler
@@ -155,7 +158,7 @@ class TestService(
155158
Try(blockchain.removeBlock(blockchain.genesisHeader.hash, withState = false))
156159

157160
// load the new genesis
158-
val genesisDataLoader = new GenesisDataLoader(blockchain, currentConfig)
161+
val genesisDataLoader = new GenesisDataLoader(blockchain, stateStorage, currentConfig)
159162
genesisDataLoader.loadGenesisData(genesisData)
160163

161164
//save account codes to world state
@@ -216,7 +219,7 @@ class TestService(
216219
private def storeGenesisAccountStorageData(accounts: Map[String, GenesisAccount]): Unit = {
217220
val emptyStorage = domain.EthereumUInt256Mpt.storageMpt(
218221
Account.EmptyStorageRootHash,
219-
blockchain.getStateStorage.getBackingStorage(0)
222+
stateStorage.getBackingStorage(0)
220223
)
221224
val storagesToPersist = accounts
222225
.flatMap(pair => pair._2.storage)
@@ -409,7 +412,7 @@ class TestService(
409412
import io.iohk.ethereum.network.p2p.messages.ETH63.TxLogEntryImplicits.TxLogEntryEnc
410413

411414
val result = for {
412-
transactionLocation <- blockchain.getTransactionLocation(request.transactionHash)
415+
transactionLocation <- transactionMappingStorage.get(request.transactionHash)
413416
block <- blockchain.getBlockByHash(transactionLocation.blockHash)
414417
_ <- block.body.transactionList.lift(transactionLocation.txIndex)
415418
receipts <- blockchain.getReceiptsByHash(block.header.hash)

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,15 +368,18 @@ trait TestServiceBuilder {
368368
with BlockchainConfigBuilder
369369
with VmBuilder
370370
with TestmodeConsensusBuilder
371-
with TestModeServiceBuilder =>
371+
with TestModeServiceBuilder
372+
with StorageBuilder =>
372373

373374
lazy val testService =
374375
new TestService(
375376
blockchain,
377+
storagesInstance.storages.stateStorage,
376378
pendingTransactionsManager,
377379
consensusConfig,
378380
testModeComponentsProvider,
379381
blockchainConfig,
382+
storagesInstance.storages.transactionMappingStorage,
380383
preimages
381384
)(scheduler)
382385
}
@@ -439,13 +442,18 @@ trait EthMiningServiceBuilder {
439442
)
440443
}
441444
trait EthTxServiceBuilder {
442-
self: BlockchainBuilder with PendingTransactionsManagerBuilder with LedgerBuilder with TxPoolConfigBuilder =>
445+
self: BlockchainBuilder
446+
with PendingTransactionsManagerBuilder
447+
with LedgerBuilder
448+
with TxPoolConfigBuilder
449+
with StorageBuilder =>
443450

444451
lazy val ethTxService = new EthTxService(
445452
blockchain,
446453
ledger,
447454
pendingTransactionsManager,
448-
txPoolConfig.getTransactionFromPoolTimeout
455+
txPoolConfig.getTransactionFromPoolTimeout,
456+
storagesInstance.storages.transactionMappingStorage
449457
)
450458
}
451459

@@ -779,7 +787,8 @@ object ShutdownHookBuilder extends ShutdownHookBuilder with Logger
779787
trait GenesisDataLoaderBuilder {
780788
self: BlockchainBuilder with StorageBuilder with BlockchainConfigBuilder =>
781789

782-
lazy val genesisDataLoader = new GenesisDataLoader(blockchain, blockchainConfig)
790+
lazy val genesisDataLoader =
791+
new GenesisDataLoader(blockchain, storagesInstance.storages.stateStorage, blockchainConfig)
783792
}
784793

785794
/** Provides the basic functionality of a Node, except the consensus algorithm.

src/main/scala/io/iohk/ethereum/testmode/TestBlockchainBuilder.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ trait TestBlockchainBuilder extends BlockchainBuilder {
2020
blockNumberMappingStorage = storages.blockNumberMappingStorage,
2121
receiptStorage = storages.receiptStorage,
2222
evmCodeStorage = storages.evmCodeStorage,
23-
pruningMode = storages.pruningMode,
2423
nodeStorage = storages.nodeStorage,
25-
cachedNodeStorage = storages.cachedNodeStorage,
2624
chainWeightStorage = storages.chainWeightStorage,
2725
transactionMappingStorage = storages.transactionMappingStorage,
2826
appStateStorage = storages.appStateStorage,

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,7 @@ class StateSyncSpec
114114
blockNumberMappingStorage = storages.blockNumberMappingStorage,
115115
receiptStorage = storages.receiptStorage,
116116
evmCodeStorage = storages.evmCodeStorage,
117-
pruningMode = storages.pruningMode,
118117
nodeStorage = storages.nodeStorage,
119-
cachedNodeStorage = storages.cachedNodeStorage,
120118
chainWeightStorage = storages.chainWeightStorage,
121119
transactionMappingStorage = storages.transactionMappingStorage,
122120
appStateStorage = storages.appStateStorage,

src/test/scala/io/iohk/ethereum/consensus/blocks/BlockGeneratorSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper
691691
)
692692
override lazy val blockchainConfig = baseBlockchainConfig
693693

694-
val genesisDataLoader = new GenesisDataLoader(blockchain, blockchainConfig)
694+
val genesisDataLoader = new GenesisDataLoader(blockchain, storagesInstance.storages.stateStorage, blockchainConfig)
695695
genesisDataLoader.loadGenesisData()
696696

697697
val bestBlock = blockchain.getBestBlock()

0 commit comments

Comments
 (0)