diff --git a/src/fiber/channel.rs b/src/fiber/channel.rs index 2936d246..4b416942 100644 --- a/src/fiber/channel.rs +++ b/src/fiber/channel.rs @@ -7,7 +7,7 @@ use crate::{ fiber::{ fee::calculate_tlc_forward_fee, network::{get_chain_hash, SendOnionPacketCommand}, - types::{ChannelUpdate, RemoveTlcFail, TlcErr, TlcErrorCode}, + types::{ChannelUpdate, TlcErr, TlcErrPacket, TlcErrorCode}, }, invoice::InvoiceStore, }; @@ -120,7 +120,7 @@ pub enum ChannelCommand { CommitmentSigned(), AddTlc( AddTlcCommand, - RpcReplyPort>, + RpcReplyPort>, ), RemoveTlc(RemoveTlcCommand, RpcReplyPort>), Shutdown(ShutdownCommand, RpcReplyPort>), @@ -501,7 +501,7 @@ where channel_id: state.get_id(), tlc_id, reason: RemoveTlcReason::RemoveTlcFail( - RemoveTlcFail::new(error_detail), + TlcErrPacket::new(error_detail), ), }), ), @@ -864,7 +864,7 @@ where onion_packet: Vec, added_tlc_id: u64, ) -> Result<(), ProcessingChannelError> { - let (send, recv) = oneshot::channel::>(); + let (send, recv) = oneshot::channel::>(); let rpc_reply = RpcReplyPort::from(send); self.network .send_message(NetworkActorMessage::Command( @@ -1350,7 +1350,7 @@ where } Err(err) => { let error_detail = self.get_tlc_detail_error(state, &err).await; - let _ = reply.send(Err(RemoveTlcFail::new(error_detail))); + let _ = reply.send(Err(TlcErrPacket::new(error_detail))); Err(err) } } diff --git a/src/fiber/gen/fiber.rs b/src/fiber/gen/fiber.rs index 3949735d..42b0aa20 100644 --- a/src/fiber/gen/fiber.rs +++ b/src/fiber/gen/fiber.rs @@ -9496,8 +9496,8 @@ impl molecule::prelude::Builder for RemoveTlcFulfillBuilder { } } #[derive(Clone)] -pub struct RemoveTlcFail(molecule::bytes::Bytes); -impl ::core::fmt::LowerHex for RemoveTlcFail { +pub struct TlcErrPacket(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for TlcErrPacket { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { use molecule::hex_string; if f.alternate() { @@ -9506,12 +9506,12 @@ impl ::core::fmt::LowerHex for RemoveTlcFail { write!(f, "{}", hex_string(self.as_slice())) } } -impl ::core::fmt::Debug for RemoveTlcFail { +impl ::core::fmt::Debug for TlcErrPacket { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { write!(f, "{}({:#x})", Self::NAME, self) } } -impl ::core::fmt::Display for RemoveTlcFail { +impl ::core::fmt::Display for TlcErrPacket { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { write!(f, "{} {{ ", Self::NAME)?; write!(f, "{}: {}", "onion_packet", self.onion_packet())?; @@ -9522,13 +9522,13 @@ impl ::core::fmt::Display for RemoveTlcFail { write!(f, " }}") } } -impl ::core::default::Default for RemoveTlcFail { +impl ::core::default::Default for TlcErrPacket { fn default() -> Self { let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); - RemoveTlcFail::new_unchecked(v) + TlcErrPacket::new_unchecked(v) } } -impl RemoveTlcFail { +impl TlcErrPacket { const DEFAULT_VALUE: [u8; 12] = [12, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0]; pub const FIELD_COUNT: usize = 1; pub fn total_size(&self) -> usize { @@ -9557,15 +9557,15 @@ impl RemoveTlcFail { Bytes::new_unchecked(self.0.slice(start..)) } } - pub fn as_reader<'r>(&'r self) -> RemoveTlcFailReader<'r> { - RemoveTlcFailReader::new_unchecked(self.as_slice()) + pub fn as_reader<'r>(&'r self) -> TlcErrPacketReader<'r> { + TlcErrPacketReader::new_unchecked(self.as_slice()) } } -impl molecule::prelude::Entity for RemoveTlcFail { - type Builder = RemoveTlcFailBuilder; - const NAME: &'static str = "RemoveTlcFail"; +impl molecule::prelude::Entity for TlcErrPacket { + type Builder = TlcErrPacketBuilder; + const NAME: &'static str = "TlcErrPacket"; fn new_unchecked(data: molecule::bytes::Bytes) -> Self { - RemoveTlcFail(data) + TlcErrPacket(data) } fn as_bytes(&self) -> molecule::bytes::Bytes { self.0.clone() @@ -9574,10 +9574,10 @@ impl molecule::prelude::Entity for RemoveTlcFail { &self.0[..] } fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult { - RemoveTlcFailReader::from_slice(slice).map(|reader| reader.to_entity()) + TlcErrPacketReader::from_slice(slice).map(|reader| reader.to_entity()) } fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { - RemoveTlcFailReader::from_compatible_slice(slice).map(|reader| reader.to_entity()) + TlcErrPacketReader::from_compatible_slice(slice).map(|reader| reader.to_entity()) } fn new_builder() -> Self::Builder { ::core::default::Default::default() @@ -9587,8 +9587,8 @@ impl molecule::prelude::Entity for RemoveTlcFail { } } #[derive(Clone, Copy)] -pub struct RemoveTlcFailReader<'r>(&'r [u8]); -impl<'r> ::core::fmt::LowerHex for RemoveTlcFailReader<'r> { +pub struct TlcErrPacketReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for TlcErrPacketReader<'r> { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { use molecule::hex_string; if f.alternate() { @@ -9597,12 +9597,12 @@ impl<'r> ::core::fmt::LowerHex for RemoveTlcFailReader<'r> { write!(f, "{}", hex_string(self.as_slice())) } } -impl<'r> ::core::fmt::Debug for RemoveTlcFailReader<'r> { +impl<'r> ::core::fmt::Debug for TlcErrPacketReader<'r> { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { write!(f, "{}({:#x})", Self::NAME, self) } } -impl<'r> ::core::fmt::Display for RemoveTlcFailReader<'r> { +impl<'r> ::core::fmt::Display for TlcErrPacketReader<'r> { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { write!(f, "{} {{ ", Self::NAME)?; write!(f, "{}: {}", "onion_packet", self.onion_packet())?; @@ -9613,7 +9613,7 @@ impl<'r> ::core::fmt::Display for RemoveTlcFailReader<'r> { write!(f, " }}") } } -impl<'r> RemoveTlcFailReader<'r> { +impl<'r> TlcErrPacketReader<'r> { pub const FIELD_COUNT: usize = 1; pub fn total_size(&self) -> usize { molecule::unpack_number(self.as_slice()) as usize @@ -9642,14 +9642,14 @@ impl<'r> RemoveTlcFailReader<'r> { } } } -impl<'r> molecule::prelude::Reader<'r> for RemoveTlcFailReader<'r> { - type Entity = RemoveTlcFail; - const NAME: &'static str = "RemoveTlcFailReader"; +impl<'r> molecule::prelude::Reader<'r> for TlcErrPacketReader<'r> { + type Entity = TlcErrPacket; + const NAME: &'static str = "TlcErrPacketReader"; fn to_entity(&self) -> Self::Entity { Self::Entity::new_unchecked(self.as_slice().to_owned().into()) } fn new_unchecked(slice: &'r [u8]) -> Self { - RemoveTlcFailReader(slice) + TlcErrPacketReader(slice) } fn as_slice(&self) -> &'r [u8] { self.0 @@ -9693,19 +9693,19 @@ impl<'r> molecule::prelude::Reader<'r> for RemoveTlcFailReader<'r> { } } #[derive(Clone, Debug, Default)] -pub struct RemoveTlcFailBuilder { +pub struct TlcErrPacketBuilder { pub(crate) onion_packet: Bytes, } -impl RemoveTlcFailBuilder { +impl TlcErrPacketBuilder { pub const FIELD_COUNT: usize = 1; pub fn onion_packet(mut self, v: Bytes) -> Self { self.onion_packet = v; self } } -impl molecule::prelude::Builder for RemoveTlcFailBuilder { - type Entity = RemoveTlcFail; - const NAME: &'static str = "RemoveTlcFailBuilder"; +impl molecule::prelude::Builder for TlcErrPacketBuilder { + type Entity = TlcErrPacket; + const NAME: &'static str = "TlcErrPacketBuilder"; fn expected_length(&self) -> usize { molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1) + self.onion_packet.as_slice().len() } @@ -9725,7 +9725,7 @@ impl molecule::prelude::Builder for RemoveTlcFailBuilder { let mut inner = Vec::with_capacity(self.expected_length()); self.write(&mut inner) .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME)); - RemoveTlcFail::new_unchecked(inner.into()) + TlcErrPacket::new_unchecked(inner.into()) } } #[derive(Clone)] @@ -9770,7 +9770,7 @@ impl RemoveTlcReason { let inner = self.0.slice(molecule::NUMBER_SIZE..); match self.item_id() { 0 => RemoveTlcFulfill::new_unchecked(inner).into(), - 1 => RemoveTlcFail::new_unchecked(inner).into(), + 1 => TlcErrPacket::new_unchecked(inner).into(), _ => panic!("{}: invalid data", Self::NAME), } } @@ -9835,7 +9835,7 @@ impl<'r> RemoveTlcReasonReader<'r> { let inner = &self.as_slice()[molecule::NUMBER_SIZE..]; match self.item_id() { 0 => RemoveTlcFulfillReader::new_unchecked(inner).into(), - 1 => RemoveTlcFailReader::new_unchecked(inner).into(), + 1 => TlcErrPacketReader::new_unchecked(inner).into(), _ => panic!("{}: invalid data", Self::NAME), } } @@ -9862,7 +9862,7 @@ impl<'r> molecule::prelude::Reader<'r> for RemoveTlcReasonReader<'r> { let inner_slice = &slice[molecule::NUMBER_SIZE..]; match item_id { 0 => RemoveTlcFulfillReader::verify(inner_slice, compatible), - 1 => RemoveTlcFailReader::verify(inner_slice, compatible), + 1 => TlcErrPacketReader::verify(inner_slice, compatible), _ => ve!(Self, UnknownItem, Self::ITEMS_COUNT, item_id), }?; Ok(()) @@ -9900,12 +9900,12 @@ impl molecule::prelude::Builder for RemoveTlcReasonBuilder { #[derive(Debug, Clone)] pub enum RemoveTlcReasonUnion { RemoveTlcFulfill(RemoveTlcFulfill), - RemoveTlcFail(RemoveTlcFail), + TlcErrPacket(TlcErrPacket), } #[derive(Debug, Clone, Copy)] pub enum RemoveTlcReasonUnionReader<'r> { RemoveTlcFulfill(RemoveTlcFulfillReader<'r>), - RemoveTlcFail(RemoveTlcFailReader<'r>), + TlcErrPacket(TlcErrPacketReader<'r>), } impl ::core::default::Default for RemoveTlcReasonUnion { fn default() -> Self { @@ -9918,8 +9918,8 @@ impl ::core::fmt::Display for RemoveTlcReasonUnion { RemoveTlcReasonUnion::RemoveTlcFulfill(ref item) => { write!(f, "{}::{}({})", Self::NAME, RemoveTlcFulfill::NAME, item) } - RemoveTlcReasonUnion::RemoveTlcFail(ref item) => { - write!(f, "{}::{}({})", Self::NAME, RemoveTlcFail::NAME, item) + RemoveTlcReasonUnion::TlcErrPacket(ref item) => { + write!(f, "{}::{}({})", Self::NAME, TlcErrPacket::NAME, item) } } } @@ -9930,8 +9930,8 @@ impl<'r> ::core::fmt::Display for RemoveTlcReasonUnionReader<'r> { RemoveTlcReasonUnionReader::RemoveTlcFulfill(ref item) => { write!(f, "{}::{}({})", Self::NAME, RemoveTlcFulfill::NAME, item) } - RemoveTlcReasonUnionReader::RemoveTlcFail(ref item) => { - write!(f, "{}::{}({})", Self::NAME, RemoveTlcFail::NAME, item) + RemoveTlcReasonUnionReader::TlcErrPacket(ref item) => { + write!(f, "{}::{}({})", Self::NAME, TlcErrPacket::NAME, item) } } } @@ -9940,7 +9940,7 @@ impl RemoveTlcReasonUnion { pub(crate) fn display_inner(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { match self { RemoveTlcReasonUnion::RemoveTlcFulfill(ref item) => write!(f, "{}", item), - RemoveTlcReasonUnion::RemoveTlcFail(ref item) => write!(f, "{}", item), + RemoveTlcReasonUnion::TlcErrPacket(ref item) => write!(f, "{}", item), } } } @@ -9948,7 +9948,7 @@ impl<'r> RemoveTlcReasonUnionReader<'r> { pub(crate) fn display_inner(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { match self { RemoveTlcReasonUnionReader::RemoveTlcFulfill(ref item) => write!(f, "{}", item), - RemoveTlcReasonUnionReader::RemoveTlcFail(ref item) => write!(f, "{}", item), + RemoveTlcReasonUnionReader::TlcErrPacket(ref item) => write!(f, "{}", item), } } } @@ -9957,9 +9957,9 @@ impl ::core::convert::From for RemoveTlcReasonUnion { RemoveTlcReasonUnion::RemoveTlcFulfill(item) } } -impl ::core::convert::From for RemoveTlcReasonUnion { - fn from(item: RemoveTlcFail) -> Self { - RemoveTlcReasonUnion::RemoveTlcFail(item) +impl ::core::convert::From for RemoveTlcReasonUnion { + fn from(item: TlcErrPacket) -> Self { + RemoveTlcReasonUnion::TlcErrPacket(item) } } impl<'r> ::core::convert::From> for RemoveTlcReasonUnionReader<'r> { @@ -9967,9 +9967,9 @@ impl<'r> ::core::convert::From> for RemoveTlcReasonUn RemoveTlcReasonUnionReader::RemoveTlcFulfill(item) } } -impl<'r> ::core::convert::From> for RemoveTlcReasonUnionReader<'r> { - fn from(item: RemoveTlcFailReader<'r>) -> Self { - RemoveTlcReasonUnionReader::RemoveTlcFail(item) +impl<'r> ::core::convert::From> for RemoveTlcReasonUnionReader<'r> { + fn from(item: TlcErrPacketReader<'r>) -> Self { + RemoveTlcReasonUnionReader::TlcErrPacket(item) } } impl RemoveTlcReasonUnion { @@ -9977,31 +9977,31 @@ impl RemoveTlcReasonUnion { pub fn as_bytes(&self) -> molecule::bytes::Bytes { match self { RemoveTlcReasonUnion::RemoveTlcFulfill(item) => item.as_bytes(), - RemoveTlcReasonUnion::RemoveTlcFail(item) => item.as_bytes(), + RemoveTlcReasonUnion::TlcErrPacket(item) => item.as_bytes(), } } pub fn as_slice(&self) -> &[u8] { match self { RemoveTlcReasonUnion::RemoveTlcFulfill(item) => item.as_slice(), - RemoveTlcReasonUnion::RemoveTlcFail(item) => item.as_slice(), + RemoveTlcReasonUnion::TlcErrPacket(item) => item.as_slice(), } } pub fn item_id(&self) -> molecule::Number { match self { RemoveTlcReasonUnion::RemoveTlcFulfill(_) => 0, - RemoveTlcReasonUnion::RemoveTlcFail(_) => 1, + RemoveTlcReasonUnion::TlcErrPacket(_) => 1, } } pub fn item_name(&self) -> &str { match self { RemoveTlcReasonUnion::RemoveTlcFulfill(_) => "RemoveTlcFulfill", - RemoveTlcReasonUnion::RemoveTlcFail(_) => "RemoveTlcFail", + RemoveTlcReasonUnion::TlcErrPacket(_) => "TlcErrPacket", } } pub fn as_reader<'r>(&'r self) -> RemoveTlcReasonUnionReader<'r> { match self { RemoveTlcReasonUnion::RemoveTlcFulfill(item) => item.as_reader().into(), - RemoveTlcReasonUnion::RemoveTlcFail(item) => item.as_reader().into(), + RemoveTlcReasonUnion::TlcErrPacket(item) => item.as_reader().into(), } } } @@ -10010,19 +10010,19 @@ impl<'r> RemoveTlcReasonUnionReader<'r> { pub fn as_slice(&self) -> &'r [u8] { match self { RemoveTlcReasonUnionReader::RemoveTlcFulfill(item) => item.as_slice(), - RemoveTlcReasonUnionReader::RemoveTlcFail(item) => item.as_slice(), + RemoveTlcReasonUnionReader::TlcErrPacket(item) => item.as_slice(), } } pub fn item_id(&self) -> molecule::Number { match self { RemoveTlcReasonUnionReader::RemoveTlcFulfill(_) => 0, - RemoveTlcReasonUnionReader::RemoveTlcFail(_) => 1, + RemoveTlcReasonUnionReader::TlcErrPacket(_) => 1, } } pub fn item_name(&self) -> &str { match self { RemoveTlcReasonUnionReader::RemoveTlcFulfill(_) => "RemoveTlcFulfill", - RemoveTlcReasonUnionReader::RemoveTlcFail(_) => "RemoveTlcFail", + RemoveTlcReasonUnionReader::TlcErrPacket(_) => "TlcErrPacket", } } } @@ -10031,8 +10031,8 @@ impl From for RemoveTlcReason { Self::new_builder().set(value).build() } } -impl From for RemoveTlcReason { - fn from(value: RemoveTlcFail) -> Self { +impl From for RemoveTlcReason { + fn from(value: TlcErrPacket) -> Self { Self::new_builder().set(value).build() } } diff --git a/src/fiber/network.rs b/src/fiber/network.rs index 0f302263..bb56c403 100644 --- a/src/fiber/network.rs +++ b/src/fiber/network.rs @@ -59,8 +59,8 @@ use super::types::{ FiberQueryInformation, GetBroadcastMessages, GetBroadcastMessagesResult, Hash256, NodeAnnouncement, NodeAnnouncementQuery, OpenChannel, Privkey, Pubkey, QueryBroadcastMessagesWithinTimeRange, QueryBroadcastMessagesWithinTimeRangeResult, - QueryChannelsWithinBlockRange, QueryChannelsWithinBlockRangeResult, RemoveTlc, RemoveTlcFail, - RemoveTlcReason, TlcErr, TlcErrData, TlcErrorCode, + QueryChannelsWithinBlockRange, QueryChannelsWithinBlockRangeResult, RemoveTlc, RemoveTlcReason, + TlcErr, TlcErrData, TlcErrPacket, TlcErrorCode, }; use super::FiberConfig; @@ -153,7 +153,7 @@ pub enum NetworkActorCommand { // is for the current node. SendPaymentOnionPacket( SendOnionPacketCommand, - RpcReplyPort>, + RpcReplyPort>, ), PeelPaymentOnionPacket( Vec, // onion_packet @@ -1969,17 +1969,17 @@ where &self, state: &mut NetworkActorState, command: SendOnionPacketCommand, - reply: RpcReplyPort>, + reply: RpcReplyPort>, ) { let SendOnionPacketCommand { packet, previous_tlc, } = command; - let invalid_onion_error = |reply: RpcReplyPort>| { + let invalid_onion_error = |reply: RpcReplyPort>| { let error_detail = TlcErr::new(TlcErrorCode::InvalidOnionPayload); reply - .send(Err(RemoveTlcFail::new(error_detail))) + .send(Err(TlcErrPacket::new(error_detail))) .expect("send error failed"); }; @@ -1995,14 +1995,14 @@ where return invalid_onion_error(reply); }; - let unknown_next_peer = |reply: RpcReplyPort>| { + let unknown_next_peer = |reply: RpcReplyPort>| { let error_detail = TlcErr::new_channel_fail( TlcErrorCode::UnknownNextPeer, channel_outpoint.clone(), None, ); reply - .send(Err(RemoveTlcFail::new(error_detail))) + .send(Err(TlcErrPacket::new(error_detail))) .expect("send add tlc response"); }; @@ -2016,7 +2016,7 @@ where return unknown_next_peer(reply); } }; - let (send, recv) = oneshot::channel::>(); + let (send, recv) = oneshot::channel::>(); let rpc_reply = RpcReplyPort::from(send); let command = ChannelCommand::AddTlc( AddTlcCommand { @@ -2045,7 +2045,7 @@ where ); let error_detail = TlcErr::new(TlcErrorCode::TemporaryNodeFailure); return reply - .send(Err(RemoveTlcFail::new(error_detail))) + .send(Err(TlcErrPacket::new(error_detail))) .expect("send add tlc response"); } } @@ -2169,7 +2169,7 @@ where ) .map_err(|err| Error::InvalidOnionPacket(err))?; - let (send, recv) = oneshot::channel::>(); + let (send, recv) = oneshot::channel::>(); let rpc_reply = RpcReplyPort::from(send); let command = SendOnionPacketCommand { packet: peeled_packet.serialize(), diff --git a/src/fiber/schema/fiber.mol b/src/fiber/schema/fiber.mol index 4fc22c61..702bb2e7 100644 --- a/src/fiber/schema/fiber.mol +++ b/src/fiber/schema/fiber.mol @@ -128,13 +128,13 @@ struct RemoveTlcFulfill { payment_preimage: Byte32, } -table RemoveTlcFail { +table TlcErrPacket { onion_packet: Bytes, } union RemoveTlcReason { RemoveTlcFulfill, - RemoveTlcFail, + TlcErrPacket, } table RemoveTlc { diff --git a/src/fiber/tests/types.rs b/src/fiber/tests/types.rs index 9d78ddd8..8f386b97 100644 --- a/src/fiber/tests/types.rs +++ b/src/fiber/tests/types.rs @@ -3,8 +3,8 @@ use crate::fiber::{ hash_algorithm::HashAlgorithm, tests::test_utils::generate_pubkey, types::{ - secp256k1_instance, AddTlc, PaymentHopData, PeeledOnionPacket, Privkey, Pubkey, - RemoveTlcFail, TlcErr, TlcErrorCode, + secp256k1_instance, AddTlc, PaymentHopData, PeeledOnionPacket, Privkey, Pubkey, TlcErr, + TlcErrPacket, TlcErrorCode, }, }; use ckb_types::packed::OutPointBuilder; @@ -104,7 +104,7 @@ fn test_tlc_fail_error() { assert!(!tlc_fail_detail.error_code.is_node()); assert!(tlc_fail_detail.error_code.is_bad_onion()); assert!(tlc_fail_detail.error_code.is_perm()); - let tlc_fail = RemoveTlcFail::new(tlc_fail_detail.clone()); + let tlc_fail = TlcErrPacket::new(tlc_fail_detail.clone()); let convert_back: TlcErr = tlc_fail.decode().expect("decoded fail"); assert_eq!(tlc_fail_detail, convert_back); @@ -112,7 +112,7 @@ fn test_tlc_fail_error() { let node_fail = TlcErr::new_node_fail(TlcErrorCode::PermanentNodeFailure, generate_pubkey().into()); assert!(node_fail.error_code.is_node()); - let tlc_fail = RemoveTlcFail::new(node_fail.clone()); + let tlc_fail = TlcErrPacket::new(node_fail.clone()); let convert_back = tlc_fail.decode().expect("decoded fail"); assert_eq!(node_fail, convert_back); } diff --git a/src/fiber/types.rs b/src/fiber/types.rs index 75f88b5c..94083bf5 100644 --- a/src/fiber/types.rs +++ b/src/fiber/types.rs @@ -1344,20 +1344,18 @@ impl TlcErr { // This is the onion packet we need to encode and send back to the sender, // currently it's the raw TlcErr serialized data from the TlcErr struct, -// sender should decode it and get the TlcErr, then decide what to do with the error +// sender should decode it and then decide what to do with the error. // Note: this supposed to be only accessible by the sender, and it's not reliable since it // is not placed on-chain due to the possibility of hop failure. -// -// FIXME: a better name like `TlcFailOnionPacket`?, since it's not only caused by removing tlc now #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct RemoveTlcFail { +pub struct TlcErrPacket { // TODO: replace this with the real onion packet pub onion_packet: Vec, } -impl RemoveTlcFail { +impl TlcErrPacket { pub fn new(tlc_fail: TlcErr) -> Self { - RemoveTlcFail { + TlcErrPacket { onion_packet: tlc_fail.serialize(), } } @@ -1367,27 +1365,27 @@ impl RemoveTlcFail { } } -impl From for molecule_fiber::RemoveTlcFail { - fn from(remove_tlc_fail: RemoveTlcFail) -> Self { - molecule_fiber::RemoveTlcFail::new_builder() +impl From for molecule_fiber::TlcErrPacket { + fn from(remove_tlc_fail: TlcErrPacket) -> Self { + molecule_fiber::TlcErrPacket::new_builder() .onion_packet(remove_tlc_fail.onion_packet.pack()) .build() } } -impl TryFrom for RemoveTlcFail { +impl TryFrom for TlcErrPacket { type Error = Error; - fn try_from(remove_tlc_fail: molecule_fiber::RemoveTlcFail) -> Result { - Ok(RemoveTlcFail { + fn try_from(remove_tlc_fail: molecule_fiber::TlcErrPacket) -> Result { + Ok(TlcErrPacket { onion_packet: remove_tlc_fail.onion_packet().unpack(), }) } } -impl std::fmt::Display for RemoveTlcFail { +impl std::fmt::Display for TlcErrPacket { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - write!(f, "RemoveTlcFail") + write!(f, "TlcErrPacket") } } @@ -1462,7 +1460,7 @@ impl TlcErrorCode { #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub enum RemoveTlcReason { RemoveTlcFulfill(RemoveTlcFulfill), - RemoveTlcFail(RemoveTlcFail), + RemoveTlcFail(TlcErrPacket), } impl From for molecule_fiber::RemoveTlcReasonUnion { @@ -1472,7 +1470,7 @@ impl From for molecule_fiber::RemoveTlcReasonUnion { molecule_fiber::RemoveTlcReasonUnion::RemoveTlcFulfill(remove_tlc_fulfill.into()) } RemoveTlcReason::RemoveTlcFail(remove_tlc_fail) => { - molecule_fiber::RemoveTlcReasonUnion::RemoveTlcFail(remove_tlc_fail.into()) + molecule_fiber::RemoveTlcReasonUnion::TlcErrPacket(remove_tlc_fail.into()) } } } @@ -1494,7 +1492,7 @@ impl TryFrom for RemoveTlcReason { molecule_fiber::RemoveTlcReasonUnion::RemoveTlcFulfill(remove_tlc_fulfill) => Ok( RemoveTlcReason::RemoveTlcFulfill(remove_tlc_fulfill.try_into()?), ), - molecule_fiber::RemoveTlcReasonUnion::RemoveTlcFail(remove_tlc_fail) => { + molecule_fiber::RemoveTlcReasonUnion::TlcErrPacket(remove_tlc_fail) => { Ok(RemoveTlcReason::RemoveTlcFail(remove_tlc_fail.try_into()?)) } }