From 80450c9033ffc5e1e3b53e45b05e19a90af2ba7a Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Tue, 20 Nov 2018 13:00:45 -0800 Subject: [PATCH] wallet/chainntfns: make birthdaySanityCheck return ErrBirthdayBlockNotSet --- wallet/chainntfns.go | 13 ++++--------- wallet/chainntfns_test.go | 4 ++-- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/wallet/chainntfns.go b/wallet/chainntfns.go index 4504d48..b719cf9 100644 --- a/wallet/chainntfns.go +++ b/wallet/chainntfns.go @@ -118,7 +118,7 @@ func (w *Wallet) handleChainNotifications() { birthdayBlock, err := birthdaySanityCheck( chainClient, birthdayStore, ) - if err != nil { + if err != nil && !waddrmgr.IsError(err, waddrmgr.ErrBirthdayBlockNotSet) { err := fmt.Errorf("unable to sanity "+ "check wallet birthday block: %v", err) @@ -450,20 +450,15 @@ func (s *walletBirthdayStore) SetBirthdayBlock(block waddrmgr.BlockStamp) error // with the backend, but before it begins syncing. This is done as the second // part to the wallet's address manager migration where we populate the birthday // block to ensure we do not miss any relevant events throughout rescans. +// waddrmgr.ErrBirthdayBlockNotSet is returned if the birthday block has not +// been set yet. func birthdaySanityCheck(chainConn chainConn, birthdayStore birthdayStore) (*waddrmgr.BlockStamp, error) { // We'll start by fetching our wallet's birthday timestamp and block. birthdayTimestamp := birthdayStore.Birthday() birthdayBlock, birthdayBlockVerified, err := birthdayStore.BirthdayBlock() - switch { - // If our wallet's birthday block has not been set yet, then this is our - // initial sync, so we'll defer setting it until then. - case waddrmgr.IsError(err, waddrmgr.ErrBirthdayBlockNotSet): - return nil, nil - - // Otherwise, we'll return the error if there was one. - case err != nil: + if err != nil { return nil, err } diff --git a/wallet/chainntfns_test.go b/wallet/chainntfns_test.go index 96ded01..ba7f8aa 100644 --- a/wallet/chainntfns_test.go +++ b/wallet/chainntfns_test.go @@ -147,8 +147,8 @@ func TestBirthdaySanityCheckEmptyBirthdayBlock(t *testing.T) { birthdayStore := &mockBirthdayStore{} birthdayBlock, err := birthdaySanityCheck(chainConn, birthdayStore) - if err != nil { - t.Fatalf("unable to sanity check birthday block: %v", err) + if !waddrmgr.IsError(err, waddrmgr.ErrBirthdayBlockNotSet) { + t.Fatalf("expected ErrBirthdayBlockNotSet, got %v", err) } if birthdayBlock != nil {