diff --git a/libethcore/ChainOperationParams.h b/libethcore/ChainOperationParams.h index 492ffc0a7..279a3948d 100644 --- a/libethcore/ChainOperationParams.h +++ b/libethcore/ChainOperationParams.h @@ -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; diff --git a/libethereum/ChainParams.cpp b/libethereum/ChainParams.cpp index 0f9478c4e..86e0d4139 100644 --- a/libethereum/ChainParams.cpp +++ b/libethereum/ChainParams.cpp @@ -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; diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index bf77b920a..652d54552 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -54,6 +54,7 @@ #include #include #include +#include #include #include #include @@ -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 ); } @@ -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() ); diff --git a/libethereum/Precompiled.cpp b/libethereum/Precompiled.cpp index b0bd2a243..91804542f 100644 --- a/libethereum/Precompiled.cpp +++ b/libethereum/Precompiled.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -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" ); @@ -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" ); diff --git a/libskale/CMakeLists.txt b/libskale/CMakeLists.txt index ba774b211..aec50d6e0 100644 --- a/libskale/CMakeLists.txt +++ b/libskale/CMakeLists.txt @@ -20,6 +20,7 @@ set(sources OverlayFS.cpp StorageDestructionPatch.cpp POWCheckPatch.cpp + PrecompiledConfigPatch.cpp PushZeroPatch.cpp SkipInvalidTransactionsPatch.cpp ) @@ -40,6 +41,7 @@ set(headers AmsterdamFixPatch.h RevertableFSPatch.h POWCheckPatch.h + PrecompiledConfigPatch.h OverlayFS.h SkipInvalidTransactionsPatch.h ) diff --git a/libskale/PrecompiledConfigPatch.cpp b/libskale/PrecompiledConfigPatch.cpp new file mode 100644 index 000000000..f36557d61 --- /dev/null +++ b/libskale/PrecompiledConfigPatch.cpp @@ -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; +} diff --git a/libskale/PrecompiledConfigPatch.h b/libskale/PrecompiledConfigPatch.h new file mode 100644 index 000000000..776dd47cc --- /dev/null +++ b/libskale/PrecompiledConfigPatch.h @@ -0,0 +1,32 @@ +#ifndef PRECOMPILEDCONFIGPATCH_H +#define PRECOMPILEDCONFIGPATCH_H + +#include +#include + +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