Skip to content

Commit 8cb7b42

Browse files
committed
Pump up some deps
Needed to pump the lightning version used and had to pump bitcoin, bitcoincore-rpc aswell to match dep verions in lightining merkle root computation changed in `bitcoin`, thus some methods in the test_utils needed to adapt (basically by adding a tx if there is none in a block). See: rust-bitcoin/rust-bitcoin@b454cf8 Also SecretKey had it's `to_string` method removed, so TEOS now encodes its tower key using `secret_bytes()` and `from_slice()`. See: rust-bitcoin/rust-secp256k1#312
1 parent b7e88d4 commit 8cb7b42

File tree

9 files changed

+63
-32
lines changed

9 files changed

+63
-32
lines changed

teos-common/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ rand = "0.8.4"
1515
chacha20poly1305 = "0.8.0"
1616

1717
# Bitcoin and Lightning
18-
bitcoin = "0.28.1"
18+
bitcoin = "0.28.0"
1919
lightning = { git = "https://github.com/meryacine/rust-lightning", branch = "expose-tlv-macros" }

teos/Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ warp = "0.3.2"
3333
torut = "0.2.1"
3434

3535
# Bitcoin and Lightning
36-
bitcoin = { version = "0.27", features = [ "base64" ] }
37-
bitcoincore-rpc = "0.14.0"
38-
lightning = "0.0.105"
39-
lightning-net-tokio = "0.0.105"
40-
lightning-block-sync = { version = "0.0.105", features = [ "rpc-client" ] }
36+
bitcoin = { version = "0.28.0", features = [ "base64" ] }
37+
bitcoincore-rpc = "0.15.0"
38+
lightning = "0.0.108"#{ git = "https://github.com/meryacine/rust-lightning", branch = "expose-tlv-macros" }
39+
lightning-net-tokio = "0.0.108"
40+
lightning-block-sync = { version = "0.0.108", features = [ "rpc-client" ] }
4141

4242
# Local
4343
teos-common = { path = "../teos-common" }

teos/src/bitcoin_cli.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,31 +38,31 @@ pub struct BitcoindClient<'a> {
3838
impl BlockSource for &BitcoindClient<'_> {
3939
/// Gets a block header given its hash.
4040
fn get_header<'a>(
41-
&'a mut self,
41+
&'a self,
4242
header_hash: &'a BlockHash,
4343
height_hint: Option<u32>,
4444
) -> AsyncBlockSourceResult<'a, BlockHeaderData> {
4545
Box::pin(async move {
46-
let mut rpc = self.bitcoind_rpc_client.lock().await;
46+
let rpc = self.bitcoind_rpc_client.lock().await;
4747
rpc.get_header(header_hash, height_hint).await
4848
})
4949
}
5050

5151
/// Gets a block given its hash.
5252
fn get_block<'a>(
53-
&'a mut self,
53+
&'a self,
5454
header_hash: &'a BlockHash,
5555
) -> AsyncBlockSourceResult<'a, Block> {
5656
Box::pin(async move {
57-
let mut rpc = self.bitcoind_rpc_client.lock().await;
57+
let rpc = self.bitcoind_rpc_client.lock().await;
5858
rpc.get_block(header_hash).await
5959
})
6060
}
6161

6262
/// Get the best block known by our node.
63-
fn get_best_block(&mut self) -> AsyncBlockSourceResult<(BlockHash, Option<u32>)> {
63+
fn get_best_block(&self) -> AsyncBlockSourceResult<(BlockHash, Option<u32>)> {
6464
Box::pin(async move {
65-
let mut rpc = self.bitcoind_rpc_client.lock().await;
65+
let rpc = self.bitcoind_rpc_client.lock().await;
6666
rpc.get_best_block().await
6767
})
6868
}
@@ -108,14 +108,14 @@ impl<'a> BitcoindClient<'a> {
108108
pub async fn get_best_block_hash_and_height(
109109
&self,
110110
) -> Result<(BlockHash, Option<u32>), std::io::Error> {
111-
let mut rpc = self.bitcoind_rpc_client.lock().await;
111+
let rpc = self.bitcoind_rpc_client.lock().await;
112112
rpc.call_method::<(BlockHash, Option<u32>)>("getblockchaininfo", &[])
113113
.await
114114
}
115115

116116
/// Sends a transaction to the network.
117117
pub async fn send_raw_transaction(&self, raw_tx: &Transaction) -> Result<Txid, std::io::Error> {
118-
let mut rpc = self.bitcoind_rpc_client.lock().await;
118+
let rpc = self.bitcoind_rpc_client.lock().await;
119119

120120
let raw_tx_json = serde_json::json!(raw_tx.encode().to_hex());
121121
rpc.call_method::<Txid>("sendrawtransaction", &[raw_tx_json])
@@ -124,7 +124,7 @@ impl<'a> BitcoindClient<'a> {
124124

125125
/// Gets a transaction given its id.
126126
pub async fn get_raw_transaction(&self, txid: &Txid) -> Result<Transaction, std::io::Error> {
127-
let mut rpc = self.bitcoind_rpc_client.lock().await;
127+
let rpc = self.bitcoind_rpc_client.lock().await;
128128

129129
let txid_hex = serde_json::json!(txid.encode().to_hex());
130130
rpc.call_method::<Transaction>("getrawtransaction", &[txid_hex])

teos/src/chain_monitor.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ where
2222
P: Poll,
2323
C: Cache,
2424
L: Deref,
25-
L::Target: chain::Listen,
25+
<L as Deref>::Target: chain::Listen,
2626
{
2727
/// A bitcoin client to poll best tips from.
2828
spv_client: SpvClient<'a, P, C, L>,
@@ -43,7 +43,7 @@ where
4343
P: Poll,
4444
C: Cache,
4545
L: Deref,
46-
L::Target: chain::Listen,
46+
<L as Deref>::Target: chain::Listen,
4747
{
4848
/// Creates a new [ChainMonitor] instance.
4949
pub async fn new(
@@ -167,6 +167,10 @@ mod tests {
167167
.borrow_mut()
168168
.insert(header.block_hash());
169169
}
170+
171+
fn filtered_block_connected(&self, header: &bitcoin::BlockHeader, txdata: &chain::transaction::TransactionData, height: u32) {
172+
173+
}
170174
}
171175

172176
#[tokio::test]

teos/src/dbm.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
44
use std::collections::{HashMap, HashSet};
55
use std::path::PathBuf;
6-
use std::str::FromStr;
76

87
use rusqlite::ffi::{SQLITE_CONSTRAINT_FOREIGNKEY, SQLITE_CONSTRAINT_PRIMARYKEY};
98
use rusqlite::limits::Limit;
@@ -567,7 +566,8 @@ impl DBM {
567566
/// When a new key is generated, old keys are not overwritten but are not retrievable from the API either.
568567
pub fn store_tower_key(&self, sk: &SecretKey) -> Result<(), Error> {
569568
let query = "INSERT INTO keys (key) VALUES (?)";
570-
self.store_data(query, params![sk.to_string()])
569+
let sk_bytes = Vec::from(sk.secret_bytes());
570+
self.store_data(query, params![sk_bytes])
571571
}
572572

573573
/// Loads the last known tower secret key from the database.
@@ -583,8 +583,8 @@ impl DBM {
583583
.unwrap();
584584

585585
stmt.query_row(["keys"], |row| {
586-
let sk: String = row.get(0).unwrap();
587-
Ok(SecretKey::from_str(&sk).unwrap())
586+
let sk: Vec<u8> = row.get(0).unwrap();
587+
Ok(SecretKey::from_slice(&sk).unwrap())
588588
})
589589
.map_err(|_| Error::NotFound)
590590
}
@@ -599,7 +599,7 @@ mod tests {
599599
get_random_tracker, get_random_user_id,
600600
};
601601
use std::iter::FromIterator;
602-
use teos_common::cryptography::get_random_bytes;
602+
use teos_common::cryptography::{get_random_bytes, get_random_keypair};
603603

604604
impl DBM {
605605
pub(crate) fn in_memory() -> Result<Self, SqliteError> {
@@ -1166,4 +1166,16 @@ mod tests {
11661166

11671167
assert!(matches!(dbm.load_last_known_block(), Err(Error::NotFound)));
11681168
}
1169+
1170+
#[test]
1171+
fn test_store_load_tower_key() {
1172+
let dbm = DBM::in_memory().unwrap();
1173+
1174+
assert!(matches!(dbm.load_tower_key(), Err(Error::NotFound)));
1175+
for _ in 0..7 {
1176+
let sk = get_random_keypair().0;
1177+
dbm.store_tower_key(&sk).unwrap();
1178+
assert_eq!(dbm.load_tower_key().unwrap(), sk);
1179+
}
1180+
}
11691181
}

teos/src/gatekeeper.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,10 @@ impl chain::Listen for Gatekeeper {
327327
self.last_known_block_height
328328
.store(height - 1, Ordering::Release);
329329
}
330+
331+
fn filtered_block_connected(&self, header: &bitcoin::BlockHeader, txdata: &chain::transaction::TransactionData, height: u32) {
332+
333+
}
330334
}
331335

332336
#[cfg(test)]

teos/src/responder.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,10 @@ impl chain::Listen for Responder {
557557
}
558558
}
559559
}
560+
561+
fn filtered_block_connected(&self, header: &BlockHeader, txdata: &chain::transaction::TransactionData, height: u32) {
562+
563+
}
560564
}
561565

562566
#[cfg(test)]

teos/src/test_utils.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use bitcoin::blockdata::block::{Block, BlockHeader};
2323
use bitcoin::blockdata::constants::genesis_block;
2424
use bitcoin::blockdata::script::{Builder, Script};
2525
use bitcoin::blockdata::transaction::{OutPoint, Transaction, TxIn, TxOut};
26-
use bitcoin::consensus;
26+
use bitcoin::{consensus, Witness};
2727
use bitcoin::hash_types::BlockHash;
2828
use bitcoin::hash_types::Txid;
2929
use bitcoin::hashes::hex::FromHex;
@@ -89,16 +89,19 @@ impl Blockchain {
8989
let prev_block = &self.blocks[i - 1];
9090
let prev_blockhash = prev_block.block_hash();
9191
let time = prev_block.header.time + height as u32;
92+
let txdata = vec![get_random_tx()];
93+
let hashes = txdata.iter().map(|obj| obj.txid().as_hash());
94+
9295
self.blocks.push(Block {
9396
header: BlockHeader {
9497
version: 0,
9598
prev_blockhash,
96-
merkle_root: Default::default(),
99+
merkle_root: bitcoin_merkle_root(hashes).unwrap().into(),
97100
time,
98101
bits,
99102
nonce: 0,
100103
},
101-
txdata: vec![],
104+
txdata,
102105
});
103106
}
104107
self
@@ -204,15 +207,15 @@ impl Blockchain {
204207
let time = prev_block.header.time + (self.blocks.len() + 1) as u32;
205208
let txdata = match txs {
206209
Some(t) => t,
207-
None => vec![],
210+
None => vec![get_random_tx()],
208211
};
209212
let hashes = txdata.iter().map(|obj| obj.txid().as_hash());
210213

211214
let block = Block {
212215
header: BlockHeader {
213216
version: 0,
214217
prev_blockhash,
215-
merkle_root: bitcoin_merkle_root(hashes).into(),
218+
merkle_root: bitcoin_merkle_root(hashes).unwrap().into(),
216219
time,
217220
bits,
218221
nonce: 0,
@@ -228,7 +231,7 @@ impl Blockchain {
228231

229232
impl BlockSource for Blockchain {
230233
fn get_header<'a>(
231-
&'a mut self,
234+
&'a self,
232235
header_hash: &'a BlockHash,
233236
_height_hint: Option<u32>,
234237
) -> AsyncBlockSourceResult<'a, BlockHeaderData> {
@@ -252,7 +255,7 @@ impl BlockSource for Blockchain {
252255
}
253256

254257
fn get_block<'a>(
255-
&'a mut self,
258+
&'a self,
256259
header_hash: &'a BlockHash,
257260
) -> AsyncBlockSourceResult<'a, Block> {
258261
Box::pin(async move {
@@ -271,7 +274,7 @@ impl BlockSource for Blockchain {
271274
})
272275
}
273276

274-
fn get_best_block(&mut self) -> AsyncBlockSourceResult<(BlockHash, Option<u32>)> {
277+
fn get_best_block(&self) -> AsyncBlockSourceResult<(BlockHash, Option<u32>)> {
275278
Box::pin(async move {
276279
if *self.unreachable.lock().unwrap() {
277280
return Err(BlockSourceError::transient("Connection refused"));
@@ -312,7 +315,7 @@ pub(crate) fn get_random_tx() -> Transaction {
312315
rng.gen_range(0..200),
313316
),
314317
script_sig: Script::new(),
315-
witness: Vec::new(),
318+
witness: Witness::new(),
316319
sequence: 0,
317320
}],
318321
output: vec![TxOut {
@@ -384,7 +387,7 @@ pub(crate) fn store_appointment_and_fks_to_db(
384387

385388
pub(crate) async fn get_last_n_blocks(chain: &mut Blockchain, n: usize) -> Vec<ValidatedBlock> {
386389
let tip = chain.tip();
387-
let mut poller = ChainPoller::new(chain, Network::Bitcoin);
390+
let poller = ChainPoller::new(chain, Network::Bitcoin);
388391

389392
let mut last_n_blocks = Vec::new();
390393
let mut last_known_block = tip;

teos/src/watcher.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,10 @@ impl chain::Listen for Watcher {
861861
self.last_known_block_height
862862
.store(height - 1, Ordering::Release);
863863
}
864+
865+
fn filtered_block_connected(&self, header: &BlockHeader, txdata: &chain::transaction::TransactionData, height: u32) {
866+
867+
}
864868
}
865869

866870
#[cfg(test)]

0 commit comments

Comments
 (0)