wallet/chainntfns: make birthdaySanityCheck return ErrBirthdayBlockNotSet

This commit is contained in:
Wilmer Paulino 2018-11-20 13:00:45 -08:00
parent cc77e41198
commit 80450c9033
No known key found for this signature in database
GPG key ID: 6DF57B9F9514972F
2 changed files with 6 additions and 11 deletions

View file

@ -118,7 +118,7 @@ func (w *Wallet) handleChainNotifications() {
birthdayBlock, err := birthdaySanityCheck( birthdayBlock, err := birthdaySanityCheck(
chainClient, birthdayStore, chainClient, birthdayStore,
) )
if err != nil { if err != nil && !waddrmgr.IsError(err, waddrmgr.ErrBirthdayBlockNotSet) {
err := fmt.Errorf("unable to sanity "+ err := fmt.Errorf("unable to sanity "+
"check wallet birthday block: %v", "check wallet birthday block: %v",
err) 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 // 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 // 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. // 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, func birthdaySanityCheck(chainConn chainConn,
birthdayStore birthdayStore) (*waddrmgr.BlockStamp, error) { birthdayStore birthdayStore) (*waddrmgr.BlockStamp, error) {
// We'll start by fetching our wallet's birthday timestamp and block. // We'll start by fetching our wallet's birthday timestamp and block.
birthdayTimestamp := birthdayStore.Birthday() birthdayTimestamp := birthdayStore.Birthday()
birthdayBlock, birthdayBlockVerified, err := birthdayStore.BirthdayBlock() birthdayBlock, birthdayBlockVerified, err := birthdayStore.BirthdayBlock()
switch { if err != nil {
// 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:
return nil, err return nil, err
} }

View file

@ -147,8 +147,8 @@ func TestBirthdaySanityCheckEmptyBirthdayBlock(t *testing.T) {
birthdayStore := &mockBirthdayStore{} birthdayStore := &mockBirthdayStore{}
birthdayBlock, err := birthdaySanityCheck(chainConn, birthdayStore) birthdayBlock, err := birthdaySanityCheck(chainConn, birthdayStore)
if err != nil { if !waddrmgr.IsError(err, waddrmgr.ErrBirthdayBlockNotSet) {
t.Fatalf("unable to sanity check birthday block: %v", err) t.Fatalf("expected ErrBirthdayBlockNotSet, got %v", err)
} }
if birthdayBlock != nil { if birthdayBlock != nil {