mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Ledger hash skip list basic support.
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -86,6 +86,10 @@ static bool LEFInit()
|
||||
<< SOElement(sfHighQualityOut, SOE_OPTIONAL)
|
||||
;
|
||||
|
||||
DECLARE_LEF(LedgerHashes, ltLEDGER_HASHES)
|
||||
<< SOElement(sfHashes, SOE_REQUIRED)
|
||||
;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user