@@ -1226,4 +1226,71 @@ mod tests {
1226
1226
assert_eq ! ( result. unwrap_err( ) . to_string( ) , error_msg) ;
1227
1227
Ok ( ( ) )
1228
1228
}
1229
+
1230
+ #[ tokio:: test]
1231
+ #[ tracing_test:: traced_test]
1232
+ async fn test_bft_gc_on_commit ( ) -> Result < ( ) > {
1233
+ let rng = & mut TestRng :: default ( ) ;
1234
+
1235
+ // Initialize the round parameters.
1236
+ let max_gc_rounds = 1 ;
1237
+ let committee_round = 0 ;
1238
+ let commit_round = 2 ;
1239
+ let current_round = commit_round + 1 ;
1240
+
1241
+ // Sample the certificates.
1242
+ let ( _, certificates) = snarkvm:: ledger:: narwhal:: batch_certificate:: test_helpers:: sample_batch_certificate_with_previous_certificates (
1243
+ current_round,
1244
+ rng,
1245
+ ) ;
1246
+
1247
+ // Initialize the committee.
1248
+ let committee = snarkvm:: ledger:: committee:: test_helpers:: sample_committee_for_round_and_members (
1249
+ committee_round,
1250
+ vec ! [
1251
+ certificates[ 0 ] . author( ) ,
1252
+ certificates[ 1 ] . author( ) ,
1253
+ certificates[ 2 ] . author( ) ,
1254
+ certificates[ 3 ] . author( ) ,
1255
+ ] ,
1256
+ rng,
1257
+ ) ;
1258
+
1259
+ // Initialize the ledger.
1260
+ let ledger = Arc :: new ( MockLedgerService :: new ( committee. clone ( ) ) ) ;
1261
+
1262
+ // Initialize the storage.
1263
+ let transmissions = Arc :: new ( BFTMemoryService :: new ( ) ) ;
1264
+ let storage = Storage :: new ( ledger. clone ( ) , transmissions, max_gc_rounds) ;
1265
+ // Insert the certificates into the storage.
1266
+ for certificate in certificates. iter ( ) {
1267
+ storage. testing_only_insert_certificate_testing_only ( certificate. clone ( ) ) ;
1268
+ }
1269
+
1270
+ // Get the leader certificate.
1271
+ let leader = committee. get_leader ( commit_round) . unwrap ( ) ;
1272
+ let leader_certificate = storage. get_certificate_for_round_with_author ( commit_round, leader) . unwrap ( ) ;
1273
+
1274
+ // Initialize the BFT.
1275
+ let account = Account :: new ( rng) ?;
1276
+ let bft = BFT :: new ( account, storage. clone ( ) , ledger, None , & [ ] , None ) ?;
1277
+ // Insert a mock DAG in the BFT.
1278
+ * bft. dag . write ( ) = crate :: helpers:: dag:: test_helpers:: mock_dag_with_modified_last_committed_round ( commit_round) ;
1279
+
1280
+ // Ensure that the `gc_round` has not been updated yet.
1281
+ assert_eq ! ( bft. storage( ) . gc_round( ) , committee_round. saturating_sub( max_gc_rounds) ) ;
1282
+
1283
+ // Insert the certificates into the BFT.
1284
+ for certificate in certificates {
1285
+ assert ! ( bft. update_dag:: <false >( certificate) . await . is_ok( ) ) ;
1286
+ }
1287
+
1288
+ // Commit the leader certificate.
1289
+ bft. commit_leader_certificate :: < false , false > ( leader_certificate) . await . unwrap ( ) ;
1290
+
1291
+ // Ensure that the `gc_round` has been updated.
1292
+ assert_eq ! ( bft. storage( ) . gc_round( ) , commit_round - max_gc_rounds) ;
1293
+
1294
+ Ok ( ( ) )
1295
+ }
1229
1296
}
0 commit comments