Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug/is 833 selfdestruct rebased #1871

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions libethcore/ChainOperationParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ struct ChainOperationParams {
u256 externalGasDifficulty = ~u256( 0 );
typedef std::vector< std::string > vecAdminOrigins_t;
vecAdminOrigins_t vecAdminOrigins; // wildcard based folters for IP addresses
int64_t maxStorageForSelfdestruct = -1;
int getLogsBlocksLimit = -1;

time_t getPatchTimestamp( SchainPatchEnum _patchEnum ) const;

Expand Down
2 changes: 2 additions & 0 deletions libethcore/Exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,7 @@ DEV_SIMPLE_EXCEPTION( FailedToDownloadDaoForkBlockHeader );
DEV_SIMPLE_EXCEPTION( AccountLocked );
DEV_SIMPLE_EXCEPTION( TransactionRefused );
DEV_SIMPLE_EXCEPTION( UnknownAccount );

DEV_SIMPLE_EXCEPTION( TooBigResponse );
} // namespace eth
} // namespace dev
5 changes: 5 additions & 0 deletions libethereum/ChainParams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ ChainParams ChainParams::loadConfig(
cp.skaleDisableChainIdCheck = params.count( c_skaleDisableChainIdCheck ) ?
params[c_skaleDisableChainIdCheck].get_bool() :
false;
cp.maxStorageForSelfdestruct = params.count( "maxStorageForSelfdestruct" ) ?
params.at( "maxStorageForSelfdestruct" ).get_int64() :
-1;
cp.getLogsBlocksLimit =
params.count( "getLogsBlocksLimit" ) ? params.at( "getLogsBlocksLimit" ).get_int() : -1;

if ( obj.count( c_skaleConfig ) ) {
processSkaleConfigItems( cp, obj );
Expand Down
21 changes: 7 additions & 14 deletions libethereum/ClientBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ LocalisedLogEntries ClientBase::logs( LogFilter const& _f ) const {
unsigned begin = min( bc().number() + 1, ( unsigned ) _f.latest() );
unsigned end = min( bc().number(), min( begin, ( unsigned ) _f.earliest() ) );

if ( begin >= end && begin - end > bc().chainParams().getLogsBlocksLimit )
BOOST_THROW_EXCEPTION( TooBigResponse() );

// Handle pending transactions differently as they're not on the block chain.
if ( begin > bc().number() ) {
Block temp = postSeal();
Expand All @@ -239,13 +242,15 @@ LocalisedLogEntries ClientBase::logs( LogFilter const& _f ) const {
std::vector< unsigned > matchingBlocksVector = bc().withBlockBloom( i, end, begin );
matchingBlocks.insert( matchingBlocksVector.begin(), matchingBlocksVector.end() );
}
else
else {
// if it is a range filter, we want to get all logs from all blocks in given range
for ( unsigned i = end; i <= begin; i++ )
matchingBlocks.insert( i );
}

for ( auto n : matchingBlocks )
for ( auto n : matchingBlocks ) {
prependLogsFromBlock( _f, bc().numberHash( n ), BlockPolarity::Live, ret );
}

reverse( ret.begin(), ret.end() );
return ret;
Expand Down Expand Up @@ -350,18 +355,6 @@ bool ClientBase::uninstallWatch( unsigned _i ) {
return true;
}

LocalisedLogEntries ClientBase::peekWatch( unsigned _watchId ) const {
Guard l( x_filtersWatches );

// LOG(m_loggerWatch) << "peekWatch" << _watchId;
auto& w = m_watches.at( _watchId );
// LOG(m_loggerWatch) << "lastPoll updated to " <<
// chrono::duration_cast<chrono::seconds>(chrono::system_clock::now().time_since_epoch()).count();
if ( w.lastPoll != chrono::system_clock::time_point::max() )
w.lastPoll = chrono::system_clock::now();
return w.get_changes();
}

LocalisedLogEntries ClientBase::checkWatch( unsigned _watchId ) {
Guard l( x_filtersWatches );
LocalisedLogEntries ret;
Expand Down
1 change: 0 additions & 1 deletion libethereum/ClientBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ class ClientBase : public Interface {
fnClientWatchHandlerMulti_t fnOnNewChanges = fnClientWatchHandlerMulti_t(),
bool isWS = false ) override;
bool uninstallWatch( unsigned _watchId ) override;
LocalisedLogEntries peekWatch( unsigned _watchId ) const override;
LocalisedLogEntries checkWatch( unsigned _watchId ) override;

using Interface::blockDetails;
Expand Down
9 changes: 8 additions & 1 deletion libethereum/ExtVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#include "ExtVM.h"

#include <exception>
#include <libethereum/SchainPatch.h>

#include <boost/thread.hpp>

Expand Down Expand Up @@ -170,6 +170,13 @@ CreateResult ExtVM::create( u256 _endowment, u256& io_gas, bytesConstRef _code,
}

void ExtVM::suicide( Address _a ) {
if ( SelfdestructStorageLimitPatch::isEnabledWhen(
this->envInfo().committedBlockTimestamp() ) &&
m_chainParams.maxStorageForSelfdestruct >= 0 &&
m_s.storageUsed( this->myAddress ) > m_chainParams.maxStorageForSelfdestruct ) {
BOOST_THROW_EXCEPTION( TooBigForSelfdestruct() );
}

// Why transfer is not used here? That caused a consensus issue before (see Quirk #2 in
// http://martin.swende.se/blog/Ethereum_quirks_and_vulns.html). There is one test case
// witnessing the current consensus
Expand Down
9 changes: 0 additions & 9 deletions libethereum/Interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,21 +154,13 @@ class Interface {
fnClientWatchHandlerMulti_t fnOnNewChanges = fnClientWatchHandlerMulti_t(),
bool isWS = false ) = 0;
virtual bool uninstallWatch( unsigned _watchId ) = 0;
LocalisedLogEntries peekWatchSafe( unsigned _watchId ) const {
try {
return peekWatch( _watchId );
} catch ( ... ) {
return LocalisedLogEntries();
}
}
LocalisedLogEntries checkWatchSafe( unsigned _watchId ) {
try {
return checkWatch( _watchId );
} catch ( ... ) {
return LocalisedLogEntries();
}
}
virtual LocalisedLogEntries peekWatch( unsigned _watchId ) const = 0;
virtual LocalisedLogEntries checkWatch( unsigned _watchId ) = 0;

// [BLOCK QUERY API]
Expand Down Expand Up @@ -328,7 +320,6 @@ class Watch : public boost::noncopyable {
}

LocalisedLogEntries check() { return m_c ? m_c->checkWatch( m_id ) : LocalisedLogEntries(); }
LocalisedLogEntries peek() { return m_c ? m_c->peekWatch( m_id ) : LocalisedLogEntries(); }
LocalisedLogEntries logs() const { return m_c->logs( m_id ); }

private:
Expand Down
1 change: 1 addition & 0 deletions libevm/VMFace.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ ETH_SIMPLE_EXCEPTION_VM( DisallowedStateChange );
ETH_SIMPLE_EXCEPTION_VM( BufferOverrun );
ETH_SIMPLE_EXCEPTION_VM( StorageOverflow );
ETH_SIMPLE_EXCEPTION_VM( InvalidContractDeployer );
ETH_SIMPLE_EXCEPTION_VM( TooBigForSelfdestruct );

/// Reports VM internal error. This is not based on VMException because it must be handled
/// differently than defined consensus exceptions.
Expand Down
8 changes: 8 additions & 0 deletions libweb3jsonrpc/Eth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,10 @@ Json::Value Eth::eth_getFilterChangesEx( string const& _filterId ) {
Json::Value Eth::eth_getFilterLogs( string const& _filterId ) {
try {
return toJson( client()->logs( static_cast< unsigned int >( jsToInt( _filterId ) ) ) );
} catch ( const TooBigResponse& ) {
BOOST_THROW_EXCEPTION( JsonRpcException( Errors::ERROR_RPC_INVALID_PARAMS,
"Log response size exceeded. Maximum allowed number of requested blocks is " +
to_string( this->client()->chainParams().getLogsBlocksLimit ) ) );
} catch ( ... ) {
BOOST_THROW_EXCEPTION( JsonRpcException( Errors::ERROR_RPC_INVALID_PARAMS ) );
}
Expand All @@ -837,6 +841,10 @@ Json::Value Eth::eth_getFilterLogs( string const& _filterId ) {
Json::Value Eth::eth_getLogs( Json::Value const& _json ) {
try {
return toJson( client()->logs( toLogFilter( _json ) ) );
} catch ( const TooBigResponse& ) {
BOOST_THROW_EXCEPTION( JsonRpcException( Errors::ERROR_RPC_INVALID_PARAMS,
"Log response size exceeded. Maximum allowed number of requested blocks is " +
to_string( this->client()->chainParams().getLogsBlocksLimit ) ) );
} catch ( ... ) {
BOOST_THROW_EXCEPTION( JsonRpcException( Errors::ERROR_RPC_INVALID_PARAMS ) );
}
Expand Down
Loading
Loading