Skip to content

Commit

Permalink
feat!: submit eviction proof for nodes that miss many proposals
Browse files Browse the repository at this point in the history
  • Loading branch information
sdbondi committed Dec 9, 2024
1 parent 50fbf05 commit a877deb
Show file tree
Hide file tree
Showing 216 changed files with 4,410 additions and 2,621 deletions.
498 changes: 320 additions & 178 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ minotari_wallet_grpc_client = { git = "https://github.com/tari-project/tari.git"
tari_common = { git = "https://github.com/tari-project/tari.git", branch = "feature-dan2" }
tari_common_types = { git = "https://github.com/tari-project/tari.git", branch = "feature-dan2" }
tari_hashing = { git = "https://github.com/tari-project/tari.git", branch = "feature-dan2" }
tari_sidechain = { git = "https://github.com/tari-project/tari.git", branch = "feature-dan2" }

# avoid including default features so each crate can choose which ones to import
tari_core = { git = "https://github.com/tari-project/tari.git", branch = "feature-dan2", default-features = false }
Expand Down Expand Up @@ -148,7 +149,7 @@ bigdecimal = "0.4.1"
bincode = "2.0.0-rc.3"
bitflags = "2.4"
blake2 = "0.10.6"
borsh = "1.3"
borsh = "1.5"
bytes = "1.5"
cacache = "12.0.0"
cargo_metadata = "0.15.3"
Expand All @@ -163,7 +164,7 @@ convert_case = "0.6.0"
cucumber = "0.21.0"
d3ne = { git = "https://github.com/stringhandler/d3ne-rs.git", tag = "v0.8.0-pre.3" }
dashmap = "5.5.0"
diesel = { version = "2.2.4", default-features = false }
diesel = { version = "2.2.6", default-features = false }
diesel_migrations = "2.2.0"
digest = "0.10"
dirs = "4.0.0"
Expand All @@ -181,7 +182,7 @@ httpmock = "0.6.8"
humantime = "2.1.0"
humantime-serde = "1.1.1"
include_dir = "0.7.2"
indexmap = "2.5.0"
indexmap = "2.6.0"
indoc = "1.0.6"
itertools = "0.11.0"
lazy_static = "1.4.0"
Expand Down Expand Up @@ -216,7 +217,7 @@ reqwest = "0.11.16"
semver = "1.0"
serde = { version = "1.0", default-features = false }
serde_json = "1.0"
serde_with = "2.3"
serde_with = "3.11.0"
sha2 = "0.10.8"
smallvec = "2.0.0-alpha.1"
std-semaphore = "0.1.0"
Expand Down Expand Up @@ -276,6 +277,7 @@ overflow-checks = true
#tari_metrics = { git = "https://github.com/account/tari.git", branch = "my-branch" }
#tari_libtor = { git = "https://github.com/account/tari.git", branch = "my-branch" }
#tari_hashing = { git = "https://github.com/account/tari.git", branch = "my-branch" }
#tari_sidechain = { git = "https://github.com/account/tari.git", branch = "my-branch" }


#[patch."https://github.com/tari-project/tari.git"]
Expand All @@ -302,4 +304,4 @@ overflow-checks = true
#tari_metrics = { path = "../tari/infrastructure/metrics" }
#tari_libtor = { path = "../tari/infrastructure/libtor" }
#tari_hashing = { path = "../tari/hashing" }

#tari_sidechain = { path = "../tari/base_layer/sidechain" }
1 change: 0 additions & 1 deletion applications/tari_dan_app_utilities/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ tari_bor = { workspace = true, default-features = true }
tari_indexer_lib = { workspace = true }
tari_networking = { workspace = true }
tari_validator_node_rpc = { workspace = true }
minotari_app_grpc = { workspace = true }

anyhow = { workspace = true }
async-trait = { workspace = true }
Expand Down
264 changes: 149 additions & 115 deletions applications/tari_dan_app_utilities/src/base_layer_scanner.rs

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions applications/tari_dan_app_utilities/src/common.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2024 The Tari Project
// SPDX-License-Identifier: BSD-3-Clause

use anyhow::{bail, Context};
use tari_base_node_client::BaseNodeClient;
use tari_common::configuration::Network;

pub async fn verify_correct_network<TClient: BaseNodeClient>(
base_node_client: &mut TClient,
configured_network: Network,
) -> anyhow::Result<()> {
let base_node_network_byte = base_node_client.get_network().await?;

let base_node_network =
Network::try_from(base_node_network_byte).context("base node returned an invalid network byte")?;

if configured_network != base_node_network {
bail!(
"Base node network is not the same as the configured network. Base node network: {}, Configured network: \
{}.",
base_node_network,
configured_network,
);
}
Ok(())
}
1 change: 1 addition & 0 deletions applications/tari_dan_app_utilities/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

pub mod base_layer_scanner;
pub mod common;
pub mod configuration;
pub mod json_encoding;
pub mod keypair;
Expand Down
40 changes: 31 additions & 9 deletions applications/tari_indexer/src/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use std::{fs, io, str::FromStr};
use std::{convert::Infallible, fs, io, str::FromStr};

use anyhow::Context;
use libp2p::identity;
use minotari_app_utilities::identity_management;
use serde::Serialize;
use tari_base_node_client::grpc::GrpcBaseNodeClient;
use tari_common::{
configuration::bootstrap::{grpc_default_port, ApplicationType},
Expand All @@ -34,15 +35,19 @@ use tari_consensus::consensus_constants::ConsensusConstants;
use tari_crypto::tari_utilities::ByteArray;
use tari_dan_app_utilities::{
base_layer_scanner,
common::verify_correct_network,
keypair::RistrettoKeypair,
seed_peer::SeedPeer,
template_manager::{self, implementation::TemplateManager},
};
use tari_dan_common_types::PeerAddress;
use tari_dan_common_types::{layer_one_transaction::LayerOneTransactionDef, PeerAddress};
use tari_dan_p2p::TariMessagingSpec;
use tari_dan_storage::global::GlobalDb;
use tari_dan_storage_sqlite::global::SqliteGlobalDbAdapter;
use tari_epoch_manager::base_layer::{EpochManagerConfig, EpochManagerHandle};
use tari_epoch_manager::{
base_layer::{EpochManagerConfig, EpochManagerHandle},
traits::LayerOneTransactionSubmitter,
};
use tari_networking::{MessagingMode, NetworkingHandle, RelayCircuitLimits, RelayReservationLimits, SwarmConfig};
use tari_shutdown::ShutdownSignal;
use tari_state_store_sqlite::SqliteStateStore;
Expand All @@ -62,12 +67,15 @@ pub async fn spawn_services(
ensure_directories_exist(config)?;

// GRPC client connection to base node
let base_node_client = GrpcBaseNodeClient::new(config.indexer.base_node_grpc_url.clone().unwrap_or_else(|| {
let port = grpc_default_port(ApplicationType::BaseNode, config.network);
format!("http://127.0.0.1:{port}")
.parse()
.expect("Default base node GRPC URL is malformed")
}));
let mut base_node_client =
GrpcBaseNodeClient::new(config.indexer.base_node_grpc_url.clone().unwrap_or_else(|| {
let port = grpc_default_port(ApplicationType::BaseNode, config.network);
format!("http://127.0.0.1:{port}")
.parse()
.expect("Default base node GRPC URL is malformed")
}));

verify_correct_network(&mut base_node_client, config.network).await?;

// Initialize networking
let identity = identity::Keypair::sr25519_from_bytes(keypair.secret_key().as_bytes().to_vec()).map_err(|e| {
Expand Down Expand Up @@ -129,6 +137,7 @@ pub async fn spawn_services(
global_db.clone(),
base_node_client.clone(),
keypair.public_key().clone(),
NoopL1Submitter,
shutdown.clone(),
);

Expand Down Expand Up @@ -190,3 +199,16 @@ fn save_identities(config: &ApplicationConfig, identity: &RistrettoKeypair) -> R

Ok(())
}

struct NoopL1Submitter;

impl LayerOneTransactionSubmitter for NoopL1Submitter {
type Error = Infallible;

async fn submit_transaction<T: Serialize + Send>(
&self,
_proof: LayerOneTransactionDef<T>,
) -> Result<(), Self::Error> {
Ok(())
}
}
14 changes: 14 additions & 0 deletions applications/tari_swarm_daemon/src/process_manager/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,20 @@ impl ProcessManagerHandle {
Ok(intances.into_iter().find(|i| i.name == name))
}

pub async fn get_instance(&self, id: InstanceId) -> anyhow::Result<Option<InstanceInfo>> {
let (tx_reply, rx_reply) = oneshot::channel();
// TODO: consider optimizing this by adding a new request variant
self.tx_request
.send(ProcessManagerRequest::ListInstances {
by_type: None,
reply: tx_reply,
})
.await?;

let intances = rx_reply.await??;
Ok(intances.into_iter().find(|i| i.id == id))
}

// pub async fn list_minotari_nodes(&self) -> anyhow::Result<Vec<InstanceInfo>> {
// self.list_instances(Some(InstanceType::MinoTariNode)).await
// }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ impl ProcessManager {
}

// "Mine in" the validators and templates
// 10 for new epoch + 10 for BL scan lag
self.mine(20).await?;
}

Expand Down
70 changes: 46 additions & 24 deletions applications/tari_swarm_daemon/src/webserver/rpc/instances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ pub async fn start_all(context: &HandlerContext, req: StartAllRequest) -> Result
Ok(StartAllResponse { num_instances })
}

pub type StartInstanceRequest = String;
#[derive(Debug, Clone, Deserialize)]
pub struct StartInstanceRequest {
pub by_name: Option<String>,
pub by_id: Option<InstanceId>,
}

#[derive(Debug, Clone, Serialize)]
pub struct StartInstanceResponse {
Expand All @@ -40,46 +44,64 @@ pub async fn start(
context: &HandlerContext,
req: StartInstanceRequest,
) -> Result<StartInstanceResponse, anyhow::Error> {
let name = req;

let instance = context
.process_manager()
.get_instance_by_name(name)
.await?
.ok_or_else(|| {
JsonRpcError::new(
JsonRpcErrorReason::ApplicationError(404),
"Instance not found".to_string(),
let instance = match (req.by_name, req.by_id) {
(_, Some(id)) => context.process_manager().get_instance(id).await?,
(Some(name), None) => context.process_manager().get_instance_by_name(name).await?,
(None, None) => {
return Err(JsonRpcError::new(
JsonRpcErrorReason::InvalidParams,
"Either `by_name` or `by_id` must be provided".to_string(),
serde_json::Value::Null,
)
})?;
.into());
},
};

let instance = instance.ok_or_else(|| {
JsonRpcError::new(
JsonRpcErrorReason::ApplicationError(404),
"Instance not found".to_string(),
serde_json::Value::Null,
)
})?;

context.process_manager().start_instance(instance.id).await?;

Ok(StartInstanceResponse { success: true })
}

pub type StopInstanceRequest = String;
#[derive(Debug, Clone, Deserialize)]
pub struct StopInstanceRequest {
pub by_name: Option<String>,
pub by_id: Option<InstanceId>,
}

#[derive(Debug, Clone, Serialize)]
pub struct StopInstanceResponse {
pub success: bool,
}

pub async fn stop(context: &HandlerContext, req: StopInstanceRequest) -> Result<StopInstanceResponse, anyhow::Error> {
let name = req;

let instance = context
.process_manager()
.get_instance_by_name(name)
.await?
.ok_or_else(|| {
JsonRpcError::new(
JsonRpcErrorReason::ApplicationError(404),
"Instance not found".to_string(),
let instance = match (req.by_name, req.by_id) {
(_, Some(id)) => context.process_manager().get_instance(id).await?,
(Some(name), None) => context.process_manager().get_instance_by_name(name).await?,
(None, None) => {
return Err(JsonRpcError::new(
JsonRpcErrorReason::InvalidParams,
"Either `by_name` or `by_id` must be provided".to_string(),
serde_json::Value::Null,
)
})?;
.into());
},
};

let instance = instance.ok_or_else(|| {
JsonRpcError::new(
JsonRpcErrorReason::ApplicationError(404),
"Instance not found".to_string(),
serde_json::Value::Null,
)
})?;

context.process_manager().stop_instance(instance.id).await?;

Expand Down
4 changes: 2 additions & 2 deletions applications/tari_swarm_daemon/src/webserver/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ async fn json_rpc_handler(Extension(context): Extension<Arc<HandlerContext>>, va
"add_asset_wallet" | "add_wallet_daemon" => call_handler(context, value, rpc::dan_wallets::create).await,
"add_indexer" => call_handler(context, value, rpc::indexers::create).await,
"add_validator_node" => call_handler(context, value, rpc::validator_nodes::create).await,
"start" => call_handler(context, value, rpc::instances::start).await,
"start_instance" => call_handler(context, value, rpc::instances::start).await,
"start_all" => call_handler(context, value, rpc::instances::start_all).await,
"stop" => call_handler(context, value, rpc::instances::stop).await,
"stop_instance" => call_handler(context, value, rpc::instances::stop).await,
"stop_all" => call_handler(context, value, rpc::instances::stop_all).await,
"list_instances" => call_handler(context, value, rpc::instances::list).await,
"delete_data" => call_handler(context, value, rpc::instances::delete_data).await,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ export default function MinotariNodes(props: Props) {
const [isLoading, setIsLoading] = React.useState(true);


const reload = () =>
jsonRpc("list_instances", { by_type: "MinoTariNode" }).then((nodes: any) => setNodes(nodes.instances));

React.useEffect(() => {
jsonRpc("list_instances", { by_type: "MinoTariNode" }).then((nodes: any) => setNodes(nodes.instances))
.then(() => setIsLoading(false));
reload().then(() => setIsLoading(false));
}, []);

if (isLoading) {
Expand All @@ -26,23 +28,26 @@ export default function MinotariNodes(props: Props) {
return (
<div>
{nodes!.map((node: any, i: number) => (
<Node key={i} {...node} showLogs={props.showLogs} />
<Node key={i} {...node} onReload={reload} showLogs={props.showLogs} />
))}
</div>
);
}

function Node(props: any) {
const onStart = () => {
jsonRpc("start_instance", { instance_id: props.id });
jsonRpc("start_instance", { by_id: props.id })
.then(props.onReload);
};

const onStop = () => {
jsonRpc("stop_instance", { instance_id: props.id });
jsonRpc("stop_instance", { by_id: props.id })
.then(props.onReload);
};

const onDeleteData = () => {
jsonRpc("delete_instance_data", { instance_id: props.id });
jsonRpc("delete_instance_data", { instance_id: props.id })
.then(props.onReload);
};

return (
Expand Down
Loading

0 comments on commit a877deb

Please sign in to comment.