Skip to content

Commit

Permalink
chore: bump fuel-core version to use the latest release (#51)
Browse files Browse the repository at this point in the history
Co-authored-by: MujkicA <[email protected]>
  • Loading branch information
segfault-magnet and MujkicA authored Dec 14, 2023
1 parent e4d3560 commit 3422c94
Show file tree
Hide file tree
Showing 18 changed files with 100 additions and 94 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ concurrency:

env:
DASEL_VERSION: https://github.com/TomWright/dasel/releases/download/v1.24.3/dasel_linux_amd64
RUST_VERSION: 1.70.0
FUEL_CORE_VERSION: 0.20.4
RUST_VERSION: 1.74.0
FUEL_CORE_VERSION: 0.22.0
IMAGE_NAME: ${{ github.repository }}

jobs:
Expand Down
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ edition = "2021"
homepage = "https://fuel.network/"
license = "Apache-2.0"
repository = "https://github.com/FuelLabs/fuel-block-committer"
rust-version = "1.70.0"
rust-version = "1.74.0"
version = "0.1.0"
name = "fuel-block-committer"

Expand All @@ -16,7 +16,7 @@ path = "tests/harness.rs"
[dependencies]
actix-web = "4"
async-trait = "0.1.68"
fuel-core-client = "0.20.4"
fuel-core-client = "0.22.0"
prometheus = "0.13.3"
serde = { version = "1.0", features = ["derive"] }
ethers = { version = "2.0", features = ["ws"] }
Expand All @@ -25,14 +25,14 @@ tokio-util = { version = "0.7.8" }
thiserror = "1.0.40"
tracing = "0.1.37"
tracing-subscriber = { version = "0.3.17", features = ["json"] }
clap = { version ="4.3", features =["derive", "env"] }
clap = { version = "4.3", features = ["derive", "env"] }
url = "2.3"
serde_json = "1.0.96"
rusqlite = { version = "0.29", features = ["bundled"] }
rusqlite = { version = "0.30", features = ["bundled"] }
futures = "0.3.28"

[dev-dependencies]
fuels-test-helpers="0.45.1"
fuels-test-helpers = "0.54.0"
rand = "0.8.5"
mockall = "0.11.4"
anyhow = "1.0.71"
4 changes: 2 additions & 2 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ services:
build:
context: fuel_node
args:
fuel_core_version: "v${FUEL_CORE_VERSION:-0.20.4}"
fuel_core_version: "v${FUEL_CORE_VERSION:-0.22.0}"
container_name: fuel-node
environment:
- PORT=4000
- IP=0.0.0.0
- DATABASE_TYPE=in-memory
- MANUAL_BLOCKS_ENABLED=true
- INSTANT=true
- DEBUG=true
# - PERIOD=6s
ports:
- "4000:4000"
Expand Down
2 changes: 1 addition & 1 deletion deployment/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Stage 1: Build
FROM lukemathwalker/cargo-chef:latest-rust-1.70 as chef
FROM lukemathwalker/cargo-chef:latest-rust-1.74 as chef
WORKDIR /build/
# hadolint ignore=DL3008

Expand Down
2 changes: 1 addition & 1 deletion eth_node/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM alpine:3.18 AS fetcher
RUN apk add --no-cache git
RUN git clone --no-checkout https://github.com/FuelLabs/fuel-v2-contracts
RUN cd fuel-v2-contracts && git checkout a83444964db35cc1b93ee7a81d5f47d771083966
RUN cd fuel-v2-contracts && git checkout 81b35368764e6f83969e502812e14baa30b20f95
RUN sed 's/\(BLOCKS_PER_COMMIT_INTERVAL\) = 10800/\1 = 3/g' -i fuel-v2-contracts/contracts/fuelchain/FuelChainState.sol
RUN sed 's/\(TIME_TO_FINALIZE\) = 10800/\1 = 1/g' -i fuel-v2-contracts/contracts/fuelchain/FuelChainState.sol

Expand Down
22 changes: 11 additions & 11 deletions src/adapters/ethereum_adapter/monitored_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl<T> MonitoredEthAdapter<T> {
Ok(_val) => {
self.health_tracker.note_success();
}
Err(Error::NetworkError(..)) => {
Err(Error::Network(..)) => {
self.metrics.eth_network_errors.inc();
self.health_tracker.note_failure();
}
Expand Down Expand Up @@ -101,7 +101,7 @@ impl Default for Metrics {

#[cfg(test)]
mod tests {
use prometheus::Registry;
use prometheus::{proto::Metric, Registry};

use super::*;
use crate::adapters::ethereum_adapter::MockEthereumAdapter;
Expand All @@ -112,7 +112,7 @@ mod tests {
let mut eth_adapter = MockEthereumAdapter::new();
eth_adapter
.expect_submit()
.returning(|_| Err(Error::NetworkError("An error".into())));
.returning(|_| Err(Error::Network("An error".into())));

eth_adapter.expect_get_block_number().returning(|| Ok(10));

Expand Down Expand Up @@ -157,11 +157,11 @@ mod tests {
let mut eth_adapter = MockEthereumAdapter::new();
eth_adapter
.expect_submit()
.returning(|_| Err(Error::NetworkError("An error".into())));
.returning(|_| Err(Error::Network("An error".into())));

eth_adapter
.expect_get_block_number()
.returning(|| Err(Error::NetworkError("An error".into())));
.returning(|| Err(Error::Network("An error".into())));

let adapter = MonitoredEthAdapter::new(eth_adapter, 3);
let health_check = adapter.connection_health_checker();
Expand All @@ -182,11 +182,11 @@ mod tests {
let mut eth_adapter = MockEthereumAdapter::new();
eth_adapter
.expect_submit()
.returning(|_| Err(Error::NetworkError("An error".into())));
.returning(|_| Err(Error::Network("An error".into())));

eth_adapter
.expect_get_block_number()
.returning(|| Err(Error::NetworkError("An error".into())));
.returning(|| Err(Error::Network("An error".into())));

let registry = Registry::new();
let adapter = MonitoredEthAdapter::new(eth_adapter, 3);
Expand All @@ -196,14 +196,14 @@ mod tests {
let _ = adapter.get_block_number().await;

let metrics = registry.gather();
let latest_block_metric = metrics
let eth_network_err_metric = metrics
.iter()
.find(|metric| metric.get_name() == "eth_network_errors")
.and_then(|metric| metric.get_metric().get(0))
.map(|metric| metric.get_counter())
.and_then(|metric| metric.get_metric().first())
.map(Metric::get_counter)
.unwrap();

assert_eq!(latest_block_metric.get_value(), 2f64);
assert_eq!(eth_network_err_metric.get_value(), 2f64);
}

fn given_a_block(block_height: u32) -> FuelBlock {
Expand Down
10 changes: 5 additions & 5 deletions src/adapters/ethereum_adapter/websocket/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl EthereumWs {
) -> Result<Self> {
let provider = Provider::<Ws>::connect(ethereum_rpc.to_string())
.await
.map_err(|e| Error::NetworkError(e.to_string()))?;
.map_err(|e| Error::Network(e.to_string()))?;

let wallet = LocalWallet::from_str(ethereum_wallet_key)?.with_chain_id(chain_id);

Expand Down Expand Up @@ -76,8 +76,8 @@ impl EthereumAdapter for EthereumWs {
.send()
.await
.map_err(|contract_err| match contract_err {
ContractError::ProviderError { e } => Error::NetworkError(e.to_string()),
ContractError::MiddlewareError { e } => Error::NetworkError(e.to_string()),
ContractError::ProviderError { e } => Error::Network(e.to_string()),
ContractError::MiddlewareError { e } => Error::Network(e.to_string()),
_ => Error::Other(contract_err.to_string()),
})?;

Expand All @@ -94,7 +94,7 @@ impl EthereumAdapter for EthereumWs {
self.provider
.request("eth_blockNumber", Value::Array(vec![]))
.await
.map_err(|err| Error::NetworkError(err.to_string()))
.map_err(|err| Error::Network(err.to_string()))
.map(|height: U64| height.as_u64())
}

Expand All @@ -111,7 +111,7 @@ impl EthereumAdapter for EthereumWs {
self.provider
.get_balance(address, None)
.await
.map_err(|err| Error::NetworkError(err.to_string()))
.map_err(|err| Error::Network(err.to_string()))
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/adapters/ethereum_adapter/websocket/event_streamer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl EventStreamer for EthEventStreamer {
self.events
.subscribe()
.await
.map_err(|e| Error::NetworkError(e.to_string()))?
.map_err(|e| Error::Network(e.to_string()))?
.map_ok(|event| {
let fuel_block_hash = event.block_hash;
let commit_height = event.commit_height;
Expand Down
40 changes: 22 additions & 18 deletions src/adapters/fuel_adapter/fuel_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl FuelClient {

impl From<FuelGqlBlock> for FuelBlock {
fn from(value: FuelGqlBlock) -> Self {
FuelBlock {
Self {
hash: *value.id,
height: value.header.height,
}
Expand All @@ -57,9 +57,9 @@ impl FuelAdapter for FuelClient {
async fn block_at_height(&self, height: u32) -> Result<Option<FuelBlock>> {
let maybe_block = self
.client
.block_by_height(height as u64)
.block_by_height(height)
.await
.map_err(|e| Error::NetworkError(e.to_string()))?;
.map_err(|e| Error::Network(e.to_string()))?;

Ok(maybe_block.map(Into::into))
}
Expand All @@ -72,7 +72,7 @@ impl FuelAdapter for FuelClient {
}
Err(err) => {
self.handle_network_error();
Err(Error::NetworkError(err.to_string()))
Err(Error::Network(err.to_string()))
}
}
}
Expand All @@ -81,24 +81,26 @@ impl FuelAdapter for FuelClient {
#[cfg(test)]
mod tests {
use fuels_test_helpers::{setup_test_provider, Config};
use prometheus::Registry;
use prometheus::{proto::Metric, Registry};

use super::*;

#[tokio::test]
async fn can_fetch_latest_block() {
// given
let node_config = Config {
manual_blocks_enabled: true,
..Config::local_node()
debug: true,
..Default::default()
};

let (provider, addr) =
setup_test_provider(vec![], vec![], Some(node_config), Some(Default::default())).await;
let provider =
setup_test_provider(vec![], vec![], Some(node_config), Some(Default::default()))
.await
.unwrap();
provider.produce_blocks(5, None).await.unwrap();

let url = Url::parse(&format!("http://{addr}")).unwrap();

let addr = provider.url();
let url = Url::parse(addr).unwrap();
let fuel_adapter = FuelClient::new(&url, 1);

// when
Expand All @@ -112,15 +114,17 @@ mod tests {
async fn can_fetch_block_at_height() {
// given
let node_config = Config {
manual_blocks_enabled: true,
..Config::local_node()
debug: true,
..Default::default()
};

let (provider, addr) =
setup_test_provider(vec![], vec![], Some(node_config), Some(Default::default())).await;
let provider =
setup_test_provider(vec![], vec![], Some(node_config), Some(Default::default()))
.await
.unwrap();
provider.produce_blocks(5, None).await.unwrap();

let url = Url::parse(&format!("http://{addr}")).unwrap();
let url = Url::parse(provider.url()).unwrap();

let fuel_adapter = FuelClient::new(&url, 1);

Expand Down Expand Up @@ -151,8 +155,8 @@ mod tests {
let network_errors_metric = metrics
.iter()
.find(|metric| metric.get_name() == "fuel_network_errors")
.and_then(|metric| metric.get_metric().get(0))
.map(|metric| metric.get_counter())
.and_then(|metric| metric.get_metric().first())
.map(Metric::get_counter)
.unwrap();

assert_eq!(network_errors_metric.get_value(), 1f64);
Expand Down
17 changes: 10 additions & 7 deletions src/adapters/storage/sqlite_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ pub struct SqliteDb {
}

impl SqliteDb {
pub async fn open(path: impl Into<PathBuf>) -> Result<Self> {
pub async fn open<I>(path: I) -> Result<Self>
where
I: Into<PathBuf> + Send,
{
let path = path.into();
task::spawn_blocking(|| async {
let connection = Connection::open(path)?;
Expand All @@ -44,12 +47,12 @@ impl SqliteDb {

fn initialize(connection: Connection) -> Result<Arc<Mutex<Connection>>> {
connection.execute(
r#"CREATE TABLE IF NOT EXISTS eth_fuel_block_submission (
r"CREATE TABLE IF NOT EXISTS eth_fuel_block_submission (
fuel_block_hash BLOB PRIMARY KEY NOT NULL,
fuel_block_height INTEGER NOT NULL UNIQUE,
completed INTEGER NOT NULL,
submittal_height BLOB NOT NULL
)"#,
)",
(), // empty list of parameters.
)?;

Expand Down Expand Up @@ -114,7 +117,7 @@ impl Storage for SqliteDb {
Ok(self
.run_blocking(move |connection| {
let mut statement = connection.prepare(
r#"SELECT * FROM eth_fuel_block_submission ORDER BY fuel_block_height DESC LIMIT 1"#,
r"SELECT * FROM eth_fuel_block_submission ORDER BY fuel_block_height DESC LIMIT 1",
)?;

let mut submission = statement.query_map([], Self::decode_submission)?;
Expand All @@ -131,13 +134,13 @@ impl Storage for SqliteDb {
let rows_updated = connection.execute(query, (fuel_block_hash,))?;

if rows_updated == 0 {
return Err(Error::StorageError(format!(
return Err(Error::Storage(format!(
"Cannot set submission to completed! Submission of block: `{fuel_block_hash:?}` not found in DB."
)));
}

let submission = connection.query_row(
r#"SELECT * FROM eth_fuel_block_submission WHERE fuel_block_hash = (?1)"#,
r"SELECT * FROM eth_fuel_block_submission WHERE fuel_block_hash = (?1)",
(fuel_block_hash,),
Self::decode_submission,
)?;
Expand Down Expand Up @@ -218,7 +221,7 @@ mod tests {
let result = db.set_submission_completed(block_hash).await;

// then
let Err(Error::StorageError(msg)) = result else {
let Err(Error::Storage(msg)) = result else {
panic!("should be storage error");
};

Expand Down
8 changes: 4 additions & 4 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ pub enum Error {
#[error("{0}")]
Other(String),
#[error("Network Error: {0}")]
NetworkError(String),
Network(String),
#[error("Storage Error: {0}")]
StorageError(String),
Storage(String),
}

impl From<rusqlite::Error> for Error {
fn from(value: rusqlite::Error) -> Self {
Self::StorageError(value.to_string())
Self::Storage(value.to_string())
}
}

impl From<serde_json::Error> for Error {
fn from(value: serde_json::Error) -> Self {
Self::StorageError(value.to_string())
Self::Storage(value.to_string())
}
}

Expand Down
Loading

0 comments on commit 3422c94

Please sign in to comment.