Skip to content

Commit

Permalink
Remove obsolete NodeObject fields:
Browse files Browse the repository at this point in the history
Legacy fields of NodeObject are removed, as they are no longer
used and there is a space savings from omitting them:

* Remove LedgerIndex
  • Loading branch information
vinniefalco committed Feb 11, 2015
1 parent e2a5535 commit f946d7b
Show file tree
Hide file tree
Showing 19 changed files with 53 additions and 104 deletions.
6 changes: 3 additions & 3 deletions src/ripple/app/ledger/AccountStateSF.cpp
Expand Up @@ -27,8 +27,7 @@

namespace ripple {

AccountStateSF::AccountStateSF (std::uint32_t ledgerSeq)
: mLedgerSeq (ledgerSeq)
AccountStateSF::AccountStateSF()
{
}

Expand All @@ -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,
Expand Down
5 changes: 1 addition & 4 deletions src/ripple/app/ledger/AccountStateSF.h
Expand Up @@ -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,
Expand All @@ -41,9 +41,6 @@ class AccountStateSF : public SHAMapSyncFilter
bool haveNode (SHAMapNodeID const& id,
uint256 const& nodeHash,
Blob& nodeData);

private:
std::uint32_t mLedgerSeq;
};

} // ripple
Expand Down
28 changes: 14 additions & 14 deletions src/ripple/app/ledger/InboundLedger.cpp
Expand Up @@ -141,8 +141,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
{
Expand Down Expand Up @@ -172,7 +172,7 @@ bool InboundLedger::tryLocal ()
}
else
{
TransactionStateSF filter (mLedger->getLedgerSeq ());
TransactionStateSF filter;

if (mLedger->peekTransactionMap ()->fetchRoot (
mLedger->getTransHash (), &filter))
Expand Down Expand Up @@ -200,7 +200,7 @@ bool InboundLedger::tryLocal ()
}
else
{
AccountStateSF filter (mLedger->getLedgerSeq ());
AccountStateSF filter;

if (mLedger->peekAccountStateMap ()->fetchRoot (
mLedger->getAccountHash (), &filter))
Expand Down Expand Up @@ -570,7 +570,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();
Expand Down Expand Up @@ -649,7 +649,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);

Expand Down Expand Up @@ -804,8 +804,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 ();

Expand Down Expand Up @@ -841,7 +841,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 ())
{
Expand Down Expand Up @@ -908,7 +908,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 ())
{
Expand Down Expand Up @@ -972,7 +972,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();
Expand All @@ -996,7 +996,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();
Expand All @@ -1015,7 +1015,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))
{
Expand All @@ -1026,7 +1026,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))
{
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/app/ledger/Ledger.cpp
Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions src/ripple/app/ledger/TransactionStateSF.cpp
Expand Up @@ -27,8 +27,7 @@

namespace ripple {

TransactionStateSF::TransactionStateSF (std::uint32_t ledgerSeq)
: mLedgerSeq (ledgerSeq)
TransactionStateSF::TransactionStateSF()
{
}

Expand All @@ -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);
}
Expand Down
5 changes: 1 addition & 4 deletions src/ripple/app/ledger/TransactionStateSF.h
Expand Up @@ -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,
Expand All @@ -42,9 +42,6 @@ class TransactionStateSF : public SHAMapSyncFilter
bool haveNode (SHAMapNodeID const& id,
uint256 const& nodeHash,
Blob& nodeData);

private:
std::uint32_t mLedgerSeq;
};

} // ripple
Expand Down
19 changes: 8 additions & 11 deletions src/ripple/app/node/SqliteFactory.cpp
Expand Up @@ -27,6 +27,8 @@

namespace ripple {

// VFALCO NOTE LedgerIndex in CommittedObjects is obsolete

static const char* s_nodeStoreDBInit [] =
{
"PRAGMA synchronous=NORMAL;",
Expand Down Expand Up @@ -94,18 +96,17 @@ class SqliteBackend : public NodeStore::Backend
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));

if (pSt.isRow (pSt.step()))
{
// 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);
}
Expand All @@ -131,15 +132,13 @@ class SqliteBackend : public NodeStore::Backend

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();
Expand All @@ -163,18 +162,17 @@ class SqliteBackend : public NodeStore::Backend
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()))
{
hash.SetHexExact(pSt.getString(3));

// 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));

Expand Down Expand Up @@ -207,8 +205,7 @@ class SqliteBackend : public NodeStore::Backend

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)
Expand Down
1 change: 0 additions & 1 deletion src/ripple/nodestore/Database.h
Expand Up @@ -106,7 +106,6 @@ class Database
@return `true` if the object was stored?
*/
virtual void store (NodeObjectType type,
std::uint32_t ledgerIndex,
Blob&& data,
uint256 const& hash) = 0;

Expand Down
7 changes: 0 additions & 7 deletions src/ripple/nodestore/NodeObject.h
Expand Up @@ -77,7 +77,6 @@ class NodeObject : public CountedObject <NodeObject>
public:
// This constructor is private, use createObject instead.
NodeObject (NodeObjectType type,
LedgerIndex ledgerIndex,
Blob&& data,
uint256 const& hash,
PrivateAccess);
Expand All @@ -94,7 +93,6 @@ class NodeObject : public CountedObject <NodeObject>
@param hash The 256-bit hash of the payload data.
*/
static Ptr createObject (NodeObjectType type,
LedgerIndex ledgerIndex,
Blob&& data,
uint256 const& hash);

Expand All @@ -106,10 +104,6 @@ class NodeObject : public CountedObject <NodeObject>
*/
uint256 const& getHash () const;

/** Retrieve the ledger index in which this object appears.
*/
LedgerIndex getLedgerIndex() const;

/** Retrieve the binary data.
*/
Blob const& getData () const;
Expand All @@ -136,7 +130,6 @@ class NodeObject : public CountedObject <NodeObject>
private:
NodeObjectType mType;
uint256 mHash;
LedgerIndex mLedgerIndex;
Blob mData;
};

Expand Down
10 changes: 4 additions & 6 deletions src/ripple/nodestore/impl/DatabaseImp.h
Expand Up @@ -309,21 +309,19 @@ class DatabaseImp
//------------------------------------------------------------------------------

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 == getSHA512Half (data));
Expand Down
3 changes: 1 addition & 2 deletions src/ripple/nodestore/impl/DatabaseRotatingImp.h
Expand Up @@ -110,11 +110,10 @@ class DatabaseRotatingImp
}

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());
}

Expand Down
9 changes: 1 addition & 8 deletions src/ripple/nodestore/impl/DecodedBlob.cpp
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/ripple/nodestore/impl/DecodedBlob.h
Expand Up @@ -51,7 +51,6 @@ class DecodedBlob
bool m_success;

void const* m_key;
LedgerIndex m_ledgerIndex;
NodeObjectType m_objectType;
unsigned char const* m_objectData;
int m_dataBytes;
Expand Down

0 comments on commit f946d7b

Please sign in to comment.