Skip to content

Commit

Permalink
Clean-ups
Browse files Browse the repository at this point in the history
  • Loading branch information
techraed committed Aug 27, 2024
1 parent c27766d commit 6c09985
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 33 deletions.
2 changes: 1 addition & 1 deletion common/src/auxiliary/waitlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub type AuxiliaryWaitlist<WaitListCallbacks> = WaitlistImpl<
pub type WaitlistedMessage = StoredDispatch;

std::thread_local! {
// Definition of the mailbox (`StorageDoubleMap`) global storage, accessed by the `Mailbox` trait implementor.
// Definition of the waitlist (`StorageDoubleMap`) global storage, accessed by the `Waitlist` trait implementor.
pub(crate) static WAITLIST_STORAGE: RefCell<DoubleBTreeMap<ProgramId, MessageId, (WaitlistedMessage, Interval<BlockNumber>)>> = const { RefCell::new(DoubleBTreeMap::new()) };
}

Expand Down
16 changes: 14 additions & 2 deletions gtest/src/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@

//! Block timestamp and height management.
use crate::BLOCK_DURATION_IN_MSECS;
use core_processor::configs::BlockInfo;
use gear_common::{auxiliary::BlockNumber, storage::GetCallback};
use std::{
cell::RefCell,
rc::Rc,
time::{SystemTime, UNIX_EPOCH},
};

use crate::BLOCK_DURATION_IN_MSECS;

type BlockInfoStorageInner = Rc<RefCell<Option<BlockInfo>>>;

thread_local! {
Expand Down Expand Up @@ -115,6 +115,18 @@ fn now() -> u64 {
.as_millis() as u64
}

/// Block number getter.
///
/// Used to get block number for auxiliary complex storage managers,
/// like auxiliary maibox, waitlist and etc.
pub(crate) struct GetBlockNumberImpl;

impl GetCallback<BlockNumber> for GetBlockNumberImpl {
fn call() -> BlockNumber {
BlocksManager::new().get().height
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
2 changes: 1 addition & 1 deletion gtest/src/gas_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub type OriginNodeDataOf = (
type GasTree = <AuxiliaryGasProvider as Provider>::GasTree;

/// Gas tree manager which operates under the hood over
/// [`gear_common::AuxiliaryGasProvider`].
/// [`gear_common::auxiliary::gas_provider::AuxiliaryGasProvider`].
///
/// Manager is needed mainly to adapt arguments of the gas tree methods to the
/// crate.
Expand Down
17 changes: 3 additions & 14 deletions gtest/src/mailbox/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@

//! Mailbox manager.
use crate::blocks::BlocksManager;
use crate::blocks::GetBlockNumberImpl;
use gear_common::{
auxiliary::{mailbox::*, BlockNumber},
storage::{GetCallback, Interval, IterableByKeyMap, Mailbox, MailboxCallbacks},
storage::{Interval, IterableByKeyMap, Mailbox, MailboxCallbacks},
};
use gear_core::ids::{MessageId, ProgramId};

/// Mailbox manager which operates under the hood over
/// [`gear_common::AuxiliaryMailbox`].
/// [`gear_common::auxiliary::mailbox::AuxiliaryMailbox`].
#[derive(Debug, Default)]
pub(crate) struct MailboxManager;

Expand Down Expand Up @@ -80,14 +80,3 @@ impl MailboxCallbacks<MailboxErrorImpl> for MailboxCallbacksImpl {
type OnInsert = ();
type OnRemove = ();
}

/// Block number getter.
///
/// Used to get block number to insert message into mailbox.
pub(crate) struct GetBlockNumberImpl;

impl GetCallback<BlockNumber> for GetBlockNumberImpl {
fn call() -> BlockNumber {
BlocksManager::new().get().height
}
}
2 changes: 1 addition & 1 deletion gtest/src/task_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use gear_common::{
};

/// Task pool manager which operates under the hood over
/// [`gear_common::AuxiliaryTaskpool`].
/// [`gear_common::auxiliary::task_pool::AuxiliaryTaskpool`].
///
/// Manager is needed mainly to adapt arguments of the task pool methods to the
/// crate.
Expand Down
17 changes: 3 additions & 14 deletions gtest/src/waitlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
#![allow(unused)]

use crate::blocks::BlocksManager;
use crate::blocks::GetBlockNumberImpl;
use gear_common::{
auxiliary::{waitlist::*, BlockNumber},
storage::{GetCallback, Interval, IterableByKeyMap, Waitlist, WaitlistCallbacks},
storage::{Interval, IterableByKeyMap, Waitlist, WaitlistCallbacks},
};
use gear_core::ids::{MessageId, ProgramId};

/// Waitlist manager which operates under the hood over
/// [`gear_common::AuxiliaryWaitlist`].
/// [`gear_common::auxiliary::waitlist::AuxiliaryWaitlist`].
#[derive(Debug, Default)]
pub(crate) struct WaitlistManager;

Expand Down Expand Up @@ -79,14 +79,3 @@ impl WaitlistCallbacks for WaitlistCallbacksImpl {
type OnInsert = ();
type OnRemove = ();
}

/// Block number getter.
///
/// Used to get block number to insert message into mailbox.
pub(crate) struct GetBlockNumberImpl;

impl GetCallback<BlockNumber> for GetBlockNumberImpl {
fn call() -> BlockNumber {
BlocksManager::new().get().height
}
}

0 comments on commit 6c09985

Please sign in to comment.