-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Traits and data structs for reachability services (#5)
- Loading branch information
1 parent
ca78dd5
commit b461014
Showing
14 changed files
with
195 additions
and
3 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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
pub mod api; | ||
pub mod services; | ||
pub mod staging_area; | ||
pub mod stores; |
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 @@ | ||
pub mod reachability_service; |
38 changes: 38 additions & 0 deletions
38
kaspad/src/domain/consensus/model/services/reachability_service.rs
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 @@ | ||
use thiserror::Error; | ||
|
||
use crate::domain::consensus::model::{ | ||
api::hash::DomainHash, staging_area::StagingArea, stores::errors::StoreError, | ||
}; | ||
|
||
#[derive(Error, Debug)] | ||
pub enum ReachabilityError { | ||
#[error("data store error")] | ||
ReachabilityStoreError(#[from] StoreError), | ||
} | ||
|
||
pub trait ReachabilityService { | ||
fn init(&mut self, staging: &dyn StagingArea) -> Result<(), ReachabilityError>; | ||
fn add( | ||
&mut self, | ||
staging: &dyn StagingArea, | ||
block: DomainHash, | ||
selected_parent: DomainHash, | ||
mergeset: &[DomainHash], | ||
is_selected_leaf: bool, | ||
) -> Result<(), ReachabilityError>; | ||
fn is_chain_ancestor_of( | ||
&self, | ||
low: DomainHash, | ||
high: DomainHash, | ||
) -> Result<bool, ReachabilityError>; | ||
fn is_dag_ancestor_of( | ||
&self, | ||
low: DomainHash, | ||
high: DomainHash, | ||
) -> Result<bool, ReachabilityError>; | ||
fn get_next_chain_ancestor( | ||
&self, | ||
descendant: DomainHash, | ||
ancestor: DomainHash, | ||
) -> Result<DomainHash, ReachabilityError>; | ||
} |
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 |
---|---|---|
@@ -1 +1,11 @@ | ||
pub struct StagingArea {} | ||
pub trait StagingArea { | ||
fn commit(&mut self); | ||
} | ||
|
||
pub struct InMemoryStagingArea {} | ||
|
||
impl StagingArea for InMemoryStagingArea { | ||
fn commit(&mut self) { | ||
todo!() | ||
} | ||
} |
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,20 @@ | ||
use thiserror::Error; | ||
|
||
#[derive(Error, Debug)] | ||
pub enum StoreError { | ||
#[error("Key not found in store")] | ||
KeyNotFound, | ||
// More usage examples: | ||
// | ||
// #[error("data store disconnected")] | ||
// Disconnect(#[from] io::Error), | ||
// #[error("the data for key `{0}` is not available")] | ||
// Redaction(String), | ||
// #[error("invalid header (expected {expected:?}, found {found:?})")] | ||
// InvalidHeader { | ||
// expected: String, | ||
// found: String, | ||
// }, | ||
// #[error("unknown data store error")] | ||
// Unknown, | ||
} |
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,2 @@ | ||
pub mod errors; | ||
pub mod reachability_store; |
43 changes: 43 additions & 0 deletions
43
kaspad/src/domain/consensus/model/stores/reachability_store.rs
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,43 @@ | ||
use super::errors::StoreError; | ||
use crate::domain::consensus::{ | ||
model::{api::hash::DomainHash, staging_area::StagingArea}, | ||
processes::reachability::interval::Interval, | ||
}; | ||
|
||
pub struct ReachabilityData { | ||
pub children: Vec<DomainHash>, | ||
pub parent: DomainHash, | ||
pub interval: Interval, | ||
pub future_covering_set: Vec<DomainHash>, | ||
} | ||
|
||
impl ReachabilityData { | ||
pub fn new( | ||
children: Vec<DomainHash>, | ||
parent: DomainHash, | ||
interval: Interval, | ||
future_covering_set: Vec<DomainHash>, | ||
) -> Self { | ||
Self { | ||
children, | ||
parent, | ||
interval, | ||
future_covering_set, | ||
} | ||
} | ||
} | ||
|
||
pub trait ReachabilityStore { | ||
fn stage( | ||
&mut self, | ||
staging: &dyn StagingArea, | ||
hash: &DomainHash, | ||
data: &ReachabilityData, | ||
) -> Result<(), StoreError>; | ||
fn get( | ||
&self, | ||
staging: &dyn StagingArea, | ||
hash: &DomainHash, | ||
) -> Result<ReachabilityData, StoreError>; | ||
fn has(&self, staging: &dyn StagingArea, hash: &DomainHash) -> Result<bool, StoreError>; | ||
} |
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 |
---|---|---|
@@ -1 +1 @@ | ||
pub mod reachabilitymanager; | ||
pub mod reachability; |
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
64 changes: 64 additions & 0 deletions
64
kaspad/src/domain/consensus/processes/reachability/manager.rs
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,64 @@ | ||
use crate::domain::consensus::model::services::reachability_service::ReachabilityService; | ||
|
||
pub struct ReachabilityManager {} | ||
|
||
impl ReachabilityManager {} | ||
|
||
impl ReachabilityService for ReachabilityManager { | ||
fn init( | ||
&mut self, | ||
staging: &dyn crate::domain::consensus::model::staging_area::StagingArea, | ||
) -> Result< | ||
(), | ||
crate::domain::consensus::model::services::reachability_service::ReachabilityError, | ||
> { | ||
todo!() | ||
} | ||
|
||
fn add( | ||
&mut self, | ||
staging: &dyn crate::domain::consensus::model::staging_area::StagingArea, | ||
block: crate::domain::consensus::model::api::hash::DomainHash, | ||
selected_parent: crate::domain::consensus::model::api::hash::DomainHash, | ||
mergeset: &[crate::domain::consensus::model::api::hash::DomainHash], | ||
is_selected_leaf: bool, | ||
) -> Result< | ||
(), | ||
crate::domain::consensus::model::services::reachability_service::ReachabilityError, | ||
> { | ||
todo!() | ||
} | ||
|
||
fn is_chain_ancestor_of( | ||
&self, | ||
low: crate::domain::consensus::model::api::hash::DomainHash, | ||
high: crate::domain::consensus::model::api::hash::DomainHash, | ||
) -> Result< | ||
bool, | ||
crate::domain::consensus::model::services::reachability_service::ReachabilityError, | ||
> { | ||
todo!() | ||
} | ||
|
||
fn is_dag_ancestor_of( | ||
&self, | ||
low: crate::domain::consensus::model::api::hash::DomainHash, | ||
high: crate::domain::consensus::model::api::hash::DomainHash, | ||
) -> Result< | ||
bool, | ||
crate::domain::consensus::model::services::reachability_service::ReachabilityError, | ||
> { | ||
todo!() | ||
} | ||
|
||
fn get_next_chain_ancestor( | ||
&self, | ||
descendant: crate::domain::consensus::model::api::hash::DomainHash, | ||
ancestor: crate::domain::consensus::model::api::hash::DomainHash, | ||
) -> Result< | ||
crate::domain::consensus::model::api::hash::DomainHash, | ||
crate::domain::consensus::model::services::reachability_service::ReachabilityError, | ||
> { | ||
todo!() | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...nsus/processes/reachabilitymanager/mod.rs → ...n/consensus/processes/reachability/mod.rs
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod interval; | ||
pub mod manager; |
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