Skip to content

Commit a63239f

Browse files
authored
fix: add temporary flag to disable storing headers (#1668)
* fix: add temporary flag to disable storing history content
1 parent f0187cb commit a63239f

File tree

5 files changed

+28
-4
lines changed

5 files changed

+28
-4
lines changed

bin/trin/src/cli.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,13 @@ pub struct TrinConfig {
216216
value_parser = max_radius_parser,
217217
)]
218218
pub max_radius: Distance,
219+
220+
#[arg(
221+
long = "disable-history-storage",
222+
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.",
223+
default_value = "false"
224+
)]
225+
pub disable_history_storage: bool,
219226
}
220227

221228
impl Default for TrinConfig {
@@ -249,6 +256,7 @@ impl Default for TrinConfig {
249256
network: MAINNET.clone(),
250257
max_radius: max_radius_parser(DEFAULT_MAX_RADIUS)
251258
.expect("Parsing static DEFAULT_MAX_RADIUS to work"),
259+
disable_history_storage: false,
252260
}
253261
}
254262
}

bin/trin/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ pub async fn run_trin(
150150
portalnet_config.clone(),
151151
storage_config_factory.create(&Subnetwork::History, trin_config.max_radius)?,
152152
header_oracle.clone(),
153+
trin_config.disable_history_storage,
153154
)
154155
.await?
155156
} else {

crates/subnetworks/history/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ pub async fn initialize_history_network(
4141
portalnet_config: PortalnetConfig,
4242
storage_config: PortalStorageConfig,
4343
header_oracle: Arc<RwLock<HeaderOracle>>,
44+
disable_history_storage: bool,
4445
) -> anyhow::Result<(
4546
HistoryHandler,
4647
HistoryNetworkTask,
@@ -58,6 +59,7 @@ pub async fn initialize_history_network(
5859
storage_config,
5960
portalnet_config.clone(),
6061
header_oracle,
62+
disable_history_storage,
6163
)
6264
.await?;
6365
let event_stream = history_network.overlay.event_stream().await?;

crates/subnetworks/history/src/network.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ impl HistoryNetwork {
4646
storage_config: PortalStorageConfig,
4747
portal_config: PortalnetConfig,
4848
header_oracle: Arc<RwLock<HeaderOracle>>,
49+
disable_history_storage: bool,
4950
) -> anyhow::Result<Self> {
5051
let config = OverlayConfig {
5152
bootnode_enrs: portal_config.bootnodes,
@@ -54,7 +55,10 @@ impl HistoryNetwork {
5455
utp_transfer_limit: portal_config.utp_transfer_limit,
5556
..Default::default()
5657
};
57-
let storage = Arc::new(PLRwLock::new(HistoryStorage::new(storage_config)?));
58+
let storage = Arc::new(PLRwLock::new(HistoryStorage::new(
59+
storage_config,
60+
disable_history_storage,
61+
)?));
5862
let validator = Arc::new(ChainHistoryValidator { header_oracle });
5963
let ping_extensions = Arc::new(HistoryPingExtensions {});
6064
let overlay = OverlayProtocol::new(

crates/subnetworks/history/src/storage.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use trin_storage::{
1212
#[derive(Debug)]
1313
pub struct HistoryStorage {
1414
store: IdIndexedV1Store<HistoryContentKey>,
15+
disable_history_storage: bool,
1516
}
1617

1718
impl ContentStore for HistoryStorage {
@@ -35,6 +36,10 @@ impl ContentStore for HistoryStorage {
3536
key: &HistoryContentKey,
3637
) -> Result<ShouldWeStoreContent, ContentStoreError> {
3738
let content_id = ContentId::from(key.content_id());
39+
// temporarily disable storing all history network
40+
if self.disable_history_storage {
41+
return Ok(ShouldWeStoreContent::NotWithinRadius);
42+
}
3843
if self.store.distance_to_content_id(&content_id) > self.store.radius() {
3944
Ok(ShouldWeStoreContent::NotWithinRadius)
4045
} else if self.store.has_content(&content_id)? {
@@ -50,11 +55,15 @@ impl ContentStore for HistoryStorage {
5055
}
5156

5257
impl HistoryStorage {
53-
pub fn new(config: PortalStorageConfig) -> Result<Self, ContentStoreError> {
58+
pub fn new(
59+
config: PortalStorageConfig,
60+
disable_history_storage: bool,
61+
) -> Result<Self, ContentStoreError> {
5462
let sql_connection_pool = config.sql_connection_pool.clone();
5563
let config = IdIndexedV1StoreConfig::new(ContentType::History, Subnetwork::History, config);
5664
Ok(Self {
5765
store: create_store(ContentType::History, config, sql_connection_pool)?,
66+
disable_history_storage,
5867
})
5968
}
6069

@@ -97,7 +106,7 @@ pub mod test {
97106
fn test_store_random_bytes() -> TestResult {
98107
let (temp_dir, storage_config) =
99108
create_test_portal_storage_config_with_capacity(CAPACITY_MB).unwrap();
100-
let mut storage = HistoryStorage::new(storage_config).unwrap();
109+
let mut storage = HistoryStorage::new(storage_config, false).unwrap();
101110
let content_key = HistoryContentKey::random().unwrap();
102111
let mut value = [0u8; 32];
103112
rand::thread_rng().fill_bytes(&mut value);
@@ -118,7 +127,7 @@ pub mod test {
118127
async fn test_get_data() -> Result<(), ContentStoreError> {
119128
let (temp_dir, storage_config) =
120129
create_test_portal_storage_config_with_capacity(CAPACITY_MB).unwrap();
121-
let mut storage = HistoryStorage::new(storage_config)?;
130+
let mut storage = HistoryStorage::new(storage_config, false)?;
122131
let content_key = HistoryContentKey::BlockHeaderByHash(BlockHeaderByHashKey::default());
123132
let value: Vec<u8> = "OGFWs179fWnqmjvHQFGHszXloc3Wzdb4".into();
124133
storage.put(content_key.clone(), &value)?;

0 commit comments

Comments
 (0)