1
- use std:: sync:: Arc ;
1
+ use std:: { collections :: HashSet , sync:: Arc } ;
2
2
3
3
use rayon:: ThreadPool ;
4
4
@@ -11,8 +11,8 @@ use crate::{
11
11
interface:: { TxpoolReadRequest , TxpoolReadResponse } ,
12
12
types:: { ReadResponseResult , TxpoolReadHandle } ,
13
13
} ,
14
- tables:: { OpenTables , TransactionBlobs } ,
15
- types:: TransactionHash ,
14
+ tables:: { KnownBlobHashes , OpenTables , TransactionBlobs , TransactionInfos } ,
15
+ types:: { TransactionBlobHash , TransactionHash , TxStateFlags } ,
16
16
} ;
17
17
18
18
// TODO: update the docs here
@@ -58,7 +58,9 @@ fn map_request(
58
58
match request {
59
59
TxpoolReadRequest :: TxBlob ( tx_hash) => tx_blob ( env, & tx_hash) ,
60
60
TxpoolReadRequest :: TxVerificationData ( tx_hash) => tx_verification_data ( env, & tx_hash) ,
61
- _ => todo ! ( ) ,
61
+ TxpoolReadRequest :: FilterKnownTxBlobHashes ( blob_hashes) => {
62
+ filter_known_tx_blob_hashes ( env, blob_hashes)
63
+ }
62
64
}
63
65
}
64
66
@@ -86,10 +88,15 @@ fn tx_blob(env: &ConcreteEnv, tx_hash: &TransactionHash) -> ReadResponseResult {
86
88
let tx_ro = inner_env. tx_ro ( ) ?;
87
89
88
90
let tx_blobs_table = inner_env. open_db_ro :: < TransactionBlobs > ( & tx_ro) ?;
91
+ let tx_infos_table = inner_env. open_db_ro :: < TransactionInfos > ( & tx_ro) ?;
89
92
90
- tx_blobs_table
91
- . get ( tx_hash)
92
- . map ( |blob| TxpoolReadResponse :: TxBlob ( blob. 0 ) )
93
+ let tx_blob = tx_blobs_table. get ( tx_hash) ?. 0 ;
94
+ let tx_info = tx_infos_table. get ( tx_hash) ?;
95
+
96
+ Ok ( TxpoolReadResponse :: TxBlob {
97
+ tx_blob,
98
+ state_stem : tx_info. flags . contains ( TxStateFlags :: STATE_STEM ) ,
99
+ } )
93
100
}
94
101
95
102
/// [`TxpoolReadRequest::TxVerificationData`].
@@ -102,3 +109,29 @@ fn tx_verification_data(env: &ConcreteEnv, tx_hash: &TransactionHash) -> ReadRes
102
109
103
110
get_transaction_verification_data ( tx_hash, & tables) . map ( TxpoolReadResponse :: TxVerificationData )
104
111
}
112
+
113
+ /// [`TxpoolReadRequest::FilterKnownTxBlobHashes`].
114
+ fn filter_known_tx_blob_hashes (
115
+ env : & ConcreteEnv ,
116
+ mut blob_hashes : HashSet < TransactionBlobHash > ,
117
+ ) -> ReadResponseResult {
118
+ let inner_env = env. env_inner ( ) ;
119
+ let tx_ro = inner_env. tx_ro ( ) ?;
120
+
121
+ let tx_blob_hashes = inner_env. open_db_ro :: < KnownBlobHashes > ( & tx_ro) ?;
122
+
123
+ let mut err = None ;
124
+ blob_hashes. retain ( |blob_hash| match tx_blob_hashes. contains ( blob_hash) {
125
+ Ok ( exists) => !exists,
126
+ Err ( e) => {
127
+ err. get_or_insert ( e) ;
128
+ false
129
+ }
130
+ } ) ;
131
+
132
+ if let Some ( e) = err {
133
+ return Err ( e) ;
134
+ }
135
+
136
+ Ok ( TxpoolReadResponse :: FilterKnownTxBlobHashes ( blob_hashes) )
137
+ }
0 commit comments