Skip to content

Commit

Permalink
1702 introduce PrecompiledConfigPatch
Browse files Browse the repository at this point in the history
  • Loading branch information
olehnikolaiev committed Nov 3, 2023
1 parent a348f52 commit 3815c22
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 2 deletions.
1 change: 1 addition & 0 deletions libethcore/ChainOperationParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ struct SChain {
time_t verifyDaSigsPatchTimestamp = 0;
time_t storageDestructionPatchTimestamp = 0;
time_t powCheckPatchTimestamp = 0;
time_t precompiledConfigPatchTimestamp = 0;
time_t pushZeroPatchTimestamp = 0;
time_t skipInvalidTransactionsPatchTimestamp = 0;

Expand Down
5 changes: 5 additions & 0 deletions libethereum/ChainParams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@ ChainParams ChainParams::loadConfig(
sChainObj.at( "powCheckPatchTimestamp" ).get_int64() :
0;

s.precompiledConfigPatchTimestamp =
sChainObj.count( "precompiledConfigPatchTimestamp" ) ?
sChainObj.at( "precompiledConfigPatchTimestamp" ).get_int64() :
0;

s.pushZeroPatchTimestamp = sChainObj.count( "pushZeroPatchTimestamp" ) ?
sChainObj.at( "pushZeroPatchTimestamp" ).get_int64() :
0;
Expand Down
3 changes: 3 additions & 0 deletions libethereum/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include <libskale/ContractStorageLimitPatch.h>
#include <libskale/ContractStorageZeroValuePatch.h>
#include <libskale/POWCheckPatch.h>
#include <libskale/PrecompiledConfigPatch.h>
#include <libskale/PushZeroPatch.h>
#include <libskale/RevertableFSPatch.h>
#include <libskale/SkipInvalidTransactionsPatch.h>
Expand Down Expand Up @@ -167,6 +168,7 @@ Client::Client( ChainParams const& _params, int _networkID,
PushZeroPatch::setTimestamp( chainParams().sChain.pushZeroPatchTimestamp );
SkipInvalidTransactionsPatch::setTimestamp(
this->chainParams().sChain.skipInvalidTransactionsPatchTimestamp );
PrecompiledConfigPatch::setTimestamp( chainParams().sChain.precompiledConfigPatchTimestamp );
}


Expand Down Expand Up @@ -661,6 +663,7 @@ size_t Client::syncTransactions(
POWCheckPatch::lastBlockTimestamp = blockChain().info().timestamp();
PushZeroPatch::lastBlockTimestamp = blockChain().info().timestamp();
SkipInvalidTransactionsPatch::lastBlockTimestamp = blockChain().info().timestamp();
PrecompiledConfigPatch::lastBlockTimestamp = blockChain().info().timestamp();

DEV_WRITE_GUARDED( x_working ) {
assert( !m_working.isSealed() );
Expand Down
5 changes: 3 additions & 2 deletions libethereum/Precompiled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <libethcore/ChainOperationParams.h>
#include <libethcore/Common.h>
#include <libethereum/SkaleHost.h>
#include <libskale/PrecompiledConfigPatch.h>
#include <libskale/State.h>
#include <boost/algorithm/hex.hpp>

Expand Down Expand Up @@ -791,7 +792,7 @@ ETH_REGISTER_PRECOMPILED( getConfigVariableUint256 )( bytesConstRef _in ) {
std::string strValue;
// call to skaleConfig.sChain.nodes means call to the historic data
// need to proccess it in a different way
if ( isCallToHistoricData( rawName ) ) {
if ( isCallToHistoricData( rawName ) && PrecompiledConfigPatch::isEnabled() ) {
if ( !g_skaleHost )
throw std::runtime_error( "SkaleHost accessor was not initialized" );

Check warning on line 797 in libethereum/Precompiled.cpp

View check run for this annotation

Codecov / codecov/patch

libethereum/Precompiled.cpp#L796-L797

Added lines #L796 - L797 were not covered by tests

Expand Down Expand Up @@ -850,7 +851,7 @@ ETH_REGISTER_PRECOMPILED( getConfigVariableAddress )( bytesConstRef _in ) {
std::string strValue;
// call to skaleConfig.sChain.nodes means call to the historic data
// need to proccess it in a different way
if ( isCallToHistoricData( rawName ) ) {
if ( isCallToHistoricData( rawName ) && PrecompiledConfigPatch::isEnabled() ) {
if ( !g_skaleHost )
throw std::runtime_error( "SkaleHost accessor was not initialized" );

Check warning on line 856 in libethereum/Precompiled.cpp

View check run for this annotation

Codecov / codecov/patch

libethereum/Precompiled.cpp#L855-L856

Added lines #L855 - L856 were not covered by tests

Expand Down
2 changes: 2 additions & 0 deletions libskale/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ set(sources
OverlayFS.cpp
StorageDestructionPatch.cpp
POWCheckPatch.cpp
PrecompiledConfigPatch.cpp
PushZeroPatch.cpp
SkipInvalidTransactionsPatch.cpp
)
Expand All @@ -40,6 +41,7 @@ set(headers
AmsterdamFixPatch.h
RevertableFSPatch.h
POWCheckPatch.h
PrecompiledConfigPatch.h
OverlayFS.h
SkipInvalidTransactionsPatch.h
)
Expand Down
11 changes: 11 additions & 0 deletions libskale/PrecompiledConfigPatch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "PrecompiledConfigPatch.h"

time_t PrecompiledConfigPatch::precompiledConfigPatchTimestamp;
time_t PrecompiledConfigPatch::lastBlockTimestamp;

bool PrecompiledConfigPatch::isEnabled() {
if ( precompiledConfigPatchTimestamp == 0 ) {
return false;
}
return precompiledConfigPatchTimestamp <= lastBlockTimestamp;

Check warning on line 10 in libskale/PrecompiledConfigPatch.cpp

View check run for this annotation

Codecov / codecov/patch

libskale/PrecompiledConfigPatch.cpp#L10

Added line #L10 was not covered by tests
}
32 changes: 32 additions & 0 deletions libskale/PrecompiledConfigPatch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#ifndef PRECOMPILEDCONFIGPATCH_H
#define PRECOMPILEDCONFIGPATCH_H

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

namespace dev {
namespace eth {
class Client;
}
} // namespace dev

/*
* Context: enable precompiled contracts to read historical config data
*/
class PrecompiledConfigPatch : public SchainPatch {
public:
static bool isEnabled();

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

private:
friend class dev::eth::Client;
static time_t precompiledConfigPatchTimestamp;
static time_t lastBlockTimestamp;
};


#endif // PRECOMPILEDCONFIGPATCH_H

0 comments on commit 3815c22

Please sign in to comment.