Skip to content

Commit

Permalink
Fixed bug when cache is not cleared
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcin-Radecki committed Nov 22, 2024
1 parent e0f677f commit 13a865a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
14 changes: 11 additions & 3 deletions examples/ordering/run.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

set -eoxu pipefail
set -eou pipefail

function usage() {
cat << EOF
Expand Down Expand Up @@ -30,6 +30,8 @@ Usage:
how many data items each node should order
[--crash-restart-delay-seconds CRASH_RESTART_DELAY_SECONDS]
delay (seconds) between subsequent node crashes
[--unit-creation-delay UNIT_CREATION_DELAY]
unit creation delay (milliseconds), default 200
EOF
exit 0
}
Expand Down Expand Up @@ -68,6 +70,7 @@ function run_ordering_binary() {
--starting-data-item "${starting_data_item}"
--data-items "${data_items}"
--required-finalization-value "${EXPECTED_FINALIZED_DATA_ITEMS}"
--unit-creation-delay "${UNIT_CREATION_DELAY}"
)
if [[ "${should_stall}" == "yes-stall" ]]; then
binary_args+=(--should-stall)
Expand All @@ -94,9 +97,10 @@ NODES=2
CRASHING_NODES=2
STALLING_DATA_PROVIDERS=1
CRASHES_COUNT=3
DATA_ITEMS=250
DATA_ITEMS=25
CRASH_RESTART_DELAY_SECONDS=5
DATA_ITEMS_COUNTER=0
UNIT_CREATION_DELAY=200

while [[ $# -gt 0 ]]; do
case "$1" in
Expand Down Expand Up @@ -124,6 +128,10 @@ while [[ $# -gt 0 ]]; do
CRASH_RESTART_DELAY_SECONDS="$2"
shift;shift
;;
--unit-creation-delay)
UNIT_CREATION_DELAY="$2"
shift;shift
;;
--help)
usage
shift
Expand All @@ -147,7 +155,7 @@ ALL_NODES=$(( NODES + CRASHING_NODES ))
PORTS=($(seq -s , 10000 $(( 10000 + ALL_NODES - 1 ))))
EXPECTED_FINALIZED_DATA_ITEMS=$(( ALL_NODES * DATA_ITEMS ))

for id in $(seq 0 $(( NODES - 1 ))); do
for id in $(seq 0 $(( ALL_NODES - 1 ))); do
rm -f "aleph-bft-examples-ordering-backup/${id}.units"
rm -f "node${id}.log"
done
Expand Down
15 changes: 12 additions & 3 deletions examples/ordering/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ use std::io::Write;
mod dataio;
mod network;

use aleph_bft::{run_session, NodeIndex, Terminator};
use aleph_bft::{run_session, NodeIndex, Terminator, default_delay_config};
use aleph_bft_mock::{Keychain, Spawner};
use clap::Parser;
use dataio::{Data, DataProvider, FinalizationHandler};
use futures::{channel::oneshot, io, StreamExt};
use log::{debug, error, info};
use network::Network;
use std::{path::Path, time::Duration};
use std::sync::Arc;
use time::{macros::format_description, OffsetDateTime};
use tokio::fs::{self, File};
use tokio_util::compat::{Compat, TokioAsyncWriteCompatExt};
Expand All @@ -31,7 +32,7 @@ struct Args {
data_items: u32,

/// Number of the first created item
#[clap(default_value = "0", long, value_parser)]
#[clap(long, value_parser)]
starting_data_item: u32,

/// Should the node stall after providing all its items
Expand All @@ -42,6 +43,10 @@ struct Args {
/// ie all nodes must finalize integer sequence [0; required_finalization_value)
#[clap(long, value_parser)]
required_finalization_value: u32,

/// Unit creation delay (milliseconds)
#[clap(long, default_value = "200", value_parser)]
unit_creation_delay: u64,
}

async fn create_backup(
Expand Down Expand Up @@ -91,7 +96,9 @@ async fn main() {
starting_data_item,
should_stall,
required_finalization_value,
unit_creation_delay,
} = Args::parse();

let id: NodeIndex = id.into();

info!("Getting network up.");
Expand All @@ -113,9 +120,11 @@ async fn main() {

let (exit_tx, exit_rx) = oneshot::channel();
let member_terminator = Terminator::create_root(exit_rx, "AlephBFT-member");
let mut delay_config = default_delay_config();
delay_config.unit_creation_delay = Arc::new(move |_| Duration::from_millis(unit_creation_delay));
let member_handle = tokio::spawn(async move {
let keychain = Keychain::new(n_members, id);
let config = aleph_bft::default_config(n_members, id, 0, 5000, Duration::ZERO)
let config = aleph_bft::create_config(n_members, id, 0, 5000, delay_config, Duration::ZERO)
.expect("Should always succeed with Duration::ZERO");
run_session(
config,
Expand Down

0 comments on commit 13a865a

Please sign in to comment.