mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-02-04 08:16:19 +00:00
Remove unused stuff from txpool (#2967)
This commit is contained in:
parent
86fc24a1d7
commit
473da69043
@ -108,8 +108,8 @@ proc newEngineEnv*(conf: var NimbusConf, chainFile: string, enableAuth: bool): E
|
||||
echo "Failed to create rpc server: ", error
|
||||
quit(QuitFailure)
|
||||
|
||||
beaconEngine = BeaconEngineRef.new(txPool, chain)
|
||||
serverApi = newServerAPI(chain, txPool)
|
||||
beaconEngine = BeaconEngineRef.new(txPool)
|
||||
serverApi = newServerAPI(txPool)
|
||||
|
||||
setupServerAPI(serverApi, server, ctx)
|
||||
setupEngineAPI(beaconEngine, server)
|
||||
|
@ -58,8 +58,8 @@ proc setupELClient*(conf: ChainConfig, taskPool: Taskpool, node: JsonNode): Test
|
||||
|
||||
let
|
||||
txPool = TxPoolRef.new(chain)
|
||||
beaconEngine = BeaconEngineRef.new(txPool, chain)
|
||||
serverApi = newServerAPI(chain, txPool)
|
||||
beaconEngine = BeaconEngineRef.new(txPool)
|
||||
serverApi = newServerAPI(txPool)
|
||||
rpcServer = newRpcHttpServer(["127.0.0.1:0"])
|
||||
rpcClient = newRpcHttpClient()
|
||||
|
||||
|
@ -48,7 +48,7 @@ proc setupRpcServer(ctx: EthContext, com: CommonRef,
|
||||
conf: NimbusConf, chain: ForkedChainRef): RpcServer =
|
||||
let
|
||||
rpcServer = newRpcHttpServer([initTAddress(conf.httpAddress, conf.httpPort)])
|
||||
serverApi = newServerAPI(chain, txPool)
|
||||
serverApi = newServerAPI(txPool)
|
||||
|
||||
|
||||
setupCommonRpc(ethNode, conf, rpcServer)
|
||||
|
@ -26,7 +26,6 @@ type
|
||||
BeaconEngineRef* = ref object
|
||||
txPool: TxPoolRef
|
||||
queue : PayloadQueue
|
||||
chain : ForkedChainRef
|
||||
|
||||
# The forkchoice update and new payload method require us to return the
|
||||
# latest valid hash in an invalid chain. To support that return, we need
|
||||
@ -94,12 +93,10 @@ func setInvalidAncestor(ben: BeaconEngineRef,
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
func new*(_: type BeaconEngineRef,
|
||||
txPool: TxPoolRef,
|
||||
chain: ForkedChainRef): BeaconEngineRef =
|
||||
txPool: TxPoolRef): BeaconEngineRef =
|
||||
let ben = BeaconEngineRef(
|
||||
txPool: txPool,
|
||||
queue : PayloadQueue(),
|
||||
chain : chain,
|
||||
)
|
||||
|
||||
txPool.com.notifyBadBlock = proc(invalid, origin: Header)
|
||||
@ -127,7 +124,7 @@ func com*(ben: BeaconEngineRef): CommonRef =
|
||||
ben.txPool.com
|
||||
|
||||
func chain*(ben: BeaconEngineRef): ForkedChainRef =
|
||||
ben.chain
|
||||
ben.txPool.chain
|
||||
|
||||
func get*(ben: BeaconEngineRef, hash: Hash32,
|
||||
header: var Header): bool =
|
||||
|
@ -13,7 +13,7 @@ import
|
||||
chronicles,
|
||||
../core/casper,
|
||||
../db/[core_db, ledger, storage_types],
|
||||
../utils/[utils, ec_recover],
|
||||
../utils/[utils],
|
||||
".."/[constants, errors, version],
|
||||
"."/[chain_config, evmforks, genesis, hardforks],
|
||||
taskpools
|
||||
|
@ -34,19 +34,13 @@ const
|
||||
|
||||
BLOCK_REWARD* = 5.u256 * 2.u256 # denoms.ether
|
||||
|
||||
UNCLE_DEPTH_PENALTY_FACTOR* = 8.u256
|
||||
|
||||
MAX_UNCLE_DEPTH* = 6
|
||||
MAX_UNCLES* = 2
|
||||
|
||||
GENESIS_BLOCK_NUMBER* = 0.BlockNumber
|
||||
GENESIS_DIFFICULTY* = 131_072.u256
|
||||
GENESIS_GAS_LIMIT* = 3_141_592
|
||||
GENESIS_PARENT_HASH* = ZERO_HASH32
|
||||
GENESIS_COINBASE* = ZERO_ADDRESS
|
||||
GENESIS_NONCE* = "\x00\x00\x00\x00\x00\x00\x00B"
|
||||
GENESIS_MIX_HASH* = ZERO_HASH32
|
||||
GENESIS_EXTRA_DATA* = ""
|
||||
|
||||
GAS_LIMIT_MINIMUM* = 5000
|
||||
GAS_LIMIT_MAXIMUM* = int64.high.GasInt # Maximum the gas limit (2^63-1).
|
||||
DEFAULT_GAS_LIMIT* = 36_000_000
|
||||
|
@ -107,32 +107,4 @@ type
|
||||
## Tx becomes obsolete as it is in a mined block, already
|
||||
"Tx obsoleted"
|
||||
|
||||
# ---------- debugging error codes as used in verifier functions -----------
|
||||
|
||||
# failed verifier codes
|
||||
|
||||
txInfoVfyItemIdList ## Corrupted ID queue/fifo structure
|
||||
txInfoVfyRejectsList ## Corrupted waste basket structure
|
||||
txInfoVfyNonceChain ## Non-consecutive nonces
|
||||
|
||||
txInfoVfySenderRbTree ## Corrupted sender list structure
|
||||
txInfoVfySenderLeafEmpty ## Empty sender list leaf record
|
||||
txInfoVfySenderTotal ## Wrong number of leaves
|
||||
txInfoVfySenderProfits ## Profits calculation error
|
||||
|
||||
txInfoVfyStatusTotal ## Wrong number of leaves
|
||||
txInfoVfyStatusGasLimits ## Wrong gas accu values
|
||||
txInfoVfyStatusSenderList ## Corrupted status-sender sub-list
|
||||
txInfoVfyStatusNonceList ## Corrupted status-nonce sub-list
|
||||
|
||||
txInfoVfyStatusSenderTotal ## Sender vs status table mismatch
|
||||
txInfoVfyStatusSenderGasLimits ## Wrong gas accu values
|
||||
|
||||
txInfoVfyRankAddrMismatch ## Different ranks in address set
|
||||
txInfoVfyReverseZombies ## Zombie addresses in reverse lookup
|
||||
txInfoVfyRankReverseLookup ## Sender missing in reverse lookup
|
||||
txInfoVfyRankReverseMismatch ## Ranks differ with revers lookup
|
||||
txInfoVfyRankDuplicateAddr ## Same address with different ranks
|
||||
txInfoVfyRankTotal ## Wrong number of leaves (i.e. adresses)
|
||||
|
||||
# End
|
||||
|
@ -14,7 +14,6 @@
|
||||
|
||||
import
|
||||
std/[hashes, times],
|
||||
../../utils/ec_recover,
|
||||
../../utils/utils,
|
||||
../../transaction,
|
||||
./tx_info,
|
||||
|
@ -6,9 +6,5 @@
|
||||
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||
|
||||
type
|
||||
EVMError* = object of CatchableError
|
||||
## Base error class for all evm errors.
|
||||
|
||||
ValidationError* = object of EVMError
|
||||
ValidationError* = object of CatchableError
|
||||
## Error to signal something does not pass a validation check.
|
||||
|
||||
|
@ -19,7 +19,7 @@ import
|
||||
../../evm_errors,
|
||||
../../types,
|
||||
../gas_costs,
|
||||
eth/common/[addresses, base, hashes]
|
||||
eth/common/[addresses, base]
|
||||
|
||||
when defined(evmc_enabled):
|
||||
import
|
||||
|
@ -51,7 +51,7 @@ proc basicServices(nimbus: NimbusNode,
|
||||
nimbus.txPool = TxPoolRef.new(nimbus.chainRef)
|
||||
doAssert nimbus.txPool.smartHead(nimbus.chainRef.latestHeader)
|
||||
|
||||
nimbus.beaconEngine = BeaconEngineRef.new(nimbus.txPool, nimbus.chainRef)
|
||||
nimbus.beaconEngine = BeaconEngineRef.new(nimbus.txPool)
|
||||
|
||||
proc manageAccounts(nimbus: NimbusNode, conf: NimbusConf) =
|
||||
if string(conf.keyStore).len > 0:
|
||||
|
@ -257,7 +257,7 @@ proc setupRpc*(nimbus: NimbusNode, conf: NimbusConf,
|
||||
allowedOrigins = conf.getAllowedOrigins()
|
||||
jwtAuthHook = httpJwtAuth(jwtKey)
|
||||
corsHook = httpCors(allowedOrigins)
|
||||
serverApi = newServerAPI(nimbus.chainRef, nimbus.txPool)
|
||||
serverApi = newServerAPI(nimbus.txPool)
|
||||
|
||||
if conf.combinedServer:
|
||||
let hooks: seq[RpcAuthHook] = @[jwtAuthHook, corsHook]
|
||||
|
@ -31,14 +31,18 @@ import
|
||||
./filters
|
||||
|
||||
type ServerAPIRef* = ref object
|
||||
com: CommonRef
|
||||
chain: ForkedChainRef
|
||||
txPool: TxPoolRef
|
||||
|
||||
const defaultTag = blockId("latest")
|
||||
|
||||
func newServerAPI*(c: ForkedChainRef, t: TxPoolRef): ServerAPIRef =
|
||||
ServerAPIRef(com: c.com, chain: c, txPool: t)
|
||||
template com(api: ServerAPIRef): CommonRef =
|
||||
api.txPool.com
|
||||
|
||||
template chain(api: ServerAPIRef): ForkedChainRef =
|
||||
api.txPool.chain
|
||||
|
||||
func newServerAPI*(txPool: TxPoolRef): ServerAPIRef =
|
||||
ServerAPIRef(txPool: txPool)
|
||||
|
||||
proc getTotalDifficulty*(api: ServerAPIRef, blockHash: Hash32): UInt256 =
|
||||
let totalDifficulty = api.com.db.getScore(blockHash).valueOr:
|
||||
|
@ -1,166 +0,0 @@
|
||||
# Nimbus
|
||||
# Copyright (c) 2018-2024 Status Research & Development GmbH
|
||||
# Licensed under either of
|
||||
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
||||
# http://www.apache.org/licenses/LICENSE-2.0)
|
||||
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or
|
||||
# http://opensource.org/licenses/MIT)
|
||||
# at your option. This file may not be copied, modified, or distributed except
|
||||
# according to those terms.
|
||||
|
||||
##
|
||||
## Recover Address From Signature
|
||||
## ==============================
|
||||
##
|
||||
## This module provides caching and direct versions for recovering the
|
||||
## `Address` from an extended signature. The caching version reduces
|
||||
## calculation time for the price of maintaing it in a LRU cache.
|
||||
|
||||
import
|
||||
../constants,
|
||||
./utils_defs,
|
||||
eth/common/[keys, eth_types_rlp],
|
||||
eth/rlp,
|
||||
stew/keyed_queue,
|
||||
results,
|
||||
stint
|
||||
|
||||
export
|
||||
utils_defs, results
|
||||
|
||||
{.push raises: [].}
|
||||
|
||||
const
|
||||
INMEMORY_SIGNATURES* = ##\
|
||||
## Default number of recent block signatures to keep in memory
|
||||
4096
|
||||
|
||||
type
|
||||
EcKey* = ##\
|
||||
## Internal key used for the LRU cache (derived from Hash32).
|
||||
array[32,byte]
|
||||
|
||||
EcAddrResult* = ##\
|
||||
## Typical `Address` result as returned by `ecRecover()` functions.
|
||||
Result[Address,UtilsError]
|
||||
|
||||
EcRecover* = object
|
||||
size: uint
|
||||
q: KeyedQueue[EcKey,Address]
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Private helpers
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
proc encodePreSealed(header: Header): seq[byte] =
|
||||
## Cut sigature off `extraData` header field.
|
||||
if header.extraData.len < EXTRA_SEAL:
|
||||
return rlp.encode(header)
|
||||
|
||||
var rlpHeader = header
|
||||
rlpHeader.extraData.setLen(header.extraData.len - EXTRA_SEAL)
|
||||
rlp.encode(rlpHeader)
|
||||
|
||||
proc hashPreSealed(header: Header): Hash32 =
|
||||
## Returns the hash of a block prior to it being sealed.
|
||||
keccak256 header.encodePreSealed
|
||||
|
||||
|
||||
proc recoverImpl(rawSig: openArray[byte]; msg: Hash32): EcAddrResult =
|
||||
## Extract account address from the last 65 bytes of the `extraData` argument
|
||||
## (which is typically the bock header field with the same name.) The second
|
||||
## argument `hash` is used to extract the intermediate public key. Typically,
|
||||
## this would be the hash of the block header without the last 65 bytes of
|
||||
## the `extraData` field reserved for the signature.
|
||||
if rawSig.len < EXTRA_SEAL:
|
||||
return err((errMissingSignature,""))
|
||||
|
||||
let sig = Signature.fromRaw(
|
||||
rawSig.toOpenArray(rawSig.len - EXTRA_SEAL, rawSig.high))
|
||||
if sig.isErr:
|
||||
return err((errSkSigResult,$sig.error))
|
||||
|
||||
# Recover the public key from signature and seal hash
|
||||
let pubKey = recover(sig.value, SkMessage(msg.data))
|
||||
if pubKey.isErr:
|
||||
return err((errSkPubKeyResult,$pubKey.error))
|
||||
|
||||
# Convert public key to address.
|
||||
ok(pubKey.value.toCanonicalAddress)
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Public function: straight ecRecover versions
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
proc ecRecover*(header: Header): EcAddrResult =
|
||||
## Extracts account address from the `extraData` field (last 65 bytes) of
|
||||
## the argument header.
|
||||
header.extraData.recoverImpl(header.hashPreSealed)
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Public constructor for caching ecRecover version
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
proc init*(er: var EcRecover; cacheSize = INMEMORY_SIGNATURES; initSize = 10) =
|
||||
## Inialise recover cache
|
||||
er.size = cacheSize.uint
|
||||
er.q.init(initSize)
|
||||
|
||||
proc init*(T: type EcRecover;
|
||||
cacheSize = INMEMORY_SIGNATURES; initSize = 10): T =
|
||||
## Inialise recover cache
|
||||
result.init(cacheSize, initSize)
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Public functions: miscellaneous
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
proc len*(er: var EcRecover): int =
|
||||
## Returns the current number of entries in the LRU cache.
|
||||
er.q.len
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Public functions: caching ecRecover version
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
proc ecRecover*(er: var EcRecover; header: var Header): EcAddrResult =
|
||||
## Extract account address from `extraData` field (last 65 bytes) of the
|
||||
## argument header. The result is kept in a LRU cache to re-purposed for
|
||||
## improved result delivery avoiding calculations.
|
||||
let key = header.blockHash.data
|
||||
block:
|
||||
let rc = er.q.lruFetch(key)
|
||||
if rc.isOk:
|
||||
return ok(rc.value)
|
||||
block:
|
||||
let rc = header.extraData.recoverImpl(header.hashPreSealed)
|
||||
if rc.isOk:
|
||||
return ok(er.q.lruAppend(key, rc.value, er.size.int))
|
||||
err(rc.error)
|
||||
|
||||
proc ecRecover*(er: var EcRecover; header: Header): EcAddrResult =
|
||||
## Variant of `ecRecover()` for call-by-value header
|
||||
var hdr = header
|
||||
er.ecRecover(hdr)
|
||||
|
||||
proc ecRecover*(er: var EcRecover; hash: Hash32): EcAddrResult =
|
||||
## Variant of `ecRecover()` for hash only. Will only succeed it the
|
||||
## argument hash is uk the LRU queue.
|
||||
let rc = er.q.lruFetch(hash.data)
|
||||
if rc.isOk:
|
||||
return ok(rc.value)
|
||||
err((errItemNotFound,""))
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Debugging
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
iterator keyItemPairs*(er: var EcRecover): (EcKey,Address) =
|
||||
var rc = er.q.first
|
||||
while rc.isOk:
|
||||
yield (rc.value.key, rc.value.data)
|
||||
rc = er.q.next(rc.value.key)
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# End
|
||||
# ------------------------------------------------------------------------------
|
@ -1,65 +0,0 @@
|
||||
# Nimbus
|
||||
# Copyright (c) 2018 Status Research & Development GmbH
|
||||
# Licensed under either of
|
||||
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
||||
# http://www.apache.org/licenses/LICENSE-2.0)
|
||||
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or
|
||||
# http://opensource.org/licenses/MIT)
|
||||
# at your option. This file may not be copied, modified, or distributed except
|
||||
# according to those terms.
|
||||
|
||||
##
|
||||
## Definitions, Error Constants, etc.
|
||||
## ===================================
|
||||
##
|
||||
|
||||
{.push raises: [].}
|
||||
|
||||
type
|
||||
UtilsErrorType* = enum
|
||||
resetUtilsError = ##\
|
||||
## Default/reset value (use `utilsNoError` below rather than this valie)
|
||||
(0, "no error")
|
||||
|
||||
errMissingSignature = ##\
|
||||
## is returned if the `extraData` header field does not seem to contain
|
||||
## a 65 byte secp256k1 signature.
|
||||
"extraData 65 byte signature suffix missing"
|
||||
|
||||
errSigPrefixError = ##\
|
||||
## Unsupported value of the (R,S) signature prefix V.
|
||||
"unsupported (R,S) signature prefix V value"
|
||||
|
||||
errSkSigResult = ##\
|
||||
## eth/keys subsytem error: signature
|
||||
"signature error"
|
||||
|
||||
errSkPubKeyResult = ##\
|
||||
## eth/keys subsytem error: public key
|
||||
"public key error"
|
||||
|
||||
errItemNotFound = ##\
|
||||
## database lookup failed
|
||||
"not found"
|
||||
|
||||
errTxEncError = ##\
|
||||
## TRansaction encoding error
|
||||
"tx enc error"
|
||||
|
||||
UtilsError* = ##\
|
||||
## Error message, tinned component + explanatory text (if any)
|
||||
(UtilsErrorType,string)
|
||||
|
||||
|
||||
const
|
||||
utilsNoError* = ##\
|
||||
## No-error constant
|
||||
(resetUtilsError, "")
|
||||
|
||||
proc `$`*(e: UtilsError): string =
|
||||
## Join text fragments
|
||||
result = $e[0]
|
||||
if e[1] != "":
|
||||
result &= ": " & e[1]
|
||||
|
||||
# End
|
@ -100,8 +100,8 @@ proc setupEnv(envFork: HardFork = MergeFork,
|
||||
server = newRpcHttpServerWithParams("127.0.0.1:0").valueOr:
|
||||
echo "Failed to create rpc server: ", error
|
||||
quit(QuitFailure)
|
||||
beaconEngine = BeaconEngineRef.new(txPool, chain)
|
||||
serverApi = newServerAPI(chain, txPool)
|
||||
beaconEngine = BeaconEngineRef.new(txPool)
|
||||
serverApi = newServerAPI(txPool)
|
||||
|
||||
setupServerAPI(serverApi, server, newEthContext())
|
||||
setupEngineAPI(beaconEngine, server)
|
||||
|
@ -191,7 +191,7 @@ proc setupEnv(signer, ks2: Address, ctx: EthContext, com: CommonRef): TestEnv =
|
||||
|
||||
com.db.persistHeaderAndSetHead(header,
|
||||
com.startOfHistory).expect("persistHeader not error")
|
||||
|
||||
|
||||
let uncles = [header]
|
||||
header.ommersHash = com.db.persistUncles(uncles)
|
||||
|
||||
@ -250,7 +250,7 @@ proc rpcMain*() =
|
||||
let
|
||||
server = newRpcHttpServerWithParams("127.0.0.1:0").valueOr:
|
||||
quit(QuitFailure)
|
||||
serverApi = newServerAPI(chain, txPool)
|
||||
serverApi = newServerAPI(txPool)
|
||||
|
||||
setupServerAPI(serverApi, server, ctx)
|
||||
setupCommonRpc(ethNode, conf, server)
|
||||
|
@ -13,7 +13,6 @@ import
|
||||
../../nimbus/core/[chain, tx_pool], # must be early (compilation annoyance)
|
||||
../../nimbus/common/common,
|
||||
../../nimbus/[config, constants],
|
||||
../../nimbus/utils/ec_recover,
|
||||
../../nimbus/core/tx_pool/[tx_chain, tx_item],
|
||||
../../nimbus/transaction,
|
||||
eth/common/transaction_utils,
|
||||
|
@ -10,7 +10,6 @@
|
||||
|
||||
import
|
||||
../../nimbus/[constants, transaction],
|
||||
../../nimbus/utils/ec_recover,
|
||||
../../nimbus/core/tx_pool/tx_item,
|
||||
eth/[common, common/transaction, keys],
|
||||
results,
|
||||
|
Loading…
x
Reference in New Issue
Block a user