@@ -14,6 +14,8 @@ import (
14
14
observerkeeper "github.com/zeta-chain/zetacore/x/observer/keeper"
15
15
)
16
16
17
+ const voteOutboundID = "Vote Outbound"
18
+
17
19
// VoteOutbound casts a vote on an outbound transaction observed on a connected chain (after
18
20
// it has been broadcasted to and finalized on a connected chain). If this is
19
21
// the first vote, a new ballot is created. When a threshold of votes is
@@ -61,45 +63,48 @@ func (k msgServer) VoteOutbound(
61
63
) (* types.MsgVoteOutboundResponse , error ) {
62
64
ctx := sdk .UnwrapSDKContext (goCtx )
63
65
64
- // Validate the message params to verify it against an existing cctx
66
+ // Validate the message params to verify it against an existing CCTX.
65
67
cctx , err := k .ValidateOutboundMessage (ctx , * msg )
66
68
if err != nil {
67
- return nil , err
69
+ return nil , cosmoserrors . Wrap ( err , voteOutboundID )
68
70
}
69
- // get ballot index
71
+
70
72
ballotIndex := msg .Digest ()
71
- // vote on outbound ballot
72
73
isFinalizingVote , isNew , ballot , observationChain , err := k .zetaObserverKeeper .VoteOnOutboundBallot (
73
74
ctx ,
74
75
ballotIndex ,
75
76
msg .OutboundChain ,
76
77
msg .Status ,
77
78
msg .Creator )
78
79
if err != nil {
79
- return nil , err
80
+ return nil , cosmoserrors . Wrap ( err , voteOutboundID )
80
81
}
81
- // if the ballot is new, set the index to the CCTX
82
+
83
+ // If the ballot is new, set the index to the CCTX.
82
84
if isNew {
83
85
observerkeeper .EmitEventBallotCreated (ctx , ballot , msg .ObservedOutboundHash , observationChain )
84
86
}
85
- // if not finalized commit state here
87
+
88
+ // If not finalized commit state here.
86
89
if ! isFinalizingVote {
87
90
return & types.MsgVoteOutboundResponse {}, nil
88
91
}
89
92
90
- // if ballot successful, the value received should be the out tx amount
93
+ // If ballot is successful, the value received should be the out tx amount.
91
94
err = cctx .AddOutbound (ctx , * msg , ballot .BallotStatus )
92
95
if err != nil {
93
- return nil , err
96
+ return nil , cosmoserrors . Wrap ( err , voteOutboundID )
94
97
}
95
- // Fund the gas stability pool with the remaining funds
98
+
99
+ // Fund the gas stability pool with the remaining funds.
96
100
k .FundStabilityPool (ctx , & cctx )
97
101
98
102
err = k .ValidateOutboundObservers (ctx , & cctx , ballot .BallotStatus , msg .ValueReceived .String ())
99
103
if err != nil {
100
104
k .SaveFailedOutbound (ctx , & cctx , err .Error (), ballotIndex )
101
105
return & types.MsgVoteOutboundResponse {}, nil
102
106
}
107
+
103
108
k .SaveSuccessfulOutbound (ctx , & cctx , ballotIndex )
104
109
return & types.MsgVoteOutboundResponse {}, nil
105
110
}
@@ -112,7 +117,7 @@ func (k Keeper) FundStabilityPool(ctx sdk.Context, cctx *types.CrossChainTx) {
112
117
// Fund the gas stability pool with the remaining funds
113
118
if err := k .FundGasStabilityPoolFromRemainingFees (ctx , * cctx .GetCurrentOutboundParam (), cctx .GetCurrentOutboundParam ().ReceiverChainId ); err != nil {
114
119
ctx .Logger ().
115
- Error (fmt . Sprintf ( "VoteOutbound : CCTX: %s Can't fund the gas stability pool with remaining fees %s" , cctx .Index , err .Error () ))
120
+ Error ("%s : CCTX: %s Can't fund the gas stability pool with remaining fees %s" , voteOutboundID , cctx .Index , err .Error ())
116
121
}
117
122
}
118
123
@@ -136,16 +141,18 @@ func (k Keeper) FundGasStabilityPoolFromRemainingFees(
136
141
remainingGas := gasLimit - gasUsed
137
142
remainingFees := math .NewUint (remainingGas ).Mul (gasPrice ).BigInt ()
138
143
139
- // We fund the stability pool with a portion of the remaining fees
144
+ // We fund the stability pool with a portion of the remaining fees.
140
145
remainingFees = percentOf (remainingFees , RemainingFeesToStabilityPoolPercent )
141
- // Fund the gas stability pool
146
+
147
+ // Fund the gas stability pool.
142
148
if err := k .fungibleKeeper .FundGasStabilityPool (ctx , chainID , remainingFees ); err != nil {
143
149
return err
144
150
}
145
151
} else {
146
- return fmt .Errorf ("VoteOutbound : The gas limit %d is less than the gas used %d" , gasLimit , gasUsed )
152
+ return fmt .Errorf ("%s : The gas limit %d is less than the gas used %d" , voteOutboundID , gasLimit , gasUsed )
147
153
}
148
154
}
155
+
149
156
return nil
150
157
}
151
158
@@ -167,7 +174,6 @@ SaveFailedOutbound saves a failed outbound transaction.It does the following thi
167
174
func (k Keeper ) SaveFailedOutbound (ctx sdk.Context , cctx * types.CrossChainTx , errMessage string , ballotIndex string ) {
168
175
cctx .SetAbort (errMessage )
169
176
ctx .Logger ().Error (errMessage )
170
-
171
177
k .SaveOutbound (ctx , cctx , ballotIndex )
172
178
}
173
179
@@ -195,48 +201,51 @@ func (k Keeper) SaveOutbound(ctx sdk.Context, cctx *types.CrossChainTx, ballotIn
195
201
outTxTssNonce := cctx .GetCurrentOutboundParam ().TssNonce
196
202
197
203
cctx .GetCurrentOutboundParam ().BallotIndex = ballotIndex
204
+
198
205
// #nosec G115 always in range
199
206
k .GetObserverKeeper ().RemoveFromPendingNonces (ctx , tssPubkey , receiverChain , int64 (outTxTssNonce ))
200
207
k .RemoveOutboundTrackerFromStore (ctx , receiverChain , outTxTssNonce )
201
208
ctx .Logger ().
202
- Info (fmt .Sprintf ("Remove tracker %s: , Block Height : %d " , getOutboundTrackerIndex (receiverChain , outTxTssNonce ), ctx .BlockHeight ()))
209
+ Info ("%s: Remove tracker %s: , Block Height : %d " , voteOutboundID , getOutboundTrackerIndex (receiverChain , outTxTssNonce ), ctx .BlockHeight ())
210
+
203
211
// This should set nonce to cctx only if a new revert is created.
204
212
k .SetCctxAndNonceToCctxAndInboundHashToCctx (ctx , * cctx )
205
213
}
206
214
207
215
func (k Keeper ) ValidateOutboundMessage (ctx sdk.Context , msg types.MsgVoteOutbound ) (types.CrossChainTx , error ) {
208
- // check if CCTX exists and if the nonce matches
216
+ // Check if CCTX exists and if the nonce matches.
209
217
cctx , found := k .GetCrossChainTx (ctx , msg .CctxHash )
210
218
if ! found {
211
- return types.CrossChainTx {}, cosmoserrors .Wrap (
219
+ return types.CrossChainTx {}, cosmoserrors .Wrapf (
212
220
sdkerrors .ErrInvalidRequest ,
213
- fmt .Sprintf ("CCTX %s does not exist" , msg .CctxHash ),
214
- )
221
+ "%s, CCTX %s does not exist" , voteOutboundID , msg .CctxHash )
215
222
}
223
+
216
224
if cctx .GetCurrentOutboundParam ().TssNonce != msg .OutboundTssNonce {
217
- return types.CrossChainTx {}, cosmoserrors .Wrap (
225
+ return types.CrossChainTx {}, cosmoserrors .Wrapf (
218
226
sdkerrors .ErrInvalidRequest ,
219
- fmt .Sprintf (
220
- "OutboundTssNonce %d does not match CCTX OutboundTssNonce %d" ,
221
- msg .OutboundTssNonce ,
222
- cctx .GetCurrentOutboundParam ().TssNonce ,
223
- ),
227
+ "%s, OutboundTssNonce %d does not match CCTX OutboundTssNonce %d" ,
228
+ voteOutboundID ,
229
+ msg .OutboundTssNonce ,
230
+ cctx .GetCurrentOutboundParam ().TssNonce ,
224
231
)
225
232
}
226
- // do not process an outbound vote if TSS is not found
233
+
234
+ // Do not process an outbound vote if TSS is not found.
227
235
_ , found = k .zetaObserverKeeper .GetTSS (ctx )
228
236
if ! found {
229
- return types.CrossChainTx {}, types .ErrCannotFindTSSKeys
237
+ return types.CrossChainTx {}, cosmoserrors . Wrap ( types .ErrCannotFindTSSKeys , voteOutboundID )
230
238
}
239
+
231
240
if cctx .GetCurrentOutboundParam ().ReceiverChainId != msg .OutboundChain {
232
- return types.CrossChainTx {}, cosmoserrors .Wrap (
241
+ return types.CrossChainTx {}, cosmoserrors .Wrapf (
233
242
sdkerrors .ErrInvalidRequest ,
234
- fmt .Sprintf (
235
- "OutboundChain %d does not match CCTX OutboundChain %d" ,
236
- msg .OutboundChain ,
237
- cctx .GetCurrentOutboundParam ().ReceiverChainId ,
238
- ),
243
+ "%s, OutboundChain %d does not match CCTX OutboundChain %d" ,
244
+ voteOutboundID ,
245
+ msg .OutboundChain ,
246
+ cctx .GetCurrentOutboundParam ().ReceiverChainId ,
239
247
)
240
248
}
249
+
241
250
return cctx , nil
242
251
}
0 commit comments