Skip to content

Commit

Permalink
fix: authority-claimer polling interval
Browse files Browse the repository at this point in the history
  • Loading branch information
vfusco committed Oct 29, 2024
1 parent e7af251 commit 0e84584
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 3 deletions.
8 changes: 8 additions & 0 deletions cmd/authority-claimer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub struct Config {
pub tx_manager_priority: Priority,
pub log_config: LogConfig,
pub postgres_endpoint: String,
pub polling_interval: u64,
pub genesis_block: u64,
pub http_server_port: u16,
}
Expand Down Expand Up @@ -86,12 +87,15 @@ impl Config {

let postgres_endpoint = cli_config.postgres_endpoint;

let polling_interval = cli_config.polling_interval;

Ok(Config {
tx_manager_config,
tx_signing_config,
tx_manager_priority: Priority::Normal,
log_config,
postgres_endpoint,
polling_interval,
genesis_block: cli_config.genesis_block,
http_server_port: cli_config.http_server_port,
})
Expand All @@ -115,6 +119,10 @@ struct AuthorityClaimerCLI {
#[arg(long, env)]
pub postgres_endpoint: String,

/// Dtatabase polling interval
#[arg(long, env, default_value_t = 7)]
pub polling_interval: u64,

/// Genesis block for reading blockchain events
#[arg(long, env, default_value_t = 1)]
pub genesis_block: u64,
Expand Down
5 changes: 4 additions & 1 deletion cmd/authority-claimer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ pub async fn run(config: Config) -> Result<(), Box<dyn Error>> {

// Creating repository.
trace!("Creating the repository");
let repository = DefaultRepository::new(config.postgres_endpoint)?;
let repository = DefaultRepository::new(
config.postgres_endpoint,
config.polling_interval,
)?;

// Creating the conditional signer.
let conditional_signer =
Expand Down
14 changes: 12 additions & 2 deletions cmd/authority-claimer/src/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use sqlx::{
};
use std::sync::Arc;
use std::{fmt::Debug, time::Duration};
use tokio::time::sleep;

use crate::rollups_events::{Address, Hash, RollupsClaim};

Expand Down Expand Up @@ -49,11 +50,16 @@ pub enum RepositoryError {
pub struct DefaultRepository {
// Connection is not thread-safe, we use a connection pool
db_pool: Arc<Pool<Postgres>>,
// Polling interval in seconds
polling_interval: u64,
}

impl DefaultRepository {
/// Create database connection pool, wait until database server is available
pub fn new(endpoint: String) -> Result<Self, RepositoryError> {
pub fn new(
endpoint: String,
polling_interval: u64,
) -> Result<Self, RepositoryError> {
let connection = PgPoolOptions::new()
.acquire_timeout(REPOSITORY_ACQUIRE_TIMEOUT)
.min_connections(REPOSITORY_MIN_CONNECTIONS)
Expand All @@ -62,6 +68,7 @@ impl DefaultRepository {
.context(DatabaseSqlxSnafu)?;
Ok(Self {
db_pool: Arc::new(connection),
polling_interval,
})
}

Expand Down Expand Up @@ -132,7 +139,10 @@ impl Repository for DefaultRepository {
);
break;
}
None => continue,
None => {
sleep(Duration::from_secs(self.polling_interval)).await;
continue;
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type NodeConfig struct {
Auth Auth
AdvancerPollingInterval Duration
ValidatorPollingInterval Duration
ClaimerPollingInterval Duration
// Temporary
MachineServerVerbosity cartesimachine.ServerVerbosity
}
Expand Down Expand Up @@ -99,6 +100,7 @@ func FromEnv() NodeConfig {
}
config.AdvancerPollingInterval = GetAdvancerPollingInterval()
config.ValidatorPollingInterval = GetValidatorPollingInterval()
config.ClaimerPollingInterval = GetClaimerPollingInterval()
// Temporary.
config.MachineServerVerbosity = cartesimachine.ServerVerbosity(GetMachineServerVerbosity())
return config
Expand Down
6 changes: 6 additions & 0 deletions internal/config/generate/Config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ go-type = "Duration"
description = """
How many seconds the node will wait before trying to finish epochs for all applications."""

[rollups.CARTESI_CLAIMER_POLLING_INTERVAL]
default = "7"
go-type = "Duration"
description = """
How many seconds the node will wait before querying the database for new claims."""

#
# Blockchain
#
Expand Down
12 changes: 12 additions & 0 deletions internal/config/generated.go

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

1 change: 1 addition & 0 deletions internal/node/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func newAuthorityClaimer(c config.NodeConfig, workDir string) services.Service {
c.BlockchainFinalityOffset))
s.Env = append(s.Env, fmt.Sprintf("POSTGRES_ENDPOINT=%v",
fmt.Sprintf("%v", c.PostgresEndpoint.Value)))
s.Env = append(s.Env, fmt.Sprintf("POLLING_INTERVAL=%v", c.ClaimerPollingInterval.Seconds()))
s.Env = append(s.Env, fmt.Sprintf("INPUT_BOX_ADDRESS=%v", c.ContractsInputBoxAddress))
s.Env = append(s.Env, fmt.Sprintf("GENESIS_BLOCK=%v",
c.ContractsInputBoxDeploymentBlockNumber))
Expand Down

0 comments on commit 0e84584

Please sign in to comment.