Skip to content

Commit 9338676

Browse files
authored
feat: add the db query tool to get latest vote and reward (#57)
1 parent 1c668ef commit 9338676

File tree

10 files changed

+2734
-5
lines changed

10 files changed

+2734
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ We also provide tools to facilitate the CI and testing process:
2626
- `root`: compute merkle root for tiny db. NOTE: large db may GC overhead
2727
limit exceeded.
2828
- `fork`: Modify the database of java-tron for shadow fork testing.
29+
- `query`: Query the latest vote and reward information from the database.
2930
- **Stress Test**: Execute the stress test and evaluate the performance of the `java-tron` fullnode.
3031

3132

tools/toolkit/README.md

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,53 @@ NOTE: large db may GC overhead limit exceeded.
173173

174174

175175
## DB Fork
176-
Database fork tool can help launch a private java-tron FullNode or network based on the state of public chain database to support shadow fork testing.
176+
DB fork tool can help launch a private java-tron FullNode or network based on the state of public chain database to support shadow fork testing.
177177

178178
### Available parameters:
179179
- `-c, --config=<config>`: config the new witnesses, balances, etc for shadow
180180
fork. Default: fork.conf
181-
- `-d, --database-directory=<database>`:
182-
java-tron database directory path. Default:
181+
- `-d, --database-directory=<database>`: java-tron database directory path. Default:
183182
output-directory
184183
- `-r, --retain-witnesses`: retain the previous witnesses and active witnesses.
185184
- `-h, --help`: provide the help info
186185

187186
Please refer [DbFork](DbFork.md) guidance for more details.
187+
188+
## DB Query
189+
The [ListWitnesses](https://developers.tron.network/reference/listwitnesses) and [getReward](https://developers.tron.network/reference/wallet-getreward)
190+
APIs provide vote and reward data only until the end of the last maintenance period.
191+
To obtain the latest information, please query the database directly using the DB query tool.
192+
193+
### Available parameters:
194+
- `-c, --config=<config>`: config the vote and reward options. Default: query.conf
195+
- `-d, --database-directory=<database>`: java-tron database directory path. Default: output-directory
196+
- `-h, --help`: provide the help info
197+
198+
### Examples:
199+
The example of `query.conf`:
200+
```conf
201+
vote = {
202+
allWitnesses = true
203+
witnessList = [
204+
"TPDa1KRmFpLA42WffiXBwEykef9exHNPKV",
205+
"TXnqPcy9zWHYyCiQ7Kmvt3aCx5jm9Qnq3e",
206+
]
207+
}
208+
209+
reward = [
210+
"TLyqzVGLV1srkB7dToTAEqgDSfPtXRJZYH",
211+
"TJvaAeFb8Lykt9RQcVyyTFN2iDvGMuyD4M"
212+
]
213+
```
214+
- `vote.allWitnesses`: configure whether to query the vote information of all witnesses.
215+
- `vote.witnessList`: configure to query the vote information from specified witness list.
216+
The option is valid only when `vote.allWitnesses = false`.
217+
- `reward`: configure the address list you need to query the reward.
218+
219+
Execute query command.
220+
```shell script
221+
# full command
222+
java -jar Toolkit.jar db query [-h] [-c=<config>] [-d=<database>]
223+
# examples
224+
java -jar Toolkit.jar db query -c query.conf -d output-directory
225+
```

tools/toolkit/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ dependencies {
5656
annotationProcessor 'org.projectlombok:lombok:1.18.12'
5757
testCompileOnly 'org.projectlombok:lombok:1.18.12'
5858
testAnnotationProcessor 'org.projectlombok:lombok:1.18.12'
59+
60+
implementation 'com.alibaba:fastjson:1.2.83'
5961
}
6062

6163
application {

tools/toolkit/src/main/java/org/tron/plugins/Db.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
DbLite.class,
1414
DbCopy.class,
1515
DbRoot.class,
16-
DbFork.class
16+
DbFork.class,
17+
DbQuery.class
1718
},
1819
commandListHeading = "%nCommands:%n%nThe most commonly used db commands are:%n"
1920
)

tools/toolkit/src/main/java/org/tron/plugins/DbFork.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public Integer call() throws IOException, RocksDBException {
148148
Config forkConfig = ConfigFactory.load();
149149
File file = Paths.get(config).toFile();
150150
if (file.exists() && file.isFile()) {
151-
forkConfig = ConfigFactory.parseFile(Paths.get(config).toFile());
151+
forkConfig = ConfigFactory.parseFile(file);
152152
} else {
153153
logger.error("Fork config file [" + config + "] not exists!");
154154
spec.commandLine().getErr().format("Fork config file: %s not exists!", config).println();

0 commit comments

Comments
 (0)