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 fn get_dms(&self) -> Option<Arc<RwLock<Dms<RepositoryMessage>>>>
pub async fn new( dms: Option<Arc<RwLock<Dms<RepositoryMessage>>>>, 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
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.
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
fp
branch. - the existence of merge commits
- the canonical history of the
finalized
branch. - 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
finalized
andfp
branch 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
finalized
branch - the
fp
branch whenhard
istrue
,
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).
pub async fn flush(&mut self) -> Result<(), Error>
Sourcepub async fn update(&mut self, _no_network: bool) -> Result<(), Error>
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.
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_transaction(
&mut self,
transaction: Transaction,
) -> Result<CommitHash, Error>
pub async fn create_transaction( &mut self, transaction: Transaction, ) -> Result<CommitHash, Error>
Creates a transaction commit on top of the HEAD.
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.