Skip to content

Commit

Permalink
go/tendermint/keymanager: error Status() if keymanager doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrus committed Jan 31, 2020
1 parent b3ee039 commit b7c97ea
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
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

0 comments on commit b7c97ea

Please sign in to comment.