Skip to content

Commit

Permalink
f Account for BestBlock dropping accessor methods
Browse files Browse the repository at this point in the history
  • Loading branch information
tnull committed Mar 25, 2024
1 parent 2a1bca7 commit f775599
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ where
let confirmation_target = ConfirmationTarget::NonAnchorChannelFee;

// We set nLockTime to the current height to discourage fee sniping.
let cur_height = self.channel_manager.current_best_block().height();
let cur_height = self.channel_manager.current_best_block().height;
let locktime = LockTime::from_height(cur_height).unwrap_or(LockTime::ZERO);

// Sign the final funding transaction and broadcast it.
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub use error::Error as NodeError;
use error::Error;

pub use event::Event;
pub use types::{BestBlock, ChannelConfig};
pub use types::ChannelConfig;

pub use io::utils::generate_entropy_mnemonic;

Expand Down Expand Up @@ -138,7 +138,7 @@ pub use types::{ChannelDetails, PeerDetails, UserChannelId};

use logger::{log_error, log_info, log_trace, FilesystemLogger, Logger};

use lightning::chain::Confirm;
use lightning::chain::{BestBlock, Confirm};
use lightning::ln::channelmanager::{self, PaymentId, RecipientOnionFields, Retry};
use lightning::ln::msgs::SocketAddress;
use lightning::ln::{PaymentHash, PaymentPreimage};
Expand Down
12 changes: 6 additions & 6 deletions src/sweep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ where
fn rebroadcast_if_necessary(&self) {
let (cur_height, cur_hash) = {
let best_block = self.best_block.lock().unwrap();
(best_block.height(), best_block.block_hash())
(best_block.height, best_block.block_hash)
};

let mut respend_descriptors = Vec::new();
Expand Down Expand Up @@ -277,7 +277,7 @@ where
}

fn prune_confirmed_outputs(&self) {
let cur_height = self.best_block.lock().unwrap().height();
let cur_height = self.best_block.lock().unwrap().height;
let mut locked_outputs = self.outputs.lock().unwrap();

// Prune all outputs that have sufficient depth by now.
Expand Down Expand Up @@ -370,9 +370,9 @@ where
) {
{
let best_block = self.best_block.lock().unwrap();
assert_eq!(best_block.block_hash(), header.prev_blockhash,
assert_eq!(best_block.block_hash, header.prev_blockhash,
"Blocks must be connected in chain-order - the connected header must build on the last connected header");
assert_eq!(best_block.height(), height - 1,
assert_eq!(best_block.height, height - 1,
"Blocks must be connected in chain-order - the connected block height must be one greater than the previous height");
}

Expand All @@ -384,9 +384,9 @@ where
let new_height = height - 1;
{
let mut best_block = self.best_block.lock().unwrap();
assert_eq!(best_block.block_hash(), header.block_hash(),
assert_eq!(best_block.block_hash, header.block_hash(),
"Blocks must be disconnected in chain-order - the disconnected header must be the last connected header");
assert_eq!(best_block.height(), height,
assert_eq!(best_block.height, height,
"Blocks must be disconnected in chain-order - the disconnected block must have the correct height");
*best_block = BestBlock::new(header.prev_blockhash, new_height)
}
Expand Down
20 changes: 1 addition & 19 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::sweep::OutputSweeper;

use lightning::blinded_path::BlindedPath;
use lightning::chain::chainmonitor;
use lightning::chain::BestBlock as LdkBestBlock;
use lightning::ln::channelmanager::ChannelDetails as LdkChannelDetails;
use lightning::ln::msgs::RoutingMessageHandler;
use lightning::ln::msgs::SocketAddress;
Expand All @@ -21,7 +20,7 @@ use lightning_net_tokio::SocketDescriptor;
use lightning_transaction_sync::EsploraSyncClient;

use bitcoin::secp256k1::{self, PublicKey, Secp256k1};
use bitcoin::{BlockHash, OutPoint};
use bitcoin::OutPoint;

use std::sync::{Arc, Mutex, RwLock};

Expand Down Expand Up @@ -454,20 +453,3 @@ impl Default for ChannelConfig {
LdkChannelConfig::default().into()
}
}

/// The best known block as identified by its hash and height.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BestBlock {
/// The block's hash
pub block_hash: BlockHash,
/// The height at which the block was confirmed.
pub height: u32,
}

impl From<LdkBestBlock> for BestBlock {
fn from(value: LdkBestBlock) -> Self {
let block_hash = value.block_hash();
let height = value.height();
Self { block_hash, height }
}
}

0 comments on commit f775599

Please sign in to comment.