mirror of
https://github.com/EvernodeXRPL/hpcore.git
synced 2026-04-29 15:37:59 +00:00
LCL history request and response. (#59)
Detect and request missing lcl history from another random node. Sending lcl history response to a asked node. Getting lcl history response and applying it. Delete lcl that exceeds max ledger sequence.
This commit is contained in:
@@ -36,9 +36,10 @@ int init()
|
||||
ctx.stage = 0;
|
||||
|
||||
//load lcl details from lcl history.
|
||||
const ledger_history ldr_hist = load_ledger();
|
||||
ledger_history ldr_hist = load_ledger();
|
||||
ctx.led_seq_no = ldr_hist.led_seq_no;
|
||||
ctx.lcl = ldr_hist.lcl;
|
||||
ctx.lcl_list.swap(ldr_hist.lcl_list);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -60,19 +61,6 @@ void consensus()
|
||||
ctx.candidate_proposals.splice(ctx.candidate_proposals.end(), p2p::ctx.collected_msgs.proposals);
|
||||
}
|
||||
|
||||
LOG_DBG << "Started stage " << std::to_string(ctx.stage);
|
||||
for (const auto p : ctx.candidate_proposals)
|
||||
{
|
||||
const bool self = p.pubkey == conf::cfg.pubkey;
|
||||
LOG_DBG << "[stage" << std::to_string(p.stage)
|
||||
<< "] users:" << p.users.size()
|
||||
<< " hinp:" << p.hash_inputs.size()
|
||||
<< " hout:" << p.hash_outputs.size()
|
||||
<< " lcl:" << p.lcl
|
||||
<< " self:" << self;
|
||||
}
|
||||
LOG_DBG << "timenow: " << std::to_string(ctx.time_now);
|
||||
|
||||
// Throughout consensus, we move over the incoming npl messages collected via the network so far into
|
||||
// the candidate npl message set (move and append). This is to have a private working set for the consensus
|
||||
// and avoid threading conflicts with network incoming npl messages.
|
||||
@@ -93,7 +81,6 @@ void consensus()
|
||||
if (ctx.stage == 0)
|
||||
{
|
||||
// Stage 0 means begining of a consensus round.
|
||||
|
||||
{
|
||||
// Remove any useless candidate proposals so we'll have a cleaner proposal set to look at
|
||||
// when we transition to stage 1.
|
||||
@@ -123,6 +110,21 @@ void consensus()
|
||||
}
|
||||
else // Stage 1, 2, 3
|
||||
{
|
||||
|
||||
std::cout << "Started stage " << std::to_string(ctx.stage) << "\n";
|
||||
for (auto p : ctx.candidate_proposals)
|
||||
{
|
||||
bool self = p.pubkey == conf::cfg.pubkey;
|
||||
LOG_DBG << "[stage" << std::to_string(p.stage)
|
||||
<< "] users:" << p.users.size()
|
||||
<< " hinp:" << p.hash_inputs.size()
|
||||
<< " hout:" << p.hash_outputs.size()
|
||||
<< " lcl:" << p.lcl
|
||||
<< " self:" << self
|
||||
<< "\n";
|
||||
}
|
||||
|
||||
LOG_DBG << "timenow:" << std::to_string(ctx.time_now) << "\n";
|
||||
// Initialize vote counters
|
||||
vote_counter votes;
|
||||
|
||||
@@ -143,13 +145,14 @@ void consensus()
|
||||
|
||||
if (should_request_history)
|
||||
{
|
||||
//todo:create history request message and request request history from a random peer.
|
||||
//create history request message and request history from a random peer.
|
||||
send_ledger_history_request(ctx.lcl, majority_lcl);
|
||||
}
|
||||
if (is_lcl_desync)
|
||||
{
|
||||
const bool should_reset = (ctx.time_now - ctx.novel_proposal_time) < floor(conf::cfg.roundtime / 4);
|
||||
bool should_reset = (ctx.time_now - ctx.novel_proposal_time) > (floor(conf::cfg.roundtime) + floor(rand() % conf::cfg.roundtime));
|
||||
//for now we are resetting to stage 0 to avoid possible deadlock situations
|
||||
timewait_stage(true);
|
||||
timewait_stage(should_reset);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -166,13 +169,14 @@ void consensus()
|
||||
else
|
||||
++itr;
|
||||
}
|
||||
//ctx.candidate_proposals.clear();
|
||||
|
||||
if (ctx.stage == 3)
|
||||
{
|
||||
apply_ledger(stg_prop);
|
||||
|
||||
// We have finished a consensus round (all 4 stages).
|
||||
LOG_DBG << "****Stage 3 consensus reached****";
|
||||
LOG_INFO << "****Stage 3 consensus reached****";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -407,8 +411,6 @@ void check_majority_stage(bool &is_desync, bool &should_reset, uint8_t &majority
|
||||
// Vote stages if only proposal lcl is match with node's last consensus lcl
|
||||
if (cp.lcl == ctx.lcl)
|
||||
increment(votes.stage, cp.stage);
|
||||
|
||||
// todo:vote for lcl checking condtion
|
||||
}
|
||||
|
||||
majority_stage = 0;
|
||||
@@ -426,7 +428,7 @@ void check_majority_stage(bool &is_desync, bool &should_reset, uint8_t &majority
|
||||
|
||||
if (majority_stage < ctx.stage - 1)
|
||||
{
|
||||
should_reset = (ctx.time_now - ctx.novel_proposal_time) < floor(conf::cfg.roundtime / 4);
|
||||
should_reset = (ctx.time_now - ctx.novel_proposal_time) > (floor(conf::cfg.roundtime) + floor(rand() % conf::cfg.roundtime));
|
||||
is_desync = true;
|
||||
|
||||
LOG_DBG << "Stage desync (Reset:" << should_reset << "). Node stage:" << std::to_string(ctx.stage)
|
||||
@@ -496,11 +498,12 @@ void check_lcl_votes(bool &is_desync, bool &should_request_history, std::string
|
||||
{
|
||||
LOG_DBG << "We are not on the consensus ledger, requesting history from a random peer";
|
||||
is_desync = true;
|
||||
//todo:create history request message and request request history from a random peer.
|
||||
|
||||
should_request_history = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the consensus percentage threshold for the specified stage.
|
||||
* @param stage The consensus stage [1, 2, 3]
|
||||
@@ -533,8 +536,9 @@ void timewait_stage(const bool reset)
|
||||
*/
|
||||
void apply_ledger(const p2p::proposal &cons_prop)
|
||||
{
|
||||
ctx.led_seq_no++;
|
||||
ctx.lcl = cons::save_ledger(cons_prop, ctx.led_seq_no);
|
||||
const std::tuple<const uint64_t, std::string> new_lcl = save_ledger(cons_prop);
|
||||
ctx.led_seq_no = std::get<0>(new_lcl);
|
||||
ctx.lcl = std::get<1>(new_lcl);
|
||||
|
||||
// After the current ledger seq no is updated, we remove any newly expired inputs from candidate set.
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user