Skip to content

Commit 0e1b9d4

Browse files
authored
Chore: cleanup some signer consts (#346)
1 parent 9feb4d2 commit 0e1b9d4

File tree

6 files changed

+24
-31
lines changed

6 files changed

+24
-31
lines changed

crates/cli/src/docker_init.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ use cb_common::{
1515
PROXY_DIR_KEYS_ENV, PROXY_DIR_SECRETS_DEFAULT, PROXY_DIR_SECRETS_ENV, SIGNER_DEFAULT,
1616
SIGNER_DIR_KEYS_DEFAULT, SIGNER_DIR_KEYS_ENV, SIGNER_DIR_SECRETS_DEFAULT,
1717
SIGNER_DIR_SECRETS_ENV, SIGNER_ENDPOINT_ENV, SIGNER_KEYS_ENV, SIGNER_MODULE_NAME,
18-
SIGNER_URL_ENV,
18+
SIGNER_PORT_DEFAULT, SIGNER_URL_ENV,
1919
},
2020
pbs::{BUILDER_API_PATH, GET_STATUS_PATH},
21-
signer::{ProxyStore, SignerLoader, DEFAULT_SIGNER_PORT},
21+
signer::{ProxyStore, SignerLoader},
2222
types::ModuleId,
2323
utils::random_jwt_secret,
2424
};
@@ -73,7 +73,7 @@ pub async fn handle_docker_init(config_path: PathBuf, output_dir: PathBuf) -> Re
7373
let mut targets = Vec::new();
7474

7575
// address for signer API communication
76-
let signer_port = cb_config.signer.as_ref().map(|s| s.port).unwrap_or(DEFAULT_SIGNER_PORT);
76+
let signer_port = cb_config.signer.as_ref().map(|s| s.port).unwrap_or(SIGNER_PORT_DEFAULT);
7777
let signer_server =
7878
if let Some(SignerConfig { inner: SignerType::Remote { url }, .. }) = &cb_config.signer {
7979
url.to_string()

crates/common/src/config/constants.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,16 @@ pub const SIGNER_MODULE_NAME: &str = "signer";
3434

3535
/// Where the signer module should open the server
3636
pub const SIGNER_ENDPOINT_ENV: &str = "CB_SIGNER_ENDPOINT";
37+
pub const SIGNER_PORT_DEFAULT: u16 = 20000;
3738

38-
// JWT authentication settings
39+
/// Number of auth failures before rate limiting the client
3940
pub const SIGNER_JWT_AUTH_FAIL_LIMIT_ENV: &str = "CB_SIGNER_JWT_AUTH_FAIL_LIMIT";
41+
pub const SIGNER_JWT_AUTH_FAIL_LIMIT_DEFAULT: u32 = 3;
42+
43+
/// How long to rate limit the client after auth failures
4044
pub const SIGNER_JWT_AUTH_FAIL_TIMEOUT_SECONDS_ENV: &str =
4145
"CB_SIGNER_JWT_AUTH_FAIL_TIMEOUT_SECONDS";
46+
pub const SIGNER_JWT_AUTH_FAIL_TIMEOUT_SECONDS_DEFAULT: u32 = 5 * 60;
4247

4348
/// Comma separated list module_id=jwt_secret
4449
pub const JWTS_ENV: &str = "CB_JWTS";

crates/common/src/config/signer.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@ use url::Url;
1212

1313
use super::{
1414
load_jwt_secrets, load_optional_env_var, utils::load_env_var, CommitBoostConfig,
15-
SIGNER_ENDPOINT_ENV, SIGNER_IMAGE_DEFAULT, SIGNER_JWT_AUTH_FAIL_LIMIT_ENV,
16-
SIGNER_JWT_AUTH_FAIL_TIMEOUT_SECONDS_ENV,
15+
SIGNER_ENDPOINT_ENV, SIGNER_IMAGE_DEFAULT, SIGNER_JWT_AUTH_FAIL_LIMIT_DEFAULT,
16+
SIGNER_JWT_AUTH_FAIL_LIMIT_ENV, SIGNER_JWT_AUTH_FAIL_TIMEOUT_SECONDS_DEFAULT,
17+
SIGNER_JWT_AUTH_FAIL_TIMEOUT_SECONDS_ENV, SIGNER_PORT_DEFAULT,
1718
};
1819
use crate::{
1920
config::{DIRK_CA_CERT_ENV, DIRK_CERT_ENV, DIRK_DIR_SECRETS_ENV, DIRK_KEY_ENV},
20-
signer::{
21-
ProxyStore, SignerLoader, DEFAULT_JWT_AUTH_FAIL_LIMIT,
22-
DEFAULT_JWT_AUTH_FAIL_TIMEOUT_SECONDS, DEFAULT_SIGNER_PORT,
23-
},
21+
signer::{ProxyStore, SignerLoader},
2422
types::{Chain, ModuleId},
2523
utils::{default_host, default_u16, default_u32},
2624
};
@@ -32,20 +30,20 @@ pub struct SignerConfig {
3230
#[serde(default = "default_host")]
3331
pub host: Ipv4Addr,
3432
/// Port to listen for signer API calls on
35-
#[serde(default = "default_u16::<DEFAULT_SIGNER_PORT>")]
33+
#[serde(default = "default_u16::<SIGNER_PORT_DEFAULT>")]
3634
pub port: u16,
3735
/// Docker image of the module
38-
#[serde(default = "default_signer")]
36+
#[serde(default = "default_signer_image")]
3937
pub docker_image: String,
4038

4139
/// Number of JWT auth failures before rate limiting an endpoint
4240
/// If set to 0, no rate limiting will be applied
43-
#[serde(default = "default_u32::<DEFAULT_JWT_AUTH_FAIL_LIMIT>")]
41+
#[serde(default = "default_u32::<SIGNER_JWT_AUTH_FAIL_LIMIT_DEFAULT>")]
4442
pub jwt_auth_fail_limit: u32,
4543

4644
/// Duration in seconds to rate limit an endpoint after the JWT auth failure
4745
/// limit has been reached
48-
#[serde(default = "default_u32::<DEFAULT_JWT_AUTH_FAIL_TIMEOUT_SECONDS>")]
46+
#[serde(default = "default_u32::<SIGNER_JWT_AUTH_FAIL_TIMEOUT_SECONDS_DEFAULT>")]
4947
pub jwt_auth_fail_timeout_seconds: u32,
5048

5149
/// Inner type-specific configuration
@@ -70,7 +68,7 @@ impl SignerConfig {
7068
}
7169
}
7270

73-
fn default_signer() -> String {
71+
fn default_signer_image() -> String {
7472
SIGNER_IMAGE_DEFAULT.to_string()
7573
}
7674

crates/common/src/signer/constants.rs

Lines changed: 0 additions & 6 deletions
This file was deleted.

crates/common/src/signer/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
mod constants;
21
mod loader;
32
mod schemes;
43
mod store;
54
mod types;
65

7-
pub use constants::*;
86
pub use loader::*;
97
pub use schemes::*;
108
pub use store::*;

tests/src/utils.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ use alloy::{primitives::U256, rpc::types::beacon::BlsPublicKey};
88
use cb_common::{
99
config::{
1010
PbsConfig, PbsModuleConfig, RelayConfig, SignerConfig, SignerType, StartSignerConfig,
11-
SIGNER_IMAGE_DEFAULT,
11+
SIGNER_IMAGE_DEFAULT, SIGNER_JWT_AUTH_FAIL_LIMIT_DEFAULT,
12+
SIGNER_JWT_AUTH_FAIL_TIMEOUT_SECONDS_DEFAULT, SIGNER_PORT_DEFAULT,
1213
},
1314
pbs::{RelayClient, RelayEntry},
14-
signer::{
15-
SignerLoader, DEFAULT_JWT_AUTH_FAIL_LIMIT, DEFAULT_JWT_AUTH_FAIL_TIMEOUT_SECONDS,
16-
DEFAULT_SIGNER_PORT,
17-
},
15+
signer::SignerLoader,
1816
types::{Chain, ModuleId},
1917
utils::default_host,
2018
};
@@ -106,10 +104,10 @@ pub fn to_pbs_config(
106104
pub fn get_signer_config(loader: SignerLoader) -> SignerConfig {
107105
SignerConfig {
108106
host: default_host(),
109-
port: DEFAULT_SIGNER_PORT,
107+
port: SIGNER_PORT_DEFAULT,
110108
docker_image: SIGNER_IMAGE_DEFAULT.to_string(),
111-
jwt_auth_fail_limit: DEFAULT_JWT_AUTH_FAIL_LIMIT,
112-
jwt_auth_fail_timeout_seconds: DEFAULT_JWT_AUTH_FAIL_TIMEOUT_SECONDS,
109+
jwt_auth_fail_limit: SIGNER_JWT_AUTH_FAIL_LIMIT_DEFAULT,
110+
jwt_auth_fail_timeout_seconds: SIGNER_JWT_AUTH_FAIL_TIMEOUT_SECONDS_DEFAULT,
113111
inner: SignerType::Local { loader, store: None },
114112
}
115113
}

0 commit comments

Comments
 (0)