@@ -308,7 +308,7 @@ TEST (active_transactions, inactive_votes_cache_existing_vote)
308
308
// Insert vote
309
309
auto vote1 (std::make_shared<nano::vote> (key.pub , key.prv , 1 , std::vector<nano::block_hash> (1 , send->hash ())));
310
310
node.vote_processor .vote (vote1, std::make_shared<nano::transport::channel_loopback> (node));
311
- ASSERT_TIMELY (5s, election->votes ().size () == 2 )
311
+ ASSERT_TIMELY (5s, election->votes ().size () == 2 );
312
312
ASSERT_EQ (1 , node.stats .count (nano::stat::type::election, nano::stat::detail::vote_new));
313
313
auto last_vote1 (election->votes ()[key.pub ]);
314
314
ASSERT_EQ (send->hash (), last_vote1.hash );
@@ -388,49 +388,28 @@ TEST (active_transactions, inactive_votes_cache_election_start)
388
388
node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled;
389
389
auto & node = *system .add_node (node_config);
390
390
nano::block_hash latest (node.latest (nano::dev_genesis_key.pub ));
391
- nano::keypair key1, key2, key3, key4, key5 ;
391
+ nano::keypair key1, key2;
392
392
nano::send_block_builder send_block_builder;
393
393
nano::state_block_builder state_block_builder;
394
394
auto send1 = send_block_builder.make_block ()
395
395
.previous (latest)
396
396
.destination (key1.pub )
397
- .balance (nano::genesis_amount - 2000 * nano::Gxrb_ratio)
397
+ .balance (nano::genesis_amount - 5000 * nano::Gxrb_ratio)
398
398
.sign (nano::dev_genesis_key.prv , nano::dev_genesis_key.pub )
399
399
.work (*system .work .generate (latest))
400
400
.build_shared ();
401
401
auto send2 = send_block_builder.make_block ()
402
402
.previous (send1->hash ())
403
403
.destination (key2.pub )
404
- .balance (nano::genesis_amount - 4000 * nano::Gxrb_ratio)
405
- .sign (nano::dev_genesis_key.prv , nano::dev_genesis_key.pub )
406
- .work (*system .work .generate (send1->hash ()))
407
- .build_shared ();
408
- auto send3 = send_block_builder.make_block ()
409
- .previous (send2->hash ())
410
- .destination (key3.pub )
411
- .balance (nano::genesis_amount - 6000 * nano::Gxrb_ratio)
412
- .sign (nano::dev_genesis_key.prv , nano::dev_genesis_key.pub )
413
- .work (*system .work .generate (send2->hash ()))
414
- .build_shared ();
415
- auto send4 = send_block_builder.make_block ()
416
- .previous (send3->hash ())
417
- .destination (key4.pub )
418
- .balance (nano::genesis_amount - 8000 * nano::Gxrb_ratio)
419
- .sign (nano::dev_genesis_key.prv , nano::dev_genesis_key.pub )
420
- .work (*system .work .generate (send3->hash ()))
421
- .build_shared ();
422
- auto send5 = send_block_builder.make_block ()
423
- .previous (send4->hash ())
424
- .destination (key5.pub )
425
404
.balance (nano::genesis_amount - 10000 * nano::Gxrb_ratio)
426
405
.sign (nano::dev_genesis_key.prv , nano::dev_genesis_key.pub )
427
- .work (*system .work .generate (send4 ->hash ()))
406
+ .work (*system .work .generate (send1 ->hash ()))
428
407
.build_shared ();
429
408
auto open1 = state_block_builder.make_block ()
430
409
.account (key1.pub )
431
410
.previous (0 )
432
411
.representative (key1.pub )
433
- .balance (2000 * nano::Gxrb_ratio)
412
+ .balance (5000 * nano::Gxrb_ratio)
434
413
.link (send1->hash ())
435
414
.sign (key1.prv , key1.pub )
436
415
.work (*system .work .generate (key1.pub ))
@@ -439,107 +418,69 @@ TEST (active_transactions, inactive_votes_cache_election_start)
439
418
.account (key2.pub )
440
419
.previous (0 )
441
420
.representative (key2.pub )
442
- .balance (2000 * nano::Gxrb_ratio)
421
+ .balance (5000 * nano::Gxrb_ratio)
443
422
.link (send2->hash ())
444
423
.sign (key2.prv , key2.pub )
445
424
.work (*system .work .generate (key2.pub ))
446
425
.build_shared ();
447
- auto open3 = state_block_builder.make_block ()
448
- .account (key3.pub )
449
- .previous (0 )
450
- .representative (key3.pub )
451
- .balance (2000 * nano::Gxrb_ratio)
452
- .link (send3->hash ())
453
- .sign (key3.prv , key3.pub )
454
- .work (*system .work .generate (key3.pub ))
455
- .build_shared ();
456
- auto open4 = state_block_builder.make_block ()
457
- .account (key4.pub )
458
- .previous (0 )
459
- .representative (key4.pub )
460
- .balance (2000 * nano::Gxrb_ratio)
461
- .link (send4->hash ())
462
- .sign (key4.prv , key4.pub )
463
- .work (*system .work .generate (key4.pub ))
464
- .build_shared ();
465
- auto open5 = state_block_builder.make_block ()
466
- .account (key5.pub )
467
- .previous (0 )
468
- .representative (key5.pub )
469
- .balance (2000 * nano::Gxrb_ratio)
470
- .link (send5->hash ())
471
- .sign (key5.prv , key5.pub )
472
- .work (*system .work .generate (key5.pub ))
473
- .build_shared ();
474
426
node.block_processor .add (send1);
475
427
node.block_processor .add (send2);
476
- node.block_processor .add (send3);
477
- node.block_processor .add (send4);
478
- node.block_processor .add (send5);
479
428
node.block_processor .add (open1);
480
429
node.block_processor .add (open2);
481
- node.block_processor .add (open3);
482
- node.block_processor .add (open4);
483
- node.block_processor .add (open5);
484
430
node.block_processor .flush ();
485
- ASSERT_TIMELY (5s, 11 == node.ledger .cache .block_count );
431
+ ASSERT_TIMELY (5s, 5 == node.ledger .cache .block_count );
486
432
ASSERT_TRUE (node.active .empty ());
487
433
ASSERT_EQ (1 , node.ledger .cache .cemented_count );
488
434
// These blocks will be processed later
489
- auto send6 = send_block_builder.make_block ()
490
- .previous (send5 ->hash ())
435
+ auto send3 = send_block_builder.make_block ()
436
+ .previous (send2 ->hash ())
491
437
.destination (nano::keypair ().pub )
492
- .balance (send5 ->balance ().number () - 1 )
438
+ .balance (send2 ->balance ().number () - 1 )
493
439
.sign (nano::dev_genesis_key.prv , nano::dev_genesis_key.pub )
494
- .work (*system .work .generate (send5 ->hash ()))
440
+ .work (*system .work .generate (send2 ->hash ()))
495
441
.build_shared ();
496
- auto send7 = send_block_builder.make_block ()
497
- .previous (send6 ->hash ())
442
+ auto send4 = send_block_builder.make_block ()
443
+ .previous (send3 ->hash ())
498
444
.destination (nano::keypair ().pub )
499
- .balance (send6 ->balance ().number () - 1 )
445
+ .balance (send3 ->balance ().number () - 1 )
500
446
.sign (nano::dev_genesis_key.prv , nano::dev_genesis_key.pub )
501
- .work (*system .work .generate (send6 ->hash ()))
447
+ .work (*system .work .generate (send3 ->hash ()))
502
448
.build_shared ();
503
449
// Inactive votes
504
- std::vector<nano::block_hash> hashes{ open1->hash (), open2->hash (), open3-> hash (), open4-> hash (), open5-> hash (), send7 ->hash () };
450
+ std::vector<nano::block_hash> hashes{ open1->hash (), open2->hash (), send4 ->hash () };
505
451
auto vote1 (std::make_shared<nano::vote> (key1.pub , key1.prv , 0 , hashes));
506
452
node.vote_processor .vote (vote1, std::make_shared<nano::transport::channel_loopback> (node));
507
- auto vote2 (std::make_shared<nano::vote> (key2.pub , key2.prv , 0 , hashes));
508
- node.vote_processor .vote (vote2, std::make_shared<nano::transport::channel_loopback> (node));
509
- auto vote3 (std::make_shared<nano::vote> (key3.pub , key3.prv , 0 , hashes));
510
- node.vote_processor .vote (vote3, std::make_shared<nano::transport::channel_loopback> (node));
511
- auto vote4 (std::make_shared<nano::vote> (key4.pub , key4.prv , 0 , hashes));
512
- node.vote_processor .vote (vote4, std::make_shared<nano::transport::channel_loopback> (node));
513
- ASSERT_TIMELY (5s, node.active .inactive_votes_cache_size () == 6 );
453
+ ASSERT_TIMELY (5s, node.active .inactive_votes_cache_size () == 3 );
514
454
ASSERT_TRUE (node.active .empty ());
515
455
ASSERT_EQ (1 , node.ledger .cache .cemented_count );
516
- // 5 votes are required to start election
517
- auto vote5 (std::make_shared<nano::vote> (key5.pub , key5.prv , 0 , hashes));
518
- node.vote_processor .vote (vote5, std::make_shared<nano::transport::channel_loopback> (node));
519
- ASSERT_TIMELY (5s, 5 == node.active .size ());
456
+ // 2 votes are required to start election (dev network)
457
+ auto vote2 (std::make_shared<nano::vote> (key2.pub , key2.prv , 0 , hashes));
458
+ node.vote_processor .vote (vote2, std::make_shared<nano::transport::channel_loopback> (node));
459
+ // Only open1 & open2 blocks elections should start (send4 is missing previous block in ledger)
460
+ ASSERT_TIMELY (5s, 2 == node.active .size ());
520
461
// Confirm elections with weight quorum
521
462
auto vote0 (std::make_shared<nano::vote> (nano::dev_genesis_key.pub , nano::dev_genesis_key.prv , std::numeric_limits<uint64_t >::max (), hashes)); // Final vote for confirmation
522
463
node.vote_processor .vote (vote0, std::make_shared<nano::transport::channel_loopback> (node));
523
464
ASSERT_TIMELY (5s, node.active .empty ());
524
- ASSERT_TIMELY (5s, 11 == node.ledger .cache .cemented_count );
465
+ ASSERT_TIMELY (5s, 5 == node.ledger .cache .cemented_count );
525
466
// A late block arrival also checks the inactive votes cache
526
467
ASSERT_TRUE (node.active .empty ());
527
- auto send7_cache (node.active .find_inactive_votes_cache (send7 ->hash ()));
528
- ASSERT_EQ (6 , send7_cache .voters .size ());
529
- ASSERT_TRUE (send7_cache .status .bootstrap_started );
530
- ASSERT_TRUE (send7_cache .status .confirmed );
531
- ASSERT_TRUE (send7_cache .status .election_started ); // already marked even though the block does not exist
532
- node.process_active (send6 );
468
+ auto send4_cache (node.active .find_inactive_votes_cache (send4 ->hash ()));
469
+ ASSERT_EQ (3 , send4_cache .voters .size ());
470
+ ASSERT_TRUE (send4_cache .status .bootstrap_started );
471
+ ASSERT_TRUE (send4_cache .status .confirmed );
472
+ ASSERT_TRUE (send4_cache .status .election_started ); // already marked even though the block does not exist
473
+ node.process_active (send3 );
533
474
node.block_processor .flush ();
534
475
// An election is started for send6 but does not confirm
535
476
ASSERT_TIMELY (5s, 1 == node.active .size ());
536
477
node.vote_processor .flush ();
537
- ASSERT_FALSE (node.block_confirmed_or_being_confirmed (node.store .tx_begin_read (), send6 ->hash ()));
478
+ ASSERT_FALSE (node.block_confirmed_or_being_confirmed (node.store .tx_begin_read (), send3 ->hash ()));
538
479
// send7 cannot be voted on but an election should be started from inactive votes
539
- ASSERT_FALSE (node.ledger .dependents_confirmed (node.store .tx_begin_read (), *send7 ));
540
- node.process_active (send7 );
480
+ ASSERT_FALSE (node.ledger .dependents_confirmed (node.store .tx_begin_read (), *send4 ));
481
+ node.process_active (send4 );
541
482
node.block_processor .flush ();
542
- ASSERT_TIMELY (5s, 13 == node.ledger .cache .cemented_count );
483
+ ASSERT_TIMELY (5s, 7 == node.ledger .cache .cemented_count );
543
484
}
544
485
545
486
namespace nano
@@ -1046,6 +987,7 @@ TEST (active_transactions, restart_dropped)
1046
987
ASSERT_EQ (0 , node.active .size ());
1047
988
node.process_active (send);
1048
989
node.block_processor .flush ();
990
+ node.scheduler .flush ();
1049
991
ASSERT_EQ (1 , node.active .size ());
1050
992
ASSERT_EQ (1 , node.stats .count (nano::stat::type::election, nano::stat::detail::election_restart));
1051
993
auto ledger_block (node.store .block_get (node.store .tx_begin_read (), send->hash ()));
@@ -1058,6 +1000,7 @@ TEST (active_transactions, restart_dropped)
1058
1000
// Try to restart election with the same difficulty
1059
1001
node.process_active (send);
1060
1002
node.block_processor .flush ();
1003
+ node.scheduler .flush ();
1061
1004
ASSERT_EQ (0 , node.active .size ());
1062
1005
ASSERT_EQ (1 , node.stats .count (nano::stat::type::election, nano::stat::detail::election_restart));
1063
1006
// Generate even higher difficulty work
@@ -1068,6 +1011,7 @@ TEST (active_transactions, restart_dropped)
1068
1011
ASSERT_EQ (0 , node.active .size ());
1069
1012
node.process_active (send);
1070
1013
node.block_processor .flush ();
1014
+ node.scheduler .flush ();
1071
1015
ASSERT_EQ (1 , node.active .size ());
1072
1016
ASSERT_EQ (1 , node.ledger .cache .cemented_count );
1073
1017
ASSERT_EQ (2 , node.stats .count (nano::stat::type::election, nano::stat::detail::election_restart));
0 commit comments