Ledger hash skip list basic support.

This commit is contained in:
JoelKatz
2012-10-29 12:55:52 -07:00
parent 0db9fc865c
commit 7cd8be5b2b
5 changed files with 48 additions and 0 deletions

View File

@@ -885,6 +885,41 @@ uint256 Ledger::getAccountRootIndex(const uint160& uAccountID)
return s.getSHA512Half();
}
uint256 Ledger::getLedgerHashIndex()
{ // get the index of the node that holds the last 256 ledgers
Serializer s(2);
s.add16(spaceHashes);
return s.getSHA512Half();
}
uint256 Ledger::getLedgerHashIndex(uint32 desiredLedgerIndex)
{ // 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)
Serializer s(6);
s.add16(spaceHashes);
s.add32(desiredLedgerIndex >> 16);
return s.getSHA512Half();
}
int Ledger::getLedgerHashOffset(uint32 ledgerIndex)
{ // get the offset for this ledger's hash (or the first one after it) in the every-256-ledger table
return (ledgerIndex >> 8) % 256;
}
int Ledger::getLedgerHashOffset(uint32 desiredLedgerIndex, uint32 currentLedgerIndex)
{ // get the offset for this ledger's hash in the every-ledger table, -1 if not in it
if (desiredLedgerIndex >= currentLedgerIndex)
return -1;
if (currentLedgerIndex < 256)
return desiredLedgerIndex;
if (desiredLedgerIndex < (currentLedgerIndex - 256))
return -1;
return currentLedgerIndex - desiredLedgerIndex - 1;
}
uint256 Ledger::getBookBase(const uint160& uTakerPaysCurrency, const uint160& uTakerPaysIssuerID,
const uint160& uTakerGetsCurrency, const uint160& uTakerGetsIssuerID)
{

View File

@@ -178,6 +178,12 @@ public:
uint256 getPrevLedgerIndex(const uint256& uHash); // last node <hash
uint256 getPrevLedgerIndex(const uint256& uHash, const uint256& uBegin); // last node <hash, >begin
// Ledger hash table function
static uint256 getLedgerHashIndex();
static uint256 getLedgerHashIndex(uint32 desiredLedgerIndex);
static int getLedgerHashOffset(uint32 desiredLedgerIndex);
static int getLedgerHashOffset(uint32 desiredLedgerIndex, uint32 currentLedgerIndex);
// index calculation functions
static uint256 getAccountRootIndex(const uint160& uAccountID);

View File

@@ -86,6 +86,10 @@ static bool LEFInit()
<< SOElement(sfHighQualityOut, SOE_OPTIONAL)
;
DECLARE_LEF(LedgerHashes, ltLEDGER_HASHES)
<< SOElement(sfHashes, SOE_REQUIRED)
;
return true;
}

View File

@@ -14,6 +14,7 @@ enum LedgerEntryType
ltNICKNAME = 'n',
ltOFFER = 'o',
ltCONTRACT = 'c',
ltLEDGER_HASHES = 'h',
};
// Used as a prefix for computing ledger indexes (keys).
@@ -28,6 +29,7 @@ enum LedgerNameSpace
spaceOwnerDir = 'O', // Directory of things owned by an account.
spaceBookDir = 'B', // Directory of order books.
spaceContract = 'c',
spaceHashes = 'h',
};
enum LedgerSpecificFlags

View File

@@ -122,6 +122,7 @@
// vector of 256-bit
FIELD(Indexes, VECTOR256, 1)
FIELD(Hashes, VECTOR256, 2)
// inner object
// OBJECT/1 is reserved for end of object