This repository has been archived by the owner on Nov 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* narwhal init
- Loading branch information
Showing
9 changed files
with
466 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
[package] | ||
name = "ursa-consensus" | ||
version = "0.1.0" | ||
edition = "2021" | ||
authors = ["b0xtch <[email protected]>"] | ||
|
||
[dependencies] | ||
anyhow = "1.0" | ||
arc-swap = { version = "1.6.0", features = ["serde"] } | ||
async-trait = "0.1" | ||
bytes = "1.3.0" | ||
|
||
fastcrypto = { git = "https://github.com/MystenLabs/fastcrypto", rev = "235211dc8195590f5353d38135f5ee51a267521e" } | ||
fastcrypto-zkp = { git = "https://github.com/MystenLabs/fastcrypto", rev = "235211dc8195590f5353d38135f5ee51a267521e", package = "fastcrypto-zkp" } | ||
fastcrypto-tbls = { git = "https://github.com/MystenLabs/fastcrypto", rev = "235211dc8195590f5353d38135f5ee51a267521e", package = "fastcrypto-tbls" } | ||
|
||
futures = "0.3.23" | ||
multiaddr = "0.17.0" | ||
mysten-metrics = { git = "https://github.com/MystenLabs/sui.git", branch = "main", package = "mysten-metrics" } | ||
mysten-network = { git = "https://github.com/MystenLabs/sui.git", branch = "main", package = "mysten-network" } | ||
|
||
narwhal-config = { git = "https://github.com/MystenLabs/sui.git", branch = "main", package = "narwhal-config" } | ||
narwhal-consensus = { git = "https://github.com/MystenLabs/sui.git", branch = "main", package = "narwhal-consensus" } | ||
narwhal-crypto = { git = "https://github.com/MystenLabs/sui.git", branch = "main", package = "narwhal-crypto" } | ||
narwhal-executor = { git = "https://github.com/MystenLabs/sui.git", branch = "main", package = "narwhal-executor" } | ||
narwhal-node = { git = "https://github.com/MystenLabs/sui.git", branch = "main", package = "narwhal-node" } | ||
narwhal-primary = { git = "https://github.com/MystenLabs/sui.git", branch = "main", package = "narwhal-primary" } | ||
narwhal-types = { git = "https://github.com/MystenLabs/sui.git", branch = "main", package = "narwhal-types" } | ||
narwhal-worker = { git = "https://github.com/MystenLabs/sui.git", branch = "main", package = "narwhal-worker" } | ||
prometheus = "0.13.3" | ||
rand = "0.8.5" | ||
serde = { version = "1.0", features = ["derive"] } | ||
tempfile = "3.3.0" | ||
tokio = { version = "1.24.2", features = ["sync", "rt", "macros"] } | ||
tokio-stream = { version = "0.1.11", features = ["net"] } | ||
tracing = "0.1.37" | ||
|
||
workspace-hack = { git = "https://github.com/MystenLabs/sui.git", branch = "main", package = "workspace-hack" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Narwhal and Bullshark - Mempool and Consensus | ||
|
||
> Narwhal and Bullshark (N/B) - Fleek Network's consensus and ordering algorithms. A DAG based consensus with total ordering and reliable broadcast. | ||
This code has been adapted from the [MystenLabs Sui](https://github.com/MystenLabs/sui) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright 2022-2023 Fleek Network | ||
// SPDX-License-Identifier: Apache-2.0, MIT | ||
|
||
use std::{path::PathBuf, sync::Arc}; | ||
|
||
use fastcrypto::{bls12381::min_sig::BLS12381KeyPair, ed25519::Ed25519KeyPair}; | ||
use multiaddr::Multiaddr; | ||
use mysten_metrics::RegistryService; | ||
use narwhal_config::{Parameters, WorkerId}; | ||
use narwhal_crypto::NetworkKeyPair as NarwhalNetworkKeyPair; | ||
use serde::{Deserialize, Serialize}; | ||
use tokio::sync::OnceCell; | ||
|
||
pub type KeyPair = Ed25519KeyPair; | ||
pub type AuthorityKeyPair = BLS12381KeyPair; | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)] | ||
pub struct ValidatorKeyPair { | ||
#[serde(skip)] | ||
keypair: OnceCell<Arc<AuthorityKeyPair>>, | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)] | ||
pub struct NetworkKeyPair { | ||
#[serde(skip)] | ||
keypair: OnceCell<Arc<KeyPair>>, | ||
} | ||
|
||
impl ValidatorKeyPair { | ||
pub fn new(keypair: AuthorityKeyPair) -> Self { | ||
let cell = OnceCell::new(); | ||
cell.set(Arc::new(keypair)) | ||
.expect("Failed to set authority keypair"); | ||
Self { keypair: cell } | ||
} | ||
|
||
pub fn authority_keypair(&self) -> &AuthorityKeyPair { | ||
self.keypair.get().as_ref().unwrap() | ||
} | ||
} | ||
|
||
impl NetworkKeyPair { | ||
pub fn new(keypair: KeyPair) -> Self { | ||
let cell = OnceCell::new(); | ||
cell.set(Arc::new(keypair)) | ||
.expect("Failed to set authority keypair"); | ||
Self { keypair: cell } | ||
} | ||
|
||
pub fn keypair(&self) -> &KeyPair { | ||
self.keypair.get().as_ref().unwrap() | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone, Deserialize, Serialize)] | ||
pub struct NodeConfig { | ||
pub keypair: ValidatorKeyPair, | ||
pub worker_keypair: NetworkKeyPair, | ||
pub account_keypair: NetworkKeyPair, | ||
pub network_keypair: NetworkKeyPair, | ||
pub network_address: Multiaddr, | ||
pub db_path: PathBuf, | ||
} | ||
|
||
pub struct NarwhalConfig { | ||
pub keypair: ValidatorKeyPair, | ||
pub network_keypair: NetworkKeyPair, | ||
pub registry_service: RegistryService, | ||
pub ids_and_keypairs: Vec<(WorkerId, NarwhalNetworkKeyPair)>, | ||
pub internal_consensus: bool, | ||
pub parameters: Parameters, | ||
pub storage_base_path: PathBuf, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2022-2023 Fleek Network | ||
// SPDX-License-Identifier: Apache-2.0, MIT | ||
|
||
use async_trait::async_trait; | ||
use bytes::Bytes; | ||
use narwhal_executor::ExecutionState; | ||
use narwhal_types::ConsensusOutput; | ||
use tokio::sync::mpsc::Sender; | ||
use tracing::error; | ||
|
||
type Epoch = u64; | ||
|
||
pub struct Execution<N> { | ||
/// a store for epoch | ||
_store: N, | ||
/// current epoch store implementation | ||
epoch: Epoch, | ||
/// managing certificates generated by narwhal | ||
transactions: Sender<Vec<u8>>, | ||
} | ||
|
||
impl<N> Execution<N> { | ||
pub fn new(store: N, epoch: Epoch, transactions: Sender<Vec<u8>>) -> Self { | ||
Self { | ||
_store: store, | ||
epoch, | ||
transactions, | ||
} | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl<N: Send + Sync> ExecutionState for Execution<N> { | ||
async fn handle_consensus_output(&self, consensus_output: ConsensusOutput) { | ||
for (_, batches) in consensus_output.batches { | ||
for batch in batches { | ||
for transaction in batch.transactions.into_iter() { | ||
assert_eq!(transaction, Bytes::from(self.epoch.to_be_bytes().to_vec())); | ||
if let Err(err) = self.transactions.send(transaction).await { | ||
error!("Failed to send txn: {}", err); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
async fn last_executed_sub_dag_index(&self) -> u64 { | ||
0 | ||
} | ||
} |
Oops, something went wrong.