Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

404 in /consensus/tip/:height if height is too high #130

Merged
merged 3 commits into from
Oct 30, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
chris124567 marked this conversation as resolved.
Show resolved Hide resolved
if jc.Check("failed to get block", err) != nil {
return
Expand Down
Loading