mirror of
https://github.com/EvernodeXRPL/hpcore.git
synced 2026-04-29 15:37:59 +00:00
Hpfs log file sync and fork detection. (#279)
Basic infrastructure for log file sync. A fork is detected by comparing the hpfs log index file against the ledger. Min and max ledger sequence hashes are sent to a full history node to request log history.
This commit is contained in:
committed by
GitHub
parent
99c5912f14
commit
af48f3b01f
@@ -12,6 +12,7 @@
|
||||
#include "peer_comm_session.hpp"
|
||||
#include "p2p.hpp"
|
||||
#include "../unl.hpp"
|
||||
#include "../sc/hpfs_log_sync.hpp"
|
||||
|
||||
namespace p2pmsg = msg::fbuf::p2pmsg;
|
||||
|
||||
@@ -108,6 +109,9 @@ namespace p2p
|
||||
// Remember the roundtime reported by this peer.
|
||||
session.reported_roundtime = chall.roundtime;
|
||||
|
||||
// Whether this node is a full history node or not.
|
||||
session.is_full_history = chall.is_full_history;
|
||||
|
||||
// Sending the challenge response to the sender.
|
||||
flatbuffers::FlatBufferBuilder fbuf;
|
||||
p2pmsg::create_peer_challenge_response_from_challenge(fbuf, chall.challenge);
|
||||
@@ -228,6 +232,40 @@ namespace p2p
|
||||
LOG_DEBUG << "Ledger hpfs response rejected. Maximum response count reached. " << session.display_name();
|
||||
}
|
||||
}
|
||||
else if (mi.type == p2pmsg::P2PMsgContent_LogRecordRequest)
|
||||
{
|
||||
if (conf::cfg.node.history == conf::HISTORY::FULL)
|
||||
{
|
||||
// Check the cap and insert log record request with lock.
|
||||
std::scoped_lock<std::mutex> lock(ctx.collected_msgs.log_record_request_mutex);
|
||||
|
||||
// If max number of log record requests reached, skip the rest.
|
||||
if (ctx.collected_msgs.log_record_requests.size() < p2p::LOG_RECORD_REQ_LIST_CAP)
|
||||
{
|
||||
const p2p::hpfs_log_request hpfs_log_request = p2pmsg::create_hpfs_log_request_from_msg(mi);
|
||||
ctx.collected_msgs.log_record_requests.push_back(std::make_pair(session.uniqueid, std::move(hpfs_log_request)));
|
||||
}
|
||||
else
|
||||
LOG_DEBUG << "Hpfs log request rejected. Maximum request count reached. " << session.display_name();
|
||||
}
|
||||
}
|
||||
else if (mi.type == p2pmsg::P2PMsgContent_LogRecordResponse)
|
||||
{
|
||||
if (conf::cfg.node.history == conf::HISTORY::FULL && sc::hpfs_log_sync::sync_ctx.is_syncing)
|
||||
{
|
||||
// Check the cap and insert log record response with lock.
|
||||
std::scoped_lock<std::mutex> lock(ctx.collected_msgs.log_record_response_mutex);
|
||||
|
||||
// If max number of log record responses reached, skip the rest.
|
||||
if (ctx.collected_msgs.log_record_responses.size() < p2p::LOG_RECORD_RES_LIST_CAP)
|
||||
{
|
||||
const p2p::hpfs_log_response hpfs_log_response = p2pmsg::create_hpfs_log_response_from_msg(mi);
|
||||
ctx.collected_msgs.log_record_responses.push_back(std::make_pair(session.uniqueid, std::move(hpfs_log_response)));
|
||||
}
|
||||
else
|
||||
LOG_DEBUG << "Hpfs log response rejected. Maximum response count reached. " << session.display_name();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
session.increment_metric(comm::SESSION_THRESHOLDS::MAX_BADMSGS_PER_MINUTE, 1);
|
||||
|
||||
Reference in New Issue
Block a user