Skip to content

Commit 3cf473d

Browse files
committed
chore: remove duplicate code in magic validator
1 parent 4f8ecc8 commit 3cf473d

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

magicblock-api/src/magic_validator.rs

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -270,14 +270,10 @@ impl MagicValidator {
270270
None
271271
};
272272

273-
let accounts_config =
274-
try_convert_accounts_config(&config.validator_config.accounts)
275-
.map_err(ApiError::ConfigError)?;
276-
277-
let remote_rpc_config = RpcProviderConfig::new(
278-
try_rpc_cluster_from_cluster(&accounts_config.remote_cluster)?,
279-
Some(CommitmentLevel::Confirmed),
280-
);
273+
let (accounts_config, remote_rpc_config) =
274+
try_get_remote_accounts_and_rpc_config(
275+
&config.validator_config.accounts,
276+
)?;
281277

282278
let remote_account_fetcher_worker =
283279
RemoteAccountFetcherWorker::new(remote_rpc_config.clone());
@@ -656,20 +652,10 @@ impl MagicValidator {
656652
}
657653

658654
async fn ensure_validator_funded_on_chain(&self) -> ApiResult<()> {
659-
// TODO(thlorenz) make this configurable in the future
655+
// NOTE: 5 SOL seems reasonable, but we may require a different amount in the future
660656
const MIN_BALANCE_SOL: u64 = 5;
661-
// TODO: @@ duplicate code getting remote_rpc_config
662-
let accounts_config = try_convert_accounts_config(
663-
&self.config.accounts,
664-
)
665-
.expect(
666-
"Failed to derive accounts config from provided magicblock config",
667-
);
668-
let remote_rpc_config = RpcProviderConfig::new(
669-
try_rpc_cluster_from_cluster(&accounts_config.remote_cluster)?,
670-
Some(CommitmentLevel::Confirmed),
671-
);
672-
657+
let (_, remote_rpc_config) =
658+
try_get_remote_accounts_and_rpc_config(&self.config.accounts)?;
673659
let validator_pubkey = self.bank().get_identity();
674660

675661
let lamports = RpcClient::new_with_commitment(
@@ -895,3 +881,15 @@ fn create_worker_runtime(thread_name: &str) -> tokio::runtime::Runtime {
895881
.build()
896882
.unwrap()
897883
}
884+
885+
fn try_get_remote_accounts_and_rpc_config(
886+
accounts: &magicblock_config::AccountsConfig,
887+
) -> ApiResult<(magicblock_accounts::AccountsConfig, RpcProviderConfig)> {
888+
let accounts_config =
889+
try_convert_accounts_config(accounts).map_err(ApiError::ConfigError)?;
890+
let remote_rpc_config = RpcProviderConfig::new(
891+
try_rpc_cluster_from_cluster(&accounts_config.remote_cluster)?,
892+
Some(CommitmentLevel::Confirmed),
893+
);
894+
Ok((accounts_config, remote_rpc_config))
895+
}

0 commit comments

Comments
 (0)