Skip to content

Commit ac6997a

Browse files
authored
fix: wallet clear short term output (#6151)
Description --- This will clear short term encumbered outputs on startup Motivation and Context --- Its possible that the wallet if stopped at the right(wrong) moment it can leave encumbered outputs locked forever. This will cause the wallet to reset these outputs on startup, as they should only be encumbered for a short while. They will then be passed on to the validation task to revalidate them. How Has This Been Tested? --- manual
1 parent feb634c commit ac6997a

File tree

9 files changed

+18
-16
lines changed

9 files changed

+18
-16
lines changed

base_layer/wallet/src/output_manager_service/service.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ where
171171
let mut base_node_service_event_stream = self.base_node_service.get_event_stream();
172172

173173
debug!(target: LOG_TARGET, "Output Manager Service started");
174+
// Outputs marked as shorttermencumbered are not yet stored as transactions in the TMS, so lets clear them
175+
self.resources.db.clear_short_term_encumberances()?;
174176
loop {
175177
tokio::select! {
176178
event = base_node_service_event_stream.recv() => {

base_layer/wallet/tests/output_manager_service_tests/service.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,14 +1157,14 @@ async fn sending_transaction_persisted_while_offline() {
11571157
assert_eq!(balance.pending_outgoing_balance, available_balance / 2);
11581158

11591159
// This simulates an offline wallet with a queued transaction that has not been sent to the receiving wallet
1160-
// yet
1160+
// This should be cleared as the transaction will be dropped.
11611161
drop(oms.output_manager_handle);
11621162
let mut oms = setup_output_manager_service(backend.clone(), true).await;
11631163

11641164
let balance = oms.output_manager_handle.get_balance().await.unwrap();
1165-
assert_eq!(balance.available_balance, available_balance / 2);
1165+
assert_eq!(balance.available_balance, available_balance);
11661166
assert_eq!(balance.time_locked_balance.unwrap(), MicroMinotari::from(0));
1167-
assert_eq!(balance.pending_outgoing_balance, available_balance / 2);
1167+
assert_eq!(balance.pending_outgoing_balance, MicroMinotari::from(0));
11681168

11691169
// Check that is the pending tx is confirmed that the encumberance persists after restart
11701170
let stp = oms
@@ -1193,9 +1193,9 @@ async fn sending_transaction_persisted_while_offline() {
11931193
let mut oms = setup_output_manager_service(backend, true).await;
11941194

11951195
let balance = oms.output_manager_handle.get_balance().await.unwrap();
1196-
assert_eq!(balance.available_balance, MicroMinotari::from(0));
1196+
assert_eq!(balance.available_balance, MicroMinotari::from(10000));
11971197
assert_eq!(balance.time_locked_balance.unwrap(), MicroMinotari::from(0));
1198-
assert_eq!(balance.pending_outgoing_balance, available_balance);
1198+
assert_eq!(balance.pending_outgoing_balance, MicroMinotari::from(10000));
11991199
}
12001200

12011201
#[tokio::test]

base_layer/wallet_ffi/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6309,7 +6309,7 @@ pub unsafe extern "C" fn wallet_verify_message_signature(
63096309
/// # Safety
63106310
/// None
63116311
#[no_mangle]
6312-
pub unsafe extern "C" fn wallet_add_base_node_peer(
6312+
pub unsafe extern "C" fn wallet_set_base_node_peer(
63136313
wallet: *mut TariWallet,
63146314
public_key: *mut TariPublicKey,
63156315
address: *const c_char,
@@ -11032,7 +11032,7 @@ mod test {
1103211032
let base_node_peer_address_ptr =
1103311033
CString::into_raw(CString::new(node_identity.first_public_address().unwrap().to_string()).unwrap())
1103411034
as *const c_char;
11035-
wallet_add_base_node_peer(
11035+
wallet_set_base_node_peer(
1103611036
wallet_ptr,
1103711037
base_node_peer_public_key_ptr,
1103811038
base_node_peer_address_ptr,
@@ -11340,7 +11340,7 @@ mod test {
1134011340
let bob_peer_address_ptr =
1134111341
CString::into_raw(CString::new(bob_node_identity.first_public_address().unwrap().to_string()).unwrap())
1134211342
as *const c_char;
11343-
wallet_add_base_node_peer(
11343+
wallet_set_base_node_peer(
1134411344
alice_wallet_ptr,
1134511345
bob_peer_public_key_ptr,
1134611346
bob_peer_address_ptr,
@@ -11355,7 +11355,7 @@ mod test {
1135511355
let alice_peer_address_ptr = CString::into_raw(
1135611356
CString::new(alice_node_identity.first_public_address().unwrap().to_string()).unwrap(),
1135711357
) as *const c_char;
11358-
wallet_add_base_node_peer(
11358+
wallet_set_base_node_peer(
1135911359
bob_wallet_ptr,
1136011360
alice_peer_public_key_ptr,
1136111361
alice_peer_address_ptr,

base_layer/wallet_ffi/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2994,7 +2994,7 @@ bool wallet_verify_message_signature(struct TariWallet *wallet,
29942994
* # Safety
29952995
* None
29962996
*/
2997-
bool wallet_add_base_node_peer(struct TariWallet *wallet,
2997+
bool wallet_set_base_node_peer(struct TariWallet *wallet,
29982998
TariPublicKey *public_key,
29992999
const char *address,
30003000
int *error_out);

clients/ffi_client/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ try {
200200
let publicKey = lib.public_key_create(publicKeyByteVector, err);
201201

202202
console.log("Set base node peer...", publicKeyHex);
203-
lib.wallet_add_base_node_peer(
203+
lib.wallet_set_base_node_peer(
204204
wallet,
205205
publicKey,
206206
"/onion3/2m2xnylrsqbaozsndkbmfisxxbwh2vgvs6oyfak2qah4snnxykrf7zad:18141",

clients/ffi_client/lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const libWallet = ffi.Library("./libminotari_wallet_ffi.dylib", {
4444
transportRef,
4545
["string", u8ArrayPtr, u16, "string", "string", errPtr],
4646
],
47-
wallet_add_base_node_peer: [bool, [walletRef, u8ArrayPtr, "string", errPtr]],
47+
wallet_set_base_node_peer: [bool, [walletRef, u8ArrayPtr, "string", errPtr]],
4848
wallet_create: [
4949
walletRef,
5050
[

clients/ffi_client/recovery.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ try {
186186
let publicKey = lib.public_key_create(publicKeyByteVector, err);
187187

188188
console.log("Set base node peer...", publicKeyHex);
189-
lib.wallet_add_base_node_peer(
189+
lib.wallet_set_base_node_peer(
190190
wallet,
191191
publicKey,
192192
"/onion3/2m2xnylrsqbaozsndkbmfisxxbwh2vgvs6oyfak2qah4snnxykrf7zad:18141",

integration_tests/src/ffi/ffi_import.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ extern "C" {
451451
msg: *const c_char,
452452
error_out: *mut c_int,
453453
) -> bool;
454-
pub fn wallet_add_base_node_peer(
454+
pub fn wallet_set_base_node_peer(
455455
wallet: *mut TariWallet,
456456
public_key: *mut TariPublicKey,
457457
address: *const c_char,

integration_tests/src/ffi/wallet.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,14 @@ impl Wallet {
235235
let mut error = 0;
236236
let success;
237237
unsafe {
238-
success = ffi_import::wallet_add_base_node_peer(
238+
success = ffi_import::wallet_set_base_node_peer(
239239
self.ptr,
240240
base_node.get_ptr(),
241241
CString::new(address).unwrap().into_raw(),
242242
&mut error,
243243
);
244244
if error > 0 {
245-
println!("wallet_add_base_node_peer error {}", error);
245+
println!("wallet_set_base_node_peer error {}", error);
246246
}
247247
}
248248
success

0 commit comments

Comments
 (0)