xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
xrpld
app
consensus
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
15
namespace
xrpl
{
16
17
// Used to construct received proposals
18
RCLCxPeerPos::RCLCxPeerPos
(
19
PublicKey
const
&
publicKey
,
20
Slice
const
&
signature
,
21
UInt256
const
& suppression,
22
Proposal
const
&
proposal
)
// trivially copyable
23
:
publicKey_
(
publicKey
),
suppression_
(suppression),
proposal_
(
proposal
)
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
35
bool
36
RCLCxPeerPos::checkSign
()
const
37
{
38
return
verifyDigest
(
publicKey
(),
proposal_
.signingHash(),
signature
(),
false
);
39
}
40
41
json::Value
42
RCLCxPeerPos::getJson
()
const
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
52
UInt256
53
proposalUniqueId
(
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
json::Value
Represents a JSON value.
Definition
json_value.h:117
xrpl::ConsensusProposal::getJson
json::Value getJson() const
Get JSON representation for debugging.
Definition
ConsensusProposal.h:217
xrpl::NetClock::time_point
std::chrono::time_point< NetClock > time_point
Definition
chrono.h:48
xrpl::PublicKey
A public key.
Definition
PublicKey.h:53
xrpl::RCLCxPeerPos::publicKey
PublicKey const & publicKey() const
Public key of peer that sent the proposal.
Definition
RCLCxPeerPos.h:68
xrpl::RCLCxPeerPos::Proposal
ConsensusProposal< NodeID, UInt256, UInt256 > Proposal
Definition
RCLCxPeerPos.h:30
xrpl::RCLCxPeerPos::signature
Slice signature() const
Signature of the proposal (not necessarily verified).
Definition
RCLCxPeerPos.h:59
xrpl::RCLCxPeerPos::suppression_
UInt256 suppression_
Definition
RCLCxPeerPos.h:102
xrpl::RCLCxPeerPos::signature_
boost::container::static_vector< std::uint8_t, 72 > signature_
Definition
RCLCxPeerPos.h:104
xrpl::RCLCxPeerPos::RCLCxPeerPos
RCLCxPeerPos(PublicKey const &publicKey, Slice const &signature, UInt256 const &suppress, Proposal const &proposal)
Constructor.
Definition
RCLCxPeerPos.cpp:18
xrpl::RCLCxPeerPos::checkSign
bool checkSign() const
Verify the signing hash of the proposal.
Definition
RCLCxPeerPos.cpp:36
xrpl::RCLCxPeerPos::proposal
Proposal const & proposal() const
Definition
RCLCxPeerPos.h:83
xrpl::RCLCxPeerPos::getJson
json::Value getJson() const
JSON representation of proposal.
Definition
RCLCxPeerPos.cpp:42
xrpl::RCLCxPeerPos::proposal_
Proposal proposal_
Definition
RCLCxPeerPos.h:103
xrpl::RCLCxPeerPos::publicKey_
PublicKey publicKey_
Definition
RCLCxPeerPos.h:101
xrpl::Serializer
Definition
Serializer.h:23
xrpl::Serializer::addBitString
int addBitString(BaseUInt< Bits, Tag > const &v)
Definition
Serializer.h:202
xrpl::Serializer::getSHA512Half
UInt256 getSHA512Half() const
Definition
libxrpl/protocol/Serializer.cpp:174
xrpl::Serializer::addVL
int addVL(Blob const &vector)
Definition
libxrpl/protocol/Serializer.cpp:180
xrpl::Serializer::add32
int add32(T i)
Definition
Serializer.h:167
xrpl::Slice
An immutable linear range of bytes.
Definition
Slice.h:28
cstdint
std::uint32_t
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::verifyDigest
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.
Definition
PublicKey.cpp:224
xrpl::proposalUniqueId
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.
Definition
RCLCxPeerPos.cpp:53
xrpl::toBase58
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition
AccountID.cpp:95
xrpl::UInt256
BaseUInt< 256 > UInt256
Definition
base_uint.h:580
xrpl::TokenType::NodePublic
@ NodePublic
Definition
tokens.h:21
std::chrono::time_point::time_since_epoch
T time_since_epoch(T... args)
Generated by
1.17.0