Skip to content

Commit

Permalink
Rename structs
Browse files Browse the repository at this point in the history
  • Loading branch information
mertwole committed Sep 3, 2024
1 parent 90adbe5 commit 9a9e220
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 41 deletions.
17 changes: 9 additions & 8 deletions relayer/src/message_relayer/all_token_transfers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ use gear_rpc_client::GearApi;
use utils_prometheus::MeteredService;

use super::common::{
block_listener::BlockListener, merkle_root_listener::MerkleRootListener,
message_queued_listener::MessageQueuedListener, message_sender::MessageSender,
ethereum_message_sender::EthereumMessageSender, gear_block_listener::GearBlockListener,
merkle_root_listener::MerkleRootListener,
message_queued_event_extractor::MessageQueuedEventExtractor,
};

pub struct MessageRelayer {
block_listener: BlockListener,
block_listener: GearBlockListener,

message_sent_listener: MessageQueuedListener,
message_sent_listener: MessageQueuedEventExtractor,

merkle_root_listener: MerkleRootListener,
message_sender: MessageSender,
message_sender: EthereumMessageSender,
}

impl MeteredService for MessageRelayer {
Expand Down Expand Up @@ -42,14 +43,14 @@ impl MessageRelayer {

let from_eth_block = eth_api.block_number().await?;

let block_listener = BlockListener::new(gear_api.clone(), from_gear_block);
let block_listener = GearBlockListener::new(gear_api.clone(), from_gear_block);

let message_sent_listener = MessageQueuedListener::new(gear_api.clone());
let message_sent_listener = MessageQueuedEventExtractor::new(gear_api.clone());

let merkle_root_listener =
MerkleRootListener::new(eth_api.clone(), gear_api.clone(), from_eth_block);

let message_sender = MessageSender::new(eth_api, gear_api);
let message_sender = EthereumMessageSender::new(eth_api, gear_api);

Ok(Self {
block_listener,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ use utils_prometheus::{impl_metered_service, MeteredService};

use crate::message_relayer::common::{AuthoritySetId, MessageInBlock};

pub mod era;
mod era;
use era::{Era, EraMetrics};

use super::merkle_root_listener::RelayedMerkleRoot;

pub struct MessageSender {
pub struct EthereumMessageSender {
eth_api: EthApi,
gear_api: GearApi,

Expand All @@ -31,7 +31,7 @@ impl_metered_service! {
}
}

impl MeteredService for MessageSender {
impl MeteredService for EthereumMessageSender {
fn get_sources(&self) -> impl IntoIterator<Item = Box<dyn prometheus::core::Collector>> {
self.metrics
.get_sources()
Expand Down Expand Up @@ -59,7 +59,7 @@ impl Metrics {
}
}

impl MessageSender {
impl EthereumMessageSender {
pub fn new(eth_api: EthApi, gear_api: GearApi) -> Self {
Self {
eth_api,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ const GEAR_BLOCK_TIME_APPROX: Duration = Duration::from_secs(3);

pub struct BlockNumber(pub u32);

pub struct BlockListener {
pub struct GearBlockListener {
gear_api: GearApi,
from_block: u32,

metrics: BlockListenerMetrics,
}

impl MeteredService for BlockListener {
impl MeteredService for GearBlockListener {
fn get_sources(&self) -> impl IntoIterator<Item = Box<dyn prometheus::core::Collector>> {
self.metrics.get_sources()
}
Expand All @@ -46,7 +46,7 @@ impl BlockListenerMetrics {
}
}

impl BlockListener {
impl GearBlockListener {
pub fn new(gear_api: GearApi, from_block: u32) -> Self {
Self {
gear_api,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ use prometheus::IntCounter;

use utils_prometheus::{impl_metered_service, MeteredService};

use super::block_listener::BlockNumber;
use super::gear_block_listener::BlockNumber;

pub struct PaidMessage {
pub nonce: [u8; 32],
}

pub struct MessagePaidListener {
pub struct MessagePaidEventExtractor {
bridging_payment_address: H256,

gear_api: GearApi,

metrics: MessagePaidListenerMetrics,
}

impl MeteredService for MessagePaidListener {
impl MeteredService for MessagePaidEventExtractor {
fn get_sources(&self) -> impl IntoIterator<Item = Box<dyn prometheus::core::Collector>> {
self.metrics.get_sources()
}
Expand All @@ -50,7 +50,7 @@ impl MessagePaidListenerMetrics {
}
}

impl MessagePaidListener {
impl MessagePaidEventExtractor {
pub fn new(gear_api: GearApi, bridging_payment_address: H256) -> Self {
Self {
bridging_payment_address,
Expand Down Expand Up @@ -81,7 +81,7 @@ impl MessagePaidListener {
) -> anyhow::Result<()> {
loop {
for block in blocks.try_iter() {
self.process_block_events(block.0, &sender).await?;
self.process_block_events(block.0, sender).await?;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ use prometheus::IntCounter;

use utils_prometheus::{impl_metered_service, MeteredService};

use super::{block_listener::BlockNumber, MessageInBlock};
use super::{gear_block_listener::BlockNumber, MessageInBlock};

pub struct MessageQueuedListener {
pub struct MessageQueuedEventExtractor {
gear_api: GearApi,

metrics: MessageQueuedListenerMetrics,
}

impl MeteredService for MessageQueuedListener {
impl MeteredService for MessageQueuedEventExtractor {
fn get_sources(&self) -> impl IntoIterator<Item = Box<dyn prometheus::core::Collector>> {
self.metrics.get_sources()
}
Expand All @@ -41,7 +41,7 @@ impl MessageQueuedListenerMetrics {
}
}

impl MessageQueuedListener {
impl MessageQueuedEventExtractor {
pub fn new(gear_api: GearApi) -> Self {
Self {
gear_api,
Expand Down Expand Up @@ -71,7 +71,7 @@ impl MessageQueuedListener {
) -> anyhow::Result<()> {
loop {
for block in blocks.try_iter() {
self.process_block_events(block.0, &sender).await?;
self.process_block_events(block.0, sender).await?;
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions relayer/src/message_relayer/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use gear_rpc_client::dto::Message;
use primitive_types::H256;

pub mod block_listener;
pub mod ethereum_message_sender;
pub mod gear_block_listener;
pub mod merkle_root_listener;
pub mod message_paid_listener;
pub mod message_queued_listener;
pub mod message_sender;
pub mod message_paid_event_extractor;
pub mod message_queued_event_extractor;
pub mod paid_messages_filter;

type AuthoritySetId = u64;
Expand Down
2 changes: 1 addition & 1 deletion relayer/src/message_relayer/common/paid_messages_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{
sync::mpsc::{channel, Receiver, Sender},
};

use super::{message_paid_listener::PaidMessage, MessageInBlock};
use super::{message_paid_event_extractor::PaidMessage, MessageInBlock};

pub struct PaidMessagesFilter {
pending_messages: HashMap<[u8; 32], MessageInBlock>,
Expand Down
23 changes: 12 additions & 11 deletions relayer/src/message_relayer/paid_token_transfers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@ use utils_prometheus::MeteredService;
use crate::message_relayer::common::paid_messages_filter::PaidMessagesFilter;

use super::common::{
block_listener::BlockListener, merkle_root_listener::MerkleRootListener,
message_paid_listener::MessagePaidListener, message_queued_listener::MessageQueuedListener,
message_sender::MessageSender,
ethereum_message_sender::EthereumMessageSender, gear_block_listener::GearBlockListener,
merkle_root_listener::MerkleRootListener,
message_paid_event_extractor::MessagePaidEventExtractor,
message_queued_event_extractor::MessageQueuedEventExtractor,
};

pub struct MessageRelayer {
block_listener: BlockListener,
block_listener: GearBlockListener,

message_sent_listener: MessageQueuedListener,
message_paid_listener: MessagePaidListener,
message_sent_listener: MessageQueuedEventExtractor,
message_paid_listener: MessagePaidEventExtractor,

paid_messages_filter: PaidMessagesFilter,

merkle_root_listener: MerkleRootListener,
message_sender: MessageSender,
message_sender: EthereumMessageSender,
}

impl MeteredService for MessageRelayer {
Expand Down Expand Up @@ -56,19 +57,19 @@ impl MessageRelayer {
);
log::info!("Starting ethereum listener from block #{}", from_eth_block);

let block_listener = BlockListener::new(gear_api.clone(), from_gear_block);
let block_listener = GearBlockListener::new(gear_api.clone(), from_gear_block);

let message_sent_listener = MessageQueuedListener::new(gear_api.clone());
let message_sent_listener = MessageQueuedEventExtractor::new(gear_api.clone());

let message_paid_listener =
MessagePaidListener::new(gear_api.clone(), bridging_payment_address);
MessagePaidEventExtractor::new(gear_api.clone(), bridging_payment_address);

let paid_messages_filter = PaidMessagesFilter::new();

let merkle_root_listener =
MerkleRootListener::new(eth_api.clone(), gear_api.clone(), from_eth_block);

let message_sender = MessageSender::new(eth_api, gear_api);
let message_sender = EthereumMessageSender::new(eth_api, gear_api);

Ok(Self {
block_listener,
Expand Down

0 comments on commit 9a9e220

Please sign in to comment.