rippled
DBInit.h
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2012, 2013 Ripple Labs Inc.
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
20 #ifndef RIPPLE_APP_DATA_DBINIT_H_INCLUDED
21 #define RIPPLE_APP_DATA_DBINIT_H_INCLUDED
22 
23 #include <array>
24 
25 namespace ripple {
26 
28 
29 // Ledger database holds ledgers and ledger confirmations
30 inline constexpr auto LgrDBName{"ledger.db"};
31 
33  {"PRAGMA synchronous=NORMAL;",
34  "PRAGMA journal_mode=WAL;",
35  "PRAGMA journal_size_limit=1582080;"}};
36 
38  {"BEGIN TRANSACTION;",
39 
40  "CREATE TABLE IF NOT EXISTS Ledgers ( \
41  LedgerHash CHARACTER(64) PRIMARY KEY, \
42  LedgerSeq BIGINT UNSIGNED, \
43  PrevHash CHARACTER(64), \
44  TotalCoins BIGINT UNSIGNED, \
45  ClosingTime BIGINT UNSIGNED, \
46  PrevClosingTime BIGINT UNSIGNED, \
47  CloseTimeRes BIGINT UNSIGNED, \
48  CloseFlags BIGINT UNSIGNED, \
49  AccountSetHash CHARACTER(64), \
50  TransSetHash CHARACTER(64) \
51  );",
52  "CREATE INDEX IF NOT EXISTS SeqLedger ON Ledgers(LedgerSeq);",
53 
54  // Old table and indexes no longer needed
55  "DROP TABLE IF EXISTS Validations;",
56 
57  "END TRANSACTION;"}};
58 
60 
61 // Transaction database holds transactions and public keys
62 inline constexpr auto TxDBName{"transaction.db"};
63 
64 inline constexpr
65 #if (ULONG_MAX > UINT_MAX) && !defined(NO_SQLITE_MMAP)
68 {
69  {
70 #else
72 #endif
73  "PRAGMA page_size=4096;", "PRAGMA synchronous=NORMAL;",
74  "PRAGMA journal_mode=WAL;", "PRAGMA journal_size_limit=1582080;",
75  "PRAGMA max_page_count=2147483646;",
76 #if (ULONG_MAX > UINT_MAX) && !defined(NO_SQLITE_MMAP)
77  "PRAGMA mmap_size=17179869184;"
78 #endif
79  }
80 };
81 
83  {"BEGIN TRANSACTION;",
84 
85  "CREATE TABLE IF NOT EXISTS Transactions ( \
86  TransID CHARACTER(64) PRIMARY KEY, \
87  TransType CHARACTER(24), \
88  FromAcct CHARACTER(35), \
89  FromSeq BIGINT UNSIGNED, \
90  LedgerSeq BIGINT UNSIGNED, \
91  Status CHARACTER(1), \
92  RawTxn BLOB, \
93  TxnMeta BLOB \
94  );",
95  "CREATE INDEX IF NOT EXISTS TxLgrIndex ON \
96  Transactions(LedgerSeq);",
97 
98  "CREATE TABLE IF NOT EXISTS AccountTransactions ( \
99  TransID CHARACTER(64), \
100  Account CHARACTER(64), \
101  LedgerSeq BIGINT UNSIGNED, \
102  TxnSeq INTEGER \
103  );",
104  "CREATE INDEX IF NOT EXISTS AcctTxIDIndex ON \
105  AccountTransactions(TransID);",
106  "CREATE INDEX IF NOT EXISTS AcctTxIndex ON \
107  AccountTransactions(Account, LedgerSeq, TxnSeq, TransID);",
108  "CREATE INDEX IF NOT EXISTS AcctLgrIndex ON \
109  AccountTransactions(LedgerSeq, Account, TransID);",
110 
111  "END TRANSACTION;"}};
112 
114 
115 // Temporary database used with an incomplete shard that is being acquired
116 inline constexpr auto AcquireShardDBName{"acquire.db"};
117 
119  {"PRAGMA synchronous=NORMAL;",
120  "PRAGMA journal_mode=WAL;",
121  "PRAGMA journal_size_limit=1582080;"}};
122 
124  {"CREATE TABLE IF NOT EXISTS Shard ( \
125  ShardIndex INTEGER PRIMARY KEY, \
126  LastLedgerHash CHARACTER(64), \
127  StoredLedgerSeqs BLOB \
128  );"}};
129 
131 
132 // Pragma for Ledger and Transaction databases with complete shards
134  {"PRAGMA synchronous=OFF;", "PRAGMA journal_mode=OFF;"}};
135 
137 
138 inline constexpr auto WalletDBName{"wallet.db"};
139 
141  {"BEGIN TRANSACTION;",
142 
143  // A node's identity must be persisted, including
144  // for clustering purposes. This table holds one
145  // entry: the server's unique identity, but the
146  // value can be overriden by specifying a node
147  // identity in the config file using a [node_seed]
148  // entry.
149  "CREATE TABLE IF NOT EXISTS NodeIdentity ( \
150  PublicKey CHARACTER(53), \
151  PrivateKey CHARACTER(52) \
152  );",
153 
154  // Peer reservations
155  "CREATE TABLE IF NOT EXISTS PeerReservations ( \
156  PublicKey CHARACTER(53) UNIQUE NOT NULL, \
157  Description CHARACTER(64) NOT NULL \
158  );",
159 
160  // Validator Manifests
161  "CREATE TABLE IF NOT EXISTS ValidatorManifests ( \
162  RawData BLOB NOT NULL \
163  );",
164 
165  "CREATE TABLE IF NOT EXISTS PublisherManifests ( \
166  RawData BLOB NOT NULL \
167  );",
168 
169  "END TRANSACTION;"}};
170 
172 
173 static constexpr auto stateDBName{"state.db"};
174 
176  {"PRAGMA synchronous=FULL;", "PRAGMA journal_mode=DELETE;"}};
177 
179  {"BEGIN TRANSACTION;",
180 
181  "CREATE TABLE IF NOT EXISTS State ( \
182  ShardIndex INTEGER PRIMARY KEY, \
183  URL TEXT \
184  );",
185 
186  "END TRANSACTION;"}};
187 
189  {"BEGIN TRANSACTION;",
190 
191  "CREATE TABLE IF NOT EXISTS download ( \
192  Path TEXT, \
193  Data BLOB, \
194  Size BIGINT UNSIGNED, \
195  Part BIGINT UNSIGNED PRIMARY KEY \
196  );",
197 
198  "END TRANSACTION;"}};
199 
200 } // namespace ripple
201 
202 #endif
ripple::AcquireShardDBName
constexpr auto AcquireShardDBName
Definition: DBInit.h:116
ripple::WalletDBName
constexpr auto WalletDBName
Definition: DBInit.h:138
ripple::AcquireShardDBInit
constexpr std::array< char const *, 1 > AcquireShardDBInit
Definition: DBInit.h:123
ripple::ShardArchiveHandlerDBInit
static constexpr std::array< char const *, 3 > ShardArchiveHandlerDBInit
Definition: DBInit.h:178
ripple::AcquireShardDBPragma
constexpr std::array< char const *, 3 > AcquireShardDBPragma
Definition: DBInit.h:118
ripple::LgrDBInit
constexpr std::array< char const *, 5 > LgrDBInit
Definition: DBInit.h:37
ripple::DownloaderDBPragma
static constexpr std::array< char const *, 2 > DownloaderDBPragma
Definition: DBInit.h:175
ripple::TxDBName
constexpr auto TxDBName
Definition: DBInit.h:62
ripple::LgrDBPragma
constexpr std::array< char const *, 3 > LgrDBPragma
Definition: DBInit.h:32
array
ripple::stateDBName
static constexpr auto stateDBName
Definition: DBInit.h:173
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::DatabaseBodyDBInit
static constexpr std::array< char const *, 3 > DatabaseBodyDBInit
Definition: DBInit.h:188
ripple::CompleteShardDBPragma
constexpr std::array< char const *, 2 > CompleteShardDBPragma
Definition: DBInit.h:133
ripple::TxDBInit
constexpr std::array< char const *, 8 > TxDBInit
Definition: DBInit.h:82
ripple::WalletDBInit
constexpr std::array< char const *, 6 > WalletDBInit
Definition: DBInit.h:140
ripple::TxDBPragma
constexpr std::array< char const *, 5 > TxDBPragma
Definition: DBInit.h:71
ripple::LgrDBName
constexpr auto LgrDBName
Definition: DBInit.h:30