mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Propagate validator lists (VLs or UNLs) over the peer network:
* Whenever a node downloads a new VL, send it to all peers that haven't already sent or received it. It also saves it to the database_dir as a Json text file named "cache." plus the public key of the list signer. Any files that exist for public keys provided in [validator_list_keys] will be loaded and processed if any download from [validator_list_sites] fails or no [validator_list_sites] are configured. * Whenever a node receives a broadcast VL message, it treats it as if it had downloaded it on it's own, broadcasting to other peers as described above. * Because nodes normally download the VL once every 5 minutes, a single node downloading a VL with an updated sequence number could potentially propagate across a large part of a well-connected network before any other nodes attempt to download, decreasing the amount of time that different parts of the network are using different VLs. * Send all of our current valid VLs to new peers on connection. This is probably the "noisiest" part of this change, but will give poorly connected or poorly networked nodes the best chance of syncing quickly. Nodes which have no http(s) access configured or available can get a VL with no extra effort. * Requests on the peer port to the /vl/<pubkey> endpoint will return that VL in the same JSON format as is used to download now, IF the node trusts and has a valid instance of that VL. * Upgrade protocol version to 2.1. VLs will only be sent to 2.1 and higher nodes. * Resolves #2953
This commit is contained in:
committed by
Manoj doshi
parent
3753840de5
commit
2c71802e38
@@ -405,6 +405,17 @@ PeerImp::json()
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool
|
||||
PeerImp::supportsFeature(ProtocolFeature f) const
|
||||
{
|
||||
switch (f)
|
||||
{
|
||||
case ProtocolFeature::ValidatorListPropagation:
|
||||
return protocol_ >= make_protocol(2, 1);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
bool
|
||||
@@ -803,6 +814,36 @@ PeerImp::doProtocolStart()
|
||||
{
|
||||
onReadMessage(error_code(), 0);
|
||||
|
||||
// Send all the validator lists that have been loaded
|
||||
if (supportsFeature(ProtocolFeature::ValidatorListPropagation))
|
||||
{
|
||||
app_.validators().for_each_available(
|
||||
[&](std::string const& manifest,
|
||||
std::string const& blob, std::string const& signature,
|
||||
std::uint32_t version,
|
||||
PublicKey const& pubKey, std::size_t sequence,
|
||||
uint256 const& hash)
|
||||
{
|
||||
protocol::TMValidatorList vl;
|
||||
|
||||
vl.set_manifest(manifest);
|
||||
vl.set_blob(blob);
|
||||
vl.set_signature(signature);
|
||||
vl.set_version(version);
|
||||
|
||||
JLOG(p_journal_.debug()) << "Sending validator list for " <<
|
||||
strHex(pubKey) << " with sequence " <<
|
||||
sequence << " to " <<
|
||||
remote_address_.to_string() << " (" << id_ << ")";
|
||||
auto m = std::make_shared<Message>(vl, protocol::mtVALIDATORLIST);
|
||||
send(m);
|
||||
// Don't send it next time.
|
||||
app_.getHashRouter().addSuppressionPeer(hash, id_);
|
||||
setPublisherListSequence(pubKey, sequence);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
protocol::TMManifests tm;
|
||||
|
||||
app_.validatorManifests ().for_each_manifest (
|
||||
@@ -1965,6 +2006,137 @@ PeerImp::onMessage (std::shared_ptr <protocol::TMHaveTransactionSet> const& m)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
PeerImp::onMessage (std::shared_ptr <protocol::TMValidatorList> const& m)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!supportsFeature(ProtocolFeature::ValidatorListPropagation))
|
||||
{
|
||||
JLOG(p_journal_.debug())
|
||||
<< "ValidatorList: received validator list from peer using "
|
||||
<< "protocol version " << to_string(protocol_)
|
||||
<< " which shouldn't support this feature.";
|
||||
fee_ = Resource::feeUnwantedData;
|
||||
return;
|
||||
}
|
||||
auto const& manifest = m->manifest();
|
||||
auto const& blob = m->blob();
|
||||
auto const& signature = m->signature();
|
||||
auto const version = m->version();
|
||||
auto const hash = sha512Half(manifest, blob, signature, version);
|
||||
|
||||
JLOG(p_journal_.debug()) << "Received validator list from " <<
|
||||
remote_address_.to_string() << " (" << id_ << ")";
|
||||
|
||||
if (! app_.getHashRouter ().addSuppressionPeer(hash, id_))
|
||||
{
|
||||
JLOG(p_journal_.debug()) <<
|
||||
"ValidatorList: received duplicate validator list";
|
||||
// Charging this fee here won't hurt the peer in the normal
|
||||
// course of operation (ie. refresh every 5 minutes), but
|
||||
// will add up if the peer is misbehaving.
|
||||
fee_ = Resource::feeUnwantedData;
|
||||
return;
|
||||
}
|
||||
|
||||
auto const applyResult = app_.validators().applyListAndBroadcast (
|
||||
manifest,
|
||||
blob,
|
||||
signature,
|
||||
version,
|
||||
remote_address_.to_string(),
|
||||
hash,
|
||||
app_.overlay(),
|
||||
app_.getHashRouter());
|
||||
auto const disp = applyResult.disposition;
|
||||
|
||||
JLOG(p_journal_.debug()) << "Processed validator list from " <<
|
||||
(applyResult.publisherKey ? strHex(*applyResult.publisherKey) :
|
||||
"unknown or invalid publisher") << " from " <<
|
||||
remote_address_.to_string() << " (" << id_ << ") with result " <<
|
||||
to_string(disp);
|
||||
|
||||
switch (disp)
|
||||
{
|
||||
case ListDisposition::accepted:
|
||||
JLOG (p_journal_.debug()) <<
|
||||
"Applied new validator list from peer " << remote_address_;
|
||||
{
|
||||
std::lock_guard<std::mutex> sl(recentLock_);
|
||||
|
||||
assert(applyResult.sequence && applyResult.publisherKey);
|
||||
auto const& pubKey = *applyResult.publisherKey;
|
||||
#ifndef NDEBUG
|
||||
if (auto const iter = publisherListSequences_.find(pubKey);
|
||||
iter != publisherListSequences_.end())
|
||||
{
|
||||
assert(iter->second < *applyResult.sequence);
|
||||
}
|
||||
#endif
|
||||
publisherListSequences_[pubKey] = *applyResult.sequence;
|
||||
}
|
||||
break;
|
||||
case ListDisposition::same_sequence:
|
||||
JLOG (p_journal_.warn()) <<
|
||||
"Validator list with current sequence from peer " <<
|
||||
remote_address_;
|
||||
// Charging this fee here won't hurt the peer in the normal
|
||||
// course of operation (ie. refresh every 5 minutes), but
|
||||
// will add up if the peer is misbehaving.
|
||||
fee_ = Resource::feeUnwantedData;
|
||||
#ifndef NDEBUG
|
||||
{
|
||||
std::lock_guard<std::mutex> sl(recentLock_);
|
||||
assert(applyResult.sequence && applyResult.publisherKey);
|
||||
assert(publisherListSequences_[*applyResult.publisherKey]
|
||||
== *applyResult.sequence);
|
||||
}
|
||||
#endif // !NDEBUG
|
||||
|
||||
break;
|
||||
case ListDisposition::stale:
|
||||
JLOG (p_journal_.warn()) <<
|
||||
"Stale validator list from peer " << remote_address_;
|
||||
// There are very few good reasons for a peer to send an
|
||||
// old list, particularly more than once.
|
||||
fee_ = Resource::feeBadData;
|
||||
break;
|
||||
case ListDisposition::untrusted:
|
||||
JLOG (p_journal_.warn()) <<
|
||||
"Untrusted validator list from peer " << remote_address_;
|
||||
// Charging this fee here won't hurt the peer in the normal
|
||||
// course of operation (ie. refresh every 5 minutes), but
|
||||
// will add up if the peer is misbehaving.
|
||||
fee_ = Resource::feeUnwantedData;
|
||||
break;
|
||||
case ListDisposition::invalid:
|
||||
JLOG (p_journal_.warn()) <<
|
||||
"Invalid validator list from peer " << remote_address_;
|
||||
// This shouldn't ever happen with a well-behaved peer
|
||||
fee_ = Resource::feeInvalidSignature;
|
||||
break;
|
||||
case ListDisposition::unsupported_version:
|
||||
JLOG (p_journal_.warn()) <<
|
||||
"Unsupported version validator list from peer " <<
|
||||
remote_address_;
|
||||
// During a version transition, this may be legitimate.
|
||||
// If it happens frequently, that's probably bad.
|
||||
fee_ = Resource::feeBadData;
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
catch (std::exception const& e)
|
||||
{
|
||||
JLOG(p_journal_.warn()) <<
|
||||
"ValidatorList: Exception, " << e.what() <<
|
||||
" from peer " << remote_address_;
|
||||
fee_ = Resource::feeBadData;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
PeerImp::onMessage (std::shared_ptr <protocol::TMValidation> const& m)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user