20#ifndef RIPPLE_APP_CONSENSUS_IMPL_DISPUTEDTX_H_INCLUDED
21#define RIPPLE_APP_CONSENSUS_IMPL_DISPUTEDTX_H_INCLUDED
23#include <xrpld/consensus/ConsensusParms.h>
25#include <xrpl/basics/Log.h>
26#include <xrpl/beast/utility/Journal.h>
27#include <xrpl/json/json_writer.h>
29#include <boost/container/flat_map.hpp>
47template <
class Tx_t,
class NodeID_t>
51 using Map_t = boost::container::flat_map<NodeID_t, bool>;
103 if (nextCutoff.consensusTime > currentCutoff.consensusTime ||
128 int const weight = support / total;
139 s <<
"Transaction " <<
ID() <<
" is stalled. We have been voting "
141 <<
" rounds. Peers have not changed their votes in "
142 << peersUnchanged <<
" rounds. The transaction has " << weight
145 CLOG(clog) << s.
str();
174 setVote(NodeID_t
const& peer,
bool votesYes);
181 unVote(NodeID_t
const& peer);
217template <
class Tx_t,
class NodeID_t>
221 auto const [it, inserted] = votes_.insert(
std::make_pair(peer, votesYes));
228 JLOG(j_.
debug()) <<
"Peer " << peer <<
" votes YES on " << tx_.id();
233 JLOG(j_.
debug()) <<
"Peer " << peer <<
" votes NO on " << tx_.id();
239 else if (votesYes && !it->second)
241 JLOG(j_.
debug()) <<
"Peer " << peer <<
" now votes YES on " << tx_.id();
248 else if (!votesYes && it->second)
250 JLOG(j_.
debug()) <<
"Peer " << peer <<
" now votes NO on " << tx_.id();
260template <
class Tx_t,
class NodeID_t>
264 auto it = votes_.find(peer);
266 if (it != votes_.end())
277template <
class Tx_t,
class NodeID_t>
284 if (ourVote_ && (nays_ == 0))
287 if (!ourVote_ && (yays_ == 0))
300 p, avalancheState_, percentTime, ++avalancheCounter_, p.
avMIN_ROUNDS);
303 avalancheState_ = *newState;
304 avalancheCounter_ = 0;
310 weight = (yays_ * 100 + (ourVote_ ? 100 : 0)) / (nays_ + yays_ + 1);
312 newPosition = weight > requiredPct;
318 newPosition = yays_ > nays_;
321 if (newPosition == ourVote_)
323 ++currentVoteCounter_;
324 JLOG(j_.
info()) <<
"No change (" << (ourVote_ ?
"YES" :
"NO") <<
") on "
325 << tx_.id() <<
" : weight " << weight <<
", percent "
327 <<
", round(s) with this vote: " << currentVoteCounter_;
332 currentVoteCounter_ = 0;
333 ourVote_ = newPosition;
334 JLOG(j_.
debug()) <<
"We now vote " << (ourVote_ ?
"YES" :
"NO") <<
" on "
340template <
class Tx_t,
class NodeID_t>
350 ret[
"our_vote"] = ourVote_;
355 for (
auto const& [nodeId, vote] : votes_)
357 ret[
"votes"] = std::move(votesj);
Decorator for streaming out compact json.
A generic endpoint for log messages.
A transaction discovered to be in dispute during consensus.
std::size_t avalancheCounter_
How long we have been in the current acceptance phase.
std::size_t currentVoteCounter_
The number of rounds we've gone without changing our vote.
Json::Value getJson() const
JSON representation of dispute, used for debugging.
bool updateVote(int percentTime, bool proposing, ConsensusParms const &p)
Update our vote given progression of consensus.
boost::container::flat_map< NodeID_t, bool > Map_t
bool setVote(NodeID_t const &peer, bool votesYes)
Change a peer's vote.
ConsensusParms::AvalancheState avalancheState_
Which minimum acceptance percentage phase we are currently in.
Tx_t const & tx() const
The disputed transaction.
bool stalled(ConsensusParms const &p, bool proposing, int peersUnchanged, beast::Journal j, std::unique_ptr< std::stringstream > const &clog) const
Are we and our peers "stalled" where we probably won't change our vote?
DisputedTx(Tx_t const &tx, bool ourVote, std::size_t numPeers, beast::Journal j)
Constructor.
bool getOurVote() const
Our vote on whether the transaction should be included.
void setOurVote(bool o)
Change our vote.
TxID_t const & ID() const
The unique id/hash of the disputed transaction.
void unVote(NodeID_t const &peer)
Remove a peer's vote.
@ objectValue
object value (collection of name/value pairs).
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
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)
@ proposing
We are normal participant in consensus and propose our position.
std::string to_string(base_uint< Bits, Tag > const &a)
Json::Value getJson(LedgerFill const &fill)
Return a new Json::Value representing the ledger with given options.
Consensus algorithm parameters.
std::size_t const avSTALLED_ROUNDS
Number of rounds before a stuck vote is considered unlikely to change because voting stalled.
std::size_t const avMIN_ROUNDS
Number of rounds before certain actions can happen.
std::size_t const minCONSENSUS_PCT
The percentage threshold above which we can declare consensus.
std::map< AvalancheState, AvalancheCutoff > const avalancheCutoffs
Map the consensus requirement avalanche state to the amount of time that must pass before moving to t...