mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-24 21:15:58 +00:00
Enable amendments in genesis ledger (RIPD-1281)
When started with "--start", put all known, non-vetoed amendments in the genesis ledger. This avoids the need to wait 256 ledgers before amendments are enabled when testing with a fresh ledger.
This commit is contained in:
@@ -186,7 +186,11 @@ public:
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
Ledger::Ledger (create_genesis_t, Config const& config, Family& family)
|
||||
Ledger::Ledger (
|
||||
create_genesis_t,
|
||||
Config const& config,
|
||||
std::vector<uint256> const& amendments,
|
||||
Family& family)
|
||||
: mImmutable (false)
|
||||
, txMap_ (std::make_shared <SHAMap> (SHAMapType::TRANSACTION,
|
||||
family, SHAMap::version{1}))
|
||||
@@ -205,6 +209,14 @@ Ledger::Ledger (create_genesis_t, Config const& config, Family& family)
|
||||
sle->setAccountID (sfAccount, id);
|
||||
sle->setFieldAmount (sfBalance, info_.drops);
|
||||
rawInsert(sle);
|
||||
|
||||
if (! amendments.empty())
|
||||
{
|
||||
auto const sle = std::make_shared<SLE>(keylet::amendments());
|
||||
sle->setFieldV256 (sfAmendments, STVector256{amendments});
|
||||
rawInsert(sle);
|
||||
}
|
||||
|
||||
stateMap_->flushDirty (hotACCOUNT_NODE, info_.seq);
|
||||
setImmutable(config);
|
||||
}
|
||||
|
||||
@@ -94,8 +94,14 @@ public:
|
||||
of XRP in the system. No more XRP than the amount which
|
||||
starts in this account can ever exist, with amounts
|
||||
used to pay fees being destroyed.
|
||||
|
||||
Amendments specified are enabled in the genesis ledger
|
||||
*/
|
||||
Ledger (create_genesis_t, Config const& config, Family& family);
|
||||
Ledger (
|
||||
create_genesis_t,
|
||||
Config const& config,
|
||||
std::vector<uint256> const& amendments,
|
||||
Family& family);
|
||||
|
||||
Ledger (
|
||||
LedgerInfo const& info,
|
||||
|
||||
@@ -1248,9 +1248,17 @@ int ApplicationImp::fdlimit() const
|
||||
void
|
||||
ApplicationImp::startGenesisLedger()
|
||||
{
|
||||
std::vector<uint256> initialAmendments =
|
||||
(config_->START_UP == Config::FRESH) ?
|
||||
m_amendmentTable->getDesired() :
|
||||
std::vector<uint256>{};
|
||||
|
||||
std::shared_ptr<Ledger> const genesis =
|
||||
std::make_shared<Ledger>(
|
||||
create_genesis, *config_, family());
|
||||
create_genesis,
|
||||
*config_,
|
||||
initialAmendments,
|
||||
family());
|
||||
m_ledgerMaster->storeLedger (genesis);
|
||||
|
||||
auto const next = std::make_shared<Ledger>(
|
||||
|
||||
@@ -85,6 +85,13 @@ public:
|
||||
virtual std::vector <uint256>
|
||||
doValidation (std::set <uint256> const& enabled) = 0;
|
||||
|
||||
// The set of amendments to enable in the genesis ledger
|
||||
// This will return all known, non-vetoed amendments.
|
||||
// If we ever have two amendments that should not both be
|
||||
// enabled at the same time, we should ensure one is vetoed.
|
||||
virtual std::vector <uint256>
|
||||
getDesired () = 0;
|
||||
|
||||
// The two function below adapt the API callers expect to the
|
||||
// internal amendment table API. This allows the amendment
|
||||
// table implementation to be independent of the ledger
|
||||
|
||||
@@ -199,6 +199,9 @@ public:
|
||||
std::vector <uint256>
|
||||
doValidation (std::set<uint256> const& enabledAmendments) override;
|
||||
|
||||
std::vector <uint256>
|
||||
getDesired () override;
|
||||
|
||||
std::map <uint256, std::uint32_t>
|
||||
doVoting (
|
||||
NetClock::time_point closeTime,
|
||||
@@ -396,6 +399,31 @@ AmendmentTableImpl::doValidation (
|
||||
return amendments;
|
||||
}
|
||||
|
||||
std::vector <uint256>
|
||||
AmendmentTableImpl::getDesired ()
|
||||
{
|
||||
// Get the list of amendments we support and do not
|
||||
// veto
|
||||
std::vector <uint256> amendments;
|
||||
amendments.reserve (amendmentMap_.size());
|
||||
|
||||
{
|
||||
std::lock_guard <std::mutex> sl (mutex_);
|
||||
for (auto const& e : amendmentMap_)
|
||||
{
|
||||
if (e.second.supported && ! e.second.vetoed)
|
||||
{
|
||||
amendments.push_back (e.first);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!amendments.empty())
|
||||
std::sort (amendments.begin (), amendments.end ());
|
||||
|
||||
return amendments;
|
||||
}
|
||||
|
||||
std::map <uint256, std::uint32_t>
|
||||
AmendmentTableImpl::doVoting (
|
||||
NetClock::time_point closeTime,
|
||||
|
||||
@@ -53,7 +53,8 @@ struct Regression_test : public beast::unit_test::suite
|
||||
// be reproduced against an open ledger. Make a local
|
||||
// closed ledger and work with it directly.
|
||||
auto closed = std::make_shared<Ledger>(
|
||||
create_genesis, env.app().config(), env.app().family());
|
||||
create_genesis, env.app().config(),
|
||||
std::vector<uint256>{}, env.app().family());
|
||||
auto expectedDrops = SYSTEM_CURRENCY_START;
|
||||
BEAST_EXPECT(closed->info().drops == expectedDrops);
|
||||
|
||||
|
||||
@@ -36,27 +36,38 @@ class SHAMapV2_test : public beast::unit_test::suite
|
||||
jtx::Env env(*this);
|
||||
Config config;
|
||||
|
||||
std::set<uint256> amendments;
|
||||
std::vector<uint256> amendments_v;
|
||||
amendments_v.push_back(from_hex_text<uint256>("12345"));
|
||||
amendments.insert(from_hex_text<uint256>("12345"));
|
||||
|
||||
auto ledger =
|
||||
std::make_shared<Ledger>(create_genesis, config, env.app().family());
|
||||
std::make_shared<Ledger>(create_genesis, config,
|
||||
|
||||
amendments_v, env.app().family());
|
||||
BEAST_EXPECT(! getSHAMapV2 (ledger->info()));
|
||||
BEAST_EXPECT(ledger->stateMap().get_version() == SHAMap::version{1});
|
||||
BEAST_EXPECT(ledger->txMap().get_version() == SHAMap::version{1});
|
||||
BEAST_EXPECT(getEnabledAmendments(*ledger) == amendments);
|
||||
|
||||
ledger =
|
||||
std::make_shared<Ledger>(*ledger, NetClock::time_point{});
|
||||
BEAST_EXPECT(! getSHAMapV2 (ledger->info()));
|
||||
BEAST_EXPECT(ledger->stateMap().get_version() == SHAMap::version{1});
|
||||
BEAST_EXPECT(ledger->txMap().get_version() == SHAMap::version{1});
|
||||
BEAST_EXPECT(getEnabledAmendments(*ledger) == amendments);
|
||||
|
||||
ledger->make_v2();
|
||||
BEAST_EXPECT(getSHAMapV2 (ledger->info()));
|
||||
BEAST_EXPECT(ledger->stateMap().get_version() == SHAMap::version{2});
|
||||
BEAST_EXPECT(ledger->txMap().get_version() == SHAMap::version{2});
|
||||
BEAST_EXPECT(getEnabledAmendments(*ledger) == amendments);
|
||||
|
||||
ledger = std::make_shared<Ledger>(*ledger, NetClock::time_point{});
|
||||
BEAST_EXPECT(getSHAMapV2 (ledger->info()));
|
||||
BEAST_EXPECT(ledger->stateMap().get_version() == SHAMap::version{2});
|
||||
BEAST_EXPECT(ledger->txMap().get_version() == SHAMap::version{2});
|
||||
BEAST_EXPECT(getEnabledAmendments(*ledger) == amendments);
|
||||
}
|
||||
|
||||
void run()
|
||||
|
||||
@@ -37,8 +37,9 @@ class SkipList_test : public beast::unit_test::suite
|
||||
{
|
||||
jtx::Env env(*this);
|
||||
Config config;
|
||||
auto prev =
|
||||
std::make_shared<Ledger>(create_genesis, config, env.app().family());
|
||||
auto prev = std::make_shared<Ledger>(
|
||||
create_genesis, config,
|
||||
std::vector<uint256>{}, env.app().family());
|
||||
history.push_back(prev);
|
||||
for (auto i = 0; i < 1023; ++i)
|
||||
{
|
||||
|
||||
@@ -152,7 +152,8 @@ class View_test
|
||||
Config config;
|
||||
std::shared_ptr<Ledger const> const genesis =
|
||||
std::make_shared<Ledger>(
|
||||
create_genesis, config, env.app().family());
|
||||
create_genesis, config,
|
||||
std::vector<uint256>{}, env.app().family());
|
||||
auto const ledger =
|
||||
std::make_shared<Ledger>(
|
||||
*genesis,
|
||||
@@ -417,7 +418,8 @@ class View_test
|
||||
Config config;
|
||||
std::shared_ptr<Ledger const> const genesis =
|
||||
std::make_shared<Ledger> (
|
||||
create_genesis, config, env.app().family());
|
||||
create_genesis, config,
|
||||
std::vector<uint256>{}, env.app().family());
|
||||
auto const ledger = std::make_shared<Ledger>(
|
||||
*genesis,
|
||||
env.app().timeKeeper().closeTime());
|
||||
@@ -751,7 +753,8 @@ class View_test
|
||||
Config config;
|
||||
std::shared_ptr<Ledger const> const genesis =
|
||||
std::make_shared<Ledger>(
|
||||
create_genesis, config, env.app().family());
|
||||
create_genesis, config,
|
||||
std::vector<uint256>{}, env.app().family());
|
||||
auto const ledger =
|
||||
std::make_shared<Ledger>(
|
||||
*genesis,
|
||||
|
||||
Reference in New Issue
Block a user