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>;
98 if (nextCutoff.consensusTime > currentCutoff.consensusTime ||
123 int const weight = support / total;
153 setVote(NodeID_t
const& peer,
bool votesYes);
160 unVote(NodeID_t
const& peer);
196template <
class Tx_t,
class NodeID_t>
200 auto const [it, inserted] = votes_.insert(
std::make_pair(peer, votesYes));
207 JLOG(j_.
debug()) <<
"Peer " << peer <<
" votes YES on " << tx_.id();
212 JLOG(j_.
debug()) <<
"Peer " << peer <<
" votes NO on " << tx_.id();
218 else if (votesYes && !it->second)
220 JLOG(j_.
debug()) <<
"Peer " << peer <<
" now votes YES on " << tx_.id();
227 else if (!votesYes && it->second)
229 JLOG(j_.
debug()) <<
"Peer " << peer <<
" now votes NO on " << tx_.id();
239template <
class Tx_t,
class NodeID_t>
243 auto it = votes_.find(peer);
245 if (it != votes_.end())
256template <
class Tx_t,
class NodeID_t>
263 if (ourVote_ && (nays_ == 0))
266 if (!ourVote_ && (yays_ == 0))
279 p, avalancheState_, percentTime, ++avalancheCounter_, p.
avMIN_ROUNDS);
282 avalancheState_ = *newState;
283 avalancheCounter_ = 0;
289 weight = (yays_ * 100 + (ourVote_ ? 100 : 0)) / (nays_ + yays_ + 1);
291 newPosition = weight > requiredPct;
297 newPosition = yays_ > nays_;
300 if (newPosition == ourVote_)
302 ++currentVoteCounter_;
303 JLOG(j_.
info()) <<
"No change (" << (ourVote_ ?
"YES" :
"NO") <<
") on "
304 << tx_.id() <<
" : weight " << weight <<
", percent "
306 <<
", round(s) with this vote: " << currentVoteCounter_;
311 currentVoteCounter_ = 0;
312 ourVote_ = newPosition;
313 JLOG(j_.
debug()) <<
"We now vote " << (ourVote_ ?
"YES" :
"NO") <<
" on "
319template <
class Tx_t,
class NodeID_t>
329 ret[
"our_vote"] = ourVote_;
334 for (
auto const& [nodeId, vote] : votes_)
336 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.
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.
bool stalled(ConsensusParms const &p, bool proposing, int peersUnchanged) const
Are we and our peers "stalled" where we probably won't change our 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...