mirror of
https://github.com/status-im/nim-eth.git
synced 2025-01-11 14:54:33 +00:00
Fix raw Exceptions in hexary caused by forward declarations (#349)
* Fix raw Exceptions in hexary caused by forward declarations * Fix raw Exceptions in trie/db caused by forward declarations * And now we can remove those db Proc CatchableError raises
This commit is contained in:
parent
2d75e73bab
commit
d05cb5d3bd
@ -4,7 +4,7 @@ import
|
||||
../rlp, ../trie/[trie_defs, db]
|
||||
|
||||
export
|
||||
stint, read, append, KeccakHash
|
||||
stint, read, append, KeccakHash, rlp
|
||||
|
||||
type
|
||||
Hash256* = MDigest[256]
|
||||
@ -373,7 +373,7 @@ method genesisHash*(db: AbstractChainDB): KeccakHash
|
||||
notImplemented()
|
||||
|
||||
method getBlockHeader*(db: AbstractChainDB, b: HashOrNum,
|
||||
output: var BlockHeader): bool {.base, gcsafe, raises: [CatchableError, Defect].} =
|
||||
output: var BlockHeader): bool {.base, gcsafe, raises: [RlpError, Defect].} =
|
||||
notImplemented()
|
||||
|
||||
proc getBlockHeader*(db: AbstractChainDB, hash: KeccakHash): BlockHeaderRef {.gcsafe.} =
|
||||
@ -386,18 +386,22 @@ proc getBlockHeader*(db: AbstractChainDB, b: BlockNumber): BlockHeaderRef {.gcsa
|
||||
if not db.getBlockHeader(HashOrNum(isHash: false, number: b), result[]):
|
||||
return nil
|
||||
|
||||
# Need to add `RlpError` and sometimes `CatchableError` as the implementations
|
||||
# of these methods in nimbus-eth1 will raise these. Using `CatchableError`
|
||||
# because some can raise for errors not know to this repository such as
|
||||
# `CanonicalHeadNotFound`. It would probably be better to use Result.
|
||||
method getBestBlockHeader*(self: AbstractChainDB): BlockHeader
|
||||
{.base, gcsafe, raises: [CatchableError, Defect].} =
|
||||
{.base, gcsafe, raises: [RlpError, CatchableError, Defect].} =
|
||||
notImplemented()
|
||||
|
||||
method getSuccessorHeader*(db: AbstractChainDB, h: BlockHeader,
|
||||
output: var BlockHeader, skip = 0'u): bool
|
||||
{.base, gcsafe, raises: [CatchableError, Defect].} =
|
||||
{.base, gcsafe, raises: [RlpError, Defect].} =
|
||||
notImplemented()
|
||||
|
||||
method getAncestorHeader*(db: AbstractChainDB, h: BlockHeader,
|
||||
output: var BlockHeader, skip = 0'u): bool
|
||||
{.base, gcsafe, raises: [CatchableError, Defect].} =
|
||||
{.base, gcsafe, raises: [RlpError, Defect].} =
|
||||
notImplemented()
|
||||
|
||||
method getBlockBody*(db: AbstractChainDB, blockHash: KeccakHash): BlockBodyRef
|
||||
|
@ -11,7 +11,7 @@ import
|
||||
# TODO: Perhaps we can move this to eth-common
|
||||
|
||||
proc getBlockHeaders*(db: AbstractChainDB, req: BlocksRequest): seq[BlockHeader]
|
||||
{.gcsafe, raises: [CatchableError, Defect].} =
|
||||
{.gcsafe, raises: [RlpError, Defect].} =
|
||||
result = newSeqOfCap[BlockHeader](req.maxResults)
|
||||
|
||||
var foundBlock: BlockHeader
|
||||
@ -50,4 +50,3 @@ proc getHelperTrieProofs*(db: AbstractChainDB,
|
||||
reqs: openarray[HelperTrieProofRequest],
|
||||
outNodes: var seq[Blob], outAuxData: var seq[Blob]) =
|
||||
discard
|
||||
|
||||
|
@ -316,7 +316,7 @@ proc acceptRequest*(network: LesNetwork, peer: LesPeer,
|
||||
network.updateFlowControl t
|
||||
|
||||
while not network.canServeRequest:
|
||||
await sleepAsync(10.milliseconds)
|
||||
await sleepAsync(chronos.milliseconds(10))
|
||||
|
||||
if peer notin network.peers:
|
||||
# The peer was disconnected or the network
|
||||
|
@ -1,3 +1,5 @@
|
||||
{.push raises: [Defect].}
|
||||
|
||||
import
|
||||
std/[tables, hashes, sets],
|
||||
nimcrypto/[hash, keccak],
|
||||
@ -14,17 +16,17 @@ type
|
||||
|
||||
# XXX: poor's man vtref types
|
||||
PutProc = proc (db: RootRef, key, val: openarray[byte]) {.
|
||||
gcsafe, raises: [Defect, CatchableError] .}
|
||||
gcsafe, raises: [Defect].}
|
||||
|
||||
GetProc = proc (db: RootRef, key: openarray[byte]): seq[byte] {.
|
||||
gcsafe, raises: [Defect, CatchableError] .}
|
||||
gcsafe, raises: [Defect].}
|
||||
## The result will be empty seq if not found
|
||||
|
||||
DelProc = proc (db: RootRef, key: openarray[byte]) {.
|
||||
gcsafe, raises: [Defect, CatchableError] .}
|
||||
gcsafe, raises: [Defect].}
|
||||
|
||||
ContainsProc = proc (db: RootRef, key: openarray[byte]): bool {.
|
||||
gcsafe, raises: [Defect, CatchableError] .}
|
||||
gcsafe, raises: [Defect].}
|
||||
|
||||
TrieDatabaseRef* = ref object
|
||||
obj: RootRef
|
||||
|
@ -34,7 +34,8 @@ proc expectHash(r: Rlp): seq[byte] =
|
||||
raise newException(RlpTypeMismatch,
|
||||
"RLP expected to be a Keccak hash value, but has an incorrect length")
|
||||
|
||||
proc dbPut(db: DB, data: openArray[byte]): TrieNodeKey {.gcsafe.}
|
||||
proc dbPut(db: DB, data: openArray[byte]): TrieNodeKey
|
||||
{.gcsafe, raises: [Defect].}
|
||||
|
||||
template get(db: DB, key: Rlp): seq[byte] =
|
||||
db.get(key.expectHash)
|
||||
@ -51,7 +52,8 @@ proc initHexaryTrie*(db: DB, rootHash: KeccakHash, isPruning = true): HexaryTrie
|
||||
template initSecureHexaryTrie*(db: DB, rootHash: KeccakHash, isPruning = true): SecureHexaryTrie =
|
||||
SecureHexaryTrie initHexaryTrie(db, rootHash, isPruning)
|
||||
|
||||
proc initHexaryTrie*(db: DB, isPruning = true): HexaryTrie =
|
||||
proc initHexaryTrie*(db: DB, isPruning = true): HexaryTrie
|
||||
{.raises: [Defect].} =
|
||||
result.db = db
|
||||
result.root = result.db.dbPut(emptyRlp)
|
||||
result.isPruning = isPruning
|
||||
@ -84,7 +86,8 @@ template keyToLocalBytes(db: DB, k: TrieNodeKey): seq[byte] =
|
||||
template extensionNodeKey(r: Rlp): auto =
|
||||
hexPrefixDecode r.listElem(0).toBytes
|
||||
|
||||
proc getAux(db: DB, nodeRlp: Rlp, path: NibblesSeq): seq[byte] {.gcsafe.}
|
||||
proc getAux(db: DB, nodeRlp: Rlp, path: NibblesSeq): seq[byte]
|
||||
{.gcsafe, raises: [RlpError, Defect].}
|
||||
|
||||
proc getAuxByHash(db: DB, node: TrieNodeKey, path: NibblesSeq): seq[byte] =
|
||||
var nodeRlp = rlpFromBytes keyToLocalBytes(db, node)
|
||||
@ -94,7 +97,8 @@ template getLookup(elem: untyped): untyped =
|
||||
if elem.isList: elem
|
||||
else: rlpFromBytes(get(db, elem.expectHash))
|
||||
|
||||
proc getAux(db: DB, nodeRlp: Rlp, path: NibblesSeq): seq[byte] =
|
||||
proc getAux(db: DB, nodeRlp: Rlp, path: NibblesSeq): seq[byte]
|
||||
{.gcsafe, raises: [RlpError, Defect].} =
|
||||
if not nodeRlp.hasData or nodeRlp.isEmpty:
|
||||
return
|
||||
|
||||
@ -348,7 +352,8 @@ proc getBranch*(self: HexaryTrie; key: openArray[byte]): seq[seq[byte]] =
|
||||
proc dbDel(t: var HexaryTrie, data: openArray[byte]) =
|
||||
if data.len >= 32: t.prune(data.keccak.data)
|
||||
|
||||
proc dbPut(db: DB, data: openArray[byte]): TrieNodeKey =
|
||||
proc dbPut(db: DB, data: openArray[byte]): TrieNodeKey
|
||||
{.raises: [Defect].} =
|
||||
result.hash = data.keccak
|
||||
result.usedBytes = 32
|
||||
put(db, result.asDbKey, data)
|
||||
@ -406,7 +411,8 @@ proc findSingleChild(r: Rlp; childPos: var byte): Rlp =
|
||||
return zeroBytesRlp
|
||||
inc i
|
||||
|
||||
proc deleteAt(self: var HexaryTrie; origRlp: Rlp, key: NibblesSeq): seq[byte] {.gcsafe.}
|
||||
proc deleteAt(self: var HexaryTrie; origRlp: Rlp, key: NibblesSeq): seq[byte]
|
||||
{.gcsafe, raises: [RlpError, Defect].}
|
||||
|
||||
proc deleteAux(self: var HexaryTrie; rlpWriter: var RlpWriter;
|
||||
origRlp: Rlp; path: NibblesSeq): bool =
|
||||
@ -457,8 +463,8 @@ proc mergeAndGraft(self: var HexaryTrie;
|
||||
if self.isTwoItemNode(soleChild):
|
||||
result = self.graft(rlpFromBytes(result))
|
||||
|
||||
proc deleteAt(self: var HexaryTrie;
|
||||
origRlp: Rlp, key: NibblesSeq): seq[byte] =
|
||||
proc deleteAt(self: var HexaryTrie; origRlp: Rlp, key: NibblesSeq): seq[byte]
|
||||
{.gcsafe, raises: [RlpError, Defect].} =
|
||||
if origRlp.isEmpty:
|
||||
return
|
||||
|
||||
@ -536,8 +542,9 @@ proc del*(self: var HexaryTrie; key: openArray[byte]) =
|
||||
self.root = self.db.dbPut(newRootBytes)
|
||||
|
||||
proc mergeAt(self: var HexaryTrie, orig: Rlp, origHash: KeccakHash,
|
||||
key: NibblesSeq, value: openArray[byte],
|
||||
isInline = false): seq[byte] {.gcsafe.}
|
||||
key: NibblesSeq, value: openArray[byte],
|
||||
isInline = false): seq[byte]
|
||||
{.gcsafe, raises: [RlpError, Defect].}
|
||||
|
||||
proc mergeAt(self: var HexaryTrie, rlp: Rlp,
|
||||
key: NibblesSeq, value: openArray[byte],
|
||||
@ -556,8 +563,9 @@ proc mergeAtAux(self: var HexaryTrie, output: var RlpWriter, orig: Rlp,
|
||||
output.appendAndSave(b, self.db)
|
||||
|
||||
proc mergeAt(self: var HexaryTrie, orig: Rlp, origHash: KeccakHash,
|
||||
key: NibblesSeq, value: openArray[byte],
|
||||
isInline = false): seq[byte] =
|
||||
key: NibblesSeq, value: openArray[byte],
|
||||
isInline = false): seq[byte]
|
||||
{.gcsafe, raises: [RlpError, Defect].} =
|
||||
template origWithNewValue: auto =
|
||||
self.prune(origHash.data)
|
||||
replaceValue(orig, key, value)
|
||||
|
Loading…
x
Reference in New Issue
Block a user