Skip to content

Commit

Permalink
806 fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
kladkogex committed Apr 30, 2024
1 parent 988878b commit 345c2a6
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 44 deletions.
2 changes: 1 addition & 1 deletion chains/Schain.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class Schain : public Agent {

uint64_t verifyDaSigsPatchTimestampS = 0;

uint64_t fastConsensusPatchTimestampS = 0;
uint64_t fastConsensusPatchTimestampS = 1;

// If a BlockError analyzer is added to the queue
// its analyze(CommittedBlock _block) function will be run on commit
Expand Down
79 changes: 38 additions & 41 deletions protocols/blockconsensus/BlockConsensusAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ BlockConsensusAgent::BlockConsensusAgent( Schain& _schain )


void BlockConsensusAgent::startConsensusProposal(
block_id _blockID, const ptr<BooleanProposalVector> &_proposalVector) {
block_id _blockID, const ptr< BooleanProposalVector >& _proposal ) {
try {
if ( getSchain()->getLastCommittedBlockID() >= _blockID ) {
LOG( debug, "Terminating consensus proposal since already committed." );
Expand All @@ -111,19 +111,19 @@ void BlockConsensusAgent::startConsensusProposal(
// for optimized block consensus, we only propose and initiated binary consensus
// for the last block winner
auto lastWinner = getSchain()->getOptimizerAgent()->getLastWinner(_blockID);
auto x = bin_consensus_value(_proposalVector->getProposalValue(schain_index(lastWinner)) ? 1 : 0);
auto x = bin_consensus_value(_proposal->getProposalValue(schain_index(lastWinner)) ? 1 : 0);
propose(x, lastWinner, _blockID);
} else {
// normal consensus. Start N binary consensuses
for (uint64_t i = 1; i <= (uint64_t) getSchain()->getNodeCount(); i++) {
if (getSchain()->getNode()->isExitRequested())
for ( uint64_t i = 1; i <= (uint64_t) getSchain()->getNodeCount(); i++ ) {
if ( getSchain()->getNode()->isExitRequested() )
return;
auto x = bin_consensus_value(_proposalVector->getProposalValue(schain_index(i)) ? 1 : 0);
propose(x, schain_index(i), _blockID);
auto x = bin_consensus_value(_proposal->getProposalValue(schain_index(i)) ? 1 : 0);
propose( x, schain_index( i ), _blockID );
}
}

} catch (ExitRequestedException &) {
} catch ( ExitRequestedException& ) {
throw;
} catch ( SkaleException& e ) {
throw_with_nested( InvalidStateException( __FUNCTION__, __CLASS_NAME__ ) );
Expand All @@ -136,7 +136,7 @@ void BlockConsensusAgent::processChildMessageImpl( const ptr< InternalMessageEnv

auto msg = dynamic_pointer_cast< ChildBVDecidedMessage >( _me->getMessage() );

reportBinaryConsensusAndDecideBlockIfCan(msg);
reportConsensusAndDecideIfNeeded( msg );
}

void BlockConsensusAgent::propose(
Expand Down Expand Up @@ -263,46 +263,44 @@ void BlockConsensusAgent::decideNormalBlockConsensusIfCan(block_id _blockId) {
decideDefaultBlock(_blockId);
}

void BlockConsensusAgent::decideOptimizedBlockConsensusIfCan(block_id _blockId) {
void BlockConsensusAgent::decideOptimizedBlockConsensusIfCan( block_id _blockId ) {


schain_index lastWinner = getSchain()->getOptimizerAgent()->getLastWinner(_blockId);
schain_index lastWinner = getSchain()->getOptimizerAgent()->getLastWinner( _blockId );

if (haveTrueDecision(_blockId, lastWinner)) {
if ( haveTrueDecision(_blockId, lastWinner) ) {
// last winner consensus completed with 1
decideBlock(_blockId, lastWinner, buildStats(_blockId));
return;
}

if (haveFalseDecision(_blockId, lastWinner)) {
if ( haveFalseDecision( _blockId, lastWinner ) ) {
// last winner consensus completed with 0
// since this is the only consensus we are running in optimized round
// we need to produce default block
// This will happen in rare situations when the last winner crashed
decideDefaultBlock(_blockId);
decideDefaultBlock( _blockId );
}
}


void BlockConsensusAgent::reportBinaryConsensusAndDecideBlockIfCan(
void BlockConsensusAgent::reportConsensusAndDecideIfNeeded(
const ptr<ChildBVDecidedMessage> &_msg) {
CHECK_ARGUMENT(_msg);

try {
auto nodeCount = (uint64_t) getSchain()->getNodeCount();
auto nodeCount = ( uint64_t ) getSchain()->getNodeCount();
schain_index blockProposerIndex = _msg->getBlockProposerIndex();
CHECK_STATE(blockProposerIndex <= nodeCount);
auto blockID = _msg->getBlockId();

if (blockID <= getSchain()->getLastCommittedBlockID()) {
if ( blockID <= getSchain()->getLastCommittedBlockID() ) {
// Old consensus is reporting, already got this block through catchup
// do nothing
return;
}

// the consensus for this block has already completed
// do nothing
if (decidedIndices->exists((uint64_t) blockID)) {
if ( decidedIndices->exists( ( uint64_t ) blockID ) ) {
return;
}

Expand All @@ -317,19 +315,18 @@ void BlockConsensusAgent::reportBinaryConsensusAndDecideBlockIfCan(
}

// record that the binary consensus completion reported by the msg
recordBinaryDecision(_msg, blockProposerIndex, blockID);
recordBinaryDecision( _msg, blockProposerIndex, blockID );

if (getSchain()->getOptimizerAgent()->doOptimizedConsensus(blockID,
getSchain()->getLastCommittedBlockTimeStamp().getS())) {
decideOptimizedBlockConsensusIfCan(blockID);
if (getSchain()->getOptimizerAgent()->doOptimizedConsensus( blockID, getSchain()->getLastCommittedBlockTimeStamp().getS()) ) {
decideOptimizedBlockConsensusIfCan( blockID );
} else {
decideNormalBlockConsensusIfCan(blockID);
decideNormalBlockConsensusIfCan( blockID );
}


} catch (ExitRequestedException &) {
} catch ( ExitRequestedException& ) {
throw;
} catch (SkaleException &e) {
} catch ( SkaleException& e ) {
throw_with_nested(InvalidStateException(__FUNCTION__, __CLASS_NAME__));
}

Expand All @@ -343,22 +340,22 @@ uint64_t BlockConsensusAgent::getPriorityLeaderForBlock(uint64_t nodeCount, bloc
if (blockID <= 1) {
seed = 1;
} else {
CHECK_STATE(blockID - 1 <= getSchain()->getLastCommittedBlockID());
auto previousBlock = getSchain()->getBlock(blockID - 1);
if (previousBlock == nullptr)
BOOST_THROW_EXCEPTION(InvalidStateException(
"Can not read block " + to_string(blockID - 1) + " from LevelDB",
__CLASS_NAME__ ));
seed = *((uint64_t *) previousBlock->getHash().data());
CHECK_STATE( blockID - 1 <= getSchain()->getLastCommittedBlockID() );
auto previousBlock = getSchain()->getBlock( blockID - 1 );
if ( previousBlock == nullptr )
BOOST_THROW_EXCEPTION( InvalidStateException(
"Can not read block " + to_string( blockID - 1 ) + " from LevelDB",
__CLASS_NAME__ ) );
seed = *( (uint64_t *) previousBlock->getHash().data() );
}

priorityLeader = ((uint64_t) seed) % nodeCount;
priorityLeader = ( (uint64_t) seed ) % nodeCount;

if (getSchain()->getOptimizerAgent()->doOptimizedConsensus(blockID,
getSchain()->getLastCommittedBlockTimeStamp().getS())) {
priorityLeader = (uint64_t) getSchain()->getOptimizerAgent()->getLastWinner(blockID);
}
CHECK_STATE(priorityLeader <= nodeCount);
CHECK_STATE( priorityLeader <= nodeCount );
return priorityLeader;
}

Expand All @@ -369,16 +366,16 @@ void BlockConsensusAgent::recordBinaryDecision(const ptr<ChildBVDecidedMessage>
trueDecisions->putIfDoesNotExist((uint64_t) blockID,
make_shared<map<schain_index, ptr<ChildBVDecidedMessage> > >());

auto map = trueDecisions->get((uint64_t) blockID);
map->emplace(blockProposerIndex, _msg);
auto map = trueDecisions->get( (uint64_t) blockID );
map->emplace( blockProposerIndex, _msg );

} else {
if (!falseDecisions->exists((uint64_t) blockID))
falseDecisions->putIfDoesNotExist((uint64_t) blockID,
make_shared<map<schain_index, ptr<ChildBVDecidedMessage> > >());
falseDecisions->putIfDoesNotExist( (uint64_t) blockID,
make_shared<map<schain_index, ptr<ChildBVDecidedMessage> > >() );

auto map = falseDecisions->get((uint64_t) blockID);
map->emplace(blockProposerIndex, _msg);
auto map = falseDecisions->get( (uint64_t) blockID );
map->emplace( blockProposerIndex, _msg );
}
}

Expand Down
4 changes: 2 additions & 2 deletions protocols/blockconsensus/BlockConsensusAgent.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ class BlockConsensusAgent : public ProtocolInstance {

void propose( bin_consensus_value _proposal, schain_index index, block_id _id );

void reportBinaryConsensusAndDecideBlockIfCan(const ptr< ChildBVDecidedMessage >& _msg );
void reportConsensusAndDecideIfNeeded(const ptr< ChildBVDecidedMessage >& _msg );

void decideDefaultBlock( block_id _blockNumber );


void startConsensusProposal( block_id _blockID, const ptr< BooleanProposalVector >& _proposalVector );
void startConsensusProposal( block_id _blockID, const ptr< BooleanProposalVector >& _proposal );

void processBlockSignMessage( const ptr< BlockSignBroadcastMessage >& _message );

Expand Down

0 comments on commit 345c2a6

Please sign in to comment.