limited testing of multiple vl key behaviour

This commit is contained in:
Richard Holland
2023-09-29 11:48:40 +00:00
parent a08f21d900
commit 28b8be7d8e
3 changed files with 77 additions and 36 deletions

View File

@@ -158,14 +158,13 @@ NegativeUNLVote::addReportingTx(
} }
} }
void std::vector<STTx>
NegativeUNLVote::addImportVLTx( NegativeUNLVote::generateImportVLVoteTx(
LedgerIndex seq, std::map<std::string, PublicKey> const& importVLKeys,
std::shared_ptr<SHAMap> const& initalSet) LedgerIndex seq)
{ {
// do import VL key voting std::vector<STTx> out;
auto const& keyMap = app_.config().IMPORT_VL_KEYS; for (auto const& [_, pk] : importVLKeys)
for (auto const& [_, pk] : keyMap)
{ {
STTx repUnlTx(ttUNL_REPORT, [pk = pk, seq](auto& obj) STTx repUnlTx(ttUNL_REPORT, [pk = pk, seq](auto& obj)
{ {
@@ -178,6 +177,23 @@ NegativeUNLVote::addImportVLTx(
obj.setFieldU32(sfLedgerSequence, seq); obj.setFieldU32(sfLedgerSequence, seq);
}); });
out.push_back(std::move(repUnlTx));
}
return out;
}
void
NegativeUNLVote::addImportVLTx(
LedgerIndex seq,
std::shared_ptr<SHAMap> const& initalSet)
{
// do import VL key voting
std::vector<STTx> toInject =
generateImportVLVoteTx(app_.config().IMPORT_VL_KEYS, seq);
for (auto const& repUnlTx: toInject)
{
uint256 txID = repUnlTx.getTransactionID(); uint256 txID = repUnlTx.getTransactionID();
Serializer s; Serializer s;
repUnlTx.add(s); repUnlTx.add(s);

View File

@@ -123,6 +123,16 @@ public:
void void
newValidators(LedgerIndex seq, hash_set<NodeID> const& nowTrusted); newValidators(LedgerIndex seq, hash_set<NodeID> 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<STTx>
generateImportVLVoteTx(
std::map<std::string, PublicKey> const& importVLKeys,
LedgerIndex seq);
private: private:
NodeID const myId_; NodeID const myId_;
beast::Journal j_; beast::Journal j_;
@@ -163,6 +173,7 @@ private:
hash_map<NodeID, std::uint32_t> const& scoreTable, hash_map<NodeID, std::uint32_t> const& scoreTable,
hash_map<NodeID, PublicKey> const& nidToKeyMap, hash_map<NodeID, PublicKey> const& nidToKeyMap,
std::shared_ptr<SHAMap> const& initalSet); std::shared_ptr<SHAMap> const& initalSet);
/** /**
* As above, but make a vl import report object instead of an n-unl * As above, but make a vl import report object instead of an n-unl
*/ */

View File

@@ -523,11 +523,11 @@ class UNLReportFork_test : public beast::unit_test::suite
using namespace csf; using namespace csf;
using namespace std::chrono; using namespace std::chrono;
std::vector<PublicKey> ivlKeys; std::vector<std::pair<std::string, PublicKey>> ivlKeys;
for (auto const& strPk : _ivlKeys) for (auto const& strPk : _ivlKeys)
{ {
auto pkHex = strUnHex(strPk); auto pkHex = strUnHex(strPk);
ivlKeys.emplace_back(makeSlice(*pkHex)); ivlKeys.emplace_back(strPk, makeSlice(*pkHex));
} }
std::vector<PublicKey> vlKeys; std::vector<PublicKey> vlKeys;
@@ -560,44 +560,58 @@ class UNLReportFork_test : public beast::unit_test::suite
sim.collectors.add(sc); sim.collectors.add(sc);
for (TrustGraph<Peer*>::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 // set prior state
sim.run(1); sim.run(255);
PeerGroup wrongImportVLNodes = d + e; 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<std::string, PublicKey>
{
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) for (Peer* peer : network)
{ {
uint32_t seq = uint32_t(peer->lastClosedLedger.seq()) + 1;
peer->submit(Tx(0)); peer->txInjections.emplace(seq, Tx(wrongImportVLNodes.contains(peer) ? 1 : 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<SHAMap>(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));
}
} }
sim.run(4); 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 << "Branches: " << sim.branches() << "\n";
std::cout << "Fully synchronized: " << std::boolalpha std::cout << "Fully synchronized: " << std::boolalpha
<< sim.synchronized() << "\n"; << sim.synchronized() << "\n";
// Not tessting anything currently.
pass();
BEAST_EXPECT(sim.synchronized());
BEAST_EXPECT(sim.branches() == 1);
} }
void void