Skip to content

Commit 72b6a87

Browse files
committed
[ETCM-533] refactor StorageProof ADT
1 parent 4ba7d45 commit 72b6a87

File tree

3 files changed

+33
-30
lines changed

3 files changed

+33
-30
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import io.iohk.ethereum.db.storage.pruning.{ArchivePruning, PruningMode}
1414
import io.iohk.ethereum.db.storage.{AppStateStorage, StateStorage}
1515
import io.iohk.ethereum.domain.BlockHeader.HeaderExtraFields.HefEmpty
1616
import io.iohk.ethereum.domain.{Blockchain, UInt256, _}
17-
import io.iohk.ethereum.jsonrpc.ProofService.{StorageProof, StorageValueProof}
17+
import io.iohk.ethereum.jsonrpc.ProofService.{EmptyStorageValueProof, StorageProof, StorageProofKey, StorageValueProof}
1818
import io.iohk.ethereum.ledger.{InMemoryWorldStateProxy, InMemoryWorldStateProxyStorage}
1919
import io.iohk.ethereum.mpt.MptNode
2020
import io.iohk.ethereum.network.EtcPeerManagerActor.PeerInfo
@@ -150,7 +150,7 @@ class BlockchainMock(genesisHash: ByteString) extends Blockchain {
150150
rootHash: NodeHash,
151151
position: BigInt,
152152
ethCompatibleStorage: Boolean
153-
): StorageProof = StorageValueProof(position)
153+
): StorageProof = EmptyStorageValueProof(StorageProofKey(position))
154154

155155
override protected def getHashByBlockNumber(number: BigInt): Option[ByteString] = Some(genesisHash)
156156

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import io.iohk.ethereum.db.storage._
1212
import io.iohk.ethereum.db.storage.pruning.PruningMode
1313
import io.iohk.ethereum.domain
1414
import io.iohk.ethereum.domain.BlockchainImpl.BestBlockLatestCheckpointNumbers
15-
import io.iohk.ethereum.jsonrpc.ProofService.{StorageProof, StorageValueProof}
15+
import io.iohk.ethereum.jsonrpc.ProofService.StorageProof
1616
import io.iohk.ethereum.ledger.{InMemoryWorldStateProxy, InMemoryWorldStateProxyStorage}
1717
import io.iohk.ethereum.mpt.{MerklePatriciaTrie, MptNode}
1818
import io.iohk.ethereum.utils.{ByteStringUtils, Logger}
@@ -321,7 +321,7 @@ class BlockchainImpl(
321321
}
322322
val value: Option[BigInt] = mpt.get(position)
323323
val proof: Option[Vector[MptNode]] = mpt.getProof(position)
324-
StorageValueProof(position, value, proof)
324+
StorageProof(position, value, proof)
325325
}
326326

327327
private def persistBestBlocksData(): Unit = {

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

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import akka.util.ByteString
44
import cats.implicits._
55
import io.iohk.ethereum.consensus.blocks.BlockGenerator
66
import io.iohk.ethereum.domain.{Account, Address, Block, Blockchain, UInt256}
7-
import io.iohk.ethereum.jsonrpc.ProofService.StorageValueProof.asRlpSerializedNode
7+
import io.iohk.ethereum.jsonrpc.ProofService.StorageProof.asRlpSerializedNode
88
import io.iohk.ethereum.jsonrpc.ProofService.{
99
GetProofRequest,
1010
GetProofResponse,
@@ -33,42 +33,45 @@ object ProofService {
3333
case class GetProofResponse(proofAccount: ProofAccount)
3434

3535
sealed trait StorageProof {
36-
val key: StorageProofKey
37-
val value: BigInt
38-
val proof: Seq[ByteString]
36+
def key: StorageProofKey
37+
def value: BigInt
38+
def proof: Seq[ByteString]
3939
}
4040

41-
/**
42-
* Object proving a relationship of a storage value to an account's storageHash
43-
*
44-
* @param key storage proof key
45-
* @param value the value of the storage slot in its account tree
46-
* @param proof the set of node values needed to traverse a patricia merkle tree (from root to leaf) to retrieve a value
47-
*/
48-
case class StorageValueProof(
49-
key: StorageProofKey,
50-
value: BigInt = BigInt(0),
51-
proof: Seq[ByteString] = Seq.empty[MptNode].map(asRlpSerializedNode)
52-
) extends StorageProof
53-
54-
object StorageValueProof {
55-
def apply(position: BigInt, value: Option[BigInt], proof: Option[Vector[MptNode]]): StorageValueProof =
41+
object StorageProof {
42+
def apply(position: BigInt, value: Option[BigInt], proof: Option[Vector[MptNode]]): StorageProof =
5643
(value, proof) match {
5744
case (Some(value), Some(proof)) =>
58-
new StorageValueProof(key = StorageProofKey(position), value = value, proof = proof.map(asRlpSerializedNode))
45+
StorageValueProof(StorageProofKey(position), value, proof.map(asRlpSerializedNode))
5946
case (None, Some(proof)) =>
60-
new StorageValueProof(key = StorageProofKey(position), proof = proof.map(asRlpSerializedNode))
61-
case (Some(value), None) => new StorageValueProof(key = StorageProofKey(position), value = value)
62-
case (None, None) => new StorageValueProof(key = StorageProofKey(position))
47+
EmptyStorageValue(StorageProofKey(position), proof.map(asRlpSerializedNode))
48+
case (Some(value), None) => EmptyStorageProof(StorageProofKey(position), value)
49+
case (None, None) => EmptyStorageValueProof(StorageProofKey(position))
6350
}
6451

65-
def apply(position: BigInt): StorageValueProof =
66-
new StorageValueProof(key = StorageProofKey(position))
67-
6852
def asRlpSerializedNode(node: MptNode): ByteString =
6953
ByteString(MptTraversals.encodeNode(node))
7054
}
7155

56+
/**
57+
* Object proving a relationship of a storage value to an account's storageHash
58+
*
59+
* @param key storage proof key
60+
* @param value the value of the storage slot in its account tree
61+
* @param proof the set of node values needed to traverse a patricia merkle tree (from root to leaf) to retrieve a value
62+
*/
63+
case class EmptyStorageValueProof(key: StorageProofKey) extends StorageProof {
64+
val value: BigInt = BigInt(0)
65+
val proof: Seq[ByteString] = Seq.empty[MptNode].map(asRlpSerializedNode)
66+
}
67+
case class EmptyStorageValue(key: StorageProofKey, proof: Seq[ByteString]) extends StorageProof {
68+
val value: BigInt = BigInt(0)
69+
}
70+
case class EmptyStorageProof(key: StorageProofKey, value: BigInt) extends StorageProof {
71+
val proof: Seq[ByteString] = Seq.empty[MptNode].map(asRlpSerializedNode)
72+
}
73+
case class StorageValueProof(key: StorageProofKey, value: BigInt, proof: Seq[ByteString]) extends StorageProof
74+
7275
/** The key used to get the storage slot in its account tree */
7376
case class StorageProofKey(v: BigInt) extends AnyVal
7477

0 commit comments

Comments
 (0)