Skip to content

Commit

Permalink
Show
Browse files Browse the repository at this point in the history
  • Loading branch information
marcopeereboom committed Nov 5, 2024
1 parent 71b1549 commit 617e0f5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
12 changes: 5 additions & 7 deletions database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,19 @@ 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 {
_, ok := target.(BlockNotFoundError)
return ok
}

func (bnfe BlockNotFoundError) Hash() chainhash.Hash {
return chainhash.Hash(bnfe)
}

type DuplicateError string

func (de DuplicateError) Error() string {
Expand Down Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion database/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,14 +337,22 @@ 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)
}
err = fmt.Errorf("wrap %w", err)
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)
Expand Down
2 changes: 1 addition & 1 deletion service/tbc/crawler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions service/tbc/tbc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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 {
Expand Down

0 comments on commit 617e0f5

Please sign in to comment.