Skip to content

Commit 30caf6b

Browse files
author
Aurélien Richez
committed
[ETCM-1042] remove old branch interface
1 parent 591b6c0 commit 30caf6b

File tree

23 files changed

+53
-89
lines changed

23 files changed

+53
-89
lines changed

src/it/scala/io/iohk/ethereum/sync/RegularSyncItSpec.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class RegularSyncItSpec extends FreeSpecBase with Matchers with BeforeAndAfterAl
125125
_ <- peer1.startRegularSync()
126126
_ <- peer2.startRegularSync()
127127
_ <- peer2.addCheckpointedBlock(
128-
peer2.blockchainReader.getBlockByNumber(peer2.blockchainReader.getBestBranchNew(), 25).get
128+
peer2.blockchainReader.getBlockByNumber(peer2.blockchainReader.getBestBranch(), 25).get
129129
)
130130
_ <- peer2.waitForRegularSyncLoadLastBlock(length)
131131
_ <- peer1.connectToPeers(Set(peer2.node))
@@ -183,8 +183,8 @@ class RegularSyncItSpec extends FreeSpecBase with Matchers with BeforeAndAfterAl
183183
)
184184
)
185185
(
186-
peer1.blockchainReader.getBlockByNumber(peer1.blockchainReader.getBestBranchNew(), blockNumer + 1),
187-
peer2.blockchainReader.getBlockByNumber(peer2.blockchainReader.getBestBranchNew(), blockNumer + 1)
186+
peer1.blockchainReader.getBlockByNumber(peer1.blockchainReader.getBestBranch(), blockNumer + 1),
187+
peer2.blockchainReader.getBlockByNumber(peer2.blockchainReader.getBestBranch(), blockNumer + 1)
188188
) match {
189189
case (Some(blockP1), Some(blockP2)) =>
190190
assert(peer1.bl.getChainWeightByHash(blockP1.hash) == peer2.bl.getChainWeightByHash(blockP2.hash))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ object RegularSyncItSpecUtils {
189189
Task(blockNumber match {
190190
case Some(bNumber) =>
191191
blockchainReader
192-
.getBlockByNumber(blockchainReader.getBestBranchNew(), bNumber)
192+
.getBlockByNumber(blockchainReader.getBestBranch(), bNumber)
193193
.getOrElse(throw new RuntimeException(s"block by number: $bNumber doesn't exist"))
194194
case None => blockchainReader.getBestBlock().get
195195
}).flatMap { block =>

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import io.iohk.ethereum.db.storage.pruning.PruningMode
2626
import io.iohk.ethereum.domain.BlockHeader.HeaderExtraFields.HefEmpty
2727
import io.iohk.ethereum.domain.Blockchain
2828
import io.iohk.ethereum.domain._
29-
import io.iohk.ethereum.domain.branch.Branch
3029
import io.iohk.ethereum.jsonrpc.ProofService.EmptyStorageValueProof
3130
import io.iohk.ethereum.jsonrpc.ProofService.StorageProof
3231
import io.iohk.ethereum.jsonrpc.ProofService.StorageProofKey
@@ -102,8 +101,6 @@ object DumpChainApp
102101

103102
val blockchain: Blockchain = new BlockchainMock(genesisHash)
104103
val blockchainReader: BlockchainReader = mock[BlockchainReader]
105-
val bestChain: Branch = mock[Branch]
106-
(blockchainReader.getBestBranch _).expects().anyNumberOfTimes().returning(bestChain)
107104
(blockchainReader.getHashByBlockNumber _).expects(*, *).returning(Some(genesisHash))
108105

109106
val nodeStatus: NodeStatus =

src/main/scala/io/iohk/ethereum/consensus/pow/validators/OmmersValidator.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ trait OmmersValidator {
3030
)(implicit blockchainConfig: BlockchainConfig): Either[OmmersError, OmmersValid] = {
3131

3232
val getBlockHeaderByHash: ByteString => Option[BlockHeader] = blockchainReader.getBlockHeaderByHash
33-
val bestBranch = blockchainReader.getBestBranchNew()
33+
val bestBranch = blockchainReader.getBestBranch()
3434
val getNBlocksBack: (ByteString, Int) => List[Block] =
3535
(_, n) =>
3636
((blockNumber - n) until blockNumber).toList

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ class BlockchainImpl(
211211
val latestCheckpointNumber = getLatestCheckpointBlockNumber()
212212

213213
val blockNumberMappingUpdates =
214-
if (blockchainReader.getHashByBlockNumber(blockchainReader.getBestBranchNew(), block.number).contains(blockHash))
214+
if (blockchainReader.getHashByBlockNumber(blockchainReader.getBestBranch(), block.number).contains(blockHash))
215215
removeBlockNumberMapping(block.number)
216216
else blockNumberMappingStorage.emptyBatchUpdate
217217

@@ -280,7 +280,7 @@ class BlockchainImpl(
280280
): BigInt =
281281
if (blockNumberToCheck > 0) {
282282
val maybePreviousCheckpointBlockNumber = for {
283-
currentBlock <- blockchainReader.getBlockByNumber(blockchainReader.getBestBranchNew(), blockNumberToCheck)
283+
currentBlock <- blockchainReader.getBlockByNumber(blockchainReader.getBestBranch(), blockNumberToCheck)
284284
if currentBlock.hasCheckpoint &&
285285
currentBlock.number < latestCheckpointBlockNumber
286286
} yield currentBlock.number

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

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
package io.iohk.ethereum.domain
22

33
import akka.util.ByteString
4+
45
import io.iohk.ethereum.db.storage.AppStateStorage
56
import io.iohk.ethereum.db.storage.BlockBodiesStorage
67
import io.iohk.ethereum.db.storage.BlockHeadersStorage
78
import io.iohk.ethereum.db.storage.BlockNumberMappingStorage
89
import io.iohk.ethereum.db.storage.ReceiptStorage
910
import io.iohk.ethereum.db.storage.StateStorage
10-
import io.iohk.ethereum.domain.branch.{BestBranch, BestBranchSubset, Branch, EmptyBranch, NewBranch, NewEmptyBranch}
11+
import io.iohk.ethereum.domain.branch.BestBranchSubset
12+
import io.iohk.ethereum.domain.branch.Branch
13+
import io.iohk.ethereum.domain.branch.EmptyBranch
1114
import io.iohk.ethereum.mpt.MptNode
1215
import io.iohk.ethereum.utils.Logger
1316

@@ -69,28 +72,11 @@ class BlockchainReader(
6972

7073
/** get the current best stored branch */
7174
def getBestBranch(): Branch = {
72-
val number = getBestBlockNumber()
73-
blockNumberMappingStorage
74-
.get(number)
75-
.map(hash =>
76-
new BestBranch(
77-
hash,
78-
number,
79-
blockNumberMappingStorage,
80-
this
81-
)
82-
)
83-
.getOrElse(EmptyBranch)
84-
85-
}
86-
87-
/** get the current best stored branch */
88-
def getBestBranchNew(): NewBranch = {
8975
val number = getBestBlockNumber()
9076
blockNumberMappingStorage
9177
.get(number)
9278
.map(hash => BestBranchSubset(hash, number))
93-
.getOrElse(NewEmptyBranch)
79+
.getOrElse(EmptyBranch)
9480
}
9581

9682
def getBestBlockNumber(): BigInt = {
@@ -125,35 +111,35 @@ class BlockchainReader(
125111
getBlockByNumber(0).get
126112

127113
/** Returns a block inside this branch based on its number */
128-
def getBlockByNumber(branch: NewBranch, number: BigInt): Option[Block] = branch match {
114+
def getBlockByNumber(branch: Branch, number: BigInt): Option[Block] = branch match {
129115
case BestBranchSubset(_, tipBlockNumber) =>
130116
if (tipBlockNumber >= number && number >= 0) {
131117
for {
132118
hash <- getHashByBlockNumber(number)
133119
block <- getBlockByHash(hash)
134120
} yield block
135121
} else None
136-
case NewEmptyBranch => None
122+
case EmptyBranch => None
137123
}
138124

139125
/** Returns a block hash for the block at the given height if any */
140-
def getHashByBlockNumber(branch: NewBranch, number: BigInt): Option[ByteString] = branch match {
126+
def getHashByBlockNumber(branch: Branch, number: BigInt): Option[ByteString] = branch match {
141127
case BestBranchSubset(_, tipBlockNumber) =>
142128
if (tipBlockNumber >= number && number >= 0) {
143129
blockNumberMappingStorage.get(number)
144130
} else None
145131

146-
case NewEmptyBranch => None
132+
case EmptyBranch => None
147133
}
148134

149135
/** Checks if given block hash is in this chain. (i.e. is an ancestor of the tip block) */
150-
def isInChain(branch: NewBranch, hash: ByteString): Boolean = branch match {
136+
def isInChain(branch: Branch, hash: ByteString): Boolean = branch match {
151137
case BestBranchSubset(_, tipBlockNumber) =>
152138
(for {
153139
header <- getBlockHeaderByHash(hash) if header.number <= tipBlockNumber
154140
hash <- getHashByBlockNumber(branch, header.number)
155141
} yield header.hash == hash).getOrElse(false)
156-
case NewEmptyBranch => false
142+
case EmptyBranch => false
157143
}
158144

159145
/** Allows to query for a block based on it's number

src/main/scala/io/iohk/ethereum/domain/branch/BestBranch.scala

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/main/scala/io/iohk/ethereum/domain/branch/Branch.scala

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@ package io.iohk.ethereum.domain.branch
22

33
import akka.util.ByteString
44

5-
sealed trait NewBranch
5+
sealed trait Branch
66

7-
case class BestBranchSubset(tipBlockHash: ByteString, tipBlockNumber: BigInt) extends NewBranch
7+
case class BestBranchSubset(tipBlockHash: ByteString, tipBlockNumber: BigInt) extends Branch
88

9-
case object NewEmptyBranch extends NewBranch
10-
11-
/** An interface to manipulate blockchain branches */
12-
trait Branch {}
9+
case object EmptyBranch extends Branch

src/main/scala/io/iohk/ethereum/domain/branch/EmptyBranch$.scala

Lines changed: 0 additions & 4 deletions
This file was deleted.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class CheckpointingService(
3636
req.parentCheckpoint.forall(blockchainReader.getBlockHeaderByHash(_).exists(_.number < blockToReturnNum))
3737

3838
Task {
39-
blockchainReader.getBlockByNumber(blockchainReader.getBestBranchNew(), blockToReturnNum)
39+
blockchainReader.getBlockByNumber(blockchainReader.getBestBranch(), blockToReturnNum)
4040
}.flatMap {
4141
case Some(b) if isValidParent =>
4242
Task.now(Right(GetLatestBlockResponse(Some(BlockInfo(b.hash, b.number)))))

0 commit comments

Comments
 (0)