From 1710a0aaf374bdc5b98ca0562f4d4451ac977c91 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Tue, 5 Apr 2022 10:03:06 +0300 Subject: [PATCH] SKALE-5059 update uninstall watch --- libethereum/ClientBase.cpp | 4 ++-- libethereum/ClientBase.h | 2 +- libethereum/Interface.h | 2 +- libskale/httpserveroverride.cpp | 7 ++++--- libweb3jsonrpc/Eth.cpp | 8 ++++---- libweb3jsonrpc/Eth.h | 3 ++- libweb3jsonrpc/EthFace.h | 3 ++- 7 files changed, 16 insertions(+), 13 deletions(-) diff --git a/libethereum/ClientBase.cpp b/libethereum/ClientBase.cpp index b1e808816..b36270c4a 100644 --- a/libethereum/ClientBase.cpp +++ b/libethereum/ClientBase.cpp @@ -290,7 +290,7 @@ unsigned ClientBase::installWatch( h256 _h, const std::string& _strOrigin, Reapi return ret; } -bool ClientBase::uninstallWatch( unsigned _i ) { +bool ClientBase::uninstallWatch( unsigned _i, const std::string& _strOrigin ) { LOG( m_loggerWatch ) << "XXX" << _i; Guard l( x_filtersWatches ); @@ -307,7 +307,7 @@ bool ClientBase::uninstallWatch( unsigned _i ) { LOG( m_loggerWatch ) << "*X*" << fit->first << ":" << fit->second.filter; m_filters.erase( fit ); } - m_filtersByIp[""] -= 1; + m_filtersByIp[_strOrigin] -= 1; return true; } diff --git a/libethereum/ClientBase.h b/libethereum/ClientBase.h index 7f44f11e2..bf5fbc347 100644 --- a/libethereum/ClientBase.h +++ b/libethereum/ClientBase.h @@ -115,7 +115,7 @@ class ClientBase : public Interface { Reaping _r = Reaping::Automatic, fnClientWatchHandlerMulti_t fnOnNewChanges = fnClientWatchHandlerMulti_t(), bool isWS = false ) override; - bool uninstallWatch( unsigned _watchId ) override; + bool uninstallWatch( unsigned _watchId, const std::string& strOrigin = "" ) override; LocalisedLogEntries peekWatch( unsigned _watchId ) const override; LocalisedLogEntries checkWatch( unsigned _watchId ) override; diff --git a/libethereum/Interface.h b/libethereum/Interface.h index 428871c13..fed5bd804 100644 --- a/libethereum/Interface.h +++ b/libethereum/Interface.h @@ -132,7 +132,7 @@ class Interface { Reaping _r = Reaping::Automatic, fnClientWatchHandlerMulti_t fnOnNewChanges = fnClientWatchHandlerMulti_t(), bool isWS = false ) = 0; - virtual bool uninstallWatch( unsigned _watchId ) = 0; + virtual bool uninstallWatch( unsigned _watchId, const std::string& strOrigin = "" ) = 0; LocalisedLogEntries peekWatchSafe( unsigned _watchId ) const { try { return peekWatch( _watchId ); diff --git a/libskale/httpserveroverride.cpp b/libskale/httpserveroverride.cpp index a8844a5b0..3a27c3a05 100644 --- a/libskale/httpserveroverride.cpp +++ b/libskale/httpserveroverride.cpp @@ -1097,7 +1097,7 @@ void SkaleWsPeer::uninstallAllWatches() { auto pEthereum = ethereum(); for ( auto iw : sw ) { try { - pEthereum->uninstallWatch( iw ); + pEthereum->uninstallWatch( iw, m_strUnDdosOrigin ); } catch ( ... ) { } } @@ -1352,7 +1352,8 @@ void SkaleWsPeer::eth_subscribe_logs( "eth_subscription/logs" ); stats::register_stats_error( "RPC", "eth_subscription/logs" ); - pThis->ethereum()->uninstallWatch( iw ); + pThis->ethereum()->uninstallWatch( + iw, pThis->m_strUnDdosOrigin ); } // } ); } // for ( const auto& joWalk : joResultLogs ) @@ -1815,7 +1816,7 @@ void SkaleWsPeer::eth_unsubscribe( joResponse["error"] = joError; return; } - ethereum()->uninstallWatch( iw ); + ethereum()->uninstallWatch( iw, m_strUnDdosOrigin ); setInstalledWatchesLogs_.erase( iw ); } } // for ( idxParam = 0; idxParam < cntParams; ++idxParam ) diff --git a/libweb3jsonrpc/Eth.cpp b/libweb3jsonrpc/Eth.cpp index f7c1dfa3a..54205cd26 100644 --- a/libweb3jsonrpc/Eth.cpp +++ b/libweb3jsonrpc/Eth.cpp @@ -64,8 +64,7 @@ bool Eth::isEnabledTransactionSending() const { throw std::runtime_error( "error config.json file, cannot find " "\"skaleConfig\"/\"nodeInfo\"/\"syncNode\"" ); - const nlohmann::json& joSkaleConfig_nodeInfo_syncNode = - joSkaleConfig_nodeInfo["syncNode"]; + const nlohmann::json& joSkaleConfig_nodeInfo_syncNode = joSkaleConfig_nodeInfo["syncNode"]; isEnabled = joSkaleConfig_nodeInfo_syncNode.get< bool >() ? false : true; } catch ( ... ) { } @@ -490,9 +489,10 @@ string Eth::eth_newPendingTransactionFilter( const std::string& strOrigin ) { return toJS( client()->installWatch( filter, strOrigin ) ); } -bool Eth::eth_uninstallFilter( string const& _filterId ) { +bool Eth::eth_uninstallFilter( string const& _filterId, const std::string& _strOrigin ) { try { - return client()->uninstallWatch( static_cast< unsigned int >( jsToInt( _filterId ) ) ); + return client()->uninstallWatch( + static_cast< unsigned int >( jsToInt( _filterId ) ), _strOrigin ); } catch ( ... ) { BOOST_THROW_EXCEPTION( JsonRpcException( Errors::ERROR_RPC_INVALID_PARAMS ) ); } diff --git a/libweb3jsonrpc/Eth.h b/libweb3jsonrpc/Eth.h index b08020f0f..ae97a3c18 100644 --- a/libweb3jsonrpc/Eth.h +++ b/libweb3jsonrpc/Eth.h @@ -118,7 +118,8 @@ class Eth : public dev::rpc::EthFace, public skutils::json_config_file_accessor virtual std::string eth_newBlockFilter( const std::string& strOrigin = "" ) override; virtual std::string eth_newPendingTransactionFilter( const std::string& strOrigin = "" ) override; - virtual bool eth_uninstallFilter( std::string const& _filterId ) override; + virtual bool eth_uninstallFilter( + std::string const& _filterId, const std::string& strOrigin = "" ) override; virtual Json::Value eth_getFilterChanges( std::string const& _filterId ) override; virtual Json::Value eth_getFilterChangesEx( std::string const& _filterId ) override; virtual Json::Value eth_getFilterLogs( std::string const& _filterId ) override; diff --git a/libweb3jsonrpc/EthFace.h b/libweb3jsonrpc/EthFace.h index 80e3acf58..07a093fef 100644 --- a/libweb3jsonrpc/EthFace.h +++ b/libweb3jsonrpc/EthFace.h @@ -469,7 +469,8 @@ class EthFace : public ServerInterface< EthFace > { // virtual std::string eth_newFilterEx( const Json::Value& param1 ) = 0; virtual std::string eth_newBlockFilter( const std::string& strOrigin = "" ) = 0; virtual std::string eth_newPendingTransactionFilter( const std::string& strOrigin = "" ) = 0; - virtual bool eth_uninstallFilter( const std::string& param1 ) = 0; + virtual bool eth_uninstallFilter( + const std::string& param1, const std::string& strOrigin = "" ) = 0; virtual Json::Value eth_getFilterChanges( const std::string& param1 ) = 0; virtual Json::Value eth_getFilterChangesEx( const std::string& param1 ) = 0; virtual Json::Value eth_getFilterLogs( const std::string& param1 ) = 0;