diff --git a/bin/trin/src/cli.rs b/bin/trin/src/cli.rs index 9a8e55ca0..d34bd4e7f 100644 --- a/bin/trin/src/cli.rs +++ b/bin/trin/src/cli.rs @@ -216,6 +216,13 @@ pub struct TrinConfig { value_parser = max_radius_parser, )] pub max_radius: Distance, + + #[arg( + long = "disable-history-storage", + help = "Disable storing all history data locally. This is a temporary flag used for upgrading the network, and should be removed once the upgrade is complete.", + default_value = "false" + )] + pub disable_history_storage: bool, } impl Default for TrinConfig { @@ -249,6 +256,7 @@ impl Default for TrinConfig { network: MAINNET.clone(), max_radius: max_radius_parser(DEFAULT_MAX_RADIUS) .expect("Parsing static DEFAULT_MAX_RADIUS to work"), + disable_history_storage: false, } } } diff --git a/bin/trin/src/lib.rs b/bin/trin/src/lib.rs index 2ee285355..fb3b6ff28 100644 --- a/bin/trin/src/lib.rs +++ b/bin/trin/src/lib.rs @@ -150,6 +150,7 @@ pub async fn run_trin( portalnet_config.clone(), storage_config_factory.create(&Subnetwork::History, trin_config.max_radius)?, header_oracle.clone(), + trin_config.disable_history_storage, ) .await? } else { diff --git a/crates/subnetworks/history/src/lib.rs b/crates/subnetworks/history/src/lib.rs index 5803c9660..e7f0692be 100644 --- a/crates/subnetworks/history/src/lib.rs +++ b/crates/subnetworks/history/src/lib.rs @@ -41,6 +41,7 @@ pub async fn initialize_history_network( portalnet_config: PortalnetConfig, storage_config: PortalStorageConfig, header_oracle: Arc>, + disable_history_storage: bool, ) -> anyhow::Result<( HistoryHandler, HistoryNetworkTask, @@ -58,6 +59,7 @@ pub async fn initialize_history_network( storage_config, portalnet_config.clone(), header_oracle, + disable_history_storage, ) .await?; let event_stream = history_network.overlay.event_stream().await?; diff --git a/crates/subnetworks/history/src/network.rs b/crates/subnetworks/history/src/network.rs index f4b96057d..9f1934036 100644 --- a/crates/subnetworks/history/src/network.rs +++ b/crates/subnetworks/history/src/network.rs @@ -46,6 +46,7 @@ impl HistoryNetwork { storage_config: PortalStorageConfig, portal_config: PortalnetConfig, header_oracle: Arc>, + disable_history_storage: bool, ) -> anyhow::Result { let config = OverlayConfig { bootnode_enrs: portal_config.bootnodes, @@ -54,7 +55,10 @@ impl HistoryNetwork { utp_transfer_limit: portal_config.utp_transfer_limit, ..Default::default() }; - let storage = Arc::new(PLRwLock::new(HistoryStorage::new(storage_config)?)); + let storage = Arc::new(PLRwLock::new(HistoryStorage::new( + storage_config, + disable_history_storage, + )?)); let validator = Arc::new(ChainHistoryValidator { header_oracle }); let ping_extensions = Arc::new(HistoryPingExtensions {}); let overlay = OverlayProtocol::new( diff --git a/crates/subnetworks/history/src/storage.rs b/crates/subnetworks/history/src/storage.rs index 47f3a439f..13b8deff6 100644 --- a/crates/subnetworks/history/src/storage.rs +++ b/crates/subnetworks/history/src/storage.rs @@ -12,6 +12,7 @@ use trin_storage::{ #[derive(Debug)] pub struct HistoryStorage { store: IdIndexedV1Store, + disable_history_storage: bool, } impl ContentStore for HistoryStorage { @@ -35,6 +36,10 @@ impl ContentStore for HistoryStorage { key: &HistoryContentKey, ) -> Result { let content_id = ContentId::from(key.content_id()); + // temporarily disable storing all history network + if self.disable_history_storage { + return Ok(ShouldWeStoreContent::NotWithinRadius); + } if self.store.distance_to_content_id(&content_id) > self.store.radius() { Ok(ShouldWeStoreContent::NotWithinRadius) } else if self.store.has_content(&content_id)? { @@ -50,11 +55,15 @@ impl ContentStore for HistoryStorage { } impl HistoryStorage { - pub fn new(config: PortalStorageConfig) -> Result { + pub fn new( + config: PortalStorageConfig, + disable_history_storage: bool, + ) -> Result { let sql_connection_pool = config.sql_connection_pool.clone(); let config = IdIndexedV1StoreConfig::new(ContentType::History, Subnetwork::History, config); Ok(Self { store: create_store(ContentType::History, config, sql_connection_pool)?, + disable_history_storage, }) } @@ -97,7 +106,7 @@ pub mod test { fn test_store_random_bytes() -> TestResult { let (temp_dir, storage_config) = create_test_portal_storage_config_with_capacity(CAPACITY_MB).unwrap(); - let mut storage = HistoryStorage::new(storage_config).unwrap(); + let mut storage = HistoryStorage::new(storage_config, false).unwrap(); let content_key = HistoryContentKey::random().unwrap(); let mut value = [0u8; 32]; rand::thread_rng().fill_bytes(&mut value); @@ -118,7 +127,7 @@ pub mod test { async fn test_get_data() -> Result<(), ContentStoreError> { let (temp_dir, storage_config) = create_test_portal_storage_config_with_capacity(CAPACITY_MB).unwrap(); - let mut storage = HistoryStorage::new(storage_config)?; + let mut storage = HistoryStorage::new(storage_config, false)?; let content_key = HistoryContentKey::BlockHeaderByHash(BlockHeaderByHashKey::default()); let value: Vec = "OGFWs179fWnqmjvHQFGHszXloc3Wzdb4".into(); storage.put(content_key.clone(), &value)?;