@@ -7947,166 +7947,49 @@ fn block_validation_check_rejection_timeout_heuristic() {
7947
7947
7948
7948
// note we just use mined nakamoto_blocks as the second block is not going to be confirmed
7949
7949
7950
- info ! ( "------------------------- Check Rejections-based timeout with 1 rejection -------------------------" ) ;
7950
+ let mut test_rejections = |signer_split_index : usize , expected_timeout : u64 | {
7951
+ let blocks_before = test_observer:: get_mined_nakamoto_blocks ( ) . len ( ) ;
7952
+ let ( ignore_signers, reject_signers) = all_signers. split_at ( signer_split_index) ;
7951
7953
7952
- let blocks_before = test_observer :: get_mined_nakamoto_blocks ( ) . len ( ) ;
7954
+ info ! ( "------------------------- Check Rejections-based timeout with {} rejections -------------------------" , reject_signers . len( ) ) ;
7953
7955
7954
- TEST_REJECT_ALL_BLOCK_PROPOSAL . set ( vec ! [ all_signers [ 19 ] ] ) ;
7955
- TEST_IGNORE_ALL_BLOCK_PROPOSALS . set ( all_signers [ 0 .. 19 ] . to_vec ( ) ) ;
7956
+ TEST_REJECT_ALL_BLOCK_PROPOSAL . set ( reject_signers . to_vec ( ) ) ;
7957
+ TEST_IGNORE_ALL_BLOCK_PROPOSALS . set ( ignore_signers . to_vec ( ) ) ;
7956
7958
7957
- next_block_and (
7958
- & mut signer_test. running_nodes . btc_regtest_controller ,
7959
- 30 ,
7960
- || Ok ( test_observer:: get_mined_nakamoto_blocks ( ) . len ( ) > blocks_before) ,
7961
- )
7962
- . unwrap ( ) ;
7963
-
7964
- signer_test
7965
- . wait_for_block_rejections ( timeout. as_secs ( ) , & [ all_signers[ 19 ] ] )
7966
- . unwrap ( ) ;
7967
-
7968
- wait_for ( 60 , || {
7969
- Ok ( signer_test
7970
- . running_nodes
7971
- . counters
7972
- . naka_miner_current_rejections
7973
- . get ( )
7974
- >= 1 )
7975
- } )
7976
- . unwrap ( ) ;
7977
- assert_eq ! (
7978
- signer_test
7979
- . running_nodes
7980
- . counters
7981
- . naka_miner_current_rejections_timeout_secs
7982
- . get( ) ,
7983
- 123
7984
- ) ;
7985
-
7986
- info ! ( "------------------------- Check Rejections-based timeout with 2 rejections -------------------------" ) ;
7987
-
7988
- let blocks_before = test_observer:: get_mined_nakamoto_blocks ( ) . len ( ) ;
7989
-
7990
- TEST_REJECT_ALL_BLOCK_PROPOSAL . set ( vec ! [ all_signers[ 18 ] , all_signers[ 19 ] ] ) ;
7991
- TEST_IGNORE_ALL_BLOCK_PROPOSALS . set ( all_signers[ 0 ..18 ] . to_vec ( ) ) ;
7992
-
7993
- next_block_and (
7994
- & mut signer_test. running_nodes . btc_regtest_controller ,
7995
- 30 ,
7996
- || Ok ( test_observer:: get_mined_nakamoto_blocks ( ) . len ( ) > blocks_before) ,
7997
- )
7998
- . unwrap ( ) ;
7999
-
8000
- signer_test
8001
- . wait_for_block_rejections ( timeout. as_secs ( ) , & [ all_signers[ 18 ] , all_signers[ 19 ] ] )
8002
- . unwrap ( ) ;
8003
-
8004
- wait_for ( 60 , || {
8005
- Ok ( signer_test
8006
- . running_nodes
8007
- . counters
8008
- . naka_miner_current_rejections
8009
- . get ( )
8010
- >= 2 )
8011
- } )
8012
- . unwrap ( ) ;
8013
- assert_eq ! (
8014
- signer_test
8015
- . running_nodes
8016
- . counters
8017
- . naka_miner_current_rejections_timeout_secs
8018
- . get( ) ,
8019
- 20
8020
- ) ;
8021
-
8022
- info ! ( "------------------------- Check Rejections-based timeout with 3 rejections -------------------------" ) ;
8023
-
8024
- let blocks_before = test_observer:: get_mined_nakamoto_blocks ( ) . len ( ) ;
8025
-
8026
- TEST_REJECT_ALL_BLOCK_PROPOSAL . set ( vec ! [ all_signers[ 17 ] , all_signers[ 18 ] , all_signers[ 19 ] ] ) ;
8027
- TEST_IGNORE_ALL_BLOCK_PROPOSALS . set ( all_signers[ 0 ..17 ] . to_vec ( ) ) ;
8028
-
8029
- next_block_and (
8030
- & mut signer_test. running_nodes . btc_regtest_controller ,
8031
- 30 ,
8032
- || Ok ( test_observer:: get_mined_nakamoto_blocks ( ) . len ( ) > blocks_before) ,
8033
- )
8034
- . unwrap ( ) ;
8035
-
8036
- signer_test
8037
- . wait_for_block_rejections (
8038
- timeout. as_secs ( ) ,
8039
- & [ all_signers[ 17 ] , all_signers[ 18 ] , all_signers[ 19 ] ] ,
7959
+ next_block_and (
7960
+ & mut signer_test. running_nodes . btc_regtest_controller ,
7961
+ 30 ,
7962
+ || Ok ( test_observer:: get_mined_nakamoto_blocks ( ) . len ( ) > blocks_before) ,
8040
7963
)
8041
7964
. unwrap ( ) ;
8042
7965
8043
- wait_for ( 60 , || {
8044
- Ok ( signer_test
8045
- . running_nodes
8046
- . counters
8047
- . naka_miner_current_rejections
8048
- . get ( )
8049
- >= 3 )
8050
- } )
8051
- . unwrap ( ) ;
8052
-
8053
- assert_eq ! (
8054
7966
signer_test
8055
- . running_nodes
8056
- . counters
8057
- . naka_miner_current_rejections_timeout_secs
8058
- . get( ) ,
8059
- 10
8060
- ) ;
8061
-
8062
- info ! ( "------------------------- Check Rejections-based timeout with 4 rejections -------------------------" ) ;
8063
-
8064
- let blocks_before = test_observer:: get_mined_nakamoto_blocks ( ) . len ( ) ;
8065
-
8066
- TEST_REJECT_ALL_BLOCK_PROPOSAL . set ( vec ! [
8067
- all_signers[ 16 ] ,
8068
- all_signers[ 17 ] ,
8069
- all_signers[ 18 ] ,
8070
- all_signers[ 19 ] ,
8071
- ] ) ;
8072
- TEST_IGNORE_ALL_BLOCK_PROPOSALS . set ( all_signers[ 0 ..16 ] . to_vec ( ) ) ;
8073
-
8074
- next_block_and (
8075
- & mut signer_test. running_nodes . btc_regtest_controller ,
8076
- 30 ,
8077
- || Ok ( test_observer:: get_mined_nakamoto_blocks ( ) . len ( ) > blocks_before) ,
8078
- )
8079
- . unwrap ( ) ;
7967
+ . wait_for_block_rejections ( timeout. as_secs ( ) , & reject_signers)
7968
+ . unwrap ( ) ;
8080
7969
8081
- signer_test
8082
- . wait_for_block_rejections (
8083
- timeout. as_secs ( ) ,
8084
- & [
8085
- all_signers[ 16 ] ,
8086
- all_signers[ 17 ] ,
8087
- all_signers[ 18 ] ,
8088
- all_signers[ 19 ] ,
8089
- ] ,
8090
- )
7970
+ wait_for ( 60 , || {
7971
+ Ok ( signer_test
7972
+ . running_nodes
7973
+ . counters
7974
+ . naka_miner_current_rejections
7975
+ . get ( )
7976
+ >= reject_signers. len ( ) as u64 )
7977
+ } )
8091
7978
. unwrap ( ) ;
7979
+ assert_eq ! (
7980
+ signer_test
7981
+ . running_nodes
7982
+ . counters
7983
+ . naka_miner_current_rejections_timeout_secs
7984
+ . get( ) ,
7985
+ expected_timeout
7986
+ ) ;
7987
+ } ;
8092
7988
8093
- wait_for ( 60 , || {
8094
- Ok ( signer_test
8095
- . running_nodes
8096
- . counters
8097
- . naka_miner_current_rejections
8098
- . get ( )
8099
- >= 4 )
8100
- } )
8101
- . unwrap ( ) ;
8102
- assert_eq ! (
8103
- signer_test
8104
- . running_nodes
8105
- . counters
8106
- . naka_miner_current_rejections_timeout_secs
8107
- . get( ) ,
8108
- 99
8109
- ) ;
7989
+ test_rejections ( 19 , 123 ) ;
7990
+ test_rejections ( 18 , 20 ) ;
7991
+ test_rejections ( 17 , 10 ) ;
7992
+ test_rejections ( 16 , 99 ) ;
8110
7993
8111
7994
// reset reject/ignore
8112
7995
TEST_REJECT_ALL_BLOCK_PROPOSAL . set ( vec ! [ ] ) ;
0 commit comments