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

Accept WebSockets provider for fee contract proxy check #2254

Merged
merged 1 commit into from
Nov 5, 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
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ ESPRESSO_SEQUENCER_GENESIS_FILE=/genesis/demo.toml
ESPRESSO_SEQUENCER_L1_PORT=8545
ESPRESSO_SEQUENCER_L1_WS_PORT=8546
ESPRESSO_SEQUENCER_L1_PROVIDER=http://demo-l1-network:${ESPRESSO_SEQUENCER_L1_PORT}
ESPRESSO_SEQUENCER_L1_WS_PROVIDER=http://demo-l1-network:${ESPRESSO_SEQUENCER_L1_WS_PORT}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jbearer is this http:// on purpose?

ESPRESSO_NODE_VALIDATOR_PORT=9000

# Only allow 1 block to be processed for events at a time, simulating a very bad L1 provider.
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ services:
- ESPRESSO_SEQUENCER_POSTGRES_USER=root
- ESPRESSO_SEQUENCER_POSTGRES_PASSWORD=password
- ESPRESSO_SEQUENCER_POSTGRES_DATABASE=sequencer
- ESPRESSO_SEQUENCER_L1_PROVIDER
- ESPRESSO_SEQUENCER_L1_PROVIDER=$ESPRESSO_SEQUENCER_L1_WS_PROVIDER
- ESPRESSO_SEQUENCER_L1_EVENTS_MAX_BLOCK_RANGE
- ESPRESSO_STATE_RELAY_SERVER_URL
- ESPRESSO_SEQUENCER_PRIVATE_STAKING_KEY=$ESPRESSO_DEMO_SEQUENCER_STAKING_PRIVATE_KEY_1
Expand Down Expand Up @@ -388,7 +388,7 @@ services:
- ESPRESSO_SEQUENCER_API_PORT
- ESPRESSO_SEQUENCER_MAX_CONNECTIONS
- ESPRESSO_SEQUENCER_STATE_PEERS=http://sequencer4:$ESPRESSO_SEQUENCER_API_PORT
- ESPRESSO_SEQUENCER_L1_PROVIDER
- ESPRESSO_SEQUENCER_L1_PROVIDER=$ESPRESSO_SEQUENCER_L1_WS_PROVIDER
- ESPRESSO_SEQUENCER_L1_EVENTS_MAX_BLOCK_RANGE
- ESPRESSO_STATE_RELAY_SERVER_URL
- ESPRESSO_SEQUENCER_PRIVATE_STAKING_KEY=$ESPRESSO_DEMO_SEQUENCER_STAKING_PRIVATE_KEY_3
Expand Down
2 changes: 1 addition & 1 deletion hotshot-state-prover/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl StateProverConfig {
pub async fn validate_light_client_contract(&self) -> anyhow::Result<()> {
let provider = Provider::<Http>::try_from(self.provider.to_string())?;

if !is_proxy_contract(provider, self.light_client_address).await? {
if !is_proxy_contract(&provider, self.light_client_address).await? {
anyhow::bail!("Light Client contract's address is not a proxy");
}

Expand Down
3 changes: 2 additions & 1 deletion process-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ environment:
- ESPRESSO_SEQUENCER_L1_PROVIDER=http://localhost:$ESPRESSO_SEQUENCER_L1_PORT
- ESPRESSO_SEQUENCER_GENESIS_FILE=data/genesis/demo.toml
- ESPRESSO_BUILDER_GENESIS_FILE=data/genesis/demo.toml
- ESPRESSO_DEMO_L1_HTTP_PROVIDER=$ESPRESSO_SEQUENCER_L1_PROVIDER
- ESPRESSO_STATE_RELAY_SERVER_URL=http://localhost:$ESPRESSO_STATE_RELAY_SERVER_PORT
- QUERY_SERVICE_URI=http://localhost:$ESPRESSO_SEQUENCER1_API_PORT/v0/
- NODE_VALIDATOR_URI=ws://localhost:$ESPRESSO_NODE_VALIDATOR_PORT/v0/
Expand Down Expand Up @@ -191,6 +190,7 @@ processes:
- ESPRESSO_SEQUENCER_IDENTITY_LATITUDE=39.0742
- ESPRESSO_SEQUENCER_IDENTITY_LONGITUDE=21.8243
- ESPRESSO_SEQUENCER_PUBLIC_API_URL=http://localhost:$ESPRESSO_SEQUENCER1_API_PORT/
- ESPRESSO_SEQUENCER_L1_PROVIDER=ws://localhost:$ESPRESSO_SEQUENCER_L1_WS_PORT
depends_on:
orchestrator:
condition: process_healthy
Expand Down Expand Up @@ -285,6 +285,7 @@ processes:
- ESPRESSO_SEQUENCER_IDENTITY_LATITUDE=35.8617
- ESPRESSO_SEQUENCER_IDENTITY_LONGITUDE=104.1954
- ESPRESSO_SEQUENCER_PUBLIC_API_URL=http://localhost:$ESPRESSO_SEQUENCER3_API_PORT/
- ESPRESSO_SEQUENCER_L1_PROVIDER=ws://localhost:$ESPRESSO_SEQUENCER_L1_WS_PORT
depends_on:
orchestrator:
condition: process_healthy
Expand Down
2 changes: 1 addition & 1 deletion sequencer/src/bin/espresso-dev-node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ async fn main() -> anyhow::Result<()> {
.get_contract_address(Contract::LightClientProxy)
.unwrap();

if !is_proxy_contract(provider.clone(), light_client_address)
if !is_proxy_contract(&provider, light_client_address)
.await
.expect("Failed to determine if light client contract is a proxy")
{
Expand Down
26 changes: 16 additions & 10 deletions sequencer/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ use std::{

use anyhow::Context;
use espresso_types::{
v0_3::ChainConfig, FeeAccount, FeeAmount, GenesisHeader, L1BlockInfo, Timestamp, Upgrade,
UpgradeType,
};
use ethers::{
providers::{Http, Provider},
types::H160,
v0_3::ChainConfig, FeeAccount, FeeAmount, GenesisHeader, L1BlockInfo, L1Client, Timestamp,
Upgrade, UpgradeType,
};
use ethers::types::H160;
use sequencer_utils::deployer::is_proxy_contract;
use serde::{Deserialize, Serialize};
use vbs::version::Version;
Expand Down Expand Up @@ -89,22 +86,31 @@ impl Genesis {

impl Genesis {
pub async fn validate_fee_contract(&self, l1_rpc_url: String) -> anyhow::Result<()> {
let provider = Provider::<Http>::try_from(l1_rpc_url)?;
let l1 = L1Client::new(l1_rpc_url.parse().context("invalid url")?)
.await
.context("connecting L1 client")?;

if let Some(fee_contract_address) = self.chain_config.fee_contract {
if !is_proxy_contract(provider.clone(), fee_contract_address).await? {
if !is_proxy_contract(l1.provider(), fee_contract_address)
.await
.context("checking if fee contract is a proxy")?
{
anyhow::bail!("Fee contract's address is not a proxy");
}
}

// now iterate over each upgrade type and validate the fee contract if it exists
for upgrade in self.upgrades.values() {
for (version, upgrade) in &self.upgrades {
match &upgrade.upgrade_type {
UpgradeType::Fee { chain_config } | UpgradeType::Marketplace { chain_config } => {
if let Some(fee_contract_address) = chain_config.fee_contract {
if fee_contract_address == H160::zero() {
anyhow::bail!("Fee contract cannot use the zero address");
} else if !is_proxy_contract(provider.clone(), fee_contract_address).await?
} else if !is_proxy_contract(l1.provider(), fee_contract_address)
.await
.context(format!(
"checking if fee contract is a proxy in upgrade {version}",
))?
{
anyhow::bail!("Fee contract's address is not a proxy");
}
Expand Down
4 changes: 4 additions & 0 deletions types/src/v0/impls/l1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ impl L1Client {
}
}

pub fn provider(&self) -> &impl Middleware<Error: 'static> {
&self.provider
}

fn update_loop(&self) -> impl Future<Output = ()> {
let rpc = self.provider.clone();
let retry_delay = self.retry_delay;
Expand Down
23 changes: 17 additions & 6 deletions types/src/v0/v0_1/l1.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use crate::parse_duration;
use async_broadcast::{InactiveReceiver, Sender};
use async_std::{
sync::{Arc, Mutex},
task::JoinHandle,
};
use clap::Parser;
use ethers::{
prelude::{H256, U256},
providers::{Http, Ws, Provider},
providers::{Http, Provider, Ws},
};
use async_broadcast::{Sender, InactiveReceiver};
use async_std::{sync::{Arc, Mutex}, task::JoinHandle};
use clap::Parser;
use lru::LruCache;
use serde::{Deserialize, Serialize};
use std::{num::NonZeroUsize, time::Duration};
Expand Down Expand Up @@ -60,11 +63,19 @@ pub struct L1ClientOptions {
pub l1_polling_interval: Duration,

/// Maximum number of L1 blocks to keep in cache at once.
#[clap(long, env = "ESPRESSO_SEQUENCER_L1_BLOCKS_CACHE_SIZE", default_value = "100")]
#[clap(
long,
env = "ESPRESSO_SEQUENCER_L1_BLOCKS_CACHE_SIZE",
default_value = "100"
)]
pub l1_blocks_cache_size: NonZeroUsize,

/// Number of L1 events to buffer before discarding.
#[clap(long, env = "ESPRESSO_SEQUENCER_L1_EVENTS_CHANNEL_CAPACITY", default_value = "100")]
#[clap(
long,
env = "ESPRESSO_SEQUENCER_L1_EVENTS_CHANNEL_CAPACITY",
default_value = "100"
)]
pub l1_events_channel_capacity: usize,

/// Maximum number of L1 blocks that can be scanned for events in a single query.
Expand Down
6 changes: 3 additions & 3 deletions utils/src/deployer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ pub async fn deploy(
.await?;

// confirm that the implementation address is the address of the light client contract deployed above
if !is_proxy_contract(provider.clone(), light_client_proxy_address)
if !is_proxy_contract(&provider, light_client_proxy_address)
.await
.expect("Failed to determine if light contract is a proxy")
{
Expand Down Expand Up @@ -405,7 +405,7 @@ pub async fn deploy(
.await?;

// confirm that the implementation address is the address of the fee contract deployed above
if !is_proxy_contract(provider.clone(), fee_contract_proxy_address)
if !is_proxy_contract(&provider, fee_contract_proxy_address)
.await
.expect("Failed to determine if fee contract is a proxy")
{
Expand Down Expand Up @@ -437,7 +437,7 @@ fn should_deploy(group: ContractGroup, only: &Option<Vec<ContractGroup>>) -> boo
}

pub async fn is_proxy_contract(
provider: Provider<Http>,
provider: &impl Middleware<Error: 'static>,
proxy_address: H160,
) -> anyhow::Result<bool> {
// confirm that the proxy_address is a proxy
Expand Down