Struct sn_routing::SectionChain [−][src]
pub struct SectionChain { /* fields omitted */ }
Expand description
Chain of section BLS keys where every key is proven (signed) by its parent key, except the first one.
CRDT
The operations that mutate the chain (insert
and merge
) are
commutative, associative and idempotent. This means the chain is a
CRDT.
Forks
It’s possible to insert multiple keys that all have the same parent key. This is called a “fork”. The chain implements automatic fork resolution which means that even in the presence of forks the chain presents the blocks in a well-defined unique and deterministic order.
Block order
Block are ordered primarily according to their parent-child relation (parents always precede
children) and forks are resolved by additionally ordering the sibling blocks according to the
Ord
relation of their public key. That is, “lower” keys precede “higher” keys.
Implementations
impl SectionChain
[src]
impl SectionChain
[src]pub fn insert(
&mut self,
parent_key: &PublicKey,
key: PublicKey,
signature: Signature
) -> Result<(), Error>
[src]
pub fn insert(
&mut self,
parent_key: &PublicKey,
key: PublicKey,
signature: Signature
) -> Result<(), Error>
[src]Insert new key into the chain. parent_key
must exists in the chain and must validate
signature
, otherwise error is returned.
pub fn merge(&mut self, other: Self) -> Result<(), Error>
[src]
pub fn merge(&mut self, other: Self) -> Result<(), Error>
[src]Merges two chains into one.
This succeeds only if the root key of one of the chain is present in the other one.
Otherwise it returns Error::InvalidOperation
pub fn get_proof_chain(
&self,
from_key: &PublicKey,
to_key: &PublicKey
) -> Result<Self, Error>
[src]
pub fn get_proof_chain(
&self,
from_key: &PublicKey,
to_key: &PublicKey
) -> Result<Self, Error>
[src]Creates a sub-chain from given from
and to
keys.
Returns Error::KeyNotFound
if the given keys are not present in the chain.
pub fn get_proof_chain_to_current(
&self,
from_key: &PublicKey
) -> Result<Self, Error>
[src]
pub fn get_proof_chain_to_current(
&self,
from_key: &PublicKey
) -> Result<Self, Error>
[src]Creates a sub-chain from a given key to the end.
Returns Error::KeyNotFound
if the given from key is not present in the chain.
pub fn minimize<'a, I>(&self, required_keys: I) -> Result<Self, Error> where
I: IntoIterator<Item = &'a PublicKey>,
[src]
pub fn minimize<'a, I>(&self, required_keys: I) -> Result<Self, Error> where
I: IntoIterator<Item = &'a PublicKey>,
[src]Creates a minimal sub-chain of self
that contains all required_keys
.
Returns Error::KeyNotFound
if some of required_keys
is not present in self
.
Note: “minimal” means it contains the fewest number of blocks of all such sub-chains.
pub fn truncate(&self, count: usize) -> Self
[src]
pub fn truncate(&self, count: usize) -> Self
[src]Returns a sub-chain of self
truncated to the last count
keys.
NOTE: a chain must have at least 1 block, so if count
is 0 it is treated the same as if
it was 1.
pub fn extend(
&self,
trusted_key: &PublicKey,
super_chain: &Self
) -> Result<Self, Error>
[src]
pub fn extend(
&self,
trusted_key: &PublicKey,
super_chain: &Self
) -> Result<Self, Error>
[src]Returns the smallest super-chain of self
that would be trusted by a peer that trust
trusted_key
. Ensures that the last key of the resuling chain is the same as the last key
of self
.
Returns Error::KeyNotFound
if any of trusted_key
, self.root_key()
or self.last_key()
is not present in super_chain
.
Returns Error::InvalidOperation
if trusted_key
is not reachable from self.last_key()
.
pub fn keys(&self) -> impl DoubleEndedIterator<Item = &PublicKey>
[src]
pub fn keys(&self) -> impl DoubleEndedIterator<Item = &PublicKey>
[src]Iterator over all the keys in the chain in order.
pub fn root_key(&self) -> &PublicKey
[src]
pub fn root_key(&self) -> &PublicKey
[src]Returns the root key of this chain. This is the first key in the chain and is the only key that doesn’t have a parent key.
pub fn prev_key(&self) -> &PublicKey
[src]
pub fn prev_key(&self) -> &PublicKey
[src]Returns the parent key of the last key or the root key if this chain has only one key.
pub fn check_trust<'a, I>(&self, trusted_keys: I) -> bool where
I: IntoIterator<Item = &'a PublicKey>,
[src]
pub fn check_trust<'a, I>(&self, trusted_keys: I) -> bool where
I: IntoIterator<Item = &'a PublicKey>,
[src]Given a collection of keys that are already trusted, returns whether this chain is also
trusted. A chain is considered trusted only if at least one of the trusted_keys
is on its
main branch.
Explanation
Consider this chain that contains fork:
A->B->C
|
+->D
Now if the only trusted key is D
, then there is no way to prove the chain is trusted,
because this chain would be indistinguishable in terms of trust from any other chain with
the same general “shape”, say:
W->X->Y->Z
|
+->D
So an adversary is easily able to forge any such chain.
When the trusted key is on the main branch, on the other hand:
D->E->F
|
+->G
Then such chain is impossible to forge because the adversary would have to have access to
the secret key corresponding to D
in order to validly sign E
. Thus such chain can be
safely considered trusted.
pub fn cmp_by_position(&self, lhs: &PublicKey, rhs: &PublicKey) -> Ordering
[src]
pub fn cmp_by_position(&self, lhs: &PublicKey, rhs: &PublicKey) -> Ordering
[src]Compare the two keys by their position in the chain. The key that is higher (closer to the
last key) is considered Greater
. If exactly one of the keys is not in the chain, the other
one is implicitly considered Greater
. If none are in the chain, they are considered
Equal
.
pub fn main_branch_len(&self) -> usize
[src]
pub fn main_branch_len(&self) -> usize
[src]Returns the number of block on the main branch of the chain - that is - the ones reachable from the last block.
NOTE: this is a O(n)
operation.
Trait Implementations
impl Clone for SectionChain
[src]
impl Clone for SectionChain
[src]fn clone(&self) -> SectionChain
[src]
fn clone(&self) -> SectionChain
[src]Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]Performs copy-assignment from source
. Read more
impl Debug for SectionChain
[src]
impl Debug for SectionChain
[src]impl<'de> Deserialize<'de> for SectionChain
[src]
impl<'de> Deserialize<'de> for SectionChain
[src]fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]Deserialize this value from the given Serde deserializer. Read more
impl Hash for SectionChain
[src]
impl Hash for SectionChain
[src]impl PartialEq<SectionChain> for SectionChain
[src]
impl PartialEq<SectionChain> for SectionChain
[src]fn eq(&self, other: &SectionChain) -> bool
[src]
fn eq(&self, other: &SectionChain) -> bool
[src]This method tests for self
and other
values to be equal, and is used
by ==
. Read more
fn ne(&self, other: &SectionChain) -> bool
[src]
fn ne(&self, other: &SectionChain) -> bool
[src]This method tests for !=
.
impl Serialize for SectionChain
[src]
impl Serialize for SectionChain
[src]impl Eq for SectionChain
[src]
impl StructuralEq for SectionChain
[src]
impl StructuralPartialEq for SectionChain
[src]
Auto Trait Implementations
impl RefUnwindSafe for SectionChain
impl Send for SectionChain
impl Sync for SectionChain
impl Unpin for SectionChain
impl UnwindSafe for SectionChain
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]pub fn equivalent(&self, key: &K) -> bool
[src]
pub fn equivalent(&self, key: &K) -> bool
[src]Compare self to key
and return true
if they are equal.
impl<T> Instrument for T
[src]
impl<T> Instrument for T
[src]fn instrument(self, span: Span) -> Instrumented<Self>
[src]
fn instrument(self, span: Span) -> Instrumented<Self>
[src]Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
fn in_current_span(self) -> Instrumented<Self>
[src]
fn in_current_span(self) -> Instrumented<Self>
[src]impl<T> Same<T> for T
impl<T> Same<T> for T
type Output = T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn to_owned(&self) -> T
[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)
[src]
pub fn clone_into(&self, target: &mut T)
[src]🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
pub fn vzip(self) -> V
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,