Skip to content

Commit 8191947

Browse files
committed
Let KVStore::remove not return a bool
Previously, `KVStore::remove` would return a `bool` indicating whether the deleted data item was present. However, depending on the backend this might require additional calls to be made. Here we therefore drop the return value, as we don't use it anyways currently.
1 parent 36f2833 commit 8191947

File tree

7 files changed

+14
-20
lines changed

7 files changed

+14
-20
lines changed

bindings/ldk_node.udl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ interface LDKNode {
8181
Invoice receive_variable_amount_payment([ByRef]string description, u32 expiry_secs);
8282
PaymentDetails? payment([ByRef]PaymentHash payment_hash);
8383
[Throws=NodeError]
84-
boolean remove_payment([ByRef]PaymentHash payment_hash);
84+
void remove_payment([ByRef]PaymentHash payment_hash);
8585
sequence<PaymentDetails> list_payments();
8686
sequence<PeerDetails> list_peers();
8787
sequence<ChannelDetails> list_channels();

src/io/fs_store.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ impl KVStore for FilesystemStore {
136136
Ok(())
137137
}
138138

139-
fn remove(&self, namespace: &str, key: &str) -> std::io::Result<bool> {
139+
fn remove(&self, namespace: &str, key: &str) -> std::io::Result<()> {
140140
let mut outer_lock = self.locks.lock().unwrap();
141141
let lock_key = (namespace.to_string(), key.to_string());
142142
let inner_lock_ref = Arc::clone(&outer_lock.entry(lock_key.clone()).or_default());
@@ -148,7 +148,7 @@ impl KVStore for FilesystemStore {
148148
dest_file_path.push(key);
149149

150150
if !dest_file_path.is_file() {
151-
return Ok(false);
151+
return Ok(());
152152
}
153153

154154
fs::remove_file(&dest_file_path)?;
@@ -190,7 +190,7 @@ impl KVStore for FilesystemStore {
190190
// Garbage collect all lock entries that are not referenced anymore.
191191
outer_lock.retain(|_, v| Arc::strong_count(&v) > 1);
192192

193-
Ok(true)
193+
Ok(())
194194
}
195195

196196
fn list(&self, namespace: &str) -> std::io::Result<Vec<String>> {

src/io/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ pub trait KVStore: KVStorePersister {
6969
/// Will create the given `namespace` if not already present in the store.
7070
fn write(&self, namespace: &str, key: &str, buf: &[u8]) -> std::io::Result<()>;
7171
/// Removes any data that had previously been persisted under the given `key`.
72-
///
73-
/// Returns `true` if the `key` was present in the given `namespace`, and `false` otherwise.
74-
fn remove(&self, namespace: &str, key: &str) -> std::io::Result<bool>;
72+
fn remove(&self, namespace: &str, key: &str) -> std::io::Result<()>;
7573
/// Returns a list of keys that are stored under the given `namespace`.
7674
///
7775
/// Will return an empty list if the `namespace` is unknown.

src/io/sqlite_store.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ impl KVStore for SqliteStore {
116116
})
117117
}
118118

119-
fn remove(&self, namespace: &str, key: &str) -> std::io::Result<bool> {
119+
fn remove(&self, namespace: &str, key: &str) -> std::io::Result<()> {
120120
let locked_conn = self.connection.lock().unwrap();
121121

122122
let sql = format!("DELETE FROM {} WHERE namespace=:namespace AND key=:key;", KV_TABLE_NAME);
123-
let changes = locked_conn
123+
locked_conn
124124
.execute(
125125
&sql,
126126
named_params! {
@@ -132,10 +132,7 @@ impl KVStore for SqliteStore {
132132
let msg = format!("Failed to delete key {}/{}: {}", namespace, key, e);
133133
std::io::Error::new(std::io::ErrorKind::Other, msg)
134134
})?;
135-
136-
let was_present = changes != 0;
137-
138-
Ok(was_present)
135+
Ok(())
139136
}
140137

141138
fn list(&self, namespace: &str) -> std::io::Result<Vec<String>> {

src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,9 +1445,7 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
14451445
}
14461446

14471447
/// Remove the payment with the given hash from the store.
1448-
///
1449-
/// Returns `true` if the payment was present and `false` otherwise.
1450-
pub fn remove_payment(&self, payment_hash: &PaymentHash) -> Result<bool, Error> {
1448+
pub fn remove_payment(&self, payment_hash: &PaymentHash) -> Result<(), Error> {
14511449
self.payment_store.remove(&payment_hash)
14521450
}
14531451

src/payment_store.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ where
121121
Ok(updated)
122122
}
123123

124-
pub(crate) fn remove(&self, hash: &PaymentHash) -> Result<bool, Error> {
124+
pub(crate) fn remove(&self, hash: &PaymentHash) -> Result<(), Error> {
125125
let store_key = hex_utils::to_string(&hash.0);
126126
self.kv_store.remove(PAYMENT_INFO_PERSISTENCE_NAMESPACE, &store_key).map_err(|e| {
127127
log_error!(

src/test/utils.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,14 @@ impl KVStore for TestStore {
9696
Ok(())
9797
}
9898

99-
fn remove(&self, namespace: &str, key: &str) -> std::io::Result<bool> {
99+
fn remove(&self, namespace: &str, key: &str) -> std::io::Result<()> {
100100
match self.persisted_bytes.write().unwrap().entry(namespace.to_string()) {
101101
hash_map::Entry::Occupied(mut e) => {
102102
self.did_persist.store(true, Ordering::SeqCst);
103-
Ok(e.get_mut().remove(&key.to_string()).is_some())
103+
e.get_mut().remove(&key.to_string());
104+
Ok(())
104105
}
105-
hash_map::Entry::Vacant(_) => Ok(false),
106+
hash_map::Entry::Vacant(_) => Ok(()),
106107
}
107108
}
108109

0 commit comments

Comments
 (0)