Skip to content

Commit 2d5567e

Browse files
committed
Add missing txpool requests
1 parent 4ba94f4 commit 2d5567e

File tree

5 files changed

+67
-16
lines changed

5 files changed

+67
-16
lines changed

binaries/cuprated/src/txpool/dandelion/tx_store.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ impl Service<TxStoreRequest<TxId>> for TxStoreService {
6565
.boxed(),
6666
TxStoreRequest::Promote(tx_id) => self
6767
.txpool_write_handle
68+
.clone()
6869
.oneshot(TxpoolWriteRequest::Promote(tx_id))
6970
.map(|res| match res {
70-
Ok(_) | Err(RuntimeError::KeyNotFound) => TxStoreResponse::Ok,
71+
Ok(_) | Err(RuntimeError::KeyNotFound) => Ok(TxStoreResponse::Ok),
7172
Err(e) => Err(e.into()),
7273
})
7374
.boxed(),

binaries/cuprated/src/txpool/incoming_tx.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,9 @@ impl Service<IncomingTxs> for IncomingTxHandler {
8484
}
8585

8686
fn call(&mut self, req: IncomingTxs) -> Self::Future {
87-
let IncomingTxs::Bytes { txs, state } = req;
88-
8987
handle_incoming_txs(
90-
txs,
91-
state,
88+
req.txs,
89+
req.state,
9290
self.txs_being_handled.clone(),
9391
self.blockchain_context_cache.clone(),
9492
self.tx_verifier_service.clone(),

storage/txpool/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub mod tables;
1313
pub mod types;
1414

1515
pub use config::Config;
16-
pub use free::open;
16+
pub use free::{open, transaction_blob_hash};
1717

1818
//re-exports
1919
pub use cuprate_database;

storage/txpool/src/service/read.rs

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::sync::Arc;
1+
use std::{collections::HashSet, sync::Arc};
22

33
use rayon::ThreadPool;
44

@@ -11,8 +11,8 @@ use crate::{
1111
interface::{TxpoolReadRequest, TxpoolReadResponse},
1212
types::{ReadResponseResult, TxpoolReadHandle},
1313
},
14-
tables::{OpenTables, TransactionBlobs},
15-
types::TransactionHash,
14+
tables::{KnownBlobHashes, OpenTables, TransactionBlobs, TransactionInfos},
15+
types::{TransactionBlobHash, TransactionHash, TxStateFlags},
1616
};
1717

1818
// TODO: update the docs here
@@ -58,7 +58,9 @@ fn map_request(
5858
match request {
5959
TxpoolReadRequest::TxBlob(tx_hash) => tx_blob(env, &tx_hash),
6060
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+
}
6264
}
6365
}
6466

@@ -86,10 +88,15 @@ fn tx_blob(env: &ConcreteEnv, tx_hash: &TransactionHash) -> ReadResponseResult {
8688
let tx_ro = inner_env.tx_ro()?;
8789

8890
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)?;
8992

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+
})
93100
}
94101

95102
/// [`TxpoolReadRequest::TxVerificationData`].
@@ -102,3 +109,29 @@ fn tx_verification_data(env: &ConcreteEnv, tx_hash: &TransactionHash) -> ReadRes
102109

103110
get_transaction_verification_data(tx_hash, &tables).map(TxpoolReadResponse::TxVerificationData)
104111
}
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+
}

storage/txpool/src/service/write.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::sync::Arc;
22

3-
use cuprate_database::{ConcreteEnv, Env, EnvInner, RuntimeError, TxRw};
3+
use cuprate_database::{ConcreteEnv, DatabaseRw, Env, EnvInner, RuntimeError, TxRw};
44
use cuprate_database_service::DatabaseWriteHandle;
55
use cuprate_types::TransactionVerificationData;
66

@@ -10,8 +10,8 @@ use crate::{
1010
interface::{TxpoolWriteRequest, TxpoolWriteResponse},
1111
types::TxpoolWriteHandle,
1212
},
13-
tables::OpenTables,
14-
types::TransactionHash,
13+
tables::{OpenTables, TransactionInfos},
14+
types::{TransactionHash, TxStateFlags},
1515
};
1616

1717
//---------------------------------------------------------------------------------------------------- init_write_service
@@ -31,6 +31,7 @@ fn handle_txpool_request(
3131
add_transaction(env, tx, *state_stem)
3232
}
3333
TxpoolWriteRequest::RemoveTransaction(tx_hash) => remove_transaction(env, tx_hash),
34+
TxpoolWriteRequest::Promote(tx_hash) => promote(env, tx_hash),
3435
}
3536
}
3637

@@ -101,3 +102,21 @@ fn remove_transaction(
101102
TxRw::commit(tx_rw)?;
102103
Ok(TxpoolWriteResponse::Ok)
103104
}
105+
106+
/// [`TxpoolWriteRequest::Promote`]
107+
fn promote(
108+
env: &ConcreteEnv,
109+
tx_hash: &TransactionHash,
110+
) -> Result<TxpoolWriteResponse, RuntimeError> {
111+
let env_inner = env.env_inner();
112+
let tx_rw = env_inner.tx_rw()?;
113+
114+
let mut tx_infos = env_inner.open_db_rw::<TransactionInfos>(&tx_rw)?;
115+
116+
tx_infos.update(tx_hash, |mut info| {
117+
info.flags.remove(TxStateFlags::STATE_STEM);
118+
Some(info)
119+
})?;
120+
121+
Ok(TxpoolWriteResponse::Ok)
122+
}

0 commit comments

Comments
 (0)