mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-27 14:35:52 +00:00
Fix the need to call setIndex after creating a new SLE.
Finish the ledger skip list code. (Note that this will cause ledger divergence if old code talks to new code.)
This commit is contained in:
@@ -15,8 +15,7 @@ AccountState::AccountState(const RippleAddress& naAccountID) : mAccountID(naAcco
|
|||||||
{
|
{
|
||||||
if (!naAccountID.isValid()) return;
|
if (!naAccountID.isValid()) return;
|
||||||
|
|
||||||
mLedgerEntry = boost::make_shared<SerializedLedgerEntry>(ltACCOUNT_ROOT);
|
mLedgerEntry = boost::make_shared<SerializedLedgerEntry>(ltACCOUNT_ROOT, Ledger::getAccountRootIndex(naAccountID));
|
||||||
mLedgerEntry->setIndex(Ledger::getAccountRootIndex(naAccountID));
|
|
||||||
mLedgerEntry->setFieldAccount(sfAccount, naAccountID.getAccountID());
|
mLedgerEntry->setFieldAccount(sfAccount, naAccountID.getAccountID());
|
||||||
|
|
||||||
mValid = true;
|
mValid = true;
|
||||||
|
|||||||
@@ -756,8 +756,7 @@ SLE::pointer Ledger::getASNode(LedgerStateParms& parms, const uint256& nodeID,
|
|||||||
}
|
}
|
||||||
|
|
||||||
parms = parms | lepCREATED | lepOKAY;
|
parms = parms | lepCREATED | lepOKAY;
|
||||||
SLE::pointer sle=boost::make_shared<SLE>(let);
|
SLE::pointer sle=boost::make_shared<SLE>(let, nodeID);
|
||||||
sle->setIndex(nodeID);
|
|
||||||
|
|
||||||
return sle;
|
return sle;
|
||||||
}
|
}
|
||||||
@@ -890,7 +889,7 @@ uint256 Ledger::getAccountRootIndex(const uint160& uAccountID)
|
|||||||
uint256 Ledger::getLedgerHashIndex()
|
uint256 Ledger::getLedgerHashIndex()
|
||||||
{ // get the index of the node that holds the last 256 ledgers
|
{ // get the index of the node that holds the last 256 ledgers
|
||||||
Serializer s(2);
|
Serializer s(2);
|
||||||
s.add16(spaceHashes);
|
s.add16(spaceSkipList);
|
||||||
return s.getSHA512Half();
|
return s.getSHA512Half();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -898,7 +897,7 @@ uint256 Ledger::getLedgerHashIndex(uint32 desiredLedgerIndex)
|
|||||||
{ // get the index of the node that holds the set of 256 ledgers that includes this ledger's hash
|
{ // get the index of the node that holds the set of 256 ledgers that includes this ledger's hash
|
||||||
// (or the first ledger after it if it's not a multiple of 256)
|
// (or the first ledger after it if it's not a multiple of 256)
|
||||||
Serializer s(6);
|
Serializer s(6);
|
||||||
s.add16(spaceHashes);
|
s.add16(spaceSkipList);
|
||||||
s.add32(desiredLedgerIndex >> 16);
|
s.add32(desiredLedgerIndex >> 16);
|
||||||
return s.getSHA512Half();
|
return s.getSHA512Half();
|
||||||
}
|
}
|
||||||
@@ -1063,6 +1062,56 @@ bool Ledger::assertSane()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Ledger::updateSkipList()
|
||||||
|
{ // update the skip list with the information from our previous ledger
|
||||||
|
|
||||||
|
if (mLedgerSeq == 0) // genesis ledger has no previous ledger
|
||||||
|
return;
|
||||||
|
|
||||||
|
uint32 prevIndex = mLedgerSeq - 1;
|
||||||
|
|
||||||
|
if ((prevIndex & 0xff) == 0)
|
||||||
|
{ // update record of every 256th ledger
|
||||||
|
uint256 hash = getLedgerHashIndex(prevIndex);
|
||||||
|
SLE::pointer skipList = getSLE(hash);
|
||||||
|
std::vector<uint256> hashes;
|
||||||
|
|
||||||
|
if (!skipList)
|
||||||
|
skipList = boost::make_shared<SLE>(ltLEDGER_HASHES, hash);
|
||||||
|
else
|
||||||
|
hashes = skipList->getFieldV256(sfHashes).peekValue();
|
||||||
|
|
||||||
|
assert(hashes.size() <= 256);
|
||||||
|
hashes.push_back(mParentHash);
|
||||||
|
skipList->setFieldV256(sfHashes, STVector256(hashes));
|
||||||
|
|
||||||
|
if (writeBack(lepCREATE, skipList) == lepERROR)
|
||||||
|
{
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// update record of past 256 ledger
|
||||||
|
uint256 hash = getLedgerHashIndex();
|
||||||
|
SLE::pointer skipList = getSLE(hash);
|
||||||
|
std::vector<uint256> hashes;
|
||||||
|
if (!skipList)
|
||||||
|
skipList = boost::make_shared<SLE>(ltLEDGER_HASHES, hash);
|
||||||
|
else
|
||||||
|
hashes = skipList->getFieldV256(sfHashes).peekValue();
|
||||||
|
|
||||||
|
assert(hashes.size() <= 256);
|
||||||
|
if (hashes.size() == 256)
|
||||||
|
hashes.erase(hashes.begin());
|
||||||
|
hashes.push_back(mParentHash);
|
||||||
|
skipList->setFieldV256(sfHashes, STVector256(hashes));
|
||||||
|
|
||||||
|
if (writeBack(lepCREATE, skipList) == lepERROR)
|
||||||
|
{
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int Ledger::sPendingSaves = 0;
|
int Ledger::sPendingSaves = 0;
|
||||||
boost::recursive_mutex Ledger::sPendingSaveLock;
|
boost::recursive_mutex Ledger::sPendingSaveLock;
|
||||||
|
|
||||||
|
|||||||
@@ -166,6 +166,7 @@ public:
|
|||||||
LedgerStateParms writeBack(LedgerStateParms parms, SLE::ref);
|
LedgerStateParms writeBack(LedgerStateParms parms, SLE::ref);
|
||||||
SLE::pointer getAccountRoot(const uint160& accountID);
|
SLE::pointer getAccountRoot(const uint160& accountID);
|
||||||
SLE::pointer getAccountRoot(const RippleAddress& naAccountID);
|
SLE::pointer getAccountRoot(const RippleAddress& naAccountID);
|
||||||
|
void updateSkipList();
|
||||||
|
|
||||||
// database functions
|
// database functions
|
||||||
static Ledger::pointer loadByIndex(uint32 ledgerIndex);
|
static Ledger::pointer loadByIndex(uint32 ledgerIndex);
|
||||||
|
|||||||
@@ -1159,6 +1159,7 @@ void LedgerConsensus::accept(SHAMap::ref set)
|
|||||||
newLCL->peekTransactionMap()->armDirty();
|
newLCL->peekTransactionMap()->armDirty();
|
||||||
newLCL->peekAccountStateMap()->armDirty();
|
newLCL->peekAccountStateMap()->armDirty();
|
||||||
applyTransactions(set, newLCL, newLCL, failedTransactions, false);
|
applyTransactions(set, newLCL, newLCL, failedTransactions, false);
|
||||||
|
newLCL->updateSkipList();
|
||||||
newLCL->setClosed();
|
newLCL->setClosed();
|
||||||
boost::shared_ptr<SHAMap::SHADirtyMap> acctNodes = newLCL->peekAccountStateMap()->disarmDirty();
|
boost::shared_ptr<SHAMap::SHADirtyMap> acctNodes = newLCL->peekAccountStateMap()->disarmDirty();
|
||||||
boost::shared_ptr<SHAMap::SHADirtyMap> txnNodes = newLCL->peekTransactionMap()->disarmDirty();
|
boost::shared_ptr<SHAMap::SHADirtyMap> txnNodes = newLCL->peekTransactionMap()->disarmDirty();
|
||||||
|
|||||||
@@ -72,8 +72,7 @@ SLE::pointer LedgerEntrySet::getEntry(const uint256& index, LedgerEntryAction& a
|
|||||||
SLE::pointer LedgerEntrySet::entryCreate(LedgerEntryType letType, const uint256& index)
|
SLE::pointer LedgerEntrySet::entryCreate(LedgerEntryType letType, const uint256& index)
|
||||||
{
|
{
|
||||||
assert(index.isNonZero());
|
assert(index.isNonZero());
|
||||||
SLE::pointer sleNew = boost::make_shared<SLE>(letType);
|
SLE::pointer sleNew = boost::make_shared<SLE>(letType, index);
|
||||||
sleNew->setIndex(index);
|
|
||||||
entryCreate(sleNew);
|
entryCreate(sleNew);
|
||||||
return sleNew;
|
return sleNew;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ enum LedgerNameSpace
|
|||||||
spaceOwnerDir = 'O', // Directory of things owned by an account.
|
spaceOwnerDir = 'O', // Directory of things owned by an account.
|
||||||
spaceBookDir = 'B', // Directory of order books.
|
spaceBookDir = 'B', // Directory of order books.
|
||||||
spaceContract = 'c',
|
spaceContract = 'c',
|
||||||
spaceHashes = 'h',
|
spaceSkipList = 's',
|
||||||
};
|
};
|
||||||
|
|
||||||
enum LedgerSpecificFlags
|
enum LedgerSpecificFlags
|
||||||
|
|||||||
@@ -39,7 +39,8 @@ SerializedLedgerEntry::SerializedLedgerEntry(const Serializer& s, const uint256&
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SerializedLedgerEntry::SerializedLedgerEntry(LedgerEntryType type) : STObject(sfLedgerEntry), mType(type)
|
SerializedLedgerEntry::SerializedLedgerEntry(LedgerEntryType type, const uint256& index) :
|
||||||
|
STObject(sfLedgerEntry), mIndex(index), mType(type)
|
||||||
{
|
{
|
||||||
mFormat = LedgerEntryFormat::getLgrFormat(type);
|
mFormat = LedgerEntryFormat::getLgrFormat(type);
|
||||||
if (mFormat == NULL) throw std::runtime_error("invalid ledger entry type");
|
if (mFormat == NULL) throw std::runtime_error("invalid ledger entry type");
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ protected:
|
|||||||
public:
|
public:
|
||||||
SerializedLedgerEntry(const Serializer& s, const uint256& index);
|
SerializedLedgerEntry(const Serializer& s, const uint256& index);
|
||||||
SerializedLedgerEntry(SerializerIterator& sit, const uint256& index);
|
SerializedLedgerEntry(SerializerIterator& sit, const uint256& index);
|
||||||
SerializedLedgerEntry(LedgerEntryType type);
|
SerializedLedgerEntry(LedgerEntryType type, const uint256& index);
|
||||||
|
|
||||||
SerializedTypeID getSType() const { return STI_LEDGERENTRY; }
|
SerializedTypeID getSType() const { return STI_LEDGERENTRY; }
|
||||||
std::string getFullText() const;
|
std::string getFullText() const;
|
||||||
|
|||||||
Reference in New Issue
Block a user