Skip to content

Commit a5120b5

Browse files
authored
Merge pull request #662 from pragma-org/tidy-kernel
chore: tidy kernel modules
2 parents 457cefa + 3963663 commit a5120b5

File tree

379 files changed

+5102
-4220
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

379 files changed

+5102
-4220
lines changed

Cargo.lock

Lines changed: 3 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/amaru-consensus/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ async-trait.workspace = true
2323
hex.workspace = true
2424
itertools.workspace = true
2525
opentelemetry.workspace = true
26-
pallas-crypto.workspace = true
2726
parking_lot.workspace = true
2827
proptest = { workspace = true, optional = true }
2928
rand = { workspace = true, optional = true }
@@ -41,7 +40,6 @@ amaru-mempool.workspace = true
4140
amaru-metrics.workspace = true
4241
amaru-ouroboros-traits.workspace = true
4342
amaru-protocols.workspace = true
44-
amaru-slot-arithmetic.workspace = true
4543
pure-stage.workspace = true
4644

4745
[dev-dependencies]

crates/amaru-consensus/benches/headers_tree.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,20 @@
2929
#[expect(clippy::unwrap_used)]
3030
#[cfg(all(unix, feature = "profiling", feature = "test-utils"))]
3131
fn main() {
32-
use amaru_consensus::consensus::headers_tree::HeadersTree;
33-
use amaru_consensus::consensus::headers_tree::data_generation::{
34-
execute_actions_on_tree, generate_random_walks, generate_tree_of_headers,
32+
use amaru_consensus::consensus::{
33+
headers_tree::{
34+
HeadersTree,
35+
data_generation::{
36+
execute_actions_on_tree, generate_random_walks, generate_tree_of_headers,
37+
},
38+
},
39+
stages::select_chain::DEFAULT_MAXIMUM_FRAGMENT_LENGTH,
3540
};
36-
use amaru_consensus::consensus::stages::select_chain::DEFAULT_MAXIMUM_FRAGMENT_LENGTH;
3741
use amaru_kernel::{BlockHeader, IsHeader};
38-
use amaru_ouroboros_traits::ChainStore;
39-
use amaru_ouroboros_traits::in_memory_consensus_store::InMemConsensusStore;
42+
use amaru_ouroboros_traits::{ChainStore, in_memory_consensus_store::InMemConsensusStore};
4043
use amaru_stores::rocksdb::{RocksDbConfig, consensus::RocksDBStore};
4144
use pprof::{ProfilerGuardBuilder, flamegraph::Options};
42-
use std::fs::File;
43-
use std::sync::Arc;
45+
use std::{fs::File, sync::Arc};
4446

4547
let profile = false;
4648
let in_memory = false;

crates/amaru-consensus/src/consensus/effects/consensus_effects.rs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::consensus::effects::{
1616
Base, BaseOps, Ledger, LedgerOps, Network, NetworkOps, Store,
1717
metrics_effects::{Metrics, MetricsOps},
1818
};
19-
use amaru_kernel::{BlockHeader, Tx};
19+
use amaru_kernel::{BlockHeader, Transaction};
2020
use amaru_ouroboros_traits::{ChainStore, TxSubmissionMempool};
2121
use amaru_protocols::mempool_effects::MemoryPool;
2222
use pure_stage::{Effects, SendData};
@@ -30,7 +30,7 @@ pub trait ConsensusOps: Send + Sync + Clone {
3030
fn network(&self) -> impl NetworkOps;
3131
/// Return a TxSubmissionMempool implementation to access mempool operations, like get_tx to retrieve a transaction
3232
/// from the mempool.
33-
fn mempool(&self) -> Arc<dyn TxSubmissionMempool<Tx>>;
33+
fn mempool(&self) -> Arc<dyn TxSubmissionMempool<Transaction>>;
3434
/// Return a LedgerOps implementation to access ledger operations, considering that it is a sub-system
3535
/// external to consensus.
3636
fn ledger(&self) -> Arc<dyn LedgerOps>;
@@ -55,7 +55,7 @@ impl<T: SendData + Sync + Clone> ConsensusEffects<T> {
5555
Arc::new(Store::new(self.effects.clone()))
5656
}
5757

58-
pub fn mempool(&self) -> Arc<dyn TxSubmissionMempool<Tx>> {
58+
pub fn mempool(&self) -> Arc<dyn TxSubmissionMempool<Transaction>> {
5959
Arc::new(MemoryPool::new(self.effects.clone()))
6060
}
6161

@@ -81,7 +81,7 @@ impl<T: SendData + Sync + Clone> ConsensusOps for ConsensusEffects<T> {
8181
self.store()
8282
}
8383

84-
fn mempool(&self) -> Arc<dyn TxSubmissionMempool<Tx>> {
84+
fn mempool(&self) -> Arc<dyn TxSubmissionMempool<Transaction>> {
8585
self.mempool()
8686
}
8787

@@ -107,33 +107,28 @@ impl<T: SendData + Sync + Clone> ConsensusOps for ConsensusEffects<T> {
107107
pub mod tests {
108108
use super::*;
109109
use crate::consensus::errors::ProcessingFailed;
110-
use amaru_kernel::peer::Peer;
111-
use amaru_kernel::protocol_messages::tip::Tip;
112-
use amaru_kernel::{Point, PoolId, RawBlock};
110+
use amaru_kernel::{Peer, Point, PoolId, RawBlock, Tip};
113111
use amaru_mempool::strategies::InMemoryMempool;
114-
use amaru_metrics::MetricsEvent;
115-
use amaru_metrics::ledger::LedgerMetrics;
112+
use amaru_metrics::{MetricsEvent, ledger::LedgerMetrics};
116113
use amaru_ouroboros::has_stake_distribution::GetPoolError;
117-
use amaru_ouroboros_traits::can_validate_blocks::HeaderValidationError;
118-
use amaru_ouroboros_traits::in_memory_consensus_store::InMemConsensusStore;
119114
use amaru_ouroboros_traits::{
120115
BlockValidationError, HasStakeDistribution, PoolSummary, TxSubmissionMempool,
116+
can_validate_blocks::HeaderValidationError, in_memory_consensus_store::InMemConsensusStore,
121117
};
122118
use amaru_protocols::blockfetch::Blocks;
123119
use amaru_slot_arithmetic::Slot;
124120
use parking_lot::Mutex;
125-
use pure_stage::serde::{from_cbor, to_cbor};
126-
use pure_stage::{BoxFuture, Instant, StageRef};
121+
use pure_stage::{
122+
BoxFuture, Instant, StageRef,
123+
serde::{from_cbor, to_cbor},
124+
};
127125
use serde::de::DeserializeOwned;
128-
use std::collections::BTreeMap;
129-
use std::future::ready;
130-
use std::sync::Arc;
131-
use std::time::Duration;
126+
use std::{collections::BTreeMap, future::ready, sync::Arc, time::Duration};
132127

133128
#[derive(Clone)]
134129
pub struct MockConsensusOps {
135130
pub mock_store: InMemConsensusStore<BlockHeader>,
136-
pub mock_mempool: Arc<dyn TxSubmissionMempool<Tx>>,
131+
pub mock_mempool: Arc<dyn TxSubmissionMempool<Transaction>>,
137132
pub mock_network: MockNetworkOps,
138133
pub mock_ledger: MockLedgerOps,
139134
pub mock_base: MockBaseOps,
@@ -150,7 +145,7 @@ pub mod tests {
150145
self.mock_network.clone()
151146
}
152147

153-
fn mempool(&self) -> Arc<dyn TxSubmissionMempool<Tx>> {
148+
fn mempool(&self) -> Arc<dyn TxSubmissionMempool<Transaction>> {
154149
self.mock_mempool.clone()
155150
}
156151

crates/amaru-consensus/src/consensus/effects/ledger_effects.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
use crate::consensus::errors::ProcessingFailed;
16-
use amaru_kernel::{BlockHeader, IgnoreEq, Point, RawBlock, peer::Peer};
16+
use amaru_kernel::{BlockHeader, IgnoreEq, Peer, Point, RawBlock};
1717
use amaru_metrics::ledger::LedgerMetrics;
1818
use amaru_ouroboros_traits::{
1919
BlockValidationError, CanValidateBlocks,

crates/amaru-consensus/src/consensus/effects/network_effects.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
use crate::consensus::errors::ProcessingFailed;
16-
use amaru_kernel::{BlockHeader, IsHeader, Point, peer::Peer, protocol_messages::tip::Tip};
16+
use amaru_kernel::{BlockHeader, IsHeader, Peer, Point, Tip};
1717
use anyhow::anyhow;
1818
use async_trait::async_trait;
1919
use pure_stage::{BoxFuture, Effects, ExternalEffect, ExternalEffectAPI, Resources, SendData};

crates/amaru-consensus/src/consensus/effects/store_effects.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
use amaru_kernel::{
16-
BlockHeader, HeaderHash, Point, RawBlock, protocol_parameters::GlobalParameters,
17-
};
15+
use amaru_kernel::{BlockHeader, GlobalParameters, HeaderHash, Point, RawBlock};
1816
use amaru_ouroboros_traits::{ChainStore, Nonces, ReadOnlyChainStore, StoreError};
1917
use pure_stage::{
2018
BoxFuture, Effects, ExternalEffect, ExternalEffectAPI, ExternalEffectSync, Resources, SendData,

crates/amaru-consensus/src/consensus/errors.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,10 @@
1313
// limitations under the License.
1414

1515
use crate::consensus;
16-
use amaru_kernel::peer::Peer;
17-
use amaru_kernel::{HeaderHash, Point};
18-
use amaru_ouroboros_traits::StoreError;
19-
use amaru_ouroboros_traits::can_validate_blocks::HeaderValidationError;
16+
use amaru_kernel::{HeaderHash, Peer, Point};
17+
use amaru_ouroboros_traits::{StoreError, can_validate_blocks::HeaderValidationError};
2018
use serde::ser::SerializeStruct;
21-
use serde::{Deserialize, Serialize};
22-
use std::fmt;
23-
use std::fmt::Display;
19+
use std::{fmt, fmt::Display};
2420
use thiserror::Error;
2521

2622
#[derive(Error, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
@@ -141,7 +137,7 @@ impl PartialEq for ProcessingFailed {
141137
}
142138
}
143139

144-
impl Serialize for ProcessingFailed {
140+
impl serde::Serialize for ProcessingFailed {
145141
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
146142
where
147143
S: serde::Serializer,
@@ -153,12 +149,12 @@ impl Serialize for ProcessingFailed {
153149
}
154150
}
155151

156-
impl<'de> Deserialize<'de> for ProcessingFailed {
152+
impl<'de> serde::Deserialize<'de> for ProcessingFailed {
157153
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
158154
where
159155
D: serde::Deserializer<'de>,
160156
{
161-
#[derive(Deserialize)]
157+
#[derive(serde::Deserialize)]
162158
struct ProcessingFailedHelper {
163159
peer: Option<Peer>,
164160
error: String,

crates/amaru-kernel/src/consensus_events.rs renamed to crates/amaru-consensus/src/consensus/events.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
use crate::protocol_messages::tip::Tip;
16-
use crate::{BlockHeader, IsHeader, Point, RawBlock, peer::Peer};
17-
use serde::{Deserialize, Serialize};
18-
use std::fmt;
19-
use std::fmt::{Debug, Formatter};
15+
use amaru_kernel::{BlockHeader, IsHeader, Peer, Point, RawBlock, Tip};
16+
use std::{
17+
fmt,
18+
fmt::{Debug, Formatter},
19+
};
2020
use tracing::Span;
2121

2222
/// Wrapper type to factor out caught-up messages from real events.
@@ -174,7 +174,7 @@ pub enum ValidateHeaderEvent {
174174
},
175175
}
176176

177-
#[derive(Clone, Serialize, Deserialize)]
177+
#[derive(Clone, serde::Serialize, serde::Deserialize)]
178178
pub enum ValidateBlockEvent {
179179
Validated {
180180
peer: Peer,
@@ -255,7 +255,7 @@ impl PartialEq for ValidateBlockEvent {
255255
}
256256
}
257257

258-
#[derive(Debug, Clone, Serialize, Deserialize)]
258+
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
259259
pub enum BlockValidationResult {
260260
BlockValidated {
261261
peer: Peer,

0 commit comments

Comments
 (0)