@@ -131,20 +131,25 @@ impl CardanoTransactionsSigningConfig {
131
131
///
132
132
/// The formula is as follows:
133
133
///
134
- /// `block_number = ⌊(tip.block_number - security_parameter) / step⌋ × step`
134
+ /// `block_number = ⌊(tip.block_number - security_parameter) / step⌋ × step - 1 `
135
135
///
136
136
/// where `⌊x⌋` is the floor function which rounds to the greatest integer less than or equal to `x`.
137
137
///
138
- /// *Note: The step is adjusted to be a multiple of the block range length in order
138
+ /// *Notes:*
139
+ /// * *The step is adjusted to be a multiple of the block range length in order
139
140
/// to guarantee that the block number signed in a certificate is effectively signed.*
141
+ /// * *1 is subtracted to the result because block range end is exclusive (ie: a BlockRange over
142
+ /// `30..45` finish at 44 included, 45 is included in the next block range).*
140
143
pub fn compute_block_number_to_be_signed ( & self , block_number : BlockNumber ) -> BlockNumber {
141
144
// TODO: See if we can remove this adjustment by including a "partial" block range in
142
145
// the signed data.
143
146
let adjusted_step = BlockRange :: from_block_number ( self . step ) . start ;
144
147
// We can't have a step lower than the block range length.
145
148
let adjusted_step = std:: cmp:: max ( adjusted_step, BlockRange :: LENGTH ) ;
146
149
147
- ( block_number. saturating_sub ( self . security_parameter ) ) / adjusted_step * adjusted_step
150
+ let block_number_to_be_signed =
151
+ ( block_number. saturating_sub ( self . security_parameter ) ) / adjusted_step * adjusted_step;
152
+ block_number_to_be_signed. saturating_sub ( 1 )
148
153
}
149
154
}
150
155
@@ -199,11 +204,11 @@ mod tests {
199
204
)
200
205
) ;
201
206
202
- // The block number to be signed is 0 because the step is 15, the block number is 20, and
207
+ // The block number to be signed is 14 because the step is 15, the block number is 20, and
203
208
// the security parameter is 0.
204
209
// This is further tested in the "computing_block_number_to_be_signed" tests below.
205
210
assert_eq ! (
206
- SignedEntityType :: CardanoTransactions ( Epoch ( 1 ) , 15 ) ,
211
+ SignedEntityType :: CardanoTransactions ( Epoch ( 1 ) , 14 ) ,
207
212
config. time_point_to_signed_entity(
208
213
SignedEntityTypeDiscriminants :: CardanoTransactions ,
209
214
& time_point
@@ -220,7 +225,7 @@ mod tests {
220
225
step: 15 ,
221
226
}
222
227
. compute_block_number_to_be_signed( 105 ) ,
223
- 105
228
+ 104
224
229
) ;
225
230
226
231
assert_eq ! (
@@ -229,7 +234,7 @@ mod tests {
229
234
step: 15 ,
230
235
}
231
236
. compute_block_number_to_be_signed( 100 ) ,
232
- 90
237
+ 89
233
238
) ;
234
239
235
240
assert_eq ! (
@@ -238,7 +243,7 @@ mod tests {
238
243
step: 15 ,
239
244
}
240
245
. compute_block_number_to_be_signed( 100 ) ,
241
- 15
246
+ 14
242
247
) ;
243
248
244
249
assert_eq ! (
@@ -271,7 +276,7 @@ mod tests {
271
276
step: BlockRange :: LENGTH * 2 - 1 ,
272
277
}
273
278
. compute_block_number_to_be_signed( BlockRange :: LENGTH * 5 + 1 ) ,
274
- BlockRange :: LENGTH * 5
279
+ BlockRange :: LENGTH * 5 - 1
275
280
) ;
276
281
277
282
assert_eq ! (
@@ -280,7 +285,7 @@ mod tests {
280
285
step: BlockRange :: LENGTH * 2 + 1 ,
281
286
}
282
287
. compute_block_number_to_be_signed( BlockRange :: LENGTH * 5 + 1 ) ,
283
- BlockRange :: LENGTH * 4
288
+ BlockRange :: LENGTH * 4 - 1
284
289
) ;
285
290
286
291
// Adjusted step is always at least BLOCK_RANGE_LENGTH.
@@ -290,7 +295,7 @@ mod tests {
290
295
step: BlockRange :: LENGTH - 1 ,
291
296
}
292
297
. compute_block_number_to_be_signed( BlockRange :: LENGTH * 10 - 1 ) ,
293
- BlockRange :: LENGTH * 9
298
+ BlockRange :: LENGTH * 9 - 1
294
299
) ;
295
300
296
301
assert_eq ! (
@@ -424,7 +429,7 @@ mod tests {
424
429
SignedEntityType :: MithrilStakeDistribution ( beacon. epoch) ,
425
430
SignedEntityType :: CardanoStakeDistribution ( beacon. epoch) ,
426
431
SignedEntityType :: CardanoImmutableFilesFull ( beacon. clone( ) ) ,
427
- SignedEntityType :: CardanoTransactions ( beacon. epoch, chain_point. block_number) ,
432
+ SignedEntityType :: CardanoTransactions ( beacon. epoch, chain_point. block_number - 1 ) ,
428
433
] ,
429
434
signed_entity_types
430
435
) ;
0 commit comments