Skip to content

Commit

Permalink
IS 864 add new config variable
Browse files Browse the repository at this point in the history
  • Loading branch information
olehnikolaiev committed May 15, 2024
1 parent d678d09 commit 538f60b
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 35 deletions.
5 changes: 4 additions & 1 deletion libethcore/ChainOperationParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ struct NodeInfo {
bool syncNode;
bool archiveMode;
bool syncFromCatchup;
bool testSignatures;

NodeInfo( std::string _name = "TestNode", u256 _id = 1, std::string _ip = "127.0.0.11",
uint16_t _port = 11111, std::string _ip6 = "::1", uint16_t _port6 = 11111,
Expand All @@ -107,7 +108,8 @@ struct NodeInfo {
"11559732032986387107991004021392285783925812861821192530917403151452391805634",
"8495653923123431417604973247489272438418190587263600148770280649306958101930",
"4082367875863433681332203403145435568316851327593401208105741076214120093531" },
bool _syncNode = false, bool _archiveMode = false, bool _syncFromCatchup = false ) {
bool _syncNode = false, bool _archiveMode = false, bool _syncFromCatchup = false,
bool _testSignatures = true ) {
name = _name;
id = _id;
ip = _ip;
Expand All @@ -122,6 +124,7 @@ struct NodeInfo {
syncNode = _syncNode;
archiveMode = _archiveMode;
syncFromCatchup = _syncFromCatchup;
testSignatures = _testSignatures;
}
};

Expand Down
15 changes: 6 additions & 9 deletions libethereum/ChainParams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,18 @@ void ChainParams::processSkaleConfigItems( ChainParams& cp, json_spirit::mObject
if ( cp.rotateAfterBlock_ < 0 )
cp.rotateAfterBlock_ = 0;

string ecdsaKeyName;
bool testSignatures = false;
try {
ecdsaKeyName = infoObj.at( "ecdsaKeyName" ).get_str();
testSignatures = infoObj.at( "testSignatures" ).get_bool();
} catch ( ... ) {
}

string ecdsaKeyName;
array< string, 4 > BLSPublicKeys;
array< string, 4 > commonBLSPublicKeys;
if ( !testSignatures ) {
ecdsaKeyName = infoObj.at( "ecdsaKeyName" ).get_str();

try {
js::mObject ima = infoObj.at( "wallets" ).get_obj().at( "ima" ).get_obj();

commonBLSPublicKeys[0] = ima["commonBLSPublicKey0"].get_str();
Expand All @@ -244,16 +246,11 @@ void ChainParams::processSkaleConfigItems( ChainParams& cp, json_spirit::mObject
BLSPublicKeys[2] = ima["BLSPublicKey2"].get_str();
BLSPublicKeys[3] = ima["BLSPublicKey3"].get_str();
}

} catch ( ... ) {
// all or nothing
if ( !syncNode && !keyShareName.empty() )
throw;
}

cp.nodeInfo = { nodeName, nodeID, ip, static_cast< uint16_t >( port ), ip6,
static_cast< uint16_t >( port6 ), sgxServerUrl, ecdsaKeyName, keyShareName, BLSPublicKeys,
commonBLSPublicKeys, syncNode, archiveMode, syncFromCatchup };
commonBLSPublicKeys, syncNode, archiveMode, syncFromCatchup, testSignatures };

auto sChainObj = skaleObj.at( "sChain" ).get_obj();
SChain s{};
Expand Down
34 changes: 17 additions & 17 deletions libethereum/SkaleHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,29 +143,31 @@ void DefaultConsensusFactory::fillSgxInfo( ConsensusEngine& consensus ) const tr
}

void DefaultConsensusFactory::fillPublicKeyInfo( ConsensusEngine& consensus ) const try {
if ( m_client.chainParams().nodeInfo.testSignatures )
// no keys in tests
return;

const std::string sgxServerUrl = m_client.chainParams().nodeInfo.sgxServerUrl;

std::shared_ptr< std::vector< std::string > > ecdsaPublicKeys =
std::make_shared< std::vector< std::string > >();
for ( const auto& node : m_client.chainParams().sChain.nodes ) {
if ( node.publicKey.size() == 0 )
return; // just don't do anything
ecdsaPublicKeys->push_back( node.publicKey.substr( 2 ) );
}

std::vector< std::shared_ptr< std::vector< std::string > > > blsPublicKeys;
for ( const auto& node : m_client.chainParams().sChain.nodes ) {
std::vector< std::string > public_key_share( 4 );
if ( node.id != this->m_client.chainParams().nodeInfo.id ) {
public_key_share[0] = node.blsPublicKey[0];
public_key_share[1] = node.blsPublicKey[1];
public_key_share[2] = node.blsPublicKey[2];
public_key_share[3] = node.blsPublicKey[3];
public_key_share[0] = node.blsPublicKey.at( 0 );
public_key_share[1] = node.blsPublicKey.at( 1 );
public_key_share[2] = node.blsPublicKey.at( 2 );
public_key_share[3] = node.blsPublicKey.at( 3 );
} else {
public_key_share[0] = m_client.chainParams().nodeInfo.BLSPublicKeys[0];
public_key_share[1] = m_client.chainParams().nodeInfo.BLSPublicKeys[1];
public_key_share[2] = m_client.chainParams().nodeInfo.BLSPublicKeys[2];
public_key_share[3] = m_client.chainParams().nodeInfo.BLSPublicKeys[3];
public_key_share[0] = m_client.chainParams().nodeInfo.BLSPublicKeys.at( 0 );
public_key_share[1] = m_client.chainParams().nodeInfo.BLSPublicKeys.at( 1 );
public_key_share[2] = m_client.chainParams().nodeInfo.BLSPublicKeys.at( 2 );
public_key_share[3] = m_client.chainParams().nodeInfo.BLSPublicKeys.at( 3 );
}

blsPublicKeys.push_back(
Expand All @@ -179,11 +181,8 @@ void DefaultConsensusFactory::fillPublicKeyInfo( ConsensusEngine& consensus ) co
size_t n = m_client.chainParams().sChain.nodes.size();
size_t t = ( 2 * n + 1 ) / 3;

if ( ecdsaPublicKeys->size() && ecdsaPublicKeys->at( 0 ).size() &&
( ( blsPublicKeys.size() && blsPublicKeys[0]->at( 0 ).size() ) ||
m_client.chainParams().nodeInfo.syncNode ) )
consensus.setPublicKeyInfo(
ecdsaPublicKeys, blsPublicKeysPtr, t, n, m_client.chainParams().nodeInfo.syncNode );
consensus.setPublicKeyInfo(
ecdsaPublicKeys, blsPublicKeysPtr, t, n, m_client.chainParams().nodeInfo.syncNode );
} catch ( ... ) {
std::throw_with_nested( std::runtime_error( "Error filling public keys info (nodeGroups)" ) );
}
Expand All @@ -195,8 +194,9 @@ void DefaultConsensusFactory::fillRotationHistory( ConsensusEngine& consensus )
std::map< uint64_t, std::vector< uint64_t > > historicNodeGroups;
auto u256toUint64 = []( const dev::u256& u ) { return std::stoull( u.str() ); };
for ( const auto& nodeGroup : m_client.chainParams().sChain.nodeGroups ) {
std::vector< string > commonBLSPublicKey = { nodeGroup.blsPublicKey[0],
nodeGroup.blsPublicKey[1], nodeGroup.blsPublicKey[2], nodeGroup.blsPublicKey[3] };
std::vector< string > commonBLSPublicKey = { nodeGroup.blsPublicKey.at( 0 ),
nodeGroup.blsPublicKey.at( 1 ), nodeGroup.blsPublicKey.at( 2 ),
nodeGroup.blsPublicKey.at( 3 ) };
previousBLSKeys[nodeGroup.finishTs] = commonBLSPublicKey;
std::vector< uint64_t > nodes;
// add ecdsa keys info and historic groups info
Expand Down
4 changes: 2 additions & 2 deletions libethereum/ValidationSchemes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void validateConfigJson( js::mObject const& _obj ) {
{ "snapshotIntervalSec", { { js::int_type }, JsonFieldPresence::Optional } },
{ "rotateAfterBlock", { { js::int_type }, JsonFieldPresence::Optional } },
{ "wallets", { { js::obj_type }, JsonFieldPresence::Optional } },
{ "ecdsaKeyName", { { js::str_type }, JsonFieldPresence::Required } },
{ "ecdsaKeyName", { { js::str_type }, JsonFieldPresence::Optional } },
{ "verifyImaMessagesViaLogsSearch",
{ { js::bool_type }, JsonFieldPresence::Optional } },
{ "verifyImaMessagesViaContractCall",
Expand Down Expand Up @@ -222,6 +222,7 @@ void validateConfigJson( js::mObject const& _obj ) {
{ "syncNode", { { js::bool_type }, JsonFieldPresence::Optional } },
{ "archiveMode", { { js::bool_type }, JsonFieldPresence::Optional } },
{ "syncFromCatchup", { { js::bool_type }, JsonFieldPresence::Optional } },
{ "testSignatures", { { js::bool_type }, JsonFieldPresence::Optional } },
{ "wallets", { { js::obj_type }, JsonFieldPresence::Optional } } } );

std::string keyShareName = "";
Expand Down Expand Up @@ -268,7 +269,6 @@ void validateConfigJson( js::mObject const& _obj ) {
{ "maxSkaledLeveldbStorageBytes", { { js::int_type }, JsonFieldPresence::Optional } },
{ "freeContractDeployment", { { js::bool_type }, JsonFieldPresence::Optional } },
{ "multiTransactionMode", { { js::bool_type }, JsonFieldPresence::Optional } },
{ "nodeGroups", { { js::obj_type }, JsonFieldPresence::Optional } },
{ "nodeGroups", { { js::obj_type }, JsonFieldPresence::Optional } } },
[]( const string& _key ) {
// function fow allowing fields
Expand Down
6 changes: 3 additions & 3 deletions test/unittests/libethereum/ClientTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ static std::string const c_genesisInfoSkaleTest = std::string() +
"basePort": )E"+std::to_string( rand_port ) + R"E(,
"logLevel": "trace",
"logLevelProposal": "trace",
"ecdsaKeyName": "NEK:fa112"
"testSignatures": true
},
"sChain": {
"schainName": "TestChain",
Expand Down Expand Up @@ -887,7 +887,7 @@ static std::string const c_genesisInfoSkaleIMABLSPublicKeyTest = std::string() +
"basePort": )E"+std::to_string( rand_port ) + R"E(,
"logLevel": "trace",
"logLevelProposal": "trace",
"ecdsaKeyName": "NEK:fa112"
"testSignatures": true
},
"sChain": {
"schainName": "TestChain",
Expand Down Expand Up @@ -1002,7 +1002,7 @@ static std::string const c_skaleConfigString = R"E(
"nodeID": 1112,
"bindIP": "127.0.0.1",
"basePort": )E"+std::to_string( rand_port ) + R"E(,
"ecdsaKeyName": "NEK:fa112"
"testSignatures": true
},
"sChain": {
"schainName": "TestChain",
Expand Down
2 changes: 1 addition & 1 deletion test/unittests/libethereum/PrecompiledConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"basePort": 1234,
"logLevel": "trace",
"logLevelProposal": "trace",
"ecdsaKeyName": "NEK:fa112",
"testSignatures": true,
"wallets": {
"ima": {
"n": 1
Expand Down
2 changes: 1 addition & 1 deletion test/unittests/libethereum/PrecompiledTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1619,7 +1619,7 @@ static std::string const genesisInfoSkaleConfigTest = std::string() +
"basePort": 1234,
"logLevel": "trace",
"logLevelProposal": "trace",
"ecdsaKeyName": "NEK:fa112",
"testSignatures": true,
"wallets": {
"ima": {
"n": 1
Expand Down
1 change: 1 addition & 0 deletions test/unittests/libethereum/SkaleHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ struct SkaleHostFixture : public TestOutputHelperFixture {
chainParams.extraData = h256::random().asBytes();
chainParams.sChain.nodeGroups = { { {}, uint64_t(-1), {"0", "0", "1", "0"} } };
chainParams.nodeInfo.port = chainParams.nodeInfo.port6 = rand_port;
chainParams.nodeInfo.testSignatures = true;
chainParams.sChain.nodes[0].port = chainParams.sChain.nodes[0].port6 = rand_port;

// not 0-timestamp genesis - to test patch
Expand Down
2 changes: 1 addition & 1 deletion test/unittests/libweb3jsonrpc/jsonrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ static std::string const c_genesisConfigString =
"basePort": )"+std::to_string( rand_port ) + R"(,
"logLevel": "trace",
"logLevelProposal": "trace",
"ecdsaKeyName": "NEK:fa112"
"testSignatures": true
},
"sChain": {
"schainName": "TestChain",
Expand Down

0 comments on commit 538f60b

Please sign in to comment.