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>;
105 setVote(NodeID_t
const& peer,
bool votesYes);
112 unVote(NodeID_t
const& peer);
142template <
class Tx_t,
class NodeID_t>
146 auto const [it, inserted] = votes_.insert(
std::make_pair(peer, votesYes));
153 JLOG(j_.
debug()) <<
"Peer " << peer <<
" votes YES on " << tx_.id();
158 JLOG(j_.
debug()) <<
"Peer " << peer <<
" votes NO on " << tx_.id();
163 else if (votesYes && !it->second)
165 JLOG(j_.
debug()) <<
"Peer " << peer <<
" now votes YES on " << tx_.id();
171 else if (!votesYes && it->second)
173 JLOG(j_.
debug()) <<
"Peer " << peer <<
" now votes NO on " << tx_.id();
181template <
class Tx_t,
class NodeID_t>
185 auto it = votes_.find(peer);
187 if (it != votes_.end())
198template <
class Tx_t,
class NodeID_t>
205 if (ourVote_ && (nays_ == 0))
208 if (!ourVote_ && (yays_ == 0))
217 weight = (yays_ * 100 + (ourVote_ ? 100 : 0)) / (nays_ + yays_ + 1);
234 newPosition = yays_ > nays_;
237 if (newPosition == ourVote_)
239 JLOG(j_.
info()) <<
"No change (" << (ourVote_ ?
"YES" :
"NO")
240 <<
") : weight " << weight <<
", percent "
246 ourVote_ = newPosition;
247 JLOG(j_.
debug()) <<
"We now vote " << (ourVote_ ?
"YES" :
"NO") <<
" on "
253template <
class Tx_t,
class NodeID_t>
263 ret[
"our_vote"] = ourVote_;
268 for (
auto const& [nodeId, vote] : votes_)
270 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.
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
Tx_t const & tx() const
The disputed transaction.
void setVote(NodeID_t const &peer, bool votesYes)
Change a peer's 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.
@ 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 avINIT_CONSENSUS_PCT
Percentage of nodes on our UNL that must vote yes.
std::size_t avLATE_CONSENSUS_PCT
Percentage of nodes that most vote yes after advancing.
std::size_t avSTUCK_CONSENSUS_PCT
Percentage of nodes that must vote yes after we are stuck.
std::size_t avLATE_CONSENSUS_TIME
Percentage of previous round duration before we advance.
std::size_t avMID_CONSENSUS_PCT
Percentage of nodes that most vote yes after advancing.
std::size_t avSTUCK_CONSENSUS_TIME
Percentage of previous round duration before we are stuck.
std::size_t avMID_CONSENSUS_TIME
Percentage of previous round duration before we advance.