Skip to content
Open
Show file tree
Hide file tree
Changes from 6 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
4 changes: 0 additions & 4 deletions .github/workflows/pr-main_l2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,6 @@ jobs:

- name: Run test
run: |
if [ "${{ matrix.based }}" = true ]; then
export INTEGRATION_TEST_SKIP_BASE_FEE_VAULT_CHECK=true
fi
sudo chmod -R a+rw crates/l2
cd crates/l2
RUST_LOG=info,ethrex_prover_lib=debug make init-prover-exec &
Expand Down Expand Up @@ -560,7 +557,6 @@ jobs:
tail -n 100 -f /tmp/ethrex.log &
tail -n 100 -f /tmp/prover.log &
export $(shell cat .env | xargs); \
INTEGRATION_TEST_SKIP_BASE_FEE_VAULT_CHECK=true \
PROPOSER_COINBASE_ADDRESS=0x0007a881CD95B1484fca47615B64803dad620C8d \
cargo test l2 --release -- --nocapture --test-threads=1

Expand Down
22 changes: 20 additions & 2 deletions crates/l2/networking/rpc/clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use ethrex_common::H256;
use ethrex_common::U256;
use ethrex_l2_common::l1_messages::L1MessageProof;
use ethrex_rpc::clients::eth::errors::GetL1BlobBaseFeeRequestError;
use ethrex_rpc::clients::eth::errors::GetL1FeeVaultAddressError;
use ethrex_rpc::clients::eth::errors::GetOperatorFeeError;
use ethrex_rpc::clients::eth::errors::GetOperatorFeeVaultAddressError;
use ethrex_rpc::types::block_identifier::BlockIdentifier;
Expand Down Expand Up @@ -57,7 +58,7 @@ pub async fn get_batch_by_number(
pub async fn get_base_fee_vault_address(
client: &EthClient,
block: BlockIdentifier,
) -> Result<Address, EthClientError> {
) -> Result<Option<Address>, EthClientError> {
let params = Some(vec![block.into()]);
let request = RpcRequest::new("ethrex_getBaseFeeVaultAddress", params);

Expand All @@ -74,7 +75,7 @@ pub async fn get_base_fee_vault_address(
pub async fn get_operator_fee_vault_address(
client: &EthClient,
block: BlockIdentifier,
) -> Result<Address, EthClientError> {
) -> Result<Option<Address>, EthClientError> {
let params = Some(vec![block.into()]);
let request = RpcRequest::new("ethrex_getOperatorFeeVaultAddress", params);

Expand Down Expand Up @@ -105,6 +106,23 @@ pub async fn get_operator_fee(
}
}

pub async fn get_l1_fee_vault_address(
client: &EthClient,
block: BlockIdentifier,
) -> Result<Option<Address>, EthClientError> {
let params = Some(vec![block.into()]);
let request = RpcRequest::new("ethrex_getL1FeeVaultAddress", params);

match client.send_request(request).await? {
RpcResponse::Success(result) => serde_json::from_value(result.result)
.map_err(GetL1FeeVaultAddressError::SerdeJSONError)
.map_err(EthClientError::from),
RpcResponse::Error(error_response) => {
Err(GetL1FeeVaultAddressError::RPCError(error_response.error.message).into())
}
}
}

pub async fn get_l1_blob_base_fee_per_gas(
client: &EthClient,
block_number: u64,
Expand Down
183 changes: 102 additions & 81 deletions crates/l2/networking/rpc/l2/fees.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use ethrex_rpc::types::block_identifier::BlockIdentifier;
use serde_json::Value;
use tracing::debug;

Expand All @@ -7,7 +8,7 @@ use crate::{
};

pub struct GetBaseFeeVaultAddress {
pub block_number: u64,
pub block: BlockIdentifier,
}

impl RpcHandler for GetBaseFeeVaultAddress {
Expand All @@ -16,34 +17,26 @@ impl RpcHandler for GetBaseFeeVaultAddress {
"No params provided".to_owned(),
))?;
if params.len() != 1 {
return Err(ethrex_rpc::RpcErr::BadParams(
"Expected 1 params".to_owned(),
))?;
return Err(ethrex_rpc::RpcErr::BadParams("Expected 1 param".to_owned()))?;
};
// Parse BlockNumber
let hex_str = serde_json::from_value::<String>(params[0].clone())
.map_err(|e| ethrex_rpc::RpcErr::BadParams(e.to_string()))?;

// Check that the BlockNumber is 0x prefixed
let hex_str = hex_str
.strip_prefix("0x")
.ok_or(ethrex_rpc::RpcErr::BadHexFormat(0))?;
let block = BlockIdentifier::parse(params[0].clone(), 0)?;

// Parse hex string
let block_number =
u64::from_str_radix(hex_str, 16).map_err(|_| ethrex_rpc::RpcErr::BadHexFormat(0))?;

Ok(GetBaseFeeVaultAddress { block_number })
Ok(GetBaseFeeVaultAddress { block })
}

async fn handle(&self, context: RpcApiContext) -> Result<Value, RpcErr> {
debug!(
"Requested BaseFeeVault with block number: {}",
self.block_number
);
debug!("Requested BaseFeeVault with block number: {}", self.block);
let block_number = match self
.block
.resolve_block_number(&context.l1_ctx.storage)
.await?
{
Some(block_number) => block_number,
_ => return Ok(Value::Null),
};
let base_fee_vault_address = context
.rollup_store
.get_fee_config_by_block(self.block_number)
.get_fee_config_by_block(block_number)
.await?
.and_then(|fc| fc.base_fee_vault);

Expand All @@ -60,7 +53,7 @@ impl RpcHandler for GetBaseFeeVaultAddress {
}

pub struct GetOperatorFeeVaultAddress {
pub block_number: u64,
pub block: BlockIdentifier,
}

impl RpcHandler for GetOperatorFeeVaultAddress {
Expand All @@ -69,34 +62,30 @@ impl RpcHandler for GetOperatorFeeVaultAddress {
"No params provided".to_owned(),
))?;
if params.len() != 1 {
return Err(ethrex_rpc::RpcErr::BadParams(
"Expected 1 params".to_owned(),
))?;
return Err(ethrex_rpc::RpcErr::BadParams("Expected 1 param".to_owned()))?;
};
// Parse BlockNumber
let hex_str = serde_json::from_value::<String>(params[0].clone())
.map_err(|e| ethrex_rpc::RpcErr::BadParams(e.to_string()))?;
let block = BlockIdentifier::parse(params[0].clone(), 0)?;

// Check that the BlockNumber is 0x prefixed
let hex_str = hex_str
.strip_prefix("0x")
.ok_or(ethrex_rpc::RpcErr::BadHexFormat(0))?;

// Parse hex string
let block_number =
u64::from_str_radix(hex_str, 16).map_err(|_| ethrex_rpc::RpcErr::BadHexFormat(0))?;

Ok(GetOperatorFeeVaultAddress { block_number })
Ok(GetOperatorFeeVaultAddress { block })
}

async fn handle(&self, context: RpcApiContext) -> Result<Value, RpcErr> {
debug!(
"Requested OperatorFeeVault with block number: {}",
self.block_number
self.block
);
let block_number = match self
.block
.resolve_block_number(&context.l1_ctx.storage)
.await?
{
Some(block_number) => block_number,
_ => return Ok(Value::Null),
};
let operator_fee_config = context
.rollup_store
.get_fee_config_by_block(self.block_number)
.get_fee_config_by_block(block_number)
.await?
.and_then(|fc| fc.operator_fee_config);

Expand All @@ -113,7 +102,7 @@ impl RpcHandler for GetOperatorFeeVaultAddress {
}

pub struct GetOperatorFee {
pub block_number: u64,
pub block: BlockIdentifier,
}

impl RpcHandler for GetOperatorFee {
Expand All @@ -122,34 +111,26 @@ impl RpcHandler for GetOperatorFee {
"No params provided".to_owned(),
))?;
if params.len() != 1 {
return Err(ethrex_rpc::RpcErr::BadParams(
"Expected 1 params".to_owned(),
))?;
return Err(ethrex_rpc::RpcErr::BadParams("Expected 1 param".to_owned()))?;
};
// Parse BlockNumber
let hex_str = serde_json::from_value::<String>(params[0].clone())
.map_err(|e| ethrex_rpc::RpcErr::BadParams(e.to_string()))?;

// Check that the BlockNumber is 0x prefixed
let hex_str = hex_str
.strip_prefix("0x")
.ok_or(ethrex_rpc::RpcErr::BadHexFormat(0))?;
let block = BlockIdentifier::parse(params[0].clone(), 0)?;

// Parse hex string
let block_number =
u64::from_str_radix(hex_str, 16).map_err(|_| ethrex_rpc::RpcErr::BadHexFormat(0))?;

Ok(GetOperatorFee { block_number })
Ok(GetOperatorFee { block })
}

async fn handle(&self, context: RpcApiContext) -> Result<Value, RpcErr> {
debug!(
"Requested OperatorFee with block number: {}",
self.block_number
);
debug!("Requested OperatorFee with block number: {}", self.block);
let block_number = match self
.block
.resolve_block_number(&context.l1_ctx.storage)
.await?
{
Some(block_number) => block_number,
_ => return Ok(Value::Null),
};
let operator_fee_per_gas = context
.rollup_store
.get_fee_config_by_block(self.block_number)
.get_fee_config_by_block(block_number)
.await?
.and_then(|fc| fc.operator_fee_config)
.map(|config| config.operator_fee_per_gas)
Expand All @@ -160,8 +141,53 @@ impl RpcHandler for GetOperatorFee {
}
}

pub struct GetL1FeeVaultAddress {
pub block: BlockIdentifier,
}

impl RpcHandler for GetL1FeeVaultAddress {
fn parse(params: &Option<Vec<Value>>) -> Result<GetL1FeeVaultAddress, RpcErr> {
let params = params.as_ref().ok_or(ethrex_rpc::RpcErr::BadParams(
"No params provided".to_owned(),
))?;
if params.len() != 1 {
return Err(ethrex_rpc::RpcErr::BadParams("Expected 1 param".to_owned()))?;
};
let block = BlockIdentifier::parse(params[0].clone(), 0)?;

Ok(GetL1FeeVaultAddress { block })
}

async fn handle(&self, context: RpcApiContext) -> Result<Value, RpcErr> {
debug!("Requested L1FeeVault with block number: {}", self.block);
let block_number = match self
.block
.resolve_block_number(&context.l1_ctx.storage)
.await?
{
Some(block_number) => block_number,
_ => return Ok(Value::Null),
};
let l1_fee_config = context
.rollup_store
.get_fee_config_by_block(block_number)
.await?
.and_then(|fc| fc.l1_fee_config);

Ok(
serde_json::to_value(l1_fee_config.map(|config| format!("{:#x}", config.l1_fee_vault)))
.map_err(|e| {
ethrex_rpc::RpcErr::Internal(format!(
"Failed to serialize l1 fee vault address: {}",
e
))
})?,
)
}
}

pub struct GetL1BlobBaseFeeRequest {
pub block_number: u64,
pub block: BlockIdentifier,
}

impl RpcHandler for GetL1BlobBaseFeeRequest {
Expand All @@ -170,32 +196,27 @@ impl RpcHandler for GetL1BlobBaseFeeRequest {
"No params provided".to_owned(),
))?;
if params.len() != 1 {
return Err(ethrex_rpc::RpcErr::BadParams(
"Expected 1 params".to_owned(),
))?;
return Err(ethrex_rpc::RpcErr::BadParams("Expected 1 param".to_owned()))?;
};
// Parse BlockNumber
let hex_str = serde_json::from_value::<String>(params[0].clone())
.map_err(|e| ethrex_rpc::RpcErr::BadParams(e.to_string()))?;

// Check that the BlockNumber is 0x prefixed
let hex_str = hex_str
.strip_prefix("0x")
.ok_or(ethrex_rpc::RpcErr::BadHexFormat(0))?;
let block = BlockIdentifier::parse(params[0].clone(), 0)?;

// Parse hex string
let block_number =
u64::from_str_radix(hex_str, 16).map_err(|_| ethrex_rpc::RpcErr::BadHexFormat(0))?;

Ok(GetL1BlobBaseFeeRequest { block_number })
Ok(GetL1BlobBaseFeeRequest { block })
}

async fn handle(&self, context: RpcApiContext) -> Result<Value, RpcErr> {
debug!("Requested L1BlobBaseFee for block {}", self.block_number);
debug!("Requested L1BlobBaseFee for block {}", self.block);
let block_number = match self
.block
.resolve_block_number(&context.l1_ctx.storage)
.await?
{
Some(block_number) => block_number,
_ => return Ok(Value::Null),
};

let l1_blob_base_fee = context
.rollup_store
.get_fee_config_by_block(self.block_number)
.get_fee_config_by_block(block_number)
.await?
.and_then(|fc| fc.l1_fee_config)
.map(|cfg| cfg.l1_fee_per_blob_gas)
Expand Down
4 changes: 3 additions & 1 deletion crates/l2/networking/rpc/rpc.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::l2::batch::{BatchNumberRequest, GetBatchByBatchNumberRequest};
use crate::l2::execution_witness::handle_execution_witness;
use crate::l2::fees::{
GetBaseFeeVaultAddress, GetL1BlobBaseFeeRequest, GetOperatorFee, GetOperatorFeeVaultAddress,
GetBaseFeeVaultAddress, GetL1BlobBaseFeeRequest, GetL1FeeVaultAddress, GetOperatorFee,
GetOperatorFeeVaultAddress,
};
use crate::l2::l1_message::GetL1MessageProof;
use crate::utils::{RpcErr, RpcNamespace, resolve_namespace};
Expand Down Expand Up @@ -232,6 +233,7 @@ pub async fn map_l2_requests(req: &RpcRequest, context: RpcApiContext) -> Result
"ethrex_getBaseFeeVaultAddress" => GetBaseFeeVaultAddress::call(req, context).await,
"ethrex_getOperatorFeeVaultAddress" => GetOperatorFeeVaultAddress::call(req, context).await,
"ethrex_getOperatorFee" => GetOperatorFee::call(req, context).await,
"ethrex_getL1FeeVaultAddress" => GetL1FeeVaultAddress::call(req, context).await,
"ethrex_getL1BlobBaseFee" => GetL1BlobBaseFeeRequest::call(req, context).await,
unknown_ethrex_l2_method => {
Err(ethrex_rpc::RpcErr::MethodNotFound(unknown_ethrex_l2_method.to_owned()).into())
Expand Down
Loading