Skip to content

Commit 344ac36

Browse files
committed
ETCM-845: Through rpc expose only blocks that are saved to storage
1 parent 9d44cf8 commit 344ac36

File tree

5 files changed

+8
-4
lines changed

5 files changed

+8
-4
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ trait Blockchain {
142142

143143
def getBestBlockNumber(): BigInt
144144

145+
def getBestSavedBlockNumber(): BigInt
146+
145147
def getBestBlock(): Option[Block]
146148

147149
def getLatestCheckpointBlockNumber(): BigInt
@@ -286,6 +288,8 @@ class BlockchainImpl(
286288
bestKnownBlockNumber
287289
}
288290

291+
override def getBestSavedBlockNumber(): BigInt = appStateStorage.getBestBlockNumber()
292+
289293
override def getLatestCheckpointBlockNumber(): BigInt =
290294
bestKnownBlockAndLatestCheckpoint.get().latestCheckpointNumber
291295

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ class EthProofService(blockchain: Blockchain, blockGenerator: BlockGenerator, et
210210
blockParam match {
211211
case BlockParam.WithNumber(blockNumber) => getBlock(blockNumber).map(ResolvedBlock(_, pendingState = None))
212212
case BlockParam.Earliest => getBlock(0).map(ResolvedBlock(_, pendingState = None))
213-
case BlockParam.Latest => getBlock(blockchain.getBestBlockNumber()).map(ResolvedBlock(_, pendingState = None))
213+
case BlockParam.Latest => getBlock(blockchain.getBestSavedBlockNumber()).map(ResolvedBlock(_, pendingState = None))
214214
case BlockParam.Pending =>
215215
blockGenerator.getPendingBlockAndState
216216
.map(pb => ResolvedBlock(pb.pendingBlock.block, pendingState = Some(pb.worldState)))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class EthTxService(
151151

152152
def getGetGasPrice(req: GetGasPriceRequest): ServiceResponse[GetGasPriceResponse] = {
153153
val blockDifference = 30
154-
val bestBlock = blockchain.getBestBlockNumber()
154+
val bestBlock = blockchain.getBestSavedBlockNumber()
155155

156156
Task {
157157
val gasPrice = ((bestBlock - blockDifference) to bestBlock)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ class PersonalService(
221221
}
222222

223223
private def getCurrentAccount(address: Address): Option[Account] =
224-
blockchain.getAccount(address, blockchain.getBestBlockNumber())
224+
blockchain.getAccount(address, blockchain.getBestSavedBlockNumber())
225225

226226
private def getMessageToSign(message: ByteString) = {
227227
val prefixed: Array[Byte] =

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ trait ResolveBlock {
2222
blockParam match {
2323
case BlockParam.WithNumber(blockNumber) => getBlock(blockNumber).map(ResolvedBlock(_, pendingState = None))
2424
case BlockParam.Earliest => getBlock(0).map(ResolvedBlock(_, pendingState = None))
25-
case BlockParam.Latest => getBlock(blockchain.getBestBlockNumber()).map(ResolvedBlock(_, pendingState = None))
25+
case BlockParam.Latest => getBlock(blockchain.getBestSavedBlockNumber()).map(ResolvedBlock(_, pendingState = None))
2626
case BlockParam.Pending =>
2727
ledger.consensus.blockGenerator.getPendingBlockAndState
2828
.map(pb => ResolvedBlock(pb.pendingBlock.block, pendingState = Some(pb.worldState)))

0 commit comments

Comments
 (0)