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

Replace H160 in config and cli options of relayer by Bytes20 #1951

Closed
Closed
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Breaking
- [#1951](https://github.com/FuelLabs/fuel-core/pull/1951): Replace `H160` in config and cli options of relayer by `Bytes20` of `fuel-types`

## [Version 0.29.0]

### Added
- [#1889](https://github.com/FuelLabs/fuel-core/pull/1889): Add new `FuelGasPriceProvider` that receives the gas price algorithm from a `GasPriceService`


### Changed
- [#1942](https://github.com/FuelLabs/fuel-core/pull/1942): Sequential relayer's commits.
- [#1952](https://github.com/FuelLabs/fuel-core/pull/1952): Change tip sorting to ratio between tip and max gas sorting in txpool
Expand Down
15 changes: 4 additions & 11 deletions bin/fuel-core/src/cli/run/relayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@ use clap::{
};
use core::time::Duration;
use fuel_core::{
relayer::{
Config,
H160,
},
relayer::Config,
types::blockchain::primitives::DaBlockHeight,
};
use std::str::FromStr;
use fuel_core_types::fuel_types::Bytes20;

#[derive(Debug, Clone, Args)]
pub struct RelayerArgs {
Expand All @@ -28,8 +25,8 @@ pub struct RelayerArgs {
pub relayer: Option<url::Url>,

/// Ethereum contract address. Create EthAddress into fuel_types
#[arg(long = "relayer-v2-listening-contracts", value_parser = parse_h160, env)]
pub eth_v2_listening_contracts: Vec<H160>,
#[arg(long = "relayer-v2-listening-contracts", env)]
pub eth_v2_listening_contracts: Vec<Bytes20>,

/// Number of da block that the contract is deployed at.
#[clap(long = "relayer-da-deploy-height", default_value_t = Config::DEFAULT_DA_DEPLOY_HEIGHT, env)]
Expand All @@ -53,10 +50,6 @@ pub struct RelayerArgs {
pub syncing_log_frequency_secs: u64,
}

pub fn parse_h160(input: &str) -> Result<H160, <H160 as FromStr>::Err> {
H160::from_str(input)
}

impl RelayerArgs {
pub fn into_config(self) -> Option<Config> {
if !self.enable_relayer {
Expand Down
12 changes: 6 additions & 6 deletions crates/services/relayer/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use ethers_contract::EthEvent;
use ethers_core::types::{
H160,
H256,
use ethers_core::types::H256;
use fuel_core_types::{
blockchain::primitives::DaBlockHeight,
fuel_types::Bytes20,
};
use fuel_core_types::blockchain::primitives::DaBlockHeight;
use once_cell::sync::Lazy;
use std::{
str::FromStr,
Expand All @@ -26,7 +26,7 @@ pub struct Config {
pub relayer: Option<url::Url>,
// TODO: Create `EthAddress` into `fuel_core_types`.
/// Ethereum contract address.
pub eth_v2_listening_contracts: Vec<H160>,
pub eth_v2_listening_contracts: Vec<Bytes20>,
/// Number of pages or blocks containing logs that
/// should be downloaded in a single call to the da layer
pub log_page_size: u64,
Expand Down Expand Up @@ -58,7 +58,7 @@ impl Default for Config {
Self {
da_deploy_height: DaBlockHeight::from(Self::DEFAULT_DA_DEPLOY_HEIGHT),
relayer: None,
eth_v2_listening_contracts: vec![H160::from_str(
eth_v2_listening_contracts: vec![Bytes20::from_str(
"0x03E4538018285e1c03CCce2F92C9538c87606911",
)
.unwrap()],
Expand Down
1 change: 0 additions & 1 deletion crates/services/relayer/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use ethers_core::types::{
Log,
SyncingStatus,
ValueOrArray,
H160,
};
use ethers_providers::{
Http,
Expand Down
9 changes: 7 additions & 2 deletions crates/services/relayer/src/service/get_logs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use super::*;
use ethers_core::types::H160;
use fuel_core_types::{
entities::RelayedTransaction,
fuel_types::Bytes20,
services::relayer::Event,
};
use futures::TryStreamExt;
Expand All @@ -18,7 +20,7 @@ pub struct DownloadedLogs {
/// Download the logs from the DA layer.
pub(crate) fn download_logs<'a, P>(
eth_sync_gap: &state::EthSyncGap,
contracts: Vec<H160>,
contracts: Vec<Bytes20>,
eth_node: &'a P,
page_size: u64,
) -> impl futures::Stream<Item = Result<DownloadedLogs, ProviderError>> + 'a
Expand All @@ -29,7 +31,10 @@ where
futures::stream::try_unfold(
eth_sync_gap.page(page_size),
move |page: Option<state::EthSyncPage>| {
let contracts = contracts.clone();
let contracts = contracts
.iter()
.map(|c| H160::from_slice(c.as_slice()))
.collect();
async move {
match page {
None => Ok(None),
Expand Down
8 changes: 4 additions & 4 deletions crates/services/relayer/src/service/get_logs/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ fn message(nonce: u64, block_number: u64, contract_address: u32, index: u64) ->
..Default::default()
};
let mut log = message.into_log();
log.address = u32_to_contract(contract_address);
log.address = H160::from_slice(u32_to_contract(contract_address).as_slice());
log.block_number = Some(block_number.into());
log.log_index = Some(index.into());
log
}

fn contracts(c: &[u32]) -> Vec<H160> {
fn contracts(c: &[u32]) -> Vec<Bytes20> {
c.iter().copied().map(u32_to_contract).collect()
}

fn u32_to_contract(n: u32) -> H160 {
fn u32_to_contract(n: u32) -> Bytes20 {
let address: [u8; 20] = n
.to_ne_bytes()
.into_iter()
Expand All @@ -72,7 +72,7 @@ fn u32_to_contract(n: u32) -> H160 {
#[derive(Clone, Debug)]
struct Input {
eth_gap: RangeInclusive<u64>,
c: Vec<H160>,
c: Vec<Bytes20>,
m: Vec<Log>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
Expand Down
4 changes: 3 additions & 1 deletion crates/services/relayer/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use fuel_core_relayer::{
LogTestHelper,
},
Config,
H160,
};
use fuel_core_services::Service;

Expand Down Expand Up @@ -284,7 +285,8 @@ impl TestContext {
}

fn given_logs(&mut self, mut logs: Vec<Log>) {
let contract_address = self.config.eth_v2_listening_contracts[0];
let contract_address =
H160::from_slice(self.config.eth_v2_listening_contracts[0].as_slice());
for log in &mut logs {
log.address = contract_address;
}
Expand Down
17 changes: 8 additions & 9 deletions tests/tests/relayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,10 @@ use fuel_core_client::client::{
FuelClient,
};
use fuel_core_poa::service::Mode;
use fuel_core_relayer::{
test_helpers::{
middleware::MockMiddleware,
EvtToLog,
LogTestHelper,
},
H160,
use fuel_core_relayer::test_helpers::{
middleware::MockMiddleware,
EvtToLog,
LogTestHelper,
};
use fuel_core_storage::{
tables::Messages,
Expand All @@ -52,6 +49,7 @@ use fuel_core_types::{
Nonce,
},
};
use fuel_types::Bytes20;
use hyper::{
service::{
make_service_fn,
Expand All @@ -62,6 +60,7 @@ use hyper::{
Response,
Server,
};
use primitive_types::H160;
use rand::{
prelude::StdRng,
Rng,
Expand Down Expand Up @@ -373,7 +372,7 @@ async fn can_restart_node_with_relayer_data() {
fn make_message_event(
nonce: Nonce,
block_number: u64,
contract_address: H160,
contract_address: Bytes20,
sender: Option<[u8; 32]>,
recipient: Option<[u8; 32]>,
amount: Option<u64>,
Expand All @@ -388,7 +387,7 @@ fn make_message_event(
data: data.map(Into::into).unwrap_or_default(),
};
let mut log = message.into_log();
log.address = contract_address;
log.address = H160::from_slice(contract_address.as_slice());
log.block_number = Some(block_number.into());
log.log_index = Some(log_index.into());
log
Expand Down
Loading