Skip to content

Commit fbf9ab8

Browse files
author
Aurélien Richez
committed
move genesisHeader and genesisBlock to BlockchainReader
1 parent 88d15b1 commit fbf9ab8

File tree

15 files changed

+23
-27
lines changed

15 files changed

+23
-27
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class BlockImporterItSpec
132132
)
133133
)
134134

135-
val genesisBlock = blockchain.genesisBlock
135+
val genesisBlock = blockchainReader.genesisBlock
136136
val block1: Block = getBlock(genesisBlock.number + 1, parent = genesisBlock.header.hash)
137137
// new chain is shorter but has a higher weight
138138
val newBlock2: Block = getBlock(genesisBlock.number + 2, difficulty = 108, parent = block1.header.hash)

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,6 @@ class BlockchainMock(genesisHash: ByteString) extends Blockchain {
210210

211211
override def isInChain(hash: NodeHash): Boolean = ???
212212

213-
override def genesisHeader: BlockHeader = ???
214-
215-
override def genesisBlock: Block = ???
216-
217213
override def getBackingMptStorage(blockNumber: BigInt): MptStorage = ???
218214

219215
override def getReadOnlyMptStorage(): MptStorage = ???

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,6 @@ trait Blockchain {
8282

8383
def saveNode(nodeHash: NodeHash, nodeEncoded: NodeEncoded, blockNumber: BigInt): Unit
8484

85-
def genesisHeader: BlockHeader
86-
87-
def genesisBlock: Block
88-
8985
/** Strict check if given block hash is in chain
9086
* Using any of getXXXByHash is not always accurate - after restart the best block is often lower than before restart
9187
* The result of that is returning data of blocks which we don't consider as a part of the chain anymore
@@ -210,10 +206,6 @@ class BlockchainImpl(
210206
def saveNode(nodeHash: NodeHash, nodeEncoded: NodeEncoded, blockNumber: BigInt): Unit =
211207
stateStorage.saveNode(nodeHash, nodeEncoded, blockNumber)
212208

213-
def genesisHeader: BlockHeader = blockchainReader.getBlockHeaderByNumber(0).get
214-
215-
def genesisBlock: Block = blockchainReader.getBlockByNumber(0).get
216-
217209
private def removeBlockNumberMapping(number: BigInt): DataSourceBatchUpdate =
218210
blockNumberMappingStorage.remove(number)
219211

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ class BlockchainReader(
110110
)
111111
)
112112
}
113+
114+
def genesisHeader: BlockHeader =
115+
getBlockHeaderByNumber(0).get
116+
117+
def genesisBlock: Block =
118+
getBlockByNumber(0).get
113119
}
114120

115121
object BlockchainReader {

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import io.iohk.ethereum.consensus.pow.miners.MockedMiner.MockedMinerResponses._
2020
import io.iohk.ethereum.crypto
2121
import io.iohk.ethereum.crypto.ECDSASignature
2222
import io.iohk.ethereum.domain.Block
23-
import io.iohk.ethereum.domain.Blockchain
2423
import io.iohk.ethereum.domain.BlockchainReader
2524
import io.iohk.ethereum.domain.Checkpoint
2625
import io.iohk.ethereum.jsonrpc.QAService.MineBlocksResponse.MinerResponseType
@@ -30,7 +29,6 @@ import io.iohk.ethereum.utils.Logger
3029

3130
class QAService(
3231
consensus: Consensus,
33-
blockchain: Blockchain,
3432
blockchainReader: BlockchainReader,
3533
checkpointBlockGenerator: CheckpointBlockGenerator,
3634
blockchainConfig: BlockchainConfig,
@@ -62,7 +60,7 @@ class QAService(
6260
blockchainReader
6361
.getBlockByHash(hashValue)
6462
.orElse(blockchainReader.getBestBlock())
65-
.getOrElse(blockchain.genesisBlock)
63+
.getOrElse(blockchainReader.genesisBlock)
6664
val checkpoint = generateCheckpoint(hashValue, req.privateKeys)
6765
val checkpointBlock: Block = checkpointBlockGenerator.generate(parent, checkpoint)
6866
syncController ! NewCheckpoint(checkpointBlock)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ class TestService(
185185
resetPreimages(genesisData)
186186

187187
// remove current genesis (Try because it may not exist)
188-
Try(blockchain.removeBlock(blockchain.genesisHeader.hash, withState = false))
188+
Try(blockchain.removeBlock(blockchainReader.genesisHeader.hash, withState = false))
189189
// TODO clear the storage ? When relaunching some tests on the same running test mantis client,
190190
// we end up with duplicate blocks because they are still present in the storage layer
191191
// for example: bcMultiChainTest/ChainAtoChainB_BlockHash_Istanbul

src/main/scala/io/iohk/ethereum/ledger/BranchResolution.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class BranchResolution(blockchain: Blockchain, blockchainReader: BlockchainReade
1616
InvalidBranch
1717
} else {
1818
val knownParentOrGenesis = blockchain
19-
.isInChain(headers.head.parentHash) || headers.head.hash == blockchain.genesisHeader.hash
19+
.isInChain(headers.head.parentHash) || headers.head.hash == blockchainReader.genesisHeader.hash
2020

2121
if (!knownParentOrGenesis)
2222
UnknownBranch

src/main/scala/io/iohk/ethereum/network/handshaker/EtcNodeStatus63ExchangeState.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ case class EtcNodeStatus63ExchangeState(
2727
networkId = peerConfiguration.networkId,
2828
totalDifficulty = chainWeight.totalDifficulty,
2929
bestHash = bestBlockHeader.hash,
30-
genesisHash = blockchain.genesisHeader.hash
30+
genesisHash = blockchainReader.genesisHeader.hash
3131
)
3232

3333
log.debug(s"sending status $status")

src/main/scala/io/iohk/ethereum/network/handshaker/EtcNodeStatus64ExchangeState.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ case class EtcNodeStatus64ExchangeState(
2626
networkId = peerConfiguration.networkId,
2727
chainWeight = chainWeight,
2828
bestHash = bestBlockHeader.hash,
29-
genesisHash = blockchain.genesisHeader.hash
29+
genesisHash = blockchainReader.genesisHeader.hash
3030
)
3131

3232
log.debug(s"sending status $status")

src/main/scala/io/iohk/ethereum/network/handshaker/EtcNodeStatusExchangeState.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ trait EtcNodeStatusExchangeState[T <: Message] extends InProgressState[PeerInfo]
3131
log.debug("Peer returned status ({})", status)
3232

3333
val validNetworkID = status.networkId == handshakerConfiguration.peerConfiguration.networkId
34-
val validGenesisHash = status.genesisHash == blockchain.genesisHeader.hash
34+
val validGenesisHash = status.genesisHash == blockchainReader.genesisHeader.hash
3535

3636
if (validNetworkID && validGenesisHash) {
3737
forkResolverOpt match {
@@ -46,7 +46,7 @@ trait EtcNodeStatusExchangeState[T <: Message] extends InProgressState[PeerInfo]
4646

4747
protected def getBestBlockHeader(): BlockHeader = {
4848
val bestBlockNumber = blockchainReader.getBestBlockNumber()
49-
blockchainReader.getBlockHeaderByNumber(bestBlockNumber).getOrElse(blockchain.genesisHeader)
49+
blockchainReader.getBlockHeaderByNumber(bestBlockNumber).getOrElse(blockchainReader.genesisHeader)
5050
}
5151

5252
protected def createStatusMsg(): MessageSerializable

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,6 @@ trait QaServiceBuilder {
592592
lazy val qaService =
593593
new QAService(
594594
consensus,
595-
blockchain,
596595
blockchainReader,
597596
checkpointBlockGenerator,
598597
blockchainConfig,

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,10 @@ class BlockchainHostActorSpec extends AnyFlatSpec with Matchers {
236236

237237
//then
238238
etcPeerManager.expectMsg(
239-
EtcPeerManagerActor.SendMessage(BlockHeaders(Seq(firstHeader, secondHeader, blockchain.genesisHeader)), peerId)
239+
EtcPeerManagerActor.SendMessage(
240+
BlockHeaders(Seq(firstHeader, secondHeader, blockchainReader.genesisHeader)),
241+
peerId
242+
)
240243
)
241244
}
242245

src/test/scala/io/iohk/ethereum/jsonrpc/QAServiceSpec.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ class QAServiceSpec
115115

116116
lazy val qaService = new QAService(
117117
testConsensus,
118-
blockchain,
119118
blockchainReader,
120119
checkpointBlockGenerator,
121120
blockchainConfig,

src/test/scala/io/iohk/ethereum/ledger/LedgerTestSetup.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ trait MockBlockchain extends MockFactory { self: TestSetupWithVmAndValidators =>
458458
(blockchainReader.getBlockByNumber _).expects(number).returning(block)
459459

460460
def setGenesisHeader(header: BlockHeader): Unit =
461-
(() => blockchain.genesisHeader).expects().returning(header)
461+
(() => blockchainReader.genesisHeader).expects().returning(header)
462462
}
463463

464464
trait EphemBlockchain extends TestSetupWithVmAndValidators with MockFactory {

src/test/scala/io/iohk/ethereum/network/EtcPeerManagerSpec.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,10 @@ class EtcPeerManagerSpec extends AnyFlatSpec with Matchers {
113113
val secondHeader: BlockHeader = baseBlockHeader.copy(number = peer1Info.maxBlockNumber + 2)
114114

115115
//when
116-
peersInfoHolder ! MessageFromPeer(BlockHeaders(Seq(firstHeader, secondHeader, blockchain.genesisHeader)), peer1.id)
116+
peersInfoHolder ! MessageFromPeer(
117+
BlockHeaders(Seq(firstHeader, secondHeader, blockchainReader.genesisHeader)),
118+
peer1.id
119+
)
117120

118121
//then
119122
requestSender.send(peersInfoHolder, PeerInfoRequest(peer1.id))

0 commit comments

Comments
 (0)