@@ -123,13 +123,13 @@ pub fn handle_finality_signature(
123
123
height : u64 ,
124
124
pub_rand : & [ u8 ] ,
125
125
proof : & Proof ,
126
- block_hash : & [ u8 ] ,
126
+ block_app_hash : & [ u8 ] ,
127
127
signature : & [ u8 ] ,
128
128
) -> Result < Response < BabylonMsg > , ContractError > {
129
129
// Ensure the finality provider exists
130
130
check_fp_exist ( deps. as_ref ( ) , fp_btc_pk_hex) ?;
131
131
132
- // TODO: Ensure the finality provider is not slashed at this time point
132
+ // TODO: Ensure the finality provider is not slashed at this time point (#82)
133
133
// NOTE: It's possible that the finality provider equivocates for height h, and the signature is
134
134
// processed at height h' > h. In this case:
135
135
// - We should reject any new signature from this finality provider, since it's known to be adversarial.
@@ -177,12 +177,12 @@ pub fn handle_finality_signature(
177
177
pub_rand,
178
178
proof,
179
179
& pr_commit,
180
- block_hash ,
180
+ block_app_hash ,
181
181
signature,
182
182
) ?;
183
183
184
184
// The public randomness value is good, save it.
185
- // TODO?: Don't save public randomness values, to save storage space
185
+ // TODO?: Don't save public randomness values, to save storage space (#122)
186
186
PUB_RAND_VALUES . save ( deps. storage , ( fp_btc_pk_hex, height) , & pub_rand. to_vec ( ) ) ?;
187
187
188
188
// Build the response
@@ -192,9 +192,10 @@ pub fn handle_finality_signature(
192
192
// extracting its secret key, and emit an event
193
193
let canonical_sig: Option < Vec < u8 > > =
194
194
SIGNATURES . may_load ( deps. storage , ( height, fp_btc_pk_hex) ) ?;
195
- let canonical_block_hash : Option < Vec < u8 > > =
195
+ let canonical_block_app_hash : Option < Vec < u8 > > =
196
196
BLOCK_HASHES . may_load ( deps. storage , ( height, fp_btc_pk_hex) ) ?;
197
- if let ( Some ( canonical_sig) , Some ( canonical_block_hash) ) = ( canonical_sig, canonical_block_hash)
197
+ if let ( Some ( canonical_sig) , Some ( canonical_block_app_hash) ) =
198
+ ( canonical_sig, canonical_block_app_hash)
198
199
{
199
200
// the finality provider has voted for a fork before!
200
201
// If this evidence is at the same height as this signature, slash this finality provider
@@ -204,10 +205,9 @@ pub fn handle_finality_signature(
204
205
fp_btc_pk : hex:: decode ( fp_btc_pk_hex) ?,
205
206
block_height : height,
206
207
pub_rand : pub_rand. to_vec ( ) ,
207
- // TODO: we use block hash in place of app hash for now, to define new interface if needed
208
- canonical_app_hash : canonical_block_hash,
208
+ canonical_app_hash : canonical_block_app_hash,
209
209
canonical_finality_sig : canonical_sig,
210
- fork_app_hash : block_hash . to_vec ( ) ,
210
+ fork_app_hash : block_app_hash . to_vec ( ) ,
211
211
fork_finality_sig : signature. to_vec ( ) ,
212
212
} ;
213
213
@@ -223,23 +223,27 @@ pub fn handle_finality_signature(
223
223
224
224
// This signature is good, save the vote to the store
225
225
SIGNATURES . save ( deps. storage , ( height, fp_btc_pk_hex) , & signature. to_vec ( ) ) ?;
226
- BLOCK_HASHES . save ( deps. storage , ( height, fp_btc_pk_hex) , & block_hash. to_vec ( ) ) ?;
226
+ BLOCK_HASHES . save (
227
+ deps. storage ,
228
+ ( height, fp_btc_pk_hex) ,
229
+ & block_app_hash. to_vec ( ) ,
230
+ ) ?;
227
231
228
- // Check if the key (height, block_hash ) exists
232
+ // Check if the key (height, block_app_hash ) exists
229
233
let mut block_votes_fp_set = BLOCK_VOTES
230
- . may_load ( deps. storage , ( height, block_hash ) ) ?
234
+ . may_load ( deps. storage , ( height, block_app_hash ) ) ?
231
235
. unwrap_or_else ( HashSet :: new) ;
232
236
233
237
// Add the fp_btc_pk_hex to the set
234
238
block_votes_fp_set. insert ( fp_btc_pk_hex. to_string ( ) ) ;
235
239
236
240
// Save the updated set back to storage
237
- BLOCK_VOTES . save ( deps. storage , ( height, block_hash ) , & block_votes_fp_set) ?;
241
+ BLOCK_VOTES . save ( deps. storage , ( height, block_app_hash ) , & block_votes_fp_set) ?;
238
242
239
243
let event = Event :: new ( "submit_finality_signature" )
240
244
. add_attribute ( "fp_pubkey_hex" , fp_btc_pk_hex)
241
245
. add_attribute ( "block_height" , height. to_string ( ) )
242
- . add_attribute ( "block_hash " , hex:: encode ( block_hash ) ) ;
246
+ . add_attribute ( "block_app_hash " , hex:: encode ( block_app_hash ) ) ;
243
247
244
248
res = res. add_event ( event) ;
245
249
@@ -289,10 +293,10 @@ pub(crate) fn verify_finality_signature(
289
293
290
294
/// `msg_to_sign` returns the message for an EOTS signature.
291
295
///
292
- /// The EOTS signature on a block will be (block_height || block_hash )
293
- fn msg_to_sign ( height : u64 , block_hash : & [ u8 ] ) -> Vec < u8 > {
296
+ /// The EOTS signature on a block will be (block_height || block_app_hash )
297
+ fn msg_to_sign ( height : u64 , block_app_hash : & [ u8 ] ) -> Vec < u8 > {
294
298
let mut msg: Vec < u8 > = height. to_be_bytes ( ) . to_vec ( ) ;
295
- msg. extend_from_slice ( block_hash ) ;
299
+ msg. extend_from_slice ( block_app_hash ) ;
296
300
msg
297
301
}
298
302
0 commit comments