Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api_key): Added support for --gateway-api to avoid rate limit from the gateway #30

Merged
merged 2 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ git # Deoxys Changelog

## Next release

- feat(api_key): api key passed to FetchConfig correctly
- feat(api_key): Added support for --gateway-api to avoid rate limit from the gateway
- fix(latest): Retrieve latest synced block via internal client
- perf(l2 sync): parallelize commitment computation and refactor part of l2 io sync
- refactor: rpc methods and removed rpc-core
Expand Down
26 changes: 13 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ where
error!("Failed to get config: {e}");
StarknetRpcApiError::InternalServerError
})?;
let sequencer = SequencerGatewayProvider::new(config.feeder_gateway, config.gateway, config.chain_id);
let sequencer = SequencerGatewayProvider::new(config.feeder_gateway, config.gateway, config.chain_id, None);

let sequencer_response = match sequencer.add_declare_transaction(declare_transaction).await {
Ok(response) => response,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ where
error!("Failed to get config: {e}");
StarknetRpcApiError::InternalServerError
})?;
let sequencer = SequencerGatewayProvider::new(config.feeder_gateway, config.gateway, config.chain_id);
let sequencer = SequencerGatewayProvider::new(config.feeder_gateway, config.gateway, config.chain_id, None);

let sequencer_response = match sequencer.add_deploy_account_transaction(deploy_account_transaction).await {
Ok(response) => response,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ where
error!("Failed to get config: {e}");
StarknetRpcApiError::InternalServerError
})?;
let sequencer = SequencerGatewayProvider::new(config.feeder_gateway, config.gateway, config.chain_id);
let sequencer = SequencerGatewayProvider::new(config.feeder_gateway, config.gateway, config.chain_id, None);

let sequencer_response = match sequencer.add_invoke_transaction(invoke_transaction).await {
Ok(response) => response,
Expand Down
10 changes: 9 additions & 1 deletion crates/client/sync/src/fetch/fetchers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ pub struct FetchConfig {
pub l1_core_address: H160,
/// Whether to check the root of the state update
pub verify: bool,
/// The optional API_KEY to avoid rate limiting from the sequencer gateway.
pub api_key: Option<String>,
}

pub async fn fetch_block(client: &SequencerGatewayProvider, block_number: u64) -> Result<p::Block, L2SyncError> {
Expand Down Expand Up @@ -75,6 +77,7 @@ where

match block.as_ref().err().or(state_update.as_ref().err()) {
Some(L2SyncError::Provider(ProviderError::RateLimited)) => {
log::info!("The fetching process has been rate limited");
log::debug!("The fetching process has been rate limited, retrying in {:?} seconds", base_delay);
attempt += 1;
if attempt >= MAX_RETRY {
Expand All @@ -93,7 +96,12 @@ where
}

pub async fn fetch_apply_genesis_block(config: FetchConfig) -> Result<DeoxysBlock, String> {
let client = SequencerGatewayProvider::new(config.gateway.clone(), config.feeder_gateway.clone(), config.chain_id);
let client = SequencerGatewayProvider::new(
config.gateway.clone(),
config.feeder_gateway.clone(),
config.chain_id,
config.api_key.clone(),
);
let block = client.get_block(BlockId::Number(0)).await.map_err(|e| format!("failed to get block: {e}"))?;

Ok(crate::convert::block(block).await)
Expand Down
1 change: 1 addition & 0 deletions crates/client/sync/src/l2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ pub async fn sync<C>(
fetch_config.gateway.clone(),
fetch_config.feeder_gateway.clone(),
fetch_config.chain_id,
fetch_config.api_key,
));
let mut last_block_hash = None;

Expand Down
16 changes: 15 additions & 1 deletion crates/node/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,16 @@ impl NetworkType {
let feeder_gateway = format!("{uri}/feeder_gateway").parse().unwrap();
let l1_core_address = self.l1_core_address();

FetchConfig { gateway, feeder_gateway, chain_id, workers: 5, sound: false, l1_core_address, verify: true }
FetchConfig {
gateway,
feeder_gateway,
chain_id,
workers: 5,
sound: false,
l1_core_address,
verify: true,
api_key: None,
}
}
}

Expand Down Expand Up @@ -126,6 +135,10 @@ pub struct ExtendedRunCmd {
#[clap(long)]
pub disable_root: bool,

/// Gateway api key to avoid rate limiting (optional)
#[clap(long)]
pub gateway_key: Option<String>,

/// A flag to run the TUI dashboard
#[cfg(feature = "tui")]
#[clap(long)]
Expand Down Expand Up @@ -168,6 +181,7 @@ pub fn run_node(mut cli: Cli) -> Result<()> {
let mut fetch_block_config = cli.run.network.block_fetch_config();
fetch_block_config.sound = cli.run.sound;
fetch_block_config.verify = !cli.run.disable_root;
fetch_block_config.api_key = cli.run.gateway_key.clone();

update_config(&fetch_block_config);
log::debug!("Using fetch block config: {:?}", fetch_block_config);
Expand Down
Loading