-
Notifications
You must be signed in to change notification settings - Fork 586
/
proposal_handle.go
52 lines (42 loc) · 1.86 KB
/
proposal_handle.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package solomachine
import (
"reflect"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
"github.com/cosmos/ibc-go/v7/modules/core/exported"
)
// CheckSubstituteAndUpdateState verifies that the subject is allowed to be updated by
// a governance proposal and that the substitute client is a solo machine.
// It will update the consensus state to the substitute's consensus state and
// the sequence to the substitute's current sequence. An error is returned if
// the client has been disallowed to be updated by a governance proposal,
// the substitute is not a solo machine, or the current public key equals
// the new public key.
func (cs ClientState) CheckSubstituteAndUpdateState(
ctx sdk.Context, cdc codec.BinaryCodec, subjectClientStore,
_ sdk.KVStore, substituteClient exported.ClientState,
) error {
substituteClientState, ok := substituteClient.(*ClientState)
if !ok {
return sdkerrors.Wrapf(clienttypes.ErrInvalidClientType, "substitute client state type %T, expected %T", substituteClient, &ClientState{})
}
subjectPublicKey, err := cs.ConsensusState.GetPubKey()
if err != nil {
return sdkerrors.Wrap(err, "failed to get consensus public key")
}
substitutePublicKey, err := substituteClientState.ConsensusState.GetPubKey()
if err != nil {
return sdkerrors.Wrap(err, "failed to get substitute client public key")
}
if reflect.DeepEqual(subjectPublicKey, substitutePublicKey) {
return sdkerrors.Wrapf(clienttypes.ErrInvalidHeader, "subject and substitute have the same public key")
}
// update to substitute parameters
cs.Sequence = substituteClientState.Sequence
cs.ConsensusState = substituteClientState.ConsensusState
cs.IsFrozen = false
setClientState(subjectClientStore, cdc, &cs)
return nil
}