diff --git a/database/database.go b/database/database.go index bdc80d97..99d57354 100644 --- a/database/database.go +++ b/database/database.go @@ -37,10 +37,12 @@ func (nfe NotFoundError) Is(target error) bool { return ok } -type BlockNotFoundError chainhash.Hash +type BlockNotFoundError struct { + chainhash.Hash +} func (bnfe BlockNotFoundError) Error() string { - return fmt.Sprintf("block not found: %v", chainhash.Hash(bnfe).String()) + return fmt.Sprintf("block not found: %v", bnfe.Hash) } func (bnfe BlockNotFoundError) Is(target error) bool { @@ -48,10 +50,6 @@ func (bnfe BlockNotFoundError) Is(target error) bool { return ok } -func (bnfe BlockNotFoundError) Hash() chainhash.Hash { - return chainhash.Hash(bnfe) -} - type DuplicateError string func (de DuplicateError) Error() string { @@ -89,7 +87,7 @@ var ( ErrDuplicate = DuplicateError("duplicate") ErrNotFound = NotFoundError("not found") ErrValidation = ValidationError("validation") - ErrBlockNotFound = BlockNotFoundError(chainhash.Hash{}) + ErrBlockNotFound BlockNotFoundError ) // ByteArray is a type that corresponds to BYTEA in a database. It supports diff --git a/database/database_test.go b/database/database_test.go index ece15d78..c203c610 100644 --- a/database/database_test.go +++ b/database/database_test.go @@ -337,7 +337,7 @@ func TestErrors(t *testing.T) { if err != nil { t.Fatal(err) } - err = BlockNotFoundError(*hash) + err = BlockNotFoundError{*hash} if !errors.Is(err, ErrBlockNotFound) { t.Fatalf("expected block not found, got %T", err) } @@ -345,6 +345,14 @@ func TestErrors(t *testing.T) { if !errors.Is(err, ErrBlockNotFound) { t.Fatalf("expected wrapped block not found, got %T", err) } + x := err.(BlockNotFoundError) + t.Logf("%v", spew.Sdump(x)) + var e *BlockNotFoundError + if !errors.As(err, &e) { + t.Fatalf("expected wrapped block not found, got %T %v", err, err) + } + block := e.Hash + t.Logf("%v", block) err = errors.New("moo") if errors.Is(err, ErrBlockNotFound) { t.Fatalf("did not expected block not found, got %T", err) diff --git a/service/tbc/crawler.go b/service/tbc/crawler.go index c71d604e..1d40bc09 100644 --- a/service/tbc/crawler.go +++ b/service/tbc/crawler.go @@ -208,7 +208,7 @@ func (s *Server) isCanonical(ctx context.Context, bh *tbcd.BlockHeader) (bool, e } // Move best block header backwards until we find bh. for { - //log.Infof("isCanonical %v @ %v bh %v", bhb.Height, bhb, bh.Height) + // log.Infof("isCanonical %v @ %v bh %v", bhb.Height, bhb, bh.Height) if height, ok := s.checkpoints[bhb.Hash]; ok && height <= bh.Height { // Did not find bh in path return false, nil diff --git a/service/tbc/tbc.go b/service/tbc/tbc.go index fd03d889..b7ad582f 100644 --- a/service/tbc/tbc.go +++ b/service/tbc/tbc.go @@ -870,6 +870,7 @@ func (s *Server) syncBlocks(ctx context.Context) { } // XXX rethink closure, this is because of index flag mutex. go func() { + var eval *database.BlockNotFoundError err := s.SyncIndexersToBest(ctx) switch { case errors.Is(err, nil): @@ -878,11 +879,13 @@ func (s *Server) syncBlocks(ctx context.Context) { return case errors.Is(err, ErrAlreadyIndexing): return - case errors.Is(err, database.ErrBlockNotFound): - panic(err) + case errors.As(err, &eval): + block := chainhash.Hash(*eval) + panic(block) default: panic(fmt.Errorf("sync blocks: %T %w", err, err)) } + log.Infof("flush -- %v", spew.Sdump(s.Synced(ctx).Synced)) // Get block headers that we missed during indexing. if s.Synced(ctx).Synced {