Skip to content

Commit e724f0d

Browse files
committed
improvements according pr comments
1 parent 61f753b commit e724f0d

File tree

8 files changed

+31
-36
lines changed

8 files changed

+31
-36
lines changed

configuration/src/configs/general.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub struct GeneralRpcServerConfig {
2121
pub block_cache_size: f64,
2222
pub shadow_data_consistency_rate: f64,
2323
pub prefetch_state_size_limit: u64,
24-
pub available_data_ranges: u64,
24+
pub keep_data_ranges_number: u64,
2525
pub archival_mode: bool,
2626
}
2727

@@ -127,7 +127,7 @@ pub struct CommonGeneralRpcServerConfig {
127127
message = "Available data ranges must be greater than or equal to 1"
128128
))]
129129
#[serde(deserialize_with = "deserialize_optional_data_or_env", default)]
130-
pub available_data_ranges: Option<u64>,
130+
pub keep_data_ranges_number: Option<u64>,
131131
#[serde(deserialize_with = "deserialize_optional_data_or_env", default)]
132132
pub archival_mode: Option<bool>,
133133
}
@@ -157,12 +157,12 @@ impl CommonGeneralRpcServerConfig {
157157
100_000
158158
}
159159

160-
pub fn default_available_data_ranges() -> u64 {
160+
pub fn default_keep_data_ranges_number() -> u64 {
161161
1
162162
}
163163

164164
pub fn default_archival_mode() -> bool {
165-
false
165+
true
166166
}
167167
}
168168

@@ -175,7 +175,7 @@ impl Default for CommonGeneralRpcServerConfig {
175175
block_cache_size: Some(Self::default_block_cache_size()),
176176
shadow_data_consistency_rate: Some(Self::default_shadow_data_consistency_rate()),
177177
prefetch_state_size_limit: Some(Self::default_prefetch_state_size_limit()),
178-
available_data_ranges: Some(Self::default_available_data_ranges()),
178+
keep_data_ranges_number: Some(Self::default_keep_data_ranges_number()),
179179
archival_mode: Some(Self::default_archival_mode()),
180180
}
181181
}
@@ -282,10 +282,10 @@ impl From<CommonGeneralConfig> for GeneralRpcServerConfig {
282282
.rpc_server
283283
.prefetch_state_size_limit
284284
.unwrap_or_else(CommonGeneralRpcServerConfig::default_prefetch_state_size_limit),
285-
available_data_ranges: common_config
285+
keep_data_ranges_number: common_config
286286
.rpc_server
287-
.available_data_ranges
288-
.unwrap_or_else(CommonGeneralRpcServerConfig::default_available_data_ranges),
287+
.keep_data_ranges_number
288+
.unwrap_or_else(CommonGeneralRpcServerConfig::default_keep_data_ranges_number),
289289
archival_mode: common_config
290290
.rpc_server
291291
.archival_mode

configuration/src/default_env_configs.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,15 @@ rpc_auth_token = "${RPC_AUTH_TOKEN}"
3131
redis_url = "${REDIS_URL}"
3232
3333
## Represents the number of available data ranges.
34-
## 1 means it will be available last 500_000 blocks (~11 epochs).
34+
## 1 means it will be available last 500_000 blocks (~11 epochs).cargo fmt
3535
## 2 means it will be available last 1_000_000 blocks (~22 epochs) etc.
3636
## Default value is 1
37-
available_data_ranges = "${AVAILABLE_DATA_RANGES}"
37+
keep_data_ranges_number = "${KEEP_DATA_RANGES_NUMBER}"
3838
3939
## If true, means we store whole state changes in the database
40-
## and available_data_ranges will be ignored
40+
## and keep_data_ranges_number will be ignored
4141
## and genesis block_height will be used as earliest_available_block_height
42+
## Default value is true
4243
archival_mode = "${ARCHIVAL_MODE}"
4344
4445
### Rpc server general configuration

configuration/src/utils.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,25 @@ pub async fn get_data_range_id(
4141
/// This function calculates the earliest available block height based on the final block height
4242
pub async fn get_earliest_available_block_height(
4343
final_block_height: u64,
44-
available_data_ranges: u64,
44+
keep_data_ranges_number: u64,
4545
) -> anyhow::Result<u64> {
4646
let final_range_id = get_data_range_id(&final_block_height).await?;
47-
Ok(final_range_id * 100_000 + available_data_ranges * BLOCK_HEIGHT_RANGE)
47+
Ok(final_range_id * 100_000 + keep_data_ranges_number * BLOCK_HEIGHT_RANGE)
4848
}
4949

5050
/// This function checks if the block height is available in the database
5151
/// It returns an error if the block height is less than the earliest available block
52-
pub async fn check_block_height(
52+
pub async fn check_block_height_availability(
5353
block_height: &near_primitives::types::BlockHeight,
5454
final_block_height: &near_primitives::types::BlockHeight,
55-
available_data_ranges: u64,
55+
keep_data_ranges_number: u64,
5656
archival_mode: bool,
5757
) -> anyhow::Result<()> {
5858
if archival_mode {
5959
return Ok(());
6060
}
6161
let earliest_available_block =
62-
get_earliest_available_block_height(*final_block_height, available_data_ranges).await?;
62+
get_earliest_available_block_height(*final_block_height, keep_data_ranges_number).await?;
6363
if *block_height < earliest_available_block {
6464
anyhow::bail!(
6565
"The data for block #{} is garbage collected on this node, use an archival node to fetch historical data",
Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
-- Add up migration script here
2-
DO $$
3-
DECLARE
4-
i INT;
5-
BEGIN
6-
-- Drop column from parent table
7-
ALTER TABLE state_changes_data DROP COLUMN IF EXISTS block_hash;
8-
ALTER TABLE state_changes_access_key DROP COLUMN IF EXISTS block_hash;
9-
ALTER TABLE state_changes_contract DROP COLUMN IF EXISTS block_hash;
10-
ALTER TABLE state_changes_account DROP COLUMN IF EXISTS block_hash;
11-
END $$;
2+
ALTER TABLE state_changes_data DROP COLUMN IF EXISTS block_hash;
3+
ALTER TABLE state_changes_access_key DROP COLUMN IF EXISTS block_hash;
4+
ALTER TABLE state_changes_contract DROP COLUMN IF EXISTS block_hash;
5+
ALTER TABLE state_changes_account DROP COLUMN IF EXISTS block_hash;

database/src/postgres/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl PageState {
4545
/// block_height 130_501_000, the `data_range_id` will be 1305 -> `state_changes_data_1305`
4646
///
4747
/// How to get `data_range_id` from block_height
48-
/// see more details in the `get_data_range_id` function below.
48+
/// see more details in the function `configuration::utils::get_data_range_id`.
4949
pub struct ShardIdPool<'a> {
5050
shard_id: near_primitives::types::ShardId,
5151
data_range_id: u64,

rpc-server/src/config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ pub struct ServerContext {
7575
/// Binary version.
7676
pub version: near_primitives::version::Version,
7777
/// Available data ranges for regular node mode.
78-
pub available_data_ranges: u64,
78+
pub keep_data_ranges_number: u64,
7979
/// Archival mode.
80-
/// If true, available_data_ranges will be ignored
80+
/// If true, keep_data_ranges_number will be ignored
8181
pub archival_mode: bool,
8282
}
8383

@@ -188,7 +188,7 @@ impl ServerContext {
188188
commit: NEARD_COMMIT.to_string(),
189189
rustc_version: RUSTC_VERSION.to_string(),
190190
},
191-
available_data_ranges: rpc_server_config.general.available_data_ranges,
191+
keep_data_ranges_number: rpc_server_config.general.keep_data_ranges_number,
192192
archival_mode: rpc_server_config.general.archival_mode,
193193
})
194194
}

rpc-server/src/modules/blocks/methods.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,15 +408,15 @@ pub async fn fetch_block(
408408
Ok(data.genesis_info.genesis_block.header.height)
409409
}
410410
}?;
411-
configuration::utils::check_block_height(
411+
configuration::utils::check_block_height_availability(
412412
&block_height,
413413
&data
414414
.blocks_info_by_finality
415415
.optimistic_block_view()
416416
.await
417417
.header
418418
.height,
419-
data.available_data_ranges,
419+
data.keep_data_ranges_number,
420420
data.archival_mode,
421421
)
422422
.await
@@ -531,15 +531,15 @@ pub async fn fetch_chunk(
531531
.map(|block_height_shard_id| (block_height_shard_id.0, block_height_shard_id.1))?,
532532
};
533533

534-
configuration::utils::check_block_height(
534+
configuration::utils::check_block_height_availability(
535535
&block_height,
536536
&data
537537
.blocks_info_by_finality
538538
.optimistic_block_view()
539539
.await
540540
.header
541541
.height,
542-
data.available_data_ranges,
542+
data.keep_data_ranges_number,
543543
data.archival_mode,
544544
)
545545
.await

rpc-server/src/modules/blocks/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,15 @@ pub async fn fetch_block_from_cache_or_get(
128128
}
129129
})?,
130130
};
131-
configuration::utils::check_block_height(
131+
configuration::utils::check_block_height_availability(
132132
&block_height,
133133
&data
134134
.blocks_info_by_finality
135135
.optimistic_block_view()
136136
.await
137137
.header
138138
.height,
139-
data.available_data_ranges,
139+
data.keep_data_ranges_number,
140140
data.archival_mode,
141141
)
142142
.await

0 commit comments

Comments
 (0)