@@ -339,7 +339,7 @@ impl<FG: ForkGraph> TransactionBatchProcessor<FG> {
339
339
/// Returns a hash map of executable program accounts (program accounts that are not writable
340
340
/// in the given transactions), and their owners, for the transactions with a valid
341
341
/// blockhash or nonce.
342
- pub fn filter_executable_program_accounts < ' a , CB : TransactionProcessingCallback > (
342
+ fn filter_executable_program_accounts < ' a , CB : TransactionProcessingCallback > (
343
343
callbacks : & CB ,
344
344
txs : & [ SanitizedTransaction ] ,
345
345
lock_results : & mut [ TransactionCheckResult ] ,
@@ -953,8 +953,9 @@ mod tests {
953
953
bpf_loader,
954
954
message:: { LegacyMessage , Message , MessageHeader } ,
955
955
rent_debits:: RentDebits ,
956
- signature:: Signature ,
956
+ signature:: { Keypair , Signature } ,
957
957
sysvar:: rent:: Rent ,
958
+ transaction:: { SanitizedTransaction , Transaction , TransactionError } ,
958
959
transaction_context:: TransactionContext ,
959
960
} ,
960
961
std:: {
@@ -1949,4 +1950,187 @@ mod tests {
1949
1950
assert_eq ! ( result[ & key1] , ( & owner1, 2 ) ) ;
1950
1951
assert_eq ! ( result[ & key2] , ( & owner2, 1 ) ) ;
1951
1952
}
1953
+
1954
+ #[ test]
1955
+ fn test_filter_executable_program_accounts_no_errors ( ) {
1956
+ let keypair1 = Keypair :: new ( ) ;
1957
+ let keypair2 = Keypair :: new ( ) ;
1958
+
1959
+ let non_program_pubkey1 = Pubkey :: new_unique ( ) ;
1960
+ let non_program_pubkey2 = Pubkey :: new_unique ( ) ;
1961
+ let program1_pubkey = Pubkey :: new_unique ( ) ;
1962
+ let program2_pubkey = Pubkey :: new_unique ( ) ;
1963
+ let account1_pubkey = Pubkey :: new_unique ( ) ;
1964
+ let account2_pubkey = Pubkey :: new_unique ( ) ;
1965
+ let account3_pubkey = Pubkey :: new_unique ( ) ;
1966
+ let account4_pubkey = Pubkey :: new_unique ( ) ;
1967
+
1968
+ let account5_pubkey = Pubkey :: new_unique ( ) ;
1969
+
1970
+ let mut bank = MockBankCallback :: default ( ) ;
1971
+ bank. account_shared_data . insert (
1972
+ non_program_pubkey1,
1973
+ AccountSharedData :: new ( 1 , 10 , & account5_pubkey) ,
1974
+ ) ;
1975
+ bank. account_shared_data . insert (
1976
+ non_program_pubkey2,
1977
+ AccountSharedData :: new ( 1 , 10 , & account5_pubkey) ,
1978
+ ) ;
1979
+ bank. account_shared_data . insert (
1980
+ program1_pubkey,
1981
+ AccountSharedData :: new ( 40 , 1 , & account5_pubkey) ,
1982
+ ) ;
1983
+ bank. account_shared_data . insert (
1984
+ program2_pubkey,
1985
+ AccountSharedData :: new ( 40 , 1 , & account5_pubkey) ,
1986
+ ) ;
1987
+ bank. account_shared_data . insert (
1988
+ account1_pubkey,
1989
+ AccountSharedData :: new ( 1 , 10 , & non_program_pubkey1) ,
1990
+ ) ;
1991
+ bank. account_shared_data . insert (
1992
+ account2_pubkey,
1993
+ AccountSharedData :: new ( 1 , 10 , & non_program_pubkey2) ,
1994
+ ) ;
1995
+ bank. account_shared_data . insert (
1996
+ account3_pubkey,
1997
+ AccountSharedData :: new ( 40 , 1 , & program1_pubkey) ,
1998
+ ) ;
1999
+ bank. account_shared_data . insert (
2000
+ account4_pubkey,
2001
+ AccountSharedData :: new ( 40 , 1 , & program2_pubkey) ,
2002
+ ) ;
2003
+
2004
+ let tx1 = Transaction :: new_with_compiled_instructions (
2005
+ & [ & keypair1] ,
2006
+ & [ non_program_pubkey1] ,
2007
+ Hash :: new_unique ( ) ,
2008
+ vec ! [ account1_pubkey, account2_pubkey, account3_pubkey] ,
2009
+ vec ! [ CompiledInstruction :: new( 1 , & ( ) , vec![ 0 ] ) ] ,
2010
+ ) ;
2011
+ let sanitized_tx1 = SanitizedTransaction :: from_transaction_for_tests ( tx1) ;
2012
+
2013
+ let tx2 = Transaction :: new_with_compiled_instructions (
2014
+ & [ & keypair2] ,
2015
+ & [ non_program_pubkey2] ,
2016
+ Hash :: new_unique ( ) ,
2017
+ vec ! [ account4_pubkey, account3_pubkey, account2_pubkey] ,
2018
+ vec ! [ CompiledInstruction :: new( 1 , & ( ) , vec![ 0 ] ) ] ,
2019
+ ) ;
2020
+ let sanitized_tx2 = SanitizedTransaction :: from_transaction_for_tests ( tx2) ;
2021
+
2022
+ let owners = & [ program1_pubkey, program2_pubkey] ;
2023
+ let programs =
2024
+ TransactionBatchProcessor :: < TestForkGraph > :: filter_executable_program_accounts (
2025
+ & bank,
2026
+ & [ sanitized_tx1, sanitized_tx2] ,
2027
+ & mut [ ( Ok ( ( ) ) , None , Some ( 0 ) ) , ( Ok ( ( ) ) , None , Some ( 0 ) ) ] ,
2028
+ owners,
2029
+ ) ;
2030
+
2031
+ // The result should contain only account3_pubkey, and account4_pubkey as the program accounts
2032
+ assert_eq ! ( programs. len( ) , 2 ) ;
2033
+ assert_eq ! (
2034
+ programs
2035
+ . get( & account3_pubkey)
2036
+ . expect( "failed to find the program account" ) ,
2037
+ & ( & program1_pubkey, 2 )
2038
+ ) ;
2039
+ assert_eq ! (
2040
+ programs
2041
+ . get( & account4_pubkey)
2042
+ . expect( "failed to find the program account" ) ,
2043
+ & ( & program2_pubkey, 1 )
2044
+ ) ;
2045
+ }
2046
+
2047
+ #[ test]
2048
+ fn test_filter_executable_program_accounts_invalid_blockhash ( ) {
2049
+ let keypair1 = Keypair :: new ( ) ;
2050
+ let keypair2 = Keypair :: new ( ) ;
2051
+
2052
+ let non_program_pubkey1 = Pubkey :: new_unique ( ) ;
2053
+ let non_program_pubkey2 = Pubkey :: new_unique ( ) ;
2054
+ let program1_pubkey = Pubkey :: new_unique ( ) ;
2055
+ let program2_pubkey = Pubkey :: new_unique ( ) ;
2056
+ let account1_pubkey = Pubkey :: new_unique ( ) ;
2057
+ let account2_pubkey = Pubkey :: new_unique ( ) ;
2058
+ let account3_pubkey = Pubkey :: new_unique ( ) ;
2059
+ let account4_pubkey = Pubkey :: new_unique ( ) ;
2060
+
2061
+ let account5_pubkey = Pubkey :: new_unique ( ) ;
2062
+
2063
+ let mut bank = MockBankCallback :: default ( ) ;
2064
+ bank. account_shared_data . insert (
2065
+ non_program_pubkey1,
2066
+ AccountSharedData :: new ( 1 , 10 , & account5_pubkey) ,
2067
+ ) ;
2068
+ bank. account_shared_data . insert (
2069
+ non_program_pubkey2,
2070
+ AccountSharedData :: new ( 1 , 10 , & account5_pubkey) ,
2071
+ ) ;
2072
+ bank. account_shared_data . insert (
2073
+ program1_pubkey,
2074
+ AccountSharedData :: new ( 40 , 1 , & account5_pubkey) ,
2075
+ ) ;
2076
+ bank. account_shared_data . insert (
2077
+ program2_pubkey,
2078
+ AccountSharedData :: new ( 40 , 1 , & account5_pubkey) ,
2079
+ ) ;
2080
+ bank. account_shared_data . insert (
2081
+ account1_pubkey,
2082
+ AccountSharedData :: new ( 1 , 10 , & non_program_pubkey1) ,
2083
+ ) ;
2084
+ bank. account_shared_data . insert (
2085
+ account2_pubkey,
2086
+ AccountSharedData :: new ( 1 , 10 , & non_program_pubkey2) ,
2087
+ ) ;
2088
+ bank. account_shared_data . insert (
2089
+ account3_pubkey,
2090
+ AccountSharedData :: new ( 40 , 1 , & program1_pubkey) ,
2091
+ ) ;
2092
+ bank. account_shared_data . insert (
2093
+ account4_pubkey,
2094
+ AccountSharedData :: new ( 40 , 1 , & program2_pubkey) ,
2095
+ ) ;
2096
+
2097
+ let tx1 = Transaction :: new_with_compiled_instructions (
2098
+ & [ & keypair1] ,
2099
+ & [ non_program_pubkey1] ,
2100
+ Hash :: new_unique ( ) ,
2101
+ vec ! [ account1_pubkey, account2_pubkey, account3_pubkey] ,
2102
+ vec ! [ CompiledInstruction :: new( 1 , & ( ) , vec![ 0 ] ) ] ,
2103
+ ) ;
2104
+ let sanitized_tx1 = SanitizedTransaction :: from_transaction_for_tests ( tx1) ;
2105
+
2106
+ let tx2 = Transaction :: new_with_compiled_instructions (
2107
+ & [ & keypair2] ,
2108
+ & [ non_program_pubkey2] ,
2109
+ Hash :: new_unique ( ) ,
2110
+ vec ! [ account4_pubkey, account3_pubkey, account2_pubkey] ,
2111
+ vec ! [ CompiledInstruction :: new( 1 , & ( ) , vec![ 0 ] ) ] ,
2112
+ ) ;
2113
+ // Let's not register blockhash from tx2. This should cause the tx2 to fail
2114
+ let sanitized_tx2 = SanitizedTransaction :: from_transaction_for_tests ( tx2) ;
2115
+
2116
+ let owners = & [ program1_pubkey, program2_pubkey] ;
2117
+ let mut lock_results = vec ! [ ( Ok ( ( ) ) , None , Some ( 0 ) ) , ( Ok ( ( ) ) , None , None ) ] ;
2118
+ let programs =
2119
+ TransactionBatchProcessor :: < TestForkGraph > :: filter_executable_program_accounts (
2120
+ & bank,
2121
+ & [ sanitized_tx1, sanitized_tx2] ,
2122
+ & mut lock_results,
2123
+ owners,
2124
+ ) ;
2125
+
2126
+ // The result should contain only account3_pubkey as the program accounts
2127
+ assert_eq ! ( programs. len( ) , 1 ) ;
2128
+ assert_eq ! (
2129
+ programs
2130
+ . get( & account3_pubkey)
2131
+ . expect( "failed to find the program account" ) ,
2132
+ & ( & program1_pubkey, 1 )
2133
+ ) ;
2134
+ assert_eq ! ( lock_results[ 1 ] . 0 , Err ( TransactionError :: BlockhashNotFound ) ) ;
2135
+ }
1952
2136
}
0 commit comments