diff --git a/src/consensus.cpp b/src/consensus.cpp index f38b733f..e0f36644 100644 --- a/src/consensus.cpp +++ b/src/consensus.cpp @@ -199,19 +199,9 @@ namespace consensus broadcast_proposal(stg_prop); - if (ctx.stage == 3) - { - if (apply_ledger(stg_prop, lcl_seq_no, lcl) != -1) - { - // node has finished a consensus round (all 4 stages). - LOG_INFO << "****Stage 3 consensus reached**** (lcl:" << lcl.substr(0, 15) - << " state:" << ctx.state << ")"; - } - else - { - LOG_ERROR << "Error occured in Stage 3 consensus execution."; - } - } + // The node has finished a consensus round (all 4 stages) + if (ctx.stage == 3 && apply_ledger(stg_prop) == -1) + LOG_ERROR << "Error occured in Stage 3 consensus execution."; } } } @@ -742,17 +732,22 @@ namespace consensus * Finalize the ledger after consensus. * @param cons_prop The proposal that reached consensus. */ - int apply_ledger(const p2p::proposal &cons_prop, const uint64_t lcl_seq_no, std::string_view lcl) + int apply_ledger(const p2p::proposal &cons_prop) { if (ledger::save_ledger(cons_prop) == -1) return -1; + std::string new_lcl = ledger::ctx.get_lcl(); + const uint64_t new_lcl_seq_no = ledger::ctx.get_seq_no(); + + LOG_INFO << "****Ledger created**** (lcl:" << new_lcl.substr(0, 15) << " state:" << ctx.state << ")"; + // After the current ledger seq no is updated, we remove any newly expired inputs from candidate set. { auto itr = ctx.candidate_user_inputs.begin(); while (itr != ctx.candidate_user_inputs.end()) { - if (itr->second.maxledgerseqno <= lcl_seq_no) + if (itr->second.maxledgerseqno <= new_lcl_seq_no) ctx.candidate_user_inputs.erase(itr++); else ++itr; @@ -760,13 +755,13 @@ namespace consensus } // Send any output from the previous consensus round to locally connected users. - dispatch_user_outputs(cons_prop, lcl_seq_no, lcl); + dispatch_user_outputs(cons_prop, new_lcl_seq_no, new_lcl); // Execute the contract { sc::contract_execution_args &args = ctx.contract_ctx.args; args.time = cons_prop.time; - args.lcl = lcl; + args.lcl = new_lcl; // Populate user bufs. feed_user_inputs_to_contract_bufmap(args.userbufs, cons_prop); @@ -783,6 +778,7 @@ namespace consensus sc::clear_args(args); } + return 0; } diff --git a/src/consensus.hpp b/src/consensus.hpp index 27deda92..77d45ade 100644 --- a/src/consensus.hpp +++ b/src/consensus.hpp @@ -134,7 +134,7 @@ namespace consensus uint64_t get_stage_time_resolution(const uint64_t time); - int apply_ledger(const p2p::proposal &proposal, const uint64_t lcl_seq_no, std::string_view lcl); + int apply_ledger(const p2p::proposal &proposal); void dispatch_user_outputs(const p2p::proposal &cons_prop, const uint64_t lcl_seq_no, std::string_view lcl); diff --git a/src/ledger.cpp b/src/ledger.cpp index 94eab35e..6d28e9bc 100644 --- a/src/ledger.cpp +++ b/src/ledger.cpp @@ -253,7 +253,7 @@ namespace ledger flatbuffers::FlatBufferBuilder builder(1024); msg::fbuf::ledger::create_ledger_from_proposal(builder, proposal, seq_no); - // Get binary hash of the the serialized lcl. + // Get binary hash of the serialized lcl. std::string_view ledger_str_buf = msg::fbuf::flatbuff_bytes_to_sv(builder.GetBufferPointer(), builder.GetSize()); const std::string lcl = crypto::get_hash(ledger_str_buf); @@ -574,7 +574,7 @@ namespace ledger const size_t pos = ledger.lcl.find("-"); const std::string rec_lcl_hash = ledger.lcl.substr((pos + 1), (ledger.lcl.size() - 1)); - // Get binary hash of the the serialized lcl. + // Get binary hash of the serialized lcl. const std::string lcl = crypto::get_hash(ledger.raw_ledger.data(), ledger.raw_ledger.size()); // Get hex from binary hash diff --git a/src/msg/fbuf/p2pmsg_helpers.cpp b/src/msg/fbuf/p2pmsg_helpers.cpp index df3915dc..da5988a8 100644 --- a/src/msg/fbuf/p2pmsg_helpers.cpp +++ b/src/msg/fbuf/p2pmsg_helpers.cpp @@ -126,7 +126,7 @@ namespace msg::fbuf::p2pmsg * Verifies the Content message structure and outputs faltbuffer Content pointer to access the given buffer. * * @param content_ref A pointer reference to assign the pointer to the Content object. - * @param content_ptr Pointer to the the buffer containing the data that should validated and interpreted + * @param content_ptr Pointer to the buffer containing the data that should validated and interpreted * via the container pointer. * @param content_size Data buffer size. * @return 0 on successful verification. -1 for failure. diff --git a/test/local-cluster/consensus-test-continuous.sh b/test/local-cluster/consensus-test-continuous.sh index 76b69531..16304fc2 100644 --- a/test/local-cluster/consensus-test-continuous.sh +++ b/test/local-cluster/consensus-test-continuous.sh @@ -78,7 +78,7 @@ while true; do LASTROUND=$TS fi - SUCCESS="`echo $line | grep '****Stage 3 consensus reached****' | wc -l`" + SUCCESS="`echo $line | grep '****Ledger created****' | wc -l`" SUCCESSFULCLOSES="`echo $SUCCESSFULCLOSES + $SUCCESS | bc`" SHOULDPRINT=`echo "$TS - $LASTROUND > $WINDOWSIZE" | bc` diff --git a/test/local-cluster/consensus-test-loop.sh b/test/local-cluster/consensus-test-loop.sh index 716da8db..100e3881 100644 --- a/test/local-cluster/consensus-test-loop.sh +++ b/test/local-cluster/consensus-test-loop.sh @@ -32,7 +32,7 @@ while true; do kill -s 0 $PID 2> /dev/null 1> /dev/null while [ "$?" -eq "0" ]; do - if [ "`cat contest.out | grep '****Stage 3 consensus reached****' | wc -l`" -gt "0" ]; + if [ "`cat contest.out | grep '****Ledger created****' | wc -l`" -gt "0" ]; then break fi diff --git a/test/vm-cluster/consensus-test-continuous.sh b/test/vm-cluster/consensus-test-continuous.sh index df7ea450..70c3c4a8 100644 --- a/test/vm-cluster/consensus-test-continuous.sh +++ b/test/vm-cluster/consensus-test-continuous.sh @@ -43,7 +43,7 @@ while true; do LASTROUND=$TS fi - SUCCESS="`echo $line | grep '****Stage 3 consensus reached****' | wc -l`" + SUCCESS="`echo $line | grep '****Ledger created****' | wc -l`" SUCCESSFULCLOSES="`echo $SUCCESSFULCLOSES + $SUCCESS | bc`" SHOULDPRINT=`echo "$TS - $LASTROUND > $WINDOWSIZE" | bc`