mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Remove RippleAddress:
The RippleAddress class was used to represent a number of fundamentally different types: account public keys, account secret keys, node public keys, node secret keys, seeds and generators. The class is replaced by the following types: * PublicKey for account and node public keys * SecretKey for account and node private keys * Generator for generating secp256k1 accounts * Seed for account, node and generator seeds
This commit is contained in:
@@ -74,15 +74,26 @@ bool CanonicalTXSet::Key::operator>= (Key const& rhs)const
|
||||
return mTXid >= rhs.mTXid;
|
||||
}
|
||||
|
||||
uint256 CanonicalTXSet::accountKey (AccountID const& account)
|
||||
{
|
||||
uint256 ret = beast::zero;
|
||||
memcpy (
|
||||
ret.begin (),
|
||||
account.begin (),
|
||||
account.size ());
|
||||
ret ^= mSetHash;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void CanonicalTXSet::insert (std::shared_ptr<STTx const> const& txn)
|
||||
{
|
||||
uint256 effectiveAccount = mSetHash;
|
||||
|
||||
effectiveAccount ^= to256 (txn->getAccountID(sfAccount));
|
||||
|
||||
mMap.insert (std::make_pair (
|
||||
Key (effectiveAccount, txn->getSequence (), txn->getTransactionID ()),
|
||||
txn));
|
||||
mMap.insert (
|
||||
std::make_pair (
|
||||
Key (
|
||||
accountKey (txn->getAccountID(sfAccount)),
|
||||
txn->getSequence (),
|
||||
txn->getTransactionID ()),
|
||||
txn));
|
||||
}
|
||||
|
||||
CanonicalTXSet::iterator CanonicalTXSet::erase (iterator const& it)
|
||||
|
||||
@@ -71,6 +71,9 @@ private:
|
||||
std::uint32_t mSeq;
|
||||
};
|
||||
|
||||
// Calculate the salted key for the given account
|
||||
uint256 accountKey (AccountID const& account);
|
||||
|
||||
public:
|
||||
using iterator = std::map <Key, std::shared_ptr<STTx const>>::iterator;
|
||||
using const_iterator = std::map <Key, std::shared_ptr<STTx const>>::const_iterator;
|
||||
|
||||
@@ -34,7 +34,6 @@
|
||||
#include <ripple/app/ledger/OrderBookDB.h>
|
||||
#include <ripple/app/ledger/TransactionMaster.h>
|
||||
#include <ripple/app/main/LoadManager.h>
|
||||
#include <ripple/app/main/LocalCredentials.h>
|
||||
#include <ripple/app/misc/HashRouter.h>
|
||||
#include <ripple/app/misc/NetworkOPs.h>
|
||||
#include <ripple/app/misc/Transaction.h>
|
||||
@@ -284,7 +283,7 @@ public:
|
||||
void processTrustedProposal (
|
||||
LedgerProposal::pointer proposal,
|
||||
std::shared_ptr<protocol::TMProposeSet> set,
|
||||
RippleAddress const &nodePublic) override;
|
||||
NodeID const &node) override;
|
||||
|
||||
bool recvValidation (
|
||||
STValidation::ref val, std::string const& source) override;
|
||||
@@ -585,12 +584,19 @@ NetworkOPsImp::getHostId (bool forAdmin)
|
||||
if (forAdmin)
|
||||
return beast::getComputerName ();
|
||||
|
||||
// For non-admin uses we hash the node ID into a single RFC1751 word:
|
||||
// (this could be cached instead of recalculated every time)
|
||||
Blob const& addr (app_.getLocalCredentials ().getNodePublic ().
|
||||
getNodePublic ());
|
||||
// For non-admin uses hash the node public key into a
|
||||
// single RFC1751 word:
|
||||
static std::string const shroudedHostId =
|
||||
[this]()
|
||||
{
|
||||
auto const& id = app_.nodeIdentity();
|
||||
|
||||
return RFC1751::getWordFromBlob (addr.data (), addr.size ());
|
||||
return RFC1751::getWordFromBlob (
|
||||
id.first.data (),
|
||||
id.first.size ());
|
||||
}();
|
||||
|
||||
return shroudedHostId;
|
||||
}
|
||||
|
||||
void NetworkOPsImp::setStateTimer ()
|
||||
@@ -673,7 +679,7 @@ void NetworkOPsImp::processHeartbeatTimer ()
|
||||
void NetworkOPsImp::processClusterTimer ()
|
||||
{
|
||||
bool const update = app_.cluster().update(
|
||||
app_.getLocalCredentials().getNodePublic(),
|
||||
app_.nodeIdentity().first,
|
||||
"",
|
||||
(m_ledgerMaster.getValidatedLedgerAge() <= 4min)
|
||||
? app_.getFeeTrack().getLocalFee()
|
||||
@@ -691,8 +697,11 @@ void NetworkOPsImp::processClusterTimer ()
|
||||
[&cluster](ClusterNode const& node)
|
||||
{
|
||||
protocol::TMClusterNode& n = *cluster.add_clusternodes();
|
||||
n.set_publickey(node.identity().humanNodePublic());
|
||||
n.set_reporttime(node.getReportTime().time_since_epoch().count());
|
||||
n.set_publickey(toBase58 (
|
||||
TokenType::TOKEN_NODE_PUBLIC,
|
||||
node.identity()));
|
||||
n.set_reporttime(
|
||||
node.getReportTime().time_since_epoch().count());
|
||||
n.set_nodeload(node.getLoadFee());
|
||||
if (!node.name().empty())
|
||||
n.set_nodename(node.name());
|
||||
@@ -1237,11 +1246,10 @@ bool NetworkOPsImp::checkLastClosedLedger (
|
||||
if (mMode >= omTRACKING)
|
||||
{
|
||||
++ourVC.nodesUsing;
|
||||
auto ourAddress =
|
||||
app_.getLocalCredentials ().getNodePublic ().getNodeID ();
|
||||
|
||||
if (ourAddress > ourVC.highNodeUsing)
|
||||
ourVC.highNodeUsing = ourAddress;
|
||||
auto const ourNodeID = calcNodeID(
|
||||
app_.nodeIdentity().first);
|
||||
if (ourNodeID > ourVC.highNodeUsing)
|
||||
ourVC.highNodeUsing = ourNodeID;
|
||||
}
|
||||
|
||||
for (auto& peer: peerList)
|
||||
@@ -1253,11 +1261,10 @@ bool NetworkOPsImp::checkLastClosedLedger (
|
||||
try
|
||||
{
|
||||
auto& vc = ledgers[peerLedger];
|
||||
|
||||
if (vc.nodesUsing == 0 ||
|
||||
peer->getNodePublic ().getNodeID () > vc.highNodeUsing)
|
||||
auto const nodeId = calcNodeID(peer->getNodePublic ());
|
||||
if (vc.nodesUsing == 0 || nodeId > vc.highNodeUsing)
|
||||
{
|
||||
vc.highNodeUsing = peer->getNodePublic ().getNodeID ();
|
||||
vc.highNodeUsing = nodeId;
|
||||
}
|
||||
|
||||
++vc.nodesUsing;
|
||||
@@ -1448,10 +1455,11 @@ uint256 NetworkOPsImp::getConsensusLCL ()
|
||||
|
||||
void NetworkOPsImp::processTrustedProposal (
|
||||
LedgerProposal::pointer proposal,
|
||||
std::shared_ptr<protocol::TMProposeSet> set, const RippleAddress& nodePublic)
|
||||
std::shared_ptr<protocol::TMProposeSet> set,
|
||||
NodeID const& node)
|
||||
{
|
||||
{
|
||||
mConsensus->storeProposal (proposal, nodePublic);
|
||||
mConsensus->storeProposal (proposal, node);
|
||||
|
||||
if (mLedgerConsensus->peerPosition (proposal))
|
||||
app_.overlay().relay(*set, proposal->getSuppressionID());
|
||||
@@ -1545,7 +1553,9 @@ void NetworkOPsImp::pubValidation (STValidation::ref val)
|
||||
Json::Value jvObj (Json::objectValue);
|
||||
|
||||
jvObj [jss::type] = "validationReceived";
|
||||
jvObj [jss::validation_public_key] = val->getSignerPublic ().humanNodePublic ();
|
||||
jvObj [jss::validation_public_key] = toBase58(
|
||||
TokenType::TOKEN_NODE_PUBLIC,
|
||||
val->getSignerPublic());
|
||||
jvObj [jss::ledger_hash] = to_string (val->getLedgerHash ());
|
||||
jvObj [jss::signature] = strHex (val->getSignature ());
|
||||
|
||||
@@ -1914,10 +1924,11 @@ Json::Value NetworkOPsImp::getServerInfo (bool human, bool admin)
|
||||
|
||||
if (admin)
|
||||
{
|
||||
if (app_.config().VALIDATION_PUB.isValid ())
|
||||
if (app_.config().VALIDATION_PUB.size ())
|
||||
{
|
||||
info[jss::pubkey_validator] =
|
||||
app_.config().VALIDATION_PUB.humanNodePublic ();
|
||||
info[jss::pubkey_validator] = toBase58 (
|
||||
TokenType::TOKEN_NODE_PUBLIC,
|
||||
app_.config().VALIDATION_PUB);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1925,9 +1936,9 @@ Json::Value NetworkOPsImp::getServerInfo (bool human, bool admin)
|
||||
}
|
||||
}
|
||||
|
||||
info[jss::pubkey_node] =
|
||||
app_.getLocalCredentials ().getNodePublic ().humanNodePublic ();
|
||||
|
||||
info[jss::pubkey_node] = toBase58 (
|
||||
TokenType::TOKEN_NODE_PUBLIC,
|
||||
app_.nodeIdentity().first);
|
||||
|
||||
info[jss::complete_ledgers] =
|
||||
app_.getLedgerMaster ().getCompleteLedgers ();
|
||||
@@ -2540,8 +2551,9 @@ bool NetworkOPsImp::subServer (InfoSub::ref isrListener, Json::Value& jvResult,
|
||||
jvResult[jss::load_base] = app_.getFeeTrack ().getLoadBase ();
|
||||
jvResult[jss::load_factor] = app_.getFeeTrack ().getLoadFactor ();
|
||||
jvResult [jss::hostid] = getHostId (admin);
|
||||
jvResult[jss::pubkey_node] = app_.getLocalCredentials ().
|
||||
getNodePublic ().humanNodePublic ();
|
||||
jvResult[jss::pubkey_node] = toBase58 (
|
||||
TokenType::TOKEN_NODE_PUBLIC,
|
||||
app_.nodeIdentity().first);
|
||||
|
||||
ScopedLockType sl (mSubLock);
|
||||
return mSubServer.emplace (isrListener->getSeq (), isrListener).second;
|
||||
|
||||
@@ -153,7 +153,7 @@ public:
|
||||
// ledger proposal/close functions
|
||||
virtual void processTrustedProposal (LedgerProposal::pointer proposal,
|
||||
std::shared_ptr<protocol::TMProposeSet> set,
|
||||
RippleAddress const& nodePublic) = 0;
|
||||
NodeID const& node) = 0;
|
||||
|
||||
virtual bool recvValidation (STValidation::ref val,
|
||||
std::string const& source) = 0;
|
||||
|
||||
@@ -86,7 +86,7 @@ public:
|
||||
private:
|
||||
bool addValidation (STValidation::ref val, std::string const& source) override
|
||||
{
|
||||
RippleAddress signer = val->getSignerPublic ();
|
||||
auto signer = val->getSignerPublic ();
|
||||
bool isCurrent = current (val);
|
||||
|
||||
if (!val->isTrusted() && app_.validators().trusted (signer))
|
||||
@@ -94,15 +94,16 @@ private:
|
||||
|
||||
if (!val->isTrusted ())
|
||||
{
|
||||
JLOG (j_.debug) << "Node " << signer.humanNodePublic ()
|
||||
<< " not in UNL st="
|
||||
<< val->getSignTime().time_since_epoch().count()
|
||||
<< ", hash=" << val->getLedgerHash ()
|
||||
<< ", shash=" << val->getSigningHash () << " src=" << source;
|
||||
JLOG (j_.trace) <<
|
||||
"Node " << toBase58 (TokenType::TOKEN_NODE_PUBLIC, signer) <<
|
||||
" not in UNL st=" << val->getSignTime().time_since_epoch().count() <<
|
||||
", hash=" << val->getLedgerHash () <<
|
||||
", shash=" << val->getSigningHash () <<
|
||||
" src=" << source;
|
||||
}
|
||||
|
||||
auto hash = val->getLedgerHash ();
|
||||
auto node = signer.getNodeID ();
|
||||
auto node = val->getNodeID ();
|
||||
|
||||
if (val->isTrusted () && isCurrent)
|
||||
{
|
||||
@@ -138,9 +139,11 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
JLOG (j_.debug) << "Val for " << hash << " from " << signer.humanNodePublic ()
|
||||
<< " added " << (val->isTrusted () ? "trusted/" : "UNtrusted/")
|
||||
<< (isCurrent ? "current" : "stale");
|
||||
JLOG (j_.debug) <<
|
||||
"Val for " << hash <<
|
||||
" from " << toBase58 (TokenType::TOKEN_NODE_PUBLIC, signer) <<
|
||||
" added " << (val->isTrusted () ? "trusted/" : "UNtrusted/") <<
|
||||
(isCurrent ? "current" : "stale");
|
||||
|
||||
if (val->isTrusted () && isCurrent)
|
||||
{
|
||||
@@ -482,7 +485,9 @@ private:
|
||||
it->add (s);
|
||||
*db << boost::str (
|
||||
insVal % to_string (it->getLedgerHash ()) %
|
||||
it->getSignerPublic ().humanNodePublic () %
|
||||
toBase58(
|
||||
TokenType::TOKEN_NODE_PUBLIC,
|
||||
it->getSignerPublic ()) %
|
||||
it->getSignTime().time_since_epoch().count() %
|
||||
sqlEscape (s.peekData ()));
|
||||
}
|
||||
|
||||
@@ -54,12 +54,12 @@ public:
|
||||
*/
|
||||
boost::optional<std::string>
|
||||
member (
|
||||
RippleAddress const& identity) const;
|
||||
PublicKey const& identity) const;
|
||||
|
||||
/** Determines whether a node is in the UNL */
|
||||
bool
|
||||
trusted (
|
||||
RippleAddress const& identity) const;
|
||||
PublicKey const& identity) const;
|
||||
|
||||
/** Insert a short-term validator key published in a manifest. */
|
||||
bool
|
||||
@@ -75,13 +75,13 @@ public:
|
||||
/** Insert a long-term validator key. */
|
||||
bool
|
||||
insertPermanentKey (
|
||||
RippleAddress const& identity,
|
||||
PublicKey const& identity,
|
||||
std::string const& comment);
|
||||
|
||||
/** Remove a long-term validator key. */
|
||||
bool
|
||||
removePermanentKey (
|
||||
RippleAddress const& identity);
|
||||
PublicKey const& identity);
|
||||
|
||||
/** The number of installed permanent and ephemeral keys */
|
||||
std::size_t
|
||||
|
||||
@@ -25,36 +25,22 @@
|
||||
|
||||
namespace ripple {
|
||||
|
||||
static
|
||||
PublicKey
|
||||
asPublicKey(RippleAddress const& raPublicKey)
|
||||
{
|
||||
auto const& blob = raPublicKey.getNodePublic();
|
||||
|
||||
if (blob.empty())
|
||||
LogicError ("Can't convert invalid RippleAddress to PublicKey");
|
||||
|
||||
return PublicKey(Slice(blob.data(), blob.size()));
|
||||
}
|
||||
|
||||
ValidatorList::ValidatorList (beast::Journal j)
|
||||
: j_ (j)
|
||||
{
|
||||
}
|
||||
|
||||
boost::optional<std::string>
|
||||
ValidatorList::member (RippleAddress const& identity) const
|
||||
ValidatorList::member (PublicKey const& identity) const
|
||||
{
|
||||
std::lock_guard <std::mutex> sl (mutex_);
|
||||
|
||||
auto const publicKey = asPublicKey (identity);
|
||||
|
||||
auto ret = ephemeral_.find (publicKey);
|
||||
auto ret = ephemeral_.find (identity);
|
||||
|
||||
if (ret != ephemeral_.end())
|
||||
return ret->second;
|
||||
|
||||
ret = permanent_.find (publicKey);
|
||||
ret = permanent_.find (identity);
|
||||
|
||||
if (ret != permanent_.end())
|
||||
return ret->second;
|
||||
@@ -63,7 +49,7 @@ ValidatorList::member (RippleAddress const& identity) const
|
||||
}
|
||||
|
||||
bool
|
||||
ValidatorList::trusted (RippleAddress const& identity) const
|
||||
ValidatorList::trusted (PublicKey const& identity) const
|
||||
{
|
||||
return static_cast<bool> (member(identity));
|
||||
}
|
||||
@@ -96,30 +82,28 @@ ValidatorList::removeEphemeralKey (
|
||||
|
||||
bool
|
||||
ValidatorList::insertPermanentKey (
|
||||
RippleAddress const& identity,
|
||||
PublicKey const& identity,
|
||||
std::string const& comment)
|
||||
{
|
||||
std::lock_guard <std::mutex> sl (mutex_);
|
||||
|
||||
auto const publicKey = asPublicKey (identity);
|
||||
|
||||
if (ephemeral_.find (publicKey) != ephemeral_.end())
|
||||
if (ephemeral_.find (identity) != ephemeral_.end())
|
||||
{
|
||||
JLOG (j_.error) <<
|
||||
toBase58 (TokenType::TOKEN_NODE_PUBLIC, publicKey) <<
|
||||
toBase58 (TokenType::TOKEN_NODE_PUBLIC, identity) <<
|
||||
": permanent key exists in ephemeral table!";
|
||||
return false;
|
||||
}
|
||||
|
||||
return permanent_.emplace (publicKey, comment).second;
|
||||
return permanent_.emplace (identity, comment).second;
|
||||
}
|
||||
|
||||
bool
|
||||
ValidatorList::removePermanentKey (
|
||||
RippleAddress const& identity)
|
||||
PublicKey const& identity)
|
||||
{
|
||||
std::lock_guard <std::mutex> sl (mutex_);
|
||||
return permanent_.erase (asPublicKey (identity));
|
||||
return permanent_.erase (identity);
|
||||
}
|
||||
|
||||
std::size_t
|
||||
@@ -186,16 +170,14 @@ ValidatorList::load (
|
||||
return false;
|
||||
}
|
||||
|
||||
auto const ra = RippleAddress::createNodePublic (match[1]);
|
||||
|
||||
if (trusted (ra))
|
||||
if (trusted (*id))
|
||||
{
|
||||
JLOG (j_.warning) <<
|
||||
"Duplicate node identity: " << match[1];
|
||||
continue;
|
||||
}
|
||||
|
||||
if (insertPermanentKey(ra, trim_whitespace (match[2])))
|
||||
if (insertPermanentKey(*id, trim_whitespace (match[2])))
|
||||
++count;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user