From a4ff975ee8f529bc8019e9d72dac0a24fb3762f1 Mon Sep 17 00:00:00 2001 From: Dmytro Nazarenko Date: Fri, 17 May 2024 15:55:36 +0100 Subject: [PATCH 01/41] Update VERSION --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 419f30096..eb9b76c9f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.19.0 +3.20.0 From 7165e07e46bd4f67b2727dd8ee02f884c2f810de Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Mon, 1 Jul 2024 19:45:38 +0100 Subject: [PATCH 02/41] IS-552 disable heartbeat on pub site --- libskale/broadcaster.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/libskale/broadcaster.cpp b/libskale/broadcaster.cpp index 195b055f9..dcd5b19b7 100644 --- a/libskale/broadcaster.cpp +++ b/libskale/broadcaster.cpp @@ -90,15 +90,8 @@ void* ZmqBroadcaster::server_socket() const { if ( !m_zmq_server_socket ) { m_zmq_server_socket = zmq_socket( m_zmq_context, ZMQ_PUB ); - int val = 15000; - zmq_setsockopt( m_zmq_server_socket, ZMQ_HEARTBEAT_IVL, &val, sizeof( val ) ); - val = 3000; - zmq_setsockopt( m_zmq_server_socket, ZMQ_HEARTBEAT_TIMEOUT, &val, sizeof( val ) ); - val = 60000; - zmq_setsockopt( m_zmq_server_socket, ZMQ_HEARTBEAT_TTL, &val, sizeof( val ) ); - // remove limits to prevent txns from being dropped out - val = 0; + int val = 0; zmq_setsockopt( m_zmq_server_socket, ZMQ_SNDHWM, &val, sizeof( val ) ); From 9cd9458bd2f60b338e14566bdd4aa3742065ab4d Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Wed, 3 Jul 2024 16:31:33 +0100 Subject: [PATCH 03/41] IS-552 fix build --- libconsensus | 2 +- libskale/broadcaster.cpp | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/libconsensus b/libconsensus index 9683c93ec..b1916ed05 160000 --- a/libconsensus +++ b/libconsensus @@ -1 +1 @@ -Subproject commit 9683c93ec19d4dd28724d9ec2e105677360918d1 +Subproject commit b1916ed05c3b77f5925662fa591b9a054290d0fd diff --git a/libskale/broadcaster.cpp b/libskale/broadcaster.cpp index 4d68cfea6..2b594c501 100644 --- a/libskale/broadcaster.cpp +++ b/libskale/broadcaster.cpp @@ -90,10 +90,9 @@ void* ZmqBroadcaster::server_socket() const { if ( !m_zmq_server_socket ) { m_zmq_server_socket = zmq_socket( m_zmq_context, ZMQ_PUB ); - val = 16; + int val = 16; zmq_setsockopt( m_zmq_server_socket, ZMQ_SNDHWM, &val, sizeof( val ) ); - const dev::eth::ChainParams& ch = m_client.chainParams(); // connect server to clients From b0f2319277e43d585648b1eea48970a3c69512c0 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Mon, 8 Jul 2024 13:53:06 +0100 Subject: [PATCH 04/41] #1741 move tracing api to the separate server --- libweb3jsonrpc/CMakeLists.txt | 4 + libweb3jsonrpc/Debug.cpp | 255 +--------------------- libweb3jsonrpc/Debug.h | 22 +- libweb3jsonrpc/DebugFace.h | 57 ----- libweb3jsonrpc/Tracing.cpp | 245 +++++++++++++++++++++ libweb3jsonrpc/Tracing.h | 60 +++++ libweb3jsonrpc/TracingFace.h | 76 +++++++ skaled/main.cpp | 25 ++- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 2 +- 9 files changed, 402 insertions(+), 344 deletions(-) create mode 100644 libweb3jsonrpc/Tracing.cpp create mode 100644 libweb3jsonrpc/Tracing.h create mode 100644 libweb3jsonrpc/TracingFace.h diff --git a/libweb3jsonrpc/CMakeLists.txt b/libweb3jsonrpc/CMakeLists.txt index b1b50a770..00a748f89 100644 --- a/libweb3jsonrpc/CMakeLists.txt +++ b/libweb3jsonrpc/CMakeLists.txt @@ -36,6 +36,10 @@ set(sources Web3Face.h WhisperFace.h + Tracing.h + Tracing.cpp + TracingFace.h + SkalePerformanceTracker.h SkalePerformanceTracker.cpp SkalePerformanceTrackerFace.h diff --git a/libweb3jsonrpc/Debug.cpp b/libweb3jsonrpc/Debug.cpp index dc7de9e52..10d01f4a3 100644 --- a/libweb3jsonrpc/Debug.cpp +++ b/libweb3jsonrpc/Debug.cpp @@ -26,246 +26,8 @@ using namespace dev::eth; using namespace skale; -#define THROW_TRACE_JSON_EXCEPTION( __MSG__ ) \ - throw jsonrpc::JsonRpcException( std::string( __FUNCTION__ ) + ":" + \ - std::to_string( __LINE__ ) + ":" + std::string( __MSG__ ) ) - - -void Debug::checkPrivilegedAccess() const { - if ( !m_enablePrivilegedApis ) { - BOOST_THROW_EXCEPTION( jsonrpc::JsonRpcException( "This API call is not enabled" ) ); - } -} - -void Debug::checkHistoricStateEnabled() const { -#ifndef HISTORIC_STATE - BOOST_THROW_EXCEPTION( - jsonrpc::JsonRpcException( "This API call is available on archive nodes only" ) ); -#endif -} - -Debug::Debug( eth::Client& _eth, SkaleDebugInterface* _debugInterface, const string& argv, - bool _enablePrivilegedApis ) - : m_eth( _eth ), - m_debugInterface( _debugInterface ), - m_argvOptions( argv ), - m_blockTraceCache( MAX_BLOCK_TRACES_CACHE_ITEMS, MAX_BLOCK_TRACES_CACHE_SIZE ), - m_enablePrivilegedApis( _enablePrivilegedApis ) {} - - -h256 Debug::blockHash( string const& _blockNumberOrHash ) const { - checkPrivilegedAccess(); - if ( isHash< h256 >( _blockNumberOrHash ) ) - return h256( _blockNumberOrHash.substr( _blockNumberOrHash.size() - 64, 64 ) ); - try { - return m_eth.blockChain().numberHash( stoul( _blockNumberOrHash ) ); - } catch ( ... ) { - THROW_TRACE_JSON_EXCEPTION( "Invalid argument" ); - } -} - -Json::Value Debug::debug_traceBlockByNumber( const string& -#ifdef HISTORIC_STATE - _blockNumber -#endif - , - Json::Value const& -#ifdef HISTORIC_STATE - _jsonTraceConfig -#endif -) { - Json::Value ret; - checkHistoricStateEnabled(); -#ifdef HISTORIC_STATE - auto bN = jsToBlockNumber( _blockNumber ); - - if ( bN == LatestBlock || bN == PendingBlock ) { - bN = m_eth.number(); - } - - if ( !m_eth.isKnown( bN ) ) { - THROW_TRACE_JSON_EXCEPTION( "Unknown block number:" + _blockNumber ); - } - - if ( bN == 0 ) { - THROW_TRACE_JSON_EXCEPTION( "Block number must be more than zero" ); - } - - try { - return m_eth.traceBlock( bN, _jsonTraceConfig ); - } catch ( std::exception const& _e ) { - THROW_TRACE_JSON_EXCEPTION( _e.what() ); - } catch ( ... ) { - THROW_TRACE_JSON_EXCEPTION( "Unknown server error" ); - } -#else - THROW_TRACE_JSON_EXCEPTION( "This API call is only supported on archive nodes" ); -#endif -} - -Json::Value Debug::debug_traceBlockByHash( string const& -#ifdef HISTORIC_STATE - _blockHash -#endif - , - Json::Value const& -#ifdef HISTORIC_STATE - _jsonTraceConfig -#endif -) { - checkHistoricStateEnabled(); - -#ifdef HISTORIC_STATE - h256 h = jsToFixed< 32 >( _blockHash ); - - if ( !m_eth.isKnown( h ) ) { - THROW_TRACE_JSON_EXCEPTION( "Unknown block hash" + _blockHash ); - } - - BlockNumber bN = m_eth.numberFromHash( h ); - - if ( bN == 0 ) { - THROW_TRACE_JSON_EXCEPTION( "Block number must be more than zero" ); - } - - try { - return m_eth.traceBlock( bN, _jsonTraceConfig ); - } catch ( std::exception const& _e ) { - THROW_TRACE_JSON_EXCEPTION( _e.what() ); - } catch ( ... ) { - THROW_TRACE_JSON_EXCEPTION( "Unknown server error" ); - } -#else - THROW_TRACE_JSON_EXCEPTION( "This API call is only supported on archive nodes" ); -#endif -} - - -Json::Value Debug::debug_traceTransaction( string const& -#ifdef HISTORIC_STATE - _txHashStr -#endif - , - Json::Value const& -#ifdef HISTORIC_STATE - _jsonTraceConfig -#endif -) { - - checkHistoricStateEnabled(); -#ifdef HISTORIC_STATE - auto txHash = h256( _txHashStr ); - - LocalisedTransaction localisedTransaction = m_eth.localisedTransaction( txHash ); - - if ( localisedTransaction.blockHash() == h256( 0 ) ) { - THROW_TRACE_JSON_EXCEPTION( - "Can't find committed transaction with this hash:" + _txHashStr ); - } - - auto blockNumber = localisedTransaction.blockNumber(); - - - if ( !m_eth.isKnown( blockNumber ) ) { - THROW_TRACE_JSON_EXCEPTION( "Unknown block number:" + to_string( blockNumber ) ); - } - - if ( blockNumber == 0 ) { - THROW_TRACE_JSON_EXCEPTION( "Block number must be more than zero" ); - } - - try { - Json::Value tracedBlock; - - tracedBlock = m_eth.traceBlock( blockNumber, _jsonTraceConfig ); - STATE_CHECK( tracedBlock.isArray() ) - STATE_CHECK( !tracedBlock.empty() ) - - - string lowerCaseTxStr = _txHashStr; - for ( auto& c : lowerCaseTxStr ) { - c = std::tolower( static_cast< unsigned char >( c ) ); - } - - - for ( Json::Value::ArrayIndex i = 0; i < tracedBlock.size(); i++ ) { - Json::Value& transactionTrace = tracedBlock[i]; - STATE_CHECK( transactionTrace.isObject() ); - STATE_CHECK( transactionTrace.isMember( "txHash" ) ); - if ( transactionTrace["txHash"] == lowerCaseTxStr ) { - STATE_CHECK( transactionTrace.isMember( "result" ) ); - return transactionTrace["result"]; - } - } - - THROW_TRACE_JSON_EXCEPTION( "Transaction not found in block" ); - - } catch ( jsonrpc::JsonRpcException& ) { - throw; - } catch ( std::exception const& _e ) { - THROW_TRACE_JSON_EXCEPTION( _e.what() ); - } catch ( ... ) { - THROW_TRACE_JSON_EXCEPTION( "Unknown server error" ); - } -#else - BOOST_THROW_EXCEPTION( - jsonrpc::JsonRpcException( "This API call is only supported on archive nodes" ) ); -#endif -} - -Json::Value Debug::debug_traceCall( Json::Value const& -#ifdef HISTORIC_STATE - _call -#endif - , - std::string const& -#ifdef HISTORIC_STATE - _blockNumber -#endif - , - Json::Value const& -#ifdef HISTORIC_STATE - _jsonTraceConfig -#endif -) { - - Json::Value ret; - checkHistoricStateEnabled(); - -#ifdef HISTORIC_STATE - - try { - auto bN = jsToBlockNumber( _blockNumber ); - - if ( bN == LatestBlock || bN == PendingBlock ) { - bN = m_eth.number(); - } - - if ( !m_eth.isKnown( bN ) ) { - THROW_TRACE_JSON_EXCEPTION( "Unknown block number:" + _blockNumber ); - } - - if ( bN == 0 ) { - THROW_TRACE_JSON_EXCEPTION( "Block number must be more than zero" ); - } - - TransactionSkeleton ts = toTransactionSkeleton( _call ); - - return m_eth.traceCall( - ts.from, ts.value, ts.to, ts.data, ts.gas, ts.gasPrice, bN, _jsonTraceConfig ); - } catch ( jsonrpc::JsonRpcException& ) { - throw; - } catch ( std::exception const& _e ) { - THROW_TRACE_JSON_EXCEPTION( _e.what() ); - } catch ( ... ) { - THROW_TRACE_JSON_EXCEPTION( "Unknown server error" ); - } - -#else - BOOST_THROW_EXCEPTION( - jsonrpc::JsonRpcException( "This API call is only supported on archive nodes" ) ); -#endif -} +Debug::Debug( eth::Client& _eth, SkaleDebugInterface* _debugInterface, const string& argv ) + : m_eth( _eth ), m_debugInterface( _debugInterface ), m_argvOptions( argv ) {} Json::Value Debug::debug_accountRangeAt( string const&, int, string const&, int ) { @@ -280,22 +42,17 @@ string Debug::debug_preimage( string const& ) { BOOST_THROW_EXCEPTION( jsonrpc::JsonRpcException( "This API call is not supported" ) ); } - void Debug::debug_pauseBroadcast( bool _pause ) { - checkPrivilegedAccess(); m_eth.skaleHost()->pauseBroadcast( _pause ); } void Debug::debug_pauseConsensus( bool _pause ) { - checkPrivilegedAccess(); m_eth.skaleHost()->pauseConsensus( _pause ); } void Debug::debug_forceBlock() { - checkPrivilegedAccess(); m_eth.skaleHost()->forceEmptyBlock(); } void Debug::debug_forceBroadcast( const string& _transactionHash ) { - checkPrivilegedAccess(); try { h256 h = jsToFixed< 32 >( _transactionHash ); if ( !m_eth.isKnownTransaction( h ) ) @@ -311,32 +68,26 @@ void Debug::debug_forceBroadcast( const string& _transactionHash ) { } string Debug::debug_interfaceCall( const string& _arg ) { - checkPrivilegedAccess(); return m_debugInterface->call( _arg ); } string Debug::debug_getVersion() { - checkPrivilegedAccess(); return Version; } string Debug::debug_getArguments() { - checkPrivilegedAccess(); return m_argvOptions; } string Debug::debug_getConfig() { - checkPrivilegedAccess(); return m_eth.chainParams().getOriginalJson(); } string Debug::debug_getSchainName() { - checkPrivilegedAccess(); return m_eth.chainParams().sChain.name; } uint64_t Debug::debug_getSnapshotCalculationTime() { - checkPrivilegedAccess(); return m_eth.getSnapshotCalculationTime(); } @@ -345,7 +96,6 @@ uint64_t Debug::debug_getSnapshotHashCalculationTime() { } uint64_t Debug::debug_doStateDbCompaction() { - checkPrivilegedAccess(); auto t1 = boost::chrono::high_resolution_clock::now(); m_eth.doStateDbCompaction(); auto t2 = boost::chrono::high_resolution_clock::now(); @@ -354,7 +104,6 @@ uint64_t Debug::debug_doStateDbCompaction() { } uint64_t Debug::debug_doBlocksDbCompaction() { - checkPrivilegedAccess(); auto t1 = boost::chrono::high_resolution_clock::now(); m_eth.doBlocksDbCompaction(); auto t2 = boost::chrono::high_resolution_clock::now(); diff --git a/libweb3jsonrpc/Debug.h b/libweb3jsonrpc/Debug.h index 63c88405a..bc94d38d7 100644 --- a/libweb3jsonrpc/Debug.h +++ b/libweb3jsonrpc/Debug.h @@ -19,13 +19,10 @@ class Client; namespace rpc { class SessionManager; -constexpr size_t MAX_BLOCK_TRACES_CACHE_SIZE = 64 * 1024 * 1024; -constexpr size_t MAX_BLOCK_TRACES_CACHE_ITEMS = 1024 * 1024; - class Debug : public DebugFace { public: explicit Debug( eth::Client& _eth, SkaleDebugInterface* _debugInterface = nullptr, - const std::string& argv = std::string(), bool _enablePrivilegedApis = false ); + const std::string& argv = std::string() ); virtual RPCModules implementedModules() const override { return RPCModules{ RPCModule{ "debug", "1.0" } }; @@ -33,14 +30,6 @@ class Debug : public DebugFace { virtual Json::Value debug_accountRangeAt( std::string const& _blockHashOrNumber, int _txIndex, std::string const& _addressHash, int _maxResults ) override; - virtual Json::Value debug_traceTransaction( - std::string const& _txHash, Json::Value const& _json ) override; - virtual Json::Value debug_traceCall( Json::Value const& _call, std::string const& _blockNumber, - Json::Value const& _options ) override; - virtual Json::Value debug_traceBlockByNumber( - std::string const& _blockNumber, Json::Value const& _json ) override; - virtual Json::Value debug_traceBlockByHash( - std::string const& _blockHash, Json::Value const& _json ) override; virtual Json::Value debug_storageRangeAt( std::string const& _blockHashOrNumber, int _txIndex, std::string const& _address, std::string const& _begin, int _maxResults ) override; virtual std::string debug_preimage( std::string const& _hashedKey ) override; @@ -68,15 +57,6 @@ class Debug : public DebugFace { eth::Client& m_eth; SkaleDebugInterface* m_debugInterface = nullptr; std::string m_argvOptions; - cache::lru_ordered_memory_constrained_cache< std::string, Json::Value > m_blockTraceCache; - bool m_enablePrivilegedApis; - - - h256 blockHash( std::string const& _blockHashOrNumber ) const; - - void checkPrivilegedAccess() const; - - void checkHistoricStateEnabled() const; }; } // namespace rpc diff --git a/libweb3jsonrpc/DebugFace.h b/libweb3jsonrpc/DebugFace.h index cfee3b7cb..6c57c383c 100644 --- a/libweb3jsonrpc/DebugFace.h +++ b/libweb3jsonrpc/DebugFace.h @@ -19,10 +19,6 @@ class DebugFace : public ServerInterface< DebugFace > { jsonrpc::JSON_STRING, "param4", jsonrpc::JSON_INTEGER, NULL ), &dev::rpc::DebugFace::debug_accountRangeAtI ); - - this->bindAndAddMethod( jsonrpc::Procedure( "debug_traceTransaction", - jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, NULL ), - &dev::rpc::DebugFace::debug_traceTransactionI ); this->bindAndAddMethod( jsonrpc::Procedure( "debug_storageRangeAt", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1", jsonrpc::JSON_STRING, "param2", @@ -32,16 +28,6 @@ class DebugFace : public ServerInterface< DebugFace > { this->bindAndAddMethod( jsonrpc::Procedure( "debug_preimage", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1", jsonrpc::JSON_STRING, NULL ), &dev::rpc::DebugFace::debug_preimageI ); - this->bindAndAddMethod( jsonrpc::Procedure( "debug_traceBlockByNumber", - jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, NULL ), - &dev::rpc::DebugFace::debug_traceBlockByNumberI ); - this->bindAndAddMethod( jsonrpc::Procedure( "debug_traceBlockByHash", - jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, NULL ), - &dev::rpc::DebugFace::debug_traceBlockByHashI ); - this->bindAndAddMethod( jsonrpc::Procedure( "debug_traceCall", jsonrpc::PARAMS_BY_POSITION, - jsonrpc::JSON_OBJECT, "param1", jsonrpc::JSON_OBJECT, "param2", - jsonrpc::JSON_STRING, "param3", jsonrpc::JSON_OBJECT, NULL ), - &dev::rpc::DebugFace::debug_traceCallI ); this->bindAndAddMethod( jsonrpc::Procedure( "debug_pauseConsensus", jsonrpc::PARAMS_BY_POSITION, @@ -108,24 +94,6 @@ class DebugFace : public ServerInterface< DebugFace > { request[2u].asString(), request[3u].asInt() ); } - inline virtual Json::Value getTracer( const Json::Value& request ) { - if ( !request.isArray() || request.empty() || request.size() > 2 ) { - BOOST_THROW_EXCEPTION( - jsonrpc::JsonRpcException( jsonrpc::Errors::ERROR_RPC_INVALID_PARAMS ) ); - } - if ( request.size() == 2 ) { - if ( !request[1u].isObject() ) { - BOOST_THROW_EXCEPTION( - jsonrpc::JsonRpcException( jsonrpc::Errors::ERROR_RPC_INVALID_PARAMS ) ); - } - return request[1u]; - - } else { - return { Json::objectValue }; - } - } - - inline virtual void debug_storageRangeAtI( const Json::Value& request, Json::Value& response ) { response = this->debug_storageRangeAt( request[0u].asString(), request[1u].asInt(), request[2u].asString(), request[3u].asString(), request[4u].asInt() ); @@ -134,23 +102,6 @@ class DebugFace : public ServerInterface< DebugFace > { response = this->debug_preimage( request[0u].asString() ); } - inline virtual void debug_traceTransactionI( - const Json::Value& request, Json::Value& response ) { - response = this->debug_traceTransaction( request[0u].asString(), getTracer( request ) ); - } - - inline virtual void debug_traceBlockByNumberI( - const Json::Value& request, Json::Value& response ) { - response = this->debug_traceBlockByNumber( request[0u].asString(), getTracer( request ) ); - } - inline virtual void debug_traceBlockByHashI( - const Json::Value& request, Json::Value& response ) { - response = this->debug_traceBlockByHash( request[0u].asString(), getTracer( request ) ); - } - inline virtual void debug_traceCallI( const Json::Value& request, Json::Value& response ) { - response = this->debug_traceCall( request[0u], request[1u].asString(), request[2u] ); - } - virtual void debug_pauseBroadcastI( const Json::Value& request, Json::Value& response ) { this->debug_pauseBroadcast( request[0u].asBool() ); response = true; // TODO make void @@ -210,17 +161,9 @@ class DebugFace : public ServerInterface< DebugFace > { virtual Json::Value debug_accountRangeAt( const std::string& param1, int param2, const std::string& param3, int param4 ) = 0; - virtual Json::Value debug_traceTransaction( - const std::string& param1, const Json::Value& param2 ) = 0; virtual Json::Value debug_storageRangeAt( const std::string& param1, int param2, const std::string& param3, const std::string& param4, int param5 ) = 0; virtual std::string debug_preimage( const std::string& param1 ) = 0; - virtual Json::Value debug_traceBlockByNumber( - const std::string& param1, const Json::Value& param2 ) = 0; - virtual Json::Value debug_traceBlockByHash( - const std::string& param1, const Json::Value& param2 ) = 0; - virtual Json::Value debug_traceCall( Json::Value const& _call, std::string const& _blockNumber, - Json::Value const& _options ) = 0; virtual void debug_pauseBroadcast( bool pause ) = 0; virtual void debug_pauseConsensus( bool pause ) = 0; virtual void debug_forceBlock() = 0; diff --git a/libweb3jsonrpc/Tracing.cpp b/libweb3jsonrpc/Tracing.cpp new file mode 100644 index 000000000..1c8121ac0 --- /dev/null +++ b/libweb3jsonrpc/Tracing.cpp @@ -0,0 +1,245 @@ +#include "Tracing.h" + +#include + +#ifdef HISTORIC_STATE + +#include +#include +#endif + +using namespace std; +using namespace dev; +using namespace dev::rpc; +using namespace dev::eth; + + +#define THROW_TRACE_JSON_EXCEPTION( __MSG__ ) \ + throw jsonrpc::JsonRpcException( std::string( __FUNCTION__ ) + ":" + \ + std::to_string( __LINE__ ) + ":" + std::string( __MSG__ ) ) + +void Tracing::checkHistoricStateEnabled() const { +#ifndef HISTORIC_STATE + BOOST_THROW_EXCEPTION( + jsonrpc::JsonRpcException( "This API call is available on archive nodes only" ) ); +#endif +} + +Tracing::Tracing( eth::Client& _eth, const string& argv ) + : m_eth( _eth ), + m_argvOptions( argv ), + m_blockTraceCache( MAX_BLOCK_TRACES_CACHE_ITEMS, MAX_BLOCK_TRACES_CACHE_SIZE ) {} + +h256 Tracing::blockHash( string const& _blockNumberOrHash ) const { + checkPrivilegedAccess(); + if ( isHash< h256 >( _blockNumberOrHash ) ) + return h256( _blockNumberOrHash.substr( _blockNumberOrHash.size() - 64, 64 ) ); + try { + return m_eth.blockChain().numberHash( stoul( _blockNumberOrHash ) ); + } catch ( ... ) { + THROW_TRACE_JSON_EXCEPTION( "Invalid argument" ); + } +} + +Json::Value Tracing::tracing_traceBlockByNumber( const string& +#ifdef HISTORIC_STATE + _blockNumber +#endif + , + Json::Value const& +#ifdef HISTORIC_STATE + _jsonTraceConfig +#endif +) { + Json::Value ret; + checkHistoricStateEnabled(); +#ifdef HISTORIC_STATE + auto bN = jsToBlockNumber( _blockNumber ); + + if ( bN == LatestBlock || bN == PendingBlock ) { + bN = m_eth.number(); + } + + if ( !m_eth.isKnown( bN ) ) { + THROW_TRACE_JSON_EXCEPTION( "Unknown block number:" + _blockNumber ); + } + + if ( bN == 0 ) { + THROW_TRACE_JSON_EXCEPTION( "Block number must be more than zero" ); + } + + try { + return m_eth.traceBlock( bN, _jsonTraceConfig ); + } catch ( std::exception const& _e ) { + THROW_TRACE_JSON_EXCEPTION( _e.what() ); + } catch ( ... ) { + THROW_TRACE_JSON_EXCEPTION( "Unknown server error" ); + } +#else + THROW_TRACE_JSON_EXCEPTION( "This API call is only supported on archive nodes" ); +#endif +} + +Json::Value Tracing::tracing_traceBlockByHash( string const& +#ifdef HISTORIC_STATE + _blockHash +#endif + , + Json::Value const& +#ifdef HISTORIC_STATE + _jsonTraceConfig +#endif +) { + checkHistoricStateEnabled(); + +#ifdef HISTORIC_STATE + h256 h = jsToFixed< 32 >( _blockHash ); + + if ( !m_eth.isKnown( h ) ) { + THROW_TRACE_JSON_EXCEPTION( "Unknown block hash" + _blockHash ); + } + + BlockNumber bN = m_eth.numberFromHash( h ); + + if ( bN == 0 ) { + THROW_TRACE_JSON_EXCEPTION( "Block number must be more than zero" ); + } + + try { + return m_eth.traceBlock( bN, _jsonTraceConfig ); + } catch ( std::exception const& _e ) { + THROW_TRACE_JSON_EXCEPTION( _e.what() ); + } catch ( ... ) { + THROW_TRACE_JSON_EXCEPTION( "Unknown server error" ); + } +#else + THROW_TRACE_JSON_EXCEPTION( "This API call is only supported on archive nodes" ); +#endif +} + + +Json::Value Tracing::tracing_traceTransaction( string const& +#ifdef HISTORIC_STATE + _txHashStr +#endif + , + Json::Value const& +#ifdef HISTORIC_STATE + _jsonTraceConfig +#endif +) { + + checkHistoricStateEnabled(); +#ifdef HISTORIC_STATE + auto txHash = h256( _txHashStr ); + + LocalisedTransaction localisedTransaction = m_eth.localisedTransaction( txHash ); + + if ( localisedTransaction.blockHash() == h256( 0 ) ) { + THROW_TRACE_JSON_EXCEPTION( + "Can't find committed transaction with this hash:" + _txHashStr ); + } + + auto blockNumber = localisedTransaction.blockNumber(); + + + if ( !m_eth.isKnown( blockNumber ) ) { + THROW_TRACE_JSON_EXCEPTION( "Unknown block number:" + to_string( blockNumber ) ); + } + + if ( blockNumber == 0 ) { + THROW_TRACE_JSON_EXCEPTION( "Block number must be more than zero" ); + } + + try { + Json::Value tracedBlock; + + tracedBlock = m_eth.traceBlock( blockNumber, _jsonTraceConfig ); + STATE_CHECK( tracedBlock.isArray() ) + STATE_CHECK( !tracedBlock.empty() ) + + + string lowerCaseTxStr = _txHashStr; + for ( auto& c : lowerCaseTxStr ) { + c = std::tolower( static_cast< unsigned char >( c ) ); + } + + + for ( Json::Value::ArrayIndex i = 0; i < tracedBlock.size(); i++ ) { + Json::Value& transactionTrace = tracedBlock[i]; + STATE_CHECK( transactionTrace.isObject() ); + STATE_CHECK( transactionTrace.isMember( "txHash" ) ); + if ( transactionTrace["txHash"] == lowerCaseTxStr ) { + STATE_CHECK( transactionTrace.isMember( "result" ) ); + return transactionTrace["result"]; + } + } + + THROW_TRACE_JSON_EXCEPTION( "Transaction not found in block" ); + + } catch ( jsonrpc::JsonRpcException& ) { + throw; + } catch ( std::exception const& _e ) { + THROW_TRACE_JSON_EXCEPTION( _e.what() ); + } catch ( ... ) { + THROW_TRACE_JSON_EXCEPTION( "Unknown server error" ); + } +#else + BOOST_THROW_EXCEPTION( + jsonrpc::JsonRpcException( "This API call is only supported on archive nodes" ) ); +#endif +} + +Json::Value Tracing::tracing_traceCall( Json::Value const& +#ifdef HISTORIC_STATE + _call +#endif + , + std::string const& +#ifdef HISTORIC_STATE + _blockNumber +#endif + , + Json::Value const& +#ifdef HISTORIC_STATE + _jsonTraceConfig +#endif +) { + + Json::Value ret; + checkHistoricStateEnabled(); + +#ifdef HISTORIC_STATE + + try { + auto bN = jsToBlockNumber( _blockNumber ); + + if ( bN == LatestBlock || bN == PendingBlock ) { + bN = m_eth.number(); + } + + if ( !m_eth.isKnown( bN ) ) { + THROW_TRACE_JSON_EXCEPTION( "Unknown block number:" + _blockNumber ); + } + + if ( bN == 0 ) { + THROW_TRACE_JSON_EXCEPTION( "Block number must be more than zero" ); + } + + TransactionSkeleton ts = toTransactionSkeleton( _call ); + + return m_eth.traceCall( + ts.from, ts.value, ts.to, ts.data, ts.gas, ts.gasPrice, bN, _jsonTraceConfig ); + } catch ( jsonrpc::JsonRpcException& ) { + throw; + } catch ( std::exception const& _e ) { + THROW_TRACE_JSON_EXCEPTION( _e.what() ); + } catch ( ... ) { + THROW_TRACE_JSON_EXCEPTION( "Unknown server error" ); + } + +#else + BOOST_THROW_EXCEPTION( + jsonrpc::JsonRpcException( "This API call is only supported on archive nodes" ) ); +#endif +} diff --git a/libweb3jsonrpc/Tracing.h b/libweb3jsonrpc/Tracing.h new file mode 100644 index 000000000..73b262187 --- /dev/null +++ b/libweb3jsonrpc/Tracing.h @@ -0,0 +1,60 @@ +#ifndef TRACING_H +#define TRACING_H + +#include "TracingFace.h" +#include "test/tools/libtestutils/FixedClient.h" + +#include +#include +#include +#include + +class SkaleHost; +class SkaleDebugInterface; + +namespace dev { +namespace eth { +class Client; + +} // namespace eth +namespace rpc { +class SessionManager; + +constexpr size_t MAX_BLOCK_TRACES_CACHE_SIZE = 64 * 1024 * 1024; +constexpr size_t MAX_BLOCK_TRACES_CACHE_ITEMS = 1024 * 1024; + +class Tracing : public TracingFace { +public: + explicit Tracing( eth::Client& _eth, const std::string& argv = std::string() ); + + virtual RPCModules implementedModules() const override { + return RPCModules{ RPCModule{ "debug", "1.0" } }; + } + + virtual Json::Value tracing_traceTransaction( + std::string const& _txHash, Json::Value const& _json ) override; + virtual Json::Value tracing_traceCall( Json::Value const& _call, + std::string const& _blockNumber, Json::Value const& _options ) override; + virtual Json::Value tracing_traceBlockByNumber( + std::string const& _blockNumber, Json::Value const& _json ) override; + virtual Json::Value tracing_traceBlockByHash( + std::string const& _blockHash, Json::Value const& _json ) override; + +private: + eth::Client& m_eth; + std::string m_argvOptions; + cache::lru_ordered_memory_constrained_cache< std::string, Json::Value > m_blockTraceCache; + bool m_enablePrivilegedApis; + + h256 blockHash( std::string const& _blockHashOrNumber ) const; + + void checkPrivilegedAccess() const; + + void checkHistoricStateEnabled() const; +}; + +} // namespace rpc +} // namespace dev + + +#endif // TRACING_H diff --git a/libweb3jsonrpc/TracingFace.h b/libweb3jsonrpc/TracingFace.h new file mode 100644 index 000000000..b32df72f9 --- /dev/null +++ b/libweb3jsonrpc/TracingFace.h @@ -0,0 +1,76 @@ +#ifndef TRACINGFACE_H +#define TRACINGFACE_H + +#include "ModularServer.h" +#include "boost/throw_exception.hpp" + +namespace dev { +namespace rpc { +class TracingFace : public ServerInterface< TracingFace > { +public: + TracingFace() { + this->bindAndAddMethod( jsonrpc::Procedure( "tracing_traceTransaction", + jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, NULL ), + &dev::rpc::TracingFace::tracing_traceTransactionI ); + this->bindAndAddMethod( jsonrpc::Procedure( "tracing_traceBlockByNumber", + jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, NULL ), + &dev::rpc::TracingFace::tracing_traceBlockByNumberI ); + this->bindAndAddMethod( jsonrpc::Procedure( "tracing_traceBlockByHash", + jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, NULL ), + &dev::rpc::TracingFace::tracing_traceBlockByHashI ); + this->bindAndAddMethod( + jsonrpc::Procedure( "tracing_traceCall", jsonrpc::PARAMS_BY_POSITION, + jsonrpc::JSON_OBJECT, "param1", jsonrpc::JSON_OBJECT, "param2", + jsonrpc::JSON_STRING, "param3", jsonrpc::JSON_OBJECT, NULL ), + &dev::rpc::TracingFace::tracing_traceCallI ); + } + + inline virtual Json::Value getTracer( const Json::Value& request ) { + if ( !request.isArray() || request.empty() || request.size() > 2 ) { + BOOST_THROW_EXCEPTION( + jsonrpc::JsonRpcException( jsonrpc::Errors::ERROR_RPC_INVALID_PARAMS ) ); + } + if ( request.size() == 2 ) { + if ( !request[1u].isObject() ) { + BOOST_THROW_EXCEPTION( + jsonrpc::JsonRpcException( jsonrpc::Errors::ERROR_RPC_INVALID_PARAMS ) ); + } + return request[1u]; + + } else { + return { Json::objectValue }; + } + } + + inline virtual void tracing_traceTransactionI( + const Json::Value& request, Json::Value& response ) { + response = this->tracing_traceTransaction( request[0u].asString(), getTracer( request ) ); + } + + inline virtual void tracing_traceBlockByNumberI( + const Json::Value& request, Json::Value& response ) { + response = this->tracing_traceBlockByNumber( request[0u].asString(), getTracer( request ) ); + } + inline virtual void tracing_traceBlockByHashI( + const Json::Value& request, Json::Value& response ) { + response = this->tracing_traceBlockByHash( request[0u].asString(), getTracer( request ) ); + } + inline virtual void tracing_traceCallI( const Json::Value& request, Json::Value& response ) { + response = this->tracing_traceCall( request[0u], request[1u].asString(), request[2u] ); + } + + virtual Json::Value tracing_traceTransaction( + const std::string& param1, const Json::Value& param2 ) = 0; + virtual Json::Value tracing_traceBlockByNumber( + const std::string& param1, const Json::Value& param2 ) = 0; + virtual Json::Value tracing_traceBlockByHash( + const std::string& param1, const Json::Value& param2 ) = 0; + virtual Json::Value tracing_traceCall( Json::Value const& _call, + std::string const& _blockNumber, Json::Value const& _options ) = 0; +}; + +} // namespace rpc +} // namespace dev + + +#endif // TRACINGFACE_H diff --git a/skaled/main.cpp b/skaled/main.cpp index 9382c6dda..015f81eac 100644 --- a/skaled/main.cpp +++ b/skaled/main.cpp @@ -75,6 +75,7 @@ #include #include #include +#include #include #include @@ -1943,7 +1944,7 @@ int main( int argc, char** argv ) try { rpc::SkaleStats, /// skaleStats rpc::NetFace, rpc::Web3Face, rpc::PersonalFace, rpc::AdminEthFace, // SKALE rpc::AdminNetFace, - rpc::DebugFace, rpc::SkalePerformanceTracker, rpc::TestFace >; + rpc::DebugFace, rpc::SkalePerformanceTracker, rpc::TracingFace, rpc::TestFace >; sessionManager.reset( new rpc::SessionManager() ); accountHolder.reset( new SimpleAccountHolder( @@ -1980,16 +1981,16 @@ int main( int argc, char** argv ) try { auto pAdminEthFace = bEnabledAPIs_admin ? new rpc::AdminEth( *g_client, *gasPricer.get(), keyManager, *sessionManager.get() ) : nullptr; -#ifdef HISTORIC_STATE - // debug interface is always enabled in historic state, but - // non-tracing calls are only available if bEnabledAPIs_debug is true - auto pDebugFace = - new rpc::Debug( *g_client, &debugInterface, argv_string, bEnabledAPIs_debug ); -#else - // debug interface is enabled on core node if bEnabledAPIs_debug is true auto pDebugFace = bEnabledAPIs_debug ? - new rpc::Debug( *g_client, &debugInterface, argv_string, true ) : + new rpc::Debug( *g_client, &debugInterface, argv_string ) : nullptr; + +#ifdef HISTORIC_STATE + // tracing interface is always enabled for the historic state nodes + auto pTracingFace = new rpc::Tracing( *g_client, argv_string ); +#else + // tracing interface is only enabled for the historic state nodes + auto pTracingFace = nullptr; #endif @@ -1997,9 +1998,9 @@ int main( int argc, char** argv ) try { new rpc::SkalePerformanceTracker( configPath.string() ) : nullptr; - g_jsonrpcIpcServer.reset( - new FullServer( pEthFace, pSkaleFace, pSkaleStatsFace, pNetFace, pWeb3Face, - pPersonalFace, pAdminEthFace, pDebugFace, pPerformanceTrackerFace, nullptr ) ); + g_jsonrpcIpcServer.reset( new FullServer( pEthFace, pSkaleFace, pSkaleStatsFace, pNetFace, + pWeb3Face, pPersonalFace, pAdminEthFace, pDebugFace, pPerformanceTrackerFace, + pTracingFace, nullptr ) ); if ( is_ipc ) { try { diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index c955130e6..cd2de8781 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -369,7 +369,7 @@ JsonRpcFixture( const std::string& _config = "", bool _owner = true, rpcServer.reset( new FullServer( ethFace , new rpc::Net( chainParams ), new rpc::Web3(), // TODO Add version parameter here? new rpc::AdminEth( *client, *gasPricer, keyManager, *sessionManager ), - new rpc::Debug( *client, nullptr, "", true), + new rpc::Debug( *client, nullptr, ""), new rpc::Test( *client ) ) ); // From 873421578d9c485ef6ddf6ce76373bb6d79e8e42 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Mon, 8 Jul 2024 15:22:17 +0100 Subject: [PATCH 05/41] #1741 fix historic build --- libweb3jsonrpc/Tracing.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libweb3jsonrpc/Tracing.cpp b/libweb3jsonrpc/Tracing.cpp index 1c8121ac0..59f924760 100644 --- a/libweb3jsonrpc/Tracing.cpp +++ b/libweb3jsonrpc/Tracing.cpp @@ -1,6 +1,8 @@ #include "Tracing.h" +#include #include +#include #ifdef HISTORIC_STATE @@ -31,7 +33,6 @@ Tracing::Tracing( eth::Client& _eth, const string& argv ) m_blockTraceCache( MAX_BLOCK_TRACES_CACHE_ITEMS, MAX_BLOCK_TRACES_CACHE_SIZE ) {} h256 Tracing::blockHash( string const& _blockNumberOrHash ) const { - checkPrivilegedAccess(); if ( isHash< h256 >( _blockNumberOrHash ) ) return h256( _blockNumberOrHash.substr( _blockNumberOrHash.size() - 64, 64 ) ); try { From d6f305da6cdaea28f3cf0a4a90c847d56b4871bd Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Tue, 9 Jul 2024 11:47:24 +0100 Subject: [PATCH 06/41] #1741 fix tracing api methods name --- libweb3jsonrpc/TracingFace.h | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/libweb3jsonrpc/TracingFace.h b/libweb3jsonrpc/TracingFace.h index b32df72f9..a4296ec21 100644 --- a/libweb3jsonrpc/TracingFace.h +++ b/libweb3jsonrpc/TracingFace.h @@ -9,19 +9,18 @@ namespace rpc { class TracingFace : public ServerInterface< TracingFace > { public: TracingFace() { - this->bindAndAddMethod( jsonrpc::Procedure( "tracing_traceTransaction", + this->bindAndAddMethod( jsonrpc::Procedure( "debug_traceTransaction", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, NULL ), &dev::rpc::TracingFace::tracing_traceTransactionI ); - this->bindAndAddMethod( jsonrpc::Procedure( "tracing_traceBlockByNumber", + this->bindAndAddMethod( jsonrpc::Procedure( "debug_traceBlockByNumber", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, NULL ), &dev::rpc::TracingFace::tracing_traceBlockByNumberI ); - this->bindAndAddMethod( jsonrpc::Procedure( "tracing_traceBlockByHash", + this->bindAndAddMethod( jsonrpc::Procedure( "debug_traceBlockByHash", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, NULL ), &dev::rpc::TracingFace::tracing_traceBlockByHashI ); - this->bindAndAddMethod( - jsonrpc::Procedure( "tracing_traceCall", jsonrpc::PARAMS_BY_POSITION, - jsonrpc::JSON_OBJECT, "param1", jsonrpc::JSON_OBJECT, "param2", - jsonrpc::JSON_STRING, "param3", jsonrpc::JSON_OBJECT, NULL ), + this->bindAndAddMethod( jsonrpc::Procedure( "debug_traceCall", jsonrpc::PARAMS_BY_POSITION, + jsonrpc::JSON_OBJECT, "param1", jsonrpc::JSON_OBJECT, "param2", + jsonrpc::JSON_STRING, "param3", jsonrpc::JSON_OBJECT, NULL ), &dev::rpc::TracingFace::tracing_traceCallI ); } From 988f1167491bf66d5295603de6c3d0da12e8ed0d Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Thu, 11 Jul 2024 18:01:10 +0100 Subject: [PATCH 07/41] IS-1022 Try separate OverlayFS --- libethcore/ChainOperationParams.h | 11 +- libethereum/Executive.cpp | 5 +- libethereum/Precompiled.cpp | 69 ++++---- libethereum/Precompiled.h | 15 +- .../unittests/libethereum/PrecompiledTest.cpp | 89 ++++++----- test/unittests/libethereum/SkaleHost.cpp | 4 +- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 150 +++++++++++++----- 7 files changed, 208 insertions(+), 135 deletions(-) diff --git a/libethcore/ChainOperationParams.h b/libethcore/ChainOperationParams.h index 1383b84b8..9af1e8d5e 100644 --- a/libethcore/ChainOperationParams.h +++ b/libethcore/ChainOperationParams.h @@ -52,7 +52,10 @@ class PrecompiledContract { u256 const& _blockNumber ) const { return m_cost( _in, _chainParams, _blockNumber ); } - std::pair< bool, bytes > execute( bytesConstRef _in ) const { return m_execute( _in ); } + std::pair< bool, bytes > execute( + bytesConstRef _in, skale::OverlayFS* _overlayFS = nullptr ) const { + return m_execute( _in, _overlayFS ); + } u256 const& startingBlock() const { return m_startingBlock; } @@ -270,9 +273,9 @@ struct ChainOperationParams { Address const& _a, bytesConstRef _in, u256 const& _blockNumber ) const { return precompiled.at( _a ).cost( _in, *this, _blockNumber ); } - std::pair< bool, bytes > executePrecompiled( - Address const& _a, bytesConstRef _in, u256 const& ) const { - return precompiled.at( _a ).execute( _in ); + std::pair< bool, bytes > executePrecompiled( Address const& _a, bytesConstRef _in, u256 const&, + skale::OverlayFS* _overlayFS = nullptr ) const { + return precompiled.at( _a ).execute( _in, _overlayFS ); } bool precompiledExecutionAllowedFrom( Address const& _a, Address const& _from, bool _readOnly ) const { diff --git a/libethereum/Executive.cpp b/libethereum/Executive.cpp index 242245ba7..6c48746b4 100644 --- a/libethereum/Executive.cpp +++ b/libethereum/Executive.cpp @@ -332,9 +332,8 @@ bool Executive::call( CallParameters const& _p, u256 const& _gasPrice, Address c bytes output; bool success; // dev::eth::g_state = m_s.delegateWrite(); - dev::eth::g_overlayFS = m_s.fs(); - tie( success, output ) = - m_chainParams.executePrecompiled( _p.codeAddress, _p.data, m_envInfo.number() ); + tie( success, output ) = m_chainParams.executePrecompiled( + _p.codeAddress, _p.data, m_envInfo.number(), m_s.fs().get() ); // m_s = dev::eth::g_state.delegateWrite(); size_t outputSize = output.size(); m_output = owning_bytes_ref{ std::move( output ), 0, outputSize }; diff --git a/libethereum/Precompiled.cpp b/libethereum/Precompiled.cpp index ecbf7f770..eef66df34 100644 --- a/libethereum/Precompiled.cpp +++ b/libethereum/Precompiled.cpp @@ -60,7 +60,6 @@ namespace eth { std::shared_ptr< skutils::json_config_file_accessor > g_configAccesssor; std::shared_ptr< SkaleHost > g_skaleHost; -std::shared_ptr< skale::OverlayFS > g_overlayFS; }; // namespace eth }; // namespace dev @@ -87,7 +86,7 @@ PrecompiledPricer const& PrecompiledRegistrar::pricer( std::string const& _name namespace { -ETH_REGISTER_PRECOMPILED( ecrecover )( bytesConstRef _in ) { +ETH_REGISTER_PRECOMPILED( ecrecover )( bytesConstRef _in, skale::OverlayFS* ) { struct { h256 hash; h256 v; @@ -115,15 +114,15 @@ ETH_REGISTER_PRECOMPILED( ecrecover )( bytesConstRef _in ) { return { true, {} }; } -ETH_REGISTER_PRECOMPILED( sha256 )( bytesConstRef _in ) { +ETH_REGISTER_PRECOMPILED( sha256 )( bytesConstRef _in, skale::OverlayFS* ) { return { true, dev::sha256( _in ).asBytes() }; } -ETH_REGISTER_PRECOMPILED( ripemd160 )( bytesConstRef _in ) { +ETH_REGISTER_PRECOMPILED( ripemd160 )( bytesConstRef _in, skale::OverlayFS* ) { return { true, h256( dev::ripemd160( _in ), h256::AlignRight ).asBytes() }; } -ETH_REGISTER_PRECOMPILED( identity )( bytesConstRef _in ) { +ETH_REGISTER_PRECOMPILED( identity )( bytesConstRef _in, skale::OverlayFS* ) { MICROPROFILE_SCOPEI( "VM", "identity", MP_RED ); return { true, _in.toBytes() }; } @@ -150,7 +149,7 @@ bigint parseBigEndianRightPadded( bytesConstRef _in, bigint const& _begin, bigin return ret; } -ETH_REGISTER_PRECOMPILED( modexp )( bytesConstRef _in ) { +ETH_REGISTER_PRECOMPILED( modexp )( bytesConstRef _in, skale::OverlayFS* ) { bigint const baseLength( parseBigEndianRightPadded( _in, 0, 32 ) ); bigint const expLength( parseBigEndianRightPadded( _in, 32, 32 ) ); bigint const modLength( parseBigEndianRightPadded( _in, 64, 32 ) ); @@ -209,7 +208,7 @@ ETH_REGISTER_PRECOMPILED_PRICER( modexp ) return multComplexity( maxLength ) * max< bigint >( adjustedExpLength, 1 ) / 20; } -ETH_REGISTER_PRECOMPILED( alt_bn128_G1_add )( bytesConstRef _in ) { +ETH_REGISTER_PRECOMPILED( alt_bn128_G1_add )( bytesConstRef _in, skale::OverlayFS* ) { return dev::crypto::alt_bn128_G1_add( _in ); } @@ -218,7 +217,7 @@ ETH_REGISTER_PRECOMPILED_PRICER( alt_bn128_G1_add ) return _blockNumber < _chainParams.istanbulForkBlock ? 500 : 150; } -ETH_REGISTER_PRECOMPILED( alt_bn128_G1_mul )( bytesConstRef _in ) { +ETH_REGISTER_PRECOMPILED( alt_bn128_G1_mul )( bytesConstRef _in, skale::OverlayFS* ) { return dev::crypto::alt_bn128_G1_mul( _in ); } @@ -227,7 +226,7 @@ ETH_REGISTER_PRECOMPILED_PRICER( alt_bn128_G1_mul ) return _blockNumber < _chainParams.istanbulForkBlock ? 40000 : 6000; } -ETH_REGISTER_PRECOMPILED( alt_bn128_pairing_product )( bytesConstRef _in ) { +ETH_REGISTER_PRECOMPILED( alt_bn128_pairing_product )( bytesConstRef _in, skale::OverlayFS* ) { return dev::crypto::alt_bn128_pairing_product( _in ); } @@ -281,7 +280,7 @@ boost::filesystem::path getFileStorageDir( const Address& _address ) { } // TODO: check file name and file existance -ETH_REGISTER_PRECOMPILED( createFile )( bytesConstRef _in ) { +ETH_REGISTER_PRECOMPILED( createFile )( bytesConstRef _in, skale::OverlayFS* _overlayFS ) { try { auto rawAddress = _in.cropped( 12, 20 ).toBytes(); std::string address; @@ -297,14 +296,14 @@ ETH_REGISTER_PRECOMPILED( createFile )( bytesConstRef _in ) { const fs::path filePath( rawFilename ); const fs::path fsDirectoryPath = getFileStorageDir( Address( address ) ); if ( !fs::exists( fsDirectoryPath ) ) { - g_overlayFS->createDirectory( fsDirectoryPath.string() ); + _overlayFS->createDirectory( fsDirectoryPath.string() ); } const fs::path fsFilePath = fsDirectoryPath / filePath.parent_path(); if ( filePath.filename().extension() == "._hash" ) { throw std::runtime_error( "createFile() failed because _hash extension is not allowed" ); } - g_overlayFS->createFile( ( fsFilePath / filePath.filename() ).string(), fileSize ); + _overlayFS->createFile( ( fsFilePath / filePath.filename() ).string(), fileSize ); u256 code = 1; bytes response = toBigEndian( code ); @@ -322,7 +321,7 @@ ETH_REGISTER_PRECOMPILED( createFile )( bytesConstRef _in ) { return { false, response }; } -ETH_REGISTER_PRECOMPILED( uploadChunk )( bytesConstRef _in ) { +ETH_REGISTER_PRECOMPILED( uploadChunk )( bytesConstRef _in, skale::OverlayFS* _overlayFS ) { try { auto rawAddress = _in.cropped( 12, 20 ).toBytes(); std::string address; @@ -349,7 +348,7 @@ ETH_REGISTER_PRECOMPILED( uploadChunk )( bytesConstRef _in ) { const _byte_* data = _in.cropped( 128 + filenameBlocksCount * UINT256_SIZE, dataLength ).data(); - g_overlayFS->writeChunk( filePath.string(), position, dataLength, data ); + _overlayFS->writeChunk( filePath.string(), position, dataLength, data ); u256 code = 1; bytes response = toBigEndian( code ); @@ -367,7 +366,7 @@ ETH_REGISTER_PRECOMPILED( uploadChunk )( bytesConstRef _in ) { return { false, response }; } -ETH_REGISTER_PRECOMPILED( readChunk )( bytesConstRef _in ) { +ETH_REGISTER_PRECOMPILED( readChunk )( bytesConstRef _in, skale::OverlayFS* _overlayFS ) { MICROPROFILE_SCOPEI( "VM", "readChunk", MP_ORANGERED ); try { auto rawAddress = _in.cropped( 12, 20 ).toBytes(); @@ -418,7 +417,7 @@ ETH_REGISTER_PRECOMPILED( readChunk )( bytesConstRef _in ) { return { false, response }; } -ETH_REGISTER_PRECOMPILED( getFileSize )( bytesConstRef _in ) { +ETH_REGISTER_PRECOMPILED( getFileSize )( bytesConstRef _in, skale::OverlayFS* _overlayFS ) { try { auto rawAddress = _in.cropped( 12, 20 ).toBytes(); std::string address; @@ -451,7 +450,7 @@ ETH_REGISTER_PRECOMPILED( getFileSize )( bytesConstRef _in ) { return { false, response }; } -ETH_REGISTER_PRECOMPILED( deleteFile )( bytesConstRef _in ) { +ETH_REGISTER_PRECOMPILED( deleteFile )( bytesConstRef _in, skale::OverlayFS* _overlayFS ) { try { auto rawAddress = _in.cropped( 12, 20 ).toBytes(); std::string address; @@ -462,8 +461,8 @@ ETH_REGISTER_PRECOMPILED( deleteFile )( bytesConstRef _in ) { const fs::path filePath = getFileStorageDir( Address( address ) ) / filename; - g_overlayFS->deleteFile( filePath.string() ); - g_overlayFS->deleteFile( filePath.string() + "._hash" ); + _overlayFS->deleteFile( filePath.string() ); + _overlayFS->deleteFile( filePath.string() + "._hash" ); u256 code = 1; bytes response = toBigEndian( code ); @@ -481,7 +480,7 @@ ETH_REGISTER_PRECOMPILED( deleteFile )( bytesConstRef _in ) { return { false, response }; } -ETH_REGISTER_PRECOMPILED( createDirectory )( bytesConstRef _in ) { +ETH_REGISTER_PRECOMPILED( createDirectory )( bytesConstRef _in, skale::OverlayFS* _overlayFS ) { try { auto rawAddress = _in.cropped( 12, 20 ).toBytes(); std::string address; @@ -491,7 +490,7 @@ ETH_REGISTER_PRECOMPILED( createDirectory )( bytesConstRef _in ) { convertBytesToString( _in, 32, directoryPath, directoryPathLength ); const fs::path absolutePath = getFileStorageDir( Address( address ) ) / directoryPath; - g_overlayFS->createDirectory( absolutePath.string() ); + _overlayFS->createDirectory( absolutePath.string() ); u256 code = 1; bytes response = toBigEndian( code ); @@ -509,7 +508,7 @@ ETH_REGISTER_PRECOMPILED( createDirectory )( bytesConstRef _in ) { return { false, response }; } -ETH_REGISTER_PRECOMPILED( deleteDirectory )( bytesConstRef _in ) { +ETH_REGISTER_PRECOMPILED( deleteDirectory )( bytesConstRef _in, skale::OverlayFS* _overlayFS ) { try { auto rawAddress = _in.cropped( 12, 20 ).toBytes(); std::string address; @@ -525,8 +524,8 @@ ETH_REGISTER_PRECOMPILED( deleteDirectory )( bytesConstRef _in ) { const std::string absolutePathStr = absolutePath.string(); - g_overlayFS->deleteFile( absolutePathStr + "._hash" ); - g_overlayFS->deleteDirectory( absolutePath.string() ); + _overlayFS->deleteFile( absolutePathStr + "._hash" ); + _overlayFS->deleteDirectory( absolutePath.string() ); u256 code = 1; bytes response = toBigEndian( code ); @@ -544,7 +543,7 @@ ETH_REGISTER_PRECOMPILED( deleteDirectory )( bytesConstRef _in ) { return { false, response }; } -ETH_REGISTER_PRECOMPILED( calculateFileHash )( bytesConstRef _in ) { +ETH_REGISTER_PRECOMPILED( calculateFileHash )( bytesConstRef _in, skale::OverlayFS* _overlayFS ) { try { auto rawAddress = _in.cropped( 12, 20 ).toBytes(); std::string address; @@ -560,7 +559,7 @@ ETH_REGISTER_PRECOMPILED( calculateFileHash )( bytesConstRef _in ) { throw std::runtime_error( "calculateFileHash() failed because file does not exist" ); } - g_overlayFS->calculateFileHash( filePath.string() ); + _overlayFS->calculateFileHash( filePath.string() ); u256 code = 1; bytes response = toBigEndian( code ); @@ -579,7 +578,7 @@ ETH_REGISTER_PRECOMPILED( calculateFileHash )( bytesConstRef _in ) { return { false, response }; } -ETH_REGISTER_PRECOMPILED( logTextMessage )( bytesConstRef _in ) { +ETH_REGISTER_PRECOMPILED( logTextMessage )( bytesConstRef _in, skale::OverlayFS* ) { try { if ( !g_configAccesssor ) throw std::runtime_error( "Config accessor was not initialized" ); @@ -794,7 +793,7 @@ static std::pair< std::string, unsigned > parseHistoricFieldRequest( std::string * so one should pass the following as calldata: * toBytes( input.length + toBytes(input) ) */ -ETH_REGISTER_PRECOMPILED( getConfigVariableUint256 )( bytesConstRef _in ) { +ETH_REGISTER_PRECOMPILED( getConfigVariableUint256 )( bytesConstRef _in, skale::OverlayFS* ) { try { size_t lengthName; std::string rawName; @@ -851,7 +850,7 @@ ETH_REGISTER_PRECOMPILED( getConfigVariableUint256 )( bytesConstRef _in ) { return { false, response }; // 1st false - means bad error occur } -ETH_REGISTER_PRECOMPILED( getConfigVariableAddress )( bytesConstRef _in ) { +ETH_REGISTER_PRECOMPILED( getConfigVariableAddress )( bytesConstRef _in, skale::OverlayFS* ) { try { size_t lengthName; std::string rawName; @@ -905,7 +904,7 @@ ETH_REGISTER_PRECOMPILED( getConfigVariableAddress )( bytesConstRef _in ) { * so one should pass the following as calldata * toBytes( input.length + toBytes(input) ) */ -ETH_REGISTER_PRECOMPILED( getConfigVariableString )( bytesConstRef _in ) { +ETH_REGISTER_PRECOMPILED( getConfigVariableString )( bytesConstRef _in, skale::OverlayFS* ) { try { size_t lengthName; std::string rawName; @@ -957,7 +956,7 @@ ETH_REGISTER_PRECOMPILED( getConfigVariableString )( bytesConstRef _in ) { return { false, response }; // 1st false - means bad error occur } -ETH_REGISTER_PRECOMPILED( fnReserved0x16 )( bytesConstRef /*_in*/ ) { +ETH_REGISTER_PRECOMPILED( fnReserved0x16 )( bytesConstRef /*_in*/, skale::OverlayFS* ) { u256 code = 0; bytes response = toBigEndian( code ); return { false, response }; // 1st false - means bad error occur @@ -973,7 +972,7 @@ static dev::u256 stat_s2a( const std::string& saIn ) { return u; } -ETH_REGISTER_PRECOMPILED( getConfigPermissionFlag )( bytesConstRef _in ) { +ETH_REGISTER_PRECOMPILED( getConfigPermissionFlag )( bytesConstRef _in, skale::OverlayFS* ) { try { dev::u256 uValue; uValue = 0; @@ -1035,7 +1034,7 @@ ETH_REGISTER_PRECOMPILED( getConfigPermissionFlag )( bytesConstRef _in ) { return { false, response }; // 1st false - means bad error occur } -ETH_REGISTER_PRECOMPILED( getBlockRandom )( bytesConstRef ) { +ETH_REGISTER_PRECOMPILED( getBlockRandom )( bytesConstRef, skale::OverlayFS* ) { try { if ( !g_skaleHost ) throw std::runtime_error( "SkaleHost accessor was not initialized" ); @@ -1056,7 +1055,7 @@ ETH_REGISTER_PRECOMPILED( getBlockRandom )( bytesConstRef ) { return { false, response }; // 1st false - means bad error occur } -ETH_REGISTER_PRECOMPILED( addBalance )( [[maybe_unused]] bytesConstRef _in ) { +ETH_REGISTER_PRECOMPILED( addBalance )( [[maybe_unused]] bytesConstRef _in, skale::OverlayFS* ) { /* try { auto rawAddress = _in.cropped( 0, 20 ).toBytes(); @@ -1086,7 +1085,7 @@ ETH_REGISTER_PRECOMPILED( addBalance )( [[maybe_unused]] bytesConstRef _in ) { return { false, response }; // 1st false - means bad error occur } -ETH_REGISTER_PRECOMPILED( getIMABLSPublicKey )( bytesConstRef ) { +ETH_REGISTER_PRECOMPILED( getIMABLSPublicKey )( bytesConstRef, skale::OverlayFS* ) { try { if ( !g_skaleHost ) throw std::runtime_error( "SkaleHost accessor was not initialized" ); diff --git a/libethereum/Precompiled.h b/libethereum/Precompiled.h index cab79e312..0d6d41e3c 100644 --- a/libethereum/Precompiled.h +++ b/libethereum/Precompiled.h @@ -51,11 +51,11 @@ namespace eth { extern std::shared_ptr< skutils::json_config_file_accessor > g_configAccesssor; extern std::shared_ptr< SkaleHost > g_skaleHost; extern skale::State g_state; -extern std::shared_ptr< skale::OverlayFS > g_overlayFS; struct ChainOperationParams; -using PrecompiledExecutor = std::function< std::pair< bool, bytes >( bytesConstRef _in ) >; +using PrecompiledExecutor = + std::function< std::pair< bool, bytes >( bytesConstRef _in, skale::OverlayFS* _overlayFS ) >; using PrecompiledPricer = std::function< bigint( bytesConstRef _in, ChainOperationParams const& _chainParams, u256 const& _blockNumber ) >; @@ -99,11 +99,12 @@ class PrecompiledRegistrar { }; // TODO: unregister on unload with a static object. -#define ETH_REGISTER_PRECOMPILED( Name ) \ - static std::pair< bool, bytes > __eth_registerPrecompiledFunction##Name( bytesConstRef _in ); \ - static PrecompiledExecutor __eth_registerPrecompiledFactory##Name = \ - ::dev::eth::PrecompiledRegistrar::registerExecutor( \ - #Name, &__eth_registerPrecompiledFunction##Name ); \ +#define ETH_REGISTER_PRECOMPILED( Name ) \ + static std::pair< bool, bytes > __eth_registerPrecompiledFunction##Name( \ + bytesConstRef _in, skale::OverlayFS* _overlayFS ); \ + static PrecompiledExecutor __eth_registerPrecompiledFactory##Name = \ + ::dev::eth::PrecompiledRegistrar::registerExecutor( \ + #Name, &__eth_registerPrecompiledFunction##Name ); \ static std::pair< bool, bytes > __eth_registerPrecompiledFunction##Name #define ETH_REGISTER_PRECOMPILED_PRICER( Name ) \ static bigint __eth_registerPricerFunction##Name( \ diff --git a/test/unittests/libethereum/PrecompiledTest.cpp b/test/unittests/libethereum/PrecompiledTest.cpp index 7be67c511..08e48b35d 100644 --- a/test/unittests/libethereum/PrecompiledTest.cpp +++ b/test/unittests/libethereum/PrecompiledTest.cpp @@ -70,7 +70,7 @@ BOOST_AUTO_TEST_CASE( modexpFermatTheorem, "03" "fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2e" "fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f" ); - auto res = exec( bytesConstRef( in.data(), in.size() ) ); + auto res = exec( bytesConstRef( in.data(), in.size() ), nullptr ); BOOST_REQUIRE( res.first ); bytes expected = fromHex( "0000000000000000000000000000000000000000000000000000000000000001" ); @@ -88,7 +88,7 @@ BOOST_AUTO_TEST_CASE( modexpZeroBase, "0000000000000000000000000000000000000000000000000000000000000020" "fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2e" "fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f" ); - auto res = exec( bytesConstRef( in.data(), in.size() ) ); + auto res = exec( bytesConstRef( in.data(), in.size() ), nullptr ); BOOST_REQUIRE( res.first ); bytes expected = fromHex( "0000000000000000000000000000000000000000000000000000000000000000" ); @@ -108,7 +108,7 @@ BOOST_AUTO_TEST_CASE( modexpExtraByteIgnored, "ffff" "8000000000000000000000000000000000000000000000000000000000000000" "07" ); - auto res = exec( bytesConstRef( in.data(), in.size() ) ); + auto res = exec( bytesConstRef( in.data(), in.size() ), nullptr ); BOOST_REQUIRE( res.first ); bytes expected = fromHex( "3b01b01ac41f2d6e917c6d6a221ce793802469026d9ab7578fa2e79e4da6aaab" ); @@ -127,7 +127,7 @@ BOOST_AUTO_TEST_CASE( modexpRightPadding, "03" "ffff" "80" ); - auto res = exec( bytesConstRef( in.data(), in.size() ) ); + auto res = exec( bytesConstRef( in.data(), in.size() ), nullptr ); BOOST_REQUIRE( res.first ); bytes expected = fromHex( "3b01b01ac41f2d6e917c6d6a221ce793802469026d9ab7578fa2e79e4da6aaab" ); @@ -143,7 +143,7 @@ BOOST_AUTO_TEST_CASE( modexpMissingValues ) { "0000000000000000000000000000000000000000000000000000000000000002" "0000000000000000000000000000000000000000000000000000000000000020" "03" ); - auto res = exec( bytesConstRef( in.data(), in.size() ) ); + auto res = exec( bytesConstRef( in.data(), in.size() ), nullptr ); BOOST_REQUIRE( res.first ); bytes expected = fromHex( "0000000000000000000000000000000000000000000000000000000000000000" ); @@ -161,7 +161,7 @@ BOOST_AUTO_TEST_CASE( modexpEmptyValue, "0000000000000000000000000000000000000000000000000000000000000020" "03" "8000000000000000000000000000000000000000000000000000000000000000" ); - auto res = exec( bytesConstRef( in.data(), in.size() ) ); + auto res = exec( bytesConstRef( in.data(), in.size() ), nullptr ); BOOST_REQUIRE( res.first ); bytes expected = fromHex( "0000000000000000000000000000000000000000000000000000000000000001" ); @@ -180,7 +180,7 @@ BOOST_AUTO_TEST_CASE( modexpZeroPowerZero, "00" "00" "80" ); - auto res = exec( bytesConstRef( in.data(), in.size() ) ); + auto res = exec( bytesConstRef( in.data(), in.size() ), nullptr ); BOOST_REQUIRE( res.first ); bytes expected = fromHex( "0000000000000000000000000000000000000000000000000000000000000001" ); @@ -199,7 +199,7 @@ BOOST_AUTO_TEST_CASE( modexpZeroPowerZeroModZero, "00" "00" "00" ); - auto res = exec( bytesConstRef( in.data(), in.size() ) ); + auto res = exec( bytesConstRef( in.data(), in.size() ), nullptr ); BOOST_REQUIRE( res.first ); bytes expected = fromHex( "0000000000000000000000000000000000000000000000000000000000000000" ); @@ -217,7 +217,7 @@ BOOST_AUTO_TEST_CASE( modexpModLengthZero, "0000000000000000000000000000000000000000000000000000000000000000" "01" "01" ); - auto res = exec( bytesConstRef( in.data(), in.size() ) ); + auto res = exec( bytesConstRef( in.data(), in.size() ), nullptr ); BOOST_REQUIRE( res.first ); BOOST_REQUIRE( res.second.empty() ); @@ -1457,13 +1457,13 @@ void benchmarkPrecompiled( char const name[], vector_ref< const PrecompiledTest bytes input = fromHex( test.input ); bytesConstRef inputRef = &input; - auto res = exec( inputRef ); + auto res = exec( inputRef, nullptr ); BOOST_REQUIRE_MESSAGE( res.first, test.name ); BOOST_REQUIRE_EQUAL( toHex( res.second ), test.expected ); timer.restart(); for ( int i = 0; i < n; ++i ) - exec( inputRef ); + exec( inputRef, nullptr ); auto d = timer.duration() / n; auto t = std::chrono::duration_cast< std::chrono::nanoseconds >( d ).count(); @@ -1721,7 +1721,7 @@ BOOST_AUTO_TEST_CASE( getConfigVariable ) { input = input.substr(0, 58); // remove 0s in the end bytes in = fromHex( numberToHex( 29 ) + input ); - auto res = exec( bytesConstRef( in.data(), in.size() ) ); + auto res = exec( bytesConstRef( in.data(), in.size() ), nullptr ); BOOST_REQUIRE( res.first ); BOOST_REQUIRE( dev::fromBigEndian( res.second ) == 30 ); @@ -1729,7 +1729,7 @@ BOOST_AUTO_TEST_CASE( getConfigVariable ) { input = stringToHex( "skaleConfig.sChain.nodes.0.schainIndex" ); input = input.substr(0, 76); // remove 0s in the end in = fromHex( numberToHex( 38 ) + input ); - res = exec( bytesConstRef( in.data(), in.size() ) ); + res = exec( bytesConstRef( in.data(), in.size() ), nullptr ); BOOST_REQUIRE( res.first ); BOOST_REQUIRE( dev::fromBigEndian( res.second ) == 13 ); @@ -1737,21 +1737,21 @@ BOOST_AUTO_TEST_CASE( getConfigVariable ) { input = stringToHex( "skaleConfig.sChain.nodes.0.publicKey" ); input = input.substr(0, 72); // remove 0s in the end in = fromHex( numberToHex( 36 ) + input ); - res = exec( bytesConstRef( in.data(), in.size() ) ); + res = exec( bytesConstRef( in.data(), in.size() ), nullptr ); BOOST_REQUIRE( !res.first ); input = stringToHex( "skaleConfig.sChain.nodes.0.unknownField" ); input = input.substr(0, 78); // remove 0s in the end in = fromHex( numberToHex( 39 ) + input ); - res = exec( bytesConstRef( in.data(), in.size() ) ); + res = exec( bytesConstRef( in.data(), in.size() ), nullptr ); BOOST_REQUIRE( !res.first ); input = stringToHex( "skaleConfig.nodeInfo.wallets.ima.n" ); input = input.substr(0, 68); // remove 0s in the end in = fromHex( numberToHex( 34 ) + input ); - res = exec( bytesConstRef( in.data(), in.size() ) ); + res = exec( bytesConstRef( in.data(), in.size() ), nullptr ); BOOST_REQUIRE( res.first ); BOOST_REQUIRE( dev::fromBigEndian( res.second ) == 1 ); @@ -1759,7 +1759,7 @@ BOOST_AUTO_TEST_CASE( getConfigVariable ) { input = stringToHex( "skaleConfig.nodeInfo.wallets.ima.t" ); input = input.substr(0, 68); // remove 0s in the end in = fromHex( numberToHex( 34 ) + input ); - res = exec( bytesConstRef( in.data(), in.size() ) ); + res = exec( bytesConstRef( in.data(), in.size() ), nullptr ); BOOST_REQUIRE( !res.first ); @@ -1768,7 +1768,7 @@ BOOST_AUTO_TEST_CASE( getConfigVariable ) { input = stringToHex( "skaleConfig.sChain.nodes.0.publicKey" ); input = input.substr(0, 72); // remove 0s in the end in = fromHex( numberToHex( 36 ) + input ); - res = exec( bytesConstRef( in.data(), in.size() ) ); + res = exec( bytesConstRef( in.data(), in.size() ), nullptr ); BOOST_REQUIRE( res.first ); BOOST_REQUIRE( res.second == fromHex("0x6180cde2cbbcc6b6a17efec4503a7d4316f8612f411ee171587089f770335f484003ad236c534b9afa82befc1f69533723abdb6ec2601e582b72dcfd7919338b") ); @@ -1777,21 +1777,21 @@ BOOST_AUTO_TEST_CASE( getConfigVariable ) { input = input.substr(0, 58); // remove 0s in the end in = fromHex( numberToHex( 29 ) + input ); - res = exec( bytesConstRef( in.data(), in.size() ) ); + res = exec( bytesConstRef( in.data(), in.size() ), nullptr ); BOOST_REQUIRE( !res.first ); input = stringToHex( "skaleConfig.sChain.nodes.0.schainIndex" ); input = input.substr(0, 76); // remove 0s in the end in = fromHex( numberToHex( 38 ) + input ); - res = exec( bytesConstRef( in.data(), in.size() ) ); + res = exec( bytesConstRef( in.data(), in.size() ), nullptr ); BOOST_REQUIRE( !res.first ); input = stringToHex( "skaleConfig.sChain.nodes.0.unknownField" ); input = input.substr(0, 78); // remove 0s in the end in = fromHex( numberToHex( 39 ) + input ); - res = exec( bytesConstRef( in.data(), in.size() ) ); + res = exec( bytesConstRef( in.data(), in.size() ), nullptr ); BOOST_REQUIRE( !res.first ); } @@ -1875,7 +1875,7 @@ struct FilestorageFixture : public TestOutputHelperFixture { file.seekp( static_cast< long >( fileSize ) - 1 ); file.write( "0", 1 ); - dev::eth::g_overlayFS = std::make_shared< skale::OverlayFS >( true ); + m_overlayFS = std::make_shared< skale::OverlayFS >( true ); } ~FilestorageFixture() override { @@ -1889,6 +1889,7 @@ struct FilestorageFixture : public TestOutputHelperFixture { std::string fileName; std::size_t fileSize; boost::filesystem::path pathToFile; + std::shared_ptr< skale::OverlayFS > m_overlayFS; }; BOOST_FIXTURE_TEST_SUITE( FilestoragePrecompiledTests, FilestorageFixture ) @@ -1901,11 +1902,11 @@ BOOST_AUTO_TEST_CASE( createFile ) { bytes in = fromHex( hexAddress + numberToHex( fileName.length() ) + stringToHex( fileName ) + numberToHex( fileSize ) ); - auto res = exec( bytesConstRef( in.data(), in.size() ) ); + auto res = exec( bytesConstRef( in.data(), in.size() ), m_overlayFS.get() ); BOOST_REQUIRE( res.first ); - dev::eth::g_overlayFS->commit(); + m_overlayFS->commit(); BOOST_REQUIRE( boost::filesystem::exists( path ) ); BOOST_REQUIRE( boost::filesystem::file_size( path ) == fileSize ); remove( path.c_str() ); @@ -1919,10 +1920,10 @@ BOOST_AUTO_TEST_CASE( fileWithHashExtension ) { bytes in = fromHex( hexAddress + numberToHex( fileName.length() ) + stringToHex( fileName ) + numberToHex( fileSize ) ); - auto res = exec( bytesConstRef( in.data(), in.size() ) ); + auto res = exec( bytesConstRef( in.data(), in.size() ), m_overlayFS.get() ); BOOST_REQUIRE( res.first == false); - dev::eth::g_overlayFS->commit(); + m_overlayFS->commit(); BOOST_REQUIRE( !boost::filesystem::exists( path ) ); } @@ -1932,10 +1933,10 @@ BOOST_AUTO_TEST_CASE( uploadChunk ) { std::string data = "random_data"; bytes in = fromHex( hexAddress + numberToHex( fileName.length() ) + stringToHex( fileName ) + numberToHex( 0 ) + numberToHex( data.length() ) + stringToHex( data ) ); - auto res = exec( bytesConstRef( in.data(), in.size() ) ); + auto res = exec( bytesConstRef( in.data(), in.size() ), m_overlayFS.get() ); BOOST_REQUIRE( res.first ); - dev::eth::g_overlayFS->commit(); + m_overlayFS->commit(); std::ifstream ifs( pathToFile.string() ); std::string content; std::copy_n( std::istreambuf_iterator< char >( ifs.rdbuf() ), data.length(), @@ -1948,7 +1949,7 @@ BOOST_AUTO_TEST_CASE( readChunk ) { bytes in = fromHex( hexAddress + numberToHex( fileName.length() ) + stringToHex( fileName ) + numberToHex( 0 ) + numberToHex( fileSize ) ); - auto res = exec( bytesConstRef( in.data(), in.size() ) ); + auto res = exec( bytesConstRef( in.data(), in.size() ), m_overlayFS.get() ); BOOST_REQUIRE( res.first ); std::ifstream file( pathToFile.c_str(), std::ios_base::binary ); @@ -1965,7 +1966,7 @@ BOOST_AUTO_TEST_CASE( readMaliciousChunk ) { fileName = "../../test"; bytes in = fromHex( hexAddress + numberToHex( fileName.length() ) + stringToHex( fileName ) + numberToHex( 0 ) + numberToHex( fileSize ) ); - auto res = exec( bytesConstRef( in.data(), in.size() ) ); + auto res = exec( bytesConstRef( in.data(), in.size() ), m_overlayFS.get() ); BOOST_REQUIRE( res.first == false); } @@ -1973,7 +1974,7 @@ BOOST_AUTO_TEST_CASE( getFileSize ) { PrecompiledExecutor exec = PrecompiledRegistrar::executor( "getFileSize" ); bytes in = fromHex( hexAddress + numberToHex( fileName.length() ) + stringToHex( fileName ) ); - auto res = exec( bytesConstRef( in.data(), in.size() ) ); + auto res = exec( bytesConstRef( in.data(), in.size() ), m_overlayFS.get() ); BOOST_REQUIRE( res.first ); BOOST_REQUIRE( res.second == toBigEndian( static_cast< u256 >( fileSize ) ) ); } @@ -1984,7 +1985,7 @@ BOOST_AUTO_TEST_CASE( getMaliciousFileSize ) { fileName = "../../test"; bytes in = fromHex( hexAddress + numberToHex( fileName.length() ) + stringToHex( fileName ) ); - auto res = exec( bytesConstRef( in.data(), in.size() ) ); + auto res = exec( bytesConstRef( in.data(), in.size() ), m_overlayFS.get() ); BOOST_REQUIRE( !res.first ); } @@ -1992,23 +1993,23 @@ BOOST_AUTO_TEST_CASE( deleteFile ) { PrecompiledExecutor execCreate = PrecompiledRegistrar::executor( "createFile" ); bytes inCreate = fromHex( hexAddress + numberToHex( fileName.length() ) + stringToHex( fileName ) + numberToHex( fileSize ) ); - execCreate( bytesConstRef( inCreate.data(), inCreate.size() ) ); - dev::eth::g_overlayFS->commit(); + execCreate( bytesConstRef( inCreate.data(), inCreate.size() ), m_overlayFS.get() ); + m_overlayFS->commit(); PrecompiledExecutor execHash = PrecompiledRegistrar::executor( "calculateFileHash" ); bytes inHash = fromHex( hexAddress + numberToHex( fileName.length() ) + stringToHex( fileName ) + numberToHex( fileSize ) ); - execHash( bytesConstRef( inHash.data(), inHash.size() ) ); - dev::eth::g_overlayFS->commit(); + execHash( bytesConstRef( inHash.data(), inHash.size() ), m_overlayFS.get() ); + m_overlayFS->commit(); BOOST_REQUIRE( boost::filesystem::exists( pathToFile.string() + "._hash" ) ); PrecompiledExecutor exec = PrecompiledRegistrar::executor( "deleteFile" ); bytes in = fromHex( hexAddress + numberToHex( fileName.length() ) + stringToHex( fileName ) ); - auto res = exec( bytesConstRef( in.data(), in.size() ) ); + auto res = exec( bytesConstRef( in.data(), in.size() ), m_overlayFS.get() ); BOOST_REQUIRE( res.first ); - dev::eth::g_overlayFS->commit(); + m_overlayFS->commit(); BOOST_REQUIRE( !boost::filesystem::exists( pathToFile ) ); BOOST_REQUIRE( !boost::filesystem::exists( pathToFile.string() + "._hash" ) ); } @@ -2021,10 +2022,10 @@ BOOST_AUTO_TEST_CASE( createDirectory ) { dev::getDataDir() / "filestorage" / ownerAddress.hex() / dirName; bytes in = fromHex( hexAddress + numberToHex( dirName.length() ) + stringToHex( dirName ) ); - auto res = exec( bytesConstRef( in.data(), in.size() ) ); + auto res = exec( bytesConstRef( in.data(), in.size() ), m_overlayFS.get() ); BOOST_REQUIRE( res.first ); - dev::eth::g_overlayFS->commit(); + m_overlayFS->commit(); BOOST_REQUIRE( boost::filesystem::exists( pathToDir ) ); remove( pathToDir.c_str() ); } @@ -2038,11 +2039,11 @@ BOOST_AUTO_TEST_CASE( deleteDirectory ) { boost::filesystem::create_directories( pathToDir ); bytes in = fromHex( hexAddress + numberToHex( dirName.length() ) + stringToHex( dirName ) ); - auto res = exec( bytesConstRef( in.data(), in.size() ) ); + auto res = exec( bytesConstRef( in.data(), in.size() ), m_overlayFS.get() ); BOOST_REQUIRE( res.first ); - dev::eth::g_overlayFS->commit(); + m_overlayFS->commit(); BOOST_REQUIRE( !boost::filesystem::exists( pathToDir ) ); } @@ -2060,11 +2061,11 @@ BOOST_AUTO_TEST_CASE( calculateFileHash ) { bytes in = fromHex( hexAddress + numberToHex( fileName.length() ) + stringToHex( fileName ) + numberToHex( fileSize ) ); - auto res = exec( bytesConstRef( in.data(), in.size() ) ); + auto res = exec( bytesConstRef( in.data(), in.size() ), m_overlayFS.get() ); BOOST_REQUIRE( res.first ); - dev::eth::g_overlayFS->commit(); + m_overlayFS->commit(); BOOST_REQUIRE( boost::filesystem::exists( fileHashName ) ); std::ifstream resultFile( fileHashName ); diff --git a/test/unittests/libethereum/SkaleHost.cpp b/test/unittests/libethereum/SkaleHost.cpp index f4b93ce8d..3e9cb43c5 100644 --- a/test/unittests/libethereum/SkaleHost.cpp +++ b/test/unittests/libethereum/SkaleHost.cpp @@ -1246,7 +1246,7 @@ BOOST_AUTO_TEST_CASE( getBlockRandom ) { auto& skaleHost = fixture.skaleHost; PrecompiledExecutor exec = PrecompiledRegistrar::executor( "getBlockRandom" ); - auto res = exec( bytesConstRef() ); + auto res = exec( bytesConstRef(), nullptr ); u256 blockRandom = skaleHost->getBlockRandom(); BOOST_REQUIRE( res.first ); BOOST_REQUIRE( res.second == toBigEndian( static_cast< u256 >( blockRandom ) ) ); @@ -1258,7 +1258,7 @@ BOOST_AUTO_TEST_CASE( getIMABLSPUblicKey ) { auto& skaleHost = fixture.skaleHost; PrecompiledExecutor exec = PrecompiledRegistrar::executor( "getIMABLSPublicKey" ); - auto res = exec( bytesConstRef() ); + auto res = exec( bytesConstRef(), nullptr ); std::array< std::string, 4 > imaBLSPublicKey = skaleHost->getIMABLSPublicKey(); BOOST_REQUIRE( res.first ); BOOST_REQUIRE( res.second == toBigEndian( dev::u256( imaBLSPublicKey[0] ) ) + toBigEndian( dev::u256( imaBLSPublicKey[1] ) ) + toBigEndian( dev::u256( imaBLSPublicKey[2] ) ) + toBigEndian( dev::u256( imaBLSPublicKey[3] ) ) ); diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index c955130e6..fbdde7ebb 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -195,15 +195,15 @@ static std::string const c_genesisConfigString = "balance": "0", "code": "0x6080604052348015600f57600080fd5b506004361060325760003560e01c80639b063104146037578063cd16ecbf146062575b600080fd5b606060048036036020811015604b57600080fd5b8101908080359060200190929190505050608d565b005b608b60048036036020811015607657600080fd5b81019080803590602001909291905050506097565b005b8060018190555050565b806000819055505056fea265627a7a7231582029df540a7555533ef4b3f66bc4f9abe138b00117d1496efbfd9d035a48cd595e64736f6c634300050d0032", "storage": { - "0x0": "0x01" - }, + "0x0": "0x01" + }, "nonce": "0" }, "0xD2002000000000000000000000000000000000D2": { "balance": "0", "code": "0x608060405234801561001057600080fd5b50600436106100455760003560e01c806313f44d101461005557806338eada1c146100af5780634ba79dfe146100f357610046565b5b6002801461005357600080fd5b005b6100976004803603602081101561006b57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610137565b60405180821515815260200191505060405180910390f35b6100f1600480360360208110156100c557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506101f4565b005b6101356004803603602081101561010957600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061030f565b005b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16148061019957506101988261042b565b5b806101ed5750600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff165b9050919050565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146102b5576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260178152602001807f43616c6c6572206973206e6f7420746865206f776e657200000000000000000081525060200191505060405180910390fd5b60018060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146103d0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260178152602001807f43616c6c6572206973206e6f7420746865206f776e657200000000000000000081525060200191505060405180910390fd5b6000600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b600080823b90506000811191505091905056fea26469706673582212202aca1f7abb7d02061b58de9b559eabe1607c880fda3932bbdb2b74fa553e537c64736f6c634300060c0033", "storage": { - }, + }, "nonce": "0" }, "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { @@ -213,10 +213,10 @@ static std::string const c_genesisConfigString = "storage" : { } }, - "0xD2001300000000000000000000000000000000D4": { - "balance": "0", - "nonce": "0", - "storage": {}, + "0xD2001300000000000000000000000000000000D4": { + "balance": "0", + "nonce": "0", + "storage": {}, "code":"0x608060405234801561001057600080fd5b506004361061004c5760003560e01c80632098776714610051578063b8bd717f1461007f578063d37165fa146100ad578063fdde8d66146100db575b600080fd5b61007d6004803603602081101561006757600080fd5b8101908080359060200190929190505050610109565b005b6100ab6004803603602081101561009557600080fd5b8101908080359060200190929190505050610136565b005b6100d9600480360360208110156100c357600080fd5b8101908080359060200190929190505050610170565b005b610107600480360360208110156100f157600080fd5b8101908080359060200190929190505050610191565b005b60005a90505b815a8203101561011e5761010f565b600080fd5b815a8203101561013257610123565b5050565b60005a90505b815a8203101561014b5761013c565b600060011461015957600080fd5b5a90505b815a8203101561016c5761015d565b5050565b60005a9050600081830390505b805a8303101561018c5761017d565b505050565b60005a90505b815a820310156101a657610197565b60016101b157600080fd5b5a90505b815a820310156101c4576101b5565b505056fea264697066735822122089b72532621e7d1849e444ee6efaad4fb8771258e6f79755083dce434e5ac94c64736f6c63430006000033" } } @@ -540,12 +540,12 @@ BOOST_AUTO_TEST_CASE( jsonrpc_netVersion ) Json::Reader().parse( _config, ret ); // Set chainID = 65535 - ret["params"]["chainID"] = "0xffff"; + ret["params"]["chainID"] = "0xffff"; Json::FastWriter fastWriter; std::string config = fastWriter.write( ret ); JsonRpcFixture fixture( config ); - + auto version = fixture.rpcClient->net_version(); BOOST_CHECK_EQUAL( version, "65535" ); } @@ -839,8 +839,8 @@ BOOST_AUTO_TEST_CASE( simple_contract ) { // pragma solidity 0.8.4; // contract test { // uint value; - // function f(uint a) public pure returns(uint d) { - // return a * 7; + // function f(uint a) public pure returns(uint d) { + // return a * 7; // } // function setValue(uint _value) external { // value = _value; @@ -908,17 +908,17 @@ BOOST_AUTO_TEST_CASE( simple_contract ) { transact["to"] = contractAddress; transact["data"] = "0x552410770000000000000000000000000000000000000000000000000000000000000001"; txHash = fixture.rpcClient->eth_sendTransaction( transact ); - dev::eth::mineTransaction( *( fixture.client ), 1 ); + dev::eth::mineTransaction( *( fixture.client ), 1 ); auto res = fixture.rpcClient->eth_getTransactionReceipt( txHash ); - BOOST_REQUIRE_EQUAL( res["status"], string( "0x1" ) ); + BOOST_REQUIRE_EQUAL( res["status"], string( "0x1" ) ); Json::Value inputTx; inputTx["to"] = contractAddress; inputTx["input"] = "0x552410770000000000000000000000000000000000000000000000000000000000000002"; txHash = fixture.rpcClient->eth_sendTransaction( inputTx ); - dev::eth::mineTransaction( *( fixture.client ), 1 ); + dev::eth::mineTransaction( *( fixture.client ), 1 ); res = fixture.rpcClient->eth_getTransactionReceipt( txHash ); - BOOST_REQUIRE_EQUAL( res["status"], string( "0x1" ) ); + BOOST_REQUIRE_EQUAL( res["status"], string( "0x1" ) ); } /* @@ -1868,7 +1868,7 @@ BOOST_AUTO_TEST_CASE( transactionWithoutFunds ) { "0200191505060405180910390f35b600081600081905550600190509190" "505600a165627a7a72305820d8407d9cdaaf82966f3fa7a3e665b8cf4e6" "5ee8909b83094a3f856b9051274500029"; - + auto senderAddress = fixture.coinbase.address(); Json::Value create; @@ -1977,7 +1977,7 @@ contract Logger{ }// j overflow } } -*/ +*/ string bytecode = "6080604052348015600f57600080fd5b50609b8061001e6000396000f3fe608060405260015460001b60005460001b4360001b4360001b6040518082815260200191505060405180910390a3600160008154809291906001019190505550600a6001541415606357600060018190555060008081548092919060010191905055505b00fea2646970667358221220fdf2f98961b803b6b32dfc9be766990cbdb17559d9a03724d12fc672e33804b164736f6c634300060c0033"; @@ -2296,7 +2296,7 @@ contract TestEstimateGas { BOOST_AUTO_TEST_CASE( storage_limit_contract ) { JsonRpcFixture fixture; dev::eth::simulateMining( *( fixture.client ), 10 ); - + // pragma solidity 0.4.25; // contract TestStorageLimit { @@ -2324,18 +2324,18 @@ BOOST_AUTO_TEST_CASE( storage_limit_contract ) { // function zero(uint256 index) public { // storageArray[index] = 0; // } - + // function strangeFunction(uint256 index) public { // storageArray[index] = 1; // storageArray[index] = 0; // storageArray[index] = 2; // } // } - + std::string bytecode = "0x608060405234801561001057600080fd5b5061034f806100206000396000f300608060405260043610610083576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680630e031ab1146100885780631007f753146100c95780636057361d146100f6578063c298557814610123578063c67cd8841461013a578063d269ad4e14610167578063e0353e5914610194575b600080fd5b34801561009457600080fd5b506100b3600480360381019080803590602001909291905050506101c1565b6040518082815260200191505060405180910390f35b3480156100d557600080fd5b506100f4600480360381019080803590602001909291905050506101e4565b005b34801561010257600080fd5b5061012160048036038101908080359060200190929190505050610204565b005b34801561012f57600080fd5b50610138610233565b005b34801561014657600080fd5b506101656004803603810190808035906020019092919050505061026c565b005b34801561017357600080fd5b50610192600480360381019080803590602001909291905050506102a3565b005b3480156101a057600080fd5b506101bf60048036038101908080359060200190929190505050610302565b005b6000818154811015156101d057fe5b906000526020600020016000915090505481565b6000818154811015156101f357fe5b906000526020600020016000905550565b600081908060018154018082558091505090600182039060005260206000200160009091929091909150555050565b60008080549050905060006001908060018154018082558091505090600182039060005260206000200160009091929091909150555050565b60008190806001815401808255809150509060018203906000526020600020016000909192909190915055506102a0610233565b50565b60016000828154811015156102b457fe5b9060005260206000200181905550600080828154811015156102d257fe5b906000526020600020018190555060026000828154811015156102f157fe5b906000526020600020018190555050565b6000808281548110151561031257fe5b9060005260206000200181905550505600a165627a7a723058201ed095336772c55688864a6b45ca6ab89311c5533f8d38cdf931f1ce38be78080029"; - + auto senderAddress = fixture.coinbase.address(); - + Json::Value create; create["from"] = toJS( senderAddress ); create["data"] = bytecode; @@ -2363,7 +2363,7 @@ BOOST_AUTO_TEST_CASE( storage_limit_contract ) { txHash = fixture.rpcClient->eth_sendTransaction( txPushValueAndCall ); dev::eth::mineTransaction( *( fixture.client ), 1 ); BOOST_REQUIRE( fixture.client->state().storageUsed( contract ) == 96 ); - + Json::Value txPushValue; // call store(2) txPushValue["to"] = contractAddress; txPushValue["data"] = "0x6057361d0000000000000000000000000000000000000000000000000000000000000002"; @@ -2372,7 +2372,7 @@ BOOST_AUTO_TEST_CASE( storage_limit_contract ) { txHash = fixture.rpcClient->eth_sendTransaction( txPushValue ); dev::eth::mineTransaction( *( fixture.client ), 1 ); BOOST_REQUIRE( fixture.client->state().storageUsed( contract ) == 128 ); - + Json::Value txThrow; // trying to call store(3) txThrow["to"] = contractAddress; txThrow["data"] = "0x6057361d0000000000000000000000000000000000000000000000000000000000000003"; @@ -2381,7 +2381,7 @@ BOOST_AUTO_TEST_CASE( storage_limit_contract ) { txHash = fixture.rpcClient->eth_sendTransaction( txThrow ); dev::eth::mineTransaction( *( fixture.client ), 1 ); BOOST_REQUIRE( fixture.client->state().storageUsed( contract ) == 128 ); - + Json::Value txEraseValue; // call erase(2) txEraseValue["to"] = contractAddress; txEraseValue["data"] = "0x1007f7530000000000000000000000000000000000000000000000000000000000000002"; @@ -2585,7 +2585,7 @@ BOOST_AUTO_TEST_CASE( storage_limit_predeployed ) { JsonRpcFixture fixture( c_genesisConfigString ); dev::eth::simulateMining( *( fixture.client ), 20 ); BOOST_REQUIRE( fixture.client->state().storageUsedTotal() == 64 ); - + string contractAddress = "0xC2002000000000000000000000000000000000C2"; string senderAddress = toJS(fixture.coinbase.address()); @@ -2813,7 +2813,7 @@ BOOST_AUTO_TEST_CASE( EIP1898Calls ) { Json::Value eip1898BadFormed3; eip1898BadFormed3["blockHash"] = dev::h256::random().hex(); eip1898BadFormed3["requireCanonical"] = 228; - + Json::Value eip1898BadFormed4; eip1898BadFormed4["blockNumber"] = dev::h256::random().hex(); eip1898BadFormed4["requireCanonical"] = true; @@ -2824,7 +2824,7 @@ BOOST_AUTO_TEST_CASE( EIP1898Calls ) { std::array wellFormedCalls = { eip1898WellFormed, eip1898WellFormed1, eip1898WellFormed2, eip1898WellFormed3 }; std::array badFormedCalls = { eip1898BadFormed, eip1898BadFormed1, eip1898BadFormed2, eip1898BadFormed3, eip1898BadFormed4, eip1898BadFormed5 }; - + auto address = fixture.coinbase.address(); std::string response; @@ -2835,7 +2835,7 @@ BOOST_AUTO_TEST_CASE( EIP1898Calls ) { for (const auto& call: badFormedCalls) { BOOST_REQUIRE_THROW(fixture.rpcClient->eth_getBalanceEIP1898( toJS( address ), call ), jsonrpc::JsonRpcException); } - + for (const auto& call: wellFormedCalls) { Json::Value transactionCallObject; transactionCallObject["to"] = "0x0000000000000000000000000000000000000005"; @@ -3366,15 +3366,15 @@ BOOST_AUTO_TEST_CASE( deploy_controller_generation2 ) { BOOST_AUTO_TEST_CASE( deployment_control_v2 ) { // Inserting ConfigController mockup into config and enabling flexibleDeploymentPatch. - // ConfigController mockup contract: - + // ConfigController mockup contract: + // pragma solidity ^0.8.9; // contract ConfigController { // bool public freeContractDeployment = false; // function isAddressWhitelisted(address addr) external view returns (bool) { // return false; // } - // function isDeploymentAllowed(address origin, address sender) + // function isDeploymentAllowed(address origin, address sender) // external view returns (bool) { // return freeContractDeployment; // } @@ -3383,7 +3383,7 @@ BOOST_AUTO_TEST_CASE( deployment_control_v2 ) { // } // } - string configControllerV2 = + string configControllerV2 = "0x608060405234801561001057600080fd5b506004361061004c576000" "3560e01c806313f44d1014610051578063a2306c4f14610081578063d0" "f557f41461009f578063f7e2a91b146100cf575b600080fd5b61006b60" @@ -3564,7 +3564,7 @@ BOOST_AUTO_TEST_CASE( PrecompiledPrintFakeEth, *boost::unit_test::precondition( balance = fixture.client->balanceAt( jsToAddress( "0x5C4e11842E8Be09264DC1976943571D7AF6d00f8" ) ); BOOST_REQUIRE_EQUAL( balance, 16 ); - Json::Value printFakeEthCall; + Json::Value printFakeEthCall; printFakeEthCall["data"] = "0x5C4e11842E8Be09264DC1976943571D7AF6d00f80000000000000000000000000000000000000000000000000000000000000010"; printFakeEthCall["from"] = "0x5C4e11842E8be09264dc1976943571d7Af6d00F9"; printFakeEthCall["to"] = "0000000000000000000000000000000000000006"; @@ -3575,7 +3575,7 @@ BOOST_AUTO_TEST_CASE( PrecompiledPrintFakeEth, *boost::unit_test::precondition( BOOST_REQUIRE_EQUAL( balance, 16 ); // pragma solidity ^0.4.25; - + // contract Caller { // function call() public view { // bool status; @@ -3747,7 +3747,7 @@ BOOST_AUTO_TEST_CASE( mtm_import_future_txs ) { // } // } // */ -// ret["accounts"]["0xD2002000000000000000000000000000000000D2"]["code"] = "0x6080604052348015600f57600080fd5b506004361060285760003560e01c8063bad0396e14602d575b600080fd5b60336047565b604051603e91906069565b60405180910390f35b60006001905090565b60008115159050919050565b6063816050565b82525050565b6000602082019050607c6000830184605c565b9291505056fea26469706673582212208d89ce57f69b9b53e8f0808cbaa6fa8fd21a495ab92d0b48b6e47d903989835464736f6c63430008090033"; +// ret["accounts"]["0xD2002000000000000000000000000000000000D2"]["code"] = "0x6080604052348015600f57600080fd5b506004361060285760003560e01c8063bad0396e14602d575b600080fd5b60336047565b604051603e91906069565b60405180910390f35b60006001905090565b60008115159050919050565b6063816050565b82525050565b6000602082019050607c6000830184605c565b9291505056fea26469706673582212208d89ce57f69b9b53e8f0808cbaa6fa8fd21a495ab92d0b48b6e47d903989835464736f6c63430008090033"; // Json::FastWriter fastWriter; // std::string config = fastWriter.write( ret ); // JsonRpcFixture fixture( config ); @@ -3767,7 +3767,7 @@ BOOST_AUTO_TEST_CASE( mtm_import_future_txs ) { // } // } // */ -// ret["accounts"]["0xD2002000000000000000000000000000000000D2"]["code"] = "0x6080604052348015600f57600080fd5b506004361060285760003560e01c8063bad0396e14602d575b600080fd5b60336047565b604051603e91906065565b60405180910390f35b600090565b60008115159050919050565b605f81604c565b82525050565b6000602082019050607860008301846058565b9291505056fea2646970667358221220c88541a65627d63d4b0cc04094bc5b2154a2700c97677dcd5de2ee2a27bed58564736f6c63430008090033"; +// ret["accounts"]["0xD2002000000000000000000000000000000000D2"]["code"] = "0x6080604052348015600f57600080fd5b506004361060285760003560e01c8063bad0396e14602d575b600080fd5b60336047565b604051603e91906065565b60405180910390f35b600090565b60008115159050919050565b605f81604c565b82525050565b6000602082019050607860008301846058565b9291505056fea2646970667358221220c88541a65627d63d4b0cc04094bc5b2154a2700c97677dcd5de2ee2a27bed58564736f6c63430008090033"; // Json::FastWriter fastWriter; // std::string config = fastWriter.write( ret ); // JsonRpcFixture fixture( config ); @@ -4076,11 +4076,11 @@ BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE( FilestorageCacheSuite ) BOOST_AUTO_TEST_CASE( cached_filestorage ) { - + auto _config = c_genesisConfigString; Json::Value ret; Json::Reader().parse( _config, ret ); - ret["skaleConfig"]["sChain"]["revertableFSPatchTimestamp"] = 1; + ret["skaleConfig"]["sChain"]["revertableFSPatchTimestamp"] = 1; Json::FastWriter fastWriter; std::string config = fastWriter.write( ret ); RestrictedAddressFixture fixture( config ); @@ -4094,6 +4094,8 @@ BOOST_AUTO_TEST_CASE( cached_filestorage ) { transactionCallObject["to"] = "0x692a70d2e424a56d2c6c27aa97d1a86395877b3a"; transactionCallObject["data"] = "0xf38fb65b"; + // fixture.rpcClient->eth_estimateGas( transactionCallObject ); + TransactionSkeleton ts = toTransactionSkeleton( transactionCallObject ); ts = fixture.client->populateTransactionWithDefaults( ts ); pair< bool, Secret > ar = fixture.accountHolder->authenticate( ts ); @@ -4105,12 +4107,80 @@ BOOST_AUTO_TEST_CASE( cached_filestorage ) { BOOST_REQUIRE( !boost::filesystem::exists( fixture.path ) ); } +BOOST_AUTO_TEST_CASE( indirect_cached_filestorage ) { + + auto _config = c_genesisConfigString; + Json::Value ret; + Json::Reader().parse( _config, ret ); + ret["skaleConfig"]["sChain"]["revertableFSPatchTimestamp"] = 1; + Json::FastWriter fastWriter; + std::string config = fastWriter.write( ret ); + RestrictedAddressFixture fixture( config ); + + auto senderAddress = fixture.coinbase.address(); + fixture.client->setAuthor( senderAddress ); + dev::eth::simulateMining( *( fixture.client ), 1000 ); + + // 1 deploy + + // // SPDX-License-Identifier: MIT + // pragma solidity ^0.8.0; + + // contract CallFs { + // address constant private CONTRACT_ADDRESS = 0x692a70D2e424a56D2C6C27aA97D1a86395877b3A; + + // fallback() external payable { + // bytes memory data = hex"f38fb65b"; // Replace with your data + + // (bool success, bytes memory returnData) = CONTRACT_ADDRESS.call(data); + // require(success, "Call failed"); + + // // Handle return data if needed + // } + // } + + string compiled = "6080604052348015600f57600080fd5b5061023e8061001f6000396000f3fe608060405260006040518060400160405280600481526020017ff38fb65b00000000000000000000000000000000000000000000000000000000815250905060008073692a70d2e424a56d2c6c27aa97d1a86395877b3a73ffffffffffffffffffffffffffffffffffffffff168360405161007a9190610174565b6000604051808303816000865af19150503d80600081146100b7576040519150601f19603f3d011682016040523d82523d6000602084013e6100bc565b606091505b509150915081610101576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016100f8906101e8565b60405180910390fd5b005b600081519050919050565b600081905092915050565b60005b8381101561013757808201518184015260208101905061011c565b60008484015250505050565b600061014e82610103565b610158818561010e565b9350610168818560208601610119565b80840191505092915050565b60006101808284610143565b915081905092915050565b600082825260208201905092915050565b7f43616c6c206661696c6564000000000000000000000000000000000000000000600082015250565b60006101d2600b8361018b565b91506101dd8261019c565b602082019050919050565b60006020820190508181036000830152610201816101c5565b905091905056fea2646970667358221220d4a86eb274744fbb863d9160afbdfca283835a191393e60f0e42fcdd67e93f9f64736f6c634300081a0033"; + + Json::Value create; + + create["from"] = toJS( senderAddress ); + create["code"] = compiled; + create["gas"] = "1000000"; + + string txHash = fixture.rpcClient->eth_sendTransaction( create ); + dev::eth::mineTransaction( *( fixture.client ), 1 ); + + Json::Value receipt = fixture.rpcClient->eth_getTransactionReceipt( txHash ); + + BOOST_REQUIRE_EQUAL( receipt["status"], string( "0x1" ) ); + + string address = receipt["contractAddress"].asString(); + + // 2 call + + Json::Value transactionCallObject; + transactionCallObject["from"] = toJS( senderAddress ); + transactionCallObject["to"] = address; + + // BOOST_REQUIRE_THROW( fixture.rpcClient->eth_estimateGas( transactionCallObject ), std::exception ); + + TransactionSkeleton ts = toTransactionSkeleton( transactionCallObject ); + ts = fixture.client->populateTransactionWithDefaults( ts ); + pair< bool, Secret > ar = fixture.accountHolder->authenticate( ts ); + Transaction tx( ts, ar.second ); + + txHash = fixture.rpcClient->eth_sendRawTransaction( toJS( tx.toBytes() ) ); + dev::eth::mineTransaction( *( fixture.client ), 1 ); + + BOOST_REQUIRE( !boost::filesystem::exists( fixture.path ) ); +} + BOOST_AUTO_TEST_CASE( uncached_filestorage ) { auto _config = c_genesisConfigString; Json::Value ret; Json::Reader().parse( _config, ret ); - ret["skaleConfig"]["sChain"]["revertableFSPatchTimestamp"] = 9999999999999; + ret["skaleConfig"]["sChain"]["revertableFSPatchTimestamp"] = 9999999999999; Json::FastWriter fastWriter; std::string config = fastWriter.write( ret ); RestrictedAddressFixture fixture( config ); From 827c34d255d64fc7fea733f13715df3f8d4c9d83 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Tue, 16 Jul 2024 19:58:33 +0100 Subject: [PATCH 08/41] IS-1022 Prettier precompileds --- libethereum/Precompiled.cpp | 51 +++++++++++++++++++------------------ libethereum/Precompiled.h | 12 ++++++++- 2 files changed, 37 insertions(+), 26 deletions(-) diff --git a/libethereum/Precompiled.cpp b/libethereum/Precompiled.cpp index eef66df34..1793e903d 100644 --- a/libethereum/Precompiled.cpp +++ b/libethereum/Precompiled.cpp @@ -86,7 +86,7 @@ PrecompiledPricer const& PrecompiledRegistrar::pricer( std::string const& _name namespace { -ETH_REGISTER_PRECOMPILED( ecrecover )( bytesConstRef _in, skale::OverlayFS* ) { +ETH_REGISTER_PRECOMPILED( ecrecover )( bytesConstRef _in ) { struct { h256 hash; h256 v; @@ -114,15 +114,15 @@ ETH_REGISTER_PRECOMPILED( ecrecover )( bytesConstRef _in, skale::OverlayFS* ) { return { true, {} }; } -ETH_REGISTER_PRECOMPILED( sha256 )( bytesConstRef _in, skale::OverlayFS* ) { +ETH_REGISTER_PRECOMPILED( sha256 )( bytesConstRef _in ) { return { true, dev::sha256( _in ).asBytes() }; } -ETH_REGISTER_PRECOMPILED( ripemd160 )( bytesConstRef _in, skale::OverlayFS* ) { +ETH_REGISTER_PRECOMPILED( ripemd160 )( bytesConstRef _in ) { return { true, h256( dev::ripemd160( _in ), h256::AlignRight ).asBytes() }; } -ETH_REGISTER_PRECOMPILED( identity )( bytesConstRef _in, skale::OverlayFS* ) { +ETH_REGISTER_PRECOMPILED( identity )( bytesConstRef _in ) { MICROPROFILE_SCOPEI( "VM", "identity", MP_RED ); return { true, _in.toBytes() }; } @@ -149,7 +149,7 @@ bigint parseBigEndianRightPadded( bytesConstRef _in, bigint const& _begin, bigin return ret; } -ETH_REGISTER_PRECOMPILED( modexp )( bytesConstRef _in, skale::OverlayFS* ) { +ETH_REGISTER_PRECOMPILED( modexp )( bytesConstRef _in ) { bigint const baseLength( parseBigEndianRightPadded( _in, 0, 32 ) ); bigint const expLength( parseBigEndianRightPadded( _in, 32, 32 ) ); bigint const modLength( parseBigEndianRightPadded( _in, 64, 32 ) ); @@ -208,7 +208,7 @@ ETH_REGISTER_PRECOMPILED_PRICER( modexp ) return multComplexity( maxLength ) * max< bigint >( adjustedExpLength, 1 ) / 20; } -ETH_REGISTER_PRECOMPILED( alt_bn128_G1_add )( bytesConstRef _in, skale::OverlayFS* ) { +ETH_REGISTER_PRECOMPILED( alt_bn128_G1_add )( bytesConstRef _in ) { return dev::crypto::alt_bn128_G1_add( _in ); } @@ -217,7 +217,7 @@ ETH_REGISTER_PRECOMPILED_PRICER( alt_bn128_G1_add ) return _blockNumber < _chainParams.istanbulForkBlock ? 500 : 150; } -ETH_REGISTER_PRECOMPILED( alt_bn128_G1_mul )( bytesConstRef _in, skale::OverlayFS* ) { +ETH_REGISTER_PRECOMPILED( alt_bn128_G1_mul )( bytesConstRef _in ) { return dev::crypto::alt_bn128_G1_mul( _in ); } @@ -226,7 +226,7 @@ ETH_REGISTER_PRECOMPILED_PRICER( alt_bn128_G1_mul ) return _blockNumber < _chainParams.istanbulForkBlock ? 40000 : 6000; } -ETH_REGISTER_PRECOMPILED( alt_bn128_pairing_product )( bytesConstRef _in, skale::OverlayFS* ) { +ETH_REGISTER_PRECOMPILED( alt_bn128_pairing_product )( bytesConstRef _in ) { return dev::crypto::alt_bn128_pairing_product( _in ); } @@ -280,7 +280,7 @@ boost::filesystem::path getFileStorageDir( const Address& _address ) { } // TODO: check file name and file existance -ETH_REGISTER_PRECOMPILED( createFile )( bytesConstRef _in, skale::OverlayFS* _overlayFS ) { +ETH_REGISTER_FS_PRECOMPILED( createFile )( bytesConstRef _in, skale::OverlayFS* _overlayFS ) { try { auto rawAddress = _in.cropped( 12, 20 ).toBytes(); std::string address; @@ -321,7 +321,7 @@ ETH_REGISTER_PRECOMPILED( createFile )( bytesConstRef _in, skale::OverlayFS* _ov return { false, response }; } -ETH_REGISTER_PRECOMPILED( uploadChunk )( bytesConstRef _in, skale::OverlayFS* _overlayFS ) { +ETH_REGISTER_FS_PRECOMPILED( uploadChunk )( bytesConstRef _in, skale::OverlayFS* _overlayFS ) { try { auto rawAddress = _in.cropped( 12, 20 ).toBytes(); std::string address; @@ -366,7 +366,7 @@ ETH_REGISTER_PRECOMPILED( uploadChunk )( bytesConstRef _in, skale::OverlayFS* _o return { false, response }; } -ETH_REGISTER_PRECOMPILED( readChunk )( bytesConstRef _in, skale::OverlayFS* _overlayFS ) { +ETH_REGISTER_PRECOMPILED( readChunk )( bytesConstRef _in ) { MICROPROFILE_SCOPEI( "VM", "readChunk", MP_ORANGERED ); try { auto rawAddress = _in.cropped( 12, 20 ).toBytes(); @@ -417,7 +417,7 @@ ETH_REGISTER_PRECOMPILED( readChunk )( bytesConstRef _in, skale::OverlayFS* _ove return { false, response }; } -ETH_REGISTER_PRECOMPILED( getFileSize )( bytesConstRef _in, skale::OverlayFS* _overlayFS ) { +ETH_REGISTER_PRECOMPILED( getFileSize )( bytesConstRef _in ) { try { auto rawAddress = _in.cropped( 12, 20 ).toBytes(); std::string address; @@ -450,7 +450,7 @@ ETH_REGISTER_PRECOMPILED( getFileSize )( bytesConstRef _in, skale::OverlayFS* _o return { false, response }; } -ETH_REGISTER_PRECOMPILED( deleteFile )( bytesConstRef _in, skale::OverlayFS* _overlayFS ) { +ETH_REGISTER_FS_PRECOMPILED( deleteFile )( bytesConstRef _in, skale::OverlayFS* _overlayFS ) { try { auto rawAddress = _in.cropped( 12, 20 ).toBytes(); std::string address; @@ -480,7 +480,7 @@ ETH_REGISTER_PRECOMPILED( deleteFile )( bytesConstRef _in, skale::OverlayFS* _ov return { false, response }; } -ETH_REGISTER_PRECOMPILED( createDirectory )( bytesConstRef _in, skale::OverlayFS* _overlayFS ) { +ETH_REGISTER_FS_PRECOMPILED( createDirectory )( bytesConstRef _in, skale::OverlayFS* _overlayFS ) { try { auto rawAddress = _in.cropped( 12, 20 ).toBytes(); std::string address; @@ -508,7 +508,7 @@ ETH_REGISTER_PRECOMPILED( createDirectory )( bytesConstRef _in, skale::OverlayFS return { false, response }; } -ETH_REGISTER_PRECOMPILED( deleteDirectory )( bytesConstRef _in, skale::OverlayFS* _overlayFS ) { +ETH_REGISTER_FS_PRECOMPILED( deleteDirectory )( bytesConstRef _in, skale::OverlayFS* _overlayFS ) { try { auto rawAddress = _in.cropped( 12, 20 ).toBytes(); std::string address; @@ -543,7 +543,8 @@ ETH_REGISTER_PRECOMPILED( deleteDirectory )( bytesConstRef _in, skale::OverlayFS return { false, response }; } -ETH_REGISTER_PRECOMPILED( calculateFileHash )( bytesConstRef _in, skale::OverlayFS* _overlayFS ) { +ETH_REGISTER_FS_PRECOMPILED( calculateFileHash ) +( bytesConstRef _in, skale::OverlayFS* _overlayFS ) { try { auto rawAddress = _in.cropped( 12, 20 ).toBytes(); std::string address; @@ -578,7 +579,7 @@ ETH_REGISTER_PRECOMPILED( calculateFileHash )( bytesConstRef _in, skale::Overlay return { false, response }; } -ETH_REGISTER_PRECOMPILED( logTextMessage )( bytesConstRef _in, skale::OverlayFS* ) { +ETH_REGISTER_PRECOMPILED( logTextMessage )( bytesConstRef _in ) { try { if ( !g_configAccesssor ) throw std::runtime_error( "Config accessor was not initialized" ); @@ -793,7 +794,7 @@ static std::pair< std::string, unsigned > parseHistoricFieldRequest( std::string * so one should pass the following as calldata: * toBytes( input.length + toBytes(input) ) */ -ETH_REGISTER_PRECOMPILED( getConfigVariableUint256 )( bytesConstRef _in, skale::OverlayFS* ) { +ETH_REGISTER_PRECOMPILED( getConfigVariableUint256 )( bytesConstRef _in ) { try { size_t lengthName; std::string rawName; @@ -850,7 +851,7 @@ ETH_REGISTER_PRECOMPILED( getConfigVariableUint256 )( bytesConstRef _in, skale:: return { false, response }; // 1st false - means bad error occur } -ETH_REGISTER_PRECOMPILED( getConfigVariableAddress )( bytesConstRef _in, skale::OverlayFS* ) { +ETH_REGISTER_PRECOMPILED( getConfigVariableAddress )( bytesConstRef _in ) { try { size_t lengthName; std::string rawName; @@ -904,7 +905,7 @@ ETH_REGISTER_PRECOMPILED( getConfigVariableAddress )( bytesConstRef _in, skale:: * so one should pass the following as calldata * toBytes( input.length + toBytes(input) ) */ -ETH_REGISTER_PRECOMPILED( getConfigVariableString )( bytesConstRef _in, skale::OverlayFS* ) { +ETH_REGISTER_PRECOMPILED( getConfigVariableString )( bytesConstRef _in ) { try { size_t lengthName; std::string rawName; @@ -956,7 +957,7 @@ ETH_REGISTER_PRECOMPILED( getConfigVariableString )( bytesConstRef _in, skale::O return { false, response }; // 1st false - means bad error occur } -ETH_REGISTER_PRECOMPILED( fnReserved0x16 )( bytesConstRef /*_in*/, skale::OverlayFS* ) { +ETH_REGISTER_PRECOMPILED( fnReserved0x16 )( bytesConstRef /*_in*/ ) { u256 code = 0; bytes response = toBigEndian( code ); return { false, response }; // 1st false - means bad error occur @@ -972,7 +973,7 @@ static dev::u256 stat_s2a( const std::string& saIn ) { return u; } -ETH_REGISTER_PRECOMPILED( getConfigPermissionFlag )( bytesConstRef _in, skale::OverlayFS* ) { +ETH_REGISTER_PRECOMPILED( getConfigPermissionFlag )( bytesConstRef _in ) { try { dev::u256 uValue; uValue = 0; @@ -1034,7 +1035,7 @@ ETH_REGISTER_PRECOMPILED( getConfigPermissionFlag )( bytesConstRef _in, skale::O return { false, response }; // 1st false - means bad error occur } -ETH_REGISTER_PRECOMPILED( getBlockRandom )( bytesConstRef, skale::OverlayFS* ) { +ETH_REGISTER_PRECOMPILED( getBlockRandom )( bytesConstRef ) { try { if ( !g_skaleHost ) throw std::runtime_error( "SkaleHost accessor was not initialized" ); @@ -1055,7 +1056,7 @@ ETH_REGISTER_PRECOMPILED( getBlockRandom )( bytesConstRef, skale::OverlayFS* ) { return { false, response }; // 1st false - means bad error occur } -ETH_REGISTER_PRECOMPILED( addBalance )( [[maybe_unused]] bytesConstRef _in, skale::OverlayFS* ) { +ETH_REGISTER_PRECOMPILED( addBalance )( [[maybe_unused]] bytesConstRef _in ) { /* try { auto rawAddress = _in.cropped( 0, 20 ).toBytes(); @@ -1085,7 +1086,7 @@ ETH_REGISTER_PRECOMPILED( addBalance )( [[maybe_unused]] bytesConstRef _in, skal return { false, response }; // 1st false - means bad error occur } -ETH_REGISTER_PRECOMPILED( getIMABLSPublicKey )( bytesConstRef, skale::OverlayFS* ) { +ETH_REGISTER_PRECOMPILED( getIMABLSPublicKey )( bytesConstRef ) { try { if ( !g_skaleHost ) throw std::runtime_error( "SkaleHost accessor was not initialized" ); diff --git a/libethereum/Precompiled.h b/libethereum/Precompiled.h index 0d6d41e3c..d66ca1f54 100644 --- a/libethereum/Precompiled.h +++ b/libethereum/Precompiled.h @@ -99,13 +99,23 @@ class PrecompiledRegistrar { }; // TODO: unregister on unload with a static object. -#define ETH_REGISTER_PRECOMPILED( Name ) \ +#define ETH_REGISTER_PRECOMPILED( Name ) \ + static std::pair< bool, bytes > __eth_registerPrecompiledFunction##Name( bytesConstRef _in ); \ + static PrecompiledExecutor __eth_registerPrecompiledFactory##Name = \ + ::dev::eth::PrecompiledRegistrar::registerExecutor( \ + #Name, []( bytesConstRef _in, skale::OverlayFS* ) -> std::pair< bool, bytes > { \ + return __eth_registerPrecompiledFunction##Name( _in ); \ + } ); \ + static std::pair< bool, bytes > __eth_registerPrecompiledFunction##Name + +#define ETH_REGISTER_FS_PRECOMPILED( Name ) \ static std::pair< bool, bytes > __eth_registerPrecompiledFunction##Name( \ bytesConstRef _in, skale::OverlayFS* _overlayFS ); \ static PrecompiledExecutor __eth_registerPrecompiledFactory##Name = \ ::dev::eth::PrecompiledRegistrar::registerExecutor( \ #Name, &__eth_registerPrecompiledFunction##Name ); \ static std::pair< bool, bytes > __eth_registerPrecompiledFunction##Name + #define ETH_REGISTER_PRECOMPILED_PRICER( Name ) \ static bigint __eth_registerPricerFunction##Name( \ bytesConstRef _in, ChainOperationParams const& _chainParams, u256 const& _blockNumber ); \ From 5c2a9689797c62a973afc14a6edd5e8e03ee3e4a Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Wed, 17 Jul 2024 17:12:46 +0100 Subject: [PATCH 09/41] IS-1022 Prettier solution --- libconsensus | 2 +- libethereum/Precompiled.h | 41 +++++++++++++----- .../unittests/libethereum/PrecompiledTest.cpp | 42 +++++++++---------- 3 files changed, 52 insertions(+), 33 deletions(-) diff --git a/libconsensus b/libconsensus index fda7a2ff8..9683c93ec 160000 --- a/libconsensus +++ b/libconsensus @@ -1 +1 @@ -Subproject commit fda7a2ff89e34e924920a5b3682d93757cc4b0e3 +Subproject commit 9683c93ec19d4dd28724d9ec2e105677360918d1 diff --git a/libethereum/Precompiled.h b/libethereum/Precompiled.h index d66ca1f54..4082dd288 100644 --- a/libethereum/Precompiled.h +++ b/libethereum/Precompiled.h @@ -54,8 +54,26 @@ extern skale::State g_state; struct ChainOperationParams; -using PrecompiledExecutor = - std::function< std::pair< bool, bytes >( bytesConstRef _in, skale::OverlayFS* _overlayFS ) >; +// using PrecompiledExecutor = +// std::function< std::pair< bool, bytes >( bytesConstRef _in, skale::OverlayFS* _overlayFS ) >; + +// allow call both with overlayFS and without it +class PrecompiledExecutor { +public: + std::pair< bool, bytes > operator()( + bytesConstRef _in, skale::OverlayFS* _overlayFS = nullptr ) const { + return proxy( _in, _overlayFS ); + } + PrecompiledExecutor() {} + PrecompiledExecutor( const std::function< std::pair< bool, bytes >( + bytesConstRef _in, skale::OverlayFS* _overlayFS ) >& _func ) + : proxy( _func ) {} + +private: + std::function< std::pair< bool, bytes >( bytesConstRef _in, skale::OverlayFS* _overlayFS ) > + proxy; +}; + using PrecompiledPricer = std::function< bigint( bytesConstRef _in, ChainOperationParams const& _chainParams, u256 const& _blockNumber ) >; @@ -103,17 +121,18 @@ class PrecompiledRegistrar { static std::pair< bool, bytes > __eth_registerPrecompiledFunction##Name( bytesConstRef _in ); \ static PrecompiledExecutor __eth_registerPrecompiledFactory##Name = \ ::dev::eth::PrecompiledRegistrar::registerExecutor( \ - #Name, []( bytesConstRef _in, skale::OverlayFS* ) -> std::pair< bool, bytes > { \ - return __eth_registerPrecompiledFunction##Name( _in ); \ - } ); \ + #Name, PrecompiledExecutor( \ + []( bytesConstRef _in, skale::OverlayFS* ) -> std::pair< bool, bytes > { \ + return __eth_registerPrecompiledFunction##Name( _in ); \ + } ) ); \ static std::pair< bool, bytes > __eth_registerPrecompiledFunction##Name -#define ETH_REGISTER_FS_PRECOMPILED( Name ) \ - static std::pair< bool, bytes > __eth_registerPrecompiledFunction##Name( \ - bytesConstRef _in, skale::OverlayFS* _overlayFS ); \ - static PrecompiledExecutor __eth_registerPrecompiledFactory##Name = \ - ::dev::eth::PrecompiledRegistrar::registerExecutor( \ - #Name, &__eth_registerPrecompiledFunction##Name ); \ +#define ETH_REGISTER_FS_PRECOMPILED( Name ) \ + static std::pair< bool, bytes > __eth_registerPrecompiledFunction##Name( \ + bytesConstRef _in, skale::OverlayFS* _overlayFS ); \ + static PrecompiledExecutor __eth_registerPrecompiledFactory##Name = \ + ::dev::eth::PrecompiledRegistrar::registerExecutor( \ + #Name, PrecompiledExecutor( &__eth_registerPrecompiledFunction##Name ) ); \ static std::pair< bool, bytes > __eth_registerPrecompiledFunction##Name #define ETH_REGISTER_PRECOMPILED_PRICER( Name ) \ diff --git a/test/unittests/libethereum/PrecompiledTest.cpp b/test/unittests/libethereum/PrecompiledTest.cpp index 08e48b35d..2dc7749ed 100644 --- a/test/unittests/libethereum/PrecompiledTest.cpp +++ b/test/unittests/libethereum/PrecompiledTest.cpp @@ -70,7 +70,7 @@ BOOST_AUTO_TEST_CASE( modexpFermatTheorem, "03" "fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2e" "fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f" ); - auto res = exec( bytesConstRef( in.data(), in.size() ), nullptr ); + auto res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( res.first ); bytes expected = fromHex( "0000000000000000000000000000000000000000000000000000000000000001" ); @@ -88,7 +88,7 @@ BOOST_AUTO_TEST_CASE( modexpZeroBase, "0000000000000000000000000000000000000000000000000000000000000020" "fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2e" "fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f" ); - auto res = exec( bytesConstRef( in.data(), in.size() ), nullptr ); + auto res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( res.first ); bytes expected = fromHex( "0000000000000000000000000000000000000000000000000000000000000000" ); @@ -108,7 +108,7 @@ BOOST_AUTO_TEST_CASE( modexpExtraByteIgnored, "ffff" "8000000000000000000000000000000000000000000000000000000000000000" "07" ); - auto res = exec( bytesConstRef( in.data(), in.size() ), nullptr ); + auto res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( res.first ); bytes expected = fromHex( "3b01b01ac41f2d6e917c6d6a221ce793802469026d9ab7578fa2e79e4da6aaab" ); @@ -127,7 +127,7 @@ BOOST_AUTO_TEST_CASE( modexpRightPadding, "03" "ffff" "80" ); - auto res = exec( bytesConstRef( in.data(), in.size() ), nullptr ); + auto res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( res.first ); bytes expected = fromHex( "3b01b01ac41f2d6e917c6d6a221ce793802469026d9ab7578fa2e79e4da6aaab" ); @@ -143,7 +143,7 @@ BOOST_AUTO_TEST_CASE( modexpMissingValues ) { "0000000000000000000000000000000000000000000000000000000000000002" "0000000000000000000000000000000000000000000000000000000000000020" "03" ); - auto res = exec( bytesConstRef( in.data(), in.size() ), nullptr ); + auto res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( res.first ); bytes expected = fromHex( "0000000000000000000000000000000000000000000000000000000000000000" ); @@ -161,7 +161,7 @@ BOOST_AUTO_TEST_CASE( modexpEmptyValue, "0000000000000000000000000000000000000000000000000000000000000020" "03" "8000000000000000000000000000000000000000000000000000000000000000" ); - auto res = exec( bytesConstRef( in.data(), in.size() ), nullptr ); + auto res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( res.first ); bytes expected = fromHex( "0000000000000000000000000000000000000000000000000000000000000001" ); @@ -180,7 +180,7 @@ BOOST_AUTO_TEST_CASE( modexpZeroPowerZero, "00" "00" "80" ); - auto res = exec( bytesConstRef( in.data(), in.size() ), nullptr ); + auto res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( res.first ); bytes expected = fromHex( "0000000000000000000000000000000000000000000000000000000000000001" ); @@ -199,7 +199,7 @@ BOOST_AUTO_TEST_CASE( modexpZeroPowerZeroModZero, "00" "00" "00" ); - auto res = exec( bytesConstRef( in.data(), in.size() ), nullptr ); + auto res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( res.first ); bytes expected = fromHex( "0000000000000000000000000000000000000000000000000000000000000000" ); @@ -217,7 +217,7 @@ BOOST_AUTO_TEST_CASE( modexpModLengthZero, "0000000000000000000000000000000000000000000000000000000000000000" "01" "01" ); - auto res = exec( bytesConstRef( in.data(), in.size() ), nullptr ); + auto res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( res.first ); BOOST_REQUIRE( res.second.empty() ); @@ -1457,13 +1457,13 @@ void benchmarkPrecompiled( char const name[], vector_ref< const PrecompiledTest bytes input = fromHex( test.input ); bytesConstRef inputRef = &input; - auto res = exec( inputRef, nullptr ); + auto res = exec( inputRef ); BOOST_REQUIRE_MESSAGE( res.first, test.name ); BOOST_REQUIRE_EQUAL( toHex( res.second ), test.expected ); timer.restart(); for ( int i = 0; i < n; ++i ) - exec( inputRef, nullptr ); + exec( inputRef ); auto d = timer.duration() / n; auto t = std::chrono::duration_cast< std::chrono::nanoseconds >( d ).count(); @@ -1721,7 +1721,7 @@ BOOST_AUTO_TEST_CASE( getConfigVariable ) { input = input.substr(0, 58); // remove 0s in the end bytes in = fromHex( numberToHex( 29 ) + input ); - auto res = exec( bytesConstRef( in.data(), in.size() ), nullptr ); + auto res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( res.first ); BOOST_REQUIRE( dev::fromBigEndian( res.second ) == 30 ); @@ -1729,7 +1729,7 @@ BOOST_AUTO_TEST_CASE( getConfigVariable ) { input = stringToHex( "skaleConfig.sChain.nodes.0.schainIndex" ); input = input.substr(0, 76); // remove 0s in the end in = fromHex( numberToHex( 38 ) + input ); - res = exec( bytesConstRef( in.data(), in.size() ), nullptr ); + res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( res.first ); BOOST_REQUIRE( dev::fromBigEndian( res.second ) == 13 ); @@ -1737,21 +1737,21 @@ BOOST_AUTO_TEST_CASE( getConfigVariable ) { input = stringToHex( "skaleConfig.sChain.nodes.0.publicKey" ); input = input.substr(0, 72); // remove 0s in the end in = fromHex( numberToHex( 36 ) + input ); - res = exec( bytesConstRef( in.data(), in.size() ), nullptr ); + res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( !res.first ); input = stringToHex( "skaleConfig.sChain.nodes.0.unknownField" ); input = input.substr(0, 78); // remove 0s in the end in = fromHex( numberToHex( 39 ) + input ); - res = exec( bytesConstRef( in.data(), in.size() ), nullptr ); + res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( !res.first ); input = stringToHex( "skaleConfig.nodeInfo.wallets.ima.n" ); input = input.substr(0, 68); // remove 0s in the end in = fromHex( numberToHex( 34 ) + input ); - res = exec( bytesConstRef( in.data(), in.size() ), nullptr ); + res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( res.first ); BOOST_REQUIRE( dev::fromBigEndian( res.second ) == 1 ); @@ -1759,7 +1759,7 @@ BOOST_AUTO_TEST_CASE( getConfigVariable ) { input = stringToHex( "skaleConfig.nodeInfo.wallets.ima.t" ); input = input.substr(0, 68); // remove 0s in the end in = fromHex( numberToHex( 34 ) + input ); - res = exec( bytesConstRef( in.data(), in.size() ), nullptr ); + res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( !res.first ); @@ -1768,7 +1768,7 @@ BOOST_AUTO_TEST_CASE( getConfigVariable ) { input = stringToHex( "skaleConfig.sChain.nodes.0.publicKey" ); input = input.substr(0, 72); // remove 0s in the end in = fromHex( numberToHex( 36 ) + input ); - res = exec( bytesConstRef( in.data(), in.size() ), nullptr ); + res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( res.first ); BOOST_REQUIRE( res.second == fromHex("0x6180cde2cbbcc6b6a17efec4503a7d4316f8612f411ee171587089f770335f484003ad236c534b9afa82befc1f69533723abdb6ec2601e582b72dcfd7919338b") ); @@ -1777,21 +1777,21 @@ BOOST_AUTO_TEST_CASE( getConfigVariable ) { input = input.substr(0, 58); // remove 0s in the end in = fromHex( numberToHex( 29 ) + input ); - res = exec( bytesConstRef( in.data(), in.size() ), nullptr ); + res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( !res.first ); input = stringToHex( "skaleConfig.sChain.nodes.0.schainIndex" ); input = input.substr(0, 76); // remove 0s in the end in = fromHex( numberToHex( 38 ) + input ); - res = exec( bytesConstRef( in.data(), in.size() ), nullptr ); + res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( !res.first ); input = stringToHex( "skaleConfig.sChain.nodes.0.unknownField" ); input = input.substr(0, 78); // remove 0s in the end in = fromHex( numberToHex( 39 ) + input ); - res = exec( bytesConstRef( in.data(), in.size() ), nullptr ); + res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( !res.first ); } From 1908b69fe21c147c1684cf544a5f7226ca292db4 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Wed, 17 Jul 2024 17:56:08 +0100 Subject: [PATCH 10/41] IS-1022 remove unneeded test --- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 68 ----------------------- 1 file changed, 68 deletions(-) diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index fbdde7ebb..590f2b384 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -4107,74 +4107,6 @@ BOOST_AUTO_TEST_CASE( cached_filestorage ) { BOOST_REQUIRE( !boost::filesystem::exists( fixture.path ) ); } -BOOST_AUTO_TEST_CASE( indirect_cached_filestorage ) { - - auto _config = c_genesisConfigString; - Json::Value ret; - Json::Reader().parse( _config, ret ); - ret["skaleConfig"]["sChain"]["revertableFSPatchTimestamp"] = 1; - Json::FastWriter fastWriter; - std::string config = fastWriter.write( ret ); - RestrictedAddressFixture fixture( config ); - - auto senderAddress = fixture.coinbase.address(); - fixture.client->setAuthor( senderAddress ); - dev::eth::simulateMining( *( fixture.client ), 1000 ); - - // 1 deploy - - // // SPDX-License-Identifier: MIT - // pragma solidity ^0.8.0; - - // contract CallFs { - // address constant private CONTRACT_ADDRESS = 0x692a70D2e424a56D2C6C27aA97D1a86395877b3A; - - // fallback() external payable { - // bytes memory data = hex"f38fb65b"; // Replace with your data - - // (bool success, bytes memory returnData) = CONTRACT_ADDRESS.call(data); - // require(success, "Call failed"); - - // // Handle return data if needed - // } - // } - - string compiled = "6080604052348015600f57600080fd5b5061023e8061001f6000396000f3fe608060405260006040518060400160405280600481526020017ff38fb65b00000000000000000000000000000000000000000000000000000000815250905060008073692a70d2e424a56d2c6c27aa97d1a86395877b3a73ffffffffffffffffffffffffffffffffffffffff168360405161007a9190610174565b6000604051808303816000865af19150503d80600081146100b7576040519150601f19603f3d011682016040523d82523d6000602084013e6100bc565b606091505b509150915081610101576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016100f8906101e8565b60405180910390fd5b005b600081519050919050565b600081905092915050565b60005b8381101561013757808201518184015260208101905061011c565b60008484015250505050565b600061014e82610103565b610158818561010e565b9350610168818560208601610119565b80840191505092915050565b60006101808284610143565b915081905092915050565b600082825260208201905092915050565b7f43616c6c206661696c6564000000000000000000000000000000000000000000600082015250565b60006101d2600b8361018b565b91506101dd8261019c565b602082019050919050565b60006020820190508181036000830152610201816101c5565b905091905056fea2646970667358221220d4a86eb274744fbb863d9160afbdfca283835a191393e60f0e42fcdd67e93f9f64736f6c634300081a0033"; - - Json::Value create; - - create["from"] = toJS( senderAddress ); - create["code"] = compiled; - create["gas"] = "1000000"; - - string txHash = fixture.rpcClient->eth_sendTransaction( create ); - dev::eth::mineTransaction( *( fixture.client ), 1 ); - - Json::Value receipt = fixture.rpcClient->eth_getTransactionReceipt( txHash ); - - BOOST_REQUIRE_EQUAL( receipt["status"], string( "0x1" ) ); - - string address = receipt["contractAddress"].asString(); - - // 2 call - - Json::Value transactionCallObject; - transactionCallObject["from"] = toJS( senderAddress ); - transactionCallObject["to"] = address; - - // BOOST_REQUIRE_THROW( fixture.rpcClient->eth_estimateGas( transactionCallObject ), std::exception ); - - TransactionSkeleton ts = toTransactionSkeleton( transactionCallObject ); - ts = fixture.client->populateTransactionWithDefaults( ts ); - pair< bool, Secret > ar = fixture.accountHolder->authenticate( ts ); - Transaction tx( ts, ar.second ); - - txHash = fixture.rpcClient->eth_sendRawTransaction( toJS( tx.toBytes() ) ); - dev::eth::mineTransaction( *( fixture.client ), 1 ); - - BOOST_REQUIRE( !boost::filesystem::exists( fixture.path ) ); -} - BOOST_AUTO_TEST_CASE( uncached_filestorage ) { auto _config = c_genesisConfigString; From 1cf5f604deb3a724aac46238730351f504501b95 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Wed, 17 Jul 2024 18:09:25 +0100 Subject: [PATCH 11/41] IS-1022 Remove unused --- test/unittests/libethereum/SkaleHost.cpp | 4 ++-- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/test/unittests/libethereum/SkaleHost.cpp b/test/unittests/libethereum/SkaleHost.cpp index 3e9cb43c5..f4b93ce8d 100644 --- a/test/unittests/libethereum/SkaleHost.cpp +++ b/test/unittests/libethereum/SkaleHost.cpp @@ -1246,7 +1246,7 @@ BOOST_AUTO_TEST_CASE( getBlockRandom ) { auto& skaleHost = fixture.skaleHost; PrecompiledExecutor exec = PrecompiledRegistrar::executor( "getBlockRandom" ); - auto res = exec( bytesConstRef(), nullptr ); + auto res = exec( bytesConstRef() ); u256 blockRandom = skaleHost->getBlockRandom(); BOOST_REQUIRE( res.first ); BOOST_REQUIRE( res.second == toBigEndian( static_cast< u256 >( blockRandom ) ) ); @@ -1258,7 +1258,7 @@ BOOST_AUTO_TEST_CASE( getIMABLSPUblicKey ) { auto& skaleHost = fixture.skaleHost; PrecompiledExecutor exec = PrecompiledRegistrar::executor( "getIMABLSPublicKey" ); - auto res = exec( bytesConstRef(), nullptr ); + auto res = exec( bytesConstRef() ); std::array< std::string, 4 > imaBLSPublicKey = skaleHost->getIMABLSPublicKey(); BOOST_REQUIRE( res.first ); BOOST_REQUIRE( res.second == toBigEndian( dev::u256( imaBLSPublicKey[0] ) ) + toBigEndian( dev::u256( imaBLSPublicKey[1] ) ) + toBigEndian( dev::u256( imaBLSPublicKey[2] ) ) + toBigEndian( dev::u256( imaBLSPublicKey[3] ) ) ); diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index 590f2b384..9fd558ca7 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -4094,8 +4094,6 @@ BOOST_AUTO_TEST_CASE( cached_filestorage ) { transactionCallObject["to"] = "0x692a70d2e424a56d2c6c27aa97d1a86395877b3a"; transactionCallObject["data"] = "0xf38fb65b"; - // fixture.rpcClient->eth_estimateGas( transactionCallObject ); - TransactionSkeleton ts = toTransactionSkeleton( transactionCallObject ); ts = fixture.client->populateTransactionWithDefaults( ts ); pair< bool, Secret > ar = fixture.accountHolder->authenticate( ts ); From ceed97240946f6f491f71accd5257784122d428d Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Wed, 17 Jul 2024 18:33:10 +0100 Subject: [PATCH 12/41] IS-1022 Cosmetic changes --- libethereum/Precompiled.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libethereum/Precompiled.h b/libethereum/Precompiled.h index 4082dd288..cc0219dc3 100644 --- a/libethereum/Precompiled.h +++ b/libethereum/Precompiled.h @@ -54,9 +54,6 @@ extern skale::State g_state; struct ChainOperationParams; -// using PrecompiledExecutor = -// std::function< std::pair< bool, bytes >( bytesConstRef _in, skale::OverlayFS* _overlayFS ) >; - // allow call both with overlayFS and without it class PrecompiledExecutor { public: @@ -116,6 +113,7 @@ class PrecompiledRegistrar { static PrecompiledRegistrar* s_this; }; +// ignore _overlayFS param and call registered function with 1 parameter // TODO: unregister on unload with a static object. #define ETH_REGISTER_PRECOMPILED( Name ) \ static std::pair< bool, bytes > __eth_registerPrecompiledFunction##Name( bytesConstRef _in ); \ From b49c0b950f987dc5a0aec02106bbeda29aa06d37 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Thu, 18 Jul 2024 15:43:14 +0100 Subject: [PATCH 13/41] IS-1022 Correct consensus --- libconsensus | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libconsensus b/libconsensus index 9683c93ec..fda7a2ff8 160000 --- a/libconsensus +++ b/libconsensus @@ -1 +1 @@ -Subproject commit 9683c93ec19d4dd28724d9ec2e105677360918d1 +Subproject commit fda7a2ff89e34e924920a5b3682d93757cc4b0e3 From c9c69b2292ce679a72878b8c1e1fa523dd48a492 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Thu, 18 Jul 2024 15:50:50 +0100 Subject: [PATCH 14/41] IS-552 Use correct consensus --- libconsensus | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libconsensus b/libconsensus index b1916ed05..fda7a2ff8 160000 --- a/libconsensus +++ b/libconsensus @@ -1 +1 @@ -Subproject commit b1916ed05c3b77f5925662fa591b9a054290d0fd +Subproject commit fda7a2ff89e34e924920a5b3682d93757cc4b0e3 From 90766d73cb1a2b85cd688020b1bc18d28850aae6 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Fri, 19 Jul 2024 20:01:17 +0100 Subject: [PATCH 15/41] IS-1022 Remove dead code and throw on nullptr --- libethereum/Executive.cpp | 2 - libethereum/Precompiled.cpp | 82 +---- .../unittests/libethereum/PrecompiledTest.cpp | 60 ---- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 329 ------------------ 4 files changed, 15 insertions(+), 458 deletions(-) diff --git a/libethereum/Executive.cpp b/libethereum/Executive.cpp index 6c48746b4..4de49515d 100644 --- a/libethereum/Executive.cpp +++ b/libethereum/Executive.cpp @@ -331,10 +331,8 @@ bool Executive::call( CallParameters const& _p, u256 const& _gasPrice, Address c m_gas = ( u256 )( _p.gas - g ); bytes output; bool success; - // dev::eth::g_state = m_s.delegateWrite(); tie( success, output ) = m_chainParams.executePrecompiled( _p.codeAddress, _p.data, m_envInfo.number(), m_s.fs().get() ); - // m_s = dev::eth::g_state.delegateWrite(); size_t outputSize = output.size(); m_output = owning_bytes_ref{ std::move( output ), 0, outputSize }; if ( !success ) { diff --git a/libethereum/Precompiled.cpp b/libethereum/Precompiled.cpp index 1793e903d..bfcff6b7c 100644 --- a/libethereum/Precompiled.cpp +++ b/libethereum/Precompiled.cpp @@ -281,6 +281,9 @@ boost::filesystem::path getFileStorageDir( const Address& _address ) { // TODO: check file name and file existance ETH_REGISTER_FS_PRECOMPILED( createFile )( bytesConstRef _in, skale::OverlayFS* _overlayFS ) { + if ( !_overlayFS ) + throw runtime_error( "_overlayFS is nullptr " ); + try { auto rawAddress = _in.cropped( 12, 20 ).toBytes(); std::string address; @@ -322,6 +325,9 @@ ETH_REGISTER_FS_PRECOMPILED( createFile )( bytesConstRef _in, skale::OverlayFS* } ETH_REGISTER_FS_PRECOMPILED( uploadChunk )( bytesConstRef _in, skale::OverlayFS* _overlayFS ) { + if ( !_overlayFS ) + throw runtime_error( "_overlayFS is nullptr " ); + try { auto rawAddress = _in.cropped( 12, 20 ).toBytes(); std::string address; @@ -451,6 +457,9 @@ ETH_REGISTER_PRECOMPILED( getFileSize )( bytesConstRef _in ) { } ETH_REGISTER_FS_PRECOMPILED( deleteFile )( bytesConstRef _in, skale::OverlayFS* _overlayFS ) { + if ( !_overlayFS ) + throw runtime_error( "_overlayFS is nullptr " ); + try { auto rawAddress = _in.cropped( 12, 20 ).toBytes(); std::string address; @@ -481,6 +490,9 @@ ETH_REGISTER_FS_PRECOMPILED( deleteFile )( bytesConstRef _in, skale::OverlayFS* } ETH_REGISTER_FS_PRECOMPILED( createDirectory )( bytesConstRef _in, skale::OverlayFS* _overlayFS ) { + if ( !_overlayFS ) + throw runtime_error( "_overlayFS is nullptr " ); + try { auto rawAddress = _in.cropped( 12, 20 ).toBytes(); std::string address; @@ -509,6 +521,9 @@ ETH_REGISTER_FS_PRECOMPILED( createDirectory )( bytesConstRef _in, skale::Overla } ETH_REGISTER_FS_PRECOMPILED( deleteDirectory )( bytesConstRef _in, skale::OverlayFS* _overlayFS ) { + if ( !_overlayFS ) + throw runtime_error( "_overlayFS is nullptr " ); + try { auto rawAddress = _in.cropped( 12, 20 ).toBytes(); std::string address; @@ -1057,30 +1072,6 @@ ETH_REGISTER_PRECOMPILED( getBlockRandom )( bytesConstRef ) { } ETH_REGISTER_PRECOMPILED( addBalance )( [[maybe_unused]] bytesConstRef _in ) { - /* - try { - auto rawAddress = _in.cropped( 0, 20 ).toBytes(); - std::string address; - boost::algorithm::hex( rawAddress.begin(), rawAddress.end(), back_inserter( address ) ); - auto add = parseBigEndianRightPadded( _in, 20, 32 ); - - auto value = u256( add ); - - g_state.addBalance( Address( address ), value ); - - dev::u256 code = 1; - bytes response = toBigEndian( code ); - return {true, response}; - } catch ( std::exception& ex ) { - std::string strError = ex.what(); - if ( strError.empty() ) - strError = "exception without description"; - LOG( getLogger( VerbosityError ) ) - << "Exception in precompiled/addBalance(): " << strError << "\n"; - } catch ( ... ) { - LOG( getLogger( VerbosityError ) ) << "Unknown exception in precompiled/addBalance()\n"; - } - */ dev::u256 code = 0; bytes response = toBigEndian( code ); return { false, response }; // 1st false - means bad error occur @@ -1111,47 +1102,4 @@ ETH_REGISTER_PRECOMPILED( getIMABLSPublicKey )( bytesConstRef ) { return { false, response }; // 1st false - means bad error occur } -// ETH_REGISTER_PRECOMPILED( convertUint256ToString )( bytesConstRef _in ) { -// try { -// auto rawValue = _in.cropped( 0, 32 ).toBytes(); -// std::string strValue = ""; -// boost::algorithm::hex( rawValue.begin(), rawValue.end(), back_inserter( strValue ) ); -// bytes response = stat_string_to_bytes_with_length( strValue ); -// return {true, response}; -// } catch ( std::exception& ex ) { -// std::string strError = ex.what(); -// if ( strError.empty() ) -// strError = "exception without description"; -// LOG( getLogger( VerbosityError ) ) -// << "Exception in precompiled/convertUint256ToString(): " << strError << "\n"; -// } catch ( ... ) { -// LOG( getLogger( VerbosityError ) ) -// << "Unknown exception in precompiled/convertUint256ToString()\n"; -// } -// u256 code = 0; -// bytes response = toBigEndian( code ); -// return {false, response}; // 1st false - means bad error occur -//} -// ETH_REGISTER_PRECOMPILED( convertAddressToString )( bytesConstRef _in ) { -// try { -// auto rawAddress = _in.cropped( 12, 20 ).toBytes(); -// std::string strValue = ""; -// boost::algorithm::hex( rawAddress.begin(), rawAddress.end(), back_inserter( strValue ) ); -// bytes response = stat_string_to_bytes_with_length( strValue ); -// return {true, response}; -// } catch ( std::exception& ex ) { -// std::string strError = ex.what(); -// if ( strError.empty() ) -// strError = "exception without description"; -// LOG( getLogger( VerbosityError ) ) -// << "Exception in precompiled/convertAddressToString(): " << strError << "\n"; -// } catch ( ... ) { -// LOG( getLogger( VerbosityError ) ) -// << "Unknown exception in precompiled/convertAddressToString()\n"; -// } -// u256 code = 0; -// bytes response = toBigEndian( code ); -// return {false, response}; // 1st false - means bad error occur -//} - } // namespace diff --git a/test/unittests/libethereum/PrecompiledTest.cpp b/test/unittests/libethereum/PrecompiledTest.cpp index 2dc7749ed..3483a4699 100644 --- a/test/unittests/libethereum/PrecompiledTest.cpp +++ b/test/unittests/libethereum/PrecompiledTest.cpp @@ -1796,66 +1796,6 @@ BOOST_AUTO_TEST_CASE( getConfigVariable ) { BOOST_REQUIRE( !res.first ); } -// temporary merge tests for getConfigVariable -// because of the specifics in test design -//BOOST_AUTO_TEST_CASE( getConfigVariableAddress ) { -// ChainParams chainParams; -// chainParams = chainParams.loadConfig( genesisInfoSkaleConfigTest ); -// chainParams.sealEngineName = NoProof::name(); -// chainParams.allowFutureBlocks = true; - -// dev::eth::g_configAccesssor.reset( new skutils::json_config_file_accessor( "../../test/unittests/libethereum/PrecompiledConfig.json" ) ); - -// std::unique_ptr client; -// dev::TransientDirectory m_tmpDir; -// auto monitor = make_shared< InstanceMonitor >("test"); -// setenv("DATA_DIR", m_tmpDir.path().c_str(), 1); -// client.reset( new eth::ClientTest( chainParams, ( int ) chainParams.networkID, -// shared_ptr< GasPricer >(), nullptr, monitor, m_tmpDir.path(), dev::WithExisting::Kill ) ); - -// client->injectSkaleHost(); -// client->startWorking(); - -// client->setAuthor( Address("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF") ); - -// ClientTest* testClient = asClientTest( client.get() ); - -// testClient->mineBlocks( 1 ); -// testClient->importTransactionsAsBlock( dev::eth::Transactions(), 1000, 4294967294 ); -// dev::eth::g_skaleHost = testClient->skaleHost(); - -// PrecompiledExecutor exec = PrecompiledRegistrar::executor( "getConfigVariableAddress" ); - -// std::string input = stringToHex( "skaleConfig.sChain.nodes.0.owner" ); -// bytes in = fromHex( numberToHex( 32 ) + input ); -// auto res = exec( bytesConstRef( in.data(), in.size() ) ); - -// BOOST_REQUIRE( res.first ); -// BOOST_REQUIRE( res.second == fromHex("0x23bbe8db4e347b4e8c937c1c8350e4b5ed33adb3db69cbdb7a38e1f40a1b82fe") ); - -// input = stringToHex( "skaleConfig.sChain.nodes.0.id" ); -// input = input.substr(0, 58); // remove 0s in the end - -// in = fromHex( numberToHex( 29 ) + input ); -// res = exec( bytesConstRef( in.data(), in.size() ) ); - -// BOOST_REQUIRE( !res.first ); - -// input = stringToHex( "skaleConfig.sChain.nodes.0.schainIndex" ); -// input = input.substr(0, 76); // remove 0s in the end -// in = fromHex( numberToHex( 38 ) + input ); -// res = exec( bytesConstRef( in.data(), in.size() ) ); - -// BOOST_REQUIRE( !res.first ); - -// input = stringToHex( "skaleConfig.sChain.nodes.0.unknownField" ); -// input = input.substr(0, 78); // remove 0s in the end -// in = fromHex( numberToHex( 39 ) + input ); -// res = exec( bytesConstRef( in.data(), in.size() ) ); - -// BOOST_REQUIRE( !res.first ); -//} - struct FilestorageFixture : public TestOutputHelperFixture { FilestorageFixture() { ownerAddress = Address( "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" ); diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index 9fd558ca7..66e643b68 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -37,7 +37,6 @@ #include #include #include "genesisGeneration2Config.h" -// SKALE#include #include #include #include @@ -316,22 +315,12 @@ JsonRpcFixture( const std::string& _config = "", bool _owner = true, chainParams.sChain.multiTransactionMode = _mtmEnabled; chainParams.nodeInfo.syncNode = _isSyncNode; - // web3.reset( new WebThreeDirect( - // "eth tests", tempDir.path(), "", chainParams, WithExisting::Kill, {"eth"}, - // true ) ); - auto monitor = make_shared< InstanceMonitor >("test"); setenv("DATA_DIR", tempDir.path().c_str(), 1); client.reset( new eth::ClientTest( chainParams, ( int ) chainParams.networkID, shared_ptr< GasPricer >(), NULL, monitor, tempDir.path(), WithExisting::Kill ) ); - // client.reset( - // new eth::Client( chainParams, ( int ) chainParams.networkID, shared_ptr< - // GasPricer >(), - // tempDir.path(), "", WithExisting::Kill, TransactionQueue::Limits{100000, - // 1024} ) ); - client->setAuthor( coinbase.address() ); // wait for 1st block - because it's always empty @@ -478,18 +467,6 @@ BOOST_AUTO_TEST_CASE( jsonrpc_gasPrice ) { BOOST_CHECK_EQUAL( gasPrice, toJS( 20 * dev::eth::shannon ) ); } -// SKALE disabled -// BOOST_AUTO_TEST_CASE(jsonrpc_isListening) -//{ -// web3->startNetwork(); -// bool listeningOn = rpcClient->net_listening(); -// BOOST_CHECK_EQUAL(listeningOn, web3->isNetworkStarted()); -// -// web3->stopNetwork(); -// bool listeningOff = rpcClient->net_listening(); -// BOOST_CHECK_EQUAL(listeningOff, web3->isNetworkStarted()); -//} - BOOST_AUTO_TEST_CASE( jsonrpc_accounts, *boost::unit_test::precondition( dev::test::run_not_express ) ) { JsonRpcFixture fixture; @@ -517,22 +494,6 @@ BOOST_AUTO_TEST_CASE( jsonrpc_number ) { BOOST_CHECK_EQUAL( numberAfter, fixture.client->number() ); } -// SKALE disabled -// BOOST_AUTO_TEST_CASE(jsonrpc_peerCount) -//{ -// auto peerCount = jsToU256(rpcClient->net_peerCount()); -// BOOST_CHECK_EQUAL(web3->peerCount(), peerCount); -//} - -// BOOST_AUTO_TEST_CASE(jsonrpc_setListening) -//{ -// rpcClient->admin_net_start(adminSession); -// BOOST_CHECK_EQUAL(web3->isNetworkStarted(), true); -// -// rpcClient->admin_net_stop(adminSession); -// BOOST_CHECK_EQUAL(web3->isNetworkStarted(), false); -//} - BOOST_AUTO_TEST_CASE( jsonrpc_netVersion ) { std::string _config = c_genesisConfigString; @@ -588,7 +549,6 @@ BOOST_AUTO_TEST_CASE( eth_sendTransaction ) { BOOST_CHECK_EQUAL( jsToDecimal( balanceString ), "0" ); dev::eth::simulateMining( *( fixture.client ), 1 ); - // BOOST_CHECK_EQUAL(client->blockByNumber(LatestBlock).author(), address); balance = fixture.client->balanceAt( address ); balanceString = fixture.rpcClient->eth_getBalance( toJS( address ), "latest" ); @@ -921,179 +881,6 @@ BOOST_AUTO_TEST_CASE( simple_contract ) { BOOST_REQUIRE_EQUAL( res["status"], string( "0x1" ) ); } -/* -// As block rotation is not exact now - let's use approximate comparisons -#define REQUIRE_APPROX_EQUAL(a, b) BOOST_REQUIRE(4*(a) > 3*(b) && 4*(a) < 5*(b)) - -BOOST_AUTO_TEST_CASE( logs_range, *boost::unit_test::disabled() ) { - JsonRpcFixture fixture; - dev::eth::simulateMining( *( fixture.client ), 1 ); - - -//pragma solidity >=0.4.10 <0.7.0; - -//contract Logger{ -// fallback() external payable { -// log2(bytes32(block.number+1), bytes32(block.number), "dimalit"); -// } -//} - - string bytecode = - "6080604052348015600f57600080fd5b50607d80601d6000396000f3fe60806040527f64696d616c69740000000000000000000000000000000000000000000000000043600102600143016001026040518082815260200191505060405180910390a200fea2646970667358221220ecafb98cd573366a37976cb7a4489abe5389d1b5989cd7b7136c8eb0c5ba0b5664736f6c63430006000033"; - - Json::Value create; - create["code"] = bytecode; - create["gas"] = "180000"; // TODO or change global default of 90000? - - string deployHash = fixture.rpcClient->eth_sendTransaction( create ); - dev::eth::mineTransaction( *( fixture.client ), 1 ); - - // -> blockNumber = 2 (1 for bootstrapAll, 1 for deploy) - - Json::Value deployReceipt = fixture.rpcClient->eth_getTransactionReceipt( deployHash ); - string contractAddress = deployReceipt["contractAddress"].asString(); - - Json::Value filterObj; - filterObj["address"] = contractAddress; - filterObj["fromBlock"] = "0x1"; - string filterId = fixture.rpcClient->eth_newFilter( filterObj ); - - Json::Value res = fixture.rpcClient->eth_getFilterLogs(filterId); - BOOST_REQUIRE(res.isArray()); - BOOST_REQUIRE_EQUAL(res.size(), 0); - res = fixture.rpcClient->eth_getFilterChanges(filterId); - BOOST_REQUIRE(res.isArray()); - BOOST_REQUIRE_EQUAL(res.size(), 0); - - // need blockNumber==2+255 afterwards - for(int i=0; i<255; ++i){ - Json::Value t; - t["from"] = toJS( fixture.coinbase.address() ); - t["value"] = jsToDecimal( "0" ); - t["to"] = contractAddress; - t["gas"] = "99000"; - - std::string txHash = fixture.rpcClient->eth_sendTransaction( t ); - BOOST_REQUIRE( !txHash.empty() ); - - dev::eth::mineTransaction( *( fixture.client ), 1 ); - } - BOOST_REQUIRE_EQUAL(fixture.client->number(), 2 + 255); - - // ask for logs - Json::Value t; - t["fromBlock"] = 0; // really 3 - t["toBlock"] = 251; - t["address"] = contractAddress; - Json::Value logs = fixture.rpcClient->eth_getLogs(t); - BOOST_REQUIRE(logs.isArray()); - BOOST_REQUIRE_EQUAL(logs.size(), 249); - - // check logs - for(size_t i=0; ieth_sendTransaction( t ); - BOOST_REQUIRE( !lastHash.empty() ); - - dev::eth::mineTransaction( *( fixture.client ), 1 ); - } - BOOST_REQUIRE_EQUAL(fixture.client->number(), 512); - - // ask for logs - t["toBlock"] = 512; - logs = fixture.rpcClient->eth_getLogs(t); - BOOST_REQUIRE(logs.isArray()); - REQUIRE_APPROX_EQUAL(logs.size(), 256+64); - - // and filter - res = fixture.rpcClient->eth_getFilterChanges(filterId); - BOOST_REQUIRE_EQUAL(res.size(), 255+255); // NB!! we had pending here, but then they disappeared! - res = fixture.rpcClient->eth_getFilterLogs(filterId); - REQUIRE_APPROX_EQUAL(res.size(), 256+64); - - ///////////////// OTHER CALLS ////////////////// - // HACK this may return DIFFERENT block! because of undeterministic block rotation! - string existing = "0x1df"; string existing_hash = logs[256+64-1-1-32]["blockHash"].asString(); - //cerr << logs << endl; - - BOOST_REQUIRE_NO_THROW(res = fixture.rpcClient->eth_getBlockByNumber(existing, true)); - BOOST_REQUIRE_EQUAL(res["number"], existing); - BOOST_REQUIRE(res["transactions"].isArray() && res["transactions"].size() == 1); - BOOST_REQUIRE_THROW(fixture.rpcClient->eth_getBlockByNumber(nonexisting, true), jsonrpc::JsonRpcException); - - BOOST_REQUIRE_NO_THROW(res = fixture.rpcClient->eth_getBlockByHash(existing_hash, false)); - REQUIRE_APPROX_EQUAL(dev::eth::jsToBlockNumber(res["number"].asCString()), dev::eth::jsToBlockNumber(existing)); - BOOST_REQUIRE_THROW(fixture.rpcClient->eth_getBlockByHash(nonexisting_hash, true), jsonrpc::JsonRpcException); - - // - - BOOST_REQUIRE_NO_THROW(res = fixture.rpcClient->eth_getBlockTransactionCountByNumber(existing)); - BOOST_REQUIRE_EQUAL(res.asString(), "0x1"); - BOOST_REQUIRE_THROW(fixture.rpcClient->eth_getBlockTransactionCountByNumber(nonexisting), jsonrpc::JsonRpcException); - - BOOST_REQUIRE_NO_THROW(res = fixture.rpcClient->eth_getBlockTransactionCountByHash(existing_hash)); - BOOST_REQUIRE_EQUAL(res.asString(), "0x1"); - BOOST_REQUIRE_THROW(fixture.rpcClient->eth_getBlockTransactionCountByHash(nonexisting_hash), jsonrpc::JsonRpcException); - - // - - BOOST_REQUIRE_NO_THROW(res = fixture.rpcClient->eth_getUncleCountByBlockNumber(existing)); - BOOST_REQUIRE_EQUAL(res.asString(), "0x0"); - BOOST_REQUIRE_THROW(fixture.rpcClient->eth_getUncleCountByBlockNumber(nonexisting), jsonrpc::JsonRpcException); - - BOOST_REQUIRE_NO_THROW(res = fixture.rpcClient->eth_getUncleCountByBlockHash(existing_hash)); - BOOST_REQUIRE_EQUAL(res.asString(), "0x0"); - BOOST_REQUIRE_THROW(fixture.rpcClient->eth_getUncleCountByBlockHash(nonexisting_hash), jsonrpc::JsonRpcException); - - // - - BOOST_REQUIRE_NO_THROW(res = fixture.rpcClient->eth_getTransactionByBlockNumberAndIndex(existing, "0x0")); - BOOST_REQUIRE_EQUAL(res["blockNumber"], existing); - // HACK disabled for undeterminism BOOST_REQUIRE_EQUAL(res["blockHash"], existing_hash); - BOOST_REQUIRE_EQUAL(res["to"], contractAddress); - BOOST_REQUIRE_THROW(fixture.rpcClient->eth_getTransactionByBlockNumberAndIndex(nonexisting, "0x0"), jsonrpc::JsonRpcException); - - BOOST_REQUIRE_NO_THROW(res = fixture.rpcClient->eth_getTransactionByBlockHashAndIndex(existing_hash, "0x0")); - // HACK disabled for undeterminism BOOST_REQUIRE_EQUAL(res["blockNumber"], existing); - BOOST_REQUIRE_EQUAL(res["blockHash"], existing_hash); - BOOST_REQUIRE_EQUAL(res["to"], contractAddress); - BOOST_REQUIRE_THROW(fixture.rpcClient->eth_getTransactionByBlockHashAndIndex(nonexisting_hash, "0x0"), jsonrpc::JsonRpcException); - - // - - BOOST_REQUIRE_THROW(fixture.rpcClient->eth_getUncleByBlockNumberAndIndex(existing, "0x0"), jsonrpc::JsonRpcException); - BOOST_REQUIRE_THROW(fixture.rpcClient->eth_getUncleByBlockNumberAndIndex(nonexisting, "0x0"), jsonrpc::JsonRpcException); - BOOST_REQUIRE_THROW(fixture.rpcClient->eth_getUncleByBlockHashAndIndex(existing_hash, "0x0"), jsonrpc::JsonRpcException); - BOOST_REQUIRE_THROW(fixture.rpcClient->eth_getUncleByBlockHashAndIndex(nonexisting_hash, "0x0"), jsonrpc::JsonRpcException); - - // - - BOOST_REQUIRE_THROW(res = fixture.rpcClient->eth_getTransactionByHash(deployHash), jsonrpc::JsonRpcException); - BOOST_REQUIRE_NO_THROW(res = fixture.rpcClient->eth_getTransactionByHash(lastHash)); - BOOST_REQUIRE_EQUAL(res["blockNumber"], "0x200"); - - BOOST_REQUIRE_THROW(res = fixture.rpcClient->eth_getTransactionReceipt(deployHash), jsonrpc::JsonRpcException); - BOOST_REQUIRE_NO_THROW(res = fixture.rpcClient->eth_getTransactionReceipt(lastHash)); - BOOST_REQUIRE_EQUAL(res["transactionHash"], lastHash); - BOOST_REQUIRE_EQUAL(res["blockNumber"], "0x200"); - BOOST_REQUIRE_EQUAL(res["to"], contractAddress); -} -*/ - BOOST_AUTO_TEST_CASE( deploy_contract_from_owner ) { JsonRpcFixture fixture( c_genesisConfigString ); Address senderAddress = fixture.coinbase.address(); @@ -1606,76 +1393,6 @@ BOOST_AUTO_TEST_CASE( web3_sha3, "0xc6888fa159d67f77c2f3d7a402e199802766bd7e8d4d1ecd2274fc920265d56a", result ); } -// SKALE disabled -// BOOST_AUTO_TEST_CASE(debugAccountRangeAtFinalBlockState) -//{ -// // mine to get some balance at coinbase -// dev::eth::mine(*(client), 1); - -// // send transaction to have non-emtpy block -// Address receiver = Address::random(); -// Json::Value tx; -// tx["from"] = toJS(coinbase.address()); -// tx["value"] = toJS(10); -// tx["to"] = toJS(receiver); -// tx["gas"] = toJS(EVMSchedule().txGas); -// tx["gasPrice"] = toJS(10 * dev::eth::szabo); -// string txHash = rpcClient->eth_sendTransaction(tx); -// BOOST_REQUIRE(!txHash.empty()); - -// dev::eth::mineTransaction(*(client), 1); - -// string receiverHash = toString(sha3(receiver)); - -// // receiver doesn't exist in the beginning of the 2nd block -// Json::Value result = rpcClient->debug_accountRangeAt("2", 0, "0", 100); -// BOOST_CHECK(!result["addressMap"].isMember(receiverHash)); - -// // receiver exists in the end of the 2nd block -// result = rpcClient->debug_accountRangeAt("2", 1, "0", 100); -// BOOST_CHECK(result["addressMap"].isMember(receiverHash)); -// BOOST_CHECK_EQUAL(result["addressMap"][receiverHash], toString(receiver)); -//} - -// SKALE disabled -// BOOST_AUTO_TEST_CASE(debugStorageRangeAtFinalBlockState) -//{ -// // mine to get some balance at coinbase -// dev::eth::mine(*(client), 1); - -// // pragma solidity ^0.4.22; -// // contract test -// //{ -// // uint hello = 7; -// //} -// string initCode = -// "608060405260076000553415601357600080fd5b60358060206000396000" -// "f3006080604052600080fd00a165627a7a7230582006db0551577963b544" -// "3e9501b4b10880e186cff876cd360e9ad6e4181731fcdd0029"; - -// Json::Value tx; -// tx["code"] = initCode; -// tx["from"] = toJS(coinbase.address()); -// string txHash = rpcClient->eth_sendTransaction(tx); - -// dev::eth::mineTransaction(*(client), 1); - -// Json::Value receipt = rpcClient->eth_getTransactionReceipt(txHash); -// string contractAddress = receipt["contractAddress"].asString(); - -// // contract doesn't exist in the beginning of the 2nd block -// Json::Value result = rpcClient->debug_storageRangeAt("2", 0, contractAddress, "0", 100); -// BOOST_CHECK(result["storage"].empty()); - -// // contracts exists in the end of the 2nd block -// result = rpcClient->debug_storageRangeAt("2", 1, contractAddress, "0", 100); -// BOOST_CHECK(!result["storage"].empty()); -// string keyHash = toJS(sha3(u256{0})); -// BOOST_CHECK(!result["storage"][keyHash].empty()); -// BOOST_CHECK_EQUAL(result["storage"][keyHash]["key"].asString(), "0x00"); -// BOOST_CHECK_EQUAL(result["storage"][keyHash]["value"].asString(), "0x07"); -//} - BOOST_AUTO_TEST_CASE( test_importRawBlock ) { JsonRpcFixture fixture( c_genesisConfigString ); string blockHash = fixture.rpcClient->test_importRawBlock( @@ -3735,52 +3452,6 @@ BOOST_AUTO_TEST_CASE( mtm_import_future_txs ) { // TODO: Enable for multitransaction mode checking -// BOOST_AUTO_TEST_CASE( check_multitransaction_mode ) { -// auto _config = c_genesisConfigString; -// Json::Value ret; -// Json::Reader().parse( _config, ret ); -// /* Test contract -// pragma solidity ^0.8.9; -// contract Test { -// function isMTMEnabled() external pure returns (bool) { -// return true; -// } -// } -// */ -// ret["accounts"]["0xD2002000000000000000000000000000000000D2"]["code"] = "0x6080604052348015600f57600080fd5b506004361060285760003560e01c8063bad0396e14602d575b600080fd5b60336047565b604051603e91906069565b60405180910390f35b60006001905090565b60008115159050919050565b6063816050565b82525050565b6000602082019050607c6000830184605c565b9291505056fea26469706673582212208d89ce57f69b9b53e8f0808cbaa6fa8fd21a495ab92d0b48b6e47d903989835464736f6c63430008090033"; -// Json::FastWriter fastWriter; -// std::string config = fastWriter.write( ret ); -// JsonRpcFixture fixture( config ); -// bool mtm = fixture.client->checkMultitransactionMode(fixture.client->state(), fixture.client->gasBidPrice()); -// BOOST_REQUIRE( mtm ); -// } - -// BOOST_AUTO_TEST_CASE( check_multitransaction_mode_false ) { -// auto _config = c_genesisConfigString; -// Json::Value ret; -// Json::Reader().parse( _config, ret ); -// /* Test contract -// pragma solidity ^0.8.9; -// contract Test { -// function isMTMEnabled() external pure returns (bool) { -// return false; -// } -// } -// */ -// ret["accounts"]["0xD2002000000000000000000000000000000000D2"]["code"] = "0x6080604052348015600f57600080fd5b506004361060285760003560e01c8063bad0396e14602d575b600080fd5b60336047565b604051603e91906065565b60405180910390f35b600090565b60008115159050919050565b605f81604c565b82525050565b6000602082019050607860008301846058565b9291505056fea2646970667358221220c88541a65627d63d4b0cc04094bc5b2154a2700c97677dcd5de2ee2a27bed58564736f6c63430008090033"; -// Json::FastWriter fastWriter; -// std::string config = fastWriter.write( ret ); -// JsonRpcFixture fixture( config ); -// bool mtm = fixture.client->checkMultitransactionMode(fixture.client->state(), fixture.client->gasBidPrice()); -// BOOST_REQUIRE( !mtm ); -// } - -// BOOST_AUTO_TEST_CASE( check_multitransaction_mode_empty ) { -// JsonRpcFixture fixture( c_genesisConfigString ); -// bool mtm = fixture.client->checkMultitransactionMode(fixture.client->state(), fixture.client->gasBidPrice()); -// BOOST_REQUIRE( !mtm ); -// } - // historic node shall ignore invalid transactions in block BOOST_AUTO_TEST_CASE( skip_invalid_transactions ) { JsonRpcFixture fixture( c_genesisConfigString, true, true, false, true ); From 09411f779535eb567f0e4f0dd6e85c9d5a29b3ea Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Mon, 22 Jul 2024 17:29:33 +0100 Subject: [PATCH 16/41] #1741 small fixes in tests --- test/historicstate/configs/basic_config.json | 3 ++- test/historicstate/hardhat/README.md | 4 ++-- test/historicstate/hardhat/scripts/trace.ts | 5 +---- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/test/historicstate/configs/basic_config.json b/test/historicstate/configs/basic_config.json index a108a100f..1fd278d37 100644 --- a/test/historicstate/configs/basic_config.json +++ b/test/historicstate/configs/basic_config.json @@ -317,7 +317,8 @@ "collectionQueueSize": 2, "collectionDuration": 10, "transactionQueueSize": 100, - "maxOpenLeveldbFiles": 25 + "maxOpenLeveldbFiles": 25, + "testSignatures": true }, "sChain": { diff --git a/test/historicstate/hardhat/README.md b/test/historicstate/hardhat/README.md index 74fca7e30..f8c70a4a4 100644 --- a/test/historicstate/hardhat/README.md +++ b/test/historicstate/hardhat/README.md @@ -30,12 +30,12 @@ npm install Now run test against skaled ```shell -npx hardhat run scripts/trace.js --network skaled +npx hardhat run scripts/trace.ts --network skaled ``` To run the same test against geth ```shell -npx hardhat run scripts/trace.js --network geth +npx hardhat run scripts/trace.ts --network geth ``` diff --git a/test/historicstate/hardhat/scripts/trace.ts b/test/historicstate/hardhat/scripts/trace.ts index d6280a68b..f6de806c9 100644 --- a/test/historicstate/hardhat/scripts/trace.ts +++ b/test/historicstate/hardhat/scripts/trace.ts @@ -371,10 +371,7 @@ async function callDebugTraceCall(_deployedContract: any, _tracer: string, _trac data: _deployedContract.interface.encodeFunctionData("getBalance", []) }; - const returnData = await ethers.provider.call(transaction, currentBlock - 1); - - const result = _deployedContract.interface.decodeFunctionResult("getBalance", returnData); - + let returnData = await ethers.provider.call(transaction, currentBlock - 1); console.log("Calling debug_traceCall to generate " + _traceFileName); From cd95c2badb625ecc9b9ce32fad610b666994e978 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Fri, 2 Aug 2024 16:20:22 +0100 Subject: [PATCH 17/41] IS-552 Use 15 sec keepalive --- libskale/broadcaster.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libskale/broadcaster.cpp b/libskale/broadcaster.cpp index 2b594c501..ee625536d 100644 --- a/libskale/broadcaster.cpp +++ b/libskale/broadcaster.cpp @@ -116,11 +116,11 @@ void* ZmqBroadcaster::client_socket() const { int value = 1; zmq_setsockopt( m_zmq_client_socket, ZMQ_TCP_KEEPALIVE, &value, sizeof( value ) ); - value = 300; + value = 15; zmq_setsockopt( m_zmq_client_socket, ZMQ_TCP_KEEPALIVE_IDLE, &value, sizeof( value ) ); value = 10; zmq_setsockopt( m_zmq_client_socket, ZMQ_TCP_KEEPALIVE_CNT, &value, sizeof( value ) ); - value = 300; + value = 15; zmq_setsockopt( m_zmq_client_socket, ZMQ_TCP_KEEPALIVE_INTVL, &value, sizeof( value ) ); value = 16; From c319ded0f68ab214b040c247691486778ba64d88 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Thu, 8 Aug 2024 17:27:06 +0100 Subject: [PATCH 18/41] SKALED-1935 Fix skale-vm build --- skale-vm/main.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/skale-vm/main.cpp b/skale-vm/main.cpp index 50c4cc55d..3c3d47963 100644 --- a/skale-vm/main.cpp +++ b/skale-vm/main.cpp @@ -286,17 +286,18 @@ int main( int argc, char** argv ) { } // Ignore decoding errors. } - unique_ptr< SealEngineFace > se( ChainParams( genesisInfo( networkName ) ).createSealEngine() ); + ChainParams chainParams( genesisInfo( networkName ) ); LastBlockHashes lastBlockHashes; - EnvInfo const envInfo( - blockHeader, lastBlockHashes, 0 /* gasUsed */, se->chainParams().chainID ); + EnvInfo const envInfo( blockHeader, lastBlockHashes, 0 /*_committedBlockTimestamp*/, + 0 /* gasUsed */, chainParams.chainID ); + EVMSchedule evmSchedule = chainParams.makeEvmSchedule( 0, envInfo.number() ); Transaction t; Address contractDestination( "1122334455667788991011121314151617181920" ); if ( !code.empty() ) { // Deploy the code on some fake account to be called later. Account account( 0, 0 ); - auto const latestVersion = se->evmSchedule( envInfo.number() ).accountVersion; + auto const latestVersion = evmSchedule.accountVersion; account.setCode( bytes{ code }, latestVersion ); std::unordered_map< Address, Account > map; map[contractDestination] = account; @@ -307,10 +308,12 @@ int main( int argc, char** argv ) { // data. t = Transaction( value, gasPrice, gas, data, 0 ); + t.ignoreExternalGas(); // for tests + state.addBalance( sender, value ); - // HACK 0 here is for gasPrice - Executive executive( state, envInfo, *se, 0 ); + // HACK 1st 0 here is for gasPrice + Executive executive( state, envInfo, chainParams, 0, 0 ); ExecutionResult res; executive.setResultRecipient( res ); t.forceSender( sender ); @@ -346,9 +349,8 @@ int main( int argc, char** argv ) { bytes output = std::move( res.output ); if ( mode == Mode::Statistics ) { - cout << "Gas used: " << res.gasUsed << " (+" - << t.baseGasRequired( se->evmSchedule( envInfo.number() ) ) << " for transaction, -" - << res.gasRefunded << " refunded)\n"; + cout << "Gas used: " << res.gasUsed << " (+" << t.baseGasRequired( evmSchedule ) + << " for transaction, -" << res.gasRefunded << " refunded)\n"; cout << "Output: " << toHex( output ) << "\n"; LogEntries logs = executive.logs(); cout << logs.size() << " logs" << ( logs.empty() ? "." : ":" ) << "\n"; From 11027a252e72e2958c8c2b4691052edde85d4659 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Tue, 20 Aug 2024 18:44:44 +0100 Subject: [PATCH 19/41] SKALED-1900 Release build --- deps/build.sh | 31 ++++++++++++++++++++++++------- skaled/CMakeLists.txt | 1 + 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/deps/build.sh b/deps/build.sh index 664c42448..01296e2e6 100755 --- a/deps/build.sh +++ b/deps/build.sh @@ -1,5 +1,6 @@ #!/bin/bash + set -e export SKALED_DEPS_CHAIN=1 @@ -1158,16 +1159,20 @@ then # echo -e "${COLOR_INFO}configuring it${COLOR_DOTS}...${COLOR_RESET}" cd libuv - eval ./autogen.sh - eval ./configure "${CONF_CROSSCOMPILING_OPTS_GENERIC}" --enable-static --disable-shared --with-pic --prefix="$INSTALL_ROOT" "${CONF_DEBUG_OPTIONS}" + # eval ./autogen.sh + # eval ./configure "${CONF_CROSSCOMPILING_OPTS_GENERIC}" --enable-static --disable-shared --with-pic --prefix="$INSTALL_ROOT" "${CONF_DEBUG_OPTIONS}" #--with-sysroot=="$INSTALL_ROOT" - cd .. + mkdir build && cd build + eval "$CMAKE" "${CMAKE_CROSSCOMPILING_OPTS}" -DCMAKE_INSTALL_PREFIX="$INSTALL_ROOT" -DCMAKE_BUILD_TYPE="$TOP_CMAKE_BUILD_TYPE" \ + -DBUILD_SHARED_LIBS=OFF \ + .. + cd ../.. fi echo -e "${COLOR_INFO}building it${COLOR_DOTS}...${COLOR_RESET}" - cd libuv + cd libuv/build eval "$MAKE" "${PARALLEL_MAKE_OPTIONS}" eval "$MAKE" "${PARALLEL_MAKE_OPTIONS}" install - cd .. + cd ../.. cd "$SOURCES_ROOT" else echo -e "${COLOR_SUCCESS}SKIPPED${COLOR_RESET}" @@ -1391,13 +1396,21 @@ then cd boost_1_68_0 echo -e "${COLOR_INFO}configuring and building it${COLOR_DOTS}...${COLOR_RESET}" eval ./bootstrap.sh --prefix="$INSTALL_ROOT" --with-libraries=atomic,context,filesystem,program_options,regex,system,thread,date_time,iostreams + + if [ "$DEBUG" = "1" ]; then + variant=debug + else + variant=release + fi + if [ ${ARCH} = "arm" ] then sed -i -e 's#using gcc ;#using gcc : arm : /usr/local/toolchains/gcc7.2-arm/bin/arm-linux-gnueabihf-g++ ;#g' project-config.jam - eval ./b2 "${CONF_CROSSCOMPILING_OPTS_BOOST}" cxxflags=-fPIC cflags=-fPIC "${PARALLEL_MAKE_OPTIONS}" --prefix="$INSTALL_ROOT" --layout=system variant=debug link=static threading=multi install + eval ./b2 "${CONF_CROSSCOMPILING_OPTS_BOOST}" cxxflags=-fPIC cflags=-fPIC "${PARALLEL_MAKE_OPTIONS}" --prefix="$INSTALL_ROOT" --layout=system variant=$variant link=static threading=multi install else - eval ./b2 cxxflags=-fPIC cflags=-fPIC "${PARALLEL_MAKE_OPTIONS}" --prefix="$INSTALL_ROOT" --layout=system variant=debug link=static threading=multi install + eval ./b2 cxxflags=-fPIC cflags=-fPIC "${PARALLEL_MAKE_OPTIONS}" --prefix="$INSTALL_ROOT" --layout=system variant=$variant link=static threading=multi install fi + cd .. cd "$SOURCES_ROOT" else @@ -2082,6 +2095,7 @@ then eval tar -xzf folly-from-git.tar.gz fi echo -e "${COLOR_INFO}fixing it${COLOR_DOTS}...${COLOR_RESET}" + sed -i 's/list(APPEND FOLLY_LINK_LIBRARIES ${LIBUNWIND_LIBRARIES})/list(APPEND FOLLY_LINK_LIBRARIES ${LIBUNWIND_LIBRARIES} lzma)/' ./folly/CMake/folly-deps.cmake sed -i 's/google::InstallFailureFunction(abort);/google::InstallFailureFunction( reinterpret_cast < google::logging_fail_func_t > ( abort ) );/g' ./folly/folly/init/Init.cpp echo -e "${COLOR_INFO}configuring it${COLOR_DOTS}...${COLOR_RESET}" cd folly @@ -2091,6 +2105,8 @@ then -DBOOST_ROOT="$INSTALL_ROOT" -DBOOST_LIBRARYDIR="$INSTALL_ROOT/lib" -DBoost_NO_WARN_NEW_VERSIONS=1 -DBoost_DEBUG=ON \ -DBUILD_SHARED_LIBS=OFF \ -DBUILD_TESTS=OFF -DBUILD_BROKEN_TESTS=OFF -DBUILD_HANGING_TESTS=OFF -DBUILD_SLOW_TESTS=OFF \ + -DCMAKE_INCLUDE_PATH="${INSTALL_ROOT}/include" \ + -DCMAKE_LIBRARY_PATH="${INSTALL_ROOT}/lib" \ .. cd .. else @@ -2100,6 +2116,7 @@ then cd build2 eval "$MAKE" "${PARALLEL_MAKE_OPTIONS}" eval "$MAKE" "${PARALLEL_MAKE_OPTIONS}" install + eval strip --strip-debug "${INSTALL_ROOT}"/lib/libfolly*.a cd "$SOURCES_ROOT" else echo -e "${COLOR_SUCCESS}SKIPPED${COLOR_RESET}" diff --git a/skaled/CMakeLists.txt b/skaled/CMakeLists.txt index 593119d59..e84624e83 100644 --- a/skaled/CMakeLists.txt +++ b/skaled/CMakeLists.txt @@ -30,6 +30,7 @@ target_link_libraries( pthread idn2 batched-io + lz4 ) if (CONSENSUS) target_link_libraries(${EXECUTABLE_NAME} PRIVATE consensus) From b103445fe495d5e4952040a5f3facba6be9d3e13 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Wed, 21 Aug 2024 13:58:43 +0100 Subject: [PATCH 20/41] SKALED-1900 Do not strip --- .github/workflows/publish.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 7a73c85ef..4c946c06e 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -118,7 +118,6 @@ jobs: make skaled -j$(nproc) #echo "Ensure release mode skaled does not have any debug markers" cp skaled/skaled skaled/skaled-debug - strip skaled/skaled cd .. - name: Configure historic state build run: | @@ -141,7 +140,6 @@ jobs: make skaled -j$(nproc) #echo "Ensure release mode skaled does not have any debug markers" cp skaled/skaled skaled/skaled-debug - strip skaled/skaled cd .. - name: Build and publish container run: | From 5ff07a7b4168c8175bf9a07a9134ce1e9f545395 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Wed, 21 Aug 2024 18:27:57 +0100 Subject: [PATCH 21/41] SKALED-1900 Use -s for stripping symbols --- CMakeLists.txt | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b034843c3..9952809ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,12 +18,6 @@ list( APPEND CMAKE_MODULE_PATH ${DEPS_INSTALL_ROOT}/lib/cmake ) link_directories( ${CMAKE_BINARY_DIR}/deps/lib ) # HACK for not-found -lff in testeth -if( NOT CMAKE_BUILD_TYPE MATCHES "Debug" ) - set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -rdynamic" ) - set( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -rdynamic" ) - set( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -rdynamic" ) -endif() - option( SKALED_PROFILING "Build for profiling" OFF ) if( SKALED_PROFILING ) set( CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -pg" ) @@ -32,6 +26,8 @@ if( SKALED_PROFILING ) set( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pg" ) endif() +set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -s") + if( CMAKE_BUILD_TYPE STREQUAL "Release" ) set( CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -O3" ) set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3" ) From 4d34648de8c8a61bdd37e0c6060d58826b016dfe Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Fri, 23 Aug 2024 20:03:56 +0100 Subject: [PATCH 22/41] SKALED-1900 Use RelWithDebInfo in separate binary --- .github/workflows/publish.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 4c946c06e..48a1d43a0 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -91,7 +91,7 @@ jobs: export CC=gcc-9 export CXX=g++-9 export TARGET=all - export CMAKE_BUILD_TYPE=RelWithDebInfo + export CMAKE_BUILD_TYPE=Release cd deps ./clean.sh rm -f ./libwebsockets-from-git.tar.gz @@ -102,10 +102,9 @@ jobs: export CC=gcc-9 export CXX=g++-9 export TARGET=all - export CMAKE_BUILD_TYPE=RelWithDebInfo + export CMAKE_BUILD_TYPE=Release mkdir -p build cd build - # -DCMAKE_C_FLAGS=-O3 -DCMAKE_CXX_FLAGS=-O3 cmake -DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE .. cd .. - name: Build all @@ -116,7 +115,6 @@ jobs: export CMAKE_BUILD_TYPE=RelWithDebInfo cd build make skaled -j$(nproc) - #echo "Ensure release mode skaled does not have any debug markers" cp skaled/skaled skaled/skaled-debug cd .. - name: Configure historic state build @@ -127,7 +125,6 @@ jobs: export CMAKE_BUILD_TYPE=RelWithDebInfo mkdir -p build-historic cd build-historic - # -DCMAKE_C_FLAGS=-O3 -DCMAKE_CXX_FLAGS=-O3 cmake -DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE -DHISTORIC_STATE=1 .. cd .. - name: Build historic state version @@ -138,7 +135,6 @@ jobs: export CMAKE_BUILD_TYPE=RelWithDebInfo cd build-historic make skaled -j$(nproc) - #echo "Ensure release mode skaled does not have any debug markers" cp skaled/skaled skaled/skaled-debug cd .. - name: Build and publish container From 12ae82eaa8fd31bae7f855c689380aadd8efa057 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Fri, 23 Aug 2024 20:19:51 +0100 Subject: [PATCH 23/41] SKALED-1900 Use strip on original skaled --- .github/workflows/publish.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 48a1d43a0..fd91ebaeb 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -116,6 +116,7 @@ jobs: cd build make skaled -j$(nproc) cp skaled/skaled skaled/skaled-debug + strip --strip-all skaled/skaled cd .. - name: Configure historic state build run: | @@ -136,6 +137,7 @@ jobs: cd build-historic make skaled -j$(nproc) cp skaled/skaled skaled/skaled-debug + strip --strip-all skaled/skaled cd .. - name: Build and publish container run: | From bbf272c5c6485f71334f3c2b85df487c816b55c8 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Tue, 27 Aug 2024 18:44:04 +0100 Subject: [PATCH 24/41] Use built-in ctest in test.ClientBase --- cmake/EthUtils.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/EthUtils.cmake b/cmake/EthUtils.cmake index 27afe8682..14256b00a 100644 --- a/cmake/EthUtils.cmake +++ b/cmake/EthUtils.cmake @@ -57,7 +57,7 @@ macro(eth_add_test NAME) add_custom_target("test.${NAME}" DEPENDS testeth WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMAND ${CMAKE_COMMAND} -DETH_TEST_NAME="${NAME}" -DCTEST_COMMAND="${CTEST_COMMAND}" -P "${ETH_SCRIPTS_DIR}/runtest.cmake" + COMMAND ${CMAKE_COMMAND} -DETH_TEST_NAME="${NAME}" -DCTEST_COMMAND="${CMAKE_CTEST_COMMAND}" -P "${ETH_SCRIPTS_DIR}/runtest.cmake" ) endmacro() From 2f70838c2cc0e86cab18af33daa2e6d1802e653c Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Wed, 28 Aug 2024 13:46:36 +0100 Subject: [PATCH 25/41] SKALED-1935 make skale-vm not crash --- skale-vm/main.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/skale-vm/main.cpp b/skale-vm/main.cpp index 3c3d47963..117da3cfe 100644 --- a/skale-vm/main.cpp +++ b/skale-vm/main.cpp @@ -292,6 +292,8 @@ int main( int argc, char** argv ) { 0 /* gasUsed */, chainParams.chainID ); EVMSchedule evmSchedule = chainParams.makeEvmSchedule( 0, envInfo.number() ); + state = state.createStateModifyCopy(); + Transaction t; Address contractDestination( "1122334455667788991011121314151617181920" ); if ( !code.empty() ) { @@ -387,5 +389,8 @@ int main( int argc, char** argv ) { << '\n'; cout << "exec time: " << fixed << setprecision( 6 ) << execTime << '\n'; } + + state.releaseWriteLock(); + return 0; } From 16b02a38167a5b2ad6adf79614d5ef82eea7d823 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Wed, 28 Aug 2024 15:59:20 +0100 Subject: [PATCH 26/41] SKALED-1900 Keep debug info in folly if build is debug --- deps/build.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/deps/build.sh b/deps/build.sh index 01296e2e6..735dc5e7f 100755 --- a/deps/build.sh +++ b/deps/build.sh @@ -2116,7 +2116,9 @@ then cd build2 eval "$MAKE" "${PARALLEL_MAKE_OPTIONS}" eval "$MAKE" "${PARALLEL_MAKE_OPTIONS}" install - eval strip --strip-debug "${INSTALL_ROOT}"/lib/libfolly*.a + if [ "$DEBUG" = "0" ]; then + eval strip --strip-debug "${INSTALL_ROOT}"/lib/libfolly*.a + fi cd "$SOURCES_ROOT" else echo -e "${COLOR_SUCCESS}SKIPPED${COLOR_RESET}" From 40c668d9edfa303e9dcaf8479f14838ab481753c Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Wed, 28 Aug 2024 16:34:19 +0100 Subject: [PATCH 27/41] SKALED-1900 Add Release into custom_build.yml --- .github/workflows/custom_build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/custom_build.yml b/.github/workflows/custom_build.yml index 93316c47a..45b57eecf 100644 --- a/.github/workflows/custom_build.yml +++ b/.github/workflows/custom_build.yml @@ -22,6 +22,7 @@ on: options: - Debug - RelWithDebInfo + - Release default: RelWithDebInfo jobs: From a6409d1ded04ab554c1e537be47f7a1281bf878d Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Wed, 28 Aug 2024 17:21:07 +0100 Subject: [PATCH 28/41] SKALED-1900 Pre-install liblz4 --- .github/workflows/publish.yml | 1 + .github/workflows/setup-build-publish.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index fd91ebaeb..f0ff28122 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -28,6 +28,7 @@ jobs: run: | sudo apt-get -y remove libzmq* || true sudo apt-get -y install software-properties-common gcc-9 g++-9 || true + sudo apt-get -y install liblz4-dev || true - name: Use g++-9 and gcov-9 by default run: | diff --git a/.github/workflows/setup-build-publish.yml b/.github/workflows/setup-build-publish.yml index d1b15117f..cf06a9e90 100644 --- a/.github/workflows/setup-build-publish.yml +++ b/.github/workflows/setup-build-publish.yml @@ -61,6 +61,7 @@ jobs: run: | sudo apt-get -y remove libzmq* || true sudo apt-get -y install software-properties-common gcc-9 g++-9 || true + sudo apt-get -y install liblz4-dev || true - name: Use g++-9 and gcov-9 by default run: | From 616b6d427ce8d2ab9d1292689eeacd803d0172f7 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Wed, 28 Aug 2024 18:47:47 +0100 Subject: [PATCH 29/41] Use RelWithDebInfo in publish.yml --- .github/workflows/publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index f0ff28122..2d7414972 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -103,7 +103,7 @@ jobs: export CC=gcc-9 export CXX=g++-9 export TARGET=all - export CMAKE_BUILD_TYPE=Release + export CMAKE_BUILD_TYPE=RelWithDebInfo mkdir -p build cd build cmake -DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE .. From 3859a557fce64fb19043e72b4aaf385666d4dedc Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Wed, 28 Aug 2024 19:12:07 +0100 Subject: [PATCH 30/41] SKALED-1900 Add check in custom build --- .github/workflows/setup-build-publish.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/setup-build-publish.yml b/.github/workflows/setup-build-publish.yml index cf06a9e90..ac1b6c069 100644 --- a/.github/workflows/setup-build-publish.yml +++ b/.github/workflows/setup-build-publish.yml @@ -151,6 +151,13 @@ jobs: export CMAKE_BUILD_TYPE=$BUILD_TYPE cd build make skaled -j$(nproc) + if [[ "$BUILD_TYPE" = "Release" ]]; then + debug_wc=$(objdump -h skaled/skaled | grep -i debug | wc -l) + sym_wc=$(readelf -s skaled/skaled | wc -l) + if (( debug_wc != 0 || sym_wc > 10000 )); then + exit 1 + fi + fi cd .. - name: Build and publish container env: From 5ee9c666094c039d56551aecbcf38c771acc4ff6 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Wed, 18 Sep 2024 15:51:24 +0100 Subject: [PATCH 31/41] SKALED-1951 Fixed some --all unit tests --- libethcore/ChainOperationParams.cpp | 4 +++- libethcore/EVMSchedule.h | 4 +++- test/tools/jsontests/BlockChainTests.cpp | 8 ++++++-- test/tools/libtesteth/ImportTest.cpp | 3 +++ test/tools/libtestutils/Common.cpp | 2 +- 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/libethcore/ChainOperationParams.cpp b/libethcore/ChainOperationParams.cpp index 4f11713a9..26eedfe39 100644 --- a/libethcore/ChainOperationParams.cpp +++ b/libethcore/ChainOperationParams.cpp @@ -82,8 +82,10 @@ EVMSchedule const ChainOperationParams::makeEvmSchedule( result = EIP158Schedule; else if ( _workingBlockNumber >= EIP150ForkBlock ) result = EIP150Schedule; + else if ( _workingBlockNumber >= homesteadForkBlock ) + return HomesteadSchedule; else - result = HomesteadSchedule; + return FrontierSchedule; // 2 based on previous - decide by timestamp if ( PushZeroPatch::isEnabledWhen( _committedBlockTimestamp ) ) diff --git a/libethcore/EVMSchedule.h b/libethcore/EVMSchedule.h index b9aec53b5..dd7563272 100644 --- a/libethcore/EVMSchedule.h +++ b/libethcore/EVMSchedule.h @@ -94,6 +94,8 @@ struct EVMSchedule { }; static const EVMSchedule DefaultSchedule = EVMSchedule(); +// Used only in GeneralStateTests --all tests +static const EVMSchedule FrontierSchedule = EVMSchedule( false, false, 21000 ); static const EVMSchedule HomesteadSchedule = EVMSchedule( true, true, 53000 ); static const EVMSchedule EIP150Schedule = [] { @@ -112,7 +114,7 @@ static const EVMSchedule EIP158Schedule = [] { EVMSchedule schedule = EIP150Schedule; schedule.expByteGas = 50; schedule.eip158Mode = true; - schedule.maxCodeSize = 1024 * 64; // We are now using 64k code size limit in SKALE + schedule.maxCodeSize = 0x6000; // 1024 * 64; // We are now using 64k code size limit in SKALE return schedule; }(); diff --git a/test/tools/jsontests/BlockChainTests.cpp b/test/tools/jsontests/BlockChainTests.cpp index a99211bf0..543c22a7a 100644 --- a/test/tools/jsontests/BlockChainTests.cpp +++ b/test/tools/jsontests/BlockChainTests.cpp @@ -940,6 +940,10 @@ void checkBlocks( _testname + "transaction data in rlp and in field do not match" ); BOOST_CHECK_MESSAGE( trField.gas() == trRlp.gas(), _testname + "transaction gasLimit in rlp and in field do not match" ); + if( trField.gasPrice() != trRlp.gasPrice() ){ + cout << trField.gasPrice() << "!=" << trRlp.gasPrice() << endl; + throw -1; + } BOOST_CHECK_MESSAGE( trField.gasPrice() == trRlp.gasPrice(), _testname + "transaction gasPrice in rlp and in field do not match" ); BOOST_CHECK_MESSAGE( trField.nonce() == trRlp.nonce(), @@ -1079,8 +1083,8 @@ BOOST_AUTO_TEST_CASE( stTransactionTest, *boost::unit_test::precondition( dev::test::run_not_express ) ) {} BOOST_AUTO_TEST_CASE( stTransitionTest, *boost::unit_test::precondition( dev::test::run_not_express ) ) {} -BOOST_AUTO_TEST_CASE( stWalletTest, - *boost::unit_test::precondition( dev::test::run_not_express ) ) {} +// BOOST_AUTO_TEST_CASE( stWalletTest, +// *boost::unit_test::precondition( dev::test::run_not_express ) ) {} // Homestead Tests BOOST_AUTO_TEST_CASE( stCallDelegateCodesCallCodeHomestead, diff --git a/test/tools/libtesteth/ImportTest.cpp b/test/tools/libtesteth/ImportTest.cpp index a805514e8..0a3bf579b 100644 --- a/test/tools/libtesteth/ImportTest.cpp +++ b/test/tools/libtesteth/ImportTest.cpp @@ -418,6 +418,7 @@ void ImportTest::importTransaction( json_spirit::mObject const& _o, eth::Transac toInt( _o.at( "gasLimit" ) ), Address( _o.at( "to" ).get_str() ), importData( _o ), toInt( _o.at( "nonce" ) ), Secret( _o.at( "secretKey" ).get_str() ) ); + o_tr.ignoreExternalGas(); } else { requireJsonFields( _o, "transaction", {{"data", jsonVType::str_type}, {"gasLimit", jsonVType::str_type}, @@ -429,6 +430,7 @@ void ImportTest::importTransaction( json_spirit::mObject const& _o, eth::Transac RLP transactionRLP( transactionRLPStream.out() ); try { o_tr = Transaction( transactionRLP.data(), CheckTransaction::Everything ); + o_tr.ignoreExternalGas(); } catch ( InvalidSignature const& ) { // create unsigned transaction o_tr = _o.at( "to" ).get_str().empty() ? @@ -438,6 +440,7 @@ void ImportTest::importTransaction( json_spirit::mObject const& _o, eth::Transac Transaction( toInt( _o.at( "value" ) ), toInt( _o.at( "gasPrice" ) ), toInt( _o.at( "gasLimit" ) ), Address( _o.at( "to" ).get_str() ), importData( _o ), toInt( _o.at( "nonce" ) ) ); + o_tr.ignoreExternalGas(); } catch ( Exception& _e ) { cnote << "invalid transaction" << boost::diagnostic_information( _e ); } diff --git a/test/tools/libtestutils/Common.cpp b/test/tools/libtestutils/Common.cpp index 7f3c39c04..64baa6746 100644 --- a/test/tools/libtestutils/Common.cpp +++ b/test/tools/libtestutils/Common.cpp @@ -39,7 +39,7 @@ boost::filesystem::path dev::test::getTestPath() { return Options::get().testpath; string testPath; - const char* ptestPath = getenv( "ETHEREUM_TEST_PATH" ); + static const char* ptestPath = getenv( "ETHEREUM_TEST_PATH" ); if ( ptestPath == nullptr ) { clog( VerbosityDebug, "test" ) From b119c8b5d7240f7ffd9a82b437c051b50a76c3f2 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Thu, 19 Sep 2024 11:56:21 +0100 Subject: [PATCH 32/41] SKALED-1951 Back to 64k contract size limit --- libethcore/EVMSchedule.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libethcore/EVMSchedule.h b/libethcore/EVMSchedule.h index dd7563272..75bd93381 100644 --- a/libethcore/EVMSchedule.h +++ b/libethcore/EVMSchedule.h @@ -114,7 +114,7 @@ static const EVMSchedule EIP158Schedule = [] { EVMSchedule schedule = EIP150Schedule; schedule.expByteGas = 50; schedule.eip158Mode = true; - schedule.maxCodeSize = 0x6000; // 1024 * 64; // We are now using 64k code size limit in SKALE + schedule.maxCodeSize = 1024 * 64; // We are now using 64k code size limit in SKALE return schedule; }(); From 3c1ba24d1779ba830edee80ff731d5b3d161009b Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Thu, 19 Sep 2024 11:57:10 +0100 Subject: [PATCH 33/41] SKALED-1951 reset() external gas in ignoreExternalGas() for tests --- libethereum/Transaction.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libethereum/Transaction.h b/libethereum/Transaction.h index 9d3894f31..326d2d147 100644 --- a/libethereum/Transaction.h +++ b/libethereum/Transaction.h @@ -127,7 +127,7 @@ class Transaction : public TransactionBase { void ignoreExternalGas() { m_externalGasIsChecked = true; - m_externalGas = 0; + m_externalGas.reset(); } private: From 901a1b27302a0cdc5ff1f3eeb0692109473de5ce Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Thu, 19 Sep 2024 16:19:56 +0100 Subject: [PATCH 34/41] SKALED-1951 Disable --all tests that require maxCodeSize 0x6000 --- test/tools/jsontests/BlockChainTests.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/test/tools/jsontests/BlockChainTests.cpp b/test/tools/jsontests/BlockChainTests.cpp index 543c22a7a..e1c393d10 100644 --- a/test/tools/jsontests/BlockChainTests.cpp +++ b/test/tools/jsontests/BlockChainTests.cpp @@ -940,10 +940,6 @@ void checkBlocks( _testname + "transaction data in rlp and in field do not match" ); BOOST_CHECK_MESSAGE( trField.gas() == trRlp.gas(), _testname + "transaction gasLimit in rlp and in field do not match" ); - if( trField.gasPrice() != trRlp.gasPrice() ){ - cout << trField.gasPrice() << "!=" << trRlp.gasPrice() << endl; - throw -1; - } BOOST_CHECK_MESSAGE( trField.gasPrice() == trRlp.gasPrice(), _testname + "transaction gasPrice in rlp and in field do not match" ); BOOST_CHECK_MESSAGE( trField.nonce() == trRlp.nonce(), @@ -1083,8 +1079,8 @@ BOOST_AUTO_TEST_CASE( stTransactionTest, *boost::unit_test::precondition( dev::test::run_not_express ) ) {} BOOST_AUTO_TEST_CASE( stTransitionTest, *boost::unit_test::precondition( dev::test::run_not_express ) ) {} -// BOOST_AUTO_TEST_CASE( stWalletTest, -// *boost::unit_test::precondition( dev::test::run_not_express ) ) {} +BOOST_AUTO_TEST_CASE( stWalletTest, + *boost::unit_test::precondition( dev::test::run_not_express ) ) {} // Homestead Tests BOOST_AUTO_TEST_CASE( stCallDelegateCodesCallCodeHomestead, @@ -1115,10 +1111,10 @@ BOOST_AUTO_TEST_CASE( stZeroCallsTest, *boost::unit_test::precondition( dev::test::run_not_express ) ) {} BOOST_AUTO_TEST_CASE( stZeroCallsRevert, *boost::unit_test::precondition( dev::test::run_not_express ) ) {} -BOOST_AUTO_TEST_CASE( stCodeSizeLimit, - *boost::unit_test::precondition( dev::test::run_not_express ) ) {} -BOOST_AUTO_TEST_CASE( stCreateTest, - *boost::unit_test::precondition( dev::test::run_not_express ) ) {} +// BOOST_AUTO_TEST_CASE( stCodeSizeLimit, +// *boost::unit_test::precondition( dev::test::run_not_express ) ) {} +// BOOST_AUTO_TEST_CASE( stCreateTest, +// *boost::unit_test::precondition( dev::test::run_not_express ) ) {} BOOST_AUTO_TEST_CASE( stRevertTest, *boost::unit_test::precondition( dev::test::run_not_express ) ) {} From ce7abdc9918d0343ce9bdd3ed59da04c800929f2 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Mon, 23 Sep 2024 15:58:00 +0100 Subject: [PATCH 35/41] SKALED-1900 Do not build with liblz4 --- .github/workflows/setup-build-publish.yml | 1 - skaled/CMakeLists.txt | 1 - 2 files changed, 2 deletions(-) diff --git a/.github/workflows/setup-build-publish.yml b/.github/workflows/setup-build-publish.yml index ac1b6c069..d223106a5 100644 --- a/.github/workflows/setup-build-publish.yml +++ b/.github/workflows/setup-build-publish.yml @@ -61,7 +61,6 @@ jobs: run: | sudo apt-get -y remove libzmq* || true sudo apt-get -y install software-properties-common gcc-9 g++-9 || true - sudo apt-get -y install liblz4-dev || true - name: Use g++-9 and gcov-9 by default run: | diff --git a/skaled/CMakeLists.txt b/skaled/CMakeLists.txt index e84624e83..593119d59 100644 --- a/skaled/CMakeLists.txt +++ b/skaled/CMakeLists.txt @@ -30,7 +30,6 @@ target_link_libraries( pthread idn2 batched-io - lz4 ) if (CONSENSUS) target_link_libraries(${EXECUTABLE_NAME} PRIVATE consensus) From 69f689c3c44ce55447676afcf36e45ba0815fcd7 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Mon, 23 Sep 2024 15:59:57 +0100 Subject: [PATCH 36/41] SKALED-1900 Remove liblz4 from publish.yml --- .github/workflows/publish.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 2d7414972..211fe676a 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -28,7 +28,6 @@ jobs: run: | sudo apt-get -y remove libzmq* || true sudo apt-get -y install software-properties-common gcc-9 g++-9 || true - sudo apt-get -y install liblz4-dev || true - name: Use g++-9 and gcov-9 by default run: | From b76f2c152c394ec1c902be44c674ba84ea70d4a9 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Thu, 26 Sep 2024 15:51:34 +0100 Subject: [PATCH 37/41] SKALED-1951 Fix CommonJSTests --- test/unittests/libdevcore/CommonJS.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/unittests/libdevcore/CommonJS.cpp b/test/unittests/libdevcore/CommonJS.cpp index bd2223344..4896d9b76 100644 --- a/test/unittests/libdevcore/CommonJS.cpp +++ b/test/unittests/libdevcore/CommonJS.cpp @@ -105,26 +105,26 @@ BOOST_AUTO_TEST_CASE( test_jsToFixed, *boost::unit_test::precondition( dev::test "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ) ); h256 b( "0x000000000000000000000000000000000000000000000000000000740c54b42f" ); BOOST_CHECK( b == jsToFixed< 32 >( "498423084079" ) ); - BOOST_CHECK( h256() == jsToFixed< 32 >( "NotAHexadecimalOrDecimal" ) ); + BOOST_CHECK_THROW( jsToFixed< 32 >( "NotAHexadecimalOrDecimal" ), std::invalid_argument ); } BOOST_AUTO_TEST_CASE( test_jsToInt, *boost::unit_test::precondition( dev::test::run_not_express ) ) { BOOST_CHECK( 43832124 == jsToInt( "43832124" ) ); BOOST_CHECK( 1342356623 == jsToInt( "0x5002bc8f" ) ); BOOST_CHECK( 3483942 == jsToInt( "015224446" ) ); - BOOST_CHECK( 0 == jsToInt( "NotAHexadecimalOrDecimal" ) ); + BOOST_CHECK_THROW( jsToInt( "NotAHexadecimalOrDecimal" ), std::invalid_argument ); BOOST_CHECK( u256( "983298932490823474234" ) == jsToInt< 32 >( "983298932490823474234" ) ); BOOST_CHECK( u256( "983298932490823474234" ) == jsToInt< 32 >( "0x354e03915c00571c3a" ) ); - BOOST_CHECK( u256() == jsToInt< 32 >( "NotAHexadecimalOrDecimal" ) ); + BOOST_CHECK_THROW( jsToInt< 32 >( "NotAHexadecimalOrDecimal" ), std::invalid_argument ); BOOST_CHECK( u128( "228273101986715476958866839113050921216" ) == jsToInt< 16 >( "0xabbbccddeeff11223344556677889900" ) ); - BOOST_CHECK( u128() == jsToInt< 16 >( "NotAHexadecimalOrDecimal" ) ); + BOOST_CHECK_THROW( jsToInt< 16 >( "NotAHexadecimalOrDecimal" ), std::invalid_argument ); } BOOST_AUTO_TEST_CASE( test_jsToU256, *boost::unit_test::precondition( dev::test::run_not_express ) ) { BOOST_CHECK( u256( "983298932490823474234" ) == jsToU256( "983298932490823474234" ) ); - BOOST_CHECK( u256() == jsToU256( "NotAHexadecimalOrDecimal" ) ); + BOOST_CHECK_THROW( jsToU256( "NotAHexadecimalOrDecimal" ), std::invalid_argument ); } BOOST_AUTO_TEST_SUITE_END() From 509aee955b9fec156f788a2c576b6135d166153e Mon Sep 17 00:00:00 2001 From: Dmytro Nazarenko Date: Fri, 27 Sep 2024 20:29:20 +0100 Subject: [PATCH 38/41] Revert "SKALED-1900 release build with separate debug info" --- .github/workflows/custom_build.yml | 1 - .github/workflows/publish.yml | 10 ++++--- .github/workflows/setup-build-publish.yml | 7 ----- CMakeLists.txt | 8 ++++-- deps/build.sh | 33 +++++------------------ 5 files changed, 20 insertions(+), 39 deletions(-) diff --git a/.github/workflows/custom_build.yml b/.github/workflows/custom_build.yml index 45b57eecf..93316c47a 100644 --- a/.github/workflows/custom_build.yml +++ b/.github/workflows/custom_build.yml @@ -22,7 +22,6 @@ on: options: - Debug - RelWithDebInfo - - Release default: RelWithDebInfo jobs: diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 211fe676a..7a73c85ef 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -91,7 +91,7 @@ jobs: export CC=gcc-9 export CXX=g++-9 export TARGET=all - export CMAKE_BUILD_TYPE=Release + export CMAKE_BUILD_TYPE=RelWithDebInfo cd deps ./clean.sh rm -f ./libwebsockets-from-git.tar.gz @@ -105,6 +105,7 @@ jobs: export CMAKE_BUILD_TYPE=RelWithDebInfo mkdir -p build cd build + # -DCMAKE_C_FLAGS=-O3 -DCMAKE_CXX_FLAGS=-O3 cmake -DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE .. cd .. - name: Build all @@ -115,8 +116,9 @@ jobs: export CMAKE_BUILD_TYPE=RelWithDebInfo cd build make skaled -j$(nproc) + #echo "Ensure release mode skaled does not have any debug markers" cp skaled/skaled skaled/skaled-debug - strip --strip-all skaled/skaled + strip skaled/skaled cd .. - name: Configure historic state build run: | @@ -126,6 +128,7 @@ jobs: export CMAKE_BUILD_TYPE=RelWithDebInfo mkdir -p build-historic cd build-historic + # -DCMAKE_C_FLAGS=-O3 -DCMAKE_CXX_FLAGS=-O3 cmake -DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE -DHISTORIC_STATE=1 .. cd .. - name: Build historic state version @@ -136,8 +139,9 @@ jobs: export CMAKE_BUILD_TYPE=RelWithDebInfo cd build-historic make skaled -j$(nproc) + #echo "Ensure release mode skaled does not have any debug markers" cp skaled/skaled skaled/skaled-debug - strip --strip-all skaled/skaled + strip skaled/skaled cd .. - name: Build and publish container run: | diff --git a/.github/workflows/setup-build-publish.yml b/.github/workflows/setup-build-publish.yml index d223106a5..d1b15117f 100644 --- a/.github/workflows/setup-build-publish.yml +++ b/.github/workflows/setup-build-publish.yml @@ -150,13 +150,6 @@ jobs: export CMAKE_BUILD_TYPE=$BUILD_TYPE cd build make skaled -j$(nproc) - if [[ "$BUILD_TYPE" = "Release" ]]; then - debug_wc=$(objdump -h skaled/skaled | grep -i debug | wc -l) - sym_wc=$(readelf -s skaled/skaled | wc -l) - if (( debug_wc != 0 || sym_wc > 10000 )); then - exit 1 - fi - fi cd .. - name: Build and publish container env: diff --git a/CMakeLists.txt b/CMakeLists.txt index 9952809ea..b034843c3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,12 @@ list( APPEND CMAKE_MODULE_PATH ${DEPS_INSTALL_ROOT}/lib/cmake ) link_directories( ${CMAKE_BINARY_DIR}/deps/lib ) # HACK for not-found -lff in testeth +if( NOT CMAKE_BUILD_TYPE MATCHES "Debug" ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -rdynamic" ) + set( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -rdynamic" ) + set( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -rdynamic" ) +endif() + option( SKALED_PROFILING "Build for profiling" OFF ) if( SKALED_PROFILING ) set( CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -pg" ) @@ -26,8 +32,6 @@ if( SKALED_PROFILING ) set( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pg" ) endif() -set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -s") - if( CMAKE_BUILD_TYPE STREQUAL "Release" ) set( CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -O3" ) set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3" ) diff --git a/deps/build.sh b/deps/build.sh index 735dc5e7f..664c42448 100755 --- a/deps/build.sh +++ b/deps/build.sh @@ -1,6 +1,5 @@ #!/bin/bash - set -e export SKALED_DEPS_CHAIN=1 @@ -1159,20 +1158,16 @@ then # echo -e "${COLOR_INFO}configuring it${COLOR_DOTS}...${COLOR_RESET}" cd libuv - # eval ./autogen.sh - # eval ./configure "${CONF_CROSSCOMPILING_OPTS_GENERIC}" --enable-static --disable-shared --with-pic --prefix="$INSTALL_ROOT" "${CONF_DEBUG_OPTIONS}" + eval ./autogen.sh + eval ./configure "${CONF_CROSSCOMPILING_OPTS_GENERIC}" --enable-static --disable-shared --with-pic --prefix="$INSTALL_ROOT" "${CONF_DEBUG_OPTIONS}" #--with-sysroot=="$INSTALL_ROOT" - mkdir build && cd build - eval "$CMAKE" "${CMAKE_CROSSCOMPILING_OPTS}" -DCMAKE_INSTALL_PREFIX="$INSTALL_ROOT" -DCMAKE_BUILD_TYPE="$TOP_CMAKE_BUILD_TYPE" \ - -DBUILD_SHARED_LIBS=OFF \ - .. - cd ../.. + cd .. fi echo -e "${COLOR_INFO}building it${COLOR_DOTS}...${COLOR_RESET}" - cd libuv/build + cd libuv eval "$MAKE" "${PARALLEL_MAKE_OPTIONS}" eval "$MAKE" "${PARALLEL_MAKE_OPTIONS}" install - cd ../.. + cd .. cd "$SOURCES_ROOT" else echo -e "${COLOR_SUCCESS}SKIPPED${COLOR_RESET}" @@ -1396,21 +1391,13 @@ then cd boost_1_68_0 echo -e "${COLOR_INFO}configuring and building it${COLOR_DOTS}...${COLOR_RESET}" eval ./bootstrap.sh --prefix="$INSTALL_ROOT" --with-libraries=atomic,context,filesystem,program_options,regex,system,thread,date_time,iostreams - - if [ "$DEBUG" = "1" ]; then - variant=debug - else - variant=release - fi - if [ ${ARCH} = "arm" ] then sed -i -e 's#using gcc ;#using gcc : arm : /usr/local/toolchains/gcc7.2-arm/bin/arm-linux-gnueabihf-g++ ;#g' project-config.jam - eval ./b2 "${CONF_CROSSCOMPILING_OPTS_BOOST}" cxxflags=-fPIC cflags=-fPIC "${PARALLEL_MAKE_OPTIONS}" --prefix="$INSTALL_ROOT" --layout=system variant=$variant link=static threading=multi install + eval ./b2 "${CONF_CROSSCOMPILING_OPTS_BOOST}" cxxflags=-fPIC cflags=-fPIC "${PARALLEL_MAKE_OPTIONS}" --prefix="$INSTALL_ROOT" --layout=system variant=debug link=static threading=multi install else - eval ./b2 cxxflags=-fPIC cflags=-fPIC "${PARALLEL_MAKE_OPTIONS}" --prefix="$INSTALL_ROOT" --layout=system variant=$variant link=static threading=multi install + eval ./b2 cxxflags=-fPIC cflags=-fPIC "${PARALLEL_MAKE_OPTIONS}" --prefix="$INSTALL_ROOT" --layout=system variant=debug link=static threading=multi install fi - cd .. cd "$SOURCES_ROOT" else @@ -2095,7 +2082,6 @@ then eval tar -xzf folly-from-git.tar.gz fi echo -e "${COLOR_INFO}fixing it${COLOR_DOTS}...${COLOR_RESET}" - sed -i 's/list(APPEND FOLLY_LINK_LIBRARIES ${LIBUNWIND_LIBRARIES})/list(APPEND FOLLY_LINK_LIBRARIES ${LIBUNWIND_LIBRARIES} lzma)/' ./folly/CMake/folly-deps.cmake sed -i 's/google::InstallFailureFunction(abort);/google::InstallFailureFunction( reinterpret_cast < google::logging_fail_func_t > ( abort ) );/g' ./folly/folly/init/Init.cpp echo -e "${COLOR_INFO}configuring it${COLOR_DOTS}...${COLOR_RESET}" cd folly @@ -2105,8 +2091,6 @@ then -DBOOST_ROOT="$INSTALL_ROOT" -DBOOST_LIBRARYDIR="$INSTALL_ROOT/lib" -DBoost_NO_WARN_NEW_VERSIONS=1 -DBoost_DEBUG=ON \ -DBUILD_SHARED_LIBS=OFF \ -DBUILD_TESTS=OFF -DBUILD_BROKEN_TESTS=OFF -DBUILD_HANGING_TESTS=OFF -DBUILD_SLOW_TESTS=OFF \ - -DCMAKE_INCLUDE_PATH="${INSTALL_ROOT}/include" \ - -DCMAKE_LIBRARY_PATH="${INSTALL_ROOT}/lib" \ .. cd .. else @@ -2116,9 +2100,6 @@ then cd build2 eval "$MAKE" "${PARALLEL_MAKE_OPTIONS}" eval "$MAKE" "${PARALLEL_MAKE_OPTIONS}" install - if [ "$DEBUG" = "0" ]; then - eval strip --strip-debug "${INSTALL_ROOT}"/lib/libfolly*.a - fi cd "$SOURCES_ROOT" else echo -e "${COLOR_SUCCESS}SKIPPED${COLOR_RESET}" From 0b091d94872df48a259795ea108373bf2f9d989f Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Mon, 30 Sep 2024 15:27:00 +0100 Subject: [PATCH 39/41] SKALED-1900 Fix static livuv --- deps/build.sh | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/deps/build.sh b/deps/build.sh index 664c42448..ce0e030c7 100755 --- a/deps/build.sh +++ b/deps/build.sh @@ -1158,16 +1158,20 @@ then # echo -e "${COLOR_INFO}configuring it${COLOR_DOTS}...${COLOR_RESET}" cd libuv - eval ./autogen.sh - eval ./configure "${CONF_CROSSCOMPILING_OPTS_GENERIC}" --enable-static --disable-shared --with-pic --prefix="$INSTALL_ROOT" "${CONF_DEBUG_OPTIONS}" + # eval ./autogen.sh + # eval ./configure "${CONF_CROSSCOMPILING_OPTS_GENERIC}" --enable-static --disable-shared --with-pic --prefix="$INSTALL_ROOT" "${CONF_DEBUG_OPTIONS}" #--with-sysroot=="$INSTALL_ROOT" - cd .. + mkdir build && cd build + eval "$CMAKE" "${CMAKE_CROSSCOMPILING_OPTS}" -DCMAKE_INSTALL_PREFIX="$INSTALL_ROOT" -DCMAKE_BUILD_TYPE="$TOP_CMAKE_BUILD_TYPE" \ + -DBUILD_SHARED_LIBS=OFF -DLIBUV_BUILD_SHARED=OFF\ + .. + cd ../.. fi echo -e "${COLOR_INFO}building it${COLOR_DOTS}...${COLOR_RESET}" - cd libuv + cd libuv/build eval "$MAKE" "${PARALLEL_MAKE_OPTIONS}" eval "$MAKE" "${PARALLEL_MAKE_OPTIONS}" install - cd .. + cd ../.. cd "$SOURCES_ROOT" else echo -e "${COLOR_SUCCESS}SKIPPED${COLOR_RESET}" @@ -1391,13 +1395,21 @@ then cd boost_1_68_0 echo -e "${COLOR_INFO}configuring and building it${COLOR_DOTS}...${COLOR_RESET}" eval ./bootstrap.sh --prefix="$INSTALL_ROOT" --with-libraries=atomic,context,filesystem,program_options,regex,system,thread,date_time,iostreams + + if [ "$DEBUG" = "1" ]; then + variant=debug + else + variant=release + fi + if [ ${ARCH} = "arm" ] then sed -i -e 's#using gcc ;#using gcc : arm : /usr/local/toolchains/gcc7.2-arm/bin/arm-linux-gnueabihf-g++ ;#g' project-config.jam - eval ./b2 "${CONF_CROSSCOMPILING_OPTS_BOOST}" cxxflags=-fPIC cflags=-fPIC "${PARALLEL_MAKE_OPTIONS}" --prefix="$INSTALL_ROOT" --layout=system variant=debug link=static threading=multi install + eval ./b2 "${CONF_CROSSCOMPILING_OPTS_BOOST}" cxxflags=-fPIC cflags=-fPIC "${PARALLEL_MAKE_OPTIONS}" --prefix="$INSTALL_ROOT" --layout=system variant=$variant link=static threading=multi install else - eval ./b2 cxxflags=-fPIC cflags=-fPIC "${PARALLEL_MAKE_OPTIONS}" --prefix="$INSTALL_ROOT" --layout=system variant=debug link=static threading=multi install + eval ./b2 cxxflags=-fPIC cflags=-fPIC "${PARALLEL_MAKE_OPTIONS}" --prefix="$INSTALL_ROOT" --layout=system variant=$variant link=static threading=multi install fi + cd .. cd "$SOURCES_ROOT" else @@ -2082,6 +2094,7 @@ then eval tar -xzf folly-from-git.tar.gz fi echo -e "${COLOR_INFO}fixing it${COLOR_DOTS}...${COLOR_RESET}" + sed -i 's/list(APPEND FOLLY_LINK_LIBRARIES ${LIBUNWIND_LIBRARIES})/list(APPEND FOLLY_LINK_LIBRARIES ${LIBUNWIND_LIBRARIES} lzma)/' ./folly/CMake/folly-deps.cmake sed -i 's/google::InstallFailureFunction(abort);/google::InstallFailureFunction( reinterpret_cast < google::logging_fail_func_t > ( abort ) );/g' ./folly/folly/init/Init.cpp echo -e "${COLOR_INFO}configuring it${COLOR_DOTS}...${COLOR_RESET}" cd folly @@ -2091,6 +2104,8 @@ then -DBOOST_ROOT="$INSTALL_ROOT" -DBOOST_LIBRARYDIR="$INSTALL_ROOT/lib" -DBoost_NO_WARN_NEW_VERSIONS=1 -DBoost_DEBUG=ON \ -DBUILD_SHARED_LIBS=OFF \ -DBUILD_TESTS=OFF -DBUILD_BROKEN_TESTS=OFF -DBUILD_HANGING_TESTS=OFF -DBUILD_SLOW_TESTS=OFF \ + -DCMAKE_INCLUDE_PATH="${INSTALL_ROOT}/include" \ + -DCMAKE_LIBRARY_PATH="${INSTALL_ROOT}/lib" \ .. cd .. else @@ -2100,6 +2115,9 @@ then cd build2 eval "$MAKE" "${PARALLEL_MAKE_OPTIONS}" eval "$MAKE" "${PARALLEL_MAKE_OPTIONS}" install + if [ "$DEBUG" = "0" ]; then + eval strip --strip-debug "${INSTALL_ROOT}"/lib/libfolly*.a + fi cd "$SOURCES_ROOT" else echo -e "${COLOR_SUCCESS}SKIPPED${COLOR_RESET}" From 67749fbef157fa7f1f41ca57fff21fa7a3a64020 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Mon, 30 Sep 2024 16:46:38 +0100 Subject: [PATCH 40/41] SKALED=1900 Use upload-artifact v4 --- .github/workflows/functional-tests.yml | 2 +- .github/workflows/setup-build-publish.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/functional-tests.yml b/.github/workflows/functional-tests.yml index f7356fc36..027486dec 100644 --- a/.github/workflows/functional-tests.yml +++ b/.github/workflows/functional-tests.yml @@ -83,7 +83,7 @@ for C in $(docker ps -aq); do docker logs $C>$C.log; done || true if: ${{ always() }} - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v4 if: ${{ always() }} continue-on-error: true with: diff --git a/.github/workflows/setup-build-publish.yml b/.github/workflows/setup-build-publish.yml index d1b15117f..0b3bf1b0a 100644 --- a/.github/workflows/setup-build-publish.yml +++ b/.github/workflows/setup-build-publish.yml @@ -161,7 +161,7 @@ jobs: bash ./scripts/build_and_publish.sh - name: Upload skaled binary as artifact - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 if: ${{ always() }} with: name: skaled-${{ inputs.node_type }} From e96df22a3a5c717451fe63e5363dc86f90721de9 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Wed, 2 Oct 2024 13:47:29 +0100 Subject: [PATCH 41/41] SKALED-1951 Remove commented code --- test/tools/jsontests/BlockChainTests.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/tools/jsontests/BlockChainTests.cpp b/test/tools/jsontests/BlockChainTests.cpp index e1c393d10..2959da8eb 100644 --- a/test/tools/jsontests/BlockChainTests.cpp +++ b/test/tools/jsontests/BlockChainTests.cpp @@ -1111,10 +1111,6 @@ BOOST_AUTO_TEST_CASE( stZeroCallsTest, *boost::unit_test::precondition( dev::test::run_not_express ) ) {} BOOST_AUTO_TEST_CASE( stZeroCallsRevert, *boost::unit_test::precondition( dev::test::run_not_express ) ) {} -// BOOST_AUTO_TEST_CASE( stCodeSizeLimit, -// *boost::unit_test::precondition( dev::test::run_not_express ) ) {} -// BOOST_AUTO_TEST_CASE( stCreateTest, -// *boost::unit_test::precondition( dev::test::run_not_express ) ) {} BOOST_AUTO_TEST_CASE( stRevertTest, *boost::unit_test::precondition( dev::test::run_not_express ) ) {}