Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signers Ledger Object wrapper #22

Open
wants to merge 6 commits into
base: wrapper
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/ripple/app/tx/impl/SetAccount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <ripple/protocol/PublicKey.h>
#include <ripple/protocol/Quality.h>
#include <ripple/protocol/st.h>
#include <ripple/protocol/MultiSigners.h>

namespace ripple {

Expand Down Expand Up @@ -321,7 +322,7 @@ SetAccount::doApply()
}

if ((!acctRoot->regularKey()) &&
(!view().peekSLE(keylet::signers(account_))))
(!view().peek(keylet::signers(account_))))
{
// Account has no regular key or multi-signer signer list.
return tecNO_ALTERNATIVE_KEY;
Expand Down
3 changes: 2 additions & 1 deletion src/ripple/app/tx/impl/SetRegularKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <ripple/basics/Log.h>
#include <ripple/protocol/Feature.h>
#include <ripple/protocol/TxFlags.h>
#include <ripple/protocol/MultiSigners.h>

namespace ripple {

Expand Down Expand Up @@ -90,7 +91,7 @@ SetRegularKey::doApply()
{
// Account has disabled master key and no multi-signer signer list.
if (acctRoot->isFlag(lsfDisableMaster) &&
!view().peekSLE(keylet::signers(account_)))
!view().peek(keylet::signers(account_)))
return tecNO_ALTERNATIVE_KEY;

acctRoot->clearRegularKey();
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/app/tx/impl/SetSignerList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ removeSignersFromLedger(
ApplyView& view,
AccountRootKeylet const& accountKeylet,
Keylet const& ownerDirKeylet,
Keylet const& signerListKeylet,
KeyletBase const& signerListKeylet,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I can specialize this parameter to SignersKeylet. Should I do that or leave it as is? Since this function is specific to signers, I don't think there is any harm in narrowing it's scope.

beast::Journal j)
{
// We have to examine the current SignerList so we know how much to
Expand Down
9 changes: 5 additions & 4 deletions src/ripple/app/tx/impl/Transactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <ripple/protocol/Protocol.h>
#include <ripple/protocol/STAccount.h>
#include <ripple/protocol/UintTypes.h>
#include <ripple/protocol/MultiSigners.h>

namespace ripple {

Expand Down Expand Up @@ -562,8 +563,8 @@ Transactor::checkMultiSign(PreclaimContext const& ctx)
{
auto const id = ctx.tx.getAccountID(sfAccount);
// Get mTxnAccountID's SignerList and Quorum.
std::shared_ptr<STLedgerEntry const> sleAccountSigners =
ctx.view.readSLE(keylet::signers(id));
std::optional<SignersImpl<false>> sleAccountSigners =
ctx.view.read(keylet::signers(id));
// If the signer list doesn't exist the account is not multi-signing.
if (!sleAccountSigners)
{
Expand All @@ -578,7 +579,7 @@ Transactor::checkMultiSign(PreclaimContext const& ctx)
assert(sleAccountSigners->getFieldU32(sfSignerListID) == 0);

auto accountSigners =
SignerEntries::deserialize(*sleAccountSigners, ctx.j, "ledger");
SignerEntries::deserialize(*(sleAccountSigners->slePtr()), ctx.j, "ledger");
if (!accountSigners)
return accountSigners.error();

Expand Down Expand Up @@ -702,7 +703,7 @@ Transactor::checkMultiSign(PreclaimContext const& ctx)
}

// Cannot perform transaction if quorum is not met.
if (weightSum < sleAccountSigners->getFieldU32(sfSignerQuorum))
if (weightSum < sleAccountSigners->slePtr()->getFieldU32(sfSignerQuorum))
{
JLOG(ctx.j.trace())
<< "applyTransaction: Signers failed to meet quorum.";
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/ledger/ApplyView.h
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ class ApplyView : public ReadView
std::optional<std::uint64_t>
dirInsert(
Keylet const& directory,
Keylet const& key,
KeyletBase const& key,
std::function<void(std::shared_ptr<SLE> const&)> const& describe)
{
return dirAdd(false, directory, key.key, describe);
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/protocol/Indexes.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ struct ticket_t
static ticket_t const ticket{};

/** A SignerList */
Keylet
SignersKeylet
signers(AccountID const& account) noexcept;

/** A Check */
Expand Down
16 changes: 16 additions & 0 deletions src/ripple/protocol/Keylet.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,22 @@ static_assert(std::is_move_assignable_v<Keylet>);
static_assert(std::is_nothrow_destructible_v<Keylet>);
#endif

template <bool>
class SignersImpl;

struct SignersKeylet final : public KeyletBase
{
template <bool Writable>
using TWrapped = SignersImpl<Writable>;

using KeyletBase::check;

explicit SignersKeylet(uint256 const& key)
: KeyletBase(ltSIGNER_LIST, key)
{
}
};

template <bool>
class AcctRootImpl;

Expand Down
71 changes: 71 additions & 0 deletions src/ripple/protocol/MultiSigners.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2021 Ripple Labs Inc.

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================

#ifndef RIPPLE_PROTOCOL_MULTI_SIGNERS_H_INCLUDED
#define RIPPLE_PROTOCOL_MULTI_SIGNERS_H_INCLUDED

#include <ripple/protocol/LedgerEntryWrapper.h>
#include <ripple/protocol/STAccount.h>
#include <ripple/protocol/STAmount.h>

namespace ripple {

template <bool Writable>
class SignersImpl final : public LedgerEntryWrapper<Writable>
{
private:
using Base = LedgerEntryWrapper<Writable>;
using SleT = typename Base::SleT;
using Base::wrapped_;

// This constructor is private so only the factory functions can
// construct an SignersImpl.
SignersImpl(std::shared_ptr<SleT>&& w) : Base(std::move(w))
{
}

// Friend declarations of factory functions.
//
// For classes that contain factories we must declare the entire class
// as a friend unless the class declaration is visible at this point.
friend class ReadView;
friend class ApplyView;

public:
// Conversion operator from SignersImpl<true> to SignersImpl<false>.
operator SignersImpl<true>() const
{
return SignersImpl<false>(
std::const_pointer_cast<std::shared_ptr<STLedgerEntry const>>(
wrapped_));
}

[[nodiscard]]
Json::Value getJson(JsonOptions options) const {
return wrapped_->getJson(options);
}

[[nodiscard]]
auto key() const {
return wrapped_->key();
}
};
} // namespace ripple

#endif // RIPPLE_PROTOCOL_MULTI_SIGNERS_H_INCLUDED
7 changes: 3 additions & 4 deletions src/ripple/protocol/impl/Indexes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,13 @@ ticket_t::operator()(AccountID const& id, SeqProxy ticketSeq) const
// This function is presently static, since it's never accessed from anywhere
// else. If we ever support multiple pages of signer lists, this would be the
// keylet used to locate them.
static Keylet
static SignersKeylet
signers(AccountID const& account, std::uint32_t page) noexcept
{
return {
ltSIGNER_LIST, indexHash(LedgerNameSpace::SIGNER_LIST, account, page)};
return SignersKeylet(indexHash(LedgerNameSpace::SIGNER_LIST, account, page));
}

Keylet
SignersKeylet
signers(AccountID const& account) noexcept
{
return signers(account, 0);
Expand Down
3 changes: 2 additions & 1 deletion src/ripple/rpc/handlers/AccountInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <ripple/rpc/GRPCHandlers.h>
#include <ripple/rpc/impl/RPCHelpers.h>
#include <grpc/status.h>
#include <ripple/protocol/MultiSigners.h>

namespace ripple {

Expand Down Expand Up @@ -138,7 +139,7 @@ doAccountInfo(RPC::JsonContext& context)

// This code will need to be revisited if in the future we support
// multiple SignerLists on one account.
auto const sleSigners = ledger->readSLE(keylet::signers(accountID));
auto const sleSigners = ledger->read(keylet::signers(accountID));
if (sleSigners)
jvSignerList.append(sleSigners->getJson(JsonOptions::none));

Expand Down
2 changes: 1 addition & 1 deletion src/ripple/rpc/impl/RPCHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ isRelatedToAccount(
}
else if (sle->getType() == ltSIGNER_LIST)
{
Keylet const accountSignerList = keylet::signers(accountID);
SignersKeylet const accountSignerList = keylet::signers(accountID);
return sle->key() == accountSignerList.key;
}
else if (sle->getType() == ltNFTOKEN_OFFER)
Expand Down