Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
831 changes: 415 additions & 416 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ members = [
[workspace.dependencies]
asim = { git="http://github.com/kaimast/asim.git" }
log = "0.4"
rand = "0.8"
rand = "0.9"
getrandom = "0.3"
ron = "0.8"
console-subscriber = "0.4"
dashmap = "6"
#winit = "0.30"
winit = { git = "https://github.com/iced-rs/winit.git", rev="254d6b3420ce4e674f516f7a2bd440665e05484d" }
winit = { git = "https://github.com/iced-rs/winit.git", rev="11414b6aa45699f038114e61b4ddf5102b2d3b4b" }
wgpu = { version="23", features=["spirv"] }
iced_aw = { version="0.11", default-features=false }
#iced = "0.13"
Expand Down Expand Up @@ -50,4 +51,4 @@ iced_widget = { git="https://github.com/iced-rs/iced.git"}
iced_winit = { git="https://github.com/iced-rs/iced.git"}
iced_core = { git="https://github.com/iced-rs/iced.git"}
iced_wgpu = { git="https://github.com/iced-rs/iced.git"}
winit = { git = "https://github.com/iced-rs/winit.git", rev="254d6b3420ce4e674f516f7a2bd440665e05484d" }
winit = { git = "https://github.com/iced-rs/winit.git", rev="11414b6aa45699f038114e61b4ddf5102b2d3b4b" }
6 changes: 6 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
UNRELEASED (0.2)
- Updated to Rust 2024

0.1:
- Initial release
- Support for Ethereum and PBFT
2 changes: 1 addition & 1 deletion cow-tree/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "cow-tree"
version = "0.1.0"
edition = "2021"
edition = "2024"

[dev-dependencies]
sha3 = "0.10"
Expand Down
2 changes: 1 addition & 1 deletion cow-tree/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![feature(trait_alias)]

use generic_array::{typenum, GenericArray};
use generic_array::{GenericArray, typenum};

mod node;
use node::{FrozenNode, Node};
Expand Down
15 changes: 9 additions & 6 deletions cow-tree/src/node.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{Value, BITS_PER_NODE};
use super::{BITS_PER_NODE, Value};

use std::rc::Rc;

Expand Down Expand Up @@ -80,11 +80,14 @@ impl<V: Value> Node<V> {
pub fn take_child(&mut self, idx: u8) -> Option<Box<Self>> {
assert!((idx as usize) < CHILDREN_PER_BRANCH);

match self {
match *self {
Self::Leaf(_) => panic!("Cannot get child of leaf!"),
Self::Branch { ref mut children } => children[idx as usize].take(),
Self::Extension { bits, child } => {
if *bits == idx {
Self::Extension {
bits,
ref mut child,
} => {
if bits == idx {
child.take()
} else {
None
Expand Down Expand Up @@ -131,7 +134,7 @@ impl<V: Value> Node<V> {
pub fn set_child(&mut self, idx: u8, new_child: Box<Self>) {
assert!((idx as usize) < CHILDREN_PER_BRANCH);

match self {
match *self {
Self::Leaf(_) => panic!("Cannot set child of leaf!"),
Self::Branch { ref mut children } => {
children[idx as usize] = Some(new_child);
Expand All @@ -140,7 +143,7 @@ impl<V: Value> Node<V> {
bits,
ref mut child,
} => {
if *bits != idx {
if bits != idx {
panic!("Cannot set child");
}

Expand Down
3 changes: 1 addition & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ all: build #generate-web

install: build
cargo install {{BUILD_FLAGS}} --path=./simba-cmd --locked
cargo install {{BUILD_FLAGS}} --path=./visualizer --locked
cargo install {{BUILD_FLAGS}} --path=./native-gui --locked

lint: lint-cmd lint-native validate-shaders #lint-web
build: build-native build-cmd #build-web


check:
cargo check --package=simba-native-gui
cargo check --package=simba-cmd
Expand Down
2 changes: 1 addition & 1 deletion native-gui/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "simba-native-gui"
version = "0.1.0"
edition = "2021"
edition = "2024"
license = "MIT"
description = "Simulating Byzantine Fault-Tolerant Applications"

Expand Down
2 changes: 1 addition & 1 deletion native-gui/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Clippy bug
#![allow(clippy::needless_return)]

use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};

use anyhow::Context;

Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2024-11-15"
channel = "nightly-2025-01-26"
targets = ["wasm32-unknown-unknown"]
2 changes: 1 addition & 1 deletion simba-cmd/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "simba-cmd"
version = "0.1.0"
edition = "2021"
edition = "2024"

[[bin]]
name = "simba"
Expand Down
8 changes: 4 additions & 4 deletions simba/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
[package]
name = "simba"
version = "0.1.0"
edition = "2021"
edition = "2024"
license = "MIT"
description = "Simulating Byzantine Fault-Tolerant Applications"

[dependencies]
log = { workspace=true }
rand = { workspace=true, features=["getrandom"] }
rand = { workspace=true }
getrandom = { workspace=true }
ron = { workspace=true }
uint = "0.10"
dashmap = { workspace=true }
Expand All @@ -17,7 +18,6 @@ derive_more = { version="1.0.0-beta.6", features=["display", "from_str", "add_as
parking_lot = "0.12"
futures = "0.3"
async-trait = "0.1"
getrandom = "0.2"
num_cpus = "1"
csv = "1"
ctrlc = { version="3", features=["termination"], optional=true }
Expand All @@ -38,4 +38,4 @@ test-log = "0.2"
default = []
all = ["runners"]
runners = ["ctrlc"]
wasm = ["getrandom/js", "instant/wasm-bindgen"]
wasm = ["getrandom/wasm_js", "instant/wasm-bindgen"]
2 changes: 1 addition & 1 deletion simba/src/clients.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::logic::AccountId;
use crate::logic::Transaction;
use crate::node::{get_node_logic, Node};
use crate::node::{Node, get_node_logic};
use crate::object::{Object, ObjectId};

use std::cell::RefCell;
Expand Down
4 changes: 2 additions & 2 deletions simba/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl Default for ProtocolConfiguration {

impl ProtocolConfiguration {
pub fn set(&mut self, parameter: &ParameterType, value: ParameterValue) {
match self {
match *self {
Self::NakamotoConsensus {
ref mut max_block_size,
..
Expand Down Expand Up @@ -173,7 +173,7 @@ impl NetworkConfiguration {
}

pub fn set(&mut self, parameter: &ParameterType, value: ParameterValue) {
match self {
match *self {
Self::Random {
ref mut num_mining_nodes,
ref mut num_non_mining_nodes,
Expand Down
2 changes: 1 addition & 1 deletion simba/src/events.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::sync::{mpsc, OnceLock};
use std::sync::{OnceLock, mpsc};

use crate::config::TimeoutConfig;
use crate::logic::BlockId;
Expand Down
2 changes: 1 addition & 1 deletion simba/src/failures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl Failures {
//FIXME node0 still has a special role in some protocols
for idx in 1..num_nodes {
let faulty = {
let rand = rand::thread_rng().gen_range(0.0..1.0);
let rand = rand::rng().random_range(0.0..1.0);
rand < config.faulty_nodes
};

Expand Down
2 changes: 1 addition & 1 deletion simba/src/ledger/conventional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use derivative::Derivative;

use crate::emit_event;
use crate::events::{BlockEvent, Event};
use crate::logic::{AccountState, Block, BlockId, Transaction, TransactionId, SIGNATURE_SIZE};
use crate::logic::{AccountState, Block, BlockId, SIGNATURE_SIZE, Transaction, TransactionId};
use crate::node::NodeIndex;

use asim::time::Time;
Expand Down
2 changes: 1 addition & 1 deletion simba/src/ledger/nakamoto/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use derivative::Derivative;

use crate::config::Difficulty;
use crate::logic::{
AccountId, AccountState, Block, BlockId, TransactionId, HASH_SIZE, NUM_SIZE, SIGNATURE_SIZE,
AccountId, AccountState, Block, BlockId, HASH_SIZE, NUM_SIZE, SIGNATURE_SIZE, TransactionId,
};

#[derive(Derivative)]
Expand Down
14 changes: 7 additions & 7 deletions simba/src/ledger/nakamoto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ use asim::time::Time;

use cow_tree::FrozenCowTree;

use rand::prelude::SliceRandom;

use crate::config::Difficulty;
use crate::emit_event;
use crate::events::{BlockEvent, Event};
use crate::logic::{
AccountId, AccountState, Block, BlockId, Transaction, TransactionId, GENESIS_BLOCK,
GENESIS_HEIGHT,
AccountId, AccountState, Block, BlockId, GENESIS_BLOCK, GENESIS_HEIGHT, Transaction,
TransactionId,
};

mod block;
pub use block::NakamotoBlock;

use rand::prelude::IteratorRandom;

use super::{GlobalLedger, NodeLedger};

uint::construct_uint! {
Expand Down Expand Up @@ -392,10 +392,10 @@ impl NakamotoNodeLedger {
}
}

let mut rng = rand::thread_rng();
let block = longest_forks.choose(&mut rng).unwrap();
let mut rng = rand::rng();
let block = longest_forks.into_iter().choose(&mut rng).unwrap();

(*block, max_length)
(block, max_length)
}

pub fn get_forks(&self) -> &HashMap<BlockId, u64> {
Expand Down
2 changes: 1 addition & 1 deletion simba/src/ledger/nakamoto/tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::rc::Rc;

use crate::config::Difficulty;
use crate::logic::{Block, Transaction, TransactionId, GENESIS_BLOCK, GENESIS_HEIGHT};
use crate::logic::{Block, GENESIS_BLOCK, GENESIS_HEIGHT, Transaction, TransactionId};

use super::{NakamotoBlock, NakamotoNodeLedger};

Expand Down
2 changes: 1 addition & 1 deletion simba/src/library.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::collections::HashMap;
use std::fs::{read_dir, File};
use std::fs::{File, read_dir};
use std::path::Path;

use crate::{
Expand Down
2 changes: 1 addition & 1 deletion simba/src/link.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::events::{Event, LinkEvent};
use crate::node::{Node, NodeData};
use crate::object::{Object, ObjectId};
use crate::{emit_event, Message};
use crate::{Message, emit_event};

use std::rc::Rc;

Expand Down
2 changes: 1 addition & 1 deletion simba/src/logic/gossip/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ use asim::time::{Duration, Time};

use derivative::Derivative;

use crate::Connectivity;
use crate::logic::{BlockId, Client, GlobalLogic, Link, NodeLogic, TimeoutConfig};
use crate::message::MessageType;
use crate::metrics::ChainMetrics;
use crate::node::NodeIndex;
use crate::object::ObjectId;
use crate::Connectivity;

mod node;
pub use node::GossipNodeLogic;
Expand Down
7 changes: 4 additions & 3 deletions simba/src/logic/nakamoto/block_generator.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::cmp::Ordering;
use std::rc::Rc;

use asim::time::{Duration, Time, START_TIME};
use asim::time::{Duration, START_TIME, Time};

use crate::config::{
Difficulty, DifficultyAdjustment, IncrementalDifficultyAdjustment,
NakamotoBlockGenerationConfig,
};
use crate::ledger::{DiffTarget, NakamotoBlock, MAX_DIFF_TARGET};
use crate::ledger::{DiffTarget, MAX_DIFF_TARGET, NakamotoBlock};
use crate::logic::Block;
use crate::node::NodeIndex;

Expand Down Expand Up @@ -43,10 +43,11 @@ struct Ouroboros {
impl BlockGenerator for ProofOfWork {
fn should_create_block(&mut self, _idx: NodeIndex) -> bool {
// TODO should be a function of the node's compute power
let mut rng = rand::rng();

let mut value = DiffTarget([0, 0, 0, 0]);
for idx in 0..4 {
value.0[idx] = rand::rngs::OsRng.next_u64();
value.0[idx] = rng.next_u64();
}

value < self.difficulty_target
Expand Down
8 changes: 4 additions & 4 deletions simba/src/logic/nakamoto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ use std::rc::Rc;

use asim::time::{Duration, Time};

use crate::RcCell;
use crate::clients::Client;
use crate::config::{Connectivity, NakamotoBlockGenerationConfig, TimeoutConfig};
use crate::ledger::{NakamotoBlock, NakamotoGlobalLedger};
use crate::link::Link;
use crate::logic::{
Block, BlockId, GlobalLogic, NodeLogic, Transaction, TransactionId, GENESIS_BLOCK, HASH_SIZE,
NUM_SIZE, SIGNATURE_SIZE,
Block, BlockId, GENESIS_BLOCK, GlobalLogic, HASH_SIZE, NUM_SIZE, NodeLogic, SIGNATURE_SIZE,
Transaction, TransactionId,
};
use crate::message::MessageType;
use crate::metrics::ChainMetrics;
use crate::node::NodeIndex;
use crate::object::ObjectId;
use crate::RcCell;

mod node;
pub use node::NakamotoNodeLogic;

mod block_generator;
use block_generator::{make_block_generator, BlockGenerator};
use block_generator::{BlockGenerator, make_block_generator};

#[derive(Clone, Debug)]
pub enum NakamotoMessage {
Expand Down
4 changes: 2 additions & 2 deletions simba/src/logic/nakamoto/node.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::config::NakamotoBlockGenerationConfig;
use crate::ledger::{NakamotoBlock, NakamotoGlobalLedger, NakamotoNodeLedger};
use crate::logic::{
AccountId, Block, BlockId, NodeLogic, Transaction, TransactionId, GENESIS_BLOCK,
AccountId, Block, BlockId, GENESIS_BLOCK, NodeLogic, Transaction, TransactionId,
};
use crate::node::Node;
use crate::object::ObjectId;
Expand All @@ -14,7 +14,7 @@ use std::collections::{HashMap, HashSet};
use std::rc::Rc;

use super::NakamotoMessage;
use super::{make_block_generator, BlockGenerator};
use super::{BlockGenerator, make_block_generator};

struct NodeState {
local_ledger: NakamotoNodeLedger,
Expand Down
4 changes: 2 additions & 2 deletions simba/src/logic/pbft/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ use std::cell::RefCell;
use std::collections::{BTreeMap, HashSet};
use std::rc::Rc;

use crate::RcCell;
use crate::clients::Client;
use crate::config::{Connectivity, TimeoutConfig};
use crate::ledger::{ConventionalBlock, ConventionalGlobalLedger, SlotNumber};
use crate::link::Link;
use crate::logic::{Block, GlobalLogic, NodeLogic, Transaction, GENESIS_BLOCK, SIGNATURE_SIZE};
use crate::logic::{Block, GENESIS_BLOCK, GlobalLogic, NodeLogic, SIGNATURE_SIZE, Transaction};
use crate::message::MessageType;
use crate::metrics::ChainMetrics;
use crate::node::NodeIndex;
use crate::object::ObjectId;
use crate::RcCell;

use asim::time::{Duration, Time};

Expand Down
Loading
Loading