mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-10 23:10:59 +00:00
lite2: refactor cleanup() (#4343)
* lite2: add Start method There are few reasons to do that: 1) separation of state and dynamics (some users will want to delay starting the light client; does not matter we should not allow them to create a light client object) 2) less important, but some users might not need autoUpdateRoutine and removeNoLongerTrustedHeadersRoutine routines * lite2: wait till routines are finished in Stop because they are started in Start, it feels more natural to wait for them to finish in Stop. * lite2: add TrustedValidatorSet func * refactor cleanup code * changed restore header and val function to handle negative height * reverted restoreTrustedHeaderAndNextVals() functionality Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
This commit is contained in:
committed by
Anton Kaliaev
parent
c5ecd802a2
commit
85244a42ea
@@ -282,8 +282,6 @@ func (c *Client) checkTrustedHeaderUsingOptions(options TrustOptions) error {
|
||||
if c.confirmationFn(action) {
|
||||
// remove all the headers ( options.Height, trustedHeader.Height ]
|
||||
c.cleanup(options.Height + 1)
|
||||
// set c.trustedHeader to one at options.Height
|
||||
c.restoreTrustedHeaderAndNextVals()
|
||||
|
||||
c.logger.Info("Rolled back to older header (newer headers were removed)",
|
||||
"old", options.Height)
|
||||
@@ -555,7 +553,7 @@ func (c *Client) Cleanup() error {
|
||||
return c.cleanup(0)
|
||||
}
|
||||
|
||||
// stopHeight=0 -> remove all data
|
||||
// cleanup deletes all headers & validator sets between +stopHeight+ and latest height included
|
||||
func (c *Client) cleanup(stopHeight int64) error {
|
||||
// 1) Get the oldest height.
|
||||
oldestHeight, err := c.trustedStore.FirstSignedHeaderHeight()
|
||||
@@ -570,7 +568,7 @@ func (c *Client) cleanup(stopHeight int64) error {
|
||||
}
|
||||
|
||||
// 3) Remove all headers and validator sets.
|
||||
if stopHeight == 0 {
|
||||
if stopHeight < oldestHeight {
|
||||
stopHeight = oldestHeight
|
||||
}
|
||||
for height := stopHeight; height <= latestHeight; height++ {
|
||||
@@ -583,6 +581,10 @@ func (c *Client) cleanup(stopHeight int64) error {
|
||||
|
||||
c.trustedHeader = nil
|
||||
c.trustedNextVals = nil
|
||||
err = c.restoreTrustedHeaderAndNextVals()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user