From ab98406f048d9c37f3c554c88b5839ee5c889ffa Mon Sep 17 00:00:00 2001 From: Stan Kladko <13399135+kladkogex@users.noreply.github.com> Date: Thu, 14 Mar 2024 17:07:51 +0000 Subject: [PATCH] 806 added patch --- Consensust.h | 2 +- chains/Schain.cpp | 28 +++++++++++++++---- chains/Schain.h | 6 ++++ monitoring/OptimizerAgent.cpp | 12 ++++++-- monitoring/OptimizerAgent.h | 2 +- .../blockconsensus/BlockConsensusAgent.cpp | 14 ++++++---- 6 files changed, 48 insertions(+), 16 deletions(-) diff --git a/Consensust.h b/Consensust.h index 86f52b6e..f7e27f4c 100644 --- a/Consensust.h +++ b/Consensust.h @@ -23,7 +23,7 @@ #pragma once -#define DEFAULT_RUNNING_TIME_S 600 +#define DEFAULT_RUNNING_TIME_S 180 #define STUCK_TEST_TIME 5 class Consensust { diff --git a/chains/Schain.cpp b/chains/Schain.cpp index ba2f2dad..15999389 100644 --- a/chains/Schain.cpp +++ b/chains/Schain.cpp @@ -243,6 +243,18 @@ Schain::Schain(weak_ptr _node, schain_index _schainIndex, const schain_id schainIndex(_schainIndex) { lastCommittedBlockTimeStamp = TimeStamp(0, 0); + if (getNode()->getPatchTimestamps().count("verifyDaSigsPatchTimestamp") > 0) { + this->verifyDaSigsPatchTimestampS = + getNode()->getPatchTimestamps().at("verifyDaSigsPatchTimestamp"); + } + + if (getNode()->getPatchTimestamps().count("verifyDaSigsPatchTimestamp") > 0) { + this->fastConsensusPatchTimestampS = + getNode()->getPatchTimestamps().at("fastConsensusPatchTimestamp"); + } + + + // construct monitoring, timeout and stuck detection agents early monitoringAgent = make_shared(*this); optimizerAgent = make_shared(*this); @@ -294,10 +306,7 @@ Schain::Schain(weak_ptr _node, schain_index _schainIndex, const schain_id getNode()->registerAgent(this); - if (getNode()->getPatchTimestamps().count("verifyDaSigsPatchTimestamp") > 0) { - this->verifyDaSigsPatchTimestampS = - getNode()->getPatchTimestamps().at("verifyDaSigsPatchTimestamp"); - } + } catch (ExitRequestedException &) { throw; @@ -432,6 +441,10 @@ bool Schain::verifyDASigsPatch(uint64_t _blockTimeStampS) { return verifyDaSigsPatchTimestampS != 0 && _blockTimeStampS >= verifyDaSigsPatchTimestampS; } +bool Schain::fastConsensusPatch(uint64_t _blockTimeStampS) { + return fastConsensusPatchTimestampS != 0 && _blockTimeStampS >= fastConsensusPatchTimestampS; +} + void Schain::blockCommitArrived(block_id _committedBlockID, schain_index _proposerIndex, const ptr &_thresholdSig, ptr _daSig) { @@ -898,11 +911,10 @@ void Schain::daProofArrived(const ptr &_daProof) { return; - ptr pv; - if (getOptimizerAgent()->doOptimizedConsensus(bid)) { + if (getOptimizerAgent()->doOptimizedConsensus(bid, getLastCommittedBlockTimeStamp().getS())) { // when we do optimized block consensus only a single block proposer // proposes and provides da proof, which is the previous winner. // proposals from other nodes, if sent made by mistake, are ignored @@ -1490,5 +1502,9 @@ uint64_t Schain::getVerifyDaSigsPatchTimestampS() const { return verifyDaSigsPatchTimestampS; } +uint64_t Schain::getFastConsensusTimestampS() const { + return fastConsensusPatchTimestampS; +} + mutex Schain::vdsMutex; diff --git a/chains/Schain.h b/chains/Schain.h index 0f4f64f5..830f2984 100644 --- a/chains/Schain.h +++ b/chains/Schain.h @@ -178,6 +178,8 @@ class Schain : public Agent { uint64_t verifyDaSigsPatchTimestampS = 0; + uint64_t fastConsensusPatchTimestampS = 0; + // If a BlockError analyzer is added to the queue // its analyze(CommittedBlock _block) function will be run on commit // and then t will be removed from the queue @@ -350,6 +352,8 @@ class Schain : public Agent { uint64_t getVerifyDaSigsPatchTimestampS() const; + uint64_t getFastConsensusTimestampS() const; + bool isInCreateBlock() const; @@ -389,6 +393,8 @@ class Schain : public Agent { bool verifyDASigsPatch( uint64_t _blockTimeStampSec ); + bool fastConsensusPatch( uint64_t _blockTimeStampSec ); + void updateInternalChainInfo( block_id _lastCommittedBlockID ); const ptr &getCatchupClientAgent() const; diff --git a/monitoring/OptimizerAgent.cpp b/monitoring/OptimizerAgent.cpp index 1edd486a..0872b71a 100644 --- a/monitoring/OptimizerAgent.cpp +++ b/monitoring/OptimizerAgent.cpp @@ -33,7 +33,12 @@ OptimizerAgent::OptimizerAgent(Schain &_sChain) : Agent(_sChain, false, true), } -bool OptimizerAgent::doOptimizedConsensus(block_id _blockId) { +bool OptimizerAgent::doOptimizedConsensus(block_id _blockId, uint64_t _lastBlockTimeStampS) { + + + if (!getSchain()->fastConsensusPatch(_lastBlockTimeStampS)) { + return false; + } auto lastWinner = getLastWinner(_blockId); @@ -69,8 +74,9 @@ schain_index OptimizerAgent::getLastWinner(block_id _blockId) { schain_index OptimizerAgent::skipSendingProposalToTheNetwork(block_id _blockId) { // whe we run optimized consensus a node skips sending proposal to the network // if node chain index is not equal to the last winner - return (getSchain()->getOptimizerAgent()->doOptimizedConsensus(_blockId) && - (getSchain()->getOptimizerAgent()->getLastWinner(_blockId) != getSchain()->getSchainIndex())); + return (getSchain()->getOptimizerAgent()->doOptimizedConsensus(_blockId, + getSchain()->getLastCommittedBlockTimeStamp().getS()) && + (getSchain()->getOptimizerAgent()->getLastWinner(_blockId) != getSchain()->getSchainIndex())); } diff --git a/monitoring/OptimizerAgent.h b/monitoring/OptimizerAgent.h index dc7e8d9a..d021942b 100644 --- a/monitoring/OptimizerAgent.h +++ b/monitoring/OptimizerAgent.h @@ -36,7 +36,7 @@ class OptimizerAgent : public Agent { // we determine consensus winner each 16 blocks - bool doOptimizedConsensus(block_id _blockId); + bool doOptimizedConsensus(block_id _blockId, uint64_t _lastBlockTimeStamp); schain_index getLastWinner(block_id _block); diff --git a/protocols/blockconsensus/BlockConsensusAgent.cpp b/protocols/blockconsensus/BlockConsensusAgent.cpp index e61ed7f7..2882c76f 100644 --- a/protocols/blockconsensus/BlockConsensusAgent.cpp +++ b/protocols/blockconsensus/BlockConsensusAgent.cpp @@ -106,7 +106,8 @@ void BlockConsensusAgent::startConsensusProposal( LOG(debug, "CONSENSUS START:BLOCK:" << to_string(_blockID)); - if (getSchain()->getOptimizerAgent()->doOptimizedConsensus(_blockID)) { + if (getSchain()->getOptimizerAgent()->doOptimizedConsensus(_blockID, + getSchain()->getLastCommittedBlockTimeStamp().getS())) { // for optimized block consensus, we only propose and initiated binary consensus // for the last block winner auto lastWinner = getSchain()->getOptimizerAgent()->getLastWinner(_blockID); @@ -231,7 +232,7 @@ bool BlockConsensusAgent::haveFalseDecision(block_id _blockId, schain_index _pro void BlockConsensusAgent::decideNormalBlockConsensusIfCan(block_id _blockId) { - auto nodeCount = (uint64_t ) getSchain()->getNodeCount(); + auto nodeCount = (uint64_t) getSchain()->getNodeCount(); // note, priorityLeader is numbered from 0 to N-1, so uint64_t priorityLeader = getPriorityLeaderForBlock((uint64_t) nodeCount, _blockId); @@ -308,7 +309,8 @@ void BlockConsensusAgent::reportBinaryConsensusAndDecideBlockIfCan( // if we are doing optimized consensus // we are only running a single binary consensus for the last // winner and ignoring all other messages, even if someone sends them by mistake - if (getSchain()->getOptimizerAgent()->doOptimizedConsensus(blockID) && + if (getSchain()->getOptimizerAgent()->doOptimizedConsensus(blockID, + getSchain()->getLastCommittedBlockTimeStamp().getS()) && (uint64_t) blockProposerIndex != getSchain()->getOptimizerAgent()->getLastWinner(blockID)) { LOG(warn, "Consensus got ChildBVBroadcastMessage for non-winner in optimized round:" + blockProposerIndex); return; @@ -317,7 +319,8 @@ void BlockConsensusAgent::reportBinaryConsensusAndDecideBlockIfCan( // record that the binary consensus completion reported by the msg recordBinaryDecision(_msg, blockProposerIndex, blockID); - if (getSchain()->getOptimizerAgent()->doOptimizedConsensus(blockID)) { + if (getSchain()->getOptimizerAgent()->doOptimizedConsensus(blockID, + getSchain()->getLastCommittedBlockTimeStamp().getS())) { decideOptimizedBlockConsensusIfCan(blockID); } else { decideNormalBlockConsensusIfCan(blockID); @@ -351,7 +354,8 @@ uint64_t BlockConsensusAgent::getPriorityLeaderForBlock(uint64_t nodeCount, bloc priorityLeader = ((uint64_t) seed) % nodeCount; - if (getSchain()->getOptimizerAgent()->doOptimizedConsensus(blockID)) { + if (getSchain()->getOptimizerAgent()->doOptimizedConsensus(blockID, + getSchain()->getLastCommittedBlockTimeStamp().getS())) { priorityLeader = (uint64_t) getSchain()->getOptimizerAgent()->getLastWinner(blockID); } CHECK_STATE(priorityLeader <= nodeCount);