Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions components/addressmanager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,11 @@ impl AddressManager {
pub fn get_all_banned_addresses(&self) -> Vec<IpAddress> {
self.banned_address_store.iterator().map(|x| IpAddress::from(x.unwrap().0)).collect_vec()
}

pub fn reset(&mut self) {
self.address_store.reset();
self.banned_address_store.reset().unwrap();
}
}

mod address_store_with_cache {
Expand Down Expand Up @@ -455,6 +460,11 @@ mod address_store_with_cache {
self.remove_by_key(key);
}
}

pub fn reset(&mut self) {
self.db_store.reset().unwrap();
self.addresses.clear();
}
}

pub fn new(db: Arc<DB>) -> Store {
Expand Down
5 changes: 5 additions & 0 deletions components/addressmanager/src/stores/address_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub trait AddressesStore: AddressesStoreReader {
#[allow(dead_code)]
fn set_failed_count(&mut self, key: AddressKey, connection_failed_count: u64) -> StoreResult<()>;
fn remove(&mut self, key: AddressKey) -> StoreResult<()>;
fn reset(&mut self) -> StoreResult<()>;
}

const IPV6_LEN: usize = 16;
Expand Down Expand Up @@ -117,4 +118,8 @@ impl AddressesStore for DbAddressesStore {
let entry = self.get(key)?;
self.set(key, Entry { connection_failed_count, address: entry.address })
}

fn reset(&mut self) -> StoreResult<()> {
self.access.delete_all(DirectDbWriter::new(&self.db))
}
}
5 changes: 5 additions & 0 deletions components/addressmanager/src/stores/banned_address_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub trait BannedAddressesStoreReader {
pub trait BannedAddressesStore: BannedAddressesStoreReader {
fn set(&mut self, ip: IpAddr, timestamp: ConnectionBanTimestamp) -> StoreResult<()>;
fn remove(&mut self, ip: IpAddr) -> StoreResult<()>;
fn reset(&mut self) -> StoreResult<()>;
}

const IPV6_LEN: usize = 16;
Expand Down Expand Up @@ -106,4 +107,8 @@ impl BannedAddressesStore for DbBannedAddressesStore {
fn remove(&mut self, ip: IpAddr) -> StoreResult<()> {
self.access.delete(DirectDbWriter::new(&self.db), ip.into())
}

fn reset(&mut self) -> StoreResult<()> {
self.access.delete_all(DirectDbWriter::new(&self.db))
}
}
13 changes: 9 additions & 4 deletions kaspad/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub struct Args {
pub user_agent_comments: Vec<String>,
pub utxoindex: bool,
pub reset_db: bool,
pub reset_address_stores: bool,
#[serde(rename = "outpeers")]
pub outbound_target: usize,
#[serde(rename = "maxinpeers")]
Expand Down Expand Up @@ -110,6 +111,7 @@ impl Default for Args {
async_threads: num_cpus::get(),
utxoindex: false,
reset_db: false,
reset_address_stores: false,
outbound_target: 8,
inbound_limit: 128,
rpc_max_clients: 128,
Expand Down Expand Up @@ -309,7 +311,7 @@ pub fn cli() -> Command {
)
.arg(
Arg::new("maxinpeers")
.long("maxinpeers")
.long("maxinpeers")
.env("KASPAD_MAXINPEERS")
.value_name("maxinpeers")
.require_equals(true)
Expand All @@ -325,7 +327,8 @@ pub fn cli() -> Command {
.value_parser(clap::value_parser!(usize))
.help("Max number of RPC clients for standard connections (default: 128)."),
)
.arg(arg!(--"reset-db" "Reset database before starting node. It's needed when switching between subnetworks.").env("KASPAD_RESET_DB"))
.arg(arg!(--"reset-db" "Reset all databases before starting node. It's needed when switching between subnetworks.").env("KASPAD_RESET_DB"))
.arg(arg!(--"reset-address-stores" "Reset the address manager's stores before starting the node.").env("KASPAD_RESET_ADDRESS_STORES"))
.arg(arg!(--"enable-unsynced-mining" "Allow the node to accept blocks from RPC while not synced (this flag is mainly used for testing)").env("KASPAD_ENABLE_UNSYNCED_MINING"))
.arg(
Arg::new("enable-mainnet-mining")
Expand All @@ -342,8 +345,8 @@ pub fn cli() -> Command {
.env("KASPAD_MAX_TRACKED_ADDRESSES")
.require_equals(true)
.value_parser(clap::value_parser!(usize))
.help(format!("Max (preallocated) number of addresses being tracked for UTXO changed events (default: {}, maximum: {}).
Setting to 0 prevents the preallocation and sets the maximum to {}, leading to 0 memory footprint as long as unused but to sub-optimal footprint if used.",
.help(format!("Max (preallocated) number of addresses being tracked for UTXO changed events (default: {}, maximum: {}).
Setting to 0 prevents the preallocation and sets the maximum to {}, leading to 0 memory footprint as long as unused but to sub-optimal footprint if used.",
0, Tracker::MAX_ADDRESS_UPPER_BOUND, Tracker::DEFAULT_MAX_ADDRESSES)),
)
.arg(arg!(--testnet "Use the test network").env("KASPAD_TESTNET"))
Expand Down Expand Up @@ -500,6 +503,7 @@ impl Args {
rpc_max_clients: arg_match_unwrap_or::<usize>(&m, "rpcmaxclients", defaults.rpc_max_clients),
max_tracked_addresses: arg_match_unwrap_or::<usize>(&m, "max-tracked-addresses", defaults.max_tracked_addresses),
reset_db: arg_match_unwrap_or::<bool>(&m, "reset-db", defaults.reset_db),
reset_address_stores: arg_match_unwrap_or::<bool>(&m, "reset-address-stores", defaults.reset_address_stores),
enable_unsynced_mining: arg_match_unwrap_or::<bool>(&m, "enable-unsynced-mining", defaults.enable_unsynced_mining),
enable_mainnet_mining: arg_match_unwrap_or::<bool>(&m, "enable-mainnet-mining", defaults.enable_mainnet_mining),
utxoindex: arg_match_unwrap_or::<bool>(&m, "utxoindex", defaults.utxoindex),
Expand Down Expand Up @@ -623,6 +627,7 @@ fn arg_match_many_unwrap_or<T: Clone + Send + Sync + 'static>(m: &clap::ArgMatch
the active network.
--reset-db Reset database before starting node. It's needed when switching between
subnetworks.
--reset-address-stores Reset the address manager's stores before starting the node.
--maxutxocachesize= Max size of loaded UTXO into ram from the disk in bytes (default:
5000000000)
--utxoindex Enable the UTXO index
Expand Down
4 changes: 4 additions & 0 deletions kaspad/src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,10 @@ Do you confirm? (y/n)";
};

let (address_manager, port_mapping_extender_svc) = AddressManager::new(config.clone(), meta_db, tick_service.clone());
if args.reset_address_stores {
info!("AddressManager: Resetting the address stores.");
address_manager.lock().reset();
}

let mining_manager = MiningManagerProxy::new(Arc::new(MiningManager::new_with_extended_config(
config.target_time_per_block(),
Expand Down