diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 64975b166..8a9c320b3 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -571,8 +571,8 @@ bool Client::isTimeToDoSnapshot( uint64_t _timestamp ) const { this->last_snapshot_time / uint64_t( snapshotIntervalMs ); } -void Client::setRestartOrExitTime( uint64_t _timestamp, bool _isExit ) const { - m_instanceMonitor->initRotationParams( _timestamp, _isExit ); +void Client::setSchainExitTime( uint64_t _timestamp ) const { + m_instanceMonitor->initRotationParams( _timestamp ); } void Client::onChainChanged( ImportRoute const& _ir ) { diff --git a/libethereum/Client.h b/libethereum/Client.h index 75b59d025..8e508042e 100644 --- a/libethereum/Client.h +++ b/libethereum/Client.h @@ -268,8 +268,8 @@ class Client : public ClientBase, protected Worker { return path; } - // set restarting or exiting time for node rotation - void setRestartOrExitTime( uint64_t _timestamp, bool _isExit ) const; + // set exiting time for node rotation + void setSchainExitTime( uint64_t _timestamp ) const; dev::h256 getSnapshotHash( unsigned _blockNumber ) const { return this->m_snapshotManager->getSnapshotHash( _blockNumber ); diff --git a/libethereum/InstanceMonitor.cpp b/libethereum/InstanceMonitor.cpp index 42ca97c28..3c3b20aa3 100644 --- a/libethereum/InstanceMonitor.cpp +++ b/libethereum/InstanceMonitor.cpp @@ -33,42 +33,27 @@ using namespace dev; namespace fs = boost::filesystem; const std::string InstanceMonitor::rotation_file_name = "rotation.txt"; -const std::string InstanceMonitor::temp_config_ext = ".tmp"; void InstanceMonitor::performRotation() { - if ( m_isExit ) { - fs::remove( m_rotationFilePath ); - ExitHandler::exitHandler( SIGTERM ); - } else { - fs::path newConfigPath = m_configPath; - newConfigPath += temp_config_ext; - if ( !fs::exists( newConfigPath ) ) { - throw std::runtime_error( "New config not found" ); - } - fs::remove( m_configPath ); - fs::rename( newConfigPath, m_configPath ); - fs::remove( m_rotationFilePath ); - ExitHandler::exitHandler( SIGTERM ); - } + fs::remove( m_rotationFilePath ); + ExitHandler::exitHandler( SIGTERM ); } -void InstanceMonitor::initRotationParams( uint64_t _timestamp, bool _isExit ) { +void InstanceMonitor::initRotationParams( uint64_t _finishTimestamp ) { nlohmann::json rotationJson = nlohmann::json::object(); - rotationJson["timestamp"] = _timestamp; - rotationJson["isExit"] = _isExit; + rotationJson["timestamp"] = _finishTimestamp; std::ofstream rotationFile( m_rotationFilePath.string() ); rotationFile << rotationJson; - m_finishTimestamp = _timestamp; - m_isExit = _isExit; + m_finishTimestamp = _finishTimestamp; } -bool InstanceMonitor::isTimeToRotate( uint64_t _timestamp ) { +bool InstanceMonitor::isTimeToRotate( uint64_t _finishTimestamp ) { if ( !fs::exists( m_rotationFilePath ) ) { return false; } - return m_finishTimestamp <= _timestamp; + return m_finishTimestamp <= _finishTimestamp; } void InstanceMonitor::restoreRotationParams() { @@ -76,8 +61,6 @@ void InstanceMonitor::restoreRotationParams() { std::ifstream rotateFile( m_rotationFilePath.string() ); auto rotateJson = nlohmann::json::parse( rotateFile ); auto rotateTimestamp = rotateJson["timestamp"].get< uint64_t >(); - auto isExit = rotateJson["isExit"].get< bool >(); m_finishTimestamp = rotateTimestamp; - m_isExit = isExit; } } diff --git a/libethereum/InstanceMonitor.h b/libethereum/InstanceMonitor.h index 3f3c3fcf2..c6d6ad21a 100644 --- a/libethereum/InstanceMonitor.h +++ b/libethereum/InstanceMonitor.h @@ -31,32 +31,24 @@ namespace fs = boost::filesystem; class InstanceMonitor { public: - explicit InstanceMonitor( const boost::filesystem::path& _configPath ) - : m_configPath( _configPath ), - m_finishTimestamp( 0 ), - m_isExit( false ), - m_rotationFilePath( dev::getDataDir() / rotation_file_name ) { + explicit InstanceMonitor() + : m_finishTimestamp( 0 ), m_rotationFilePath( dev::getDataDir() / rotation_file_name ) { restoreRotationParams(); } void performRotation(); - void initRotationParams( uint64_t _timestamp, bool _isExit ); - bool isTimeToRotate( uint64_t _timestamp ); + void initRotationParams( uint64_t _finishTimestamp ); + bool isTimeToRotate( uint64_t _finishTimestamp ); protected: void restoreRotationParams(); [[nodiscard]] uint64_t finishTimestamp() const { return m_finishTimestamp; } - [[nodiscard]] bool isExit() const { - return m_isExit; + [[nodiscard]] fs::path rotationFilePath() const { + return m_rotationFilePath; } - [[nodiscard]] fs::path rotationFilePath() const { return m_rotationFilePath; } - - private : boost::filesystem::path const m_configPath; uint64_t m_finishTimestamp; - bool m_isExit; const fs::path m_rotationFilePath; static const std::string rotation_file_name; - static const std::string temp_config_ext; }; diff --git a/libskale/httpserveroverride.cpp b/libskale/httpserveroverride.cpp index 2b26f81c2..578150556 100644 --- a/libskale/httpserveroverride.cpp +++ b/libskale/httpserveroverride.cpp @@ -2688,20 +2688,19 @@ bool SkaleServerOverride::handleProtocolSpecificRequest( SkaleServerHelper& sse, } const SkaleServerOverride::protocol_rpc_map_t SkaleServerOverride::g_protocol_rpc_map = { - {"eth_setRestartOrExitTime", &SkaleServerOverride::eth_setRestartOrExitTime}, - {"setRestartOrExitTime", &SkaleServerOverride::eth_setRestartOrExitTime}, + {"setSchainExitTime", &SkaleServerOverride::setSchainExitTime}, }; /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -void SkaleServerOverride::eth_setRestartOrExitTime( SkaleServerHelper& /*sse*/, +void SkaleServerOverride::setSchainExitTime( SkaleServerHelper& /*sse*/, const std::string& strOrigin, const nlohmann::json& joRequest, nlohmann::json& joResponse ) { SkaleServerOverride* pSO = this; try { // check "params" in joRequest and it's JSON object { } if ( !skale::server::helper::checkParamsIsObject( - "eth_setRestartOrExitTime", joRequest, joResponse ) ) + "setSchainExitTime", joRequest, joResponse ) ) return; const nlohmann::json& joParams = joRequest["params"]; // parse value of "finishTime" @@ -2717,31 +2716,7 @@ void SkaleServerOverride::eth_setRestartOrExitTime( SkaleServerHelper& /*sse*/, // no "finishTime" present in "params" throw std::runtime_error( "missing the \"finishTime\" parameter" ); } - // parse value of "isExit" - bool isExit = false; - if ( joParams.count( "isExit" ) > 0 ) { - const nlohmann::json& joValue = joParams["isExit"]; - if ( joValue.is_boolean() ) - isExit = joValue.get< bool >(); - else if ( joValue.is_number() ) - isExit = joValue.get< int >() ? true : false; - else if ( joValue.is_string() ) { - std::string s = skutils::tools::to_lower( - skutils::tools::trim_copy( joValue.get< std::string >() ) ); - if ( s.length() > 0 ) { - char c = s[0]; - if ( c == 't' || c == 'y' ) // "true", "yes" - isExit = true; - else if ( '0' <= c && c <= '9' ) - isExit = atoi( s.c_str() ) ? true : false; - else - throw std::runtime_error( - "invalid value in the \"isExit\" parameter, need boolean flag" ); - } - } else - throw std::runtime_error( - "invalid value in the \"isExit\" parameter, need boolean flag" ); - } + // get connection info skutils::url u( strOrigin ); std::string strIP = u.host(); @@ -2749,14 +2724,13 @@ void SkaleServerOverride::eth_setRestartOrExitTime( SkaleServerHelper& /*sse*/, strIP ); // NOTICE: supports both IPv4 and IPv6 // print info about this method call into log output clog( dev::VerbosityInfo, cc::warn( "ADMIN-CALL" ) ) - << ( cc::debug( "Got " ) + cc::info( "eth_setRestartOrExitTime" ) + + << ( cc::debug( "Got " ) + cc::info( "setSchainExitTime" ) + cc::debug( " call with " ) + cc::notice( "finishTime" ) + cc::debug( "=" ) + - cc::size10( finishTime ) + cc::debug( ", " ) + cc::notice( "isExit" ) + - cc::debug( "=" ) + cc::yn( isExit ) + cc::debug( ", " ) + - cc::notice( "origin" ) + cc::debug( "=" ) + cc::notice( strOrigin ) + - cc::debug( ", " ) + cc::notice( "remote IP" ) + cc::debug( "=" ) + - cc::notice( strIP ) + cc::debug( ", " ) + cc::notice( "isLocalAddress" ) + - cc::debug( "=" ) + cc::yn( isLocalAddress ) ); + cc::size10( finishTime ) + cc::debug( ", " ) + cc::notice( "origin" ) + + cc::debug( "=" ) + cc::notice( strOrigin ) + cc::debug( ", " ) + + cc::notice( "remote IP" ) + cc::debug( "=" ) + cc::notice( strIP ) + + cc::debug( ", " ) + cc::notice( "isLocalAddress" ) + cc::debug( "=" ) + + cc::yn( isLocalAddress ) ); // return call error if call from outside of local network if ( !isLocalAddress ) throw std::runtime_error( @@ -2764,24 +2738,18 @@ void SkaleServerOverride::eth_setRestartOrExitTime( SkaleServerHelper& /*sse*/, // RPC call will extract text from it // and return it as call error // - // TO-DO: handle call to eth_setRestartOrExitTime or setRestartOrExitTime - both names are - // supported - // // TO-DO: optionally, put some data into joResponse which represents return value JSON // // TESTING: you can use wascat console // npm install -g // wscat -c 127.0.0.1:15020 - // {"jsonrpc":"2.0","id":12345,"method":"eth_setRestartOrExitTime","params":{}} - // {"jsonrpc":"2.0","id":12345,"method":"eth_setRestartOrExitTime","params":{"finishTime":123,"isExit":true}} + // {"jsonrpc":"2.0","id":12345,"method":"setSchainExitTime","params":{}} + // {"jsonrpc":"2.0","id":12345,"method":"setSchainExitTime","params":{"finishTime":123}} // // or specify JSON right in command line... // // wscat -c ws://127.0.0.1:15020 -w 1 -x - // '{"jsonrpc":"2.0","id":12345,"method":"eth_setRestartOrExitTime","params":{"finishTime":123,"isExit":true}}' - // wscat -c ws://127.0.0.1:15020 -w 1 -x - // '{"jsonrpc":"2.0","id":12345,"method":"setRestartOrExitTime","params":{"finishTime":123,"isExit":true}}' - // + // '{"jsonrpc":"2.0","id":12345,"method":"setSchainExitTime","params":{"finishTime":123}}' // Result std::string strRequest = joRequest.dump(); @@ -2792,30 +2760,29 @@ void SkaleServerOverride::eth_setRestartOrExitTime( SkaleServerHelper& /*sse*/, dev::eth::Client* pClient = dynamic_cast< dev::eth::Client* >( pEthereum ); if ( !pClient ) throw std::runtime_error( "internal error, no client interface found" ); - pClient->setRestartOrExitTime( uint64_t( finishTime ), isExit ); + pClient->setSchainExitTime( uint64_t( finishTime ) ); joResponse = nlohmann::json::parse( strResponse ); } catch ( const std::exception& ex ) { if ( pSO->m_bTraceCalls ) clog( dev::Verbosity::VerbosityError, cc::debug( " during call from " ) + cc::u( strOrigin ) ) - << ( " " + cc::error( "error in " ) + cc::warn( "eth_setRestartOrExitTime" ) + + << ( " " + cc::error( "error in " ) + cc::warn( "setSchainExitTime" ) + cc::error( " rpc method, exception " ) + cc::warn( ex.what() ) ); nlohmann::json joError = nlohmann::json::object(); joError["code"] = -32602; joError["message"] = - std::string( "error in \"eth_setRestartOrExitTime\" rpc method, exception: " ) + - ex.what(); + std::string( "error in \"setSchainExitTime\" rpc method, exception: " ) + ex.what(); joResponse["error"] = joError; return; } catch ( ... ) { if ( pSO->m_bTraceCalls ) clog( dev::Verbosity::VerbosityError, cc::debug( " during call from " ) + cc::u( strOrigin ) ) - << ( " " + cc::error( "error in " ) + cc::warn( "eth_setRestartOrExitTime" ) + + << ( " " + cc::error( "error in " ) + cc::warn( "setSchainExitTime" ) + cc::error( " rpc method, unknown exception " ) ); nlohmann::json joError = nlohmann::json::object(); joError["code"] = -32602; - joError["message"] = "error in \"eth_setRestartOrExitTime\" rpc method, unknown exception"; + joError["message"] = "error in \"setSchainExitTime\" rpc method, unknown exception"; joResponse["error"] = joError; return; } diff --git a/libskale/httpserveroverride.h b/libskale/httpserveroverride.h index 6c74d200f..f54bfef94 100644 --- a/libskale/httpserveroverride.h +++ b/libskale/httpserveroverride.h @@ -403,7 +403,7 @@ class SkaleServerOverride : public jsonrpc::AbstractServerConnector, typedef std::map< std::string, rpc_method_t > protocol_rpc_map_t; static const protocol_rpc_map_t g_protocol_rpc_map; - void eth_setRestartOrExitTime( SkaleServerHelper& sse, const std::string& strOrigin, + void setSchainExitTime( SkaleServerHelper& sse, const std::string& strOrigin, const nlohmann::json& joRequest, nlohmann::json& joResponse ); friend class SkaleRelayWS; diff --git a/libweb3jsonrpc/Eth.cpp b/libweb3jsonrpc/Eth.cpp index 6a4d6b634..34d43f7e1 100644 --- a/libweb3jsonrpc/Eth.cpp +++ b/libweb3jsonrpc/Eth.cpp @@ -255,10 +255,9 @@ Json::Value Eth::eth_unsubscribe( Json::Value const& /*_transaction*/ ) { } } -Json::Value Eth::eth_setRestartOrExitTime( Json::Value const& /*_transaction*/ ) { +Json::Value Eth::setSchainExitTime( Json::Value const& /*_transaction*/ ) { try { - throw JsonRpcException( - "eth_setRestartOrExitTime() API is not supported yet over HTTP(S)" ); + throw JsonRpcException( "setSchainExitTime() API is not supported yet over HTTP(S)" ); } catch ( Exception const& ) { throw JsonRpcException( exceptionToErrorMessage() ); } diff --git a/libweb3jsonrpc/Eth.h b/libweb3jsonrpc/Eth.h index 2dcbee16c..18c931da3 100644 --- a/libweb3jsonrpc/Eth.h +++ b/libweb3jsonrpc/Eth.h @@ -134,7 +134,7 @@ class Eth : public dev::rpc::EthFace { virtual std::string eth_chainId() override; virtual Json::Value eth_subscribe( Json::Value const& _transaction ) override; virtual Json::Value eth_unsubscribe( Json::Value const& _transaction ) override; - virtual Json::Value eth_setRestartOrExitTime( Json::Value const& _transaction ) override; + virtual Json::Value setSchainExitTime( Json::Value const& _transaction ) override; void setTransactionDefaults( eth::TransactionSkeleton& _t ); diff --git a/libweb3jsonrpc/EthFace.h b/libweb3jsonrpc/EthFace.h index 3c9db8942..62780cd66 100644 --- a/libweb3jsonrpc/EthFace.h +++ b/libweb3jsonrpc/EthFace.h @@ -190,13 +190,9 @@ class EthFace : public ServerInterface< EthFace > { &dev::rpc::EthFace::eth_unsubscribeI ); this->bindAndAddMethod( - jsonrpc::Procedure( "eth_setRestartOrExitTime", jsonrpc::PARAMS_BY_POSITION, + jsonrpc::Procedure( "setSchainExitTime", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1", jsonrpc::JSON_OBJECT, NULL ), - &dev::rpc::EthFace::eth_setRestartOrExitTimeI ); - this->bindAndAddMethod( - jsonrpc::Procedure( "setRestartOrExitTime", jsonrpc::PARAMS_BY_POSITION, - jsonrpc::JSON_OBJECT, "param1", jsonrpc::JSON_OBJECT, NULL ), - &dev::rpc::EthFace::eth_setRestartOrExitTimeI ); + &dev::rpc::EthFace::setSchainExitTimeI ); this->bindAndAddMethod( jsonrpc::Procedure( "eth_inspectTransaction", jsonrpc::PARAMS_BY_POSITION, @@ -396,9 +392,8 @@ class EthFace : public ServerInterface< EthFace > { inline virtual void eth_unsubscribeI( const Json::Value& request, Json::Value& response ) { response = this->eth_unsubscribe( request[0u] ); } - inline virtual void eth_setRestartOrExitTimeI( - const Json::Value& request, Json::Value& response ) { - response = this->eth_setRestartOrExitTime( request[0u] ); + inline virtual void setSchainExitTimeI( const Json::Value& request, Json::Value& response ) { + response = this->setSchainExitTime( request[0u] ); } inline virtual void eth_signTransactionI( const Json::Value& request, Json::Value& response ) { response = this->eth_signTransaction( request[0u] ); @@ -481,7 +476,7 @@ class EthFace : public ServerInterface< EthFace > { virtual Json::Value eth_signTransaction( const Json::Value& param1 ) = 0; virtual Json::Value eth_subscribe( const Json::Value& param1 ) = 0; virtual Json::Value eth_unsubscribe( const Json::Value& param1 ) = 0; - virtual Json::Value eth_setRestartOrExitTime( const Json::Value& param1 ) = 0; + virtual Json::Value setSchainExitTime( const Json::Value& param1 ) = 0; virtual Json::Value eth_inspectTransaction( const std::string& param1 ) = 0; virtual std::string eth_sendRawTransaction( const std::string& param1 ) = 0; virtual bool eth_notePassword( const std::string& param1 ) = 0; diff --git a/libweb3jsonrpc/eth.json b/libweb3jsonrpc/eth.json index c1f92fec7..0577147a2 100644 --- a/libweb3jsonrpc/eth.json +++ b/libweb3jsonrpc/eth.json @@ -47,8 +47,7 @@ { "name": "eth_signTransaction", "params": [{}], "order": [], "returns": {}}, { "name": "eth_subscribe", "params": [{}], "order": [], "returns": {}}, { "name": "eth_unsubscribe", "params": [{}], "order": [], "returns": {}}, -{ "name": "eth_setRestartOrExitTime", "params": [{}], "order": [], "returns": {}}, -{ "name": "setRestartOrExitTime", "params": [{}], "order": [], "returns": {}}, +{ "name": "setSchainExitTime", "params": [{}], "order": [], "returns": {}}, { "name": "eth_inspectTransaction", "params": [""], "order": [], "returns": {}}, { "name": "eth_sendRawTransaction", "params": [""], "order": [], "returns": ""}, { "name": "eth_notePassword", "params": [""], "order": [], "returns": true}, diff --git a/skaled/main.cpp b/skaled/main.cpp index e196bec48..59bea03b9 100644 --- a/skaled/main.cpp +++ b/skaled/main.cpp @@ -1321,7 +1321,7 @@ int main( int argc, char** argv ) try { std::shared_ptr< GasPricer > gasPricer; std::shared_ptr< InstanceMonitor > instanceMonitor; - instanceMonitor.reset( new InstanceMonitor( configPath ) ); + instanceMonitor.reset( new InstanceMonitor() ); if ( getDataDir().size() ) Defaults::setDBPath( getDataDir() ); diff --git a/test/unittests/libethereum/ClientTest.cpp b/test/unittests/libethereum/ClientTest.cpp index 1ee2ad958..dd8ee4eb0 100644 --- a/test/unittests/libethereum/ClientTest.cpp +++ b/test/unittests/libethereum/ClientTest.cpp @@ -122,7 +122,7 @@ class TestClientFixture : public TestOutputHelperFixture { // ), dir, // dir, chainParams, WithExisting::Kill, {"eth"}, testingMode ) ); - auto monitor = make_shared< InstanceMonitor >("test"); + auto monitor = make_shared< InstanceMonitor >(); m_ethereum.reset( new eth::ClientTest( chainParams, ( int ) chainParams.networkID, shared_ptr< GasPricer >(), NULL, monitor, dir, WithExisting::Kill ) ); @@ -189,7 +189,7 @@ class TestClientSnapshotsFixture : public TestOutputHelperFixture, public Fixtur std::shared_ptr< SnapshotManager > mgr; mgr.reset( new SnapshotManager( fs::path( BTRFS_DIR_PATH ), {"vol1", "vol2"} ) ); - auto monitor = make_shared< InstanceMonitor >("test"); + auto monitor = make_shared< InstanceMonitor >(); m_ethereum.reset( new eth::ClientTest( chainParams, ( int ) chainParams.networkID, shared_ptr< GasPricer >(), mgr, monitor, dir, WithExisting::Kill ) ); diff --git a/test/unittests/libethereum/InstanceMonitorTest.cpp b/test/unittests/libethereum/InstanceMonitorTest.cpp index beea2e0dc..0ea900527 100644 --- a/test/unittests/libethereum/InstanceMonitorTest.cpp +++ b/test/unittests/libethereum/InstanceMonitorTest.cpp @@ -13,16 +13,12 @@ namespace fs = boost::filesystem; class InstanceMonitorMock: public InstanceMonitor { public: - explicit InstanceMonitorMock(fs::path const &config) : InstanceMonitor(config) {}; + explicit InstanceMonitorMock() : InstanceMonitor() {}; uint64_t getFinishTimestamp() { return this->finishTimestamp(); }; - bool getIsExit() { - return this->isExit(); - }; - fs::path getRotationFilePath() { return this->rotationFilePath(); } @@ -30,11 +26,9 @@ class InstanceMonitorMock: public InstanceMonitor { class InstanceMonitorTestFixture : public TestOutputHelperFixture { public: - fs::path configPath = "testConfig.json"; - InstanceMonitorTestFixture() : instanceMonitor( configPath ) { + InstanceMonitorTestFixture() : instanceMonitor() { std::fstream file; - file.open( configPath.string(), std::ios::out ); rotationFilePath = instanceMonitor.getRotationFilePath(); } @@ -42,9 +36,6 @@ class InstanceMonitorTestFixture : public TestOutputHelperFixture { fs::path rotationFilePath; ~InstanceMonitorTestFixture() override { - if (fs::exists(configPath)) { - fs::remove(configPath); - } if (fs::exists(rotationFilePath)) { fs::remove(rotationFilePath); } @@ -55,10 +46,8 @@ BOOST_FIXTURE_TEST_SUITE( InstanceMonitorSuite, InstanceMonitorTestFixture ) BOOST_AUTO_TEST_CASE( test_initRotationParams ) { uint64_t ts = 100; - bool isExit = false; BOOST_REQUIRE( !fs::exists( instanceMonitor.getRotationFilePath() ) ); - instanceMonitor.initRotationParams(ts, isExit); - BOOST_CHECK_EQUAL(instanceMonitor.getIsExit(), isExit); + instanceMonitor.initRotationParams(ts); BOOST_CHECK_EQUAL(instanceMonitor.getFinishTimestamp(), ts); BOOST_REQUIRE( fs::exists( instanceMonitor.getRotationFilePath() ) ); @@ -66,7 +55,6 @@ BOOST_AUTO_TEST_CASE( test_initRotationParams ) { std::ifstream rotateFile( instanceMonitor.getRotationFilePath().string() ); auto rotateJson = nlohmann::json::parse( rotateFile ); - BOOST_CHECK_EQUAL(rotateJson["isExit"].get< bool >(), isExit); BOOST_CHECK_EQUAL(rotateJson["timestamp"].get< uint64_t >(), ts); } @@ -74,7 +62,7 @@ BOOST_AUTO_TEST_CASE( test_isTimeToRotate_false ) { uint64_t currentTime = 100; uint64_t finishTime = 200; BOOST_REQUIRE( !instanceMonitor.isTimeToRotate( currentTime ) ); - instanceMonitor.initRotationParams(finishTime, false); + instanceMonitor.initRotationParams(finishTime); BOOST_REQUIRE( !instanceMonitor.isTimeToRotate( currentTime ) ); } @@ -83,36 +71,18 @@ BOOST_AUTO_TEST_CASE( test_isTimeToRotate_true ) { BOOST_REQUIRE( !instanceMonitor.isTimeToRotate( currentTime ) ); - instanceMonitor.initRotationParams(100, false); + instanceMonitor.initRotationParams(100); BOOST_REQUIRE( instanceMonitor.isTimeToRotate( currentTime ) ); - instanceMonitor.initRotationParams(50, false); + instanceMonitor.initRotationParams(50); BOOST_REQUIRE( instanceMonitor.isTimeToRotate( currentTime ) ); } -BOOST_AUTO_TEST_CASE( test_exiting ) { - instanceMonitor.initRotationParams(0, true); - instanceMonitor.performRotation(); - BOOST_REQUIRE( ExitHandler::getSignal() == SIGTERM ); - BOOST_REQUIRE( !( fs::exists( instanceMonitor.getRotationFilePath() ) ) ); -} - -BOOST_AUTO_TEST_CASE( test_restarting ) { - fs::path newConfigPath = configPath; - newConfigPath += ".tmp"; - std::ofstream newConfig; - newConfig.open(newConfigPath.string()); - newConfig << 1; - newConfig.close(); - instanceMonitor.initRotationParams(0, false); +BOOST_AUTO_TEST_CASE( test_rotation ) { + instanceMonitor.initRotationParams(0); instanceMonitor.performRotation(); BOOST_REQUIRE( ExitHandler::getSignal() == SIGTERM ); BOOST_REQUIRE( !( fs::exists( instanceMonitor.getRotationFilePath() ) ) ); - BOOST_REQUIRE( !( fs::exists( newConfigPath) ) ); - std::ifstream config(configPath.string() ); - int val; - config >> val; - BOOST_REQUIRE(val == 1 ); } BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test/unittests/libethereum/SkaleHost.cpp b/test/unittests/libethereum/SkaleHost.cpp index 3304d8b2e..819e78c1e 100644 --- a/test/unittests/libethereum/SkaleHost.cpp +++ b/test/unittests/libethereum/SkaleHost.cpp @@ -102,7 +102,7 @@ struct SkaleHostFixture : public TestOutputHelperFixture { accountHolder->setAccounts( {coinbase, account2} ); gasPricer = make_shared< eth::TrivialGasPricer >( 0, DefaultGasPrice ); - auto monitor = make_shared< InstanceMonitor >( "test" ); + auto monitor = make_shared< InstanceMonitor >(); client = make_unique< Client >( chainParams, chainParams.networkID, gasPricer, nullptr, monitor, tempDir.path() ); this->tq = client->debugGetTransactionQueue(); diff --git a/test/unittests/libskale/HashSnapshot.cpp b/test/unittests/libskale/HashSnapshot.cpp index c4ff74987..b9800a9bd 100644 --- a/test/unittests/libskale/HashSnapshot.cpp +++ b/test/unittests/libskale/HashSnapshot.cpp @@ -307,7 +307,7 @@ struct SnapshotHashingFixture : public TestOutputHelperFixture, public FixtureCo newFileHash << fileHash; - auto monitor = make_shared< InstanceMonitor >("test"); + auto monitor = make_shared< InstanceMonitor >(); client.reset( new eth::ClientTest( chainParams, ( int ) chainParams.networkID, shared_ptr< GasPricer >(), NULL, monitor, boost::filesystem::path( BTRFS_DIR_PATH ), WithExisting::Kill ) ); diff --git a/test/unittests/libweb3jsonrpc/Client.cpp b/test/unittests/libweb3jsonrpc/Client.cpp index 05eb14da5..aa21ade71 100644 --- a/test/unittests/libweb3jsonrpc/Client.cpp +++ b/test/unittests/libweb3jsonrpc/Client.cpp @@ -69,7 +69,7 @@ BOOST_AUTO_TEST_CASE( Personal ) { // dev::WebThreeDirect web3( WebThreeDirect::composeClientVersion( "eth" ), getDataDir(), // string(), // chainParams, WithExisting::Kill, set< string >{"eth"} ); - auto monitor = make_shared< InstanceMonitor >("test"); + auto monitor = make_shared< InstanceMonitor >(); Client client( chainParams, ( int ) chainParams.networkID, shared_ptr< GasPricer >(), NULL, monitor, getDataDir(), WithExisting::Kill, TransactionQueue::Limits{100000, 1024} ); diff --git a/test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp b/test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp index ee991e0cc..c3f3b3b0e 100644 --- a/test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp +++ b/test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp @@ -688,10 +688,10 @@ Json::Value WebThreeStubClient::eth_unsubscribe( const Json::Value& param1 ) { jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString() ); } -Json::Value WebThreeStubClient::eth_setRestartOrExitTime( const Json::Value& param1 ) { +Json::Value WebThreeStubClient::setSchainExitTime( const Json::Value& param1 ) { Json::Value p; p.append( param1 ); - Json::Value result = this->CallMethod( "eth_setRestartOrExitTime", p ); + Json::Value result = this->CallMethod( "setSchainExitTime", p ); if ( result.isObject() ) return result; else diff --git a/test/unittests/libweb3jsonrpc/WebThreeStubClient.h b/test/unittests/libweb3jsonrpc/WebThreeStubClient.h index e91dedafc..c1397ae01 100644 --- a/test/unittests/libweb3jsonrpc/WebThreeStubClient.h +++ b/test/unittests/libweb3jsonrpc/WebThreeStubClient.h @@ -82,7 +82,7 @@ class WebThreeStubClient : public jsonrpc::Client { Json::Value eth_signTransaction( const Json::Value& param1 ) noexcept( false ); Json::Value eth_subscribe( const Json::Value& param1 ) noexcept( false ); Json::Value eth_unsubscribe( const Json::Value& param1 ) noexcept( false ); - Json::Value eth_setRestartOrExitTime( const Json::Value& param1 ) noexcept( false ); + Json::Value setSchainExitTime( const Json::Value& param1 ) noexcept( false ); Json::Value eth_inspectTransaction( const std::string& param1 ) noexcept( false ); std::string eth_sendRawTransaction( const std::string& param1 ) noexcept( false ); bool eth_notePassword( const std::string& param1 ) noexcept( false ); diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index 2eb0653e4..3704156d4 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -210,7 +210,7 @@ struct JsonRpcFixture : public TestOutputHelperFixture { // "eth tests", tempDir.path(), "", chainParams, WithExisting::Kill, {"eth"}, // true ) ); - auto monitor = make_shared< InstanceMonitor >("test"); + auto monitor = make_shared< InstanceMonitor >(); client.reset( new eth::ClientTest( chainParams, ( int ) chainParams.networkID, shared_ptr< GasPricer >(), NULL, monitor, tempDir.path(), WithExisting::Kill ) ); @@ -1666,12 +1666,11 @@ BOOST_AUTO_TEST_CASE( storage_limit_chain ) { BOOST_REQUIRE( fixture.client->state().storageUsedTotal() == 128 ); } -BOOST_AUTO_TEST_CASE( eth_setRestartOrExitTime ){ +BOOST_AUTO_TEST_CASE( setSchainExitTime ){ JsonRpcFixture fixture; Json::Value requestJson; requestJson["finishTime"] = 100; - requestJson["isExit"] = true; - BOOST_REQUIRE_THROW(fixture.rpcClient->eth_setRestartOrExitTime(requestJson), jsonrpc::JsonRpcException); + BOOST_REQUIRE_THROW(fixture.rpcClient->setSchainExitTime(requestJson), jsonrpc::JsonRpcException); } BOOST_FIXTURE_TEST_SUITE( RestrictedAddressSuite, RestrictedAddressFixture ) diff --git a/test/unittests/mapreduce_consensus/ConsensusEngine.cpp b/test/unittests/mapreduce_consensus/ConsensusEngine.cpp index 512b98aa1..1bfa02ba5 100644 --- a/test/unittests/mapreduce_consensus/ConsensusEngine.cpp +++ b/test/unittests/mapreduce_consensus/ConsensusEngine.cpp @@ -215,7 +215,7 @@ class ConsensusExtFaceFixture : public ConsensusExtFace { // web3.reset( new WebThreeDirect( // "eth tests", "", "", chainParams, WithExisting::Kill, {"eth"}, true ) ); - auto monitor = make_shared< InstanceMonitor >("test"); + auto monitor = make_shared< InstanceMonitor >(); client.reset( new eth::Client( chainParams, ( int ) chainParams.networkID, shared_ptr< GasPricer >(), NULL, monitor, "", WithExisting::Kill, TransactionQueue::Limits{100000, 1024} ) );