Skip to content

Commit

Permalink
806 added patch
Browse files Browse the repository at this point in the history
  • Loading branch information
kladkogex committed Mar 14, 2024
1 parent 5d2814a commit ab98406
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Consensust.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
28 changes: 22 additions & 6 deletions chains/Schain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,18 @@ Schain::Schain(weak_ptr<Node> _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<MonitoringAgent>(*this);
optimizerAgent = make_shared<OptimizerAgent>(*this);
Expand Down Expand Up @@ -294,10 +306,7 @@ Schain::Schain(weak_ptr<Node> _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;
Expand Down Expand Up @@ -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<ThresholdSignature> &_thresholdSig, ptr<ThresholdSignature> _daSig) {
Expand Down Expand Up @@ -898,11 +911,10 @@ void Schain::daProofArrived(const ptr<DAProof> &_daProof) {
return;



ptr<BooleanProposalVector> 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
Expand Down Expand Up @@ -1490,5 +1502,9 @@ uint64_t Schain::getVerifyDaSigsPatchTimestampS() const {
return verifyDaSigsPatchTimestampS;
}

uint64_t Schain::getFastConsensusTimestampS() const {
return fastConsensusPatchTimestampS;
}


mutex Schain::vdsMutex;
6 changes: 6 additions & 0 deletions chains/Schain.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -350,6 +352,8 @@ class Schain : public Agent {

uint64_t getVerifyDaSigsPatchTimestampS() const;

uint64_t getFastConsensusTimestampS() const;


bool isInCreateBlock() const;

Expand Down Expand Up @@ -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<CatchupClientAgent> &getCatchupClientAgent() const;
Expand Down
12 changes: 9 additions & 3 deletions monitoring/OptimizerAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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()));
}


2 changes: 1 addition & 1 deletion monitoring/OptimizerAgent.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
14 changes: 9 additions & 5 deletions protocols/blockconsensus/BlockConsensusAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit ab98406

Please sign in to comment.