-
Notifications
You must be signed in to change notification settings - Fork 119
/
Copy pathmsg_server_vote_blame.go
55 lines (45 loc) · 1.45 KB
/
msg_server_vote_blame.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
package keeper
import (
"context"
sdkerrors "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
crosschainTypes "github.com/zeta-chain/zetacore/x/crosschain/types"
"github.com/zeta-chain/zetacore/x/observer/types"
)
func (k msgServer) VoteBlame(
goCtx context.Context,
msg *types.MsgVoteBlame,
) (*types.MsgVoteBlameResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
// GetChainFromChainID makes sure we are getting only supported chains , if a chain support has been turned on using gov proposal, this function returns nil
observationChain, found := k.GetSupportedChainFromChainID(ctx, msg.ChainId)
if !found {
return nil, sdkerrors.Wrapf(
crosschainTypes.ErrUnsupportedChain,
"ChainID %d, Blame vote", msg.ChainId)
}
if ok := k.IsNonTombstonedObserver(ctx, msg.Creator); !ok {
return nil, types.ErrNotObserver
}
ballot, isFinalized, isNew, err := k.VoteOnBallot(
ctx,
observationChain,
msg.Digest(),
types.ObservationType_TSSKeySign,
msg.Creator,
types.VoteType_SuccessObservation,
)
if err != nil {
return nil, sdkerrors.Wrap(err, errVoteOnBallot)
}
if isNew {
EmitEventBallotCreated(ctx, ballot, msg.BlameInfo.Index, observationChain.String())
}
if !isFinalized {
// Return nil here to add vote to ballot and commit state.
return &types.MsgVoteBlameResponse{}, nil
}
// Ballot is finalized: exactly when threshold vote is in.
k.SetBlame(ctx, msg.BlameInfo)
return &types.MsgVoteBlameResponse{}, nil
}