diff --git a/lib/ain-cpp-imports/src/bridge.rs b/lib/ain-cpp-imports/src/bridge.rs index 79a1a89130..a1ad4df87f 100644 --- a/lib/ain-cpp-imports/src/bridge.rs +++ b/lib/ain-cpp-imports/src/bridge.rs @@ -50,6 +50,8 @@ pub mod ffi { fn getNumCores() -> i32; fn getCORSAllowedOrigin() -> String; fn getNumConnections() -> i32; + fn getEccLruCacheCount() -> usize; + fn getEvmValidationLruCacheCount() -> usize; fn isEthDebugRPCEnabled() -> bool; fn isEthDebugTraceRPCEnabled() -> bool; } diff --git a/lib/ain-cpp-imports/src/lib.rs b/lib/ain-cpp-imports/src/lib.rs index 9912cf27bd..ece5efcdb7 100644 --- a/lib/ain-cpp-imports/src/lib.rs +++ b/lib/ain-cpp-imports/src/lib.rs @@ -100,6 +100,12 @@ mod ffi { pub fn getNumConnections() -> i32 { unimplemented!("{}", UNIMPL_MSG) } + pub fn getEccLruCacheCount() -> usize { + unimplemented!("{}", UNIMPL_MSG) + } + pub fn getEvmValidationLruCacheCount() -> usize { + unimplemented!("{}", UNIMPL_MSG) + } pub fn isEthDebugRPCEnabled() -> bool { unimplemented!("{}", UNIMPL_MSG) } @@ -217,6 +223,14 @@ pub fn get_num_connections() -> i32 { ffi::getNumConnections() } +pub fn get_ecc_lru_cache_count() -> usize { + ffi::getEccLruCacheCount() +} + +pub fn get_evmv_lru_cache_count() -> usize { + ffi::getEvmValidationLruCacheCount() +} + pub fn is_eth_debug_rpc_enabled() -> bool { ffi::isEthDebugRPCEnabled() } diff --git a/lib/ain-evm/src/core.rs b/lib/ain-evm/src/core.rs index 5d9dd24bea..32bc8d9629 100644 --- a/lib/ain-evm/src/core.rs +++ b/lib/ain-evm/src/core.rs @@ -49,11 +49,9 @@ pub struct SignedTxCache { inner: spin::Mutex>, } -const DEFAULT_CACHE_SIZE: usize = 10000; - impl Default for SignedTxCache { fn default() -> Self { - Self::new(DEFAULT_CACHE_SIZE) + Self::new(ain_cpp_imports::get_ecc_lru_cache_count()) } } @@ -104,7 +102,7 @@ struct TxValidationCache { impl Default for TxValidationCache { fn default() -> Self { - Self::new(DEFAULT_CACHE_SIZE) + Self::new(ain_cpp_imports::get_evmv_lru_cache_count()) } } diff --git a/src/dfi/threadpool.h b/src/dfi/threadpool.h index a8fc05e564..d50fccfd61 100644 --- a/src/dfi/threadpool.h +++ b/src/dfi/threadpool.h @@ -7,6 +7,7 @@ #include static const int DEFAULT_DFTX_WORKERS = 0; +static const int DEFAULT_ECC_PRECACHE_WORKERS = -1; // Until C++20x concurrency impls make it into standard, std::future and std::async impls // doesn't have the primitives needed for working with many at the same time efficiently diff --git a/src/ffi/ffiexports.cpp b/src/ffi/ffiexports.cpp index b63bd2ed84..0841b6a153 100644 --- a/src/ffi/ffiexports.cpp +++ b/src/ffi/ffiexports.cpp @@ -301,10 +301,18 @@ int32_t getNumConnections() { return (int32_t)g_connman->GetNodeCount(CConnman::CONNECTIONS_ALL); } +size_t getEccLruCacheCount() { + return gArgs.GetArg("-ecclrucache", DEFAULT_ECC_LRU_CACHE_COUNT); +} + +size_t getEvmValidationLruCacheCount() { + return gArgs.GetArg("-evmvlrucache", DEFAULT_EVMV_LRU_CACHE_COUNT); +} + bool isEthDebugRPCEnabled() { - return gArgs.GetBoolArg("-ethdebug", false); + return gArgs.GetBoolArg("-ethdebug", DEFAULT_ETH_DEBUG_ENABLED); } bool isEthDebugTraceRPCEnabled() { - return gArgs.GetBoolArg("-ethdebugtrace", true); + return gArgs.GetBoolArg("-ethdebugtrace", DEFAULT_ETH_DEBUG_TRACE_ENABLED); } diff --git a/src/ffi/ffiexports.h b/src/ffi/ffiexports.h index 45e689f19d..51d2896bd2 100644 --- a/src/ffi/ffiexports.h +++ b/src/ffi/ffiexports.h @@ -11,8 +11,11 @@ static constexpr uint64_t DEFAULT_EVM_BLOCK_GAS_LIMIT = 30000000; static constexpr uint64_t DEFAULT_EVM_FINALITY_COUNT = 100; static constexpr uint32_t DEFAULT_ETH_MAX_CONNECTIONS = 100; -static constexpr bool DEFAULT_DEBUG_ENABLED = false; -static constexpr bool DEFAULT_DEBUG_TRACE_ENABLED = true; +static constexpr uint32_t DEFAULT_ECC_LRU_CACHE_COUNT = 10000; +static constexpr uint32_t DEFAULT_EVMV_LRU_CACHE_COUNT = 10000; + +static constexpr bool DEFAULT_ETH_DEBUG_ENABLED = false; +static constexpr bool DEFAULT_ETH_DEBUG_TRACE_ENABLED = true; struct Attributes { uint64_t blockGasTarget; @@ -74,6 +77,8 @@ rust::string getClientVersion(); int32_t getNumCores(); rust::string getCORSAllowedOrigin(); int32_t getNumConnections(); +size_t getEccLruCacheCount(); +size_t getEvmValidationLruCacheCount(); bool isEthDebugRPCEnabled(); bool isEthDebugTraceRPCEnabled(); diff --git a/src/init.cpp b/src/init.cpp index 6b7bf1343f..8de325b409 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -424,6 +424,9 @@ void SetupServerArgs() gArgs.AddArg("-datadir=", "Specify data directory", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); gArgs.AddArg("-dbbatchsize", strprintf("Maximum database write batch size in bytes (default: %u)", nDefaultDbBatchSize), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::OPTIONS); gArgs.AddArg("-dbcache=", strprintf("Maximum database cache size MiB (%d to %d, default: %d). In addition, unused mempool memory is shared for this cache (see -maxmempool).", nMinDbCache, nMaxDbCache, nDefaultDbCache), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); + gArgs.AddArg("-ecclrucache=", strprintf("Maximum ECC LRU cache size items (default: %d).", DEFAULT_ECC_LRU_CACHE_COUNT), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); + gArgs.AddArg("-evmvlrucache=", strprintf("Maximum EVM TX Validator LRU cache size items (default: %d).", DEFAULT_EVMV_LRU_CACHE_COUNT), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); + gArgs.AddArg("-eccprecache=", strprintf("ECC pre-cache concurrency control (default: %d, (-1: auto, 0: disable, : workers).", DEFAULT_ECC_PRECACHE_WORKERS), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); gArgs.AddArg("-debuglogfile=", strprintf("Specify location of debug log file. Relative paths will be prefixed by a net-specific datadir location. (-nodebuglogfile to disable; default: %s)", DEFAULT_DEBUGLOGFILE), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); gArgs.AddArg("-feefilter", strprintf("Tell other nodes to filter invs to us by our mempool min fee (default: %u)", DEFAULT_FEEFILTER), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::OPTIONS); gArgs.AddArg("-includeconf=", "Specify additional configuration file, relative to the -datadir path (only useable from configuration file, not command line)", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); @@ -652,8 +655,8 @@ void SetupServerArgs() gArgs.AddArg("-ethrpcport=", strprintf("Listen for ETH-JSON-RPC connections on > (default: %u, testnet: %u, changi: %u, devnet: %u, regtest: %u)", defaultBaseParams->ETHRPCPort(), testnetBaseParams->ETHRPCPort(), changiBaseParams->ETHRPCPort(), devnetBaseParams->ETHRPCPort(), regtestBaseParams->ETHRPCPort()), ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::RPC); gArgs.AddArg("-wsport=", strprintf("Listen for ETH-WebSockets connections on > (default: %u, testnet: %u, changi: %u, devnet: %u, regtest: %u)", defaultBaseParams->WSPort(), testnetBaseParams->WSPort(), changiBaseParams->WSPort(), devnetBaseParams->WSPort(), regtestBaseParams->ETHRPCPort()), ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::RPC); gArgs.AddArg("-ethmaxconnections=", strprintf("Set the maximum number of connections allowed by the ETH-RPC server (default: %u, testnet: %u, changi: %u, devnet: %u, regtest: %u)", DEFAULT_ETH_MAX_CONNECTIONS, DEFAULT_ETH_MAX_CONNECTIONS, DEFAULT_ETH_MAX_CONNECTIONS, DEFAULT_ETH_MAX_CONNECTIONS, DEFAULT_ETH_MAX_CONNECTIONS), ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::RPC); - gArgs.AddArg("-ethdebug", strprintf("Enable debug_* ETH RPCs (default: %b)", DEFAULT_DEBUG_ENABLED), ArgsManager::ALLOW_ANY, OptionsCategory::RPC); - gArgs.AddArg("-ethdebugtrace", strprintf("Enable debug_trace* ETH RPCs (default: %b)", DEFAULT_DEBUG_TRACE_ENABLED), ArgsManager::ALLOW_ANY, OptionsCategory::RPC); + gArgs.AddArg("-ethdebug", strprintf("Enable debug_* ETH RPCs (default: %b)", DEFAULT_ETH_DEBUG_ENABLED), ArgsManager::ALLOW_ANY, OptionsCategory::RPC); + gArgs.AddArg("-ethdebugtrace", strprintf("Enable debug_trace* ETH RPCs (default: %b)", DEFAULT_ETH_DEBUG_TRACE_ENABLED), ArgsManager::ALLOW_ANY, OptionsCategory::RPC); #if HAVE_DECL_DAEMON gArgs.AddArg("-daemon", "Run in the background as a daemon and accept commands", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); diff --git a/src/validation.cpp b/src/validation.cpp index 8435899cc4..16b4802170 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -3016,7 +3016,9 @@ bool CChainState::ConnectBlock(const CBlock &block, XResultThrowOnErr(evm_try_unsafe_update_state_in_template( result, evmTemplate->GetTemplate(), static_cast(reinterpret_cast(&mnview)))); - { + auto eccPreCacheControl = gArgs.GetArg("-eccprecache", DEFAULT_ECC_PRECACHE_WORKERS); + auto isEccPreCacheEnabled = eccPreCacheControl == -1 || eccPreCacheControl > 0; + if (isEccPreCacheEnabled) { // Pre-warm validation cache auto &pool = DfTxTaskPool->pool;