Updated ledger creation to report current lcl. (#136)

This commit is contained in:
Ravin Perera
2020-10-24 07:22:28 +05:30
committed by GitHub
parent 86fba4e87a
commit 00069b7a43
7 changed files with 20 additions and 24 deletions

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -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

View File

@@ -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.

View File

@@ -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`

View File

@@ -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

View File

@@ -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`