Add a flag to the ledger for SHAMapV2

This will allow code that looks at the ledger header to know what version the
SHAMap uses. This is helpful for code that rebuilds ledger binary structures
from the leaves.
This commit is contained in:
JoelKatz
2016-11-28 15:56:08 -08:00
committed by Nik Bougalis
parent 22a375a5f4
commit dc3571184a
6 changed files with 101 additions and 4 deletions

View File

@@ -4628,6 +4628,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\test\ledger\SHAMapV2_test.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\test\ledger\SkipList_test.cpp"> <ClCompile Include="..\..\src\test\ledger\SkipList_test.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>

View File

@@ -5352,6 +5352,9 @@
<ClCompile Include="..\..\src\test\ledger\PendingSaves_test.cpp"> <ClCompile Include="..\..\src\test\ledger\PendingSaves_test.cpp">
<Filter>test\ledger</Filter> <Filter>test\ledger</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\test\ledger\SHAMapV2_test.cpp">
<Filter>test\ledger</Filter>
</ClCompile>
<ClCompile Include="..\..\src\test\ledger\SkipList_test.cpp"> <ClCompile Include="..\..\src\test\ledger\SkipList_test.cpp">
<Filter>test\ledger</Filter> <Filter>test\ledger</Filter>
</ClCompile> </ClCompile>

View File

@@ -217,9 +217,11 @@ Ledger::Ledger (
beast::Journal j) beast::Journal j)
: mImmutable (true) : mImmutable (true)
, txMap_ (std::make_shared <SHAMap> (SHAMapType::TRANSACTION, , txMap_ (std::make_shared <SHAMap> (SHAMapType::TRANSACTION,
info.txHash, family, SHAMap::version{1})) info.txHash, family,
SHAMap::version{getSHAMapV2(info) ? 2 : 1}))
, stateMap_ (std::make_shared <SHAMap> (SHAMapType::STATE, , stateMap_ (std::make_shared <SHAMap> (SHAMapType::STATE,
info.accountHash, family, SHAMap::version{1})) info.accountHash, family,
SHAMap::version{getSHAMapV2(info) ? 2 : 1}))
, info_ (info) , info_ (info)
{ {
loaded = true; loaded = true;
@@ -273,6 +275,12 @@ Ledger::Ledger (Ledger const& prevLedger,
info_.closeTimeResolution = getNextLedgerTimeResolution( info_.closeTimeResolution = getNextLedgerTimeResolution(
prevLedger.info_.closeTimeResolution, prevLedger.info_.closeTimeResolution,
getCloseAgree(prevLedger.info()), info_.seq); getCloseAgree(prevLedger.info()), info_.seq);
if (stateMap_->get_version() == SHAMap::version{2})
{
info_.closeFlags |= sLCF_SHAMapV2;
}
if (prevLedger.info_.closeTime == NetClock::time_point{}) if (prevLedger.info_.closeTime == NetClock::time_point{})
{ {
info_.closeTime = roundCloseTime(closeTime, info_.closeTimeResolution); info_.closeTime = roundCloseTime(closeTime, info_.closeTimeResolution);
@@ -1053,6 +1061,7 @@ Ledger::make_v2()
info_.accountHash = stateMap_->getHash ().as_uint256(); info_.accountHash = stateMap_->getHash ().as_uint256();
info_.txHash = txMap_->getHash ().as_uint256(); info_.txHash = txMap_->getHash ().as_uint256();
info_.hash = calculateLedgerHash (info_); info_.hash = calculateLedgerHash (info_);
info_.closeFlags |= sLCF_SHAMapV2;
} }
void void

View File

@@ -416,7 +416,10 @@ public:
// ledger close flags // ledger close flags
static static
std::uint32_t const sLCF_NoConsensusTime = 1; std::uint32_t const sLCF_NoConsensusTime = 0x01;
static
std::uint32_t const sLCF_SHAMapV2 = 0x02;
inline inline
bool getCloseAgree (LedgerInfo const& info) bool getCloseAgree (LedgerInfo const& info)
@@ -424,6 +427,12 @@ bool getCloseAgree (LedgerInfo const& info)
return (info.closeFlags & sLCF_NoConsensusTime) == 0; return (info.closeFlags & sLCF_NoConsensusTime) == 0;
} }
inline
bool getSHAMapV2 (LedgerInfo const& info)
{
return (info.closeFlags & sLCF_SHAMapV2) != 0;
}
void addRaw (LedgerInfo const&, Serializer&); void addRaw (LedgerInfo const&, Serializer&);
} // ripple } // ripple

View File

@@ -0,0 +1,71 @@
//-----------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
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
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/app/ledger/Ledger.h>
#include <ripple/test/jtx.h>
#include <ripple/beast/unit_test.h>
namespace ripple {
namespace test {
// Test that converting a ledger to SHAMapV2
// works as expected
class SHAMapV2_test : public beast::unit_test::suite
{
void
testSHAMapV2()
{
jtx::Env env(*this);
Config config;
auto ledger =
std::make_shared<Ledger>(create_genesis, config, 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});
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});
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});
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});
}
void run()
{
testSHAMapV2();
}
};
BEAST_DEFINE_TESTSUITE(SHAMapV2,ledger,ripple);
} // test
} // ripple

View File

@@ -22,5 +22,6 @@
#include <test/ledger/Directory_test.cpp> #include <test/ledger/Directory_test.cpp>
#include <test/ledger/PaymentSandbox_test.cpp> #include <test/ledger/PaymentSandbox_test.cpp>
#include <test/ledger/PendingSaves_test.cpp> #include <test/ledger/PendingSaves_test.cpp>
#include <test/ledger/SHAMapV2_test.cpp>
#include <test/ledger/SkipList_test.cpp> #include <test/ledger/SkipList_test.cpp>
#include <test/ledger/View_test.cpp> #include <test/ledger/View_test.cpp>