Closed halibobo1205 closed 2 years ago
The function has been developed, welcome to discuss. https://github.com/tronprotocol/java-tron/pull/4318
The function has been developed, welcome to discuss. tronprotocol/java-tron#4318
new pr: https://github.com/tronprotocol/java-tron/pull/4325/
Close this issue as it is implemented by GreatVoyage-v4.5.0. Check TIP detail at TIP-370 Check implementation PR at https://github.com/tronprotocol/java-tron/pull/4325
Simple Summary
This TIP describes feature about
java-tron
stop block synchronization according to specified conditions, such as a givenblock height
,block timestamp
, make the blockchain stop exactly at a specific state.Abstract
There are some scenarios that require
java-tron
to be stopped according to given conditions, such as givenblock time
,block height
, used fordatabase snapshots
, statistics, etc. So we decided to support this feature,three conditions are considered:block time
,block height
,block sync count
.Motivation
Currently java-tron does not have a very convenient way to get a specific database state, previously perhaps by manual, or additional scripting, which results in either inaccuracy or high maintenance costs. Therefore a convenient way to achieve this purpose is needed.
Specification
For this feature,three conditions are supported,
block time
,block height
,block sync count
after node starts , if there has more than one condition , triggered in order of activation.persistent database
mentioned below is leveldb or rocksdb.1. Conditions
blockHeader
inpersistent database
is matched with a given block time.blockHeader
inpersistent database
is matched with a given block height.block sync count
arrive at a given block count since node start.2. How To Set Conditions.
Add three new settings to the config.conf file as follows.
3. Add New Method To Query Persistent DB Directly For
LatestBlockHeaderNumber
.add new method
getFromRoot
, Input & Output are same as exist get methodBecause of confirmed block principle,
TronStoreWithRevoking
is composed ofsnapshotImpl
(in-memory database ) andsnapshotRoot
(persistent DB). Theget
andput
operations give priority to in-memory snapshotImpl queries, so the currentget
operation cannot directly know thesnapshotRoot
state, such asLatestBlockHeaderNumber
,andLatestSolidifiedBlockNum
is not updated in real-time. So it was decided to add a new method to querysnapshotRoot
directly.4. Init Shutdown Condition According To A Given Condition.
init
stop sync block height
inManager.class
, updatestop sync block height
whenpushBlock
ifnode.shutdown.BlockTime
if has a priority Trigger,see the implementation for details.5. Check
stop sync block height
And Exit.Check
stop sync block height
whenprocessBlock
inTronNetDelegate.class
,when matched withLatestBlockHeaderNumber
inpersistent DB
, stop sync and exit,,see the implementation for details.Rationale
Get
LatestBlockHeaderNumber
by adding a new method to querypersistent DB
directly, add a newexit thread
, whenLatestBlockHeaderNumber
inpersistent DB
meets the given condition, the node stops synchronization and exits. Because it is judged to stop before thepushBlock
, for blocks that have been persisted, the data correctness and integrity have been guaranteed and verified bytwo-thirds
SRs.Implementation
Add New Method For Query
persistent DB
.Init Shutdown Condition According To A Given Condition.