@@ -457,9 +457,21 @@ pub struct MultipleMinerTest {
457
457
}
458
458
459
459
impl MultipleMinerTest {
460
- pub fn new ( num_signers : usize , num_transfer_txs : u64 ) -> MultipleMinerTest {
461
- Self :: new_with_config_modifications ( num_signers, num_transfer_txs, |_| { } , |_| { } , |_| { } )
462
- }
460
+ /// Create a new test harness for running multiple miners with num_signers underlying signers and enough funds to send
461
+ /// num_txs transfer transactions.
462
+ ///
463
+ /// Will partition the signer set so that ~half are listening and using node 1 for RPC and events,
464
+ /// and the rest are using node 2
465
+ pub fn new ( num_signers : usize , num_txs : u64 ) -> MultipleMinerTest {
466
+ Self :: new_with_config_modifications ( num_signers, num_txs, |_| { } , |_| { } , |_| { } )
467
+ }
468
+
469
+ /// Create a new test harness for running multiple miners with num_signers underlying signers and enough funds to send
470
+ /// num_txs transfer transactions.
471
+ ///
472
+ /// Will also modify the signer config and the node 1 and node 2 configs with the provided
473
+ /// modifiers. Will partition the signer set so that ~half are listening and using node 1 for RPC and events,
474
+ /// and the rest are using node 2 unless otherwise specified via the signer config modifier.
463
475
pub fn new_with_config_modifications <
464
476
F : FnMut ( & mut SignerConfig ) ,
465
477
G : FnMut ( & mut NeonConfig ) ,
@@ -589,6 +601,7 @@ impl MultipleMinerTest {
589
601
}
590
602
}
591
603
604
+ /// Boot node 1 to epoch 3.0 and wait for node 2 to catch up.
592
605
pub fn boot_to_epoch_3 ( & mut self ) {
593
606
info ! (
594
607
"------------------------- Booting Both Miners to Epoch 3.0 -------------------------"
@@ -601,6 +614,7 @@ impl MultipleMinerTest {
601
614
info ! ( "------------------------- Reached Epoch 3.0 -------------------------" ) ;
602
615
}
603
616
617
+ /// Returns a tuple of the node 1 and node 2 miner private keys respectively
604
618
pub fn get_miner_private_keys ( & self ) -> ( StacksPrivateKey , StacksPrivateKey ) {
605
619
(
606
620
self . signer_test
@@ -613,6 +627,7 @@ impl MultipleMinerTest {
613
627
)
614
628
}
615
629
630
+ /// Returns a tuple of the node 1 and node 2 miner public keys respectively
616
631
pub fn get_miner_public_keys ( & self ) -> ( StacksPublicKey , StacksPublicKey ) {
617
632
let ( sk1, sk2) = self . get_miner_private_keys ( ) ;
618
633
(
@@ -621,6 +636,7 @@ impl MultipleMinerTest {
621
636
)
622
637
}
623
638
639
+ /// Returns a tuple of the node 1 and node 2 miner private key hashes respectively
624
640
pub fn get_miner_public_key_hashes ( & self ) -> ( Hash160 , Hash160 ) {
625
641
let ( pk1, pk2) = self . get_miner_public_keys ( ) ;
626
642
(
@@ -629,6 +645,7 @@ impl MultipleMinerTest {
629
645
)
630
646
}
631
647
648
+ /// Returns a tuple of the node 1 and node 2 miner node configs respectively
632
649
pub fn get_node_configs ( & self ) -> ( NeonConfig , NeonConfig ) {
633
650
(
634
651
self . signer_test . running_nodes . conf . clone ( ) ,
@@ -640,6 +657,8 @@ impl MultipleMinerTest {
640
657
& mut self . signer_test . running_nodes . btc_regtest_controller
641
658
}
642
659
660
+ /// Mine `nmb_blocks` blocks on the bitcoin regtest chain and wait for the sortition
661
+ /// database to confirm the block.
643
662
pub fn mine_bitcoin_blocks_and_confirm (
644
663
& mut self ,
645
664
sortdb : & SortitionDB ,
@@ -660,6 +679,8 @@ impl MultipleMinerTest {
660
679
} )
661
680
}
662
681
682
+ /// Mine `nmb_blocks` blocks on the bitcoin regtest chain and wait for the sortition
683
+ /// database to confirm the block and the test_observer to see the block.
663
684
pub fn mine_bitcoin_blocks_and_confirm_with_test_observer (
664
685
& mut self ,
665
686
sortdb : & SortitionDB ,
@@ -683,6 +704,8 @@ impl MultipleMinerTest {
683
704
} )
684
705
}
685
706
707
+ /// Mine a bitcoin block and wait for the sortition database to confirm the block and wait
708
+ /// for a tenure change transaction to be subseqently mined in a stacks block at the appropriate height.
686
709
pub fn mine_bitcoin_block_and_tenure_change_tx (
687
710
& mut self ,
688
711
sortdb : & SortitionDB ,
@@ -699,6 +722,7 @@ impl MultipleMinerTest {
699
722
)
700
723
}
701
724
725
+ /// Sends a transfer tx to the stacks node and returns the txid
702
726
pub fn send_transfer_tx ( & mut self ) -> String {
703
727
let http_origin = format ! (
704
728
"http://{}" ,
@@ -718,6 +742,8 @@ impl MultipleMinerTest {
718
742
submit_tx ( & http_origin, & transfer_tx)
719
743
}
720
744
745
+ /// Sends a transfer tx to the stacks node and waits for the stacks node to mine it
746
+ /// Returns the txid of the transfer tx.
721
747
pub fn send_and_mine_transfer_tx ( & mut self , timeout_secs : u64 ) -> Result < String , String > {
722
748
let stacks_height_before = self . get_peer_stacks_tip_height ( ) ;
723
749
let txid = self . send_transfer_tx ( ) ;
@@ -727,18 +753,22 @@ impl MultipleMinerTest {
727
753
Ok ( txid)
728
754
}
729
755
756
+ /// Return the Peer Info from node 1
730
757
pub fn get_peer_info ( & self ) -> PeerInfo {
731
758
self . signer_test . get_peer_info ( )
732
759
}
733
760
761
+ /// Returns the peer info's reported stacks tip height from node 1
734
762
pub fn get_peer_stacks_tip_height ( & self ) -> u64 {
735
763
self . get_peer_info ( ) . stacks_tip_height
736
764
}
737
765
766
+ /// Returns the peer stacks tip hash from node 1
738
767
pub fn get_peer_stacks_tip ( & self ) -> BlockHeaderHash {
739
768
self . get_peer_info ( ) . stacks_tip
740
769
}
741
770
771
+ /// Ensures that miner 2 submits a commit pointing to the current view reported by the stacks node as expected
742
772
pub fn submit_commit_miner_2 ( & mut self , sortdb : & SortitionDB ) {
743
773
if !self . rl2_counters . naka_skip_commit_op . get ( ) {
744
774
warn ! ( "Miner 2's commit ops were not paused. This may result in no commit being submitted." ) ;
@@ -780,6 +810,7 @@ impl MultipleMinerTest {
780
810
self . rl2_counters . naka_skip_commit_op . set ( true ) ;
781
811
}
782
812
813
+ /// Ensures that miner 1 submits a commit pointing to the current view reported by the stacks node as expected
783
814
pub fn submit_commit_miner_1 ( & mut self , sortdb : & SortitionDB ) {
784
815
if !self
785
816
. signer_test
@@ -842,6 +873,7 @@ impl MultipleMinerTest {
842
873
. set ( true ) ;
843
874
}
844
875
876
+ /// Shutdown the test harness
845
877
pub fn shutdown ( self ) {
846
878
info ! ( "------------------------- Shutting Down Multiple Miners Test -------------------------" ) ;
847
879
self . rl2_coord_channels
@@ -871,6 +903,8 @@ impl MultipleMinerTest {
871
903
}
872
904
}
873
905
906
+ /// Returns whether the last block in the test observer contains a tenure change
907
+ /// transaction with the given cause.
874
908
fn last_block_contains_tenure_change_tx ( cause : TenureChangeCause ) -> bool {
875
909
let blocks = test_observer:: get_blocks ( ) ;
876
910
let last_block = & blocks. last ( ) . unwrap ( ) ;
@@ -888,16 +922,19 @@ fn last_block_contains_tenure_change_tx(cause: TenureChangeCause) -> bool {
888
922
}
889
923
}
890
924
925
+ /// Asserts that the last block in the test observer contains a tenure change with the given cause.
891
926
fn verify_last_block_contains_tenure_change_tx ( cause : TenureChangeCause ) {
892
927
assert ! ( last_block_contains_tenure_change_tx( cause) ) ;
893
928
}
894
929
930
+ /// Verifies that the tip of the sortition database was won by the provided miner public key hash
895
931
fn verify_sortition_winner ( sortdb : & SortitionDB , miner_pkh : & Hash160 ) {
896
932
let tip = SortitionDB :: get_canonical_burn_chain_tip ( sortdb. conn ( ) ) . unwrap ( ) ;
897
933
assert ! ( tip. sortition) ;
898
934
assert_eq ! ( & tip. miner_pk_hash. unwrap( ) , miner_pkh) ;
899
935
}
900
936
937
+ /// Waits for a tenure change transaction to be observed in the test_observer at the expected height
901
938
fn wait_for_tenure_change_tx (
902
939
timeout_secs : u64 ,
903
940
cause : TenureChangeCause ,
@@ -927,6 +964,8 @@ fn wait_for_tenure_change_tx(
927
964
} )
928
965
}
929
966
967
+ /// Waits for a block proposal to be observed in the test_observer stackerdb chunks at the expected height
968
+ /// and signed by the expected miner
930
969
fn wait_for_block_proposal (
931
970
timeout_secs : u64 ,
932
971
expected_height : u64 ,
@@ -958,6 +997,8 @@ fn wait_for_block_proposal(
958
997
proposed_block. ok_or_else ( || "Failed to find block proposal" . to_string ( ) )
959
998
}
960
999
1000
+ /// Waits for a BlockPushed to be observed in the test_observer stackerdb chunks for a block
1001
+ /// with the provided signer signature hash
961
1002
fn wait_for_block_pushed (
962
1003
timeout_secs : u64 ,
963
1004
block_signer_signature_hash : Sha512Trunc256Sum ,
@@ -982,6 +1023,7 @@ fn wait_for_block_pushed(
982
1023
block. ok_or_else ( || "Failed to find block pushed" . to_string ( ) )
983
1024
}
984
1025
1026
+ /// Waits for a block with the provided expected height to be proposed and pushed by the miner with the provided public key.
985
1027
fn wait_for_block_pushed_by_miner_key (
986
1028
timeout_secs : u64 ,
987
1029
expected_height : u64 ,
@@ -991,6 +1033,8 @@ fn wait_for_block_pushed_by_miner_key(
991
1033
wait_for_block_pushed ( timeout_secs, block_proposed. header . signer_signature_hash ( ) )
992
1034
}
993
1035
1036
+ /// Waits for >30% of num_signers block rejection to be observed in the test_observer stackerdb chunks for a block
1037
+ /// with the provided signer signature hash
994
1038
fn wait_for_block_global_rejection (
995
1039
timeout_secs : u64 ,
996
1040
block_signer_signature_hash : Sha512Trunc256Sum ,
@@ -1019,6 +1063,8 @@ fn wait_for_block_global_rejection(
1019
1063
} )
1020
1064
}
1021
1065
1066
+ /// Waits for the provided number of block rejections to be observed in the test_observer stackerdb chunks for a block
1067
+ /// with the provided signer signature hash
1022
1068
fn wait_for_block_rejections (
1023
1069
timeout_secs : u64 ,
1024
1070
block_signer_signature_hash : Sha512Trunc256Sum ,
@@ -1047,6 +1093,8 @@ fn wait_for_block_rejections(
1047
1093
} )
1048
1094
}
1049
1095
1096
+ /// Waits for >70% of the provided signers to send an acceptance for a block
1097
+ /// with the provided signer signature hash
1050
1098
pub fn wait_for_block_global_acceptance_from_signers (
1051
1099
timeout_secs : u64 ,
1052
1100
signer_signature_hash : & Sha512Trunc256Sum ,
@@ -1077,6 +1125,8 @@ pub fn wait_for_block_global_acceptance_from_signers(
1077
1125
} )
1078
1126
}
1079
1127
1128
+ /// Waits for all of the provided signers to send an acceptance for a block
1129
+ /// with the provided signer signature hash
1080
1130
pub fn wait_for_block_acceptance_from_signers (
1081
1131
timeout_secs : u64 ,
1082
1132
signer_signature_hash : & Sha512Trunc256Sum ,
@@ -1106,6 +1156,8 @@ pub fn wait_for_block_acceptance_from_signers(
1106
1156
} )
1107
1157
}
1108
1158
1159
+ /// Waits for all of the provided signers to send a rejection for a block
1160
+ /// with the provided signer signature hash
1109
1161
pub fn wait_for_block_rejections_from_signers (
1110
1162
timeout_secs : u64 ,
1111
1163
expected_signers : & [ StacksPublicKey ] ,
@@ -3113,22 +3165,18 @@ fn tenure_extend_after_idle_miner() {
3113
3165
. expect ( "Failed to mine the tenure change block" ) ;
3114
3166
3115
3167
// Now, wait for a block with a tenure change due to the new block
3116
- wait_for ( 30 , || {
3117
- Ok ( last_block_contains_tenure_change_tx (
3118
- TenureChangeCause :: BlockFound ,
3119
- ) )
3120
- } )
3121
- . expect ( "Timed out waiting for a block with a tenure change" ) ;
3168
+ wait_for_tenure_change_tx ( 30 , TenureChangeCause :: BlockFound , tip_height_before + 1 )
3169
+ . expect ( "Timed out waiting for a block with a tenure change" ) ;
3122
3170
3123
3171
info ! ( "---- Waiting for a tenure extend ----" ) ;
3124
3172
3125
3173
TEST_IGNORE_SIGNERS . set ( false ) ;
3126
3174
// Now, wait for a block with a tenure extend
3127
- wait_for ( miner_idle_timeout . as_secs ( ) + 20 , || {
3128
- Ok ( last_block_contains_tenure_change_tx (
3129
- TenureChangeCause :: Extended ,
3130
- ) )
3131
- } )
3175
+ wait_for_tenure_change_tx (
3176
+ miner_idle_timeout . as_secs ( ) + 20 ,
3177
+ TenureChangeCause :: Extended ,
3178
+ tip_height_before + 1 ,
3179
+ )
3132
3180
. expect ( "Timed out waiting for a block with a tenure extend" ) ;
3133
3181
signer_test. shutdown ( ) ;
3134
3182
}
@@ -7837,8 +7885,6 @@ fn tenure_extend_after_2_bad_commits() {
7837
7885
wait_for_tenure_change_tx ( 30 , TenureChangeCause :: Extended , stacks_height_before + 1 )
7838
7886
. expect ( "Failed to mine tenure extend tx" ) ;
7839
7887
7840
- verify_last_block_contains_tenure_change_tx ( TenureChangeCause :: Extended ) ;
7841
-
7842
7888
info ! ( "------------------------- Miner 1 Mines Another Block -------------------------" ) ;
7843
7889
miners
7844
7890
. send_and_mine_transfer_tx ( 30 )
0 commit comments