Skip to content

Commit

Permalink
M src/list/raxos/protocal/rustfmt.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
drmingdrmer committed Sep 26, 2024
1 parent 08842c7 commit 6dbd238
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 88 deletions.
22 changes: 11 additions & 11 deletions src/list/raxos/protocal/rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@
# use_field_init_shorthand = true


reorder_imports = true
imports_granularity = "Item"
group_imports = "StdExternalCrate"
where_single_line = true
trailing_comma = "Vertical"
reorder_imports = true
imports_granularity = "Item"
group_imports = "StdExternalCrate"
where_single_line = true
trailing_comma = "Vertical"
overflow_delimited_expr = true
wrap_comments = true
comment_width = 80
max_width = 100
inline_attribute_width = 80
wrap_comments = true
comment_width = 80
max_width = 100
inline_attribute_width = 0

merge_derives = false
merge_derives = false

# pre-unstable

chain_width = 100
chain_width = 100
3 changes: 1 addition & 2 deletions src/list/raxos/protocal/src/apaxos/acceptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use validit::Validate;

use crate::apaxos::decided::Decided;
use crate::apaxos::history::History;
use crate::apaxos::history_view::HistoryView;
use crate::commonly_used::history_view::BasicView;
use crate::apaxos::history_view::BasicView;
use crate::Types;

#[derive(Clone, Default, Debug)]
Expand Down
1 change: 0 additions & 1 deletion src/list/raxos/protocal/src/apaxos/decided.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::apaxos::history::History;
use crate::apaxos::history_view::HistoryView;
use crate::Types;

#[derive(Debug, Clone, Default)]
Expand Down
15 changes: 1 addition & 14 deletions src/list/raxos/protocal/src/apaxos/history.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
use std::fmt::Debug;

use crate::apaxos::errors::APError;
use crate::apaxos::errors::TimeRegression;
use crate::apaxos::history_view::HistoryView;
use crate::commonly_used::history_view::BasicView;
use crate::apaxos::history_view::BasicView;
use crate::Types;

pub struct TimeEvent<T: Types> {
time: T::Time,
event: T::Event,
}

impl<T: Types> TimeEvent<T> {
pub fn new(time: T::Time, event: T::Event) -> Self {
Self { time, event }
}
}

/// A [`History`] contains [`Time`] and [`Event`] in a Partially Ordered Set.
///
/// [`History`] is used by an [`Acceptor`] to store the [`Time`] and [`Event`]
Expand Down
43 changes: 38 additions & 5 deletions src/list/raxos/protocal/src/apaxos/history_view.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
use crate::apaxos::decided::Decided;
use crate::apaxos::history::History;
use crate::Types;

// For doc reference
#[rustfmt::skip]
#[allow(unused_imports)]
use crate::apaxos::history::History;

/// Represents a snapshot view of a [`History`] up to a specific time.
///
/// This trait extends the [`History`] trait to represent a subset of the
/// history that includes all time and events **before or equal** a specific
/// "view time".
///
/// This trait is used by a [`Proposer`] to represent the system state it sees.
pub trait HistoryView<T: Types> {
#[derive(Debug, Clone, Default)]
pub struct BasicView<T>
where T: Types
{
current_time: T::Time,
history: T::History,
}

impl<T> BasicView<T>
where T: Types
{
pub fn new(current_time: T::Time, history: T::History) -> Self {
Self {
current_time,
history,
}
}

/// Returns the "current" time of this snapshot view.
///
/// This time represents the **greatest** single time.
Expand All @@ -19,7 +40,9 @@ pub trait HistoryView<T: Types> {
/// Note: The current time does not necessarily have to be an actual event
/// time present in this History. It can be any valid time that defines
/// the causal "cut" for this snapshot view.
fn current_time(&self) -> T::Time;
pub fn current_time(&self) -> T::Time {
self.current_time
}

/// Attempts to append an [`Event`] at the current time.
///
Expand All @@ -28,7 +51,17 @@ pub trait HistoryView<T: Types> {
///
/// This method should return an `Err` if there is already an [`Event`] at
/// the ([`current_time()`](Self::current_time)).
fn append(self, event: T::Event) -> Result<Decided<T>, Decided<T>>;
pub fn append(mut self, event: T::Event) -> Result<Decided<T>, Decided<T>> {
if let Some(_ev) = self.history.get(&self.current_time) {
//
} else {
self.history.append(self.current_time, event).unwrap();
}

Ok(Decided::new(self.current_time, self.into_history()))
}

fn into_history(self) -> T::History;
pub fn into_history(self) -> T::History {
self.history
}
}
6 changes: 2 additions & 4 deletions src/list/raxos/protocal/src/apaxos/proposer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ use phase1::Phase1;
use phase2::Phase2;

use crate::apaxos::errors::APError;
use crate::apaxos::history::History;
use crate::apaxos::history_view::HistoryView;
use crate::commonly_used::history_view::BasicView;
use crate::apaxos::history_view::BasicView;
use crate::APaxos;
use crate::Types;

Expand Down Expand Up @@ -46,7 +44,7 @@ impl<'a, T: Types> Proposer<'a, T> {
}
}

fn new_phase2(&mut self, mut maybe_committed: BasicView<T>) -> Phase2<T> {
fn new_phase2(&mut self, maybe_committed: BasicView<T>) -> Phase2<T> {
// If the current time already has an event, no new event is added.

let decided = match maybe_committed.append(self.event.clone()) {
Expand Down
3 changes: 1 addition & 2 deletions src/list/raxos/protocal/src/apaxos/proposer/phase1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use std::collections::BTreeMap;

use crate::apaxos::errors::APError;
use crate::apaxos::history::History;
use crate::apaxos::history_view::HistoryView;
use crate::commonly_used::history_view::BasicView;
use crate::apaxos::history_view::BasicView;
use crate::APaxos;
use crate::QuorumSet;
use crate::Transport;
Expand Down
1 change: 0 additions & 1 deletion src/list/raxos/protocal/src/apaxos/proposer/phase2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::collections::BTreeMap;

use crate::apaxos::decided::Decided;
use crate::apaxos::errors::APError;
use crate::commonly_used::history_view::BasicView;
use crate::APaxos;
use crate::QuorumSet;
use crate::Transport;
Expand Down
45 changes: 0 additions & 45 deletions src/list/raxos/protocal/src/commonly_used/history_view.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/list/raxos/protocal/src/commonly_used/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//! used in paxos.
pub mod history;
pub mod history_view;
pub mod quorum_set;
pub mod time;
pub mod transport;
Expand Down
2 changes: 1 addition & 1 deletion src/list/raxos/protocal/src/commonly_used/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::collections::VecDeque;

use crate::apaxos::acceptor::Acceptor;
use crate::apaxos::decided::Decided;
use crate::commonly_used::history_view::BasicView;
use crate::apaxos::history_view::BasicView;
use crate::Transport;
use crate::Types;

Expand Down
2 changes: 1 addition & 1 deletion src/list/raxos/protocal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use apaxos::ptime::Time;

use crate::apaxos::decided::Decided;
use crate::apaxos::history::History;
use crate::commonly_used::history_view::BasicView;
use crate::apaxos::history_view::BasicView;

pub trait AcceptorId: Debug + Clone + Copy + Ord + 'static {}

Expand Down

0 comments on commit 6dbd238

Please sign in to comment.