Skip to content

Commit

Permalink
1672 Add stats to selfdestruct. Print patches
Browse files Browse the repository at this point in the history
  • Loading branch information
kladkogex committed Sep 26, 2023
1 parent 98f342d commit ec344c6
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 15 deletions.
4 changes: 3 additions & 1 deletion libethereum/BlockChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1263,7 +1263,8 @@ void BlockChain::garbageCollect( bool _force ) {

m_lastCollection = chrono::system_clock::now();

while ( m_lastStats.memTotal() >= c_maxCacheSize ) {
// We subtract memory that blockhashes occupy because it is treated sepaparately
while ( m_lastStats.memTotal() - m_lastStats.memBlockHashes >= c_maxCacheSize ) {
Guard l( x_cacheUsage );
for ( CacheID const& id : m_cacheUsage.back() ) {
m_inUse.erase( id );
Expand Down Expand Up @@ -1316,6 +1317,7 @@ void BlockChain::garbageCollect( bool _force ) {

{
WriteGuard l( x_blockHashes );
// This is where block hash memory cleanup is treated
// allow only 4096 blockhashes in the cache
if ( m_blockHashes.size() > 4096 ) {
auto last = m_blockHashes.begin();
Expand Down
30 changes: 17 additions & 13 deletions libethereum/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,16 @@ Client::Client( ChainParams const& _params, int _networkID,
init( _forceAction, _networkID );

TotalStorageUsedPatch::g_client = this;
ContractStorageLimitPatch::contractStoragePatchTimestamp =
chainParams().sChain.contractStoragePatchTimestamp;
ContractStorageZeroValuePatch::contractStorageZeroValuePatchTimestamp =
chainParams().sChain.contractStorageZeroValuePatchTimestamp;
VerifyDaSigsPatch::verifyDaSigsPatchTimestamp = chainParams().sChain.verifyDaSigsPatchTimestamp;
RevertableFSPatch::revertableFSPatchTimestamp = chainParams().sChain.revertableFSPatchTimestamp;
StorageDestructionPatch::storageDestructionPatchTimestamp =
chainParams().sChain.storageDestructionPatchTimestamp;
POWCheckPatch::powCheckPatchTimestamp = chainParams().sChain.powCheckPatchTimestamp;
ContractStorageLimitPatch::setTimestamp( chainParams().sChain.contractStoragePatchTimestamp );
ContractStorageZeroValuePatch::setTimestamp(
chainParams().sChain.contractStorageZeroValuePatchTimestamp );
VerifyDaSigsPatch::setTimestamp( chainParams().sChain.verifyDaSigsPatchTimestamp );
RevertableFSPatch::setTimestamp( chainParams().sChain.revertableFSPatchTimestamp );
StorageDestructionPatch::setTimestamp( chainParams().sChain.storageDestructionPatchTimestamp );
POWCheckPatch::setTimestamp( chainParams().sChain.powCheckPatchTimestamp );
}


Client::~Client() {
stopWorking();
}
Expand Down Expand Up @@ -1080,7 +1079,9 @@ Block Client::blockByNumber( BlockNumber _h ) const {

auto readState = m_state.createStateReadOnlyCopy();
readState.mutableHistoricState().setRootByBlockNumber( _h );
DEV_GUARDED( m_blockImportMutex ) { return Block( bc(), hash, readState ); }
DEV_GUARDED( m_blockImportMutex ) {
return Block( bc(), hash, readState );
}
assert( false );
return Block( bc() );
} catch ( Exception& ex ) {
Expand All @@ -1094,7 +1095,9 @@ Block Client::blockByNumber( BlockNumber _h ) const {
Block Client::latestBlock() const {
// TODO Why it returns not-filled block??! (see Block ctor)
try {
DEV_GUARDED( m_blockImportMutex ) { return Block( bc(), bc().currentHash(), m_state ); }
DEV_GUARDED( m_blockImportMutex ) {
return Block( bc(), bc().currentHash(), m_state );
}
assert( false );
return Block( bc() );
} catch ( Exception& ex ) {
Expand Down Expand Up @@ -1242,7 +1245,7 @@ ExecutionResult Client::call( Address const& _from, u256 _value, Address _dest,
t.checkOutExternalGas( ~u256( 0 ) );
if ( _ff == FudgeFactor::Lenient ) {
historicBlock.mutableState().mutableHistoricState().addBalance(
_from, ( u256 )( t.gas() * t.gasPrice() + t.value() ) );
_from, ( u256 ) ( t.gas() * t.gasPrice() + t.value() ) );
}

ret = historicBlock.executeHistoricCall( bc().lastBlockHashes(), t );
Expand All @@ -1266,7 +1269,8 @@ ExecutionResult Client::call( Address const& _from, u256 _value, Address _dest,
t.forceChainId( chainParams().chainID );
t.checkOutExternalGas( ~u256( 0 ) );
if ( _ff == FudgeFactor::Lenient )
temp.mutableState().addBalance( _from, ( u256 )( t.gas() * t.gasPrice() + t.value() ) );
temp.mutableState().addBalance(
_from, ( u256 ) ( t.gas() * t.gasPrice() + t.value() ) );
ret = temp.execute( bc().lastBlockHashes(), t, skale::Permanence::Reverted );
} catch ( InvalidNonce const& in ) {
LOG( m_logger ) << "exception in client call(1):"
Expand Down
13 changes: 12 additions & 1 deletion libethereum/SchainPatch.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
#ifndef SCHAINPATCH_H
#define SCHAINPATCH_H

class SchainPatch {};
#include <libdevcore/Log.h>

class SchainPatch {
public:
static void printInfo( const std::string& _patchName, time_t _timeStamp ) {
if ( _timeStamp == 0 ) {
cnote << "Patch " << _patchName << " is disabled";
} else {
cnote << "Patch " << _patchName << " is set at timestamp " << _timeStamp;
}
}
};

#endif // SCHAINPATCH_H
5 changes: 5 additions & 0 deletions libskale/ContractStorageLimitPatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ class ContractStorageLimitPatch : public SchainPatch {
public:
static bool isEnabled();

static void setTimestamp( time_t _timeStamp ) {
printInfo( __FILE__, _timeStamp );
contractStoragePatchTimestamp = _timeStamp;
}

private:
friend class dev::eth::Client;
static time_t contractStoragePatchTimestamp;
Expand Down
6 changes: 6 additions & 0 deletions libskale/ContractStorageZeroValuePatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ class ContractStorageZeroValuePatch : public SchainPatch {
public:
static bool isEnabled();

static void setTimestamp( time_t _timeStamp ) {
printInfo( __FILE__, _timeStamp );
contractStorageZeroValuePatchTimestamp = _timeStamp;
}


private:
friend class dev::eth::Client;
static time_t contractStorageZeroValuePatchTimestamp;
Expand Down
5 changes: 5 additions & 0 deletions libskale/POWCheckPatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ class POWCheckPatch : public SchainPatch {
public:
static bool isEnabled();

static void setTimestamp( time_t _timeStamp ) {
printInfo( __FILE__, _timeStamp );
powCheckPatchTimestamp = _timeStamp;
}

private:
friend class dev::eth::Client;
static time_t powCheckPatchTimestamp;
Expand Down
5 changes: 5 additions & 0 deletions libskale/RevertableFSPatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ class RevertableFSPatch : public SchainPatch {
public:
static bool isEnabled();

static void setTimestamp( time_t _timeStamp ) {
printInfo( __FILE__, _timeStamp );
revertableFSPatchTimestamp = _timeStamp;
}

private:
friend class dev::eth::Client;
static time_t revertableFSPatchTimestamp;
Expand Down
6 changes: 6 additions & 0 deletions libskale/StorageDestructionPatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ class StorageDestructionPatch : public SchainPatch {
public:
static bool isEnabled();

static void setTimestamp( time_t _timeStamp ) {
printInfo( __FILE__, _timeStamp );
storageDestructionPatchTimestamp = _timeStamp;
}


private:
friend class dev::eth::Client;
static time_t storageDestructionPatchTimestamp;
Expand Down
5 changes: 5 additions & 0 deletions libskale/VerifyDaSigsPatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ class VerifyDaSigsPatch : public SchainPatch {
static time_t verifyDaSigsPatchTimestamp;
static time_t lastBlockTimestamp;

static void setTimestamp( time_t _timeStamp ) {
printInfo( __FILE__, _timeStamp );
verifyDaSigsPatchTimestamp = _timeStamp;
}

public:
static time_t getVerifyDaSigsPatchTimestamp();
};
Expand Down

0 comments on commit ec344c6

Please sign in to comment.