Enable simple multisign with a Feature (RIPD-182):

Eventually multisign will need to be enabled onto the network, at
which point compiling it in or out will no longer be an option.
In preparation, the compile guards are removed and multisign is
being enabled with a Feature.

You can locally enable a Feature using your config file.  To
enable multisign with your config file add a section like this:

[features]
MultiSign

The exact spelling and capitalization of both "features" and
"MultiSign" is important.  If you don't get those right multisign
will not be enabled.

There is a minor issue.  The "sign_for" and "submit_multisigned"
RPC commands are only enabled if multisign is enabled.  However
those commands are still shown in the help message even if
multisign is disabled.  This is because the code that produces
the help message doesn't read the config file (where the Features
are kept).  This problem will become irrelevant once multisign is
enabled onto the network.
This commit is contained in:
Scott Schurr
2015-08-11 14:11:01 -07:00
parent 9b15c88b0e
commit ef51128270
17 changed files with 71 additions and 73 deletions

View File

@@ -171,15 +171,6 @@
#define RIPPLE_ENABLE_TICKETS 0
#endif
/** Config: RIPPLE_ENABLE_MULTI_SIGN
When set, activates the current state of the multi-sign feature which is
under development. When the feature is complete and released this
#define should be removed.
*/
#ifndef RIPPLE_ENABLE_MULTI_SIGN
#define RIPPLE_ENABLE_MULTI_SIGN 0
#endif
// Uses OpenSSL instead of alternatives
#ifndef RIPPLE_USE_OPENSSL
#define RIPPLE_USE_OPENSSL 0

View File

@@ -146,14 +146,10 @@ void printHelp (const po::options_description& desc)
" version\n"
" server_info\n"
" sign <private_key> <json> [offline]\n"
#if RIPPLE_ENABLE_MULTI_SIGN
" sign_for\n"
#endif // RIPPLE_ENABLE_MULTI_SIGN
" stop\n"
" submit <tx_blob>|[<private_key> <json>]\n"
#if RIPPLE_ENABLE_MULTI_SIGN
" submit_multisigned\n"
#endif // RIPPLE_ENABLE_MULTI_SIGN
" tx <id>\n"
" validation_create [<seed>|<pass_phrase>|<key>]\n"
" validation_seed [<seed>|<pass_phrase>|<key>]\n"

View File

@@ -56,6 +56,7 @@
#include <ripple/overlay/Overlay.h>
#include <ripple/overlay/predicates.h>
#include <ripple/protocol/BuildInfo.h>
#include <ripple/protocol/Feature.h>
#include <ripple/protocol/HashPrefix.h>
#include <ripple/protocol/Indexes.h>
#include <ripple/resource/Fees.h>
@@ -675,7 +676,10 @@ void NetworkOPsImp::submitTransaction (Job&, STTx::pointer iTrans)
{
try
{
if (! passesLocalChecks (*trans, reason) || ! trans->checkSign ())
// Tell the call to checkSign() whether multisign is enabled.
if (!passesLocalChecks (*trans, reason) ||
!trans->checkSign (m_ledgerMaster.getValidatedRules().enabled(
featureMultiSign, getConfig().features)))
{
m_journal.warning << "Submitted transaction " <<
(reason.empty () ? "has bad signature" : "error: " + reason);

View File

@@ -219,7 +219,7 @@ public:
expect (env.seq(alice) == aliceSeq + 1);
// Make sure multisign is disabled in production.
// NOTE: THESE FOUR TESTS FAIL IF RIPPLE_ENABLE_MULTI_SIGN != 0
// NOTE: These four tests will fail when multisign is default enabled.
env.disable_testing();
aliceSeq = env.seq (alice);
env(noop(alice), msig(bogie), fee(2 * baseFee), ter(temINVALID));

View File

@@ -21,6 +21,7 @@
#include <ripple/app/tx/impl/SetAccount.h>
#include <ripple/basics/Log.h>
#include <ripple/core/Config.h>
#include <ripple/protocol/Feature.h>
#include <ripple/protocol/Indexes.h>
#include <ripple/protocol/Quality.h>
#include <ripple/protocol/TxFlags.h>
@@ -197,8 +198,8 @@ SetAccount::doApply ()
// Account has no regular key or multi-signer signer list.
// Prevent transaction changes until we're ready.
if ((RIPPLE_ENABLE_MULTI_SIGN) ||
view().flags() & tapENABLE_TESTING)
if (view().flags() & tapENABLE_TESTING ||
view().rules().enabled(featureMultiSign, ctx_.config.features))
return tecNO_ALTERNATIVE_KEY;
return tecNO_REGULAR_KEY;

View File

@@ -21,6 +21,7 @@
#include <ripple/app/ledger/Ledger.h>
#include <ripple/app/tx/impl/SetSignerList.h>
#include <ripple/app/tx/impl/SignerEntries.h>
#include <ripple/protocol/Feature.h>
#include <ripple/protocol/STObject.h>
#include <ripple/protocol/STArray.h>
#include <ripple/protocol/STTx.h>
@@ -74,10 +75,10 @@ SetSignerList::determineOperation(STTx const& tx,
TER
SetSignerList::preflight (PreflightContext const& ctx)
{
#if ! RIPPLE_ENABLE_MULTI_SIGN
if (! (ctx.flags & tapENABLE_TESTING))
if (! (ctx.flags & tapENABLE_TESTING) &&
! ctx.rules.enabled(featureMultiSign,
ctx.config.features))
return temDISABLED;
#endif
auto const ret = preflight1 (ctx);
if (!isTesSuccess (ret))

View File

@@ -24,6 +24,7 @@
#include <ripple/app/ledger/LedgerMaster.h>
#include <ripple/app/main/Application.h>
#include <ripple/app/misc/HashRouter.h>
#include <ripple/protocol/Feature.h>
#include <ripple/protocol/JsonFields.h>
#include <boost/optional.hpp>
@@ -89,11 +90,14 @@ Transaction::pointer Transaction::sharedTransaction (
bool Transaction::checkSign (std::string& reason, SigVerify sigVerify) const
{
bool const allowMultiSign = getApp().getLedgerMaster().
getValidatedRules().enabled (featureMultiSign, getConfig().features);
if (! mFromPubKey.isValid ())
reason = "Transaction has bad source public key";
else if (!sigVerify(*mTransaction, [] (STTx const& tx)
else if (!sigVerify(*mTransaction, [allowMultiSign] (STTx const& tx)
{
return tx.checkSign();
return tx.checkSign(allowMultiSign);
}))
reason = "Transaction has bad signature";
else

View File

@@ -25,6 +25,7 @@
#include <ripple/core/Config.h>
#include <ripple/core/LoadFeeTrack.h>
#include <ripple/json/to_string.h>
#include <ripple/protocol/Feature.h>
#include <ripple/protocol/Indexes.h>
#include <ripple/protocol/types.h>
@@ -70,12 +71,8 @@ preflight2 (PreflightContext const& ctx)
{
return (ctx.flags & tapNO_CHECK_SIGN) ||
tx.checkSign(
#if RIPPLE_ENABLE_MULTI_SIGN
true
#else
ctx.flags & tapENABLE_TESTING
#endif
);
(ctx.flags & tapENABLE_TESTING) ||
(ctx.rules.enabled(featureMultiSign, ctx.config.features)));
}))
{
JLOG(ctx.j.debug) << "preflight2: bad signature";
@@ -258,12 +255,11 @@ TER Transactor::apply ()
TER Transactor::checkSign ()
{
#if RIPPLE_ENABLE_MULTI_SIGN
#else
if(view().flags() & tapENABLE_TESTING)
#endif
// Make sure multisigning is enabled before we check for multisignatures.
if ((view().flags() & tapENABLE_TESTING) ||
(view().rules().enabled(featureMultiSign, ctx_.config.features)))
{
// If the mSigningPubKey is empty, then we must be multi-signing.
// If the mSigningPubKey is empty, then we must be multisigning.
if (mSigningPubKey.getAccountPublic ().empty ())
return checkMultiSign ();
}

View File

@@ -28,6 +28,7 @@
#include <ripple/net/HTTPClient.h>
#include <ripple/protocol/JsonFields.h>
#include <ripple/protocol/ErrorCodes.h>
#include <ripple/protocol/Feature.h>
#include <ripple/protocol/SystemParameters.h>
#include <ripple/protocol/types.h>
#include <ripple/server/ServerHandler.h>
@@ -922,13 +923,9 @@ public:
{ "random", &RPCParser::parseAsIs, 0, 0 },
{ "ripple_path_find", &RPCParser::parseRipplePathFind, 1, 2 },
{ "sign", &RPCParser::parseSignSubmit, 2, 3 },
#if RIPPLE_ENABLE_MULTI_SIGN
{ "sign_for", &RPCParser::parseSignFor, 4, 4 },
#endif // RIPPLE_ENABLE_MULTI_SIGN
{ "submit", &RPCParser::parseSignSubmit, 1, 3 },
#if RIPPLE_ENABLE_MULTI_SIGN
{ "submit_multisigned", &RPCParser::parseSubmitMultiSigned, 1, 1 },
#endif // RIPPLE_ENABLE_MULTI_SIGN
{ "server_info", &RPCParser::parseAsIs, 0, 0 },
{ "server_state", &RPCParser::parseAsIs, 0, 0 },
{ "stop", &RPCParser::parseAsIs, 0, 0 },

View File

@@ -34,6 +34,7 @@ uint256
feature (const char* name);
/** @} */
extern uint256 const featureMultiSign;
extern uint256 const featureSusPay;
} // ripple

View File

@@ -122,13 +122,7 @@ public:
void sign (RippleAddress const& private_key);
bool checkSign(bool allowMultiSign =
#if RIPPLE_ENABLE_MULTI_SIGN
true
#else
false
#endif
) const;
bool checkSign(bool allowMultiSign) const;
// SQL Functions with metadata.
static

View File

@@ -45,6 +45,7 @@ feature (const char* name)
return feature(name, std::strlen(name));
}
uint256 const featureMultiSign = feature("MultiSign");
uint256 const featureSusPay = feature("SusPay");
} // ripple

View File

@@ -44,7 +44,7 @@ public:
j.setFieldVL (sfMessageKey, publicAcct.getAccountPublic ());
j.sign (privateAcct);
unexpected (!j.checkSign (), "Transaction fails signature test");
unexpected (!j.checkSign (true), "Transaction fails signature test");
Serializer rawTxn;
j.add (rawTxn);

View File

@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012-2014 Ripple Labs Inc.
Copyright (c) 2012-2015 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
@@ -18,10 +18,9 @@
//==============================================================================
#include <BeastConfig.h>
#include <ripple/app/misc/NetworkOPs.h>
#include <ripple/json/json_value.h>
#include <ripple/net/RPCErr.h>
#include <ripple/protocol/JsonFields.h>
#include <ripple/app/main/Application.h>
#include <ripple/app/ledger/LedgerMaster.h>
#include <ripple/protocol/Feature.h>
#include <ripple/resource/Fees.h>
#include <ripple/rpc/Context.h>
#include <ripple/rpc/impl/TransactionSign.h>
@@ -35,11 +34,16 @@ namespace ripple {
// }
Json::Value doSignFor (RPC::Context& context)
{
// Bail if multisign is not enabled.
if (! getApp().getLedgerMaster().getValidatedRules().
enabled (featureMultiSign, getConfig().features))
{
RPC::inject_error (rpcNOT_ENABLED, context.params);
return context.params;
}
context.loadType = Resource::feeHighBurdenRPC;
NetworkOPs::FailHard const failType =
NetworkOPs::doFailHard (
context.params.isMember ("fail_hard")
&& context.params["fail_hard"].asBool ());
auto const failHard = context.params[jss::fail_hard].asBool();
auto const failType = NetworkOPs::doFailHard (failHard);
return RPC::transactionSignFor (
context.params, failType, context.netOps, context.role);

View File

@@ -1,10 +1,12 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012-2014 Ripple Labs Inc.
Copyright (c) 2012-2015 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
@@ -16,8 +18,9 @@
//==============================================================================
#include <BeastConfig.h>
#include <ripple/app/misc/NetworkOPs.h>
#include <ripple/basics/StringUtilities.h>
#include <ripple/app/main/Application.h>
#include <ripple/app/ledger/LedgerMaster.h>
#include <ripple/protocol/Feature.h>
#include <ripple/resource/Fees.h>
#include <ripple/rpc/Context.h>
#include <ripple/rpc/impl/TransactionSign.h>
@@ -30,11 +33,16 @@ namespace ripple {
// }
Json::Value doSubmitMultiSigned (RPC::Context& context)
{
// Bail if multisign is not enabled.
if (! getApp().getLedgerMaster().getValidatedRules().
enabled (featureMultiSign, getConfig().features))
{
RPC::inject_error (rpcNOT_ENABLED, context.params);
return context.params;
}
context.loadType = Resource::feeHighBurdenRPC;
NetworkOPs::FailHard const failType = NetworkOPs::doFailHard (
context.params.isMember ("fail_hard")
&& context.params["fail_hard"].asBool ());
auto const failHard = context.params[jss::fail_hard].asBool();
auto const failType = NetworkOPs::doFailHard (failHard);
return RPC::transactionSubmitMultiSigned (
context.params, failType, context.netOps, context.role);

View File

@@ -58,9 +58,12 @@ Status handle (Context& context, Object& object)
class HandlerTable {
public:
HandlerTable (std::vector<Handler> const& entries) {
for (auto& entry: entries)
template<std::size_t N>
HandlerTable (const Handler(&entries)[N])
{
for (std::size_t i = 0; i < N; ++i)
{
auto const& entry = entries[i];
assert (table_.find(entry.name_) == table_.end());
table_[entry.name_] = entry;
}
@@ -70,7 +73,7 @@ class HandlerTable {
addHandler<VersionHandler>();
}
const Handler* getHandler(std::string name) {
const Handler* getHandler(std::string name) const {
auto i = table_.find(name);
return i == table_.end() ? nullptr : &i->second;
}
@@ -94,7 +97,7 @@ class HandlerTable {
};
};
HandlerTable HANDLERS({
Handler handlerArray[] {
// Some handlers not specified here are added to the table via addHandler()
// Request-response methods
{ "account_info", byRef (&doAccountInfo), Role::USER, NO_CONDITION },
@@ -133,13 +136,9 @@ HandlerTable HANDLERS({
{ "random", byRef (&doRandom), Role::USER, NO_CONDITION },
{ "ripple_path_find", byRef (&doRipplePathFind), Role::USER, NO_CONDITION },
{ "sign", byRef (&doSign), Role::USER, NO_CONDITION },
#if RIPPLE_ENABLE_MULTI_SIGN
{ "sign_for", byRef (&doSignFor), Role::USER, NO_CONDITION },
#endif // RIPPLE_ENABLE_MULTI_SIGN
{ "submit", byRef (&doSubmit), Role::USER, NEEDS_CURRENT_LEDGER },
#if RIPPLE_ENABLE_MULTI_SIGN
{ "submit_multisigned", byRef (&doSubmitMultiSigned), Role::USER, NEEDS_CURRENT_LEDGER },
#endif // RIPPLE_ENABLE_MULTI_SIGN
{ "server_info", byRef (&doServerInfo), Role::USER, NO_CONDITION },
{ "server_state", byRef (&doServerState), Role::USER, NO_CONDITION },
{ "stop", byRef (&doStop), Role::ADMIN, NO_CONDITION },
@@ -161,12 +160,13 @@ HandlerTable HANDLERS({
// Evented methods
{ "subscribe", byRef (&doSubscribe), Role::USER, NO_CONDITION },
{ "unsubscribe", byRef (&doUnsubscribe), Role::USER, NO_CONDITION },
});
};
} // namespace
const Handler* getHandler(std::string const& name) {
return HANDLERS.getHandler(name);
static beast::static_initializer<HandlerTable> const handlers(handlerArray);
return handlers->getHandler(name);
}
} // RPC

View File

@@ -72,8 +72,8 @@
#include <ripple/rpc/handlers/RipplePathFind.cpp>
#include <ripple/rpc/handlers/ServerInfo.cpp>
#include <ripple/rpc/handlers/ServerState.cpp>
#include <ripple/rpc/handlers/SignHandler.cpp>
#include <ripple/rpc/handlers/SignFor.cpp>
#include <ripple/rpc/handlers/SignHandler.cpp>
#include <ripple/rpc/handlers/Stop.cpp>
#include <ripple/rpc/handlers/Submit.cpp>
#include <ripple/rpc/handlers/SubmitMultiSigned.cpp>