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
impl DistributedRepository
pub fn get_raw(&self) -> Arc<RwLock<RawRepository>>
pub async fn new( raw: Arc<RwLock<RawRepository>>, config: Config, private_key: Option<PrivateKey> ) -> Result<Self, Error>
sourcepub async fn genesis(raw: RawRepository) -> Result<(), Error>
pub async fn genesis(raw: RawRepository) -> Result<(), Error>
Initializes the genesis repository, leaving a genesis header.
It also
- creates
fpbranch and its commit (for the genesis block). - creates the
finalizedbranch.
Note that genesis can be called on any commit except a merge commit.
sourcepub async fn read_last_finalization_info(
&self
) -> Result<FinalizationInfo, Error>
pub async fn read_last_finalization_info( &self ) -> Result<FinalizationInfo, Error>
Reads the last finalization information from the repository.
sourcepub async fn read_finalization_info(
&self,
_height: BlockHeight
) -> Result<FinalizationInfo, Error>
pub async fn read_finalization_info( &self, _height: BlockHeight ) -> Result<FinalizationInfo, Error>
Reads the finalization information at specific height.
sourcepub async fn read_commit(
&self,
commit_hash: CommitHash
) -> Result<Commit, Error>
pub async fn read_commit( &self, commit_hash: CommitHash ) -> Result<Commit, Error>
Reads the given commit.
sourcepub async fn read_agendas(&self) -> Result<Vec<(CommitHash, Hash256)>, Error>
pub async fn read_agendas(&self) -> Result<Vec<(CommitHash, Hash256)>, Error>
Returns the currently valid and height-acceptable agendas in the repository.
sourcepub async fn read_governance_approved_agendas(
&self
) -> Result<Vec<(CommitHash, Hash256)>, Error>
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.
sourcepub async fn read_blocks(&self) -> Result<Vec<(CommitHash, Hash256)>, Error>
pub async fn read_blocks(&self) -> Result<Vec<(CommitHash, Hash256)>, Error>
Returns the currently valid and height-acceptable blocks in the repository.
sourcepub async fn check(&self, _starting_height: BlockHeight) -> Result<bool, Error>
pub async fn check(&self, _starting_height: BlockHeight) -> Result<bool, Error>
Checks the validity of the repository, starting from the given height.
It checks
- all the reserved branches and tags
- the finalization proof in the
fpbranch. - the existence of merge commits
- the canonical history of the
finalizedbranch. - the reserved state in a valid format.
sourcepub async fn check_gitignore(&self) -> Result<bool, Error>
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.
sourcepub async fn sync(
&mut self,
commit_hash: CommitHash
) -> Result<Result<(), String>, Error>
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.
- Finalization: move the
finalizedandfpbranch to the last finalized block commit. - Block observed: add a
b-#branch on the block candidate. - 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.
sourcepub async fn sync_all(
&mut self
) -> Result<Vec<(String, Result<(), String>)>, Error>
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()).
sourcepub 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>
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.
sourcepub async fn clean(&mut self, hard: bool) -> Result<(), Error>
pub async fn clean(&mut self, hard: bool) -> Result<(), Error>
Cleans all the outdated commits, remote repositories and branches.
It will leave only
- the
finalizedbranch - the
fpbranch whenhardistrue,
and when hard is false,
- the
pbranch - 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).
pub async fn flush(&mut self) -> Result<(), Error>
pub async fn update(&mut self) -> Result<(), Error>
sourcepub async fn approve(
&mut self,
agenda_hash: &Hash256,
proof: Vec<TypedSignature<Agenda>>,
timestamp: Timestamp
) -> Result<CommitHash, Error>
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.
sourcepub async fn create_agenda(
&mut self,
author: MemberName
) -> Result<(Agenda, CommitHash), Error>
pub async fn create_agenda( &mut self, author: MemberName ) -> Result<(Agenda, CommitHash), Error>
Creates an agenda commit on top of the HEAD.
sourcepub async fn create_block(
&mut self,
author: PublicKey
) -> Result<(BlockHeader, CommitHash), Error>
pub async fn create_block( &mut self, author: PublicKey ) -> Result<(BlockHeader, CommitHash), Error>
Creates a block commit on top of the HEAD.
sourcepub async fn create_extra_agenda_transaction(
&mut self,
transaction: &ExtraAgendaTransaction
) -> Result<CommitHash, Error>
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.
sourcepub async fn finalize(
&mut self,
block_commit_hash: CommitHash,
proof: FinalizationProof
) -> Result<CommitHash, Error>
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.
sourcepub async fn commit_gitignore(&mut self) -> Result<(), Error>
pub async fn commit_gitignore(&mut self) -> Result<(), Error>
Creates a commit that adds .simperby/ entry to .gitignore.
It fails if it exists normally.