Skip to content

Commit 5d4e2e5

Browse files
authored
feat(balances): adding project IDs denylist (#931)
1 parent 4a61b77 commit 5d4e2e5

File tree

6 files changed

+43
-1
lines changed

6 files changed

+43
-1
lines changed

src/env/mod.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use {
33
analytics::Config as AnalyticsConfig,
44
database::config::PostgresConfig,
55
error,
6+
handlers::balance::Config as BalanceConfig,
67
names::Config as NamesConfig,
78
profiler::ProfilerConfig,
89
project::{storage::Config as StorageConfig, Config as RegistryConfig},
@@ -66,6 +67,7 @@ pub struct Config {
6667
pub rate_limiting: RateLimitingConfig,
6768
pub irn: IrnConfig,
6869
pub names: NamesConfig,
70+
pub balances: BalanceConfig,
6971
}
7072

7173
impl Config {
@@ -81,6 +83,7 @@ impl Config {
8183
rate_limiting: from_env("RPC_PROXY_RATE_LIMITING_")?,
8284
irn: from_env("RPC_PROXY_IRN_")?,
8385
names: from_env("RPC_PROXY_NAMES_")?,
86+
balances: from_env("RPC_PROXY_BALANCES_")?,
8487
})
8588
}
8689
}
@@ -108,6 +111,7 @@ mod test {
108111
analytics,
109112
database::config::PostgresConfig,
110113
env::{Config, ServerConfig},
114+
handlers::balance::Config as BalanceConfig,
111115
names::Config as NamesConfig,
112116
profiler::ProfilerConfig,
113117
project,
@@ -229,6 +233,8 @@ mod test {
229233
("RPC_PROXY_IRN_NAMESPACE_SECRET", "namespace"),
230234
// Names configuration
231235
("RPC_PROXY_NAMES_ALLOWED_ZONES", "test1.id,test2.id"),
236+
// Account balances-related configuration
237+
("RPC_PROXY_BALANCES_DENYLIST_PROJECT_IDS", "test_project_id"),
232238
];
233239

234240
values.iter().for_each(set_env_var);
@@ -323,7 +329,10 @@ mod test {
323329
},
324330
names: NamesConfig {
325331
allowed_zones: Some(vec!["test1.id".to_owned(), "test2.id".to_owned()]),
326-
}
332+
},
333+
balances: BalanceConfig {
334+
denylist_project_ids: Some(vec!["test_project_id".to_owned()]),
335+
},
327336
}
328337
);
329338

src/handlers/balance.rs

+15
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ pub const H160_EMPTY_ADDRESS: H160 = H160::repeat_byte(0xee);
2727
const PROVIDER_MAX_CALLS: usize = 2;
2828
const METADATA_CACHE_TTL: Duration = Duration::from_secs(60 * 60 * 24); // 1 day
2929

30+
#[derive(Debug, Clone, Deserialize, Eq, PartialEq)]
31+
pub struct Config {
32+
/// List of project ids that are not allowed to use the balance RPC call
33+
/// An empty balances list will be returned for the project ids in the denylist
34+
pub denylist_project_ids: Option<Vec<String>>,
35+
}
36+
3037
#[derive(Debug, Deserialize, Clone)]
3138
#[serde(rename_all = "camelCase")]
3239
pub struct BalanceQueryParams {
@@ -127,6 +134,14 @@ async fn handler_internal(
127134
Path(address): Path<String>,
128135
) -> Result<Response, RpcError> {
129136
let project_id = query.project_id.clone();
137+
138+
// Check the denylist for the project id
139+
if let Some(denylist_project_ids) = &state.config.balances.denylist_project_ids {
140+
if denylist_project_ids.contains(&project_id) {
141+
return Ok(Json(BalanceResponseBody { balances: vec![] }).into_response());
142+
}
143+
}
144+
130145
state.validate_project_access_and_quota(&project_id).await?;
131146

132147
// if headers not contains `x-sdk-version` then respond with an empty balance

terraform/ecs/cluster.tf

+1
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ resource "aws_ecs_task_definition" "app_task" {
134134
{ name = "RPC_PROXY_IRN_NAMESPACE_SECRET", value = var.irn_namespace_secret },
135135

136136
{ name = "RPC_PROXY_NAMES_ALLOWED_ZONES", value = var.names_allowed_zones },
137+
{ name = "RPC_PROXY_BALANCES_DENYLIST_PROJECT_IDS", value = var.balances_denylist_project_ids },
137138

138139
{ name = "RPC_PROXY_ANALYTICS_EXPORT_BUCKET", value = var.analytics_datalake_bucket_name },
139140
],

terraform/ecs/variables.tf

+7
Original file line numberDiff line numberDiff line change
@@ -428,3 +428,10 @@ variable "names_allowed_zones" {
428428
description = "Comma separated list of allowed zones for names"
429429
type = string
430430
}
431+
432+
#-------------------------------------------------------------------------------
433+
# Address balances projects denylist
434+
variable "balances_denylist_project_ids" {
435+
description = "Comma separated list of project IDs to denylist"
436+
type = string
437+
}

terraform/res_ecs.tf

+3
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ module "ecs" {
102102
# ENS Names
103103
names_allowed_zones = var.names_allowed_zones
104104

105+
# Address balances related configuration
106+
balances_denylist_project_ids = var.balances_denylist_project_ids
107+
105108
# Analytics
106109
analytics_datalake_bucket_name = data.terraform_remote_state.datalake.outputs.datalake_bucket_id
107110
analytics_datalake_kms_key_arn = data.terraform_remote_state.datalake.outputs.datalake_kms_key_arn

terraform/variables.tf

+7
Original file line numberDiff line numberDiff line change
@@ -278,3 +278,10 @@ variable "names_allowed_zones" {
278278
description = "Comma separated list of allowed zones for names"
279279
type = string
280280
}
281+
282+
#-------------------------------------------------------------------------------
283+
# Address balances projects denylist
284+
variable "balances_denylist_project_ids" {
285+
description = "Comma separated list of project IDs to denylist"
286+
type = string
287+
}

0 commit comments

Comments
 (0)