diff --git a/pkg/api/node_api.go b/pkg/api/node_api.go index 19d63c3ad..167e41e9f 100644 --- a/pkg/api/node_api.go +++ b/pkg/api/node_api.go @@ -793,7 +793,12 @@ func (a *NodeApi) stateHashDebug(height proto.Height) (*proto.StateHashDebug, er if err != nil { return nil, errors.Wrapf(err, "failed to get state hash at height %d", height) } - stateHashDebug := proto.NewStateHashJSDebug(*stateHash, height, a.app.version().Version) + snapshotStateHash, err := a.state.SnapshotStateHashAtHeight(height) + if err != nil { + return nil, errors.Wrapf(err, "failed to get snapshot state hash at height %d", height) + } + version := a.app.version().Version + stateHashDebug := proto.NewStateHashJSDebug(*stateHash, height, version, snapshotStateHash) return &stateHashDebug, nil } @@ -804,8 +809,14 @@ func (a *NodeApi) stateHash(w http.ResponseWriter, r *http.Request) error { // TODO(nickeskov): which error it should send? return &BadRequestError{err} } + if height < 1 { + return apiErrs.BlockDoesNotExist + } stateHashDebug, err := a.stateHashDebug(height) if err != nil { + if state.IsNotFound(err) { + return apiErrs.BlockDoesNotExist + } return errors.Wrap(err, "failed to get state hash debug") } @@ -820,8 +831,15 @@ func (a *NodeApi) stateHashLast(w http.ResponseWriter, _ *http.Request) error { if err != nil { return errors.Wrap(err, "failed to get last height") } - stateHashDebug, err := a.stateHashDebug(height - 1) + h := height - 1 + if h < 1 { + return apiErrs.BlockDoesNotExist + } + stateHashDebug, err := a.stateHashDebug(h) if err != nil { + if state.IsNotFound(err) { + return apiErrs.BlockDoesNotExist + } return errors.Wrap(err, "failed to get last state hash") } if err := trySendJson(w, stateHashDebug); err != nil { @@ -837,6 +855,9 @@ func (a *NodeApi) snapshotStateHash(w http.ResponseWriter, r *http.Request) erro // TODO(nickeskov): which error it should send? return &BadRequestError{err} } + if height < 1 { + return apiErrs.BlockDoesNotExist + } sh, err := a.state.SnapshotStateHashAtHeight(height) if err != nil { if state.IsNotFound(err) { diff --git a/pkg/proto/types.go b/pkg/proto/types.go index 58fe6c15b..1de254e07 100644 --- a/pkg/proto/types.go +++ b/pkg/proto/types.go @@ -4370,12 +4370,13 @@ func (s *StateHash) toStateHashJS() stateHashJS { type StateHashDebug struct { stateHashJS - Height uint64 `json:"height,omitempty"` - Version string `json:"version,omitempty"` + Height uint64 `json:"height,omitempty"` + Version string `json:"version,omitempty"` + SnapshotHash crypto.Digest `json:"snapshotHash"` } -func NewStateHashJSDebug(s StateHash, h uint64, v string) StateHashDebug { - return StateHashDebug{s.toStateHashJS(), h, v} +func NewStateHashJSDebug(s StateHash, h uint64, v string, snapshotStateHash crypto.Digest) StateHashDebug { + return StateHashDebug{s.toStateHashJS(), h, v, snapshotStateHash} } func (s StateHashDebug) GetStateHash() *StateHash {