xrpld
Loading...
Searching...
No Matches
RCLCxPeerPos.cpp
1#include <xrpld/app/consensus/RCLCxPeerPos.h>
2
3#include <xrpl/basics/Slice.h>
4#include <xrpl/basics/base_uint.h>
5#include <xrpl/basics/chrono.h>
6#include <xrpl/beast/utility/instrumentation.h>
7#include <xrpl/json/json_value.h>
8#include <xrpl/protocol/PublicKey.h>
9#include <xrpl/protocol/Serializer.h>
10#include <xrpl/protocol/jss.h>
11#include <xrpl/protocol/tokens.h>
12
13#include <cstdint>
14
15namespace xrpl {
16
17// Used to construct received proposals
19 PublicKey const& publicKey,
20 Slice const& signature,
21 uint256 const& suppression,
22 Proposal const& proposal) // trivially copyable
24{
25 // The maximum allowed size of a signature is 72 bytes; we verify
26 // this elsewhere, but we want to be extra careful here:
27 XRPL_ASSERT(
28 !signature.empty() && signature.size() <= signature_.capacity(),
29 "xrpl::RCLCxPeerPos::RCLCxPeerPos : valid signature size");
30
31 if (!signature.empty() && signature.size() <= signature_.capacity())
32 signature_.assign(signature.begin(), signature.end());
33}
34
35bool
37{
38 return verifyDigest(publicKey(), proposal_.signingHash(), signature(), false);
39}
40
43{
44 auto ret = proposal().getJson();
45
46 if (publicKey().size() != 0u)
47 ret[jss::peer_id] = toBase58(TokenType::NodePublic, publicKey());
48
49 return ret;
50}
51
54 uint256 const& proposeHash,
55 uint256 const& previousLedger,
56 std::uint32_t proposeSeq,
57 NetClock::time_point closeTime,
58 Slice const& publicKey,
59 Slice const& signature)
60{
61 Serializer s(512);
62 s.addBitString(proposeHash);
63 s.addBitString(previousLedger);
64 s.add32(proposeSeq);
65 s.add32(closeTime.time_since_epoch().count());
66 s.addVL(publicKey);
67 s.addVL(signature);
68
69 return s.getSHA512Half();
70}
71
72} // namespace xrpl
Represents a JSON value.
Definition json_value.h:130
json::Value getJson() const
Get JSON representation for debugging.
std::chrono::time_point< NetClock > time_point
Definition chrono.h:46
A public key.
Definition PublicKey.h:42
PublicKey const & publicKey() const
Public key of peer that sent the proposal.
RCLCxPeerPos(PublicKey const &publicKey, Slice const &signature, uint256 const &suppress, Proposal const &proposal)
Constructor.
ConsensusProposal< NodeID, uint256, uint256 > Proposal
Slice signature() const
Signature of the proposal (not necessarily verified).
boost::container::static_vector< std::uint8_t, 72 > signature_
bool checkSign() const
Verify the signing hash of the proposal.
Proposal const & proposal() const
json::Value getJson() const
JSON representation of proposal.
int addBitString(BaseUInt< Bits, Tag > const &v)
Definition Serializer.h:105
uint256 getSHA512Half() const
int addVL(Blob const &vector)
An immutable linear range of bytes.
Definition Slice.h:26
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
bool verifyDigest(PublicKey const &publicKey, uint256 const &digest, Slice const &sig, bool mustBeFullyCanonical=true) noexcept
Verify a secp256k1 signature on the digest of a message.
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition AccountID.cpp:93
uint256 proposalUniqueId(uint256 const &proposeHash, uint256 const &previousLedger, std::uint32_t proposeSeq, NetClock::time_point closeTime, Slice const &publicKey, Slice const &signature)
Calculate a unique identifier for a signed proposal.
BaseUInt< 256 > uint256
Definition base_uint.h:562
T time_since_epoch(T... args)