mirror of
https://github.com/tendermint/tendermint.git
synced 2026-07-20 15:02:33 +00:00
lite2: return if there are no headers in RemoveNoLongerTrustedHeaders (#4378)
This commit is contained in:
+7
-1
@@ -960,11 +960,14 @@ func (c *Client) removeNoLongerTrustedHeadersRoutine() {
|
||||
// Exposed for testing.
|
||||
func (c *Client) RemoveNoLongerTrustedHeaders(now time.Time) {
|
||||
// 1) Get the oldest height.
|
||||
oldestHeight, err := c.trustedStore.FirstSignedHeaderHeight()
|
||||
oldestHeight, err := c.FirstTrustedHeight()
|
||||
if err != nil {
|
||||
c.logger.Error("can't get first trusted height", "err", err)
|
||||
return
|
||||
}
|
||||
if oldestHeight == -1 { // no headers yet => wait
|
||||
return
|
||||
}
|
||||
|
||||
// 2) Get the latest height.
|
||||
latestHeight, err := c.LastTrustedHeight()
|
||||
@@ -972,6 +975,9 @@ func (c *Client) RemoveNoLongerTrustedHeaders(now time.Time) {
|
||||
c.logger.Error("can't get last trusted height", "err", err)
|
||||
return
|
||||
}
|
||||
if latestHeight == -1 { // no headers yet => wait
|
||||
return
|
||||
}
|
||||
|
||||
// 3) Remove all headers that are outside of the trusting period.
|
||||
for height := oldestHeight; height <= latestHeight; height++ {
|
||||
|
||||
@@ -307,6 +307,12 @@ func TestClientRemovesNoLongerTrustedHeaders(t *testing.T) {
|
||||
dbs.New(dbm.NewMemDB(), chainID),
|
||||
Logger(log.TestingLogger()),
|
||||
)
|
||||
|
||||
assert.NotPanics(t, func() {
|
||||
now := bTime.Add(4 * time.Hour).Add(1 * time.Second)
|
||||
c.RemoveNoLongerTrustedHeaders(now)
|
||||
})
|
||||
|
||||
require.NoError(t, err)
|
||||
err = c.Start()
|
||||
require.NoError(t, err)
|
||||
|
||||
Reference in New Issue
Block a user