Add [features] section to .cfg:

This non-production config section allows features to be enabled
by listing their text descriptions, one line each, in the config
section titled "features".

NOTE: Feature names with leading or trailing whitespace, or
      containing an equals sign ('=') are not supported.
This commit is contained in:
Vinnie Falco
2015-07-29 07:36:29 -07:00
committed by Edward Hennis
parent 2ec40cb6f1
commit d49f9ea109
11 changed files with 145 additions and 17 deletions

View File

@@ -2751,6 +2751,8 @@
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\ripple\protocol\ErrorCodes.h"> <ClInclude Include="..\..\src\ripple\protocol\ErrorCodes.h">
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\ripple\protocol\Feature.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\protocol\HashPrefix.h"> <ClInclude Include="..\..\src\ripple\protocol\HashPrefix.h">
</ClInclude> </ClInclude>
<ClCompile Include="..\..\src\ripple\protocol\impl\AccountID.cpp"> <ClCompile Include="..\..\src\ripple\protocol\impl\AccountID.cpp">
@@ -2773,6 +2775,10 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\ripple\protocol\impl\Feature.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\ripple\protocol\impl\HashPrefix.cpp"> <ClCompile Include="..\..\src\ripple\protocol\impl\HashPrefix.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
@@ -2945,6 +2951,8 @@
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\ripple\protocol\SOTemplate.h"> <ClInclude Include="..\..\src\ripple\protocol\SOTemplate.h">
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\ripple\protocol\st.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\protocol\STAccount.h"> <ClInclude Include="..\..\src\ripple\protocol\STAccount.h">
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\ripple\protocol\STAmount.h"> <ClInclude Include="..\..\src\ripple\protocol\STAmount.h">

View File

@@ -3471,6 +3471,9 @@
<ClInclude Include="..\..\src\ripple\protocol\ErrorCodes.h"> <ClInclude Include="..\..\src\ripple\protocol\ErrorCodes.h">
<Filter>ripple\protocol</Filter> <Filter>ripple\protocol</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\ripple\protocol\Feature.h">
<Filter>ripple\protocol</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\protocol\HashPrefix.h"> <ClInclude Include="..\..\src\ripple\protocol\HashPrefix.h">
<Filter>ripple\protocol</Filter> <Filter>ripple\protocol</Filter>
</ClInclude> </ClInclude>
@@ -3489,6 +3492,9 @@
<ClCompile Include="..\..\src\ripple\protocol\impl\ErrorCodes.cpp"> <ClCompile Include="..\..\src\ripple\protocol\impl\ErrorCodes.cpp">
<Filter>ripple\protocol\impl</Filter> <Filter>ripple\protocol\impl</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\ripple\protocol\impl\Feature.cpp">
<Filter>ripple\protocol\impl</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple\protocol\impl\HashPrefix.cpp"> <ClCompile Include="..\..\src\ripple\protocol\impl\HashPrefix.cpp">
<Filter>ripple\protocol\impl</Filter> <Filter>ripple\protocol\impl</Filter>
</ClCompile> </ClCompile>
@@ -3651,6 +3657,9 @@
<ClInclude Include="..\..\src\ripple\protocol\SOTemplate.h"> <ClInclude Include="..\..\src\ripple\protocol\SOTemplate.h">
<Filter>ripple\protocol</Filter> <Filter>ripple\protocol</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\ripple\protocol\st.h">
<Filter>ripple\protocol</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\protocol\STAccount.h"> <ClInclude Include="..\..\src\ripple\protocol\STAccount.h">
<Filter>ripple\protocol</Filter> <Filter>ripple\protocol</Filter>
</ClInclude> </ClInclude>

View File

@@ -29,23 +29,25 @@ namespace ripple {
struct PreflightContext struct PreflightContext
{ {
public: public:
explicit PreflightContext(STTx const& tx_,
Rules const& rules_, ApplyFlags flags_,
SigVerify verify_,
beast::Journal j_ = {})
: tx(tx_)
, rules(rules_)
, flags(flags_)
, verify(verify_)
, j(j_)
{
}
STTx const& tx; STTx const& tx;
Rules const& rules; Rules const& rules;
ApplyFlags flags; ApplyFlags flags;
SigVerify verify; SigVerify verify;
Config const& config;
beast::Journal j; beast::Journal j;
PreflightContext(STTx const& tx_,
Rules const& rules_, ApplyFlags flags_,
SigVerify verify_, Config const& config_,
beast::Journal j_)
: tx(tx_)
, rules(rules_)
, flags(flags_)
, verify(verify_)
, config(config_)
, j(j_)
{
}
}; };
class Transactor class Transactor

View File

@@ -86,8 +86,8 @@ preflight (Rules const& rules, STTx const& tx,
{ {
try try
{ {
PreflightContext pfctx( PreflightContext pfctx(tx,
tx, rules, flags, verify, j); rules, flags, verify, config, j);
return invoke_preflight(pfctx); return invoke_preflight(pfctx);
} }
catch (std::exception const& e) catch (std::exception const& e)

View File

@@ -21,6 +21,7 @@
#define RIPPLE_CORE_CONFIG_H_INCLUDED #define RIPPLE_CORE_CONFIG_H_INCLUDED
#include <ripple/basics/BasicConfig.h> #include <ripple/basics/BasicConfig.h>
#include <ripple/basics/base_uint.h>
#include <ripple/protocol/SystemParameters.h> #include <ripple/protocol/SystemParameters.h>
#include <ripple/protocol/RippleAddress.h> #include <ripple/protocol/RippleAddress.h>
#include <ripple/json/json_value.h> #include <ripple/json/json_value.h>
@@ -36,6 +37,7 @@
#include <map> #include <map>
#include <string> #include <string>
#include <type_traits> #include <type_traits>
#include <unordered_set>
#include <vector> #include <vector>
namespace ripple { namespace ripple {
@@ -53,6 +55,8 @@ countSectionEntries (IniFileSections& secSource, std::string const& strSection);
IniFileSections::mapped_type* IniFileSections::mapped_type*
getIniFileSection (IniFileSections& secSource, std::string const& strSection); getIniFileSection (IniFileSections& secSource, std::string const& strSection);
class Rules;
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
enum SizedItemName enum SizedItemName
@@ -257,6 +261,8 @@ public:
boost::optional<boost::asio::ip::address_v4> rpc_ip; boost::optional<boost::asio::ip::address_v4> rpc_ip;
boost::optional<std::uint16_t> rpc_port; boost::optional<std::uint16_t> rpc_port;
std::unordered_set<uint256, beast::uhash<>> features;
public: public:
Config (); Config ();

View File

@@ -22,6 +22,7 @@
#include <ripple/core/ConfigSections.h> #include <ripple/core/ConfigSections.h>
#include <ripple/basics/Log.h> #include <ripple/basics/Log.h>
#include <ripple/json/json_reader.h> #include <ripple/json/json_reader.h>
#include <ripple/protocol/Feature.h>
#include <ripple/protocol/SystemParameters.h> #include <ripple/protocol/SystemParameters.h>
#include <ripple/net/HTTPClient.h> #include <ripple/net/HTTPClient.h>
#include <beast/http/URL.h> #include <beast/http/URL.h>
@@ -553,6 +554,12 @@ void Config::loadFromString (std::string const& fileContents)
if (getSingleSection (secConfig, SECTION_DEBUG_LOGFILE, strTemp)) if (getSingleSection (secConfig, SECTION_DEBUG_LOGFILE, strTemp))
DEBUG_LOGFILE = strTemp; DEBUG_LOGFILE = strTemp;
{
auto const part = section("features");
for(auto const& s : part.values())
features.insert(feature(s));
}
} }
int Config::getSize (SizedItemName item) const int Config::getSize (SizedItemName item) const

View File

@@ -26,10 +26,12 @@
#include <ripple/protocol/Protocol.h> #include <ripple/protocol/Protocol.h>
#include <ripple/protocol/STLedgerEntry.h> #include <ripple/protocol/STLedgerEntry.h>
#include <ripple/protocol/STTx.h> #include <ripple/protocol/STTx.h>
#include <beast/hash/uhash.h>
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <cassert> #include <cassert>
#include <cstdint> #include <cstdint>
#include <memory> #include <memory>
#include <unordered_set>
namespace ripple { namespace ripple {
@@ -137,7 +139,9 @@ public:
/** Returns `true` if a feature is enabled. */ /** Returns `true` if a feature is enabled. */
bool bool
enabled (uint256 const& feature) const; enabled (uint256 const& id,
std::unordered_set<uint256,
beast::uhash<>> const& presets) const;
/** Returns `true` if these rules don't match the ledger. */ /** Returns `true` if these rules don't match the ledger. */
bool bool

View File

@@ -86,11 +86,15 @@ Rules::Rules (DigestAwareReadView const& ledger)
} }
bool bool
Rules::enabled (uint256 const& feature) const Rules::enabled (uint256 const& id,
std::unordered_set<uint256,
beast::uhash<>> const& presets) const
{ {
if (presets.count(id) > 0)
return true;
if (! impl_) if (! impl_)
return false; return false;
return impl_->enabled(feature); return impl_->enabled(id);
} }
bool bool

View File

@@ -0,0 +1,39 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 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_FEATURE_H_INCLUDED
#define RIPPLE_PROTOCOL_FEATURE_H_INCLUDED
#include <ripple/basics/base_uint.h>
#include <string>
namespace ripple {
/** Convert feature description to feature id. */
/** @{ */
uint256
feature (std::string const& name);
uint256
feature (const char* name);
/** @} */
} // ripple
#endif

View File

@@ -0,0 +1,48 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 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.
*/
//==============================================================================
#include <BeastConfig.h>
#include <ripple/protocol/digest.h>
#include <ripple/protocol/Feature.h>
#include <cstring>
namespace ripple {
static
uint256
feature (char const* s, std::size_t n)
{
sha512_half_hasher h;
h(s, n);
return static_cast<uint256>(h);
}
uint256
feature (std::string const& name)
{
return feature(name.c_str(), name.size());
}
uint256
feature (const char* name)
{
return feature(name, std::strlen(name));
}
} // ripple

View File

@@ -24,6 +24,7 @@
#include <ripple/protocol/impl/ByteOrder.cpp> #include <ripple/protocol/impl/ByteOrder.cpp>
#include <ripple/protocol/impl/digest.cpp> #include <ripple/protocol/impl/digest.cpp>
#include <ripple/protocol/impl/ErrorCodes.cpp> #include <ripple/protocol/impl/ErrorCodes.cpp>
#include <ripple/protocol/impl/Feature.cpp>
#include <ripple/protocol/impl/HashPrefix.cpp> #include <ripple/protocol/impl/HashPrefix.cpp>
#include <ripple/protocol/impl/Indexes.cpp> #include <ripple/protocol/impl/Indexes.cpp>
#include <ripple/protocol/impl/Keylet.cpp> #include <ripple/protocol/impl/Keylet.cpp>