Skip to content

Commit 614eb69

Browse files
committed
[WIP] Toying with the idea of VL exchange
* Log Validator Lists received from peers
1 parent 4eae037 commit 614eb69

3 files changed

Lines changed: 155 additions & 12 deletions

File tree

src/xrpld/app/misc/ValidatorList.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ class ValidatorList
363363
static std::vector<ValidatorBlobInfo>
364364
parseBlobs(protocol::TMValidatorListCollection const& body);
365365

366-
static void
366+
static std::optional<std::string>
367367
sendValidatorList(
368368
Peer& peer,
369369
std::uint64_t peerSequence,
@@ -375,6 +375,18 @@ class ValidatorList
375375
HashRouter& hashRouter,
376376
beast::Journal j);
377377

378+
std::tuple<
379+
std::string,
380+
std::uint32_t,
381+
std::map<std::size_t, ValidatorBlobInfo>,
382+
uint256>
383+
sendLatestValidatorLists(
384+
Peer& peer,
385+
std::uint64_t peerSequence,
386+
PublicKey const& publisherKey,
387+
HashRouter& hashRouter,
388+
beast::Journal j) const;
389+
378390
[[nodiscard]] static std::pair<std::size_t, std::size_t>
379391
buildValidatorListMessages(
380392
std::size_t messageVersion,
@@ -815,7 +827,7 @@ class ValidatorList
815827
HashRouter& hashRouter,
816828
beast::Journal j);
817829

818-
static void
830+
static std::optional<std::string>
819831
sendValidatorList(
820832
Peer& peer,
821833
std::uint64_t peerSequence,

src/xrpld/app/misc/detail/ValidatorList.cpp

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -735,8 +735,62 @@ ValidatorList::buildValidatorListMessages(
735735
return {0, 0};
736736
}
737737

738+
std::tuple<
739+
std::string,
740+
std::uint32_t,
741+
std::map<std::size_t, ValidatorBlobInfo>,
742+
uint256>
743+
ValidatorList::sendLatestValidatorLists(
744+
Peer& peer,
745+
std::uint64_t peerSequence,
746+
PublicKey const& publisherKey,
747+
HashRouter& hashRouter,
748+
beast::Journal j) const
749+
{
750+
std::vector<ValidatorList::MessageWithHash> messages;
751+
std::map<std::size_t, ValidatorBlobInfo> blobInfos;
752+
753+
if (publisherLists_.count(publisherKey) == 0)
754+
return {};
755+
ValidatorList::PublisherListCollection const& lists =
756+
publisherLists_.at(publisherKey);
757+
758+
auto const maxSequence = lists.current.sequence;
759+
ASSERT(
760+
lists.current.sequence == maxSequence ||
761+
lists.remaining.count(maxSequence) == 1,
762+
"ripple::ValidatorList::sendLatestValidatorLists : valid sequence");
763+
764+
if (peerSequence < maxSequence)
765+
{
766+
buildBlobInfos(blobInfos, lists);
767+
sendValidatorList(
768+
peer,
769+
peerSequence,
770+
publisherKey,
771+
maxSequence,
772+
lists.rawVersion,
773+
lists.rawManifest,
774+
blobInfos,
775+
messages,
776+
hashRouter,
777+
j);
778+
779+
// Suppress the messages so they'll be ignored next time.
780+
uint256 lasthash;
781+
for (auto const& m : messages)
782+
{
783+
lasthash = m.hash;
784+
hashRouter.addSuppressionPeer(lasthash, peer.id());
785+
}
786+
return std::make_tuple(
787+
lists.rawManifest, lists.rawVersion, blobInfos, lasthash);
788+
}
789+
return {};
790+
}
791+
738792
// static
739-
void
793+
std::optional<std::string>
740794
ValidatorList::sendValidatorList(
741795
Peer& peer,
742796
std::uint64_t peerSequence,
@@ -754,7 +808,7 @@ ValidatorList::sendValidatorList(
754808
: peer.supportsFeature(ProtocolFeature::ValidatorListPropagation) ? 1
755809
: 0;
756810
if (!messageVersion)
757-
return;
811+
return {};
758812
auto const [newPeerSequence, numVLs] = buildValidatorListMessages(
759813
messageVersion,
760814
peerSequence,
@@ -790,6 +844,7 @@ ValidatorList::sendValidatorList(
790844
if (sent)
791845
{
792846
if (messageVersion > 1)
847+
{
793848
JLOG(j.debug())
794849
<< "Sent " << messages.size()
795850
<< " validator list collection(s) containing " << numVLs
@@ -798,6 +853,8 @@ ValidatorList::sendValidatorList(
798853
<< newPeerSequence << " to "
799854
<< peer.getRemoteAddress().to_string() << " [" << peer.id()
800855
<< "]";
856+
return "ValidatorListCollection";
857+
}
801858
else
802859
{
803860
XRPL_ASSERT(
@@ -809,13 +866,15 @@ ValidatorList::sendValidatorList(
809866
<< " with sequence " << newPeerSequence << " to "
810867
<< peer.getRemoteAddress().to_string() << " [" << peer.id()
811868
<< "]";
869+
return "ValidatorList";
812870
}
813871
}
814872
}
873+
return {};
815874
}
816875

817876
// static
818-
void
877+
std::optional<std::string>
819878
ValidatorList::sendValidatorList(
820879
Peer& peer,
821880
std::uint64_t peerSequence,
@@ -828,7 +887,7 @@ ValidatorList::sendValidatorList(
828887
beast::Journal j)
829888
{
830889
std::vector<ValidatorList::MessageWithHash> messages;
831-
sendValidatorList(
890+
return sendValidatorList(
832891
peer,
833892
peerSequence,
834893
publisherKey,
@@ -899,7 +958,7 @@ ValidatorList::broadcastBlobs(
899958
std::map<std::size_t, ValidatorBlobInfo> blobInfos;
900959

901960
XRPL_ASSERT(
902-
lists.current.sequence == maxSequence ||
961+
lists.current.sequence <= maxSequence ||
903962
lists.remaining.count(maxSequence) == 1,
904963
"ripple::ValidatorList::broadcastBlobs : valid sequence");
905964
// Can't use overlay.foreach here because we need to modify

src/xrpld/overlay/detail/PeerImp.cpp

Lines changed: 77 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,46 @@ PeerImp::domain() const
848848

849849
// Protocol logic
850850

851+
void
852+
logVLBlob(beast::Journal j, ValidatorBlobInfo const& blob, std::size_t count)
853+
{
854+
auto const stream = j.trace();
855+
JLOG(stream) << "Blob " << count << " Signature: " << blob.signature;
856+
JLOG(stream) << "Blob " << count << " blob: " << base64_decode(blob.blob);
857+
JLOG(stream) << "Blob " << count << " manifest: "
858+
<< (blob.manifest ? base64_decode(*blob.manifest) : "NONE");
859+
}
860+
861+
void
862+
logVLBlob(
863+
beast::Journal j,
864+
std::pair<std::size_t, ValidatorBlobInfo> const& blob,
865+
std::size_t count)
866+
{
867+
logVLBlob(j, blob.second, count);
868+
}
869+
870+
template <class TBlobs>
871+
void
872+
logVL(
873+
beast::Journal j,
874+
std::string const& manifest,
875+
std::uint32_t version,
876+
TBlobs const& blobs,
877+
uint256 const& hash)
878+
{
879+
auto const stream = j.trace();
880+
JLOG(stream) << "Manifest: " << manifest;
881+
JLOG(stream) << "Version: " << version;
882+
JLOG(stream) << "Hash: " << hash;
883+
std::size_t count = 1;
884+
for (auto const& blob : blobs)
885+
{
886+
logVLBlob(j, blob, count);
887+
++count;
888+
}
889+
}
890+
851891
void
852892
PeerImp::doProtocolStart()
853893
{
@@ -2066,6 +2106,8 @@ PeerImp::onValidatorListMessage(
20662106
return;
20672107
}
20682108

2109+
logVL(p_journal_, manifest, version, blobs, hash);
2110+
20692111
auto const applyResult = app_.validators().applyListsAndBroadcast(
20702112
manifest,
20712113
version,
@@ -2108,7 +2150,8 @@ PeerImp::onValidatorListMessage(
21082150
"ripple::PeerImp::onValidatorListMessage : lower sequence");
21092151
}
21102152
#endif
2111-
publisherListSequences_[pubKey] = applyResult.sequence;
2153+
if (publisherListSequences_[pubKey] < applyResult.sequence)
2154+
publisherListSequences_[pubKey] = applyResult.sequence;
21122155
}
21132156
break;
21142157
case ListDisposition::same_sequence:
@@ -2127,8 +2170,37 @@ PeerImp::onValidatorListMessage(
21272170
}
21282171
#endif // !NDEBUG
21292172

2173+
[[fallthrough]];
2174+
case ListDisposition::stale: {
2175+
auto const [pubKey, currentPeerSeq] = [&]() {
2176+
std::lock_guard<std::mutex> sl(recentLock_);
2177+
ASSERT(
2178+
applyResult.sequence && applyResult.publisherKey,
2179+
"ripple::PeerImp::onValidatorListMessage : (stale) nonzero "
2180+
"sequence");
2181+
auto const& pubKey = *applyResult.publisherKey;
2182+
auto const& current = publisherListSequences_[pubKey];
2183+
ASSERT(
2184+
current <= applyResult.sequence,
2185+
"ripple::PeerImp::onValidatorListMessage : (stale) valid "
2186+
"sequence");
2187+
return std::make_pair(
2188+
pubKey, current ? current : applyResult.sequence);
2189+
}();
2190+
if (currentPeerSeq <= applyResult.sequence)
2191+
{
2192+
auto const [sentmanifest, sentversion, sentblobs, senthash] =
2193+
app_.validators().sendLatestValidatorLists(
2194+
*this,
2195+
currentPeerSeq,
2196+
pubKey,
2197+
app_.getHashRouter(),
2198+
p_journal_);
2199+
logVL(
2200+
p_journal_, sentmanifest, sentversion, sentblobs, senthash);
2201+
}
2202+
}
21302203
break;
2131-
case ListDisposition::stale:
21322204
case ListDisposition::untrusted:
21332205
case ListDisposition::invalid:
21342206
case ListDisposition::unsupported_version:
@@ -2219,7 +2291,7 @@ PeerImp::onValidatorListMessage(
22192291
break;
22202292
case ListDisposition::stale:
22212293
JLOG(p_journal_.warn())
2222-
<< "Ignored " << count << "stale " << messageType
2294+
<< "Ignored " << count << " stale " << messageType
22232295
<< "(s) from peer " << remote_address_;
22242296
break;
22252297
case ListDisposition::untrusted:
@@ -2229,12 +2301,12 @@ PeerImp::onValidatorListMessage(
22292301
break;
22302302
case ListDisposition::unsupported_version:
22312303
JLOG(p_journal_.warn())
2232-
<< "Ignored " << count << "unsupported version "
2304+
<< "Ignored " << count << " unsupported version "
22332305
<< messageType << "(s) from peer " << remote_address_;
22342306
break;
22352307
case ListDisposition::invalid:
22362308
JLOG(p_journal_.warn())
2237-
<< "Ignored " << count << "invalid " << messageType
2309+
<< "Ignored " << count << " invalid " << messageType
22382310
<< "(s) from peer " << remote_address_;
22392311
break;
22402312
default:

0 commit comments

Comments
 (0)