rippled
Loading...
Searching...
No Matches
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#include <cstdint>
25
26namespace ripple {
27
29
30// These pragmas are built at startup and applied to all database
31// connections, unless otherwise noted.
32inline constexpr char const* CommonDBPragmaJournal{"PRAGMA journal_mode=%s;"};
33inline constexpr char const* CommonDBPragmaSync{"PRAGMA synchronous=%s;"};
34inline constexpr char const* CommonDBPragmaTemp{"PRAGMA temp_store=%s;"};
35// A warning will be logged if any lower-safety sqlite tuning settings
36// are used and at least this much ledger history is configured. This
37// includes full history nodes. This is because such a large amount of
38// data will be more difficult to recover if a rare failure occurs,
39// which are more likely with some of the other available tuning settings.
40inline constexpr std::uint32_t SQLITE_TUNING_CUTOFF = 10'000'000;
41
42// Ledger database holds ledgers and ledger confirmations
43inline constexpr auto LgrDBName{"ledger.db"};
44
46 {"BEGIN TRANSACTION;",
47
48 "CREATE TABLE IF NOT EXISTS Ledgers ( \
49 LedgerHash CHARACTER(64) PRIMARY KEY, \
50 LedgerSeq BIGINT UNSIGNED, \
51 PrevHash CHARACTER(64), \
52 TotalCoins BIGINT UNSIGNED, \
53 ClosingTime BIGINT UNSIGNED, \
54 PrevClosingTime BIGINT UNSIGNED, \
55 CloseTimeRes BIGINT UNSIGNED, \
56 CloseFlags BIGINT UNSIGNED, \
57 AccountSetHash CHARACTER(64), \
58 TransSetHash CHARACTER(64) \
59 );",
60 "CREATE INDEX IF NOT EXISTS SeqLedger ON Ledgers(LedgerSeq);",
61
62 // Old table and indexes no longer needed
63 "DROP TABLE IF EXISTS Validations;",
64
65 "END TRANSACTION;"}};
66
68
69// Transaction database holds transactions and public keys
70inline constexpr auto TxDBName{"transaction.db"};
71
73 {"BEGIN TRANSACTION;",
74
75 "CREATE TABLE IF NOT EXISTS Transactions ( \
76 TransID CHARACTER(64) PRIMARY KEY, \
77 TransType CHARACTER(24), \
78 FromAcct CHARACTER(35), \
79 FromSeq BIGINT UNSIGNED, \
80 LedgerSeq BIGINT UNSIGNED, \
81 Status CHARACTER(1), \
82 RawTxn BLOB, \
83 TxnMeta BLOB \
84 );",
85 "CREATE INDEX IF NOT EXISTS TxLgrIndex ON \
86 Transactions(LedgerSeq);",
87
88 "CREATE TABLE IF NOT EXISTS AccountTransactions ( \
89 TransID CHARACTER(64), \
90 Account CHARACTER(64), \
91 LedgerSeq BIGINT UNSIGNED, \
92 TxnSeq INTEGER \
93 );",
94 "CREATE INDEX IF NOT EXISTS AcctTxIDIndex ON \
95 AccountTransactions(TransID);",
96 "CREATE INDEX IF NOT EXISTS AcctTxIndex ON \
97 AccountTransactions(Account, LedgerSeq, TxnSeq, TransID);",
98 "CREATE INDEX IF NOT EXISTS AcctLgrIndex ON \
99 AccountTransactions(LedgerSeq, Account, TransID);",
100
101 "END TRANSACTION;"}};
102
104
105inline constexpr auto WalletDBName{"wallet.db"};
106
108 {"BEGIN TRANSACTION;",
109
110 // A node's identity must be persisted, including
111 // for clustering purposes. This table holds one
112 // entry: the server's unique identity, but the
113 // value can be overriden by specifying a node
114 // identity in the config file using a [node_seed]
115 // entry.
116 "CREATE TABLE IF NOT EXISTS NodeIdentity ( \
117 PublicKey CHARACTER(53), \
118 PrivateKey CHARACTER(52) \
119 );",
120
121 // Peer reservations
122 "CREATE TABLE IF NOT EXISTS PeerReservations ( \
123 PublicKey CHARACTER(53) UNIQUE NOT NULL, \
124 Description CHARACTER(64) NOT NULL \
125 );",
126
127 // Validator Manifests
128 "CREATE TABLE IF NOT EXISTS ValidatorManifests ( \
129 RawData BLOB NOT NULL \
130 );",
131
132 "CREATE TABLE IF NOT EXISTS PublisherManifests ( \
133 RawData BLOB NOT NULL \
134 );",
135
136 "END TRANSACTION;"}};
137
138} // namespace ripple
139
140#endif
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
constexpr std::array< char const *, 8 > TxDBInit
Definition DBInit.h:72
constexpr char const * CommonDBPragmaSync
Definition DBInit.h:33
constexpr auto LgrDBName
Definition DBInit.h:43
constexpr std::array< char const *, 5 > LgrDBInit
Definition DBInit.h:45
constexpr std::array< char const *, 6 > WalletDBInit
Definition DBInit.h:107
constexpr char const * CommonDBPragmaTemp
Definition DBInit.h:34
constexpr std::uint32_t SQLITE_TUNING_CUTOFF
Definition DBInit.h:40
constexpr auto TxDBName
Definition DBInit.h:70
constexpr char const * CommonDBPragmaJournal
Definition DBInit.h:32
constexpr auto WalletDBName
Definition DBInit.h:105