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

go/tendermint/keymanager: error Status() if keymanager doesn't exist #2628

Merged
merged 1 commit into from
Jan 31, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions .changelog/2628.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
go/tendermint/keymanager: error in Status() if keymanager doesn't exist

This fixes panics in the key-manager client if keymanager for the specific
runtime doesn't exist.
17 changes: 9 additions & 8 deletions go/consensus/tendermint/apps/keymanager/keymanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,22 @@ func (app *keymanagerApplication) onEpochChange(ctx *abci.Context, epoch epochti

var forceEmit bool
oldStatus, err := state.Status(rt.ID)
if err != nil {
switch err {
case nil:
case api.ErrNoSuchStatus:
// This must be a new key manager runtime.
forceEmit = true
oldStatus = &api.Status{
ID: rt.ID,
}
default:
// This is fatal, as it suggests state corruption.
ctx.Logger().Error("failed to query key manager status",
"id", rt.ID,
"err", err,
)
return errors.Wrap(err, "failed to query key manager status")
}
if oldStatus == nil {
// This must be a new key manager runtime.
forceEmit = true
oldStatus = &api.Status{
ID: rt.ID,
}
}

newStatus := app.generateStatus(ctx, rt, oldStatus, nodes)
if forceEmit || !bytes.Equal(cbor.Marshal(oldStatus), cbor.Marshal(newStatus)) {
Expand Down
2 changes: 1 addition & 1 deletion go/consensus/tendermint/apps/keymanager/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (st *ImmutableState) getStatusesRaw() ([][]byte, error) {
func (st *ImmutableState) Status(id common.Namespace) (*api.Status, error) {
_, raw := st.Snapshot.Get(statusKeyFmt.Encode(&id))
if raw == nil {
return nil, nil
return nil, api.ErrNoSuchStatus
}

var status api.Status
Expand Down
4 changes: 2 additions & 2 deletions go/keymanager/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ const (
)

var (
// ErrNoSuchKeyManager is the error returned when a key manager does not
// ErrNoSuchStatus is the error returned when a key manager status does not
// exist.
ErrNoSuchKeyManager = errors.New(ModuleName, 1, "keymanager: no such key manager")
ErrNoSuchStatus = errors.New(ModuleName, 1, "keymanager: no such status")

// TestPublicKey is the insecure hardcoded key manager public key, used
// in insecure builds when a RAK is unavailable.
Expand Down