Skip to content

Commit

Permalink
fix: flush databases for RPC calls that mutate
Browse files Browse the repository at this point in the history
Calls GlobalState::flush_databases() for:

NeptuneRpcServer
 ::clear_all_standings()
 ::clear_standing_by_ip()
 ::send()
 ::prune_abandoned_monitored_utxos()
  • Loading branch information
dan-da committed Jan 16, 2024
1 parent 9b9ff2c commit 8032b8c
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/rpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,11 @@ impl RPC for NeptuneRPCServer {

// iterates and modifies standing field for all connected peers
global_state_mut.net.clear_all_standings_in_database().await;

global_state_mut
.flush_databases()
.await
.expect("flushed DBs");
}

/// Locking:
Expand All @@ -455,6 +460,11 @@ impl RPC for NeptuneRPCServer {

//Also clears this IP's standing in database, whether it is connected or not.
global_state_mut.net.clear_ip_standing_in_database(ip).await;

global_state_mut
.flush_databases()
.await
.expect("flushed DBs");
}

/// Locking:
Expand Down Expand Up @@ -542,6 +552,8 @@ impl RPC for NeptuneRPCServer {
.await;
}

self.state.flush_databases().await.expect("flushed DBs");

if response.is_ok() {
Some(Hash::hash(&transaction))
} else {
Expand Down Expand Up @@ -583,19 +595,24 @@ impl RPC for NeptuneRPCServer {
}

async fn prune_abandoned_monitored_utxos(self, _context: tarpc::context::Context) -> usize {
let state = self.state.lock_guard().await;
let tip_block_header = state.chain.light_state().header();
let mut global_state_mut = self.state.lock_guard_mut().await;
let tip_block_header = global_state_mut.chain.light_state().header();
const DEFAULT_MUTXO_PRUNE_DEPTH: usize = 200;

let prune_count_res = state
let prune_count_res = global_state_mut
.wallet_state
.prune_abandoned_monitored_utxos(
DEFAULT_MUTXO_PRUNE_DEPTH,
tip_block_header,
state.chain.archival_state(),
global_state_mut.chain.archival_state(),
)
.await;

global_state_mut
.flush_databases()
.await
.expect("flushed DBs");

match prune_count_res {
Ok(prune_count) => {
info!("Marked {prune_count} monitored UTXOs as abandoned");
Expand Down

0 comments on commit 8032b8c

Please sign in to comment.