tendermint / light-client

DEPRECATED: A light client for tendermint, supporting signatures, proofs, and validation (see github.com/tendermint/tendermint/lite)
Other
17 stars 9 forks source link

Garbage collect old seeds #41

Closed ethanfrey closed 6 years ago

ethanfrey commented 7 years ago

We don't want info to grow forever, and we can safely delete old seeds, at least those beyond the unbonding period. After some discussion with Jae, the following will allow this functionality.

1) Extend the provider interface:

type Provider interface {
    StoreSeed(seed Seed) error
    // GetByHeight returns the closest seed at with height <= h
    GetByHeight(h int) (Seed, error)
    // GetByHash returns a seed exactly matching this validator hash
    GetByHash(hash []byte) (Seed, error)

        // NEW: delete all headers before height h, and the validator sets that are safe to delete
        CleanupBefore(h int)
}

2) Store extra info with the persisted validators

A validator hash may be used by multiple headers, even non-sequentially. We only store it one time, so to safely cleanup, we need to be able to determine the last height that used this validator hash. To do so, when persisting a validator set, we persist hash -> (lastHeight, ValSet). When we store a new header, and the validator set already is stored, just update lastHeight.

When doing cleanup, loop through all headers, record which validator hashes they have and delete the headers. Then go through and check which of those validators one can safely delete (often many headers will use the same validators).