Remove obsolete NodeObject fields:

Legacy fields of NodeObject are removed, as they are no longer
used and there is a space savings from omitting them:

* Remove LedgerIndex
This commit is contained in:
Vinnie Falco
2015-02-08 15:11:57 -08:00
parent 0b82b5a0d6
commit d1c08889fe
19 changed files with 53 additions and 104 deletions

View File

@@ -27,8 +27,7 @@
namespace ripple {
AccountStateSF::AccountStateSF (std::uint32_t ledgerSeq)
: mLedgerSeq (ledgerSeq)
AccountStateSF::AccountStateSF()
{
}
@@ -41,7 +40,8 @@ void AccountStateSF::gotNode (bool fromFilter,
// VFALCO SHAMapSync filters should be passed the SHAMap, the
// SHAMap should provide an accessor to get the injected Database,
// and this should use that Database instad of getNodeStore
getApp().getNodeStore ().store (hotACCOUNT_NODE, mLedgerSeq, std::move (nodeData), nodeHash);
getApp().getNodeStore ().store (
hotACCOUNT_NODE, std::move (nodeData), nodeHash);
}
bool AccountStateSF::haveNode (SHAMapNodeID const& id,

View File

@@ -29,7 +29,7 @@ namespace ripple {
class AccountStateSF : public SHAMapSyncFilter
{
public:
explicit AccountStateSF (std::uint32_t ledgerSeq);
AccountStateSF();
// Note that the nodeData is overwritten by this call
void gotNode (bool fromFilter,
@@ -41,9 +41,6 @@ public:
bool haveNode (SHAMapNodeID const& id,
uint256 const& nodeHash,
Blob& nodeData);
private:
std::uint32_t mLedgerSeq;
};
} // ripple

View File

@@ -142,8 +142,8 @@ bool InboundLedger::tryLocal ()
if (m_journal.trace) m_journal.trace <<
"Ledger header found in fetch pack";
mLedger = std::make_shared<Ledger> (data, true);
getApp().getNodeStore ().store (hotLEDGER,
mLedger->getLedgerSeq (), std::move (data), mHash);
getApp().getNodeStore ().store (
hotLEDGER, std::move (data), mHash);
}
else
{
@@ -173,7 +173,7 @@ bool InboundLedger::tryLocal ()
}
else
{
TransactionStateSF filter (mLedger->getLedgerSeq ());
TransactionStateSF filter;
if (mLedger->peekTransactionMap ()->fetchRoot (
mLedger->getTransHash (), &filter))
@@ -201,7 +201,7 @@ bool InboundLedger::tryLocal ()
}
else
{
AccountStateSF filter (mLedger->getLedgerSeq ());
AccountStateSF filter;
if (mLedger->peekAccountStateMap ()->fetchRoot (
mLedger->getAccountHash (), &filter))
@@ -571,7 +571,7 @@ void InboundLedger::trigger (Peer::ptr const& peer)
// VFALCO Why 256? Make this a constant
nodeIDs.reserve (256);
nodeHashes.reserve (256);
AccountStateSF filter (mSeq);
AccountStateSF filter;
// Release the lock while we process the large state map
sl.unlock();
@@ -650,7 +650,7 @@ void InboundLedger::trigger (Peer::ptr const& peer)
std::vector<uint256> nodeHashes;
nodeIDs.reserve (256);
nodeHashes.reserve (256);
TransactionStateSF filter (mSeq);
TransactionStateSF filter;
mLedger->peekTransactionMap ()->getMissingNodes (
nodeIDs, nodeHashes, 256, &filter);
@@ -805,8 +805,8 @@ bool InboundLedger::takeHeader (std::string const& data)
Serializer s (data.size () + 4);
s.add32 (HashPrefix::ledgerMaster);
s.addRaw (data);
getApp().getNodeStore ().store (hotLEDGER,
mLedger->getLedgerSeq (), std::move (s.modData ()), mHash);
getApp().getNodeStore ().store (
hotLEDGER, std::move (s.modData ()), mHash);
progress ();
@@ -842,7 +842,7 @@ bool InboundLedger::takeTxNode (const std::list<SHAMapNodeID>& nodeIDs,
std::list<SHAMapNodeID>::const_iterator nodeIDit = nodeIDs.begin ();
std::list< Blob >::const_iterator nodeDatait = data.begin ();
TransactionStateSF tFilter (mLedger->getLedgerSeq ());
TransactionStateSF tFilter;
while (nodeIDit != nodeIDs.end ())
{
@@ -909,7 +909,7 @@ bool InboundLedger::takeAsNode (const std::list<SHAMapNodeID>& nodeIDs,
std::list<SHAMapNodeID>::const_iterator nodeIDit = nodeIDs.begin ();
std::list< Blob >::const_iterator nodeDatait = data.begin ();
AccountStateSF tFilter (mLedger->getLedgerSeq ());
AccountStateSF tFilter;
while (nodeIDit != nodeIDs.end ())
{
@@ -973,7 +973,7 @@ bool InboundLedger::takeAsRootNode (Blob const& data, SHAMapAddNode& san)
return false;
}
AccountStateSF tFilter (mLedger->getLedgerSeq ());
AccountStateSF tFilter;
san += mLedger->peekAccountStateMap ()->addRootNode (
mLedger->getAccountHash (), data, snfWIRE, &tFilter);
return san.isGood();
@@ -997,7 +997,7 @@ bool InboundLedger::takeTxRootNode (Blob const& data, SHAMapAddNode& san)
return false;
}
TransactionStateSF tFilter (mLedger->getLedgerSeq ());
TransactionStateSF tFilter;
san += mLedger->peekTransactionMap ()->addRootNode (
mLedger->getTransHash (), data, snfWIRE, &tFilter);
return san.isGood();
@@ -1016,7 +1016,7 @@ std::vector<InboundLedger::neededHash_t> InboundLedger::getNeededHashes ()
if (!mHaveState)
{
AccountStateSF filter (mLedger->getLedgerSeq ());
AccountStateSF filter;
// VFALCO NOTE What's the number 4?
for (auto const& h : mLedger->getNeededAccountStateHashes (4, &filter))
{
@@ -1027,7 +1027,7 @@ std::vector<InboundLedger::neededHash_t> InboundLedger::getNeededHashes ()
if (!mHaveTransactions)
{
TransactionStateSF filter (mLedger->getLedgerSeq ());
TransactionStateSF filter;
// VFALCO NOTE What's the number 4?
for (auto const& h : mLedger->getNeededTransactionHashes (4, &filter))
{

View File

@@ -688,7 +688,7 @@ bool Ledger::saveValidatedLedger (bool current)
s.add32 (HashPrefix::ledgerMaster);
addRaw (s);
getApp().getNodeStore ().store (
hotLEDGER, mLedgerSeq, std::move (s.modData ()), mHash);
hotLEDGER, std::move (s.modData ()), mHash);
}
AcceptedLedger::pointer aLedger;

View File

@@ -27,8 +27,7 @@
namespace ripple {
TransactionStateSF::TransactionStateSF (std::uint32_t ledgerSeq)
: mLedgerSeq (ledgerSeq)
TransactionStateSF::TransactionStateSF()
{
}
@@ -43,7 +42,6 @@ void TransactionStateSF::gotNode (bool fromFilter,
// and this should use that Database instad of getNodeStore
getApp().getNodeStore ().store (
(type == SHAMapTreeNode::tnTRANSACTION_NM) ? hotTRANSACTION : hotTRANSACTION_NODE,
mLedgerSeq,
std::move (nodeData),
nodeHash);
}

View File

@@ -30,7 +30,7 @@ namespace ripple {
class TransactionStateSF : public SHAMapSyncFilter
{
public:
explicit TransactionStateSF (std::uint32_t ledgerSeq);
TransactionStateSF();
// Note that the nodeData is overwritten by this call
void gotNode (bool fromFilter,
@@ -42,9 +42,6 @@ public:
bool haveNode (SHAMapNodeID const& id,
uint256 const& nodeHash,
Blob& nodeData);
private:
std::uint32_t mLedgerSeq;
};
} // ripple

View File

@@ -27,6 +27,8 @@
namespace ripple {
// VFALCO NOTE LedgerIndex in CommittedObjects is obsolete
static const char* s_nodeStoreDBInit [] =
{
"PRAGMA synchronous=NORMAL;",
@@ -94,7 +96,7 @@ public:
uint256 const hash (uint256::fromVoid (key));
static SqliteStatement pSt (m_db->getDB()->getSqliteDB(),
"SELECT ObjType,LedgerIndex,Object FROM CommittedObjects WHERE Hash = ?;");
"SELECT ObjType,Object FROM CommittedObjects WHERE Hash = ?;");
pSt.bind (1, to_string (hash));
@@ -102,10 +104,9 @@ public:
{
// VFALCO NOTE This is unfortunately needed,
// the DatabaseCon creates the blob?
Blob data (pSt.getBlob (2));
Blob data (pSt.getBlob(1));
*pObject = NodeObject::createObject (
getTypeFromString (pSt.peekString (0)),
pSt.getUInt32 (1),
std::move(data),
hash);
}
@@ -131,15 +132,13 @@ public:
void storeBatch (NodeStore::Batch const& batch)
{
// VFALCO TODO Rewrite this to use Beast::db
auto sl (m_db->lock());
static SqliteStatement pStB (m_db->getDB()->getSqliteDB(), "BEGIN TRANSACTION;");
static SqliteStatement pStE (m_db->getDB()->getSqliteDB(), "END TRANSACTION;");
static SqliteStatement pSt (m_db->getDB()->getSqliteDB(),
"INSERT OR IGNORE INTO CommittedObjects "
"(Hash,ObjType,LedgerIndex,Object) VALUES (?, ?, ?, ?);");
"(Hash,ObjType,Object) VALUES (?, ?, ?, ?);");
pStB.step();
pStB.reset();
@@ -163,7 +162,7 @@ public:
uint256 hash;
static SqliteStatement pSt(m_db->getDB()->getSqliteDB(),
"SELECT ObjType,LedgerIndex,Object,Hash FROM CommittedObjects;");
"SELECT ObjType,Object,Hash FROM CommittedObjects;");
while (pSt.isRow (pSt.step()))
{
@@ -171,10 +170,9 @@ public:
// VFALCO NOTE This is unfortunately needed,
// the DatabaseCon creates the blob?
Blob data (pSt.getBlob (2));
Blob data (pSt.getBlob (1));
NodeObject::Ptr const object (NodeObject::createObject (
getTypeFromString (pSt.peekString (0)),
pSt.getUInt32 (1),
std::move(data),
hash));
@@ -207,8 +205,7 @@ public:
statement.bind(1, to_string (object->getHash()));
statement.bind(2, type);
statement.bind(3, object->getLedgerIndex());
statement.bindStatic(4, object->getData());
statement.bindStatic(3, object->getData());
}
NodeObjectType getTypeFromString (std::string const& s)

View File

@@ -106,7 +106,6 @@ public:
@return `true` if the object was stored?
*/
virtual void store (NodeObjectType type,
std::uint32_t ledgerIndex,
Blob&& data,
uint256 const& hash) = 0;

View File

@@ -77,7 +77,6 @@ private:
public:
// This constructor is private, use createObject instead.
NodeObject (NodeObjectType type,
LedgerIndex ledgerIndex,
Blob&& data,
uint256 const& hash,
PrivateAccess);
@@ -94,7 +93,6 @@ public:
@param hash The 256-bit hash of the payload data.
*/
static Ptr createObject (NodeObjectType type,
LedgerIndex ledgerIndex,
Blob&& data,
uint256 const& hash);
@@ -106,10 +104,6 @@ public:
*/
uint256 const& getHash () const;
/** Retrieve the ledger index in which this object appears.
*/
LedgerIndex getLedgerIndex() const;
/** Retrieve the binary data.
*/
Blob const& getData () const;
@@ -136,7 +130,6 @@ public:
private:
NodeObjectType mType;
uint256 mHash;
LedgerIndex mLedgerIndex;
Blob mData;
};

View File

@@ -306,21 +306,19 @@ public:
//------------------------------------------------------------------------------
void store (NodeObjectType type,
std::uint32_t index,
Blob&& data,
uint256 const& hash)
uint256 const& hash) override
{
storeInternal (type, index, std::move(data), hash, *m_backend.get());
storeInternal (type, std::move(data), hash, *m_backend.get());
}
void storeInternal (NodeObjectType type,
std::uint32_t index,
Blob&& data,
uint256 const& hash,
Backend& backend)
{
NodeObject::Ptr object = NodeObject::createObject(type, index,
std::move(data), hash);
NodeObject::Ptr object = NodeObject::createObject(
type, std::move(data), hash);
#if RIPPLE_VERIFY_NODEOBJECT_KEYS
assert (hash == Serializer::getSHA512Half (data));

View File

@@ -110,11 +110,10 @@ public:
}
void store (NodeObjectType type,
std::uint32_t index,
Blob&& data,
uint256 const& hash) override
{
storeInternal (type, index, std::move(data), hash,
storeInternal (type, std::move(data), hash,
*getWritableBackend());
}

View File

@@ -40,17 +40,10 @@ DecodedBlob::DecodedBlob (void const* key, void const* value, int valueBytes)
m_success = false;
m_key = key;
// VFALCO NOTE Ledger indexes should have started at 1
m_ledgerIndex = LedgerIndex (-1);
m_objectType = hotUNKNOWN;
m_objectData = nullptr;
m_dataBytes = std::max (0, valueBytes - 9);
if (valueBytes > 4)
{
LedgerIndex const* index = static_cast <LedgerIndex const*> (value);
m_ledgerIndex = beast::ByteOrder::swapIfLittleEndian (*index);
}
// VFALCO NOTE What about bytes 4 through 7 inclusive?
if (valueBytes > 8)
@@ -90,7 +83,7 @@ NodeObject::Ptr DecodedBlob::createObject ()
Blob data(m_objectData, m_objectData + m_dataBytes);
object = NodeObject::createObject (
m_objectType, m_ledgerIndex, std::move(data), uint256::fromVoid(m_key));
m_objectType, std::move(data), uint256::fromVoid(m_key));
}
return object;

View File

@@ -51,7 +51,6 @@ private:
bool m_success;
void const* m_key;
LedgerIndex m_ledgerIndex;
NodeObjectType m_objectType;
unsigned char const* m_objectData;
int m_dataBytes;

View File

@@ -27,30 +27,27 @@ namespace NodeStore {
void
EncodedBlob::prepare (NodeObject::Ptr const& object)
{
m_key = object->getHash ().begin ();
m_key = object->getHash().begin ();
// This is how many bytes we need in the flat data
m_size = object->getData ().size () + 9;
m_data.ensureSize (m_size);
// These sizes must be the same!
static_assert (sizeof (std::uint32_t) == sizeof (object->getLedgerIndex ()),
"Ledger Indices must be exactly 32-bits long.");
m_data.ensureSize(m_size);
{
std::uint32_t* buf = static_cast <std::uint32_t*> (m_data.getData ());
buf [0] = beast::ByteOrder::swapIfLittleEndian (object->getLedgerIndex ());
buf [1] = beast::ByteOrder::swapIfLittleEndian (object->getLedgerIndex ());
// these 8 bytes are unused
std::uint64_t* buf = static_cast <
std::uint64_t*>(m_data.getData ());
*buf = 0;
}
{
unsigned char* buf = static_cast <unsigned char*> (m_data.getData ());
buf [8] = static_cast <unsigned char> (object->getType ());
memcpy (&buf [9], object->getData ().data (), object->getData ().size ());
unsigned char* buf = static_cast <
unsigned char*> (m_data.getData ());
buf [8] = static_cast <
unsigned char> (object->getType ());
memcpy (&buf [9], object->getData ().data(),
object->getData ().size());
}
}

View File

@@ -27,13 +27,11 @@ namespace ripple {
NodeObject::NodeObject (
NodeObjectType type,
LedgerIndex ledgerIndex,
Blob&& data,
uint256 const& hash,
PrivateAccess)
: mType (type)
, mHash (hash)
, mLedgerIndex (ledgerIndex)
{
mData = std::move (data);
}
@@ -41,12 +39,11 @@ NodeObject::NodeObject (
NodeObject::Ptr
NodeObject::createObject (
NodeObjectType type,
LedgerIndex ledgerIndex,
Blob&& data,
uint256 const& hash)
{
return std::make_shared <NodeObject> (
type, ledgerIndex, std::move (data), hash, PrivateAccess ());
type, std::move (data), hash, PrivateAccess ());
}
NodeObjectType
@@ -61,12 +58,6 @@ NodeObject::getHash () const
return mHash;
}
LedgerIndex
NodeObject::getLedgerIndex () const
{
return mLedgerIndex;
}
Blob const&
NodeObject::getData () const
{
@@ -82,9 +73,6 @@ NodeObject::isCloneOf (NodeObject::Ptr const& other) const
if (mHash != other->mHash)
return false;
if (mLedgerIndex != other->mLedgerIndex)
return false;
if (mData != other->mData)
return false;

View File

@@ -66,8 +66,6 @@ public:
break;
};
LedgerIndex ledgerIndex = 1 + r.nextInt (1024 * 1024);
uint256 hash;
r.fillBitsRandomly (hash.begin (), hash.size ());
@@ -77,7 +75,7 @@ public:
r.fillBitsRandomly (data.data (), payloadBytes);
return NodeObject::createObject(type, ledgerIndex, std::move(data), hash);
return NodeObject::createObject(type, std::move(data), hash);
}
private:
@@ -176,7 +174,6 @@ public:
Blob data (object->getData ());
db.store (object->getType (),
object->getLedgerIndex (),
std::move (data),
object->getHash ());
}

View File

@@ -84,7 +84,6 @@ private:
beast::xor_shift_engine gen_;
std::uint8_t prefix_;
std::uniform_int_distribution<std::uint32_t> d_seq_;
std::uniform_int_distribution<std::uint32_t> d_type_;
std::uniform_int_distribution<std::uint32_t> d_size_;
@@ -92,7 +91,6 @@ public:
explicit
Sequence(std::uint8_t prefix)
: prefix_ (prefix)
, d_seq_ (minLedger, maxLedger)
, d_type_ (hotLEDGER, hotTRANSACTION_NODE)
, d_size_ (minSize, maxSize)
{
@@ -122,7 +120,7 @@ public:
rngcpy (&value[0], value.size(), gen_);
return NodeObject::createObject (
static_cast<NodeObjectType>(d_type_(gen_)),
d_seq_(gen_), std::move(value), key);
std::move(value), key);
}
// returns a batch of NodeObjects starting at n

View File

@@ -1401,8 +1401,7 @@ PeerImp::onMessage (std::shared_ptr <protocol::TMGetObjectByHash> const& m)
if (obj.has_nodeid ())
newObj.set_index (obj.nodeid ());
if (!reply.has_seq () && (hObj->getLedgerIndex () != 0))
reply.set_seq (hObj->getLedgerIndex ());
// VFALCO NOTE "seq" in the message is obsolete
}
}
}

View File

@@ -943,8 +943,8 @@ void SHAMap::writeNode (
Serializer s;
node->addRaw (s, snfPREFIX);
db_.store (t, seq,
std::move (s.modData ()), node->getNodeHash ());
db_.store (t, std::move (s.modData()),
node->getNodeHash ());
}
// We can't modify an inner node someone else might have a