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/1702 adopt precompiled oracle #1713

Merged
merged 35 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
685fd91
1702 add owner field to nodes in chain params
olehnikolaiev Oct 20, 2023
a733b76
1702 use historicGroupIndex
olehnikolaiev Oct 24, 2023
b7cd5a5
1702 update precompiled to work with oracle
olehnikolaiev Oct 24, 2023
295b850
1702 improve tests
olehnikolaiev Oct 30, 2023
786882f
1702 improve tests
olehnikolaiev Oct 31, 2023
e9b63e9
1702 remove unnecessary changes
olehnikolaiev Oct 31, 2023
4f22ffb
Merge branch 'v3.18.0' into bug/1702-adopt-precompiled-oracle
olehnikolaiev Oct 31, 2023
a348f52
1702 fix tests
olehnikolaiev Nov 1, 2023
3815c22
1702 introduce PrecompiledConfigPatch
olehnikolaiev Nov 3, 2023
ee9c48a
#1702 renamed owner to nodeAddress
kladkogex Nov 6, 2023
aa4c0d8
#1702 changed [] to at() for safe vector access
kladkogex Nov 6, 2023
95215c7
#1702 added param validation
kladkogex Nov 6, 2023
4d55443
#1702 added a log record if node info is empty in config
kladkogex Nov 6, 2023
7f136c5
#1702 changed assertion to runtime error
kladkogex Nov 6, 2023
ea28913
#1702 changed assertion to runtime error
kladkogex Nov 6, 2023
3652a82
#1702 changed to standard boost library
kladkogex Nov 6, 2023
41ddce9
1702 fix build
olehnikolaiev Nov 6, 2023
399e9b1
1702 deny access to some config fields from precompileds for security…
olehnikolaiev Nov 6, 2023
cfbd435
1702 fix tests
olehnikolaiev Nov 7, 2023
80618dd
#1702 improve code quality
olehnikolaiev Nov 7, 2023
582b526
#1702 use common approach to access config variables
olehnikolaiev Nov 8, 2023
ea694fc
#1702 improve code quality
olehnikolaiev Nov 8, 2023
ca16ebf
#1702 improve input proccessing for precompileds
olehnikolaiev Nov 13, 2023
4995613
#1702 add more checks
olehnikolaiev Nov 13, 2023
edd62d4
#1702 improve tests
olehnikolaiev Nov 13, 2023
aaab497
Merge branch 'v3.18.0' into bug/1702-adopt-precompiled-oracle
olehnikolaiev Nov 21, 2023
3b122e5
Merge branch 'v3.18.0' into bug/1702-adopt-precompiled-oracle
olehnikolaiev Nov 21, 2023
4b51081
#1702 pass historic publicKey instead of address
olehnikolaiev Nov 22, 2023
e411718
Merge branch 'bug/1702-adopt-precompiled-oracle' of github.com:skalen…
olehnikolaiev Nov 22, 2023
a504090
#1702 fix tests
olehnikolaiev Nov 22, 2023
1a67380
#1702 add more tests
olehnikolaiev Nov 22, 2023
7700738
#1702 change [] to at()
olehnikolaiev Nov 22, 2023
c8921f6
#1702 change [] to at()
olehnikolaiev Nov 22, 2023
23a5437
#1702 change [] to at()
olehnikolaiev Nov 22, 2023
d301345
Merge branch 'v3.18.0' into bug/1702-adopt-precompiled-oracle
olehnikolaiev Nov 23, 2023
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 @@ -140,6 +140,7 @@ struct GroupNode {
u256 id;
u256 schainIndex;
std::string publicKey;
std::string address;
};

/// skale
Expand Down Expand Up @@ -175,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
20 changes: 16 additions & 4 deletions libethereum/ChainParams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@
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 All @@ -288,10 +293,17 @@
auto groupNodesObj = nodeGroupObj["nodes"].get_obj();
for ( const auto& groupNodeConf : groupNodesObj ) {
auto groupNodeConfObj = groupNodeConf.second.get_array();
u256 sChainIndex = groupNodeConfObj[0].get_uint64();
u256 id = groupNodeConfObj[1].get_uint64();
std::string publicKey = groupNodeConfObj[2].get_str();
groupNodes.push_back( { id, sChainIndex, publicKey } );
u256 sChainIndex = groupNodeConfObj.at( 0 ).get_uint64();
u256 id = groupNodeConfObj.at( 1 ).get_uint64();
std::string publicKey = groupNodeConfObj.at( 2 ).get_str();
std::string address = groupNodeConfObj.at( 3 ).get_str();
if ( publicKey.empty() ) {
BOOST_THROW_EXCEPTION( std::runtime_error( "Empty public key in config" ) );

Check warning on line 301 in libethereum/ChainParams.cpp

View check run for this annotation

Codecov / codecov/patch

libethereum/ChainParams.cpp#L301

Added line #L301 was not covered by tests
}
if ( address.empty() ) {
BOOST_THROW_EXCEPTION( std::runtime_error( "Empty address in config" ) );

Check warning on line 304 in libethereum/ChainParams.cpp

View check run for this annotation

Codecov / codecov/patch

libethereum/ChainParams.cpp#L304

Added line #L304 was not covered by tests
}
groupNodes.push_back( { id, sChainIndex, publicKey, address } );
}
std::sort( groupNodes.begin(), groupNodes.end(),
[]( const GroupNode& lhs, const GroupNode& rhs ) {
Expand Down
36 changes: 25 additions & 11 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 @@
PushZeroPatch::setTimestamp( chainParams().sChain.pushZeroPatchTimestamp );
SkipInvalidTransactionsPatch::setTimestamp(
this->chainParams().sChain.skipInvalidTransactionsPatchTimestamp );
PrecompiledConfigPatch::setTimestamp( chainParams().sChain.precompiledConfigPatchTimestamp );
}


Expand Down Expand Up @@ -313,8 +315,12 @@
if ( m_dbPath.size() )
Defaults::setDBPath( m_dbPath );

if ( ChainParams().sChain.nodeGroups.size() > 0 )
initIMABLSPublicKey();
if ( chainParams().sChain.nodeGroups.size() > 0 ) {
initHistoricGroupIndex();
} else {
LOG( m_logger ) << "Empty node groups in config. "
"This is OK in tests but not OK in production";

Check warning on line 322 in libethereum/Client.cpp

View check run for this annotation

Codecov / codecov/patch

libethereum/Client.cpp#L322

Added line #L322 was not covered by tests
}

// init snapshots for not newly created chains
if ( number() ) {
Expand Down Expand Up @@ -621,7 +627,7 @@
}

if ( chainParams().sChain.nodeGroups.size() > 0 )
updateIMABLSPublicKey();
updateHistoricGroupIndex();

m_snapshotAgent->doSnapshotIfNeeded( number(), _timestamp );

Expand Down Expand Up @@ -661,6 +667,7 @@
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 Expand Up @@ -1288,9 +1295,9 @@
return ret;
}

void Client::initIMABLSPublicKey() {
void Client::initHistoricGroupIndex() {
if ( number() == 0 ) {
imaBLSPublicKeyGroupIndex = 0;
historicGroupIndex = 0;
return;
}

Expand All @@ -1302,7 +1309,11 @@
chainParams().sChain.nodeGroups.end(),
[&currentBlockTimestamp](
const dev::eth::NodeGroup& ng ) { return currentBlockTimestamp <= ng.finishTs; } );
assert( it != chainParams().sChain.nodeGroups.end() );

if ( it == chainParams().sChain.nodeGroups.end() ) {
BOOST_THROW_EXCEPTION(

Check warning on line 1314 in libethereum/Client.cpp

View check run for this annotation

Codecov / codecov/patch

libethereum/Client.cpp#L1313-L1314

Added lines #L1313 - L1314 were not covered by tests
std::runtime_error( "Assertion failed: it == chainParams().sChain.nodeGroups.end()" ) );
}

if ( it != chainParams().sChain.nodeGroups.begin() ) {
auto prevIt = std::prev( it );
Expand All @@ -1311,15 +1322,18 @@
it = prevIt;
}

imaBLSPublicKeyGroupIndex = std::distance( chainParams().sChain.nodeGroups.begin(), it );
historicGroupIndex = std::distance( chainParams().sChain.nodeGroups.begin(), it );

Check warning on line 1325 in libethereum/Client.cpp

View check run for this annotation

Codecov / codecov/patch

libethereum/Client.cpp#L1325

Added line #L1325 was not covered by tests
}

void Client::updateIMABLSPublicKey() {
void Client::updateHistoricGroupIndex() {
uint64_t blockTimestamp = blockInfo( hashFromNumber( number() ) ).timestamp();
uint64_t currentFinishTs = chainParams().sChain.nodeGroups[imaBLSPublicKeyGroupIndex].finishTs;
uint64_t currentFinishTs = chainParams().sChain.nodeGroups[historicGroupIndex].finishTs;
if ( blockTimestamp >= currentFinishTs )
++imaBLSPublicKeyGroupIndex;
assert( imaBLSPublicKeyGroupIndex < chainParams().sChain.nodeGroups.size() );
++historicGroupIndex;
if ( historicGroupIndex >= chainParams().sChain.nodeGroups.size() ) {
BOOST_THROW_EXCEPTION( std::runtime_error(

Check warning on line 1334 in libethereum/Client.cpp

View check run for this annotation

Codecov / codecov/patch

libethereum/Client.cpp#L1334

Added line #L1334 was not covered by tests
"Assertion failed: historicGroupIndex >= chainParams().sChain.nodeGroups.size())" ) );
}
}

// new block watch
Expand Down
24 changes: 20 additions & 4 deletions libethereum/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,22 @@ class Client : public ClientBase, protected Worker {
}

std::array< std::string, 4 > getIMABLSPublicKey() const {
return chainParams().sChain.nodeGroups[imaBLSPublicKeyGroupIndex].blsPublicKey;
return chainParams().sChain.nodeGroups[historicGroupIndex].blsPublicKey;
}

// get node id for historic node in chain
std::string getHistoricNodeId( unsigned _id ) const {
return chainParams().sChain.nodeGroups[historicGroupIndex].nodes[_id].id.str();
}

// get schain index for historic node in chain
std::string getHistoricNodeIndex( unsigned _idx ) const {
return chainParams().sChain.nodeGroups[historicGroupIndex].nodes[_idx].schainIndex.str();
}

// get node owner for historic node in chain
std::string getHistoricNodeOwner( unsigned _idx ) const {
return chainParams().sChain.nodeGroups[historicGroupIndex].nodes[_idx].address;
}

void doStateDbCompaction() const { m_state.getOriginalDb()->doCompaction(); }
Expand Down Expand Up @@ -532,10 +547,11 @@ class Client : public ClientBase, protected Worker {
fs::path m_dbPath;

private:
void initIMABLSPublicKey();
void updateIMABLSPublicKey();
void initHistoricGroupIndex();
void updateHistoricGroupIndex();

unsigned imaBLSPublicKeyGroupIndex = 0;
// which group corresponds to the current block timestamp on this node
unsigned historicGroupIndex = 0;

public:
FILE* performance_fd;
Expand Down
152 changes: 116 additions & 36 deletions libethereum/Precompiled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <cryptopp/files.h>
#include <cryptopp/hex.h>
#include <cryptopp/sha.h>
#include <libdevcore/CommonJS.h>
#include <libdevcore/FileSystem.h>
#include <libdevcore/Log.h>
#include <libdevcore/SHA3.h>
Expand All @@ -36,8 +37,11 @@
#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>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/predicate.hpp>

#include <mutex>

Expand Down Expand Up @@ -673,25 +677,7 @@
return { false, response }; // 1st false - means bad error occur
}

static const std::list< std::string > g_listReadableConfigParts{ "sealEngine",
//"genesis.*"
//"params.*",

"skaleConfig.nodeInfo.wallets.ima.commonBLSPublicKey*",
"skaleConfig.nodeInfo.wallets.ima.BLSPublicKey*",

"skaleConfig.nodeInfo.nodeName", "skaleConfig.nodeInfo.nodeID",
"skaleConfig.nodeInfo.basePort*", "skaleConfig.nodeInfo.*RpcPort*",
"skaleConfig.nodeInfo.acceptors", "skaleConfig.nodeInfo.max-connections",
"skaleConfig.nodeInfo.max-http-queues", "skaleConfig.nodeInfo.ws-mode",

"skaleConfig.contractSettings.*",

"skaleConfig.sChain.emptyBlockIntervalMs",

"skaleConfig.sChain.schainName", "skaleConfig.sChain.schainID",

"skaleConfig.sChain.nodes.*" };
static const std::list< std::string > g_listReadableConfigParts{ "skaleConfig.sChain.nodes." };

static bool stat_is_accessible_json_path( const std::string& strPath ) {
if ( strPath.empty() )
Expand All @@ -700,7 +686,7 @@
itEnd = g_listReadableConfigParts.cend();
for ( ; itWalk != itEnd; ++itWalk ) {
const std::string strWildCard = ( *itWalk );
if ( skutils::tools::wildcmp( strWildCard.c_str(), strPath.c_str() ) )
if ( boost::algorithm::starts_with( strPath, strWildCard ) )

Check warning on line 689 in libethereum/Precompiled.cpp

View check run for this annotation

Codecov / codecov/patch

libethereum/Precompiled.cpp#L689

Added line #L689 was not covered by tests
return true;
}
return false;
Expand Down Expand Up @@ -756,6 +742,48 @@
return uValue;
}

static bool isCallToHistoricData( const std::string& callData ) {

Check warning on line 745 in libethereum/Precompiled.cpp

View check run for this annotation

Codecov / codecov/patch

libethereum/Precompiled.cpp#L745

Added line #L745 was not covered by tests
// in C++ 20 there is string::starts_with, but we do not use C++ 20 yet
return boost::algorithm::starts_with( callData, "skaleConfig.sChain.nodes." );

Check warning on line 747 in libethereum/Precompiled.cpp

View check run for this annotation

Codecov / codecov/patch

libethereum/Precompiled.cpp#L747

Added line #L747 was not covered by tests
}

static std::pair< std::string, unsigned > parseHistoricFieldRequest( std::string callData ) {
std::vector< std::string > splitted;
boost::split( splitted, callData, boost::is_any_of( "." ) );

Check warning on line 752 in libethereum/Precompiled.cpp

View check run for this annotation

Codecov / codecov/patch

libethereum/Precompiled.cpp#L750-L752

Added lines #L750 - L752 were not covered by tests
// first 3 elements are skaleConfig, sChain, nodes - it was checked before
unsigned id = std::stoul( splitted.at( 3 ) );
std::string fieldName;
boost::trim_if( splitted.at( 4 ), []( char c ) { return c == '\0'; } );
std::set< std::string > allowedValues{ "id", "schainIndex", "owner" };
fieldName = splitted.at( 4 );
if ( allowedValues.count( fieldName ) ) {
return { fieldName, id };

Check warning on line 760 in libethereum/Precompiled.cpp

View check run for this annotation

Codecov / codecov/patch

libethereum/Precompiled.cpp#L754-L760

Added lines #L754 - L760 were not covered by tests
} else {
BOOST_THROW_EXCEPTION( std::runtime_error( "Unknown field:" + fieldName ) );

Check warning on line 762 in libethereum/Precompiled.cpp

View check run for this annotation

Codecov / codecov/patch

libethereum/Precompiled.cpp#L762

Added line #L762 was not covered by tests
}
return { fieldName, id };
}

/*
* this precompiled contract is designed to get access to specific integer config values
* and works as key / values map
* input: bytes - length + path to config variable
* output: bytes - config variable value
*
* variables available through this precompiled contract:
* 1. id - node id for INDEX node in schain group for current block number
* 2. schainIndex - schain index for INDEX node in schain group for current block number
* to access those variables one should use the following scheme:
* prefix=skaleConfig.sChain.nodes - to access corresponding structure inside skaled
* index - node index user wants to get access to
* field - the field user wants to request
*
* example:
* to request the value for 1-st node (1 based) for the node id field the input should be
* input=skaleConfig.sChain.nodes.0.id (inside skaled node indexes are 0 based)
* so one should pass the following as calldata:
* toBytes( ( ( input.length + 1 ) / 32 ) * 32) + toBytes(input)
*/
ETH_REGISTER_PRECOMPILED( getConfigVariableUint256 )( bytesConstRef _in ) {
try {
size_t lengthName;
Expand All @@ -767,18 +795,33 @@

if ( !g_configAccesssor )
throw std::runtime_error( "Config accessor was not initialized" );
nlohmann::json joConfig = g_configAccesssor->getConfigJSON();
nlohmann::json joValue =
skutils::json_config_file_accessor::stat_extract_at_path( joConfig, rawName );
std::string strValue = skutils::tools::trim_copy(
joValue.is_string() ? joValue.get< std::string >() : joValue.dump() );

// dev::u256 uValue( strValue.c_str() );
dev::u256 uValue = stat_parse_u256_hex_or_dec( strValue );
// std::cout << "------------ Loaded config var \""
// << rawName << "\" value is " << uValue
// << "\n";
std::string strValue;

Check warning on line 799 in libethereum/Precompiled.cpp

View check run for this annotation

Codecov / codecov/patch

libethereum/Precompiled.cpp#L799

Added line #L799 was not covered by tests
// call to skaleConfig.sChain.nodes means call to the historic data
// need to proccess it in a different way
if ( isCallToHistoricData( rawName ) && PrecompiledConfigPatch::isEnabled() ) {
if ( !g_skaleHost )
throw std::runtime_error( "SkaleHost accessor was not initialized" );

Check warning on line 804 in libethereum/Precompiled.cpp

View check run for this annotation

Codecov / codecov/patch

libethereum/Precompiled.cpp#L802-L804

Added lines #L802 - L804 were not covered by tests

std::string field;

Check warning on line 806 in libethereum/Precompiled.cpp

View check run for this annotation

Codecov / codecov/patch

libethereum/Precompiled.cpp#L806

Added line #L806 was not covered by tests
unsigned id;
std::tie( field, id ) = parseHistoricFieldRequest( rawName );
if ( field == "id" ) {
strValue = g_skaleHost->getHistoricNodeId( id );
} else if ( field == "schainIndex" ) {
strValue = g_skaleHost->getHistoricNodeIndex( id );

Check warning on line 812 in libethereum/Precompiled.cpp

View check run for this annotation

Codecov / codecov/patch

libethereum/Precompiled.cpp#L808-L812

Added lines #L808 - L812 were not covered by tests
} else {
throw std::runtime_error( "Incorrect config field" );

Check warning on line 814 in libethereum/Precompiled.cpp

View check run for this annotation

Codecov / codecov/patch

libethereum/Precompiled.cpp#L814

Added line #L814 was not covered by tests
}
} else {
nlohmann::json joConfig = g_configAccesssor->getConfigJSON();

Check warning on line 817 in libethereum/Precompiled.cpp

View check run for this annotation

Codecov / codecov/patch

libethereum/Precompiled.cpp#L817

Added line #L817 was not covered by tests
nlohmann::json joValue =
skutils::json_config_file_accessor::stat_extract_at_path( joConfig, rawName );
strValue = skutils::tools::trim_copy(
joValue.is_string() ? joValue.get< std::string >() : joValue.dump() );

Check warning on line 821 in libethereum/Precompiled.cpp

View check run for this annotation

Codecov / codecov/patch

libethereum/Precompiled.cpp#L819-L821

Added lines #L819 - L821 were not covered by tests
}
Comment on lines +826 to +832
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change so that the else {} part is only used when the patch is enabled, since stat_extract_at_path is unsecure and complex. If it is needed, it needs to be rewritten in a clean and secure
way using standard C++ and boost libraries


dev::u256 uValue = jsToInt( strValue );

Check warning on line 824 in libethereum/Precompiled.cpp

View check run for this annotation

Codecov / codecov/patch

libethereum/Precompiled.cpp#L824

Added line #L824 was not covered by tests
bytes response = toBigEndian( uValue );
return { true, response };
} catch ( std::exception& ex ) {
Expand All @@ -796,6 +839,25 @@
return { false, response }; // 1st false - means bad error occur
}

/*
* this precompiled contract is designed to get access to specific config values that are ETH
* addresses and works as key / values map input: bytes - length + path to config variable output:
* bytes - config variable value
*
* variables available through this precompiled contract:
* 1. owner - address for INDEX node in schain group for current block number
* to access those variables one should use the following scheme:
* prefix=skaleConfig.sChain.nodes - to access corresponding structure inside skaled
* index - node index user wants to get access to
* field - the field user wants to request
*
* example:
* to request the value for 2-nd node (1 based) for the owner field the input should be
* input=skaleConfig.sChain.nodes.1.owner (inside skaled node indexes are 0 based)
* so one should pass the following as calldata
* toBytes( ( ( input.length + 1 ) / 32 ) * 32) + toBytes(input)
*
*/
ETH_REGISTER_PRECOMPILED( getConfigVariableAddress )( bytesConstRef _in ) {
try {
size_t lengthName;
Expand All @@ -807,13 +869,31 @@

if ( !g_configAccesssor )
throw std::runtime_error( "Config accessor was not initialized" );
nlohmann::json joConfig = g_configAccesssor->getConfigJSON();
nlohmann::json joValue =
skutils::json_config_file_accessor::stat_extract_at_path( joConfig, rawName );
std::string strValue = skutils::tools::trim_copy(
joValue.is_string() ? joValue.get< std::string >() : joValue.dump() );
dev::u256 uValue( strValue.c_str() );

std::string strValue;

Check warning on line 873 in libethereum/Precompiled.cpp

View check run for this annotation

Codecov / codecov/patch

libethereum/Precompiled.cpp#L873

Added line #L873 was not covered by tests
// call to skaleConfig.sChain.nodes means call to the historic data
// need to proccess it in a different way
if ( isCallToHistoricData( rawName ) && PrecompiledConfigPatch::isEnabled() ) {
if ( !g_skaleHost )
throw std::runtime_error( "SkaleHost accessor was not initialized" );

Check warning on line 878 in libethereum/Precompiled.cpp

View check run for this annotation

Codecov / codecov/patch

libethereum/Precompiled.cpp#L876-L878

Added lines #L876 - L878 were not covered by tests

std::string field;

Check warning on line 880 in libethereum/Precompiled.cpp

View check run for this annotation

Codecov / codecov/patch

libethereum/Precompiled.cpp#L880

Added line #L880 was not covered by tests
unsigned id;
std::tie( field, id ) = parseHistoricFieldRequest( rawName );
if ( field == "owner" ) {
strValue = g_skaleHost->getHistoricNodeOwner( id );

Check warning on line 884 in libethereum/Precompiled.cpp

View check run for this annotation

Codecov / codecov/patch

libethereum/Precompiled.cpp#L882-L884

Added lines #L882 - L884 were not covered by tests
} else {
throw std::runtime_error( "Incorrect config field" );

Check warning on line 886 in libethereum/Precompiled.cpp

View check run for this annotation

Codecov / codecov/patch

libethereum/Precompiled.cpp#L886

Added line #L886 was not covered by tests
}
} else {
nlohmann::json joConfig = g_configAccesssor->getConfigJSON();

Check warning on line 889 in libethereum/Precompiled.cpp

View check run for this annotation

Codecov / codecov/patch

libethereum/Precompiled.cpp#L889

Added line #L889 was not covered by tests
nlohmann::json joValue =
skutils::json_config_file_accessor::stat_extract_at_path( joConfig, rawName );
strValue = skutils::tools::trim_copy(
joValue.is_string() ? joValue.get< std::string >() : joValue.dump() );

Check warning on line 893 in libethereum/Precompiled.cpp

View check run for this annotation

Codecov / codecov/patch

libethereum/Precompiled.cpp#L891-L893

Added lines #L891 - L893 were not covered by tests
}

dev::u256 uValue( strValue );

Check warning on line 896 in libethereum/Precompiled.cpp

View check run for this annotation

Codecov / codecov/patch

libethereum/Precompiled.cpp#L896

Added line #L896 was not covered by tests
bytes response = toBigEndian( uValue );
return { true, response };
} catch ( std::exception& ex ) {
Expand Down
Loading
Loading