|
@ -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++ { |
|
|