Keep binary objects in a hash-indexed table. Remove redundant fields.

This commit is contained in:
JoelKatz
2011-11-14 10:39:29 -08:00
parent b4198029af
commit 2c45e16d5a

View File

@@ -1,71 +1,37 @@
CREATE TABLE Transactions ( -- trans in all state CREATE TABLE Transactions ( -- transactions in all states
TransID BLOB PRIMARY KEY, TransID BLOB PRIMARY KEY,
NodeHash BLOB, FromID BLOB, -- 20 byte hash of pub key
FromName BLOB, -- 20 byte hash of pub key
FromPubKey BLOB,
FromSeq BIGINT UNSIGNED, -- account seq FromSeq BIGINT UNSIGNED, -- account seq
DestName BLOB, -- 20 byte hash of pub key FromLedger BIGINT UNSIGNED,
Ident BIGINT, ToID BLOB, -- 20 byte hash of pub key
SourceLedger BIGINT UNSIGNED, -- ledger source expected FirstSeen TEXT, -- time first seen
Signature BLOB, CommitSeq BIGINT UNSIGNED, -- ledger commited to, 0 if none
LedgerCommited BIGINT UNSIGNED, -- 0 if none Status VARCHAR(1) -- (N)ew, (A)ctive, (C)onflicted, (D)one, (H)eld
Status VARCHAR(12) NOT NULL
); );
CREATE INDEX TransHashSet ON Transactions(LedgerCommited, NodeHash);
CREATE TABLE PubKeys ( -- holds pub keys for nodes and accounts CREATE TABLE PubKeys ( -- holds pub keys for nodes and accounts
Hash BLOB PRIMARY KEY, ID BLOB PRIMARY KEY,
PubKey BLOB NOT NULL PubKey BLOB NOT NULL
); );
CREATE TABLE AccountStatus ( -- holds balances and sequence numbers
AccountName BLOB, -- 20 byte hash
Balance BIGINT UNSIGNED,
Seq BIGINT UNSIGNED,
FirstLedger BIGINT UNSIGNED,
LastLedger BIGINT UNSIGNED -- 2^60 if still valid
);
CREATE UNIQUE INDEX CurrentStatus ON AccountStatus(AccountName, LastLedger);
CREATE TABLE Ledgers ( -- closed ledgers CREATE TABLE Ledgers ( -- closed ledgers
LedgerHash BLOB PRIMARY KEY, LedgerHash BLOB PRIMARY KEY,
LedgerSeq BIGINT UNSIGNED, LedgerSeq BIGINT UNSIGNED,
PrevHash BLOB, PrevHash BLOB,
FeeHeld BIGINT UNSIGNED, FeeHeld BIGINT UNSIGNED,
AccountSetHash BLOB, AccountSetHash BLOB,
TransSetHash BLOB, TransSetHash BLOB,
FullyStored VARCHAR(1), -- all data in our db FullyStored VARCHAR(1), -- all data is in our db
Status VARCHAR(1) Status VARCHAR(1) -- (A)ccepted, (C)ompatible, (I)ncompatible
); );
CREATE INDEX SeqLedger ON Ledgers(LedgerSeq); CREATE INDEX SeqLedger ON Ledgers(LedgerSeq);
CREATE TABLE AccountSetHashNodes (
LedgerSeq BIGINT UNSIGNED,
NodeID BLOB,
Hashes BLOB -- 32 hashes, each 20 bytes
);
CREATE UNIQUE INDEX FindAccountHashNodes ON AccountSetHashNodes(LedgerSeq, NodeID);
CREATE TABLE TransSetHashNodes (
LedgerSeq BIGINT UNSIGNED,
NodeID BLOB,
Hashes BLOB -- 32 hashes, each 20 bytes
);
CREATE UNIQUE INDEX FindTransHashNodes ON TransSetHashNodes(LedgerSeq, NodeID);
CREATE TABLE LedgerConfirmations ( CREATE TABLE LedgerConfirmations (
LedgerSeq BIGINT UNSIGNED, LedgerSeq BIGINT UNSIGNED,
@@ -74,7 +40,7 @@ CREATE TABLE LedgerConfirmations (
Signature BLOB Signature BLOB
); );
CREATE INDEX SeqLedgerConf ON LedgerConfirmations(LedgerSeq); CREATE INDEX LedgerConfByHash ON LedgerConfirmations(LedgerHash);
CREATE TABLE TrustedNodes ( CREATE TABLE TrustedNodes (
@@ -84,25 +50,29 @@ CREATE TABLE TrustedNodes (
); );
CREATE TABLE KnownNodes ( CREATE TABLE KnownNodes (
Hanko BLOB PRIMARY KEY, Hanko BLOB PRIMARY KEY,
LastSeen TEXT, -- YYYY-MM-DD HH:MM:SS.SSS LastSeen TEXT, -- YYYY-MM-DD HH:MM:SS.SSS
LastIP BLOB, -- IPv4 or IPv6 HaveContactInfo VARCHAR(1),
LastPort BIGINT UNSIGNED,
ContactObject BLOB ContactObject BLOB
); );
CREATE TABLE ByHash ( -- used to synch nodes
CREATE TABLE CommittedObjects ( -- used to synch nodes
Hash BLOB PRIMARY KEY, Hash BLOB PRIMARY KEY,
ObjType CHAR(1) NOT NULL, ObjType CHAR(1) NOT NULL, -- (L)edger, (T)ransaction, (A)ccount node, transaction (N)ode
LedgerIndex BIGINT UNSIGNED, -- 2^60 if valid now, 0 if none LedgerIndex BIGINT UNSIGNED, -- 0 if none
Object BLOB Object BLOB
); );
CREATE INDEX ObjectLocate ON CommittedObjects(LedgerIndex, ObjType);
CREATE TABLE LocalAccounts ( -- wallet CREATE TABLE LocalAccounts ( -- wallet
Hash BLOB PRIMARY KEY, ID BLOB PRIMARY KEY,
CurrentBalance BIGINT UNSIGNED, Hash BLOB,
KeyFormat TEXT, -- can be encrypted Seq BIGINT UNSIGNED, -- last transaction seen/issued
PrivateKey BLOB Balance BIGINT UNSIGNED,
LedgerSeq BIGINT UNSIGNED, -- ledger this balance is from
KeyFormat TEXT, -- can be encrypted
PrivateKey BLOB,
Comment TEXT Comment TEXT
); );