-
Notifications
You must be signed in to change notification settings - Fork 572
/
proposal_handle.go
63 lines (52 loc) · 2.1 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
53
54
55
56
57
58
59
60
61
62
63
package types
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/v3/modules/core/02-client/types"
"github.com/cosmos/ibc-go/v3/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,
) (exported.ClientState, error) {
if !cs.AllowUpdateAfterProposal {
return nil, sdkerrors.Wrapf(
clienttypes.ErrUpdateClientFailed,
"solo machine client is not allowed to updated with a proposal",
)
}
substituteClientState, ok := substituteClient.(*ClientState)
if !ok {
return nil, sdkerrors.Wrapf(
clienttypes.ErrInvalidClientType, "substitute client state type %T, expected %T", substituteClient, &ClientState{},
)
}
subjectPublicKey, err := cs.ConsensusState.GetPubKey()
if err != nil {
return nil, sdkerrors.Wrap(err, "failed to get consensus public key")
}
substitutePublicKey, err := substituteClientState.ConsensusState.GetPubKey()
if err != nil {
return nil, sdkerrors.Wrap(err, "failed to get substitute client public key")
}
if reflect.DeepEqual(subjectPublicKey, substitutePublicKey) {
return nil, sdkerrors.Wrapf(
clienttypes.ErrInvalidHeader, "subject and substitute have the same public key",
)
}
clientState := &cs
// update to substitute parameters
clientState.Sequence = substituteClientState.Sequence
clientState.ConsensusState = substituteClientState.ConsensusState
clientState.IsFrozen = false
return clientState, nil
}