@@ -613,22 +613,52 @@ func (h *blockHeaderStore) ChainTip() (*wire.BlockHeader, uint32, error) {
613613 return & latestHeader , tipHeight , nil
614614}
615615
616- // FilterHeaderStore is an implementation of a fully fledged database for any
617- // variant of filter headers. The FilterHeaderStore combines a flat file to
616+ // FilterHeaderStore defines the interface for storing and retrieving filter
617+ // headers.
618+ type FilterHeaderStore interface {
619+ // ChainTip returns the hash and height of the latest filter header.
620+ ChainTip () (* chainhash.Hash , uint32 , error )
621+
622+ // FetchHeader fetches the filter header for a specific block hash.
623+ FetchHeader (hash * chainhash.Hash ) (* chainhash.Hash , error )
624+
625+ // FetchHeaderAncestors fetches the given number of headers starting
626+ // from the specified stop hash and working backwards.
627+ FetchHeaderAncestors (numHeaders uint32 ,
628+ stopHash * chainhash.Hash ) ([]chainhash.Hash , uint32 , error )
629+
630+ // FetchHeaderByHeight fetches the filter header for a specific block
631+ // height.
632+ FetchHeaderByHeight (height uint32 ) (* chainhash.Hash , error )
633+
634+ // WriteHeaders writes a set of filter headers to the store.
635+ WriteHeaders (hdrs ... FilterHeader ) error
636+
637+ // RollbackLastBlock rolls back the last block, returning the new tip
638+ // after rollback.
639+ RollbackLastBlock (newTip * chainhash.Hash ) (* BlockStamp , error )
640+ }
641+
642+ // filterHeaderStore is an implementation of a fully fledged database for any
643+ // variant of filter headers. The filterHeaderStore combines a flat file to
618644// store the block headers with a database instance for managing the index into
619645// the set of flat files.
620- type FilterHeaderStore struct {
646+ type filterHeaderStore struct {
621647 * headerStore
622648}
623649
650+ // Compile-time assertion to ensure filterHeaderStore implements
651+ // FilterHeaderStore interface.
652+ var _ FilterHeaderStore = (* filterHeaderStore )(nil )
653+
624654// NewFilterHeaderStore returns a new instance of the FilterHeaderStore based
625655// on a target file path, filter type, and target net parameters. These
626656// parameters are required as if this is the initial start up of the
627657// FilterHeaderStore, then the initial genesis filter header will need to be
628658// inserted.
629659func NewFilterHeaderStore (filePath string , db walletdb.DB ,
630660 filterType HeaderType , netParams * chaincfg.Params ,
631- headerStateAssertion * FilterHeader ) (* FilterHeaderStore , error ) {
661+ headerStateAssertion * FilterHeader ) (FilterHeaderStore , error ) {
632662
633663 fStore , err := newHeaderStore (db , filePath , filterType )
634664 if err != nil {
@@ -642,7 +672,7 @@ func NewFilterHeaderStore(filePath string, db walletdb.DB,
642672 return nil , err
643673 }
644674
645- fhs := & FilterHeaderStore {
675+ fhs := & filterHeaderStore {
646676 fStore ,
647677 }
648678
@@ -746,7 +776,7 @@ func NewFilterHeaderStore(filePath string, db walletdb.DB,
746776// maybeResetHeaderState will reset the header state if the header assertion
747777// fails, but only if the target height is found. The boolean returned indicates
748778// that header state was reset.
749- func (f * FilterHeaderStore ) maybeResetHeaderState (
779+ func (f * filterHeaderStore ) maybeResetHeaderState (
750780 headerStateAssertion * FilterHeader ) (bool , error ) {
751781
752782 // First, we'll attempt to locate the header at this height. If no such
@@ -781,7 +811,11 @@ func (f *FilterHeaderStore) maybeResetHeaderState(
781811
782812// FetchHeader returns the filter header that corresponds to the passed block
783813// height.
784- func (f * FilterHeaderStore ) FetchHeader (hash * chainhash.Hash ) (* chainhash.Hash , error ) {
814+ //
815+ // NOTE: Part of the FilterHeaderStore interface.
816+ func (f * filterHeaderStore ) FetchHeader (
817+ hash * chainhash.Hash ) (* chainhash.Hash , error ) {
818+
785819 // Lock store for read.
786820 f .mtx .RLock ()
787821 defer f .mtx .RUnlock ()
@@ -795,7 +829,11 @@ func (f *FilterHeaderStore) FetchHeader(hash *chainhash.Hash) (*chainhash.Hash,
795829}
796830
797831// FetchHeaderByHeight returns the filter header for a particular block height.
798- func (f * FilterHeaderStore ) FetchHeaderByHeight (height uint32 ) (* chainhash.Hash , error ) {
832+ //
833+ // NOTE: Part of the FilterHeaderStore interface.
834+ func (f * filterHeaderStore ) FetchHeaderByHeight (
835+ height uint32 ) (* chainhash.Hash , error ) {
836+
799837 // Lock store for read.
800838 f .mtx .RLock ()
801839 defer f .mtx .RUnlock ()
@@ -809,7 +847,9 @@ func (f *FilterHeaderStore) FetchHeaderByHeight(height uint32) (*chainhash.Hash,
809847// then return the final header specified by the stop hash. We'll also return
810848// the starting height of the header range as well so callers can compute the
811849// height of each header without knowing the height of the stop hash.
812- func (f * FilterHeaderStore ) FetchHeaderAncestors (numHeaders uint32 ,
850+ //
851+ // NOTE: Part of the FilterHeaderStore interface.
852+ func (f * filterHeaderStore ) FetchHeaderAncestors (numHeaders uint32 ,
813853 stopHash * chainhash.Hash ) ([]chainhash.Hash , uint32 , error ) {
814854
815855 // First, we'll find the final header in the range, this will be the
@@ -855,7 +895,9 @@ func (f *FilterHeader) toIndexEntry() headerEntry {
855895// WriteHeaders writes a batch of filter headers to persistent storage. The
856896// headers themselves are appended to the flat file, and then the index updated
857897// to reflect the new entries.
858- func (f * FilterHeaderStore ) WriteHeaders (hdrs ... FilterHeader ) error {
898+ //
899+ // NOTE: Part of the FilterHeaderStore interface.
900+ func (f * filterHeaderStore ) WriteHeaders (hdrs ... FilterHeader ) error {
859901 // Lock store for write.
860902 f .mtx .Lock ()
861903 defer f .mtx .Unlock ()
@@ -896,7 +938,9 @@ func (f *FilterHeaderStore) WriteHeaders(hdrs ...FilterHeader) error {
896938
897939// ChainTip returns the latest filter header and height known to the
898940// FilterHeaderStore.
899- func (f * FilterHeaderStore ) ChainTip () (* chainhash.Hash , uint32 , error ) {
941+ //
942+ // NOTE: Part of the FilterHeaderStore interface.
943+ func (f * filterHeaderStore ) ChainTip () (* chainhash.Hash , uint32 , error ) {
900944 // Lock store for read.
901945 f .mtx .RLock ()
902946 defer f .mtx .RUnlock ()
@@ -919,7 +963,11 @@ func (f *FilterHeaderStore) ChainTip() (*chainhash.Hash, uint32, error) {
919963// re-org which disconnects the latest filter header from the end of the main
920964// chain. The information about the latest header tip after truncation is
921965// returned.
922- func (f * FilterHeaderStore ) RollbackLastBlock (newTip * chainhash.Hash ) (* BlockStamp , error ) {
966+ //
967+ // NOTE: Part of the FilterHeaderStore interface.
968+ func (f * filterHeaderStore ) RollbackLastBlock (
969+ newTip * chainhash.Hash ) (* BlockStamp , error ) {
970+
923971 // Lock store for write.
924972 f .mtx .Lock ()
925973 defer f .mtx .Unlock ()
0 commit comments