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

ABCI 2.0: ABCI results should be enums #91

Merged
merged 3 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
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