xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
include
xrpl
rdb
DBInit.h
1
#pragma once
2
3
#include <
array
>
4
#include <
cstdint
>
5
#include <format>
6
#include <
string
>
7
#include <
string_view
>
8
9
namespace
xrpl
{
10
12
13
// These pragmas are built at startup and applied to all database
14
// connections, unless otherwise noted.
15
//
16
// They are exposed as functions rather than as format-string constants so
17
// that the un-substituted template can never reach sqlite: an unrecognized
18
// pragma value is silently ignored, so forgetting to interpolate would
19
// leave the setting at its default instead of failing loudly.
20
[[nodiscard]]
inline
std::string
21
commonDbPragmaJournal
(
std::string_view
journalMode)
22
{
23
return
std::format
(
"PRAGMA journal_mode={};"
, journalMode);
24
}
25
26
[[nodiscard]]
inline
std::string
27
commonDbPragmaSync
(
std::string_view
synchronous)
28
{
29
return
std::format
(
"PRAGMA synchronous={};"
, synchronous);
30
}
31
32
[[nodiscard]]
inline
std::string
33
commonDbPragmaTemp
(
std::string_view
tempStore)
34
{
35
return
std::format
(
"PRAGMA temp_store={};"
, tempStore);
36
}
37
38
// A warning will be logged if any lower-safety sqlite tuning settings
39
// are used and at least this much ledger history is configured. This
40
// includes full history nodes. This is because such a large amount of
41
// data will be more difficult to recover if a rare failure occurs,
42
// which are more likely with some of the other available tuning settings.
43
inline
constexpr
std::uint32_t
kSqliteTuningCutoff
= 10'000'000;
44
45
// Ledger database holds ledgers and ledger confirmations
46
inline
constexpr
auto
kLgrDbName
{
"ledger.db"
};
47
48
inline
constexpr
std::array<char const*, 5>
kLgrDbInit
{
49
{
50
"BEGIN TRANSACTION;"
,
51
52
"CREATE TABLE IF NOT EXISTS Ledgers ( \
53
LedgerHash CHARACTER(64) PRIMARY KEY, \
54
LedgerSeq BIGINT UNSIGNED, \
55
PrevHash CHARACTER(64), \
56
TotalCoins BIGINT UNSIGNED, \
57
ClosingTime BIGINT UNSIGNED, \
58
PrevClosingTime BIGINT UNSIGNED, \
59
CloseTimeRes BIGINT UNSIGNED, \
60
CloseFlags BIGINT UNSIGNED, \
61
AccountSetHash CHARACTER(64), \
62
TransSetHash CHARACTER(64) \
63
);"
,
64
"CREATE INDEX IF NOT EXISTS SeqLedger ON Ledgers(LedgerSeq);"
,
65
66
// Old table and indexes no longer needed
67
"DROP TABLE IF EXISTS Validations;"
,
68
69
"END TRANSACTION;"
,
70
},
71
};
72
74
75
// Transaction database holds transactions and public keys
76
inline
constexpr
auto
kTxDbName
{
"transaction.db"
};
77
78
inline
constexpr
std::array<char const*, 8>
kTxDbInit
{
79
{
80
"BEGIN TRANSACTION;"
,
81
82
"CREATE TABLE IF NOT EXISTS Transactions ( \
83
TransID CHARACTER(64) PRIMARY KEY, \
84
TransType CHARACTER(24), \
85
FromAcct CHARACTER(35), \
86
FromSeq BIGINT UNSIGNED, \
87
LedgerSeq BIGINT UNSIGNED, \
88
Status CHARACTER(1), \
89
RawTxn BLOB, \
90
TxnMeta BLOB \
91
);"
,
92
"CREATE INDEX IF NOT EXISTS TxLgrIndex ON \
93
Transactions(LedgerSeq);"
,
94
95
"CREATE TABLE IF NOT EXISTS AccountTransactions ( \
96
TransID CHARACTER(64), \
97
Account CHARACTER(64), \
98
LedgerSeq BIGINT UNSIGNED, \
99
TxnSeq INTEGER \
100
);"
,
101
"CREATE INDEX IF NOT EXISTS AcctTxIDIndex ON \
102
AccountTransactions(TransID);"
,
103
"CREATE INDEX IF NOT EXISTS AcctTxIndex ON \
104
AccountTransactions(Account, LedgerSeq, TxnSeq, TransID);"
,
105
"CREATE INDEX IF NOT EXISTS AcctLgrIndex ON \
106
AccountTransactions(LedgerSeq, Account, TransID);"
,
107
108
"END TRANSACTION;"
,
109
},
110
};
111
113
114
inline
constexpr
auto
kWalletDbName
{
"wallet.db"
};
115
116
inline
constexpr
std::array<char const*, 6>
kWalletDbInit
{
117
{
118
"BEGIN TRANSACTION;"
,
119
120
// A node's identity must be persisted, including
121
// for clustering purposes. This table holds one
122
// entry: the server's unique identity, but the
123
// value can be overriden by specifying a node
124
// identity in the config file using a [node_seed]
125
// entry.
126
"CREATE TABLE IF NOT EXISTS NodeIdentity ( \
127
PublicKey CHARACTER(53), \
128
PrivateKey CHARACTER(52) \
129
);"
,
130
131
// Peer reservations
132
"CREATE TABLE IF NOT EXISTS PeerReservations ( \
133
PublicKey CHARACTER(53) UNIQUE NOT NULL, \
134
Description CHARACTER(64) NOT NULL \
135
);"
,
136
137
// Validator Manifests
138
"CREATE TABLE IF NOT EXISTS ValidatorManifests ( \
139
RawData BLOB NOT NULL \
140
);"
,
141
142
"CREATE TABLE IF NOT EXISTS PublisherManifests ( \
143
RawData BLOB NOT NULL \
144
);"
,
145
146
"END TRANSACTION;"
,
147
},
148
};
149
150
}
// namespace xrpl
array
std::string
std::string_view
cstdint
std::format
T format(T... args)
std::uint32_t
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::kLgrDbInit
constexpr std::array< char const *, 5 > kLgrDbInit
Definition
DBInit.h:48
xrpl::kSqliteTuningCutoff
constexpr std::uint32_t kSqliteTuningCutoff
Definition
DBInit.h:43
xrpl::kTxDbInit
constexpr std::array< char const *, 8 > kTxDbInit
Definition
DBInit.h:78
xrpl::kWalletDbName
constexpr auto kWalletDbName
Definition
DBInit.h:114
xrpl::commonDbPragmaJournal
std::string commonDbPragmaJournal(std::string_view journalMode)
Definition
DBInit.h:21
xrpl::kLgrDbName
constexpr auto kLgrDbName
Definition
DBInit.h:46
xrpl::kWalletDbInit
constexpr std::array< char const *, 6 > kWalletDbInit
Definition
DBInit.h:116
xrpl::commonDbPragmaTemp
std::string commonDbPragmaTemp(std::string_view tempStore)
Definition
DBInit.h:33
xrpl::kTxDbName
constexpr auto kTxDbName
Definition
DBInit.h:76
xrpl::commonDbPragmaSync
std::string commonDbPragmaSync(std::string_view synchronous)
Definition
DBInit.h:27
string
string_view
Generated by
1.17.0