Skip to content

Commit

Permalink
Merge branch 'master' into add-country-code
Browse files Browse the repository at this point in the history
  • Loading branch information
chris124567 authored Oct 30, 2024
2 parents cc143d8 + 4536c20 commit c5047c0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
7 changes: 6 additions & 1 deletion api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,15 @@ func (s *server) consensusTipHeightHandler(jc jape.Context) {
if jc.DecodeParam("height", &height) != nil {
return
}

tip, err := s.e.BestTip(height)
if jc.Check("failed to get block", err) != nil {
if errors.Is(err, explorer.ErrNoTip) {
jc.Error(explorer.ErrNoTip, http.StatusNotFound)
return
} else if jc.Check("failed to get tip", err) != nil {
return
}

jc.Encode(tip)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/explored/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func runRootCmd(ctx context.Context, log *zap.Logger) error {
UniqueID: gateway.GenerateUniqueID(),
NetAddress: syncerAddr,
}
s := syncer.New(syncerListener, cm, ps, header, syncer.WithLogger(log.Named("syncer")))
s := syncer.New(syncerListener, cm, ps, header, syncer.WithLogger(log.Named("syncer")), syncer.WithMaxInboundPeers(256))
defer s.Close()
go s.Run(ctx)

Expand Down
5 changes: 2 additions & 3 deletions explorer/explorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ import (
)

var (
// ErrNoTip is returned when Tip() is unable to find any blocks in the
// database and thus there is no tip. It does not mean there was an
// error in the underlying database.
// ErrNoTip is returned when we are unable to find the tip in the
// database or there is no tips at all.
ErrNoTip = errors.New("no tip found")

// ErrContractNotFound is returned when ContractRevisions is unable to find
Expand Down
6 changes: 5 additions & 1 deletion persist/sqlite/blocks.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package sqlite

import (
"database/sql"
"errors"
"fmt"

"go.sia.tech/core/types"
Expand Down Expand Up @@ -58,7 +60,9 @@ func (s *Store) Block(id types.BlockID) (result explorer.Block, err error) {
func (s *Store) BestTip(height uint64) (result types.ChainIndex, err error) {
err = s.transaction(func(tx *txn) error {
err = tx.QueryRow(`SELECT id, height FROM blocks WHERE height=?`, height).Scan(decode(&result.ID), decode(&result.Height))
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
return explorer.ErrNoTip
} else if err != nil {
return err
}

Expand Down

0 comments on commit c5047c0

Please sign in to comment.