Skip to content

Commit

Permalink
Update to main, up to Dec 9 0c67753, channel state refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
optout21 committed Jan 9, 2024
2 parents d7d2f98 + 0c67753 commit 4131866
Show file tree
Hide file tree
Showing 53 changed files with 5,470 additions and 2,639 deletions.
8 changes: 5 additions & 3 deletions fuzz/src/chanmon_consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,16 @@ impl NodeSigner for KeyProvider {
}

impl SignerProvider for KeyProvider {
type Signer = TestChannelSigner;
type EcdsaSigner = TestChannelSigner;
#[cfg(taproot)]
type TaprootSigner = TestChannelSigner;

fn generate_channel_keys_id(&self, _inbound: bool, _channel_value_satoshis: u64, _user_channel_id: u128) -> [u8; 32] {
let id = self.rand_bytes_id.fetch_add(1, atomic::Ordering::Relaxed) as u8;
[id; 32]
}

fn derive_channel_signer(&self, channel_value_satoshis: u64, channel_keys_id: [u8; 32]) -> Self::Signer {
fn derive_channel_signer(&self, channel_value_satoshis: u64, channel_keys_id: [u8; 32]) -> Self::EcdsaSigner {
let secp_ctx = Secp256k1::signing_only();
let id = channel_keys_id[0];
let keys = InMemorySigner::new(
Expand All @@ -256,7 +258,7 @@ impl SignerProvider for KeyProvider {
TestChannelSigner::new_with_revoked(keys, revoked_commitment, false)
}

fn read_chan_signer(&self, buffer: &[u8]) -> Result<Self::Signer, DecodeError> {
fn read_chan_signer(&self, buffer: &[u8]) -> Result<Self::EcdsaSigner, DecodeError> {
let mut reader = std::io::Cursor::new(buffer);

let inner: InMemorySigner = ReadableArgs::read(&mut reader, self)?;
Expand Down
8 changes: 5 additions & 3 deletions fuzz/src/full_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,17 @@ impl NodeSigner for KeyProvider {
}

impl SignerProvider for KeyProvider {
type Signer = TestChannelSigner;
type EcdsaSigner = TestChannelSigner;
#[cfg(taproot)]
type TaprootSigner = TestChannelSigner;

fn generate_channel_keys_id(&self, inbound: bool, _channel_value_satoshis: u64, _user_channel_id: u128) -> [u8; 32] {
let ctr = self.counter.fetch_add(1, Ordering::Relaxed) as u8;
self.signer_state.borrow_mut().insert(ctr, (inbound, Arc::new(Mutex::new(EnforcementState::new()))));
[ctr; 32]
}

fn derive_channel_signer(&self, channel_value_satoshis: u64, channel_keys_id: [u8; 32]) -> Self::Signer {
fn derive_channel_signer(&self, channel_value_satoshis: u64, channel_keys_id: [u8; 32]) -> Self::EcdsaSigner {
let secp_ctx = Secp256k1::signing_only();
let ctr = channel_keys_id[0];
let (inbound, state) = self.signer_state.borrow().get(&ctr).unwrap().clone();
Expand Down Expand Up @@ -726,7 +728,7 @@ mod tests {
pub lines: Mutex<HashMap<(String, String), usize>>,
}
impl Logger for TrackingLogger {
fn log(&self, record: &Record) {
fn log(&self, record: Record) {
*self.lines.lock().unwrap().entry((record.module_path.to_string(), format!("{}", record.args))).or_insert(0) += 1;
println!("{:<5} [{} : {}, {}] {}", record.level.to_string(), record.module_path, record.file, record.line, record.args);
}
Expand Down
17 changes: 12 additions & 5 deletions fuzz/src/onion_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ impl MessageRouter for TestMessageRouter {
Ok(OnionMessagePath {
intermediate_nodes: vec![],
destination,
first_node_addresses: None,
})
}
}
Expand All @@ -91,6 +92,7 @@ impl OffersMessageHandler for TestOffersMessageHandler {
}
}

#[derive(Debug)]
struct TestCustomMessage {}

const CUSTOM_MESSAGE_TYPE: u64 = 4242;
Expand Down Expand Up @@ -189,11 +191,13 @@ impl NodeSigner for KeyProvider {
}

impl SignerProvider for KeyProvider {
type Signer = TestChannelSigner;
type EcdsaSigner = TestChannelSigner;
#[cfg(taproot)]
type TaprootSigner = TestChannelSigner;

fn generate_channel_keys_id(&self, _inbound: bool, _channel_value_satoshis: u64, _user_channel_id: u128) -> [u8; 32] { unreachable!() }

fn derive_channel_signer(&self, _channel_value_satoshis: u64, _channel_keys_id: [u8; 32]) -> Self::Signer {
fn derive_channel_signer(&self, _channel_value_satoshis: u64, _channel_keys_id: [u8; 32]) -> Self::EcdsaSigner {
unreachable!()
}

Expand All @@ -216,7 +220,7 @@ mod tests {
pub lines: Mutex<HashMap<(String, String), usize>>,
}
impl Logger for TrackingLogger {
fn log(&self, record: &Record) {
fn log(&self, record: Record) {
*self.lines.lock().unwrap().entry((record.module_path.to_string(), format!("{}", record.args))).or_insert(0) += 1;
println!("{:<5} [{} : {}, {}] {}", record.level.to_string(), record.module_path, record.file, record.line, record.args);
}
Expand Down Expand Up @@ -263,9 +267,12 @@ mod tests {
{
let log_entries = logger.lines.lock().unwrap();
assert_eq!(log_entries.get(&("lightning::onion_message::messenger".to_string(),
"Received an onion message with path_id None and a reply_path".to_string())), Some(&1));
"Received an onion message with path_id None and a reply_path: Custom(TestCustomMessage)"
.to_string())), Some(&1));
assert_eq!(log_entries.get(&("lightning::onion_message::messenger".to_string(),
"Sending onion message when responding to Custom onion message with path_id None".to_string())), Some(&1));
"Constructing onion message when responding to Custom onion message with path_id None: TestCustomMessage".to_string())), Some(&1));
assert_eq!(log_entries.get(&("lightning::onion_message::messenger".to_string(),
"Buffered onion message when responding to Custom onion message with path_id None".to_string())), Some(&1));
}

let two_unblinded_hops_om = "\
Expand Down
2 changes: 1 addition & 1 deletion fuzz/src/utils/test_logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl<'a, Out: Output> Write for LockedWriteAdapter<'a, Out> {
}

impl<Out: Output> Logger for TestLogger<Out> {
fn log(&self, record: &Record) {
fn log(&self, record: Record) {
write!(LockedWriteAdapter(&self.out),
"{:<5} {} [{} : {}] {}\n", record.level.to_string(), self.id, record.module_path, record.line, record.args)
.unwrap();
Expand Down
Loading

0 comments on commit 4131866

Please sign in to comment.