Skip to content

Commit

Permalink
ABCI 2.0: ABCI results should be enums (#91)
Browse files Browse the repository at this point in the history
* [cherry-picked] ABCI++: Update new protos to use enum instead of bool (#8158)

This pull request updates the new ABCI++ protos to use `enum`s in place of `bool`s. `enums` may be preferred over `bool` because an `enum` can be udpated to include new statuses in the future, whereas a `bool` cannot and is fixed as just `true` or `false` over the whole lifecycle of the API.

* Detect and handle UNKNOWN in `ResponseVerifyVoteExtension`

Co-authored-by: William Banfield <4561443+williambanfield@users.noreply.github.com>
  • Loading branch information
sergio-mena and williambanfield committed Jan 12, 2023
1 parent 0b340da commit b575c25
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions abci/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ func (r ResponseVerifyVoteExtension) IsAccepted() bool {
return r.Status == ResponseVerifyVoteExtension_ACCEPT
}

// IsStatusUnknown returns true if Code is Unknown
func (r ResponseVerifyVoteExtension) IsStatusUnknown() bool {
return r.Status == ResponseVerifyVoteExtension_UNKNOWN
}

//---------------------------------------------------------------------------
// override JSON marshaling so we emit defaults (ie. disable omitempty)

Expand Down
2 changes: 2 additions & 0 deletions consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -2043,6 +2043,8 @@ func (cs *State) tryAddVote(vote *types.Vote, peerID p2p.ID) (bool, error) {
return added, err
} else if errors.Is(err, types.ErrVoteNonDeterministicSignature) {
cs.Logger.Debug("vote has non-deterministic signature", "err", err)
} else if errors.Is(err, types.ErrInvalidVoteExtension) {
cs.Logger.Debug("vote has invalid extension")
} else {
// Either
// 1) bad peer OR
Expand Down
6 changes: 4 additions & 2 deletions state/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package state
import (
"bytes"
"context"
"errors"
"fmt"
"time"

Expand Down Expand Up @@ -321,8 +320,11 @@ func (blockExec *BlockExecutor) VerifyVoteExtension(ctx context.Context, vote *t
panic(fmt.Errorf("VerifyVoteExtension call failed: %w", err))
}

if resp.IsStatusUnknown() {
panic(fmt.Sprintf("VerifyVoteExtension responded with status %s", resp.Status.String()))
}
if !resp.IsAccepted() {
return errors.New("invalid vote extension")
return types.ErrInvalidVoteExtension
}

return nil
Expand Down
1 change: 1 addition & 0 deletions types/vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var (
ErrVoteNonDeterministicSignature = errors.New("non-deterministic signature")
ErrVoteNil = errors.New("nil vote")
ErrVoteExtensionAbsent = errors.New("vote extension absent")
ErrInvalidVoteExtension = errors.New("invalid vote extension")
)

type ErrVoteConflictingVotes struct {
Expand Down

0 comments on commit b575c25

Please sign in to comment.