Improve names for messages 4 and 5

This commit is contained in:
Franck Royer 2021-01-27 14:14:20 +11:00
parent 33db688e3a
commit 8fd2620b83
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
14 changed files with 168 additions and 166 deletions

View File

@ -46,10 +46,10 @@ group Execution
Alice ->> Monero: Lock Alice ->> Monero: Lock
Alice -> Bob: Message4 Alice -> Bob: TransferProof
note right: xmr lock tx transfer proof\nThis can be removed if Bob watches the blockchain. note right: xmr lock tx transfer proof\nThis can be removed if Bob watches the blockchain.
Bob -> Alice: Message5 Bob -> Alice: EncryptedSignature
note left: redeem tx enc sig S_a note left: redeem tx enc sig S_a
Alice ->> Bitcoin: Redeem Alice ->> Bitcoin: Redeem

View File

@ -1,4 +1,4 @@
use crate::protocol::{alice, alice::Message4, bob, bob::Message5}; use crate::protocol::{alice, alice::TransferProof, bob, bob::EncryptedSignature};
use async_trait::async_trait; use async_trait::async_trait;
use futures::prelude::*; use futures::prelude::*;
use libp2p::{ use libp2p::{
@ -40,15 +40,15 @@ pub enum AliceToBob {
/// All responses are empty /// All responses are empty
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
pub enum Request { pub enum Request {
Message4(Box<Message4>), TransferProof(Box<TransferProof>),
Message5(Box<Message5>), EncryptedSignature(Box<EncryptedSignature>),
} }
#[derive(Clone, Copy, Debug, Serialize, Deserialize)] #[derive(Clone, Copy, Debug, Serialize, Deserialize)]
/// Response are only used for acknowledgement purposes. /// Response are only used for acknowledgement purposes.
pub enum Response { pub enum Response {
Message4, TransferProof,
Message5, EncryptedSignature,
} }
#[derive(Debug, Clone, Copy, Default)] #[derive(Debug, Clone, Copy, Default)]
@ -64,10 +64,10 @@ pub struct Message1Protocol;
pub struct Message2Protocol; pub struct Message2Protocol;
#[derive(Debug, Clone, Copy, Default)] #[derive(Debug, Clone, Copy, Default)]
pub struct Message4Protocol; pub struct TransferProofProtocol;
#[derive(Debug, Clone, Copy, Default)] #[derive(Debug, Clone, Copy, Default)]
pub struct Message5Protocol; pub struct EncryptedSignatureProtocol;
impl ProtocolName for Swap { impl ProtocolName for Swap {
fn protocol_name(&self) -> &[u8] { fn protocol_name(&self) -> &[u8] {
@ -93,15 +93,15 @@ impl ProtocolName for Message2Protocol {
} }
} }
impl ProtocolName for Message4Protocol { impl ProtocolName for TransferProofProtocol {
fn protocol_name(&self) -> &[u8] { fn protocol_name(&self) -> &[u8] {
b"/xmr/btc/message4/1.0.0" b"/xmr/btc/transfer_proof/1.0.0"
} }
} }
impl ProtocolName for Message5Protocol { impl ProtocolName for EncryptedSignatureProtocol {
fn protocol_name(&self) -> &[u8] { fn protocol_name(&self) -> &[u8] {
b"/xmr/btc/message5/1.0.0" b"/xmr/btc/encrypted_signature/1.0.0"
} }
} }

View File

@ -4,10 +4,10 @@ pub use self::{
event_loop::{EventLoop, EventLoopHandle}, event_loop::{EventLoop, EventLoopHandle},
message0::Message0, message0::Message0,
message1::Message1, message1::Message1,
message4::Message4,
state::*, state::*,
swap::{run, run_until}, swap::{run, run_until},
swap_response::*, swap_response::*,
transfer_proof::TransferProof,
}; };
use crate::{ use crate::{
bitcoin, bitcoin,
@ -21,7 +21,7 @@ use crate::{
transport::build, transport::build,
Seed as NetworkSeed, Seed as NetworkSeed,
}, },
protocol::{bob, bob::Message5, SwapAmounts}, protocol::{bob, bob::EncryptedSignature, SwapAmounts},
seed::Seed, seed::Seed,
}; };
use anyhow::{bail, Result}; use anyhow::{bail, Result};
@ -33,16 +33,16 @@ use std::{path::PathBuf, sync::Arc};
use tracing::{debug, info}; use tracing::{debug, info};
use uuid::Uuid; use uuid::Uuid;
mod encrypted_signature;
pub mod event_loop; pub mod event_loop;
mod message0; mod message0;
mod message1; mod message1;
mod message2; mod message2;
mod message4;
mod message5;
pub mod state; pub mod state;
mod steps; mod steps;
pub mod swap; pub mod swap;
mod swap_response; mod swap_response;
mod transfer_proof;
pub struct Swap { pub struct Swap {
pub state: AliceState, pub state: AliceState,
@ -236,8 +236,8 @@ pub enum OutEvent {
msg: Box<bob::Message2>, msg: Box<bob::Message2>,
bob_peer_id: PeerId, bob_peer_id: PeerId,
}, },
Message4, TransferProof,
Message5(Message5), EncryptedSignature(EncryptedSignature),
} }
impl From<peer_tracker::OutEvent> for OutEvent { impl From<peer_tracker::OutEvent> for OutEvent {
@ -286,18 +286,18 @@ impl From<message2::OutEvent> for OutEvent {
} }
} }
impl From<message4::OutEvent> for OutEvent { impl From<transfer_proof::OutEvent> for OutEvent {
fn from(event: message4::OutEvent) -> Self { fn from(event: transfer_proof::OutEvent) -> Self {
match event { match event {
message4::OutEvent::Msg => OutEvent::Message4, transfer_proof::OutEvent::Msg => OutEvent::TransferProof,
} }
} }
} }
impl From<message5::OutEvent> for OutEvent { impl From<encrypted_signature::OutEvent> for OutEvent {
fn from(event: message5::OutEvent) -> Self { fn from(event: encrypted_signature::OutEvent) -> Self {
match event { match event {
message5::OutEvent::Msg(msg) => OutEvent::Message5(msg), encrypted_signature::OutEvent::Msg(msg) => OutEvent::EncryptedSignature(msg),
} }
} }
} }
@ -312,8 +312,8 @@ pub struct Behaviour {
message0: message0::Behaviour, message0: message0::Behaviour,
message1: message1::Behaviour, message1: message1::Behaviour,
message2: message2::Behaviour, message2: message2::Behaviour,
message4: message4::Behaviour, transfer_proof: transfer_proof::Behaviour,
message5: message5::Behaviour, encrypted_signature: encrypted_signature::Behaviour,
} }
impl Behaviour { impl Behaviour {
@ -339,9 +339,9 @@ impl Behaviour {
debug!("Sent Message1"); debug!("Sent Message1");
} }
/// Send Message4 to Bob. /// Send Transfer Proof to Bob.
pub fn send_message4(&mut self, bob: PeerId, msg: Message4) { pub fn send_transfer_proof(&mut self, bob: PeerId, msg: TransferProof) {
self.message4.send(bob, msg); self.transfer_proof.send(bob, msg);
debug!("Sent Message 4"); debug!("Sent Transfer Proof");
} }
} }

View File

@ -1,6 +1,8 @@
use crate::{ use crate::{
network::request_response::{Message5Protocol, OneShotCodec, Request, Response, TIMEOUT}, network::request_response::{
protocol::bob::Message5, EncryptedSignatureProtocol, OneShotCodec, Request, Response, TIMEOUT,
},
protocol::bob::EncryptedSignature,
}; };
use libp2p::{ use libp2p::{
request_response::{ request_response::{
@ -19,15 +21,16 @@ use tracing::{debug, error};
#[derive(Debug)] #[derive(Debug)]
pub enum OutEvent { pub enum OutEvent {
Msg(Message5), Msg(EncryptedSignature),
} }
/// A `NetworkBehaviour` that represents receiving of message 5 from Bob. /// A `NetworkBehaviour` that represents receiving the Bitcoin encrypted
/// signature from Bob.
#[derive(NetworkBehaviour)] #[derive(NetworkBehaviour)]
#[behaviour(out_event = "OutEvent", poll_method = "poll")] #[behaviour(out_event = "OutEvent", poll_method = "poll")]
#[allow(missing_debug_implementations)] #[allow(missing_debug_implementations)]
pub struct Behaviour { pub struct Behaviour {
rr: RequestResponse<OneShotCodec<Message5Protocol>>, rr: RequestResponse<OneShotCodec<EncryptedSignatureProtocol>>,
#[behaviour(ignore)] #[behaviour(ignore)]
events: VecDeque<OutEvent>, events: VecDeque<OutEvent>,
} }
@ -37,8 +40,9 @@ impl Behaviour {
&mut self, &mut self,
_: &mut Context<'_>, _: &mut Context<'_>,
_: &mut impl PollParameters, _: &mut impl PollParameters,
) -> Poll<NetworkBehaviourAction<RequestProtocol<OneShotCodec<Message5Protocol>>, OutEvent>> ) -> Poll<
{ NetworkBehaviourAction<RequestProtocol<OneShotCodec<EncryptedSignatureProtocol>>, OutEvent>,
> {
if let Some(event) = self.events.pop_front() { if let Some(event) = self.events.pop_front() {
return Poll::Ready(NetworkBehaviourAction::GenerateEvent(event)); return Poll::Ready(NetworkBehaviourAction::GenerateEvent(event));
} }
@ -56,7 +60,7 @@ impl Default for Behaviour {
Self { Self {
rr: RequestResponse::new( rr: RequestResponse::new(
OneShotCodec::default(), OneShotCodec::default(),
vec![(Message5Protocol, ProtocolSupport::Full)], vec![(EncryptedSignatureProtocol, ProtocolSupport::Full)],
config, config,
), ),
events: Default::default(), events: Default::default(),
@ -74,11 +78,11 @@ impl NetworkBehaviourEventProcess<RequestResponseEvent<Request, Response>> for B
}, },
.. ..
} => { } => {
if let Request::Message5(msg) = request { if let Request::EncryptedSignature(msg) = request {
debug!("Received message 5"); debug!("Received encrypted signature");
self.events.push_back(OutEvent::Msg(*msg)); self.events.push_back(OutEvent::Msg(*msg));
// Send back empty response so that the request/response protocol completes. // Send back empty response so that the request/response protocol completes.
let _ = self.rr.send_response(channel, Response::Message5); let _ = self.rr.send_response(channel, Response::EncryptedSignature);
} }
} }
RequestResponseEvent::Message { RequestResponseEvent::Message {

View File

@ -2,9 +2,9 @@ use crate::{
network::{request_response::AliceToBob, transport::SwapTransport, TokioExecutor}, network::{request_response::AliceToBob, transport::SwapTransport, TokioExecutor},
protocol::{ protocol::{
alice, alice,
alice::{Behaviour, Message4, OutEvent, SwapResponse}, alice::{Behaviour, OutEvent, SwapResponse, TransferProof},
bob, bob,
bob::Message5, bob::EncryptedSignature,
}, },
}; };
use anyhow::{anyhow, Context, Result}; use anyhow::{anyhow, Context, Result};
@ -39,13 +39,13 @@ pub struct EventLoopHandle {
msg0: Receiver<(bob::Message0, ResponseChannel<AliceToBob>)>, msg0: Receiver<(bob::Message0, ResponseChannel<AliceToBob>)>,
msg1: Receiver<(bob::Message1, ResponseChannel<AliceToBob>)>, msg1: Receiver<(bob::Message1, ResponseChannel<AliceToBob>)>,
msg2: Receiver<bob::Message2>, msg2: Receiver<bob::Message2>,
msg5: Receiver<Message5>, r_encrypted_signature: Receiver<EncryptedSignature>,
request: Receiver<crate::protocol::alice::swap_response::OutEvent>, request: Receiver<crate::protocol::alice::swap_response::OutEvent>,
conn_established: Receiver<PeerId>, conn_established: Receiver<PeerId>,
send_swap_response: Sender<(ResponseChannel<AliceToBob>, SwapResponse)>, send_swap_response: Sender<(ResponseChannel<AliceToBob>, SwapResponse)>,
send_msg0: Sender<(ResponseChannel<AliceToBob>, alice::Message0)>, send_msg0: Sender<(ResponseChannel<AliceToBob>, alice::Message0)>,
send_msg1: Sender<(ResponseChannel<AliceToBob>, alice::Message1)>, send_msg1: Sender<(ResponseChannel<AliceToBob>, alice::Message1)>,
send_msg4: Sender<(PeerId, Message4)>, s_transfer_proof: Sender<(PeerId, TransferProof)>,
} }
impl EventLoopHandle { impl EventLoopHandle {
@ -77,8 +77,8 @@ impl EventLoopHandle {
.ok_or_else(|| anyhow!("Failed to receive message 2 from Bob")) .ok_or_else(|| anyhow!("Failed to receive message 2 from Bob"))
} }
pub async fn recv_message5(&mut self) -> Result<Message5> { pub async fn recv_encrypted_signature(&mut self) -> Result<EncryptedSignature> {
self.msg5 self.r_encrypted_signature
.recv() .recv()
.await .await
.ok_or_else(|| anyhow!("Failed to receive Bitcoin encrypted signature from Bob")) .ok_or_else(|| anyhow!("Failed to receive Bitcoin encrypted signature from Bob"))
@ -123,8 +123,8 @@ impl EventLoopHandle {
Ok(()) Ok(())
} }
pub async fn send_message4(&mut self, bob: PeerId, msg: Message4) -> Result<()> { pub async fn send_transfer_proof(&mut self, bob: PeerId, msg: TransferProof) -> Result<()> {
let _ = self.send_msg4.send((bob, msg)).await?; let _ = self.s_transfer_proof.send((bob, msg)).await?;
Ok(()) Ok(())
} }
} }
@ -135,13 +135,13 @@ pub struct EventLoop {
msg0: Sender<(bob::Message0, ResponseChannel<AliceToBob>)>, msg0: Sender<(bob::Message0, ResponseChannel<AliceToBob>)>,
msg1: Sender<(bob::Message1, ResponseChannel<AliceToBob>)>, msg1: Sender<(bob::Message1, ResponseChannel<AliceToBob>)>,
msg2: Sender<bob::Message2>, msg2: Sender<bob::Message2>,
msg5: Sender<Message5>, r_encrypted_signature: Sender<EncryptedSignature>,
request: Sender<crate::protocol::alice::swap_response::OutEvent>, request: Sender<crate::protocol::alice::swap_response::OutEvent>,
conn_established: Sender<PeerId>, conn_established: Sender<PeerId>,
send_swap_response: Receiver<(ResponseChannel<AliceToBob>, SwapResponse)>, send_swap_response: Receiver<(ResponseChannel<AliceToBob>, SwapResponse)>,
send_msg0: Receiver<(ResponseChannel<AliceToBob>, alice::Message0)>, send_msg0: Receiver<(ResponseChannel<AliceToBob>, alice::Message0)>,
send_msg1: Receiver<(ResponseChannel<AliceToBob>, alice::Message1)>, send_msg1: Receiver<(ResponseChannel<AliceToBob>, alice::Message1)>,
send_msg4: Receiver<(PeerId, Message4)>, s_transfer_proof: Receiver<(PeerId, TransferProof)>,
} }
impl EventLoop { impl EventLoop {
@ -163,39 +163,39 @@ impl EventLoop {
let msg0 = Channels::new(); let msg0 = Channels::new();
let msg1 = Channels::new(); let msg1 = Channels::new();
let msg2 = Channels::new(); let msg2 = Channels::new();
let msg5 = Channels::new(); let r_encrypted_signature = Channels::new();
let request = Channels::new(); let request = Channels::new();
let conn_established = Channels::new(); let conn_established = Channels::new();
let send_swap_response = Channels::new(); let send_swap_response = Channels::new();
let send_msg0 = Channels::new(); let send_msg0 = Channels::new();
let send_msg1 = Channels::new(); let send_msg1 = Channels::new();
let send_msg4 = Channels::new(); let s_transfer_proof = Channels::new();
let driver = EventLoop { let driver = EventLoop {
swarm, swarm,
msg0: msg0.sender, msg0: msg0.sender,
msg1: msg1.sender, msg1: msg1.sender,
msg2: msg2.sender, msg2: msg2.sender,
msg5: msg5.sender, r_encrypted_signature: r_encrypted_signature.sender,
request: request.sender, request: request.sender,
conn_established: conn_established.sender, conn_established: conn_established.sender,
send_swap_response: send_swap_response.receiver, send_swap_response: send_swap_response.receiver,
send_msg0: send_msg0.receiver, send_msg0: send_msg0.receiver,
send_msg1: send_msg1.receiver, send_msg1: send_msg1.receiver,
send_msg4: send_msg4.receiver, s_transfer_proof: s_transfer_proof.receiver,
}; };
let handle = EventLoopHandle { let handle = EventLoopHandle {
msg0: msg0.receiver, msg0: msg0.receiver,
msg1: msg1.receiver, msg1: msg1.receiver,
msg2: msg2.receiver, msg2: msg2.receiver,
msg5: msg5.receiver, r_encrypted_signature: r_encrypted_signature.receiver,
request: request.receiver, request: request.receiver,
conn_established: conn_established.receiver, conn_established: conn_established.receiver,
send_swap_response: send_swap_response.sender, send_swap_response: send_swap_response.sender,
send_msg0: send_msg0.sender, send_msg0: send_msg0.sender,
send_msg1: send_msg1.sender, send_msg1: send_msg1.sender,
send_msg4: send_msg4.sender, s_transfer_proof: s_transfer_proof.sender,
}; };
Ok((driver, handle)) Ok((driver, handle))
@ -218,9 +218,9 @@ impl EventLoop {
OutEvent::Message2 { msg, bob_peer_id : _} => { OutEvent::Message2 { msg, bob_peer_id : _} => {
let _ = self.msg2.send(*msg).await; let _ = self.msg2.send(*msg).await;
} }
OutEvent::Message4 => trace!("Bob ack'd message 4"), OutEvent::TransferProof => trace!("Bob ack'd receiving the transfer proof"),
OutEvent::Message5(msg) => { OutEvent::EncryptedSignature(msg) => {
let _ = self.msg5.send(msg).await; let _ = self.r_encrypted_signature.send(msg).await;
} }
OutEvent::Request(event) => { OutEvent::Request(event) => {
let _ = self.request.send(*event).await; let _ = self.request.send(*event).await;
@ -242,9 +242,9 @@ impl EventLoop {
self.swarm.send_message1(channel, msg); self.swarm.send_message1(channel, msg);
} }
}, },
msg4 = self.send_msg4.next().fuse() => { transfer_proof = self.s_transfer_proof.next().fuse() => {
if let Some((bob_peer_id, msg)) = msg4 { if let Some((bob_peer_id, msg)) = transfer_proof {
self.swarm.send_message4(bob_peer_id, msg); self.swarm.send_transfer_proof(bob_peer_id, msg);
} }
}, },
} }

View File

@ -8,13 +8,10 @@ use crate::{
}, },
monero, monero,
monero::CreateWalletForOutput, monero::CreateWalletForOutput,
protocol::{alice, alice::Message4, bob, bob::Message5, SwapAmounts}, protocol::{alice, alice::TransferProof, bob, bob::EncryptedSignature, SwapAmounts},
}; };
use anyhow::{anyhow, Context, Result}; use anyhow::{anyhow, Context, Result};
use ecdsa_fun::{ use ecdsa_fun::{adaptor::Adaptor, nonce::Deterministic};
adaptor::{Adaptor, EncryptedSignature},
nonce::Deterministic,
};
use libp2p::PeerId; use libp2p::PeerId;
use rand::{CryptoRng, RngCore}; use rand::{CryptoRng, RngCore};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -42,7 +39,7 @@ pub enum AliceState {
state3: Box<State3>, state3: Box<State3>,
}, },
EncSigLearned { EncSigLearned {
encrypted_signature: EncryptedSignature, encrypted_signature: bitcoin::EncryptedSignature,
state3: Box<State3>, state3: Box<State3>,
}, },
BtcRedeemed, BtcRedeemed,
@ -475,13 +472,13 @@ pub struct State5 {
} }
impl State5 { impl State5 {
pub fn next_message(&self) -> Message4 { pub fn next_message(&self) -> TransferProof {
Message4 { TransferProof {
tx_lock_proof: self.tx_lock_proof.clone(), tx_lock_proof: self.tx_lock_proof.clone(),
} }
} }
pub fn receive(self, msg: Message5) -> State6 { pub fn receive(self, msg: EncryptedSignature) -> State6 {
State6 { State6 {
a: self.a, a: self.a,
B: self.B, B: self.B,
@ -553,7 +550,7 @@ pub struct State6 {
tx_lock: bitcoin::TxLock, tx_lock: bitcoin::TxLock,
tx_punish_sig_bob: bitcoin::Signature, tx_punish_sig_bob: bitcoin::Signature,
tx_redeem_encsig: EncryptedSignature, tx_redeem_encsig: bitcoin::EncryptedSignature,
lock_xmr_fee: monero::Amount, lock_xmr_fee: monero::Amount,
} }

View File

@ -12,7 +12,7 @@ use crate::{
monero::Transfer, monero::Transfer,
protocol::{ protocol::{
alice, alice,
alice::{event_loop::EventLoopHandle, Message4, SwapResponse}, alice::{event_loop::EventLoopHandle, SwapResponse, TransferProof},
SwapAmounts, SwapAmounts,
}, },
}; };
@ -132,7 +132,7 @@ where
// Otherwise Alice might publish the lock tx twice! // Otherwise Alice might publish the lock tx twice!
event_loop_handle event_loop_handle
.send_message4(bob_peer_id, Message4 { .send_transfer_proof(bob_peer_id, TransferProof {
tx_lock_proof: transfer_proof, tx_lock_proof: transfer_proof,
}) })
.await?; .await?;
@ -144,7 +144,7 @@ pub async fn wait_for_bitcoin_encrypted_signature(
event_loop_handle: &mut EventLoopHandle, event_loop_handle: &mut EventLoopHandle,
) -> Result<EncryptedSignature> { ) -> Result<EncryptedSignature> {
let msg3 = event_loop_handle let msg3 = event_loop_handle
.recv_message5() .recv_encrypted_signature()
.await .await
.context("Failed to receive Bitcoin encrypted signature from Bob")?; .context("Failed to receive Bitcoin encrypted signature from Bob")?;

View File

@ -1,6 +1,6 @@
use crate::{ use crate::{
monero, monero,
network::request_response::{Message4Protocol, OneShotCodec, Request, Response, TIMEOUT}, network::request_response::{OneShotCodec, Request, Response, TransferProofProtocol, TIMEOUT},
}; };
use libp2p::{ use libp2p::{
request_response::{ request_response::{
@ -19,7 +19,7 @@ use std::{
use tracing::error; use tracing::error;
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Message4 { pub struct TransferProof {
pub tx_lock_proof: monero::TransferProof, pub tx_lock_proof: monero::TransferProof,
} }
@ -28,19 +28,20 @@ pub enum OutEvent {
Msg, Msg,
} }
/// A `NetworkBehaviour` that represents sending message 4 to Bob. /// A `NetworkBehaviour` that represents sending the Monero transfer proof to
/// Bob.
#[derive(NetworkBehaviour)] #[derive(NetworkBehaviour)]
#[behaviour(out_event = "OutEvent", poll_method = "poll")] #[behaviour(out_event = "OutEvent", poll_method = "poll")]
#[allow(missing_debug_implementations)] #[allow(missing_debug_implementations)]
pub struct Behaviour { pub struct Behaviour {
rr: RequestResponse<OneShotCodec<Message4Protocol>>, rr: RequestResponse<OneShotCodec<TransferProofProtocol>>,
#[behaviour(ignore)] #[behaviour(ignore)]
events: VecDeque<OutEvent>, events: VecDeque<OutEvent>,
} }
impl Behaviour { impl Behaviour {
pub fn send(&mut self, bob: PeerId, msg: Message4) { pub fn send(&mut self, bob: PeerId, msg: TransferProof) {
let msg = Request::Message4(Box::new(msg)); let msg = Request::TransferProof(Box::new(msg));
let _id = self.rr.send_request(&bob, msg); let _id = self.rr.send_request(&bob, msg);
} }
@ -48,7 +49,7 @@ impl Behaviour {
&mut self, &mut self,
_: &mut Context<'_>, _: &mut Context<'_>,
_: &mut impl PollParameters, _: &mut impl PollParameters,
) -> Poll<NetworkBehaviourAction<RequestProtocol<OneShotCodec<Message4Protocol>>, OutEvent>> ) -> Poll<NetworkBehaviourAction<RequestProtocol<OneShotCodec<TransferProofProtocol>>, OutEvent>>
{ {
if let Some(event) = self.events.pop_front() { if let Some(event) = self.events.pop_front() {
return Poll::Ready(NetworkBehaviourAction::GenerateEvent(event)); return Poll::Ready(NetworkBehaviourAction::GenerateEvent(event));
@ -67,7 +68,7 @@ impl Default for Behaviour {
Self { Self {
rr: RequestResponse::new( rr: RequestResponse::new(
OneShotCodec::default(), OneShotCodec::default(),
vec![(Message4Protocol, ProtocolSupport::Full)], vec![(TransferProofProtocol, ProtocolSupport::Full)],
config, config,
), ),
events: Default::default(), events: Default::default(),
@ -81,12 +82,12 @@ impl NetworkBehaviourEventProcess<RequestResponseEvent<Request, Response>> for B
RequestResponseEvent::Message { RequestResponseEvent::Message {
message: RequestResponseMessage::Request { .. }, message: RequestResponseMessage::Request { .. },
.. ..
} => panic!("Alice should never get a message 4 request from Bob"), } => panic!("Alice should never get a transfer proof request from Bob"),
RequestResponseEvent::Message { RequestResponseEvent::Message {
message: RequestResponseMessage::Response { response, .. }, message: RequestResponseMessage::Response { response, .. },
.. ..
} => { } => {
if let Response::Message4 = response { if let Response::TransferProof = response {
self.events.push_back(OutEvent::Msg); self.events.push_back(OutEvent::Msg);
} }
} }

View File

@ -2,7 +2,6 @@
//! Bob holds BTC and wishes receive XMR. //! Bob holds BTC and wishes receive XMR.
use crate::{ use crate::{
bitcoin, bitcoin,
bitcoin::EncryptedSignature,
config::Config, config::Config,
database, database,
database::Database, database::Database,
@ -22,26 +21,26 @@ use tracing::{debug, info};
use uuid::Uuid; use uuid::Uuid;
pub use self::{ pub use self::{
encrypted_signature::EncryptedSignature,
event_loop::{EventLoop, EventLoopHandle}, event_loop::{EventLoop, EventLoopHandle},
message0::Message0, message0::Message0,
message1::Message1, message1::Message1,
message2::Message2, message2::Message2,
message5::Message5,
state::*, state::*,
swap::{run, run_until}, swap::{run, run_until},
swap_request::*, swap_request::*,
}; };
use crate::protocol::alice::Message4; use crate::protocol::alice::TransferProof;
mod encrypted_signature;
pub mod event_loop; pub mod event_loop;
mod message0; mod message0;
mod message1; mod message1;
mod message2; mod message2;
mod message4;
mod message5;
pub mod state; pub mod state;
pub mod swap; pub mod swap;
mod swap_request; mod swap_request;
mod transfer_proof;
pub struct Swap { pub struct Swap {
pub state: BobState, pub state: BobState,
@ -213,8 +212,8 @@ pub enum OutEvent {
Message0(Box<alice::Message0>), Message0(Box<alice::Message0>),
Message1(Box<alice::Message1>), Message1(Box<alice::Message1>),
Message2, Message2,
Message4(Box<Message4>), TransferProof(Box<TransferProof>),
Message5, EncryptedSignature,
} }
impl From<peer_tracker::OutEvent> for OutEvent { impl From<peer_tracker::OutEvent> for OutEvent {
@ -257,18 +256,18 @@ impl From<message2::OutEvent> for OutEvent {
} }
} }
impl From<message4::OutEvent> for OutEvent { impl From<transfer_proof::OutEvent> for OutEvent {
fn from(event: message4::OutEvent) -> Self { fn from(event: transfer_proof::OutEvent) -> Self {
match event { match event {
message4::OutEvent::Msg(msg) => OutEvent::Message4(Box::new(msg)), transfer_proof::OutEvent::Msg(msg) => OutEvent::TransferProof(Box::new(msg)),
} }
} }
} }
impl From<message5::OutEvent> for OutEvent { impl From<encrypted_signature::OutEvent> for OutEvent {
fn from(event: message5::OutEvent) -> Self { fn from(event: encrypted_signature::OutEvent) -> Self {
match event { match event {
message5::OutEvent::Msg => OutEvent::Message5, encrypted_signature::OutEvent::Msg => OutEvent::EncryptedSignature,
} }
} }
} }
@ -283,8 +282,8 @@ pub struct Behaviour {
message0: message0::Behaviour, message0: message0::Behaviour,
message1: message1::Behaviour, message1: message1::Behaviour,
message2: message2::Behaviour, message2: message2::Behaviour,
message4: message4::Behaviour, transfer_proof: transfer_proof::Behaviour,
message5: message5::Behaviour, encrypted_signature: encrypted_signature::Behaviour,
} }
impl Behaviour { impl Behaviour {
@ -313,9 +312,13 @@ impl Behaviour {
} }
/// Sends Bob's fourth message to Alice. /// Sends Bob's fourth message to Alice.
pub fn send_message3(&mut self, alice: PeerId, tx_redeem_encsig: EncryptedSignature) { pub fn send_encrypted_signature(
let msg = Message5 { tx_redeem_encsig }; &mut self,
self.message5.send(alice, msg); alice: PeerId,
tx_redeem_encsig: bitcoin::EncryptedSignature,
) {
let msg = EncryptedSignature { tx_redeem_encsig };
self.encrypted_signature.send(alice, msg);
debug!("Sent Message3"); debug!("Sent Message3");
} }

View File

@ -1,6 +1,5 @@
use crate::{ use crate::network::request_response::{
bitcoin::EncryptedSignature, EncryptedSignatureProtocol, OneShotCodec, Request, Response, TIMEOUT,
network::request_response::{Message5Protocol, OneShotCodec, Request, Response, TIMEOUT},
}; };
use libp2p::{ use libp2p::{
request_response::{ request_response::{
@ -19,8 +18,8 @@ use std::{
use tracing::error; use tracing::error;
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Message5 { pub struct EncryptedSignature {
pub tx_redeem_encsig: EncryptedSignature, pub tx_redeem_encsig: crate::bitcoin::EncryptedSignature,
} }
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
@ -28,19 +27,19 @@ pub enum OutEvent {
Msg, Msg,
} }
/// A `NetworkBehaviour` that represents sending message 5 to Alice. /// A `NetworkBehaviour` that represents sending encrypted signature to Alice.
#[derive(NetworkBehaviour)] #[derive(NetworkBehaviour)]
#[behaviour(out_event = "OutEvent", poll_method = "poll")] #[behaviour(out_event = "OutEvent", poll_method = "poll")]
#[allow(missing_debug_implementations)] #[allow(missing_debug_implementations)]
pub struct Behaviour { pub struct Behaviour {
rr: RequestResponse<OneShotCodec<Message5Protocol>>, rr: RequestResponse<OneShotCodec<EncryptedSignatureProtocol>>,
#[behaviour(ignore)] #[behaviour(ignore)]
events: VecDeque<OutEvent>, events: VecDeque<OutEvent>,
} }
impl Behaviour { impl Behaviour {
pub fn send(&mut self, alice: PeerId, msg: Message5) { pub fn send(&mut self, alice: PeerId, msg: EncryptedSignature) {
let msg = Request::Message5(Box::new(msg)); let msg = Request::EncryptedSignature(Box::new(msg));
let _id = self.rr.send_request(&alice, msg); let _id = self.rr.send_request(&alice, msg);
} }
@ -48,8 +47,9 @@ impl Behaviour {
&mut self, &mut self,
_: &mut Context<'_>, _: &mut Context<'_>,
_: &mut impl PollParameters, _: &mut impl PollParameters,
) -> Poll<NetworkBehaviourAction<RequestProtocol<OneShotCodec<Message5Protocol>>, OutEvent>> ) -> Poll<
{ NetworkBehaviourAction<RequestProtocol<OneShotCodec<EncryptedSignatureProtocol>>, OutEvent>,
> {
if let Some(event) = self.events.pop_front() { if let Some(event) = self.events.pop_front() {
return Poll::Ready(NetworkBehaviourAction::GenerateEvent(event)); return Poll::Ready(NetworkBehaviourAction::GenerateEvent(event));
} }
@ -67,7 +67,7 @@ impl Default for Behaviour {
Self { Self {
rr: RequestResponse::new( rr: RequestResponse::new(
OneShotCodec::default(), OneShotCodec::default(),
vec![(Message5Protocol, ProtocolSupport::Full)], vec![(EncryptedSignatureProtocol, ProtocolSupport::Full)],
config, config,
), ),
events: Default::default(), events: Default::default(),
@ -86,7 +86,7 @@ impl NetworkBehaviourEventProcess<RequestResponseEvent<Request, Response>> for B
message: RequestResponseMessage::Response { response, .. }, message: RequestResponseMessage::Response { response, .. },
.. ..
} => { } => {
if let Response::Message5 = response { if let Response::EncryptedSignature = response {
self.events.push_back(OutEvent::Msg); self.events.push_back(OutEvent::Msg);
} }
} }

View File

@ -3,7 +3,7 @@ use crate::{
network::{transport::SwapTransport, TokioExecutor}, network::{transport::SwapTransport, TokioExecutor},
protocol::{ protocol::{
alice, alice,
alice::{Message4, SwapResponse}, alice::{SwapResponse, TransferProof},
bob::{self, Behaviour, OutEvent, SwapRequest}, bob::{self, Behaviour, OutEvent, SwapRequest},
}, },
}; };
@ -40,14 +40,14 @@ pub struct EventLoopHandle {
swap_response: Receiver<SwapResponse>, swap_response: Receiver<SwapResponse>,
msg0: Receiver<alice::Message0>, msg0: Receiver<alice::Message0>,
msg1: Receiver<alice::Message1>, msg1: Receiver<alice::Message1>,
msg4: Receiver<Message4>, r_transfer_proof: Receiver<TransferProof>,
conn_established: Receiver<PeerId>, conn_established: Receiver<PeerId>,
dial_alice: Sender<()>, dial_alice: Sender<()>,
send_swap_request: Sender<SwapRequest>, send_swap_request: Sender<SwapRequest>,
send_msg0: Sender<bob::Message0>, send_msg0: Sender<bob::Message0>,
send_msg1: Sender<bob::Message1>, send_msg1: Sender<bob::Message1>,
send_msg2: Sender<bob::Message2>, send_msg2: Sender<bob::Message2>,
send_msg3: Sender<EncryptedSignature>, s_encrypted_signature: Sender<EncryptedSignature>,
} }
impl EventLoopHandle { impl EventLoopHandle {
@ -72,11 +72,11 @@ impl EventLoopHandle {
.ok_or_else(|| anyhow!("Failed to receive message 1 from Alice")) .ok_or_else(|| anyhow!("Failed to receive message 1 from Alice"))
} }
pub async fn recv_message4(&mut self) -> Result<Message4> { pub async fn recv_transfer_proof(&mut self) -> Result<TransferProof> {
self.msg4 self.r_transfer_proof
.recv() .recv()
.await .await
.ok_or_else(|| anyhow!("Failed to receive message 4 from Alice")) .ok_or_else(|| anyhow!("Failed to receive transfer proof from Alice"))
} }
/// Dials other party and wait for the connection to be established. /// Dials other party and wait for the connection to be established.
@ -114,7 +114,7 @@ impl EventLoopHandle {
} }
pub async fn send_message3(&mut self, tx_redeem_encsig: EncryptedSignature) -> Result<()> { pub async fn send_message3(&mut self, tx_redeem_encsig: EncryptedSignature) -> Result<()> {
let _ = self.send_msg3.send(tx_redeem_encsig).await?; let _ = self.s_encrypted_signature.send(tx_redeem_encsig).await?;
Ok(()) Ok(())
} }
} }
@ -126,14 +126,14 @@ pub struct EventLoop {
swap_response: Sender<SwapResponse>, swap_response: Sender<SwapResponse>,
msg0: Sender<alice::Message0>, msg0: Sender<alice::Message0>,
msg1: Sender<alice::Message1>, msg1: Sender<alice::Message1>,
msg4: Sender<Message4>, r_transfer_proof: Sender<TransferProof>,
conn_established: Sender<PeerId>, conn_established: Sender<PeerId>,
dial_alice: Receiver<()>, dial_alice: Receiver<()>,
send_swap_request: Receiver<SwapRequest>, send_swap_request: Receiver<SwapRequest>,
send_msg0: Receiver<bob::Message0>, send_msg0: Receiver<bob::Message0>,
send_msg1: Receiver<bob::Message1>, send_msg1: Receiver<bob::Message1>,
send_msg2: Receiver<bob::Message2>, send_msg2: Receiver<bob::Message2>,
send_msg3: Receiver<EncryptedSignature>, s_encrypted_signature: Receiver<EncryptedSignature>,
} }
impl EventLoop { impl EventLoop {
@ -155,14 +155,14 @@ impl EventLoop {
let swap_response = Channels::new(); let swap_response = Channels::new();
let msg0 = Channels::new(); let msg0 = Channels::new();
let msg1 = Channels::new(); let msg1 = Channels::new();
let msg4 = Channels::new(); let r_transfer_proof = Channels::new();
let conn_established = Channels::new(); let conn_established = Channels::new();
let dial_alice = Channels::new(); let dial_alice = Channels::new();
let send_swap_request = Channels::new(); let send_swap_request = Channels::new();
let send_msg0 = Channels::new(); let send_msg0 = Channels::new();
let send_msg1 = Channels::new(); let send_msg1 = Channels::new();
let send_msg2 = Channels::new(); let send_msg2 = Channels::new();
let send_msg3 = Channels::new(); let s_encrypted_signature = Channels::new();
let event_loop = EventLoop { let event_loop = EventLoop {
swarm, swarm,
@ -170,28 +170,28 @@ impl EventLoop {
swap_response: swap_response.sender, swap_response: swap_response.sender,
msg0: msg0.sender, msg0: msg0.sender,
msg1: msg1.sender, msg1: msg1.sender,
msg4: msg4.sender, r_transfer_proof: r_transfer_proof.sender,
conn_established: conn_established.sender, conn_established: conn_established.sender,
dial_alice: dial_alice.receiver, dial_alice: dial_alice.receiver,
send_swap_request: send_swap_request.receiver, send_swap_request: send_swap_request.receiver,
send_msg0: send_msg0.receiver, send_msg0: send_msg0.receiver,
send_msg1: send_msg1.receiver, send_msg1: send_msg1.receiver,
send_msg2: send_msg2.receiver, send_msg2: send_msg2.receiver,
send_msg3: send_msg3.receiver, s_encrypted_signature: s_encrypted_signature.receiver,
}; };
let handle = EventLoopHandle { let handle = EventLoopHandle {
swap_response: swap_response.receiver, swap_response: swap_response.receiver,
msg0: msg0.receiver, msg0: msg0.receiver,
msg1: msg1.receiver, msg1: msg1.receiver,
msg4: msg4.receiver, r_transfer_proof: r_transfer_proof.receiver,
conn_established: conn_established.receiver, conn_established: conn_established.receiver,
dial_alice: dial_alice.sender, dial_alice: dial_alice.sender,
send_swap_request: send_swap_request.sender, send_swap_request: send_swap_request.sender,
send_msg0: send_msg0.sender, send_msg0: send_msg0.sender,
send_msg1: send_msg1.sender, send_msg1: send_msg1.sender,
send_msg2: send_msg2.sender, send_msg2: send_msg2.sender,
send_msg3: send_msg3.sender, s_encrypted_signature: s_encrypted_signature.sender,
}; };
Ok((event_loop, handle)) Ok((event_loop, handle))
@ -215,10 +215,10 @@ impl EventLoop {
let _ = self.msg1.send(*msg).await; let _ = self.msg1.send(*msg).await;
} }
OutEvent::Message2 => info!("Alice acknowledged message 2 received"), OutEvent::Message2 => info!("Alice acknowledged message 2 received"),
OutEvent::Message4(msg) => { OutEvent::TransferProof(msg) => {
let _ = self.msg4.send(*msg).await; let _ = self.r_transfer_proof.send(*msg).await;
} }
OutEvent::Message5 => info!("Alice acknowledged message 5 received"), OutEvent::EncryptedSignature => info!("Alice acknowledged encrypted signature received"),
} }
}, },
option = self.dial_alice.next().fuse() => { option = self.dial_alice.next().fuse() => {
@ -259,9 +259,9 @@ impl EventLoop {
self.swarm.send_message2(self.alice_peer_id.clone(), msg); self.swarm.send_message2(self.alice_peer_id.clone(), msg);
} }
}, },
msg3 = self.send_msg3.next().fuse() => { encrypted_signature = self.s_encrypted_signature.next().fuse() => {
if let Some(tx_redeem_encsig) = msg3 { if let Some(tx_redeem_encsig) = encrypted_signature {
self.swarm.send_message3(self.alice_peer_id.clone(), tx_redeem_encsig); self.swarm.send_encrypted_signature(self.alice_peer_id.clone(), tx_redeem_encsig);
} }
} }
} }

View File

@ -9,14 +9,10 @@ use crate::{
config::Config, config::Config,
monero, monero,
monero::{monero_private_key, TransferProof}, monero::{monero_private_key, TransferProof},
protocol::{alice, bob, bob::Message5, SwapAmounts}, protocol::{alice, bob, bob::EncryptedSignature, SwapAmounts},
}; };
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use ecdsa_fun::{ use ecdsa_fun::{adaptor::Adaptor, nonce::Deterministic, Signature};
adaptor::{Adaptor, EncryptedSignature},
nonce::Deterministic,
Signature,
};
use monero_harness::rpc::wallet::BlockHeight; use monero_harness::rpc::wallet::BlockHeight;
use rand::{CryptoRng, RngCore}; use rand::{CryptoRng, RngCore};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -244,7 +240,7 @@ pub struct State2 {
pub punish_address: bitcoin::Address, pub punish_address: bitcoin::Address,
pub tx_lock: bitcoin::TxLock, pub tx_lock: bitcoin::TxLock,
pub tx_cancel_sig_a: Signature, pub tx_cancel_sig_a: Signature,
pub tx_refund_encsig: EncryptedSignature, pub tx_refund_encsig: bitcoin::EncryptedSignature,
pub min_monero_confirmations: u32, pub min_monero_confirmations: u32,
} }
@ -313,7 +309,7 @@ pub struct State3 {
punish_address: bitcoin::Address, punish_address: bitcoin::Address,
pub tx_lock: bitcoin::TxLock, pub tx_lock: bitcoin::TxLock,
pub tx_cancel_sig_a: Signature, pub tx_cancel_sig_a: Signature,
pub tx_refund_encsig: EncryptedSignature, pub tx_refund_encsig: bitcoin::EncryptedSignature,
pub min_monero_confirmations: u32, pub min_monero_confirmations: u32,
} }
@ -433,19 +429,19 @@ pub struct State4 {
punish_address: bitcoin::Address, punish_address: bitcoin::Address,
pub tx_lock: bitcoin::TxLock, pub tx_lock: bitcoin::TxLock,
pub tx_cancel_sig_a: Signature, pub tx_cancel_sig_a: Signature,
pub tx_refund_encsig: EncryptedSignature, pub tx_refund_encsig: bitcoin::EncryptedSignature,
pub monero_wallet_restore_blockheight: u32, pub monero_wallet_restore_blockheight: u32,
} }
impl State4 { impl State4 {
pub fn next_message(&self) -> Message5 { pub fn next_message(&self) -> EncryptedSignature {
let tx_redeem = bitcoin::TxRedeem::new(&self.tx_lock, &self.redeem_address); let tx_redeem = bitcoin::TxRedeem::new(&self.tx_lock, &self.redeem_address);
let tx_redeem_encsig = self.b.encsign(self.S_a_bitcoin, tx_redeem.digest()); let tx_redeem_encsig = self.b.encsign(self.S_a_bitcoin, tx_redeem.digest());
Message5 { tx_redeem_encsig } EncryptedSignature { tx_redeem_encsig }
} }
pub fn tx_redeem_encsig(&self) -> EncryptedSignature { pub fn tx_redeem_encsig(&self) -> bitcoin::EncryptedSignature {
let tx_redeem = bitcoin::TxRedeem::new(&self.tx_lock, &self.redeem_address); let tx_redeem = bitcoin::TxRedeem::new(&self.tx_lock, &self.redeem_address);
self.b.encsign(self.S_a_bitcoin, tx_redeem.digest()) self.b.encsign(self.S_a_bitcoin, tx_redeem.digest())
} }
@ -615,7 +611,7 @@ pub struct State5 {
pub redeem_address: bitcoin::Address, pub redeem_address: bitcoin::Address,
punish_address: bitcoin::Address, punish_address: bitcoin::Address,
pub tx_lock: bitcoin::TxLock, pub tx_lock: bitcoin::TxLock,
tx_refund_encsig: EncryptedSignature, tx_refund_encsig: bitcoin::EncryptedSignature,
tx_cancel_sig: Signature, tx_cancel_sig: Signature,
pub monero_wallet_restore_blockheight: u32, pub monero_wallet_restore_blockheight: u32,
} }

View File

@ -130,7 +130,7 @@ where
{ {
event_loop_handle.dial().await?; event_loop_handle.dial().await?;
let msg4_watcher = event_loop_handle.recv_message4(); let transfer_proof_watcher = event_loop_handle.recv_transfer_proof();
let cancel_timelock_expires = let cancel_timelock_expires =
state3.wait_for_cancel_timelock_to_expire(bitcoin_wallet.as_ref()); state3.wait_for_cancel_timelock_to_expire(bitcoin_wallet.as_ref());
@ -143,11 +143,11 @@ where
monero_wallet.inner.block_height().await?; monero_wallet.inner.block_height().await?;
select! { select! {
msg4 = msg4_watcher => { transfer_proof = transfer_proof_watcher => {
let msg4 = msg4?; let transfer_proof = transfer_proof?;
BobState::XmrLockProofReceived { BobState::XmrLockProofReceived {
state: state3, state: state3,
lock_transfer_proof: msg4.tx_lock_proof, lock_transfer_proof: transfer_proof.tx_lock_proof,
monero_wallet_restore_blockheight monero_wallet_restore_blockheight
} }
}, },

View File

@ -1,6 +1,6 @@
use crate::{ use crate::{
network::request_response::{Message4Protocol, OneShotCodec, Request, Response, TIMEOUT}, network::request_response::{OneShotCodec, Request, Response, TransferProofProtocol, TIMEOUT},
protocol::alice::Message4, protocol::alice::TransferProof,
}; };
use libp2p::{ use libp2p::{
request_response::{ request_response::{
@ -19,15 +19,16 @@ use tracing::{debug, error};
#[derive(Debug)] #[derive(Debug)]
pub enum OutEvent { pub enum OutEvent {
Msg(Message4), Msg(TransferProof),
} }
/// A `NetworkBehaviour` that represents receiving of message 4 from Alice. /// A `NetworkBehaviour` that represents receiving the transfer proof from
/// Alice.
#[derive(NetworkBehaviour)] #[derive(NetworkBehaviour)]
#[behaviour(out_event = "OutEvent", poll_method = "poll")] #[behaviour(out_event = "OutEvent", poll_method = "poll")]
#[allow(missing_debug_implementations)] #[allow(missing_debug_implementations)]
pub struct Behaviour { pub struct Behaviour {
rr: RequestResponse<OneShotCodec<Message4Protocol>>, rr: RequestResponse<OneShotCodec<TransferProofProtocol>>,
#[behaviour(ignore)] #[behaviour(ignore)]
events: VecDeque<OutEvent>, events: VecDeque<OutEvent>,
} }
@ -37,7 +38,7 @@ impl Behaviour {
&mut self, &mut self,
_: &mut Context<'_>, _: &mut Context<'_>,
_: &mut impl PollParameters, _: &mut impl PollParameters,
) -> Poll<NetworkBehaviourAction<RequestProtocol<OneShotCodec<Message4Protocol>>, OutEvent>> ) -> Poll<NetworkBehaviourAction<RequestProtocol<OneShotCodec<TransferProofProtocol>>, OutEvent>>
{ {
if let Some(event) = self.events.pop_front() { if let Some(event) = self.events.pop_front() {
return Poll::Ready(NetworkBehaviourAction::GenerateEvent(event)); return Poll::Ready(NetworkBehaviourAction::GenerateEvent(event));
@ -56,7 +57,7 @@ impl Default for Behaviour {
Self { Self {
rr: RequestResponse::new( rr: RequestResponse::new(
OneShotCodec::default(), OneShotCodec::default(),
vec![(Message4Protocol, ProtocolSupport::Full)], vec![(TransferProofProtocol, ProtocolSupport::Full)],
config, config,
), ),
events: Default::default(), events: Default::default(),
@ -74,11 +75,11 @@ impl NetworkBehaviourEventProcess<RequestResponseEvent<Request, Response>> for B
}, },
.. ..
} => { } => {
if let Request::Message4(msg) = request { if let Request::TransferProof(msg) = request {
debug!("Received message 4"); debug!("Received Transfer Proof");
self.events.push_back(OutEvent::Msg(*msg)); self.events.push_back(OutEvent::Msg(*msg));
// Send back empty response so that the request/response protocol completes. // Send back empty response so that the request/response protocol completes.
let _ = self.rr.send_response(channel, Response::Message4); let _ = self.rr.send_response(channel, Response::TransferProof);
} }
} }
RequestResponseEvent::Message { RequestResponseEvent::Message {