Skip to content

Commit 3e1b9c6

Browse files
committed
fix pipeline
1 parent 4d825bd commit 3e1b9c6

12 files changed

Lines changed: 102 additions & 70 deletions

File tree

src/core_types.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ pub(crate) struct ExternalKeySource {
8080
}
8181

8282
#[derive(Clone)]
83+
#[allow(clippy::large_enum_variant)]
8384
pub(crate) enum NodeKeySource {
8485
InternalMnemonic(Mnemonic),
8586
#[allow(dead_code)]

src/rgb_kv_store.rs

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ use rgb_lib::ContractId;
1313

1414
pub(crate) const RGB_PRIMARY_NS: &str = "rgb";
1515
pub(crate) const RGB_CHANNEL_INFO_NS: &str = "channel_info";
16+
pub(crate) const RGB_CHANNEL_INFO_PENDING_NS: &str = "channel_info_pending";
1617
pub(crate) const RGB_PAYMENT_INFO_INBOUND_NS: &str = "payment_info_inbound";
1718
pub(crate) const RGB_PAYMENT_INFO_OUTBOUND_NS: &str = "payment_info_outbound";
1819
pub(crate) const RGB_TRANSFER_INFO_NS: &str = "transfer_info";
1920
pub(crate) const RGB_CONSIGNMENT_NS: &str = "consignment";
21+
pub(crate) const RGB_WALLET_CONFIG_NS: &str = "wallet_config";
2022

2123
pub(crate) trait RgbKvStoreExt {
2224
fn write_config(&self, key: &str, value: &str);
@@ -39,18 +41,14 @@ pub(crate) trait RgbKvStoreExt {
3941
fn remove_rgb_consignment(&self, txid: &str) -> Result<(), io::Error>;
4042
}
4143

42-
fn pending_suffix(pending: bool) -> &'static str {
44+
fn channel_namespace(pending: bool) -> &'static str {
4345
if pending {
44-
"pending"
46+
RGB_CHANNEL_INFO_PENDING_NS
4547
} else {
46-
"final"
48+
RGB_CHANNEL_INFO_NS
4749
}
4850
}
4951

50-
fn channel_key(channel_id: &str, pending: bool) -> String {
51-
format!("{channel_id}:{}", pending_suffix(pending))
52-
}
53-
5452
fn payment_key(payment_hash: &PaymentHash, pending: bool) -> String {
5553
let hash = payment_hash.0.as_hex().to_string();
5654
if pending {
@@ -62,29 +60,29 @@ fn payment_key(payment_hash: &PaymentHash, pending: bool) -> String {
6260

6361
impl<T: KVStoreSync + ?Sized> RgbKvStoreExt for T {
6462
fn write_config(&self, key: &str, value: &str) {
65-
let _ = self.write("", "", key, value.as_bytes().to_vec());
63+
let _ = self.write(
64+
RGB_PRIMARY_NS,
65+
RGB_WALLET_CONFIG_NS,
66+
key,
67+
value.as_bytes().to_vec(),
68+
);
6669
}
6770

6871
fn read_rgb_channel_info(&self, channel_id: &str, pending: bool) -> Result<RgbInfo, io::Error> {
69-
let key = channel_key(channel_id, pending);
70-
let bytes = self.read(RGB_PRIMARY_NS, RGB_CHANNEL_INFO_NS, &key)?;
71-
serde_json::from_slice(&bytes).map_err(|e| {
72-
io::Error::new(
73-
io::ErrorKind::InvalidData,
74-
format!("invalid RGB channel info: {e}"),
75-
)
76-
})
72+
let namespace = channel_namespace(pending);
73+
let bytes = self.read(RGB_PRIMARY_NS, namespace, channel_id)?;
74+
bincode::deserialize(&bytes).map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
7775
}
7876

7977
fn write_rgb_channel_info(&self, channel_id: &str, rgb_info: &RgbInfo, pending: bool) {
80-
let key = channel_key(channel_id, pending);
81-
let bytes = serde_json::to_vec(rgb_info).expect("valid RGB channel info");
82-
let _ = self.write(RGB_PRIMARY_NS, RGB_CHANNEL_INFO_NS, &key, bytes);
78+
let namespace = channel_namespace(pending);
79+
let bytes = bincode::serialize(rgb_info).expect("valid RGB channel info");
80+
let _ = self.write(RGB_PRIMARY_NS, namespace, channel_id, bytes);
8381
}
8482

8583
fn remove_rgb_channel_info(&self, channel_id: &str, pending: bool) -> Result<(), io::Error> {
86-
let key = channel_key(channel_id, pending);
87-
self.remove(RGB_PRIMARY_NS, RGB_CHANNEL_INFO_NS, &key, false)
84+
let namespace = channel_namespace(pending);
85+
self.remove(RGB_PRIMARY_NS, namespace, channel_id, false)
8886
}
8987

9088
fn read_rgb_payment_info(
@@ -99,12 +97,7 @@ impl<T: KVStoreSync + ?Sized> RgbKvStoreExt for T {
9997
};
10098
let key = payment_key(payment_hash, false);
10199
let bytes = self.read(RGB_PRIMARY_NS, ns, &key)?;
102-
serde_json::from_slice(&bytes).map_err(|e| {
103-
io::Error::new(
104-
io::ErrorKind::InvalidData,
105-
format!("invalid RGB payment info: {e}"),
106-
)
107-
})
100+
bincode::deserialize(&bytes).map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
108101
}
109102

110103
fn write_rgb_payment_info(
@@ -119,23 +112,14 @@ impl<T: KVStoreSync + ?Sized> RgbKvStoreExt for T {
119112
RGB_PAYMENT_INFO_OUTBOUND_NS
120113
};
121114
let key = payment_key(payment_hash, pending);
122-
let bytes = serde_json::to_vec(payment_info).map_err(|e| {
123-
io::Error::new(
124-
io::ErrorKind::InvalidData,
125-
format!("invalid RGB payment info: {e}"),
126-
)
127-
})?;
115+
let bytes = bincode::serialize(payment_info)
116+
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;
128117
self.write(RGB_PRIMARY_NS, ns, &key, bytes)
129118
}
130119

131120
fn read_rgb_transfer_info(&self, txid: &str) -> Result<TransferInfo, io::Error> {
132121
let bytes = self.read(RGB_PRIMARY_NS, RGB_TRANSFER_INFO_NS, txid)?;
133-
serde_json::from_slice(&bytes).map_err(|e| {
134-
io::Error::new(
135-
io::ErrorKind::InvalidData,
136-
format!("invalid RGB transfer info: {e}"),
137-
)
138-
})
122+
bincode::deserialize(&bytes).map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
139123
}
140124

141125
fn read_rgb_consignment(&self, txid: &str) -> Result<Vec<u8>, io::Error> {

src/routes.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4405,8 +4405,16 @@ pub(crate) async fn send_rgb(
44054405
})
44064406
.await
44074407
.unwrap()?;
4408-
let signed_psbt = unlocked_state.rgb_sign_psbt(begin_result.psbt)?;
4409-
unlocked_state.rgb_send_end(signed_psbt)?
4408+
let unlocked_state_copy = unlocked_state.clone();
4409+
let signed_psbt = tokio::task::spawn_blocking(move || {
4410+
unlocked_state_copy.rgb_sign_psbt(begin_result.psbt)
4411+
})
4412+
.await
4413+
.unwrap()?;
4414+
let unlocked_state_copy = unlocked_state.clone();
4415+
tokio::task::spawn_blocking(move || unlocked_state_copy.rgb_send_end(signed_psbt))
4416+
.await
4417+
.unwrap()?
44104418
};
44114419

44124420
Ok(Json(SendRgbResponse {

src/sdk/mod.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,8 +1600,16 @@ pub(crate) async fn send_rgb(
16001600
})
16011601
.await
16021602
.unwrap()?;
1603-
let signed_psbt = unlocked_state.rgb_sign_psbt(begin_result.psbt)?;
1604-
unlocked_state.rgb_send_end(signed_psbt)?
1603+
let unlocked_state_copy = unlocked_state.clone();
1604+
let signed_psbt = tokio::task::spawn_blocking(move || {
1605+
unlocked_state_copy.rgb_sign_psbt(begin_result.psbt)
1606+
})
1607+
.await
1608+
.unwrap()?;
1609+
let unlocked_state_copy = unlocked_state.clone();
1610+
tokio::task::spawn_blocking(move || unlocked_state_copy.rgb_send_end(signed_psbt))
1611+
.await
1612+
.unwrap()?
16051613
};
16061614

16071615
Ok(SendRgbData {
@@ -4011,6 +4019,8 @@ mod tests {
40114019
max_media_upload_size_mb: 1,
40124020
enable_virtual_channels_v0: false,
40134021
virtual_peer_pubkeys: vec![],
4022+
lsp_base_url: None,
4023+
lsp_bearer_token: None,
40144024
database: Arc::new(database),
40154025
}),
40164026
cancel_token: CancellationToken::new(),

src/signer/external.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ impl NodeSigner for ExternalSigner {
191191
};
192192
let bytes = Vec::<u8>::from_hex(&shared_secret_hex).map_err(|_| ())?;
193193
let arr: [u8; 32] = bytes.try_into().map_err(|_| ())?;
194-
Ok(SharedSecret::from_slice(&arr).map_err(|_| ())?)
194+
SharedSecret::from_slice(&arr).map_err(|_| ())
195195
}
196196

197197
fn sign_invoice(

src/signer/key_source.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ fn write_restricted_file(path: &Path, bytes: &[u8]) -> Result<(), RlnSignerError
8484
file.sync_all().map_err(|e| {
8585
RlnSignerError::Protocol(format!("failed to sync key source file: {e}"))
8686
})?;
87-
return Ok(());
87+
Ok(())
8888
}
8989

9090
#[cfg(not(unix))]

src/test/lib_sdk/close_force_standard.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ fn close_force_standard() {
5454
})
5555
.expect("node A issueassetnia")
5656
.asset_id;
57+
assert_eq!(
58+
wait_for_asset_balance(&node_a, &asset_id, Duration::from_secs(30)).spendable,
59+
1_000
60+
);
5761

5862
let node_a_pubkey = node_a.node_info().expect("node A node_info").pubkey;
5963
let node_b_pubkey = node_b.node_info().expect("node B node_info").pubkey;

src/test/lib_sdk/external_signer.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ use serial_test::serial;
66
use std::fs;
77
use std::sync::atomic::{AtomicBool, Ordering};
88
use std::sync::{Arc, Mutex, OnceLock};
9+
#[cfg(feature = "vls")]
910
use std::thread;
11+
#[cfg(feature = "vls")]
1012
use std::time::Duration;
1113

1214
const NODE_ID_HEX: &str = "0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798";
@@ -209,6 +211,7 @@ fn test_bootstrap() -> SdkExternalSignerBootstrap {
209211
}
210212
}
211213

214+
#[cfg(feature = "vls")]
212215
fn make_native_signer(seed_byte: u8) -> Arc<rgb_lightning_node::NativeExternalSigner> {
213216
rgb_lightning_node::NativeExternalSigner::new(
214217
format!("{seed_byte:02x}").repeat(32),
@@ -311,6 +314,7 @@ fn mock_response(req: &Value, bootstrap: &SdkExternalSignerBootstrap) -> Value {
311314
json!({"Node": {"RandomBytes": {"bytes_hex": "ab".repeat(32)}}})
312315
}
313316

317+
#[cfg(feature = "vls")]
314318
#[test]
315319
#[serial]
316320
fn external_init_unlock_and_restart_same_signer() {
@@ -374,6 +378,7 @@ fn external_init_unlock_and_restart_same_signer() {
374378
}
375379
}
376380

381+
#[cfg(feature = "vls")]
377382
#[test]
378383
#[serial]
379384
fn external_restart_with_mismatched_signer_fails_unlock() {

src/test/lib_sdk/helpers.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ pub(crate) fn wait_for_usable_channel(
432432
Instant::now() < deadline,
433433
"timeout waiting for usable channel"
434434
);
435-
if polls % 5 == 0 {
435+
if polls.is_multiple_of(5) {
436436
mine(1);
437437
}
438438
sleep(Duration::from_secs(2));
@@ -549,7 +549,7 @@ pub(crate) fn wait_for_usable_channel_counts(nodes: &[(&SdkNode, usize)], timeou
549549
Instant::now() < deadline,
550550
"usable channel counts did not reach expected values in time"
551551
);
552-
if polls % 5 == 0 {
552+
if polls.is_multiple_of(5) {
553553
mine(1);
554554
}
555555
sleep(Duration::from_secs(1));
@@ -630,6 +630,8 @@ pub(crate) fn wait_for_balance(
630630
) {
631631
let deadline = Instant::now() + timeout;
632632
loop {
633+
node.sync()
634+
.expect("node sync while waiting for spendable balance");
633635
let balance = asset_balance_spendable(node, asset_id);
634636
if balance == expected_balance {
635637
return;
@@ -823,7 +825,18 @@ pub(crate) fn close_channel_with_force(
823825
.iter()
824826
.any(|channel| channel.channel_id == channel_id)
825827
{
826-
mine_blocks(true, if force { 144 } else { 6 });
828+
if force {
829+
// Force-close settlement needs the CSV delay to elapse before the sweep
830+
// transaction is broadcast. Mine a short tail of extra blocks so the
831+
// delayed sweep reliably gets confirmed before balance assertions run.
832+
mine_blocks(true, 144);
833+
for _ in 0..6 {
834+
sleep(Duration::from_secs(1));
835+
mine(1);
836+
}
837+
} else {
838+
mine_blocks(true, 6);
839+
}
827840
return;
828841
}
829842
assert!(Instant::now() < deadline, "channel did not close in time");

src/test/lib_sdk/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#![allow(clippy::clone_on_copy)]
2+
#![allow(clippy::too_many_arguments)]
3+
14
pub(crate) mod helpers;
25

36
mod close_coop_other_side;

0 commit comments

Comments
 (0)