mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-02-25 07:17:40 +01:00
Merge pull request #1756 from TheBlueMatt/2022-10-rgs-no-std
Fix `rapid-gossip-sync` `no-std` and properly test no-std in CI
This commit is contained in:
commit
559ed20f92
7 changed files with 47 additions and 36 deletions
37
.github/workflows/build.yml
vendored
37
.github/workflows/build.yml
vendored
|
@ -113,27 +113,28 @@ jobs:
|
|||
if: "matrix.build-no-std && !matrix.coverage"
|
||||
shell: bash # Default on Winblows is powershell
|
||||
run: |
|
||||
cd lightning
|
||||
cargo test --verbose --color always --no-default-features --features no-std
|
||||
# check if there is a conflict between no-std and the default std feature
|
||||
cargo test --verbose --color always --features no-std
|
||||
# check that things still pass without grind_signatures
|
||||
# note that outbound_commitment_test only runs in this mode, because of hardcoded signature values
|
||||
cargo test --verbose --color always --no-default-features --features std
|
||||
# check if there is a conflict between no-std and the c_bindings cfg
|
||||
RUSTFLAGS="--cfg=c_bindings" cargo test --verbose --color always --no-default-features --features=no-std
|
||||
cd ..
|
||||
cd lightning-invoice
|
||||
cargo test --verbose --color always --no-default-features --features no-std
|
||||
# check if there is a conflict between no-std and the default std feature
|
||||
cargo test --verbose --color always --features no-std
|
||||
# check if there is a conflict between no-std and the c_bindings cfg
|
||||
RUSTFLAGS="--cfg=c_bindings" cargo test --verbose --color always --no-default-features --features=no-std
|
||||
for DIR in lightning lightning-invoice lightning-rapid-gossip-sync; do
|
||||
cd $DIR
|
||||
cargo test --verbose --color always --no-default-features --features no-std
|
||||
# check if there is a conflict between no-std and the default std feature
|
||||
cargo test --verbose --color always --features no-std
|
||||
# check that things still pass without grind_signatures
|
||||
# note that outbound_commitment_test only runs in this mode, because of hardcoded signature values
|
||||
cargo test --verbose --color always --no-default-features --features std
|
||||
# check if there is a conflict between no-std and the c_bindings cfg
|
||||
RUSTFLAGS="--cfg=c_bindings" cargo test --verbose --color always --no-default-features --features=no-std
|
||||
cd ..
|
||||
done
|
||||
# check no-std compatibility across dependencies
|
||||
cd ..
|
||||
cd no-std-check
|
||||
cargo check --verbose --color always
|
||||
cd ..
|
||||
- name: Build no-std-check on Rust ${{ matrix.toolchain }} for ARM Embedded
|
||||
if: "matrix.build-no-std && matrix.platform == 'ubuntu-latest'"
|
||||
run: |
|
||||
cd no-std-check
|
||||
rustup target add thumbv7m-none-eabi
|
||||
sudo apt-get -y install gcc-arm-none-eabi
|
||||
cargo build --target=thumbv7m-none-eabi
|
||||
- name: Test on no-std builds Rust ${{ matrix.toolchain }} and full code-linking for coverage generation
|
||||
if: "matrix.build-no-std && matrix.coverage"
|
||||
run: |
|
||||
|
|
|
@ -16,7 +16,7 @@ std = ["lightning/std"]
|
|||
_bench_unstable = []
|
||||
|
||||
[dependencies]
|
||||
lightning = { version = "0.0.111", path = "../lightning" }
|
||||
lightning = { version = "0.0.111", path = "../lightning", default-features = false }
|
||||
bitcoin = { version = "0.29.0", default-features = false }
|
||||
|
||||
[dev-dependencies]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use core::fmt::Debug;
|
||||
use std::fmt::Formatter;
|
||||
use core::fmt::Formatter;
|
||||
use lightning::ln::msgs::{DecodeError, LightningError};
|
||||
|
||||
/// All-encompassing standard error type that processing can return
|
||||
|
@ -12,8 +12,8 @@ pub enum GraphSyncError {
|
|||
LightningError(LightningError),
|
||||
}
|
||||
|
||||
impl From<std::io::Error> for GraphSyncError {
|
||||
fn from(error: std::io::Error) -> Self {
|
||||
impl From<lightning::io::Error> for GraphSyncError {
|
||||
fn from(error: lightning::io::Error) -> Self {
|
||||
Self::DecodeError(DecodeError::Io(error.kind()))
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ impl From<LightningError> for GraphSyncError {
|
|||
}
|
||||
|
||||
impl Debug for GraphSyncError {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
|
||||
match self {
|
||||
GraphSyncError::DecodeError(e) => f.write_fmt(format_args!("DecodeError: {:?}", e)),
|
||||
GraphSyncError::LightningError(e) => f.write_fmt(format_args!("LightningError: {:?}", e))
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
//!
|
||||
//! After the gossip data snapshot has been downloaded, one of the client's graph processing
|
||||
//! functions needs to be called. In this example, we process the update by reading its contents
|
||||
//! from disk, which we do by calling [sync_network_graph_with_file_path]:
|
||||
//! from disk, which we do by calling [`RapidGossipSync::update_network_graph`]:
|
||||
//!
|
||||
//! ```
|
||||
//! use bitcoin::blockdata::constants::genesis_block;
|
||||
|
@ -56,15 +56,20 @@
|
|||
//! let block_hash = genesis_block(Network::Bitcoin).header.block_hash();
|
||||
//! let network_graph = NetworkGraph::new(block_hash, &logger);
|
||||
//! let rapid_sync = RapidGossipSync::new(&network_graph);
|
||||
//! let new_last_sync_timestamp_result = rapid_sync.sync_network_graph_with_file_path("./rapid_sync.lngossip");
|
||||
//! let snapshot_contents: &[u8] = &[0; 0];
|
||||
//! let new_last_sync_timestamp_result = rapid_sync.update_network_graph(snapshot_contents);
|
||||
//! ```
|
||||
//! [sync_network_graph_with_file_path]: RapidGossipSync::sync_network_graph_with_file_path
|
||||
|
||||
#![cfg_attr(all(not(feature = "std"), not(test)), no_std)]
|
||||
|
||||
// Allow and import test features for benching
|
||||
#![cfg_attr(all(test, feature = "_bench_unstable"), feature(test))]
|
||||
#[cfg(all(test, feature = "_bench_unstable"))]
|
||||
extern crate test;
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
extern crate alloc;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use std::fs::File;
|
||||
use core::ops::Deref;
|
||||
|
@ -143,6 +148,7 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::fs;
|
||||
|
|
|
@ -16,6 +16,9 @@ use lightning::io;
|
|||
use crate::error::GraphSyncError;
|
||||
use crate::RapidGossipSync;
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
use alloc::{vec::Vec, borrow::ToOwned};
|
||||
|
||||
/// The purpose of this prefix is to identify the serialization format, should other rapid gossip
|
||||
/// sync formats arise in the future.
|
||||
///
|
||||
|
@ -47,7 +50,7 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
|
|||
let backdated_timestamp = latest_seen_timestamp.saturating_sub(24 * 3600 * 7);
|
||||
|
||||
let node_id_count: u32 = Readable::read(read_cursor)?;
|
||||
let mut node_ids: Vec<PublicKey> = Vec::with_capacity(std::cmp::min(
|
||||
let mut node_ids: Vec<PublicKey> = Vec::with_capacity(core::cmp::min(
|
||||
node_id_count,
|
||||
MAX_INITIAL_NODE_ID_VECTOR_CAPACITY,
|
||||
) as usize);
|
||||
|
@ -132,7 +135,7 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
|
|||
htlc_maximum_msat: default_htlc_maximum_msat,
|
||||
fee_base_msat: default_fee_base_msat,
|
||||
fee_proportional_millionths: default_fee_proportional_millionths,
|
||||
excess_data: vec![],
|
||||
excess_data: Vec::new(),
|
||||
}
|
||||
} else {
|
||||
// incremental update, field flags will indicate mutated values
|
||||
|
@ -162,7 +165,7 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
|
|||
htlc_maximum_msat: directional_info.htlc_maximum_msat,
|
||||
fee_base_msat: directional_info.fees.base_msat,
|
||||
fee_proportional_millionths: directional_info.fees.proportional_millionths,
|
||||
excess_data: vec![],
|
||||
excess_data: Vec::new(),
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ use prelude::*;
|
|||
use io;
|
||||
use alloc::collections::LinkedList;
|
||||
use sync::{Arc, Mutex, MutexGuard, FairRwLock};
|
||||
use core::sync::atomic::{AtomicBool, AtomicU64, Ordering};
|
||||
use core::sync::atomic::{AtomicBool, AtomicU32, Ordering};
|
||||
use core::{cmp, hash, fmt, mem};
|
||||
use core::ops::Deref;
|
||||
use core::convert::Infallible;
|
||||
|
@ -540,7 +540,7 @@ pub struct PeerManager<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: D
|
|||
|
||||
/// Used to track the last value sent in a node_announcement "timestamp" field. We ensure this
|
||||
/// value increases strictly since we don't assume access to a time source.
|
||||
last_node_announcement_serial: AtomicU64,
|
||||
last_node_announcement_serial: AtomicU32,
|
||||
|
||||
our_node_secret: SecretKey,
|
||||
ephemeral_key_midstate: Sha256Engine,
|
||||
|
@ -594,7 +594,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, OM: Deref, L: Deref> PeerManager<D
|
|||
/// minute should suffice.
|
||||
///
|
||||
/// (C-not exported) as we can't export a PeerManager with a dummy route handler
|
||||
pub fn new_channel_only(channel_message_handler: CM, onion_message_handler: OM, our_node_secret: SecretKey, current_time: u64, ephemeral_random_data: &[u8; 32], logger: L) -> Self {
|
||||
pub fn new_channel_only(channel_message_handler: CM, onion_message_handler: OM, our_node_secret: SecretKey, current_time: u32, ephemeral_random_data: &[u8; 32], logger: L) -> Self {
|
||||
Self::new(MessageHandler {
|
||||
chan_handler: channel_message_handler,
|
||||
route_handler: IgnoringMessageHandler{},
|
||||
|
@ -620,7 +620,7 @@ impl<Descriptor: SocketDescriptor, RM: Deref, L: Deref> PeerManager<Descriptor,
|
|||
/// cryptographically secure random bytes.
|
||||
///
|
||||
/// (C-not exported) as we can't export a PeerManager with a dummy channel handler
|
||||
pub fn new_routing_only(routing_message_handler: RM, our_node_secret: SecretKey, current_time: u64, ephemeral_random_data: &[u8; 32], logger: L) -> Self {
|
||||
pub fn new_routing_only(routing_message_handler: RM, our_node_secret: SecretKey, current_time: u32, ephemeral_random_data: &[u8; 32], logger: L) -> Self {
|
||||
Self::new(MessageHandler {
|
||||
chan_handler: ErroringMessageHandler::new(),
|
||||
route_handler: routing_message_handler,
|
||||
|
@ -684,7 +684,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
|
|||
/// incremented irregularly internally. In general it is best to simply use the current UNIX
|
||||
/// timestamp, however if it is not available a persistent counter that increases once per
|
||||
/// minute should suffice.
|
||||
pub fn new(message_handler: MessageHandler<CM, RM, OM>, our_node_secret: SecretKey, current_time: u64, ephemeral_random_data: &[u8; 32], logger: L, custom_message_handler: CMH) -> Self {
|
||||
pub fn new(message_handler: MessageHandler<CM, RM, OM>, our_node_secret: SecretKey, current_time: u32, ephemeral_random_data: &[u8; 32], logger: L, custom_message_handler: CMH) -> Self {
|
||||
let mut ephemeral_key_midstate = Sha256::engine();
|
||||
ephemeral_key_midstate.input(ephemeral_random_data);
|
||||
|
||||
|
@ -701,7 +701,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
|
|||
our_node_secret,
|
||||
ephemeral_key_midstate,
|
||||
peer_counter: AtomicCounter::new(),
|
||||
last_node_announcement_serial: AtomicU64::new(current_time),
|
||||
last_node_announcement_serial: AtomicU32::new(current_time),
|
||||
logger,
|
||||
custom_message_handler,
|
||||
secp_ctx,
|
||||
|
@ -2001,7 +2001,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
|
|||
.or(self.message_handler.onion_message_handler.provided_node_features());
|
||||
let announcement = msgs::UnsignedNodeAnnouncement {
|
||||
features,
|
||||
timestamp: self.last_node_announcement_serial.fetch_add(1, Ordering::AcqRel) as u32,
|
||||
timestamp: self.last_node_announcement_serial.fetch_add(1, Ordering::AcqRel),
|
||||
node_id: PublicKey::from_secret_key(&self.secp_ctx, &self.our_node_secret),
|
||||
rgb, alias, addresses,
|
||||
excess_address_data: Vec::new(),
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
#![no_std]
|
Loading…
Add table
Reference in a new issue