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: Constraints API v0 #49

Merged
merged 34 commits into from
Nov 29, 2024
Merged
Changes from 4 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
22a13a8
feat: constraints-api-v0
thedevbirb Nov 6, 2024
f2f2fcf
docs(constraints-api): fix broken links
thedevbirb Nov 7, 2024
dc2919d
fix(constraints-api-v0): drop validator_delegations migration, curren…
thedevbirb Nov 8, 2024
40cda8e
feat(constraints-api): add startup configuration
thedevbirb Nov 8, 2024
38c8e8f
Merge pull request #22 from chainbound/lore/feat/constraints-api-config
merklefruit Nov 8, 2024
ffc5e5e
introduce max_block_value_to_verify in constraints config
gd-0 Nov 11, 2024
61d611f
address PR comments + other fixes
gd-0 Nov 11, 2024
b531d46
feat: import website from aestus upstream, solve conflicts
merklefruit Nov 11, 2024
b66e136
chore: re-added cargo.lock
merklefruit Nov 11, 2024
9d7e97f
chore: run fmt clippy checks
merklefruit Nov 11, 2024
f995522
chore: default run on unspecified ip
merklefruit Nov 11, 2024
30c5cb5
chore: rm aestus naming and links from web page
merklefruit Nov 11, 2024
8ba703c
chore: gattaca logo
merklefruit Nov 11, 2024
25d777e
chore: reverted changes to dockerfile + tls dependencies
merklefruit Nov 11, 2024
c864a9e
chore: addressed review
merklefruit Nov 11, 2024
9ee178a
chore: logo size
merklefruit Nov 11, 2024
ea15474
fix(tests): make them compile
thedevbirb Nov 12, 2024
ae59749
chore(api): should verify proofs logic
thedevbirb Nov 12, 2024
00b5bcb
Merge pull request #23 from gd-0/dont-enforce-constraints-if-block-va…
thedevbirb Nov 12, 2024
9003727
chore(website): fmt
thedevbirb Nov 12, 2024
0aee3e8
Merge pull request #25 from chainbound/feat/import-website
thedevbirb Nov 12, 2024
30c66ac
fix(db): retry creating pool handle
merklefruit Nov 12, 2024
7a0342f
fix(db): don't panic upon failing migrations once
merklefruit Nov 12, 2024
44b1823
fix(website): rm blob related fields from table
merklefruit Nov 12, 2024
f778527
Merge pull request #26 from chainbound/fix/retry-db-pool
thedevbirb Nov 12, 2024
b78427d
fix(ssz): restore SSZ backwards compatibility on SignedBuilderSubmiss…
thedevbirb Nov 15, 2024
cdb2795
Merge pull request #27 from chainbound/lore/fix/ssz
merklefruit Nov 18, 2024
ca4d329
fix(ssz): order of enum variants is important
thedevbirb Nov 26, 2024
dd97cb2
refactor(api/builder): submit_block(_with_proofs) now have the same impl
thedevbirb Nov 15, 2024
bd2b542
Merge pull request #28 from chainbound/lore/refactor/constraints-api
thedevbirb Nov 27, 2024
f81a92e
fix(constraints-api): don't read from db for checking proposer duties…
thedevbirb Nov 27, 2024
242607c
Merge pull request #30 from chainbound/lore/fix/db-read-constraints-api
thedevbirb Nov 28, 2024
5848eec
fix(constraints-api): review constraints saving logic
thedevbirb Nov 27, 2024
abf32f5
Merge pull request #29 from chainbound/lore/fix/submit-constraints-logic
thedevbirb Nov 28, 2024
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
1 change: 1 addition & 0 deletions Cargo.lock

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

4 changes: 1 addition & 3 deletions crates/api/src/service.rs
Original file line number Diff line number Diff line change
@@ -36,9 +36,7 @@ const PAYLOAD_ATTRIBUTE_CHANNEL_SIZE: usize = 300;
pub struct ApiService {}

impl ApiService {
pub async fn run(mut config: RelayConfig) {
let postgres_db = PostgresDatabaseService::from_relay_config(&config).unwrap();
postgres_db.run_migrations().await;
pub async fn run(mut config: RelayConfig, postgres_db: PostgresDatabaseService) {
postgres_db.init_region(&config).await;
postgres_db
.store_builders_info(&config.builders)
1 change: 1 addition & 0 deletions crates/cmd/Cargo.toml
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ helix-api.workspace = true
helix-website.workspace = true
helix-common.workspace = true
helix-utils.workspace = true
helix-database.workspace = true

[target.'cfg(not(target_env = "msvc"))'.dependencies]
tikv-jemallocator = { version = "0.5", features = ["profiling"] }
18 changes: 16 additions & 2 deletions crates/cmd/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use helix_api::service::ApiService;
use helix_common::{LoggingConfig, RelayConfig};
use helix_database::postgres::postgres_db_service::PostgresDatabaseService;
use helix_utils::set_panic_hook;
use helix_website::website_service::WebsiteService;

@@ -59,12 +60,25 @@ async fn run() {

let mut handles = Vec::new();

let postgres_db = PostgresDatabaseService::from_relay_config(&config).await;

// Try to run database migrations until they succeed
loop {
match postgres_db.run_migrations().await {
Ok(_) => break,
Err(e) => {
tracing::error!("Failed to run migrations: {:?}", e);
tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;
}
}
}

// Start the API service
handles.push(tokio::spawn(ApiService::run(config.clone())));
handles.push(tokio::spawn(ApiService::run(config.clone(), postgres_db.clone())));

// Start the website service (if enabled)
if config.website.enabled {
handles.push(tokio::spawn(WebsiteService::run_loop(config.clone())));
handles.push(tokio::spawn(WebsiteService::run_loop(config.clone(), postgres_db.clone())));
}

futures::future::join_all(handles).await;
31 changes: 19 additions & 12 deletions crates/database/src/postgres/postgres_db_service.rs
Original file line number Diff line number Diff line change
@@ -85,9 +85,7 @@ impl PostgresDatabaseService {
})
}

pub fn from_relay_config(
relay_config: &RelayConfig,
) -> Result<Self, Box<dyn std::error::Error>> {
pub async fn from_relay_config(relay_config: &RelayConfig) -> Self {
let mut cfg = Config::new();
cfg.host = Some(relay_config.postgres.hostname.clone());
cfg.port = Some(relay_config.postgres.port);
@@ -96,29 +94,38 @@ impl PostgresDatabaseService {
cfg.password = Some(relay_config.postgres.password.clone());
cfg.manager = Some(ManagerConfig { recycling_method: RecyclingMethod::Fast });

let pool = cfg.create_pool(None, NoTls)?;
Ok(PostgresDatabaseService {
let pool = loop {
match cfg.create_pool(None, NoTls) {
Ok(pool) => break pool,
Err(e) => {
error!("Error creating pool: {}", e);
tokio::time::sleep(std::time::Duration::from_secs(5)).await;
}
}
};

PostgresDatabaseService {
validator_registration_cache: Arc::new(DashMap::new()),
pending_validator_registrations: Arc::new(DashSet::new()),
known_validators_cache: Arc::new(DashSet::new()),
validator_pool_cache: Arc::new(DashMap::new()),
region: relay_config.postgres.region,
pool: Arc::new(pool),
})
}
}

pub async fn run_migrations(&self) {
let mut conn = self.pool.get().await.unwrap();
pub async fn run_migrations(&self) -> Result<(), Box<dyn std::error::Error>> {
let mut conn = self.pool.get().await?;

let client = conn.deref_mut().deref_mut();
match run_migrations_async(client).await {
Ok(report) => {
info!("Applied migrations: {}", report.applied_migrations().len());
info!("Migrations report: {:?}", report);
Ok(())
}
Err(e) => {
panic!("Error applying migrations: {}", e);
}
};
Err(e) => Err(e),
}
}

pub async fn init_region(&self, config: &RelayConfig) {
3 changes: 0 additions & 3 deletions crates/website/src/models.rs
Original file line number Diff line number Diff line change
@@ -13,9 +13,6 @@ pub struct DeliveredPayload {
pub block_number: u64,
pub epoch: u64,
pub num_txs: usize,
pub num_blobs: usize,
pub blob_gas_used: u64,
pub excess_blob_gas: u64,
}

impl DeliveredPayload {
8 changes: 1 addition & 7 deletions crates/website/src/postgres_db_website.rs
Original file line number Diff line number Diff line change
@@ -47,9 +47,6 @@ impl FromRow for DeliveredPayload {
},
block_number: parse_i32_to_u64(row.get::<&str, i32>("block_number"))?,
num_txs: parse_i32_to_usize(row.get::<&str, i32>("num_txs"))?,
num_blobs: parse_i32_to_usize(row.get::<&str, i32>("num_blobs"))?,
blob_gas_used: parse_i32_to_u64(row.get::<&str, i32>("blob_gas_used"))?,
excess_blob_gas: parse_i32_to_u64(row.get::<&str, i32>("excess_blob_gas"))?,
epoch: parse_i32_to_u64(row.get::<&str, i32>("slot_number"))? / 32, //Calculate directly
})
}
@@ -73,10 +70,7 @@ impl WebsiteDatabaseService for PostgresDatabaseService {
block_submission.gas_used,
block_submission.value,
block_submission.num_txs,
block_submission.block_number,
block_submission.num_blobs,
block_submission.blob_gas_used,
block_submission.excess_blob_gas
block_submission.block_number
FROM
delivered_payload
INNER JOIN
14 changes: 6 additions & 8 deletions crates/website/src/website_service.rs
Original file line number Diff line number Diff line change
@@ -23,9 +23,9 @@ use hex::encode as hex_encode;
pub struct WebsiteService {}

impl WebsiteService {
pub async fn run_loop(config: RelayConfig) {
pub async fn run_loop(config: RelayConfig, postgres_db: PostgresDatabaseService) {
loop {
match WebsiteService::run(config.clone()).await {
match WebsiteService::run(config.clone(), postgres_db.clone()).await {
Ok(_) => {
tracing::error!("Website service unexpectedly completed. Restarting...")
}
@@ -35,15 +35,13 @@ impl WebsiteService {
}
}

async fn run(config: RelayConfig) -> Result<(), Box<dyn std::error::Error>> {
async fn run(
config: RelayConfig,
postgres_db: PostgresDatabaseService,
) -> Result<(), Box<dyn std::error::Error>> {
info!("Starting WebsiteService");

// Initialize PostgresDB
//
// NOTE: We don't need to run migrations as the ApiService already does that.
let postgres_db = PostgresDatabaseService::from_relay_config(&config).unwrap();
let db = Arc::new(postgres_db);
debug!("PostgresDB initialized");

// ChainInfo
let chain_info = Arc::new(match config.network_config {
4 changes: 0 additions & 4 deletions crates/website/templates/index.html
Original file line number Diff line number Diff line change
@@ -240,7 +240,6 @@ <h2>
</a>
</th>
<th>Num txs</th>
<th>Blobs</th>
<th>Block hash</th>
<th></th>
</tr>
@@ -255,9 +254,6 @@ <h2>
<td>{{ payload.block_number|pretty_int }}</td>
<td>{{ payload.bid_trace.value|wei_to_eth }}</td>
<td>{{ payload.num_txs }}</td>
<td>
<div title="Blob Gas Used: {{ payload.blob_gas_used }}">{{ payload.num_blobs }}</div>
</td>
<td>{{ payload.bid_trace.block_hash }}</td>
<td>
<div class="icons-container">