From 28b8be7d8e017e7b0c1d00e66593bb8ca96e222e Mon Sep 17 00:00:00 2001 From: Richard Holland Date: Fri, 29 Sep 2023 11:48:40 +0000 Subject: [PATCH] limited testing of multiple vl key behaviour --- src/ripple/app/misc/NegativeUNLVote.cpp | 30 ++++++++--- src/ripple/app/misc/NegativeUNLVote.h | 11 ++++ src/test/consensus/UNLReport_test.cpp | 72 +++++++++++++++---------- 3 files changed, 77 insertions(+), 36 deletions(-) diff --git a/src/ripple/app/misc/NegativeUNLVote.cpp b/src/ripple/app/misc/NegativeUNLVote.cpp index f6a248068..4906fa7b9 100644 --- a/src/ripple/app/misc/NegativeUNLVote.cpp +++ b/src/ripple/app/misc/NegativeUNLVote.cpp @@ -158,14 +158,13 @@ NegativeUNLVote::addReportingTx( } } -void -NegativeUNLVote::addImportVLTx( - LedgerIndex seq, - std::shared_ptr const& initalSet) +std::vector +NegativeUNLVote::generateImportVLVoteTx( + std::map const& importVLKeys, + LedgerIndex seq) { - // do import VL key voting - auto const& keyMap = app_.config().IMPORT_VL_KEYS; - for (auto const& [_, pk] : keyMap) + std::vector out; + for (auto const& [_, pk] : importVLKeys) { STTx repUnlTx(ttUNL_REPORT, [pk = pk, seq](auto& obj) { @@ -178,6 +177,23 @@ NegativeUNLVote::addImportVLTx( obj.setFieldU32(sfLedgerSequence, seq); }); + out.push_back(std::move(repUnlTx)); + } + + return out; +} + +void +NegativeUNLVote::addImportVLTx( + LedgerIndex seq, + std::shared_ptr const& initalSet) +{ + // do import VL key voting + std::vector toInject = + generateImportVLVoteTx(app_.config().IMPORT_VL_KEYS, seq); + + for (auto const& repUnlTx: toInject) + { uint256 txID = repUnlTx.getTransactionID(); Serializer s; repUnlTx.add(s); diff --git a/src/ripple/app/misc/NegativeUNLVote.h b/src/ripple/app/misc/NegativeUNLVote.h index 7909f7d8e..0511c5c9c 100644 --- a/src/ripple/app/misc/NegativeUNLVote.h +++ b/src/ripple/app/misc/NegativeUNLVote.h @@ -123,6 +123,16 @@ public: void newValidators(LedgerIndex seq, hash_set const& nowTrusted); + /** + * This generates UNLReport txns for each of the ImportVL keys in the node's + * config. Exposed publicly here so that it can be used by test cases in future. + */ + static + std::vector + generateImportVLVoteTx( + std::map const& importVLKeys, + LedgerIndex seq); + private: NodeID const myId_; beast::Journal j_; @@ -163,6 +173,7 @@ private: hash_map const& scoreTable, hash_map const& nidToKeyMap, std::shared_ptr const& initalSet); + /** * As above, but make a vl import report object instead of an n-unl */ diff --git a/src/test/consensus/UNLReport_test.cpp b/src/test/consensus/UNLReport_test.cpp index fa5ad7d3b..078593c85 100644 --- a/src/test/consensus/UNLReport_test.cpp +++ b/src/test/consensus/UNLReport_test.cpp @@ -523,11 +523,11 @@ class UNLReportFork_test : public beast::unit_test::suite using namespace csf; using namespace std::chrono; - std::vector ivlKeys; + std::vector> ivlKeys; for (auto const& strPk : _ivlKeys) { auto pkHex = strUnHex(strPk); - ivlKeys.emplace_back(makeSlice(*pkHex)); + ivlKeys.emplace_back(strPk, makeSlice(*pkHex)); } std::vector vlKeys; @@ -560,44 +560,58 @@ class UNLReportFork_test : public beast::unit_test::suite sim.collectors.add(sc); - for (TrustGraph::ForkInfo const& fi : - sim.trustGraph.forkablePairs(0.8)) - { - std::cout << "Can fork " << PeerGroup{fi.unlA} << " " - << " " << PeerGroup{fi.unlB} << " overlap " << fi.overlap - << " required " << fi.required << "\n"; - }; - // set prior state - sim.run(1); + sim.run(255); PeerGroup wrongImportVLNodes = d + e; - // All peers see some TX 0 + + // RH TODO: replace this simulation with a better one where we use actual UNLReport txns + /* + auto txns = + NegativeUNLVote::generateImportVLVoteTx( + std::map + { + ivlKeys[wrongImportVLNodes.contains(peer) ? 1 : 0] + }, seq); + */ + + // 2 of the 3 vote for one and the other 3 for the other for (Peer* peer : network) { - - peer->submit(Tx(0)); - // Peers 4,5 will close the next ledger differently by injecting - // a non-consensus approved transaciton - - if (wrongImportVLNodes.contains(peer)) - { - // NegativeUNLVote vote(myId, peer->j, history.env.app()); - // pre(vote); - // auto txSet = std::make_shared(SHAMapType::TRANSACTION, history.env.app().getNodeFamily()); - // addImportVLTx(peer->lastClosedLedger.seq(), txSet); - std::cout << "seq(): " << peer->lastClosedLedger.seq() << "\n"; - STTx tx = createUNLRTx1(peer->lastClosedLedger.seq(), ivlKeys[1], vlKeys[0]); - peer->txInjections.emplace(peer->lastClosedLedger.seq(), Tx(47)); - } + uint32_t seq = uint32_t(peer->lastClosedLedger.seq()) + 1; + peer->txInjections.emplace(seq, Tx(wrongImportVLNodes.contains(peer) ? 1 : 0)); } + sim.run(4); + + // all 5 vote for one but 3 of them also vote for the other + for (Peer* peer : network) + { + uint32_t seq = uint32_t(peer->lastClosedLedger.seq()) + 1; + + if (!wrongImportVLNodes.contains(peer)) + peer->txInjections.emplace(seq, Tx(2)); + peer->txInjections.emplace(seq, Tx(3)); + } + + // RH TODO: check that ledgers closed with the correct number of txns + /* + sim.run(1); + for (Peer* peer : network) + { + peer->lastClosedLedger + } + */ + + + sim.run(4); + std::cout << "Branches: " << sim.branches() << "\n"; std::cout << "Fully synchronized: " << std::boolalpha << sim.synchronized() << "\n"; - // Not tessting anything currently. - pass(); + BEAST_EXPECT(sim.synchronized()); + BEAST_EXPECT(sim.branches() == 1); } void