Skip to content

Commit

Permalink
chore: fix linters and workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
therealdannzor committed Jul 5, 2024
1 parent 5202477 commit 211af17
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 151 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ jobs:
- name: cargo test compile
run: cargo test -vv --no-run --locked --all-features --release
- name: cargo test
run: cargo nextest run --all-features --release -E "not package(tari_integration_tests)" --profile ci
run: cargo nextest run --all-features --release
- name: upload artifact
uses: actions/upload-artifact@v4 # upload test results as artifact
if: always()
Expand Down
28 changes: 0 additions & 28 deletions .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,6 @@ jobs:
- name: cargo test compile
run: cargo test --no-run --locked --all-features --release ${{ env.TARGET_BINS }}

- name: Run ${{ env.CI_PROFILE }} integration tests for binaries
if: ${{ env.CI_BINS == 'true' }}
timeout-minutes: 90
run: |
cargo test \
--test cucumber \
-v \
--all-features \
--release \
--package tari_integration_tests \
-- -t "${{ env.CI_PROFILE }} and (not @wallet-ffi) and (not @chat-ffi) and (not @broken)" \
-c 5 \
--retry 2
- name: upload artifact
uses: actions/upload-artifact@v4 # upload test results as artifact
if: always()
Expand Down Expand Up @@ -176,20 +162,6 @@ jobs:
if: ${{ env.CI_FFI == 'true' }}
run: cargo test --no-run --locked --all-features --release ${{ env.TARGET_BINS }}

- name: Run ${{ env.CI_PROFILE }} integration tests for ffi
if: ${{ env.CI_FFI == 'true' }}
timeout-minutes: 90
run: |
cargo test \
--test cucumber \
-v \
--all-features \
--release \
--package tari_integration_tests \
-- -t "(@wallet-ffi or @chat-ffi) and ${{ env.CI_PROFILE }} and (not @broken)" \
-c 1 \
--retry 2
- name: upload artifact
uses: actions/upload-artifact@v4 # upload test results as artifact
if: always()
Expand Down
56 changes: 10 additions & 46 deletions src/server/grpc/base_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,16 @@ use log::error;
use minotari_app_grpc::{
tari_rpc,
tari_rpc::{
base_node_client::BaseNodeClient,
Block,
BlockBlobRequest,
BlockGroupRequest,
BlockGroupResponse,
BlockHeaderResponse,
BlockHeight,
BlockTimingResponse,
ConsensusConstants,
Empty,
FetchMatchingUtxosRequest,
GetActiveValidatorNodesRequest,
GetBlocksRequest,
GetHeaderByHashRequest,
GetMempoolTransactionsRequest,
GetNewBlockBlobResult,
GetNewBlockResult,
GetNewBlockTemplateWithCoinbasesRequest,
GetNewBlockWithCoinbasesRequest,
GetPeersRequest,
GetShardKeyRequest,
GetShardKeyResponse,
GetSideChainUtxosRequest,
GetTemplateRegistrationsRequest,
HeightRequest,
HistoricalBlock,
ListConnectedPeersResponse,
ListHeadersRequest,
MempoolStatsResponse,
NetworkStatusResponse,
NewBlockTemplate,
NewBlockTemplateRequest,
NewBlockTemplateResponse,
NodeIdentity,
SearchKernelsRequest,
SearchUtxosRequest,
SoftwareUpdate,
StringValue,
SubmitBlockResponse,
SubmitTransactionRequest,
SubmitTransactionResponse,
SyncInfoResponse,
SyncProgressResponse,
TipInfoResponse,
TransactionStateRequest,
TransactionStateResponse,
base_node_client::BaseNodeClient, Block, BlockBlobRequest, BlockGroupRequest, BlockGroupResponse,
BlockHeaderResponse, BlockHeight, BlockTimingResponse, ConsensusConstants, Empty, FetchMatchingUtxosRequest,
GetActiveValidatorNodesRequest, GetBlocksRequest, GetHeaderByHashRequest, GetMempoolTransactionsRequest,
GetNewBlockBlobResult, GetNewBlockResult, GetNewBlockTemplateWithCoinbasesRequest,
GetNewBlockWithCoinbasesRequest, GetPeersRequest, GetShardKeyRequest, GetShardKeyResponse,
GetSideChainUtxosRequest, GetTemplateRegistrationsRequest, HeightRequest, HistoricalBlock,
ListConnectedPeersResponse, ListHeadersRequest, MempoolStatsResponse, NetworkStatusResponse, NewBlockTemplate,
NewBlockTemplateRequest, NewBlockTemplateResponse, NodeIdentity, SearchKernelsRequest, SearchUtxosRequest,
SoftwareUpdate, StringValue, SubmitBlockResponse, SubmitTransactionRequest, SubmitTransactionResponse,
SyncInfoResponse, SyncProgressResponse, TipInfoResponse, TransactionStateRequest, TransactionStateResponse,
ValueAtHeightResponse,
},
};
Expand Down
27 changes: 11 additions & 16 deletions src/server/grpc/p2pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,9 @@ use std::sync::Arc;

use log::{debug, info, warn};
use minotari_app_grpc::tari_rpc::{
base_node_client::BaseNodeClient,
pow_algo::PowAlgos,
sha_p2_pool_server::ShaP2Pool,
GetNewBlockRequest,
GetNewBlockResponse,
GetNewBlockTemplateWithCoinbasesRequest,
HeightRequest,
NewBlockTemplateRequest,
PowAlgo,
SubmitBlockRequest,
SubmitBlockResponse,
base_node_client::BaseNodeClient, pow_algo::PowAlgos, sha_p2_pool_server::ShaP2Pool, GetNewBlockRequest,
GetNewBlockResponse, GetNewBlockTemplateWithCoinbasesRequest, HeightRequest, NewBlockTemplateRequest, PowAlgo,
SubmitBlockRequest, SubmitBlockResponse,
};
use tari_core::proof_of_work::sha3x_difficulty;
use tokio::sync::Mutex;
Expand All @@ -33,7 +25,8 @@ const LOG_TARGET: &str = "p2pool_grpc";

/// P2Pool specific gRPC service to provide `get_new_block` and `submit_block` functionalities.
pub struct ShaP2PoolGrpc<S>
where S: ShareChain + Send + Sync + 'static
where
S: ShareChain + Send + Sync + 'static,
{
/// Base node client
client: Arc<Mutex<BaseNodeClient<tonic::transport::Channel>>>,
Expand All @@ -44,7 +37,8 @@ where S: ShareChain + Send + Sync + 'static
}

impl<S> ShaP2PoolGrpc<S>
where S: ShareChain + Send + Sync + 'static
where
S: ShareChain + Send + Sync + 'static,
{
pub async fn new(
base_node_address: String,
Expand Down Expand Up @@ -73,7 +67,8 @@ where S: ShareChain + Send + Sync + 'static

#[tonic::async_trait]
impl<S> ShaP2Pool for ShaP2PoolGrpc<S>
where S: ShareChain + Send + Sync + 'static
where
S: ShareChain + Send + Sync + 'static,
{
/// Returns a new block (that can be mined) which contains all the shares generated
/// from the current share chain as coinbase transactions.
Expand Down Expand Up @@ -173,8 +168,8 @@ where S: ShareChain + Send + Sync + 'static
.into_inner();
let mut network_difficulty_matches = false;
while let Ok(Some(diff_resp)) = network_difficulty_stream.message().await {
if origin_block_header.height == diff_resp.height + 1 &&
request_block_difficulty.as_u64() > diff_resp.difficulty
if origin_block_header.height == diff_resp.height + 1
&& request_block_difficulty.as_u64() > diff_resp.difficulty
{
network_difficulty_matches = true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/server/p2p/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ use tokio::{
sync::{
broadcast,
broadcast::error::{RecvError, SendError},
mpsc,
Mutex,
mpsc, Mutex,
},
time::sleep,
};
Expand Down Expand Up @@ -110,6 +109,7 @@ impl ServiceClient {
Ok(())
}

#[allow(clippy::cast_possible_truncation)]
async fn validate_block_with_retries(&self, block: &Block, mut retries: u64) -> Result<bool, ClientError> {
if retries >= self.config.validate_block_max_retries {
warn!(target: LOG_TARGET, "❗Too many validation retries!");
Expand Down
7 changes: 1 addition & 6 deletions src/server/p2p/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@
// SPDX-License-Identifier: BSD-3-Clause

use libp2p::{
gossipsub::PublishError,
identity::DecodingError,
kad::NoKnownPeers,
multiaddr,
noise,
swarm::DialError,
gossipsub::PublishError, identity::DecodingError, kad::NoKnownPeers, multiaddr, noise, swarm::DialError,
TransportError,
};
use thiserror::Error;
Expand Down
8 changes: 6 additions & 2 deletions src/server/p2p/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ macro_rules! impl_conversions {
};
}
pub fn deserialize_message<'a, T>(raw_message: &'a [u8]) -> Result<T, Error>
where T: Deserialize<'a> {
where
T: Deserialize<'a>,
{
serde_cbor::from_slice(raw_message).map_err(Error::SerializeDeserialize)
}

pub fn serialize_message<T>(input: &T) -> Result<Vec<u8>, Error>
where T: Serialize {
where
T: Serialize,
{
serde_cbor::to_vec(input).map_err(Error::SerializeDeserialize)
}

Expand Down
4 changes: 2 additions & 2 deletions src/server/p2p/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
pub use client::*;
pub use error::*;
pub use p2p::*;
pub use network::*;

pub(crate) mod client;
mod error;
pub mod messages;
mod p2p;
mod network;
pub mod peer_store;
29 changes: 9 additions & 20 deletions src/server/p2p/p2p.rs → src/server/p2p/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,10 @@ use libp2p::{
mdns,
mdns::tokio::Tokio,
multiaddr::Protocol,
noise,
request_response,
noise, request_response,
request_response::{cbor, ResponseChannel},
swarm::{NetworkBehaviour, SwarmEvent},
tcp,
yamux,
Multiaddr,
StreamProtocol,
Swarm,
tcp, yamux, Multiaddr, StreamProtocol, Swarm,
};
use log::{debug, error, info, warn};
use tari_common::configuration::Network;
Expand All @@ -43,20 +38,12 @@ use crate::{
server::{
config,
p2p::{
client,
messages,
client, messages,
messages::{
PeerInfo,
ShareChainSyncRequest,
ShareChainSyncResponse,
ValidateBlockRequest,
ValidateBlockResult,
PeerInfo, ShareChainSyncRequest, ShareChainSyncResponse, ValidateBlockRequest, ValidateBlockResult,
},
peer_store::PeerStore,
Error,
LibP2PError,
ServiceClient,
ServiceClientChannels,
Error, LibP2PError, ServiceClient, ServiceClientChannels,
},
},
sharechain::{block::Block, ShareChain},
Expand Down Expand Up @@ -102,7 +89,8 @@ pub struct ServerNetworkBehaviour {
/// Service is the implementation that holds every peer-to-peer related logic
/// that makes sure that all the communications, syncing, broadcasting etc... are done.
pub struct Service<S>
where S: ShareChain + Send + Sync + 'static
where
S: ShareChain + Send + Sync + 'static,
{
swarm: Swarm<ServerNetworkBehaviour>,
port: u16,
Expand All @@ -122,7 +110,8 @@ where S: ShareChain + Send + Sync + 'static
}

impl<S> Service<S>
where S: ShareChain + Send + Sync + 'static
where
S: ShareChain + Send + Sync + 'static,
{
/// Constructs a new Service from the provided config.
/// It also instantiates libp2p swarm inside.
Expand Down
2 changes: 1 addition & 1 deletion src/server/p2p/peer_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl PeerStore {
pub async fn cleanup(&self) -> Vec<PeerId> {
let mut expired_peers = vec![];

for (k, v) in self.inner.iter() {
for (k, v) in &self.inner {
debug!(target: LOG_TARGET, "{:?} -> {:?}", k, v);
let elapsed = v.created.elapsed();
let expired = elapsed.gt(&self.ttl);
Expand Down
9 changes: 5 additions & 4 deletions src/server/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ use thiserror::Error;

use crate::{
server::{
config,
grpc,
config, grpc,
grpc::{base_node::TariBaseNodeGrpc, error::TonicError, p2pool::ShaP2PoolGrpc},
p2p,
},
Expand All @@ -35,7 +34,8 @@ pub enum Error {

/// Server represents the server running all the necessary components for sha-p2pool.
pub struct Server<S>
where S: ShareChain + Send + Sync + 'static
where
S: ShareChain + Send + Sync + 'static,
{
config: config::Config,
p2p_service: p2p::Service<S>,
Expand All @@ -45,7 +45,8 @@ where S: ShareChain + Send + Sync + 'static

// TODO: add graceful shutdown
impl<S> Server<S>
where S: ShareChain + Send + Sync + 'static
where
S: ShareChain + Send + Sync + 'static,
{
pub async fn new(config: config::Config, share_chain: S) -> Result<Self, Error> {
let share_chain = Arc::new(share_chain);
Expand Down
Loading

0 comments on commit 211af17

Please sign in to comment.