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 fn get_raw(&self) -> Arc<RwLock<RawRepository>>

source

pub async fn new( 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) -> Result<(), Error>

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_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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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<T> for T

§

type Output = T

Should always be Self
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.
§

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

§

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