Skip to content

Commit

Permalink
Merge branch 'develop' into SKALED-1674-thread-kill
Browse files Browse the repository at this point in the history
  • Loading branch information
dimalit authored Sep 28, 2023
2 parents 599a8cc + 421c3db commit 3d5f19b
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 12 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ on:
defaults:
run:
shell: bash
jobs:
jobs:
cancel-runs:
name: Cancel Previous Runs
runs-on: ubuntu-latest
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
build:
runs-on: self-hosted
env:
Expand Down
16 changes: 16 additions & 0 deletions libdevcore/LevelDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class LevelDBWriteBatch : public WriteBatchFace {

private:
leveldb::WriteBatch m_writeBatch;
std::atomic< uint64_t > keysToBeDeletedCount;
};

void LevelDBWriteBatch::insert( Slice _key, Slice _value ) {
Expand All @@ -78,6 +79,7 @@ void LevelDBWriteBatch::insert( Slice _key, Slice _value ) {
}

void LevelDBWriteBatch::kill( Slice _key ) {
LevelDB::g_keysToBeDeletedStats++;
m_writeBatch.Delete( toLDBSlice( _key ) );
}

Expand Down Expand Up @@ -168,6 +170,9 @@ void LevelDB::insert( Slice _key, Slice _value ) {
void LevelDB::kill( Slice _key ) {
leveldb::Slice const key( _key.data(), _key.size() );
auto const status = m_db->Delete( m_writeOptions, key );
// At this point the key is not actually deleted. It will be deleted when the batch
// is committed
g_keysToBeDeletedStats++;
checkStatus( status );
}

Expand All @@ -185,6 +190,10 @@ void LevelDB::commit( std::unique_ptr< WriteBatchFace > _batch ) {
DatabaseError() << errinfo_comment( "Invalid batch type passed to LevelDB::commit" ) );
}
auto const status = m_db->Write( m_writeOptions, &batchPtr->writeBatch() );
// Commit happened. This means the keys actually got deleted in LevelDB. Increment key deletes
// stats and set g_keysToBeDeletedStats to zero
g_keyDeletesStats += g_keysToBeDeletedStats;
g_keysToBeDeletedStats = 0;
checkStatus( status );
}

Expand Down Expand Up @@ -275,5 +284,12 @@ void LevelDB::doCompaction() const {
m_db->CompactRange( nullptr, nullptr );
}

std::atomic< uint64_t > LevelDB::g_keysToBeDeletedStats = 0;
std::atomic< uint64_t > LevelDB::g_keyDeletesStats = 0;

uint64_t LevelDB::getKeyDeletesStats() {
return g_keyDeletesStats;
}

} // namespace db
} // namespace dev
7 changes: 7 additions & 0 deletions libdevcore/LevelDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ class LevelDB : public DatabaseFace {

void doCompaction() const;

// Return the total count of key deletes since the start
static uint64_t getKeyDeletesStats();
// count of the keys that were deleted since the start of skaled
static std::atomic< uint64_t > g_keyDeletesStats;
// count of the keys that are scheduled to be deleted but are not yet deleted
static std::atomic< uint64_t > g_keysToBeDeletedStats;

private:
std::unique_ptr< leveldb::DB > m_db;
leveldb::ReadOptions const m_readOptions;
Expand Down
22 changes: 12 additions & 10 deletions libethereum/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include <libdevcore/microprofile.h>

#include <libdevcore/FileSystem.h>
#include <libdevcore/LevelDB.h>
#include <libdevcore/system_usage.h>

#ifdef HISTORIC_STATE
Expand Down Expand Up @@ -152,18 +153,18 @@ Client::Client( ChainParams const& _params, int _networkID,

init( _forceAction, _networkID );

// Set timestamps for patches
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 @@ -924,7 +925,8 @@ void Client::sealUnconditionally( bool submitToBlockChain ) {
<< ":BDS:" << BlockDetails::howMany() << ":TSS:" << TransactionSkeleton::howMany()
<< ":UTX:" << TransactionQueue::UnverifiedTransaction::howMany()
<< ":VTX:" << TransactionQueue::VerifiedTransaction::howMany()
<< ":CMM:" << bc().getTotalCacheMemory();
<< ":CMM:" << bc().getTotalCacheMemory()
<< ":KDS:" << db::LevelDB::getKeyDeletesStats();
if ( number() % 1000 == 0 ) {
ssBlockStats << ":RAM:" << getRAMUsage();
ssBlockStats << ":CPU:" << getCPUUsage();
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 3d5f19b

Please sign in to comment.