Browse Source

lite2: return if there are no headers in RemoveNoLongerTrustedHeaders (#4378)

pull/4384/head v0.33.1-dev0
Anton Kaliaev 5 years ago
committed by GitHub
parent
commit
aeb6cc475e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions
  1. +7
    -1
      lite2/client.go
  2. +6
    -0
      lite2/client_test.go

+ 7
- 1
lite2/client.go View File

@ -960,11 +960,14 @@ func (c *Client) removeNoLongerTrustedHeadersRoutine() {
// Exposed for testing. // Exposed for testing.
func (c *Client) RemoveNoLongerTrustedHeaders(now time.Time) { func (c *Client) RemoveNoLongerTrustedHeaders(now time.Time) {
// 1) Get the oldest height. // 1) Get the oldest height.
oldestHeight, err := c.trustedStore.FirstSignedHeaderHeight()
oldestHeight, err := c.FirstTrustedHeight()
if err != nil { if err != nil {
c.logger.Error("can't get first trusted height", "err", err) c.logger.Error("can't get first trusted height", "err", err)
return return
} }
if oldestHeight == -1 { // no headers yet => wait
return
}
// 2) Get the latest height. // 2) Get the latest height.
latestHeight, err := c.LastTrustedHeight() 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) c.logger.Error("can't get last trusted height", "err", err)
return return
} }
if latestHeight == -1 { // no headers yet => wait
return
}
// 3) Remove all headers that are outside of the trusting period. // 3) Remove all headers that are outside of the trusting period.
for height := oldestHeight; height <= latestHeight; height++ { for height := oldestHeight; height <= latestHeight; height++ {


+ 6
- 0
lite2/client_test.go View File

@ -307,6 +307,12 @@ func TestClientRemovesNoLongerTrustedHeaders(t *testing.T) {
dbs.New(dbm.NewMemDB(), chainID), dbs.New(dbm.NewMemDB(), chainID),
Logger(log.TestingLogger()), Logger(log.TestingLogger()),
) )
assert.NotPanics(t, func() {
now := bTime.Add(4 * time.Hour).Add(1 * time.Second)
c.RemoveNoLongerTrustedHeaders(now)
})
require.NoError(t, err) require.NoError(t, err)
err = c.Start() err = c.Start()
require.NoError(t, err) require.NoError(t, err)


Loading…
Cancel
Save