[bug] handling new_tx doesn't end up in sending empty message

This commit is contained in:
Sosthene 2024-11-22 14:50:35 +01:00 committed by Nicolas Cantu
parent 74863aac3b
commit 2e51f2ba42
2 changed files with 10 additions and 27 deletions

View File

@ -142,7 +142,7 @@ impl SilentPaymentWallet {
pub(crate) static WALLET: OnceLock<SilentPaymentWallet> = OnceLock::new();
fn handle_new_tx_request(new_tx_msg: &mut NewTxMessage) -> Result<()> {
fn handle_new_tx_request(new_tx_msg: &NewTxMessage) -> Result<()> {
let tx = deserialize::<Transaction>(&Vec::from_hex(&new_tx_msg.transaction)?)?;
let mempool_accept = DAEMON
.get()
@ -152,11 +152,6 @@ fn handle_new_tx_request(new_tx_msg: &mut NewTxMessage) -> Result<()> {
if !mempool_accept.allowed {
return Err(AnkError::NewTxError(mempool_accept.reject_reason.unwrap()))?;
}
if new_tx_msg.tweak_data.is_none() {
// we add the tweak_data
let partial_tweak = compute_partial_tweak_to_transaction(&tx)?;
new_tx_msg.tweak_data = Some(partial_tweak.to_string());
}
// we try to broadcast it
DAEMON.get().unwrap().lock_anyhow()?.broadcast(&tx)?;

View File

@ -140,27 +140,15 @@ fn process_faucet_message(ank_msg: Envelope, addr: SocketAddr) {
fn process_new_tx_message(ank_msg: Envelope, addr: SocketAddr) {
log::debug!("Received a new tx message");
if let Ok(mut new_tx_msg) = serde_json::from_str::<NewTxMessage>(&ank_msg.content) {
match handle_new_tx_request(&mut new_tx_msg) {
Ok(new_tx_msg) => {
// Repeat the msg to all except sender
if let Err(e) = broadcast_message(
AnkFlag::NewTx,
serde_json::to_string(&new_tx_msg).expect("This should not fail"),
BroadcastType::ExcludeSender(addr),
) {
log::error!("Failed to send message with error: {}", e);
}
}
Err(e) => {
log::error!("handle_new_tx_request returned error: {}", e);
new_tx_msg.error = Some(e.into());
if let Err(e) = broadcast_message(
AnkFlag::NewTx,
serde_json::to_string(&new_tx_msg).expect("This shouldn't fail"),
BroadcastType::Sender(addr),
) {
log::error!("Failed to broadcast message: {}", e);
}
if let Err(e) = handle_new_tx_request(&mut new_tx_msg) {
log::error!("handle_new_tx_request returned error: {}", e);
new_tx_msg.error = Some(e.into());
if let Err(e) = broadcast_message(
AnkFlag::NewTx,
serde_json::to_string(&new_tx_msg).expect("This shouldn't fail"),
BroadcastType::Sender(addr),
) {
log::error!("Failed to broadcast message: {}", e);
}
}
} else {