mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-02-24 17:58:30 +00:00
Remove usage of aliases for Hash32 such as BlockHash (#2707)
These create only confusion as if they are actual different types and it is within their usage already clear what they are about because of the name of the variable or the function. They are also nowhere aliased like this in any of the Portal specification.
This commit is contained in:
parent
e1c942ccef
commit
833719a866
@ -17,7 +17,6 @@ type
|
||||
|
||||
ContentId* = UInt256
|
||||
ContentKeyByteList* = ByteList[2048] # The encoded content key
|
||||
BlockHash* = Hash32
|
||||
|
||||
func fromSszBytes*(T: type Hash32, data: openArray[byte]): T {.raises: [SszError].} =
|
||||
if data.len != sizeof(result):
|
||||
|
@ -38,11 +38,11 @@ type
|
||||
|
||||
BlockDataTable* = Table[string, BlockData]
|
||||
|
||||
iterator blockHashes*(blockData: BlockDataTable): BlockHash =
|
||||
iterator blockHashes*(blockData: BlockDataTable): Hash32 =
|
||||
for k, v in blockData:
|
||||
var blockHash: BlockHash
|
||||
var blockHash: Hash32
|
||||
try:
|
||||
blockHash.data = hexToByteArray[sizeof(BlockHash)](k)
|
||||
blockHash.data = hexToByteArray[sizeof(Hash32)](k)
|
||||
except ValueError as e:
|
||||
error "Invalid hex for block hash", error = e.msg, number = v.number
|
||||
continue
|
||||
@ -54,9 +54,9 @@ func readBlockData*(
|
||||
): Result[seq[(ContentKey, seq[byte])], string] =
|
||||
var res: seq[(ContentKey, seq[byte])]
|
||||
|
||||
var blockHash: BlockHash
|
||||
var blockHash: Hash32
|
||||
try:
|
||||
blockHash.data = hexToByteArray[sizeof(BlockHash)](hash)
|
||||
blockHash.data = hexToByteArray[sizeof(Hash32)](hash)
|
||||
except ValueError as e:
|
||||
return err("Invalid hex for blockhash, number " & $blockData.number & ": " & e.msg)
|
||||
|
||||
@ -127,9 +127,9 @@ func readBlockHeader*(blockData: BlockData): Result[Header, string] =
|
||||
func readHeaderData*(
|
||||
hash: string, blockData: BlockData, verify = false
|
||||
): Result[(ContentKey, seq[byte]), string] =
|
||||
var blockHash: BlockHash
|
||||
var blockHash: Hash32
|
||||
try:
|
||||
blockHash.data = hexToByteArray[sizeof(BlockHash)](hash)
|
||||
blockHash.data = hexToByteArray[sizeof(Hash32)](hash)
|
||||
except ValueError as e:
|
||||
return err("Invalid hex for blockhash, number " & $blockData.number & ": " & e.msg)
|
||||
|
||||
|
@ -28,7 +28,7 @@ type
|
||||
epochRecordDeprecated = 0x03
|
||||
|
||||
BlockKey = object
|
||||
blockHash: BlockHash
|
||||
blockHash: Hash32
|
||||
|
||||
EpochRecordKeyDeprecated = object
|
||||
epochHash: Digest
|
||||
|
@ -33,7 +33,7 @@ type
|
||||
blockNumber = 0x03
|
||||
|
||||
BlockKey* = object
|
||||
blockHash*: BlockHash
|
||||
blockHash*: Hash32
|
||||
|
||||
BlockNumberKey* = object
|
||||
blockNumber*: uint64
|
||||
@ -49,19 +49,19 @@ type
|
||||
of blockNumber:
|
||||
blockNumberKey*: BlockNumberKey
|
||||
|
||||
func blockHeaderContentKey*(id: BlockHash | uint64): ContentKey =
|
||||
when id is BlockHash:
|
||||
func blockHeaderContentKey*(id: Hash32 | uint64): ContentKey =
|
||||
when id is Hash32:
|
||||
ContentKey(contentType: blockHeader, blockHeaderKey: BlockKey(blockHash: id))
|
||||
else:
|
||||
ContentKey(
|
||||
contentType: blockNumber, blockNumberKey: BlockNumberKey(blockNumber: id)
|
||||
)
|
||||
|
||||
func blockBodyContentKey*(hash: BlockHash): ContentKey =
|
||||
ContentKey(contentType: blockBody, blockBodyKey: BlockKey(blockHash: hash))
|
||||
func blockBodyContentKey*(blockHash: Hash32): ContentKey =
|
||||
ContentKey(contentType: blockBody, blockBodyKey: BlockKey(blockHash: blockHash))
|
||||
|
||||
func receiptsContentKey*(hash: BlockHash): ContentKey =
|
||||
ContentKey(contentType: receipts, receiptsKey: BlockKey(blockHash: hash))
|
||||
func receiptsContentKey*(blockHash: Hash32): ContentKey =
|
||||
ContentKey(contentType: receipts, receiptsKey: BlockKey(blockHash: blockHash))
|
||||
|
||||
func encode*(contentKey: ContentKey): ContentKeyByteList =
|
||||
ContentKeyByteList.init(SSZ.encode(contentKey))
|
||||
|
@ -184,8 +184,8 @@ template calcReceiptsRoot*(receipts: PortalReceipts): Hash32 =
|
||||
template calcWithdrawalsRoot*(receipts: Withdrawals): Hash32 =
|
||||
calcRootHash(receipts)
|
||||
|
||||
func validateBlockHeader*(header: Header, hash: BlockHash): Result[void, string] =
|
||||
if not (header.rlpHash() == hash):
|
||||
func validateBlockHeader*(header: Header, blockHash: Hash32): Result[void, string] =
|
||||
if not (header.rlpHash() == blockHash):
|
||||
err("Block header hash does not match")
|
||||
else:
|
||||
ok()
|
||||
@ -197,7 +197,7 @@ func validateBlockHeader*(header: Header, number: uint64): Result[void, string]
|
||||
ok()
|
||||
|
||||
func validateBlockHeaderBytes*(
|
||||
bytes: openArray[byte], id: uint64 | BlockHash
|
||||
bytes: openArray[byte], id: uint64 | Hash32
|
||||
): Result[Header, string] =
|
||||
let header = ?decodeRlp(bytes, Header)
|
||||
|
||||
@ -411,7 +411,7 @@ func verifyHeader(
|
||||
verifyHeader(n.accumulator, header, proof)
|
||||
|
||||
proc getVerifiedBlockHeader*(
|
||||
n: HistoryNetwork, id: BlockHash | uint64
|
||||
n: HistoryNetwork, id: Hash32 | uint64
|
||||
): Future[Opt[Header]] {.async: (raises: [CancelledError]).} =
|
||||
let
|
||||
contentKey = blockHeaderContentKey(id).encode()
|
||||
@ -460,18 +460,18 @@ proc getVerifiedBlockHeader*(
|
||||
return Opt.none(Header)
|
||||
|
||||
proc getBlockBody*(
|
||||
n: HistoryNetwork, hash: BlockHash, header: Header
|
||||
n: HistoryNetwork, blockHash: Hash32, header: Header
|
||||
): Future[Opt[BlockBody]] {.async: (raises: [CancelledError]).} =
|
||||
if header.txRoot == EMPTY_ROOT_HASH and header.ommersHash == EMPTY_UNCLE_HASH:
|
||||
# Short path for empty body indicated by txRoot and ommersHash
|
||||
return Opt.some(BlockBody(transactions: @[], uncles: @[]))
|
||||
|
||||
let
|
||||
contentKey = blockBodyContentKey(hash).encode()
|
||||
contentKey = blockBodyContentKey(blockHash).encode()
|
||||
contentId = contentKey.toContentId()
|
||||
|
||||
logScope:
|
||||
hash
|
||||
blockHash
|
||||
contentKey
|
||||
|
||||
let bodyFromDb = n.contentDB.get(BlockBody, contentId, header)
|
||||
@ -502,7 +502,7 @@ proc getBlockBody*(
|
||||
return Opt.none(BlockBody)
|
||||
|
||||
proc getBlock*(
|
||||
n: HistoryNetwork, id: BlockHash | uint64
|
||||
n: HistoryNetwork, id: Hash32 | uint64
|
||||
): Future[Opt[Block]] {.async: (raises: [CancelledError]).} =
|
||||
debug "Trying to retrieve block", id
|
||||
|
||||
@ -514,7 +514,7 @@ proc getBlock*(
|
||||
warn "Failed to get header when getting block", id
|
||||
return Opt.none(Block)
|
||||
hash =
|
||||
when id is BlockHash:
|
||||
when id is Hash32:
|
||||
id
|
||||
else:
|
||||
header.rlpHash()
|
||||
@ -526,25 +526,25 @@ proc getBlock*(
|
||||
|
||||
proc getBlockHashByNumber*(
|
||||
n: HistoryNetwork, blockNumber: uint64
|
||||
): Future[Result[BlockHash, string]] {.async: (raises: [CancelledError]).} =
|
||||
): Future[Result[Hash32, string]] {.async: (raises: [CancelledError]).} =
|
||||
let header = (await n.getVerifiedBlockHeader(blockNumber)).valueOr:
|
||||
return err("Cannot retrieve block header for given block number")
|
||||
|
||||
ok(header.rlpHash())
|
||||
|
||||
proc getReceipts*(
|
||||
n: HistoryNetwork, hash: BlockHash, header: Header
|
||||
n: HistoryNetwork, blockHash: Hash32, header: Header
|
||||
): Future[Opt[seq[Receipt]]] {.async: (raises: [CancelledError]).} =
|
||||
if header.receiptsRoot == EMPTY_ROOT_HASH:
|
||||
# Short path for empty receipts indicated by receipts root
|
||||
return Opt.some(newSeq[Receipt]())
|
||||
|
||||
let
|
||||
contentKey = receiptsContentKey(hash).encode()
|
||||
contentKey = receiptsContentKey(blockHash).encode()
|
||||
contentId = contentKey.toContentId()
|
||||
|
||||
logScope:
|
||||
hash
|
||||
blockHash
|
||||
contentKey
|
||||
|
||||
let receiptsFromDb = n.getContentFromDb(seq[Receipt], contentId)
|
||||
|
@ -47,7 +47,7 @@ const
|
||||
|
||||
type
|
||||
HeaderRecord* = object
|
||||
blockHash*: BlockHash
|
||||
blockHash*: Hash32
|
||||
totalDifficulty*: UInt256
|
||||
|
||||
EpochRecord* = List[HeaderRecord, EPOCH_SIZE]
|
||||
|
@ -21,10 +21,6 @@ import
|
||||
export ssz_serialization, common_types, hash, results
|
||||
|
||||
type
|
||||
NodeHash* = Hash32
|
||||
CodeHash* = Hash32
|
||||
AddressHash* = Hash32
|
||||
|
||||
ContentType* = enum
|
||||
# Note: Need to add this unused value as a case object with an enum without
|
||||
# a 0 valueis not allowed: "low(contentType) must be 0 for discriminant".
|
||||
@ -40,16 +36,16 @@ type
|
||||
|
||||
AccountTrieNodeKey* = object
|
||||
path*: Nibbles
|
||||
nodeHash*: NodeHash
|
||||
nodeHash*: Hash32
|
||||
|
||||
ContractTrieNodeKey* = object
|
||||
addressHash*: AddressHash
|
||||
addressHash*: Hash32
|
||||
path*: Nibbles
|
||||
nodeHash*: NodeHash
|
||||
nodeHash*: Hash32
|
||||
|
||||
ContractCodeKey* = object
|
||||
addressHash*: AddressHash
|
||||
codeHash*: CodeHash
|
||||
addressHash*: Hash32
|
||||
codeHash*: Hash32
|
||||
|
||||
ContentKey* = object
|
||||
case contentType*: ContentType
|
||||
@ -64,21 +60,16 @@ type
|
||||
|
||||
ContentKeyType* = AccountTrieNodeKey | ContractTrieNodeKey | ContractCodeKey
|
||||
|
||||
func init*(
|
||||
T: type AccountTrieNodeKey, path: Nibbles, nodeHash: NodeHash
|
||||
): T {.inline.} =
|
||||
func init*(T: type AccountTrieNodeKey, path: Nibbles, nodeHash: Hash32): T {.inline.} =
|
||||
T(path: path, nodeHash: nodeHash)
|
||||
|
||||
func init*(
|
||||
T: type ContractTrieNodeKey,
|
||||
addressHash: AddressHash,
|
||||
path: Nibbles,
|
||||
nodeHash: NodeHash,
|
||||
T: type ContractTrieNodeKey, addressHash: Hash32, path: Nibbles, nodeHash: Hash32
|
||||
): T {.inline.} =
|
||||
T(addressHash: addressHash, path: path, nodeHash: nodeHash)
|
||||
|
||||
func init*(
|
||||
T: type ContractCodeKey, addressHash: AddressHash, codeHash: CodeHash
|
||||
T: type ContractCodeKey, addressHash: Hash32, codeHash: Hash32
|
||||
): T {.inline.} =
|
||||
T(addressHash: addressHash, codeHash: codeHash)
|
||||
|
||||
|
@ -26,7 +26,7 @@ type
|
||||
|
||||
AccountTrieNodeOffer* = object
|
||||
proof*: TrieProof
|
||||
blockHash*: BlockHash
|
||||
blockHash*: Hash32
|
||||
|
||||
AccountTrieNodeRetrieval* = object
|
||||
node*: TrieNode
|
||||
@ -34,7 +34,7 @@ type
|
||||
ContractTrieNodeOffer* = object
|
||||
storageProof*: TrieProof
|
||||
accountProof*: TrieProof
|
||||
blockHash*: BlockHash
|
||||
blockHash*: Hash32
|
||||
|
||||
ContractTrieNodeRetrieval* = object
|
||||
node*: TrieNode
|
||||
@ -42,7 +42,7 @@ type
|
||||
ContractCodeOffer* = object
|
||||
code*: Bytecode
|
||||
accountProof*: TrieProof
|
||||
blockHash*: BlockHash
|
||||
blockHash*: Hash32
|
||||
|
||||
ContractCodeRetrieval* = object
|
||||
code*: Bytecode
|
||||
@ -53,7 +53,7 @@ type
|
||||
ContentValueType* = ContentOfferType | ContentRetrievalType
|
||||
|
||||
func init*(
|
||||
T: type AccountTrieNodeOffer, proof: TrieProof, blockHash: BlockHash
|
||||
T: type AccountTrieNodeOffer, proof: TrieProof, blockHash: Hash32
|
||||
): T {.inline.} =
|
||||
T(proof: proof, blockHash: blockHash)
|
||||
|
||||
@ -64,7 +64,7 @@ func init*(
|
||||
T: type ContractTrieNodeOffer,
|
||||
storageProof: TrieProof,
|
||||
accountProof: TrieProof,
|
||||
blockHash: BlockHash,
|
||||
blockHash: Hash32,
|
||||
): T {.inline.} =
|
||||
T(storageProof: storageProof, accountProof: accountProof, blockHash: blockHash)
|
||||
|
||||
@ -75,7 +75,7 @@ func init*(
|
||||
T: type ContractCodeOffer,
|
||||
code: Bytecode,
|
||||
accountProof: TrieProof,
|
||||
blockHash: BlockHash,
|
||||
blockHash: Hash32,
|
||||
): T {.inline.} =
|
||||
T(code: code, accountProof: accountProof, blockHash: blockHash)
|
||||
|
||||
|
@ -23,7 +23,7 @@ logScope:
|
||||
|
||||
proc getNextNodeHash(
|
||||
trieNode: TrieNode, nibbles: UnpackedNibbles, nibbleIdx: var int
|
||||
): Opt[(Nibbles, NodeHash)] =
|
||||
): Opt[(Nibbles, Hash32)] =
|
||||
# the trie node should have already been validated against the lookup hash
|
||||
# so we expect that no rlp errors should be possible
|
||||
try:
|
||||
@ -41,7 +41,7 @@ proc getNextNodeHash(
|
||||
|
||||
let nextHashBytes = trieNodeRlp.listElem(nextNibble.int).toBytes()
|
||||
if nextHashBytes.len() == 0:
|
||||
return Opt.none((Nibbles, NodeHash))
|
||||
return Opt.none((Nibbles, Hash32))
|
||||
|
||||
nibbleIdx += 1
|
||||
return Opt.some(
|
||||
@ -56,16 +56,16 @@ proc getNextNodeHash(
|
||||
if unpackedPrefix != nibbles[nibbleIdx ..< nibbleIdx + unpackedPrefix.len()]:
|
||||
# The nibbles don't match so we stop the search and don't increment
|
||||
# the nibble index to indicate how many nibbles were consumed
|
||||
return Opt.none((Nibbles, NodeHash))
|
||||
return Opt.none((Nibbles, Hash32))
|
||||
|
||||
nibbleIdx += prefix.unpackNibbles().len()
|
||||
if isLeaf:
|
||||
return Opt.none((Nibbles, NodeHash))
|
||||
return Opt.none((Nibbles, Hash32))
|
||||
|
||||
# extension node
|
||||
let nextHashBytes = trieNodeRlp.listElem(1).toBytes()
|
||||
if nextHashBytes.len() == 0:
|
||||
return Opt.none((Nibbles, NodeHash))
|
||||
return Opt.none((Nibbles, Hash32))
|
||||
|
||||
Opt.some((nibbles[0 ..< nibbleIdx].packNibbles(), Hash32.fromBytes(nextHashBytes)))
|
||||
except RlpError as e:
|
||||
@ -263,7 +263,7 @@ proc getProofsByStateRoot*(
|
||||
|
||||
# Used by: eth_getBalance,
|
||||
proc getBalance*(
|
||||
n: StateNetwork, blockNumOrHash: uint64 | BlockHash, address: Address
|
||||
n: StateNetwork, blockNumOrHash: uint64 | Hash32, address: Address
|
||||
): Future[Opt[UInt256]] {.async: (raises: [CancelledError]).} =
|
||||
let stateRoot = (await n.getStateRootByBlockNumOrHash(blockNumOrHash)).valueOr:
|
||||
warn "Failed to get state root by block number or hash", blockNumOrHash
|
||||
@ -273,7 +273,7 @@ proc getBalance*(
|
||||
|
||||
# Used by: eth_getTransactionCount
|
||||
proc getTransactionCount*(
|
||||
n: StateNetwork, blockNumOrHash: uint64 | BlockHash, address: Address
|
||||
n: StateNetwork, blockNumOrHash: uint64 | Hash32, address: Address
|
||||
): Future[Opt[AccountNonce]] {.async: (raises: [CancelledError]).} =
|
||||
let stateRoot = (await n.getStateRootByBlockNumOrHash(blockNumOrHash)).valueOr:
|
||||
warn "Failed to get state root by block number or hash", blockNumOrHash
|
||||
@ -283,10 +283,7 @@ proc getTransactionCount*(
|
||||
|
||||
# Used by: eth_getStorageAt
|
||||
proc getStorageAt*(
|
||||
n: StateNetwork,
|
||||
blockNumOrHash: uint64 | BlockHash,
|
||||
address: Address,
|
||||
slotKey: UInt256,
|
||||
n: StateNetwork, blockNumOrHash: uint64 | Hash32, address: Address, slotKey: UInt256
|
||||
): Future[Opt[UInt256]] {.async: (raises: [CancelledError]).} =
|
||||
let stateRoot = (await n.getStateRootByBlockNumOrHash(blockNumOrHash)).valueOr:
|
||||
warn "Failed to get state root by block number or hash", blockNumOrHash
|
||||
@ -296,7 +293,7 @@ proc getStorageAt*(
|
||||
|
||||
# Used by: eth_getCode
|
||||
proc getCode*(
|
||||
n: StateNetwork, blockNumOrHash: uint64 | BlockHash, address: Address
|
||||
n: StateNetwork, blockNumOrHash: uint64 | Hash32, address: Address
|
||||
): Future[Opt[Bytecode]] {.async: (raises: [CancelledError]).} =
|
||||
let stateRoot = (await n.getStateRootByBlockNumOrHash(blockNumOrHash)).valueOr:
|
||||
warn "Failed to get state root by block number or hash", blockNumOrHash
|
||||
@ -307,7 +304,7 @@ proc getCode*(
|
||||
# Used by: eth_getProof
|
||||
proc getProofs*(
|
||||
n: StateNetwork,
|
||||
blockNumOrHash: uint64 | BlockHash,
|
||||
blockNumOrHash: uint64 | Hash32,
|
||||
address: Address,
|
||||
slotKeys: seq[UInt256],
|
||||
): Future[Opt[Proofs]] {.async: (raises: [CancelledError]).} =
|
||||
|
@ -130,7 +130,7 @@ proc getContractCode*(
|
||||
n.getContent(key, ContractCodeRetrieval)
|
||||
|
||||
proc getStateRootByBlockNumOrHash*(
|
||||
n: StateNetwork, blockNumOrHash: uint64 | BlockHash
|
||||
n: StateNetwork, blockNumOrHash: uint64 | Hash32
|
||||
): Future[Opt[Hash32]] {.async: (raises: [CancelledError]).} =
|
||||
if n.historyNetwork.isNone():
|
||||
warn "History network is not available"
|
||||
|
@ -91,7 +91,7 @@ proc historyGetContent(
|
||||
ok(content)
|
||||
|
||||
proc historyGetBlockHeader*(
|
||||
client: PortalRpcClient, blockHash: BlockHash, validateContent = true
|
||||
client: PortalRpcClient, blockHash: Hash32, validateContent = true
|
||||
): Future[Result[Header, PortalRpcError]] {.async: (raises: []).} =
|
||||
## Fetches the block header for the given hash from the Portal History Network.
|
||||
## The data is first looked up in the node's local database before trying to
|
||||
@ -116,7 +116,7 @@ proc historyGetBlockHeader*(
|
||||
decodeRlp(headerBytes, Header).valueOrErr(InvalidContentValue)
|
||||
|
||||
proc historyGetBlockBody*(
|
||||
client: PortalRpcClient, blockHash: BlockHash, validateContent = true
|
||||
client: PortalRpcClient, blockHash: Hash32, validateContent = true
|
||||
): Future[Result[BlockBody, PortalRpcError]] {.async: (raises: []).} =
|
||||
## Fetches the block body for the given block hash from the Portal History
|
||||
## Network. The data is first looked up in the node's local database before
|
||||
@ -136,7 +136,7 @@ proc historyGetBlockBody*(
|
||||
decodeBlockBodyBytes(content.toBytes()).valueOrErr(InvalidContentValue)
|
||||
|
||||
proc historyGetReceipts*(
|
||||
client: PortalRpcClient, blockHash: BlockHash, validateContent = true
|
||||
client: PortalRpcClient, blockHash: Hash32, validateContent = true
|
||||
): Future[Result[seq[Receipt], PortalRpcError]] {.async: (raises: []).} =
|
||||
## Fetches the receipts for the given block hash from the Portal History
|
||||
## Network. The data is first looked up in the node's local database before
|
||||
|
@ -21,7 +21,7 @@ import
|
||||
suite "History Content Keys":
|
||||
test "BlockHeader":
|
||||
# Input
|
||||
const blockHash = BlockHash.fromHex(
|
||||
const blockHash = Hash32.fromHex(
|
||||
"0xd1c390624d3bd4e409a61a858e5dcc5517729a9170d014a6c96530d64dd8621d"
|
||||
)
|
||||
|
||||
@ -53,7 +53,7 @@ suite "History Content Keys":
|
||||
|
||||
test "BlockBody":
|
||||
# Input
|
||||
const blockHash = BlockHash.fromHex(
|
||||
const blockHash = Hash32.fromHex(
|
||||
"0xd1c390624d3bd4e409a61a858e5dcc5517729a9170d014a6c96530d64dd8621d"
|
||||
)
|
||||
|
||||
@ -85,7 +85,7 @@ suite "History Content Keys":
|
||||
|
||||
test "Receipts":
|
||||
# Input
|
||||
const blockHash = BlockHash.fromHex(
|
||||
const blockHash = Hash32.fromHex(
|
||||
"0xd1c390624d3bd4e409a61a858e5dcc5517729a9170d014a6c96530d64dd8621d"
|
||||
)
|
||||
|
||||
|
@ -39,7 +39,7 @@ suite "History Content Values Validation":
|
||||
blockBodyBytes = blockData.body.hexToSeqByte()
|
||||
receiptsBytes = blockData.receipts.hexToSeqByte()
|
||||
|
||||
blockHash = BlockHash.fromHex(blockHashStr)
|
||||
blockHash = Hash32.fromHex(blockHashStr)
|
||||
|
||||
blockHeader =
|
||||
decodeRlp(blockHeaderBytes, Header).expect("Valid header should decode")
|
||||
|
@ -59,7 +59,7 @@ proc stop(hn: HistoryNode) {.async.} =
|
||||
proc containsId(hn: HistoryNode, contentId: ContentId): bool =
|
||||
return hn.historyNetwork.contentDB.get(contentId).isSome()
|
||||
|
||||
proc store*(hn: HistoryNode, blockHash: BlockHash, blockHeader: Header) =
|
||||
proc store*(hn: HistoryNode, blockHash: Hash32, blockHeader: Header) =
|
||||
let
|
||||
headerRlp = rlp.encode(blockHeader)
|
||||
blockHeaderWithProof = BlockHeaderWithProof(
|
||||
@ -72,14 +72,14 @@ proc store*(hn: HistoryNode, blockHash: BlockHash, blockHeader: Header) =
|
||||
contentKeyBytes, contentId, SSZ.encode(blockHeaderWithProof)
|
||||
)
|
||||
|
||||
proc store*(hn: HistoryNode, blockHash: BlockHash, blockBody: BlockBody) =
|
||||
proc store*(hn: HistoryNode, blockHash: Hash32, blockBody: BlockBody) =
|
||||
let
|
||||
contentKeyBytes = blockBodyContentKey(blockHash).encode()
|
||||
contentId = history_content.toContentId(contentKeyBytes)
|
||||
|
||||
hn.portalProtocol().storeContent(contentKeyBytes, contentId, blockBody.encode())
|
||||
|
||||
proc store*(hn: HistoryNode, blockHash: BlockHash, receipts: seq[Receipt]) =
|
||||
proc store*(hn: HistoryNode, blockHash: Hash32, receipts: seq[Receipt]) =
|
||||
let
|
||||
contentKeyBytes = receiptsContentKey(blockHash).encode()
|
||||
contentId = history_content.toContentId(contentKeyBytes)
|
||||
|
@ -145,7 +145,7 @@ proc containsId*(sn: StateNode, contentId: ContentId): bool {.inline.} =
|
||||
return sn.stateNetwork.contentDB.get(contentId).isSome()
|
||||
|
||||
proc mockStateRootLookup*(
|
||||
sn: StateNode, blockNumOrHash: uint64 | BlockHash, stateRoot: Hash32
|
||||
sn: StateNode, blockNumOrHash: uint64 | Hash32, stateRoot: Hash32
|
||||
) =
|
||||
let
|
||||
blockHeader = Header(stateRoot: stateRoot)
|
||||
|
@ -29,7 +29,7 @@ suite "State Content Keys":
|
||||
raiseAssert "Cannot read test vector: " & error
|
||||
|
||||
packedNibbles = packNibbles(testCase.path)
|
||||
nodeHash = NodeHash.fromHex(testCase.node_hash)
|
||||
nodeHash = Hash32.fromHex(testCase.node_hash)
|
||||
contentKey = AccountTrieNodeKey.init(packedNibbles, nodeHash).toContentKey()
|
||||
encoded = contentKey.encode()
|
||||
|
||||
@ -60,7 +60,7 @@ suite "State Content Keys":
|
||||
|
||||
packedNibbles = packNibbles(testCase.path)
|
||||
addressHash = Address.fromHex(testCase.address).data.keccak256()
|
||||
nodeHash = NodeHash.fromHex(testCase.node_hash)
|
||||
nodeHash = Hash32.fromHex(testCase.node_hash)
|
||||
contentKey =
|
||||
ContractTrieNodeKey.init(addressHash, packedNibbles, nodeHash).toContentKey()
|
||||
encoded = contentKey.encode()
|
||||
@ -92,7 +92,7 @@ suite "State Content Keys":
|
||||
raiseAssert "Cannot read test vector: " & error
|
||||
|
||||
addressHash = Address.fromHex(testCase.address).data.keccak256()
|
||||
codeHash = CodeHash.fromHex(testCase.code_hash)
|
||||
codeHash = Hash32.fromHex(testCase.code_hash)
|
||||
contentKey = ContractCodeKey.init(addressHash, codeHash).toContentKey()
|
||||
encoded = contentKey.encode()
|
||||
|
||||
|
@ -27,7 +27,7 @@ suite "State Content Values":
|
||||
testCase = YamlAccountTrieNodeWithProof.loadFromYaml(file).valueOr:
|
||||
raiseAssert "Cannot read test vector: " & error
|
||||
|
||||
blockHash = BlockHash.fromHex(testCase.block_hash)
|
||||
blockHash = Hash32.fromHex(testCase.block_hash)
|
||||
proof =
|
||||
TrieProof.init(testCase.proof.map((hex) => TrieNode.init(hex.hexToSeqByte())))
|
||||
accountTrieNodeOffer = AccountTrieNodeOffer.init(proof, blockHash)
|
||||
@ -75,7 +75,7 @@ suite "State Content Values":
|
||||
testCase = YamlContractStorageTrieNodeWithProof.loadFromYaml(file).valueOr:
|
||||
raiseAssert "Cannot read test vector: " & error
|
||||
|
||||
blockHash = BlockHash.fromHex(testCase.block_hash)
|
||||
blockHash = Hash32.fromHex(testCase.block_hash)
|
||||
storageProof = TrieProof.init(
|
||||
testCase.storage_proof.map((hex) => TrieNode.init(hex.hexToSeqByte()))
|
||||
)
|
||||
@ -133,7 +133,7 @@ suite "State Content Values":
|
||||
raiseAssert "Cannot read test vector: " & error
|
||||
|
||||
code = Bytecode.init(testCase.bytecode.hexToSeqByte())
|
||||
blockHash = BlockHash.fromHex(testCase.block_hash)
|
||||
blockHash = Hash32.fromHex(testCase.block_hash)
|
||||
accountProof = TrieProof.init(
|
||||
testCase.account_proof.map((hex) => TrieNode.init(hex.hexToSeqByte()))
|
||||
)
|
||||
|
@ -96,7 +96,7 @@ proc calculateWithdrawalsRoot(items: openArray[WithdrawalV1]): Hash32 {.raises:
|
||||
|
||||
proc asPortalBlockData*(
|
||||
payload: ExecutionPayloadV1
|
||||
): (common_types.BlockHash, BlockHeaderWithProof, PortalBlockBodyLegacy) =
|
||||
): (Hash32, BlockHeaderWithProof, PortalBlockBodyLegacy) =
|
||||
let
|
||||
txRoot = calculateTransactionData(payload.transactions)
|
||||
|
||||
|
@ -139,9 +139,7 @@ proc getBlockReceipts(
|
||||
## Portal JSON-RPC API helper calls for pushing block and receipts
|
||||
|
||||
proc gossipBlockHeader(
|
||||
client: RpcClient,
|
||||
id: common_types.BlockHash | uint64,
|
||||
headerWithProof: BlockHeaderWithProof,
|
||||
client: RpcClient, id: Hash32 | uint64, headerWithProof: BlockHeaderWithProof
|
||||
): Future[Result[void, string]] {.async: (raises: []).} =
|
||||
let
|
||||
contentKey = blockHeaderContentKey(id)
|
||||
@ -160,7 +158,7 @@ proc gossipBlockHeader(
|
||||
|
||||
proc gossipBlockBody(
|
||||
client: RpcClient,
|
||||
hash: common_types.BlockHash,
|
||||
hash: Hash32,
|
||||
body: PortalBlockBodyLegacy | PortalBlockBodyShanghai,
|
||||
): Future[Result[void, string]] {.async: (raises: []).} =
|
||||
let
|
||||
@ -179,7 +177,7 @@ proc gossipBlockBody(
|
||||
return ok()
|
||||
|
||||
proc gossipReceipts(
|
||||
client: RpcClient, hash: common_types.BlockHash, receipts: PortalReceipts
|
||||
client: RpcClient, hash: Hash32, receipts: PortalReceipts
|
||||
): Future[Result[void, string]] {.async: (raises: []).} =
|
||||
let
|
||||
contentKey = receiptsContentKey(hash)
|
||||
|
@ -15,19 +15,19 @@ import
|
||||
|
||||
type OffersBuilder* = object
|
||||
worldState: WorldStateRef
|
||||
blockHash: BlockHash
|
||||
blockHash: Hash32
|
||||
accountTrieOffers: seq[AccountTrieOfferWithKey]
|
||||
contractTrieOffers: seq[ContractTrieOfferWithKey]
|
||||
contractCodeOffers: seq[ContractCodeOfferWithKey]
|
||||
|
||||
proc init*(T: type OffersBuilder, worldState: WorldStateRef, blockHash: BlockHash): T =
|
||||
proc init*(T: type OffersBuilder, worldState: WorldStateRef, blockHash: Hash32): T =
|
||||
T(worldState: worldState, blockHash: blockHash)
|
||||
|
||||
proc toTrieProof(proof: seq[seq[byte]]): TrieProof =
|
||||
TrieProof.init(proof.map((node) => TrieNode.init(node)))
|
||||
|
||||
proc buildAccountTrieNodeOffer(
|
||||
builder: var OffersBuilder, addressHash: content_keys.AddressHash, proof: TrieProof
|
||||
builder: var OffersBuilder, addressHash: Hash32, proof: TrieProof
|
||||
) =
|
||||
try:
|
||||
let
|
||||
@ -43,7 +43,7 @@ proc buildAccountTrieNodeOffer(
|
||||
|
||||
proc buildContractTrieNodeOffer(
|
||||
builder: var OffersBuilder,
|
||||
addressHash: content_keys.AddressHash,
|
||||
addressHash: Hash32,
|
||||
slotHash: SlotKeyHash,
|
||||
storageProof: TrieProof,
|
||||
accountProof: TrieProof,
|
||||
@ -64,7 +64,7 @@ proc buildContractTrieNodeOffer(
|
||||
|
||||
proc buildContractCodeOffer(
|
||||
builder: var OffersBuilder,
|
||||
addressHash: content_keys.AddressHash,
|
||||
addressHash: Hash32,
|
||||
code: seq[byte],
|
||||
accountProof: TrieProof,
|
||||
) =
|
||||
|
Loading…
x
Reference in New Issue
Block a user