Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 0 additions & 48 deletions .travis.yml

This file was deleted.

42 changes: 21 additions & 21 deletions fuzz/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ use bitcoin::blockdata::script::Builder;
use bitcoin::blockdata::transaction::TxOut;
use bitcoin::hash_types::BlockHash;

use bitcoin::secp256k1;

use lightning::chain;
use lightning::ln::channelmanager::ChannelDetails;
use lightning::ln::features::InitFeatures;
Expand Down Expand Up @@ -120,7 +118,10 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
($MsgType: path, $len: expr) => {{
let mut reader = ::std::io::Cursor::new(get_slice!($len));
match <$MsgType>::read(&mut reader) {
Ok(msg) => msg,
Ok(msg) => {
assert_eq!(reader.position(), $len as u64);
msg
},
Err(e) => match e {
msgs::DecodeError::UnknownVersion => return,
msgs::DecodeError::UnknownRequiredFeature => return,
Expand All @@ -134,10 +135,10 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
}

macro_rules! decode_msg_with_len16 {
($MsgType: path, $begin_len: expr, $excess: expr) => {
($MsgType: path, $excess: expr) => {
{
let extra_len = slice_to_be16(&get_slice_nonadvancing!($begin_len as usize + 2)[$begin_len..$begin_len + 2]);
decode_msg!($MsgType, $begin_len as usize + 2 + (extra_len as usize) + $excess)
let extra_len = slice_to_be16(get_slice_nonadvancing!(2));
decode_msg!($MsgType, 2 + (extra_len as usize) + $excess)
}
}
}
Expand All @@ -162,30 +163,29 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
loop {
match get_slice!(1)[0] {
0 => {
let start_len = slice_to_be16(&get_slice_nonadvancing!(64 + 2)[64..64 + 2]) as usize;
let addr_len = slice_to_be16(&get_slice_nonadvancing!(64+start_len+2 + 74)[64+start_len+2 + 72..64+start_len+2 + 74]);
let start_len = slice_to_be16(&get_slice_nonadvancing!(2)[0..2]) as usize;
let addr_len = slice_to_be16(&get_slice_nonadvancing!(start_len+2 + 74)[start_len+2 + 72..start_len+2 + 74]);
if addr_len > (37+1)*4 {
return;
}
let msg = decode_msg_with_len16!(msgs::NodeAnnouncement, 64, 288);
node_pks.insert(msg.contents.node_id);
let _ = net_graph.update_node_from_announcement::<secp256k1::VerifyOnly>(&msg, None);
let msg = decode_msg_with_len16!(msgs::UnsignedNodeAnnouncement, 288);
node_pks.insert(msg.node_id);
let _ = net_graph.update_node_from_unsigned_announcement(&msg);
},
1 => {
let msg = decode_msg_with_len16!(msgs::ChannelAnnouncement, 64*4, 32+8+33*4);
node_pks.insert(msg.contents.node_id_1);
node_pks.insert(msg.contents.node_id_2);
let _ = net_graph.update_channel_from_announcement::<secp256k1::VerifyOnly>(&msg, None, None);
let msg = decode_msg_with_len16!(msgs::UnsignedChannelAnnouncement, 32+8+33*4);
node_pks.insert(msg.node_id_1);
node_pks.insert(msg.node_id_2);
let _ = net_graph.update_channel_from_unsigned_announcement::<&FuzzChainSource>(&msg, &None);
},
2 => {
let msg = decode_msg_with_len16!(msgs::ChannelAnnouncement, 64*4, 32+8+33*4);
node_pks.insert(msg.contents.node_id_1);
node_pks.insert(msg.contents.node_id_2);
let val = slice_to_be64(get_slice!(8));
let _ = net_graph.update_channel_from_announcement::<secp256k1::VerifyOnly>(&msg, Some(val), None);
let msg = decode_msg_with_len16!(msgs::UnsignedChannelAnnouncement, 32+8+33*4);
node_pks.insert(msg.node_id_1);
node_pks.insert(msg.node_id_2);
let _ = net_graph.update_channel_from_unsigned_announcement(&msg, &Some(&FuzzChainSource { input: Arc::clone(&input) }));
},
3 => {
let _ = net_graph.update_channel(&decode_msg!(msgs::ChannelUpdate, 136), None);
let _ = net_graph.update_channel_unsigned(&decode_msg!(msgs::UnsignedChannelUpdate, 72));
},
4 => {
let short_channel_id = slice_to_be64(get_slice!(8));
Expand Down
103 changes: 89 additions & 14 deletions lightning-c-bindings/include/lightning.h
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,32 @@ typedef struct LDKC2TupleTempl_HTLCOutputInCommitment__Signature {

typedef LDKC2TupleTempl_HTLCOutputInCommitment__Signature LDKC2Tuple_HTLCOutputInCommitmentSignatureZ;



/**
* An Err type for failure to process messages.
*/
typedef struct MUST_USE_STRUCT LDKLightningError {
/**
* Nearly everywhere, inner must be non-null, however in places where
* the Rust equivalent takes an Option, it may be set to null to indicate None.
*/
LDKnativeLightningError *inner;
bool is_owned;
} LDKLightningError;

typedef union LDKCResultPtr_u8__LightningError {
uint8_t *result;
LDKLightningError *err;
} LDKCResultPtr_u8__LightningError;

typedef struct LDKCResultTempl_u8__LightningError {
LDKCResultPtr_u8__LightningError contents;
bool result_ok;
} LDKCResultTempl_u8__LightningError;

typedef LDKCResultTempl_u8__LightningError LDKCResult_NoneLightningErrorZ;

typedef struct LDKPublicKey {
uint8_t compressed_form[33];
} LDKPublicKey;
Expand Down Expand Up @@ -2641,20 +2667,6 @@ typedef struct MUST_USE_STRUCT LDKGossipTimestampFilter {
bool is_owned;
} LDKGossipTimestampFilter;



/**
* An Err type for failure to process messages.
*/
typedef struct MUST_USE_STRUCT LDKLightningError {
/**
* Nearly everywhere, inner must be non-null, however in places where
* the Rust equivalent takes an Option, it may be set to null to indicate None.
*/
LDKnativeLightningError *inner;
bool is_owned;
} LDKLightningError;

typedef struct LDKCVecTempl_UpdateAddHTLC {
LDKUpdateAddHTLC *data;
uintptr_t datalen;
Expand Down Expand Up @@ -3153,6 +3165,10 @@ extern const LDKCResult_NoneChannelMonitorUpdateErrZ (*CResult_NoneChannelMonito

extern const void (*CResult_NoneChannelMonitorUpdateErrZ_free)(LDKCResult_NoneChannelMonitorUpdateErrZ);

extern const LDKCResult_NoneLightningErrorZ (*CResult_NoneLightningErrorZ_err)(LDKLightningError);

extern const void (*CResult_NoneLightningErrorZ_free)(LDKCResult_NoneLightningErrorZ);

extern const LDKCResult_NoneMonitorUpdateErrorZ (*CResult_NoneMonitorUpdateErrorZ_err)(LDKMonitorUpdateError);

extern const void (*CResult_NoneMonitorUpdateErrorZ_free)(LDKCResult_NoneMonitorUpdateErrorZ);
Expand Down Expand Up @@ -3301,6 +3317,8 @@ LDKCResult_NonePeerHandleErrorZ CResult_NonePeerHandleErrorZ_ok(void);

LDKC2Tuple_HTLCOutputInCommitmentSignatureZ C2Tuple_HTLCOutputInCommitmentSignatureZ_new(LDKHTLCOutputInCommitment a, LDKSignature b);

LDKCResult_NoneLightningErrorZ CResult_NoneLightningErrorZ_ok(void);

void Event_free(LDKEvent this_ptr);

LDKEvent Event_clone(const LDKEvent *orig);
Expand Down Expand Up @@ -7262,6 +7280,46 @@ LDKNetworkGraph NetworkGraph_read(LDKu8slice ser);
*/
MUST_USE_RES LDKNetworkGraph NetworkGraph_new(void);

/**
* For an already known node (from channel announcements), update its stored properties from a
* given node announcement.
*
* You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
* RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
* routing messages from a source using a protocol other than the lightning P2P protocol.
*/
MUST_USE_RES LDKCResult_NoneLightningErrorZ NetworkGraph_update_node_from_announcement(LDKNetworkGraph *this_arg, const LDKNodeAnnouncement *msg);

/**
* For an already known node (from channel announcements), update its stored properties from a
* given node announcement without verifying the associated signatures. Because we aren't
* given the associated signatures here we cannot relay the node announcement to any of our
* peers.
*/
MUST_USE_RES LDKCResult_NoneLightningErrorZ NetworkGraph_update_node_from_unsigned_announcement(LDKNetworkGraph *this_arg, const LDKUnsignedNodeAnnouncement *msg);

/**
* Store or update channel info from a channel announcement.
*
* You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
* RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
* routing messages from a source using a protocol other than the lightning P2P protocol.
*
* If a `chain::Access` object is provided via `chain_access`, it will be called to verify
* the corresponding UTXO exists on chain and is correctly-formatted.
*/
MUST_USE_RES LDKCResult_NoneLightningErrorZ NetworkGraph_update_channel_from_announcement(LDKNetworkGraph *this_arg, const LDKChannelAnnouncement *msg, LDKAccess *chain_access);

/**
* Store or update channel info from a channel announcement without verifying the associated
* signatures. Because we aren't given the associated signatures here we cannot relay the
* channel announcement to any of our peers.
*
* If a `chain::Access` object is provided via `chain_access`, it will be called to verify
* the corresponding UTXO exists on chain and is correctly-formatted.
*/
MUST_USE_RES LDKCResult_NoneLightningErrorZ NetworkGraph_update_channel_from_unsigned_announcement(LDKNetworkGraph *this_arg, const LDKUnsignedChannelAnnouncement *msg, LDKAccess *chain_access);

/**
* Close a channel if a corresponding HTLC fail was sent.
* If permanent, removes a channel from the local storage.
Expand All @@ -7270,4 +7328,21 @@ MUST_USE_RES LDKNetworkGraph NetworkGraph_new(void);
*/
void NetworkGraph_close_channel_from_update(LDKNetworkGraph *this_arg, uint64_t short_channel_id, bool is_permanent);

/**
* For an already known (from announcement) channel, update info about one of the directions
* of the channel.
*
* You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
* RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
* routing messages from a source using a protocol other than the lightning P2P protocol.
*/
MUST_USE_RES LDKCResult_NoneLightningErrorZ NetworkGraph_update_channel(LDKNetworkGraph *this_arg, const LDKChannelUpdate *msg);

/**
* For an already known (from announcement) channel, update info about one of the directions
* of the channel without verifying the associated signatures. Because we aren't given the
* associated signatures here we cannot relay the channel update to any of our peers.
*/
MUST_USE_RES LDKCResult_NoneLightningErrorZ NetworkGraph_update_channel_unsigned(LDKNetworkGraph *this_arg, const LDKUnsignedChannelUpdate *msg);

/* Text to put at the end of the generated file */
14 changes: 14 additions & 0 deletions lightning-c-bindings/include/lightningpp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1830,6 +1830,20 @@ class CResult_RouteLightningErrorZ {
const LDKCResult_RouteLightningErrorZ* operator &() const { return &self; }
const LDKCResult_RouteLightningErrorZ* operator ->() const { return &self; }
};
class CResult_NoneLightningErrorZ {
private:
LDKCResult_NoneLightningErrorZ self;
public:
CResult_NoneLightningErrorZ(const CResult_NoneLightningErrorZ&) = delete;
~CResult_NoneLightningErrorZ() { CResult_NoneLightningErrorZ_free(self); }
CResult_NoneLightningErrorZ(CResult_NoneLightningErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_NoneLightningErrorZ)); }
CResult_NoneLightningErrorZ(LDKCResult_NoneLightningErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_NoneLightningErrorZ)); }
operator LDKCResult_NoneLightningErrorZ() { LDKCResult_NoneLightningErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_NoneLightningErrorZ)); return res; }
LDKCResult_NoneLightningErrorZ* operator &() { return &self; }
LDKCResult_NoneLightningErrorZ* operator ->() { return &self; }
const LDKCResult_NoneLightningErrorZ* operator &() const { return &self; }
const LDKCResult_NoneLightningErrorZ* operator ->() const { return &self; }
};
class CResult_CVec_SignatureZNoneZ {
private:
LDKCResult_CVec_SignatureZNoneZ self;
Expand Down
13 changes: 13 additions & 0 deletions lightning-c-bindings/src/c_types/derived.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,3 +400,16 @@ pub static CResult_RouteLightningErrorZ_ok: extern "C" fn (crate::routing::route
pub static CResult_RouteLightningErrorZ_err: extern "C" fn (crate::ln::msgs::LightningError) -> CResult_RouteLightningErrorZ =
crate::c_types::CResultTempl::<crate::routing::router::Route, crate::ln::msgs::LightningError>::err;

#[no_mangle]
pub type CResult_NoneLightningErrorZ = crate::c_types::CResultTempl<u8, crate::ln::msgs::LightningError>;
#[no_mangle]
pub static CResult_NoneLightningErrorZ_free: extern "C" fn(CResult_NoneLightningErrorZ) = crate::c_types::CResultTempl_free::<u8, crate::ln::msgs::LightningError>;
#[no_mangle]
pub extern "C" fn CResult_NoneLightningErrorZ_ok() -> CResult_NoneLightningErrorZ {
crate::c_types::CResultTempl::ok(0)
}

#[no_mangle]
pub static CResult_NoneLightningErrorZ_err: extern "C" fn (crate::ln::msgs::LightningError) -> CResult_NoneLightningErrorZ =
crate::c_types::CResultTempl::<u8, crate::ln::msgs::LightningError>::err;

Loading