Skip to content

Commit 85d44c2

Browse files
committed
docs(toolkit): clarify lite snapshot trace exclusion
1 parent 296a784 commit 85d44c2

3 files changed

Lines changed: 20 additions & 16 deletions

File tree

plugins/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ DB lite provides lite database, parameters are compatible with previous `LiteFul
7575
- `-fn | --fn-data-path`: The database path to be split or merged.
7676
- `-ds | --dataset-path`: When operation is `split`,`dataset-path` is the path that store the `snapshot` or `history`, when
7777
operation is `split`, `dataset-path` is the `history` data path.
78-
- `--exclude-historical-balance`: Only used with `operate=split -t snapshot`, default: false. When set to true, `balance-trace` and `account-trace` are excluded from the lite snapshot. The flag has functional impact only when the source full node ran with `historyBalanceLookup=true` (off by default; most operators are unaffected). **WARNING:** for nodes that had `historyBalanceLookup=true`, this loss is permanent — a lite node booted from such a snapshot cannot answer historical balance lookups (`getBlockBalance` / `getAccountBalance`), and running `merge` afterwards will NOT restore the feature. If you need historical balance lookup on the resulting lite node, do **not** enable this flag. `split -t history` and `merge` ignore this flag.
78+
- `--exclude-historical-balance`: Only used with `operate=split -t snapshot`, default: false. When set to true, `balance-trace` and `account-trace` are excluded from the lite snapshot. The flag has functional impact only when the source full node ran with `historyBalanceLookup=true` (off by default; most operators are unaffected). **WARNING:** for nodes that had `historyBalanceLookup=true`, this loss is permanent — a lite node booted from such a snapshot cannot safely serve historical balance lookups (`getBlockBalance` may fail, and `getAccountBalance` may return `balance=0` when `account-trace` data is missing), and running `merge` afterwards will NOT restore the feature. If you need historical balance lookup on the resulting lite node, do **not** enable this flag. `split -t history` and `merge` ignore this flag.
7979
- `-h | --help`: Provide the help info.
8080

8181
### Examples:
@@ -87,7 +87,7 @@ DB lite provides lite database, parameters are compatible with previous `LiteFul
8787
#split and get a snapshot dataset
8888
java -jar Toolkit.jar db lite -o split -t snapshot --fn-data-path output-directory/database --dataset-path /tmp
8989
#split and get a snapshot dataset without balance-trace / account-trace (smaller snapshot;
90-
#historical balance lookup will be permanently unavailable on the resulting lite node)
90+
#historical balance lookup cannot be safely served on the resulting lite node)
9191
java -jar Toolkit.jar db lite -o split -t snapshot --fn-data-path output-directory/database --dataset-path /tmp --exclude-historical-balance
9292
#split and get a history dataset
9393
java -jar Toolkit.jar db lite -o split -t history --fn-data-path output-directory/database --dataset-path /tmp

plugins/src/main/java/common/org/tron/plugins/DbLite.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,12 @@ enum Type { snapshot, history }
120120
+ "This flag only has a functional impact when the source full node ran with "
121121
+ "`historyBalanceLookup=true` (off by default; most operators are unaffected). "
122122
+ "WARNING: when historyBalanceLookup was enabled, this loss is permanent: a lite "
123-
+ "node booted from such a snapshot cannot answer historical balance lookups "
124-
+ "(getBlockBalance / getAccountBalance), and running merge afterwards will NOT "
125-
+ "restore the feature. If you need to keep historyBalanceLookup working on the "
126-
+ "resulting lite node, do NOT enable this flag. `split -t history` and `merge` "
127-
+ "ignore this flag.",
123+
+ "node booted from such a snapshot cannot safely serve historical balance lookups "
124+
+ "(getBlockBalance may fail, and getAccountBalance may return balance=0 when "
125+
+ "account-trace data is missing). Running merge afterwards will NOT restore the "
126+
+ "feature. If you need to keep historyBalanceLookup working on the resulting "
127+
+ "lite node, do NOT enable this flag. `split -t history` and `merge` ignore "
128+
+ "this flag.",
128129
order = 5)
129130
private boolean excludeHistoricalBalance;
130131

@@ -143,8 +144,8 @@ public Integer call() {
143144
try {
144145
switch (this.operate) {
145146
case split:
146-
warnIfExcludingHistoricalBalance();
147147
if (Type.snapshot == this.type) {
148+
warnIfExcludingHistoricalBalance();
148149
generateSnapshot(fnDataPath, datasetPath);
149150
} else if (Type.history == type) {
150151
generateHistory(fnDataPath, datasetPath);
@@ -307,12 +308,14 @@ private void warnIfExcludingHistoricalBalance() {
307308
+ "will be excluded from the lite snapshot. This only matters when the source full "
308309
+ "node ran with historyBalanceLookup=true (off by default; most operators are "
309310
+ "unaffected). When that switch was enabled, this loss is permanent: lite nodes "
310-
+ "booted from this snapshot cannot answer historical balance lookups "
311-
+ "(getBlockBalance / getAccountBalance), and running merge afterwards will NOT "
312-
+ "restore the feature. If you need to keep historyBalanceLookup working on the "
313-
+ "resulting lite node, do NOT use this flag.";
311+
+ "booted from this snapshot cannot safely serve historical balance lookups "
312+
+ "(getBlockBalance may fail, and getAccountBalance may return balance=0 when "
313+
+ "account-trace data is missing). Running merge afterwards will NOT restore the "
314+
+ "feature. If you need to keep historyBalanceLookup working on the resulting "
315+
+ "lite node, do NOT use this flag.";
314316
logger.warn(msg);
315-
spec.commandLine().getErr().println(msg);
317+
spec.commandLine().getErr().println(spec.commandLine().getColorScheme()
318+
.errorText(msg));
316319
}
317320

318321
private List<String> getSnapshotDbs(String sourceDir) {
@@ -786,4 +789,3 @@ public long getSnapshotMaxNum() {
786789
}
787790

788791

789-

plugins/src/test/java/org/tron/plugins/DbLiteTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void shutdown() throws InterruptedException {
7171
context.close();
7272
}
7373

74-
public void init(String dbType) throws IOException {
74+
public void init(String dbType, boolean historyBalanceLookup) throws IOException {
7575
dbPath = folder.newFolder().toString();
7676
Args.setParam(new String[] {
7777
"-d", dbPath, "-w", "--p2p-disable", "true", "--storage-db-engine", dbType},
@@ -80,6 +80,7 @@ public void init(String dbType) throws IOException {
8080
Args.getInstance().setAllowAccountStateRoot(1);
8181
Args.getInstance().setRpcPort(PublicMethod.chooseRandomPort());
8282
Args.getInstance().setRpcEnable(true);
83+
Args.getInstance().setHistoryBalanceLookup(historyBalanceLookup);
8384
databaseDir = Args.getInstance().getStorage().getDbDirectory();
8485
// init dbBackupConfig to avoid NPE
8586
Args.getInstance().dbBackupConfig = DbBackupConfig.getInstance();
@@ -99,7 +100,8 @@ public void testTools(String dbType, int checkpointVersion, boolean excludeHisto
99100
throws InterruptedException, IOException {
100101
logger.info("dbType {}, checkpointVersion {}, excludeHistoricalBalance {}",
101102
dbType, checkpointVersion, excludeHistoricalBalance);
102-
init(dbType);
103+
boolean historyBalanceLookup = excludeHistoricalBalance;
104+
init(dbType, historyBalanceLookup);
103105
final String[] argsForSnapshot = excludeHistoricalBalance
104106
? new String[] {"-o", "split", "-t", "snapshot", "--fn-data-path",
105107
dbPath + File.separator + databaseDir, "--dataset-path",

0 commit comments

Comments
 (0)