3#include <xrpld/consensus/ConsensusParms.h>
5#include <xrpl/basics/Log.h>
6#include <xrpl/beast/utility/Journal.h>
7#include <xrpl/json/json_writer.h>
9#include <boost/container/flat_map.hpp>
29template <
class Tx,
class NodeId>
33 using Map_t = boost::container::flat_map<NodeId, bool>;
50 [[nodiscard]]
TxID_t const&
81 if (nextCutoff.consensusTime > currentCutoff.consensusTime ||
101 int const support = (
yays_ + (proposing &&
ourVote_ ? 1 : 0)) * 100;
102 int const total =
nays_ +
yays_ + (proposing ? 1 : 0);
108 int const weight = support / total;
118 s <<
"Transaction " <<
id() <<
" is stalled. We have been voting "
120 <<
" rounds. Peers have not changed their votes in " << peersUnchanged
121 <<
" rounds. The transaction has " << weight <<
"% support. ";
122 JLOG(
j_.error()) << s.
str();
123 CLOG(clog) << s.
str();
130 [[nodiscard]] Tx
const&
195template <
class Tx,
class NodeId>
206 JLOG(
j_.debug()) <<
"Peer " << peer <<
" votes YES on " <<
tx_.id();
211 JLOG(
j_.debug()) <<
"Peer " << peer <<
" votes NO on " <<
tx_.id();
217 if (votesYes && !it->second)
219 JLOG(
j_.debug()) <<
"Peer " << peer <<
" now votes YES on " <<
tx_.id();
226 if (!votesYes && it->second)
228 JLOG(
j_.debug()) <<
"Peer " << peer <<
" now votes NO on " <<
tx_.id();
238template <
class Tx,
class NodeId>
242 auto it =
votes_.find(peer);
259template <
class Tx,
class NodeId>
269 bool newPosition =
false;
278 auto const [requiredPct, newState] =
291 newPosition = weight > requiredPct;
303 JLOG(
j_.info()) <<
"No change (" << (
ourVote_ ?
"YES" :
"NO") <<
") on " <<
tx_.id()
304 <<
" : weight " << weight <<
", percent " << percentTime
312 JLOG(
j_.debug()) <<
"We now vote " << (
ourVote_ ?
"YES" :
"NO") <<
" on " <<
tx_.id();
317template <
class Tx,
class NodeId>
332 for (
auto const& [nodeId, vote] :
votes_)
334 ret[
"votes"] = std::move(votes);
A generic endpoint for log messages.
Decorator for streaming out compact json.
ConsensusParms::AvalancheState avalancheState_
std::size_t currentVoteCounter_
void setOurVote(bool o)
Change our vote.
TxID_t const & id() const
The unique id/hash of the disputed transaction.
boost::container::flat_map< NodeID_t, bool > Map_t
json::Value getJson() const
JSON representation of dispute, used for debugging.
void unVote(NodeId const &peer)
Remove a peer's vote.
bool updateVote(int percentTime, bool proposing, ConsensusParms const &p)
Update our vote given progression of consensus.
bool setVote(NodeId const &peer, bool votesYes)
Change a peer's vote.
DisputedTx(Tx tx, bool ourVote, std::size_t numPeers, beast::Journal j)
Constructor.
bool stalled(ConsensusParms const &p, bool proposing, int peersUnchanged, beast::Journal j, std::unique_ptr< std::stringstream > const &clog) const
std::size_t avalancheCounter_
bool getOurVote() const
Our vote on whether the transaction should be included.
@ Object
object value (collection of name/value pairs).
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::string to_string(BaseUInt< Bits, Tag > const &a)
json::Value getJson(LedgerFill const &fill)
Return a new json::Value representing the ledger with given options.
std::pair< std::size_t, std::optional< ConsensusParms::AvalancheState > > getNeededWeight(ConsensusParms const &p, ConsensusParms::AvalancheState currentState, int percentTime, std::size_t currentRounds, std::size_t minimumRounds)
Consensus algorithm parameters.
std::size_t const avMinRounds
Number of rounds before certain actions can happen.
std::size_t const avStalledRounds
std::map< AvalancheState, AvalancheCutoff > const avalancheCutoffs
std::size_t const minConsensusPct
The percentage threshold above which we can declare consensus.