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

806 improve consensus throughput latest #831

Draft
wants to merge 53 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
ec7e908
806 Improve consensus throughput by 15%
kladkogex Feb 23, 2024
15b344f
1560 slow catchup
kladkogex Feb 23, 2024
7f44e80
806_improve_consensus_throughput
kladkogex Feb 23, 2024
7257cfa
806 optimize consensus
kladkogex Feb 26, 2024
66913ac
806 improve consensus speed
kladkogex Mar 1, 2024
a5bcf6d
806 improve consensus speed
kladkogex Mar 1, 2024
ed32f95
806 improve consensus speed
kladkogex Mar 1, 2024
08a6346
806 improve consensus speed
kladkogex Mar 1, 2024
d983712
Fix
kladkogex Mar 6, 2024
6249d38
806 removed unneded if
kladkogex Mar 13, 2024
5d2814a
806 faster test blocks
kladkogex Mar 13, 2024
ab98406
806 added patch
kladkogex Mar 14, 2024
574bd3d
806 fix Running time
kladkogex Apr 30, 2024
988878b
806 fix formatting
kladkogex Apr 30, 2024
345c2a6
806 fix formatting
kladkogex Apr 30, 2024
b933f8a
806 fix formatting
kladkogex Apr 30, 2024
06e2db4
806 fix formatting
kladkogex Apr 30, 2024
e435079
806 fix formatting
kladkogex Apr 30, 2024
4b545cc
806 fix formatting
kladkogex Apr 30, 2024
7361cc1
806 fix formatting
kladkogex Apr 30, 2024
bff0530
806 fix formatting
kladkogex Apr 30, 2024
0f96094
806 fix formatting
kladkogex Apr 30, 2024
aed6810
806 fix formatting
kladkogex Apr 30, 2024
66ae7ce
806 add more comments
kladkogex May 2, 2024
3a1f607
806 more testing
kladkogex May 2, 2024
801852c
Create consensus-spec.md
kladkogex May 2, 2024
f896810
Update consensus-spec.md
kladkogex May 2, 2024
9e9c648
Update consensus-spec.md
kladkogex May 2, 2024
b603901
Update consensus-spec.md
kladkogex May 2, 2024
714e3d8
Update consensus-spec.md
kladkogex May 2, 2024
dc834c1
Update consensus-spec.md
kladkogex May 2, 2024
846aa09
Update consensus-spec.md
kladkogex May 2, 2024
8d0b5f7
Update consensus-spec.md
kladkogex May 2, 2024
7f39616
Update consensus-spec.md
kladkogex May 2, 2024
5890a5a
Update consensus-spec.md
kladkogex May 2, 2024
819a0d4
Update consensus-spec.md
kladkogex May 2, 2024
98ebbb3
Update consensus-spec.md
kladkogex May 2, 2024
eef7846
Update consensus-spec.md
kladkogex May 2, 2024
0514650
Update consensus-spec.md
kladkogex May 2, 2024
5e0bf0f
Update consensus-spec.md
kladkogex May 2, 2024
d9f6ab4
Update consensus-spec.md
kladkogex May 2, 2024
548923b
Update consensus-spec.md
kladkogex May 2, 2024
4dc1e9b
Update consensus-spec.md
kladkogex May 3, 2024
512799c
Update consensus-spec.md
kladkogex May 3, 2024
b3b5d87
Update consensus-spec.md
kladkogex May 3, 2024
c4c721a
Update consensus-spec.md
kladkogex May 3, 2024
02873a7
Update consensus-spec.md
kladkogex May 3, 2024
b7f8edc
Update consensus-spec.md
kladkogex May 3, 2024
8b8c262
Update consensus-spec.md
kladkogex May 3, 2024
b92b336
Update consensus-spec.md
kladkogex May 3, 2024
1848bb9
Update consensus-spec.md
kladkogex May 3, 2024
5481a91
806 third party add cache file
kladkogex May 7, 2024
391d420
806 add cache fils
kladkogex May 7, 2024
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
87 changes: 47 additions & 40 deletions .idea/workspace.xml

Large diffs are not rendered by default.

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 30
#define DEFAULT_RUNNING_TIME_S 180
#define STUCK_TEST_TIME 5

class Consensust {
Expand Down
75 changes: 70 additions & 5 deletions chains/Schain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
#include "messages/NetworkMessageEnvelope.h"
#include "monitoring/MonitoringAgent.h"
#include "monitoring/StuckDetectionAgent.h"
#include "monitoring/OptimizerAgent.h"
#include "network/ClientSocket.h"
#include "network/IO.h"
#include "network/Sockets.h"
Expand Down Expand Up @@ -241,6 +242,7 @@ Schain::Schain( weak_ptr< Node > _node, schain_index _schainIndex, const schain_
node( _node ),
schainIndex( _schainIndex ) {
lastCommittedBlockTimeStamp = TimeStamp( 0, 0 );
setTimeStampValuesFromConfig();

// construct monitoring, timeout and stuck detection agents early
monitoringAgent = make_shared< MonitoringAgent >( *this );
Expand Down Expand Up @@ -291,10 +293,7 @@ Schain::Schain( weak_ptr< Node > _node, schain_index _schainIndex, const schain_
getNode()->registerAgent( this );


if ( getNode()->getPatchTimestamps().count( "verifyDaSigsPatchTimestamp" ) > 0 ) {
this->verifyDaSigsPatchTimestampS =
getNode()->getPatchTimestamps().at( "verifyDaSigsPatchTimestamp" );
}


} catch ( ExitRequestedException& ) {
throw;
Expand All @@ -309,6 +308,7 @@ void Schain::constructChildAgents() {
MONITOR( __CLASS_NAME__, __FUNCTION__ )

try {
optimizerAgent = make_shared< OptimizerAgent >( *this );
oracleResultAssemblyAgent = make_shared< OracleResultAssemblyAgent >( *this );
pricingAgent = make_shared< PricingAgent >( *this );
catchupClientAgent = make_shared< CatchupClientAgent >( *this );
Expand Down Expand Up @@ -404,6 +404,13 @@ void Schain::lockWithDeadLockCheck( const char* _functionName ) {
result = ( ( uint64_t ) getLastCommittedBlockID() ) - committedIDOld;
if ( !getNode()->isSyncOnlyNode() ) {
proposeNextBlock( true );
} else {
// on sync nodes we get candidate block and throw it away immediately
// this is to clean skaled queues
if (extFace) { // if extFace is null we are in consensus tests and there is no skaled
u256 stateRoot = 0;
extFace->pendingTransactions( getNode()->getMaxTransactionsPerBlock(), stateRoot );
}
}
}

Expand Down Expand Up @@ -541,6 +548,13 @@ void Schain::proposeNextBlock( bool _isCalledAfterCatchup ) {

proposedBlockArrived( myProposal );

if (getOptimizerAgent()->skipSendingProposalToTheNetwork(_proposedBlockID)) {
// a node skips sending and saving its proposal during
// optimized block consensus, if the node was not a winner
// last time
return; // dont propose
}

LOG( debug, "PROPOSING BLOCK NUMBER:" << to_string( _proposedBlockID ) );

auto db = getNode()->getProposalHashDB();
Expand Down Expand Up @@ -884,7 +898,10 @@ void Schain::daProofArrived( const ptr< DAProof >& _daProof ) {
if ( _daProof->getBlockId() <= getLastCommittedBlockID() )
return;

auto pv = getNode()->getDaProofDB()->addDAProof( _daProof );
// this will add the DAProof to DB. If there are enough DAProofs in DB
// to start binary consensus, this will return binary proposal vector of 1s and 0s
auto pv =
addDAProofToDBAndCalculateProposalVectorIfItsTimeToStartBinaryConsensus( _daProof );


if ( pv != nullptr ) {
Expand Down Expand Up @@ -1462,3 +1479,51 @@ uint64_t Schain::getVerifyDaSigsPatchTimestampS() const {


mutex Schain::vdsMutex;

// this function is called on arrival of each DA proof
// if it is time to make binary proposals it will return a vector of 0s and 1s
// for normal consensus it will happen when 2t+1 DA proofs arrive (which is 11)
// for optimized consensus it will happen when a DA proof from the previous winner arrives
ptr<BooleanProposalVector>
Schain::addDAProofToDBAndCalculateProposalVectorIfItsTimeToStartBinaryConsensus(
const ptr<DAProof> &_daProof) {

ptr<BooleanProposalVector> pv;

if (getOptimizerAgent()->doOptimizedConsensus(_daProof->getBlockId(), getLastCommittedBlockTimeStamp().getS())) {
// when we do optimized block consensus only the previous winner
// proposes and provides da proof
// proposals from other nodes, if sent made by mistake, are ignored
auto lastWinner = getOptimizerAgent()->getPreviousWinner( _daProof->getBlockId() );
if (_daProof->getProposerIndex() == lastWinner) {
getNode()->getDaProofDB()->addDAProof(_daProof);
pv = make_shared<BooleanProposalVector>(getNodeCount(), lastWinner);
}
} else {
// do things regular way
// the binary proposal vector is formed and the consensus is started when
// 2/3 of nodes (11) submit a da proof
pv = getNode()->getDaProofDB()->addDAProof(_daProof);
}
return pv;
}

// returns true if fastConsensusPatch ie enabled
bool Schain::fastConsensusPatchEnabled(uint64_t _blockTimeStampSec ) {
return fastConsensusPatchTimestampS != 0 && _blockTimeStampSec >= fastConsensusPatchTimestampS;
}

// macro to set patchstamp variable from connfig
#define SET_TIMESTAMP_FROM_CONFIG(__TIMESTAMP_NAME__) \
{ \
auto& timestamps = getNode()->getPatchTimestamps(); \
if (timestamps.count(#__TIMESTAMP_NAME__) > 0) { \
__TIMESTAMP_NAME__ = timestamps.at(#__TIMESTAMP_NAME__); \
} \
}

// set all timestamp values from config
void Schain::setTimeStampValuesFromConfig() {
SET_TIMESTAMP_FROM_CONFIG(verifyDaSigsPatchTimestampS)
SET_TIMESTAMP_FROM_CONFIG(fastConsensusPatchTimestampS)
}
12 changes: 11 additions & 1 deletion chains/Schain.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class CatchupServerAgent;
class MonitoringAgent;
class TimeoutAgent;
class StuckDetectionAgent;

class OptimizerAgent;

class BlockProposalServerAgent;

Expand Down Expand Up @@ -136,6 +136,7 @@ class Schain : public Agent {

ptr< OracleResultAssemblyAgent > oracleResultAssemblyAgent;

ptr<OptimizerAgent> optimizerAgent;

ptr< IO > io;

Expand Down Expand Up @@ -176,6 +177,7 @@ class Schain : public Agent {
ptr< NodeInfo > thisNodeInfo = nullptr;

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
Expand Down Expand Up @@ -390,4 +392,12 @@ class Schain : public Agent {

const ptr<CatchupClientAgent> &getCatchupClientAgent() const;

ptr< OptimizerAgent > getOptimizerAgent() const;

bool fastConsensusPatchEnabled( uint64_t _blockTimeStampSec );

void setTimeStampValuesFromConfig();

ptr<BooleanProposalVector>
addDAProofToDBAndCalculateProposalVectorIfItsTimeToStartBinaryConsensus(const ptr<DAProof> &_daProof);
};
9 changes: 7 additions & 2 deletions chains/SchainGettersSetters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,13 @@ ptr< CryptoManager > Schain::getCryptoManager() const {
return cryptoManager;
}


ptr< OptimizerAgent > Schain::getOptimizerAgent() const {
CHECK_STATE( optimizerAgent );
return optimizerAgent;
}


void Schain::createBlockConsensusInstance() {
blockConsensusInstance = make_shared< BlockConsensusAgent >( *this );
}
Expand Down Expand Up @@ -320,8 +327,6 @@ void Schain::updateLastCommittedBlockInfo( uint64_t _lastCommittedBlockID,
tpsAverage = ( blockSizeAverage * 1000 ) / blockTimeAverageMs;
getRandomForBlockId( ( uint64_t ) lastCommittedBlockID );

if ( getNode()->isSyncOnlyNode() )
return;
}


Expand Down
21 changes: 21 additions & 0 deletions datastructures/BooleanProposalVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,27 @@ BooleanProposalVector::BooleanProposalVector( node_count _nodeCount, const strin
}



// This is boolean proposal constructor in case of optimized proposal. In this
// case we proposer 1 for the previos winner and 0 for everyone else
BooleanProposalVector::BooleanProposalVector( node_count _nodeCount, schain_index _previousWinner )
: nodeCount( _nodeCount ) {

CHECK_ARGUMENT( _previousWinner > 0 );
CHECK_ARGUMENT( _previousWinner <= (uint64_t )_nodeCount );
proposals.push_back( false );

for ( uint64_t i = 1; i <= _nodeCount; i++ ) {
if ( i == _previousWinner ) {
proposals.push_back( true );
trueCount++;
} else {
proposals.push_back( false );
}
}
}


bool BooleanProposalVector::getProposalValue( schain_index _index ) {
CHECK_STATE( proposals.size() == nodeCount + 1 );
CHECK_STATE( _index <= ( uint64_t ) nodeCount );
Expand Down
2 changes: 2 additions & 0 deletions datastructures/BooleanProposalVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class BooleanProposalVector : public DataStructure {

BooleanProposalVector( node_count _nodeCount, const string& _vectorStr );

BooleanProposalVector( node_count _nodeCount, schain_index _singleWinner );

bool getProposalValue( schain_index _index );

[[nodiscard]] uint64_t getTrueCount() const;
Expand Down
10 changes: 10 additions & 0 deletions db/BlockProposalDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "exceptions/FatalError.h"
#include "leveldb/db.h"
#include "monitoring/LivelinessMonitor.h"
#include "monitoring/OptimizerAgent.h"
#include "node/Node.h"
#include "pendingqueue/PendingTransactionsAgent.h"
#include "thirdparty/json.hpp"
Expand Down Expand Up @@ -79,8 +80,17 @@ void BlockProposalDB::addBlockProposal( const ptr< BlockProposal > _proposal ) {

addProposalToCacheIfDoesNotExist( _proposal );


// save own proposal to levelDB
if ( _proposal->getProposerIndex() == getSchain()->getSchainIndex() ) {

// for optimized consensus only previous winner proposed.
// non-winners skip sending proposal and do not need to save it to the db
// since saving proposal to the db is done to be able to resend it in case of a
// crash
if (getSchain()->getOptimizerAgent()->skipSendingProposalToTheNetwork(_proposal->getBlockID()))
return;

serializeProposalAndSaveItToLevelDB( _proposal );
}
}
Expand Down
Loading
Loading