Skip to content

Commit

Permalink
added errors to abci query
Browse files Browse the repository at this point in the history
  • Loading branch information
brennanjl committed Sep 11, 2024
1 parent af26b01 commit 32dd3fc
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions internal/abci/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -1594,12 +1594,10 @@ func (a *AbciApp) ProcessProposal(ctx context.Context, req *abciTypes.RequestPro

func (a *AbciApp) Query(ctx context.Context, req *abciTypes.RequestQuery) (*abciTypes.ResponseQuery, error) {
a.log.Debug("ABCI Query", zap.String("path", req.Path), zap.String("data", string(req.Data)))

switch {
// TODO: why do we not return errors in case of the snapshotter not being configured?
case req.Path == statesync.ABCISnapshotQueryPath:
if a.snapshotter == nil {
return &abciTypes.ResponseQuery{}, nil
return nil, fmt.Errorf("this node is not configured to serve snapshots")
}

var snapshot *statesync.Snapshot
Expand All @@ -1616,21 +1614,21 @@ func (a *AbciApp) Query(ctx context.Context, req *abciTypes.RequestQuery) (*abci
}

if !exists {
return &abciTypes.ResponseQuery{}, nil
return nil, fmt.Errorf("snapshot not found for height %s", height)
}

bts, err := json.Marshal(snapshot)
bts, err := snapshot.MarshalBinary()
if err != nil {
return nil, err
}
return &abciTypes.ResponseQuery{Value: bts}, nil
case req.Path == statesync.ABCILatestSnapshotHeightPath:
if a.snapshotter == nil {
return &abciTypes.ResponseQuery{}, nil
return nil, fmt.Errorf("this node is not configured to serve snapshots")
}
snaps := a.snapshotter.ListSnapshots()
if len(snaps) == 0 {
return &abciTypes.ResponseQuery{}, nil
return nil, fmt.Errorf("no snapshots available")
}
latest := snaps[len(snaps)-1]
for _, snap := range snaps {
Expand All @@ -1656,7 +1654,7 @@ func (a *AbciApp) Query(ctx context.Context, req *abciTypes.RequestQuery) (*abci

paths := strings.Split(req.Path[ABCIPeerFilterPathLen:], "/")
if len(paths) != 2 {
return &abciTypes.ResponseQuery{Code: 1}, fmt.Errorf("invalid path: %s", req.Path)
return nil, fmt.Errorf("invalid path: %s", req.Path)
}

switch paths[0] {
Expand All @@ -1667,15 +1665,15 @@ func (a *AbciApp) Query(ctx context.Context, req *abciTypes.RequestQuery) (*abci
}
// ID is not in the allowed list of peers, so reject the connection
a.log.Warn("Connection attempt rejected, peer is not allowed to connect", zap.String("peerID", paths[1]))
return &abciTypes.ResponseQuery{Code: 1}, nil
return nil, fmt.Errorf("node rejected connection attempt from peer %s", paths[1])
case "addr":
return &abciTypes.ResponseQuery{Code: abciTypes.CodeTypeOK}, nil
default:
return &abciTypes.ResponseQuery{Code: 1}, fmt.Errorf("invalid path: %s", req.Path)
return nil, fmt.Errorf("invalid path: %s", req.Path)
}
default:
// If the query path is not recognized, return an error.
return &abciTypes.ResponseQuery{Code: 1}, fmt.Errorf("unknown query path: %s", req.Path)
return nil, fmt.Errorf("unknown query path: %s", req.Path)
}
}

Expand Down

0 comments on commit 32dd3fc

Please sign in to comment.