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 all 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
1 change: 1 addition & 0 deletions libethcore/ChainOperationParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,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
14 changes: 11 additions & 3 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,9 +293,12 @@
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();
u256 sChainIndex = groupNodeConfObj.at( 0 ).get_uint64();
u256 id = groupNodeConfObj.at( 1 ).get_uint64();
std::string publicKey = groupNodeConfObj.at( 2 ).get_str();
if ( publicKey.empty() ) {
BOOST_THROW_EXCEPTION( std::runtime_error( "Empty public key in config" ) );

Check warning on line 300 in libethereum/ChainParams.cpp

View check run for this annotation

Codecov / codecov/patch

libethereum/ChainParams.cpp#L300

Added line #L300 was not covered by tests
}
groupNodes.push_back( { id, sChainIndex, publicKey } );
}
std::sort( groupNodes.begin(), groupNodes.end(),
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.at( 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
27 changes: 23 additions & 4 deletions libethereum/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,25 @@ class Client : public ClientBase, protected Worker {
}

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

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

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

// get node owner for historic node in chain
std::string getHistoricNodePublicKey( unsigned _idx ) const {
return chainParams().sChain.nodeGroups.at( historicGroupIndex ).nodes.at( _idx ).publicKey;
}

void doStateDbCompaction() const { m_state.getOriginalDb()->doCompaction(); }
Expand Down Expand Up @@ -532,10 +550,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
Loading
Loading