Skip to content

Commit

Permalink
404 in /consensus/tip if height is too high
Browse files Browse the repository at this point in the history
  • Loading branch information
chris124567 committed Oct 29, 2024
1 parent 303af61 commit 425df6f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ var (
// ErrTooManyIDs is returned by the batch transaction and contract
// endpoints when more than maxIDs IDs are specified.
ErrTooManyIDs = fmt.Errorf("too many IDs provided (provide less than %d)", maxIDs)

// ErrInvalidTip is returned by /consensus/tip/:height when a block at that
// height does not exist yet.
ErrInvalidTip = errors.New("invalid tip")
)

type server struct {
Expand Down Expand Up @@ -200,6 +204,17 @@ func (s *server) consensusTipHeightHandler(jc jape.Context) {
if jc.DecodeParam("height", &height) != nil {
return
}

maxTip, err := s.e.Tip()
if jc.Check("failed to get tip", err) != nil {
return
}

if height > maxTip.Height {
jc.Error(ErrInvalidTip, http.StatusNotFound)
return
}

tip, err := s.e.BestTip(height)
if jc.Check("failed to get block", err) != nil {
return
Expand Down

0 comments on commit 425df6f

Please sign in to comment.