Struct DistributedRepository

Source
pub struct DistributedRepository { /* private fields */ }
Expand description

The local Simperby blockchain data repository.

It automatically locks the repository once created.

  • It verifies all the incoming changes and applies them to the local repository only if they are valid.

Implementations§

Source§

impl DistributedRepository

Source

pub async fn update_(&self) -> Result<(), Error>

Source

pub async fn flush_(&self) -> Result<(), Error>

Source§

impl DistributedRepository

Source

pub fn get_raw(&self) -> Arc<RwLock<RawRepository>>

Source

pub fn get_dms(&self) -> Option<Arc<RwLock<Dms<RepositoryMessage>>>>

Source

pub async fn new( dms: Option<Arc<RwLock<Dms<RepositoryMessage>>>>, raw: Arc<RwLock<RawRepository>>, config: Config, private_key: Option<PrivateKey>, ) -> Result<Self, Error>

Source

pub async fn genesis(raw: RawRepository) -> Result<(), Error>

Initializes the genesis repository, leaving a genesis header.

It also

  • creates fp branch and its commit (for the genesis block).
  • creates the finalized branch.

Note that genesis can be called on any commit except a merge commit.

Source

pub async fn read_last_finalization_info( &self, ) -> Result<FinalizationInfo, Error>

Reads the last finalization information from the repository.

Source

pub async fn read_finalization_info( &self, height: BlockHeight, ) -> Result<FinalizationInfo, Error>

Reads the finalization information at specific height.

Source

pub async fn read_commit( &self, commit_hash: CommitHash, ) -> Result<Commit, Error>

Reads the given commit.

Source

pub async fn read_agendas(&self) -> Result<Vec<(CommitHash, Hash256)>, Error>

Returns the currently valid and height-acceptable agendas in the repository.

Source

pub async fn read_governance_approved_agendas( &self, ) -> Result<Vec<(CommitHash, Hash256)>, Error>

Returns governance-approved agendas in the repository. The result will be a list of agenda proofs, not just agendas.

Source

pub async fn read_blocks(&self) -> Result<Vec<(CommitHash, Hash256)>, Error>

Returns the currently valid and height-acceptable blocks in the repository.

Source

pub async fn check(&self, _starting_height: BlockHeight) -> Result<bool, Error>

Checks the validity of the repository, starting from the given height.

It checks

  1. all the reserved branches and tags
  2. the finalization proof in the fp branch.
  3. the existence of merge commits
  4. the canonical history of the finalized branch.
  5. the reserved state in a valid format.
Source

pub async fn check_gitignore(&self) -> Result<bool, Error>

Checks the existence of .gitignore file and .simperby/ entry in .gitignore. This returns true if both exist.

Source

pub async fn sync( &mut self, commit_hash: CommitHash, ) -> Result<Result<(), String>, Error>

Synchronizes the repository with the given commit (interpreted as a branch tip).

  • Returns Ok(Ok(())) if the branch is successfully received.
  • Returns Ok(Err(_)) if the branch is invalid and thus rejected, with a reason.
  • Returns Err(_) if an error occurs.
  1. Finalization: move the finalized and fp branch to the last finalized block commit.
  2. Block observed: add a b-# branch on the block candidate.
  3. Agenda observed (either governance-approved or not): add an a-# branch on the agenda candidate.

This will verify every commit along the way. If the given commit is not a descendant of the current finalized (i.e., cannot be fast-forwarded), it fails.

Source

pub async fn sync_all( &mut self, ) -> Result<Vec<(String, Result<(), String>)>, Error>

Performs sync() on all local branches and remote tracking branches on the repository.

Returns the list of (branch name, result of sync()).

Source

pub async fn test_push_eligibility( &self, commit_hash: CommitHash, branch_name: String, timestamp: Timestamp, signature: TypedSignature<(CommitHash, String, Timestamp)>, _timestamp_to_test: Timestamp, ) -> Result<bool, Error>

Tests if the given push request is acceptable.

Source

pub async fn clean(&mut self, hard: bool) -> Result<(), Error>

Cleans all the outdated commits, remote repositories and branches.

It will leave only

  • the finalized branch
  • the fp branch when hard is true,

and when hard is false,

  • the p branch
  • the a-# branches
  • the b-# branches will be left as well if only the branches have valid commit sequences and are not outdated (branched from the last finalized commit).
Source

pub async fn broadcast(&mut self) -> Result<(), Error>

Broadcasts all the local messages.

Source

pub async fn flush(&mut self) -> Result<(), Error>

Source

pub async fn update(&mut self, _no_network: bool) -> Result<(), Error>

Updates the repository module with the latest messages from the DMS.

Note that it never finalizes a block. Finalization is done by the consensus module, or the sync method.

Source

pub async fn approve( &mut self, agenda_hash: &Hash256, proof: Vec<TypedSignature<Agenda>>, timestamp: Timestamp, ) -> Result<CommitHash, Error>

Informs that the given agenda has been approved.

After verification, it will create an agenda-proof commit, and update the corresponding a-# branch to it

TODO: get AgendaProof instead.

Source

pub async fn create_transaction( &mut self, transaction: Transaction, ) -> Result<CommitHash, Error>

Creates a transaction commit on top of the HEAD.

Source

pub async fn create_agenda( &mut self, author: MemberName, ) -> Result<(Agenda, CommitHash), Error>

Creates an agenda commit on top of the HEAD.

Source

pub async fn create_block( &mut self, author: PublicKey, ) -> Result<(BlockHeader, CommitHash), Error>

Creates a block commit on top of the HEAD.

Source

pub async fn create_extra_agenda_transaction( &mut self, transaction: &ExtraAgendaTransaction, ) -> Result<CommitHash, Error>

Creates an extra-agenda transaction commit on top of the HEAD.

Source

pub async fn finalize( &mut self, block_commit_hash: CommitHash, proof: FinalizationProof, ) -> Result<CommitHash, Error>

Finalizes the block with the given proof. Returns the commit hash of the updated fp branch.

Source

pub async fn commit_gitignore(&mut self) -> Result<(), Error>

Creates a commit that adds .simperby/ entry to .gitignore. It fails if it exists normally.

Source

pub async fn vote(&mut self, commit_hash: CommitHash) -> Result<(), Error>

Puts a ‘vote’ tag on the commit.

Source

pub async fn veto(&mut self, commit_hash: CommitHash) -> Result<(), Error>

Puts a ‘veto’ tag on the commit.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,