pub struct Blockchain {
    ref_cache: RefCache,
    ledgers: Multiverse<Ledger>,
    storage: Storage,
    block0: HeaderHash,
    rewards_report_all: bool,
}
Expand description

blockchain object, can be safely shared across multiple threads. However it is better not to as some operations may require a mutex.

This objects holds a reference to the persistent storage. It also holds 2 different caching of objects:

  • RefCache: a cache of blocks headers and associated states;
  • Multiverse: of ledger. It is a cache of different ledger states.

Fields§

§ref_cache: RefCache§ledgers: Multiverse<Ledger>§storage: Storage§block0: HeaderHash§rewards_report_all: bool

Implementations§

source§

impl Blockchain

source

pub fn new( block0: HeaderHash, storage: Storage, cache_capacity: usize, rewards_report_all: bool ) -> Self

source

pub fn block0(&self) -> &HeaderHash

source

pub fn storage(&self) -> &Storage

source

pub async fn branches(&self) -> Result<Vec<Branch>, Error>

source

pub async fn gc(&self, tip: Arc<Ref>) -> Result<(), Error>

source

async fn create_and_store_reference( &self, header_hash: HeaderHash, header: Header, ledger: Ledger, time_frame: Arc<TimeFrame>, leadership: Arc<Leadership>, epoch_rewards_info: Option<Arc<EpochRewardsInfo>>, previous_epoch_state: Option<Arc<Ref>> ) -> Arc<Ref>

create and store a reference of this leader to the new

source

pub async fn get_ref( &self, header_hash: HeaderHash ) -> Result<Option<Arc<Ref>>, Error>

get Ref of the given header hash

once the Ref is in hand, it means we have the Leadership schedule associated to this block and the Ledger state after this block.

If the future returns None it means we don’t know about this block locally and it might be necessary to contacts the network to retrieve a missing branch

TODO: the case where the block is in storage but not yet in the cache is not implemented

source

async fn load_header_parent( &self, header: Header, force: bool ) -> Result<PreCheckedHeader, Error>

load the header’s parent Ref.

source

pub async fn pre_check_header( &self, header: Header, force: bool ) -> Result<PreCheckedHeader, Error>

load the header’s parent and perform some simple verification:

  • check the block_date is increasing
  • check the chain_length is monotonically increasing

At the end of this future we know either of:

  • the block is already present (nothing to do);
  • the block’s parent is already present (we can then continue validation)
  • the block’s parent is missing: we need to download it and call again this function.
source

pub async fn post_check_header( &self, header: Header, parent: Arc<Ref>, check_header_proof: CheckHeaderProof ) -> Result<PostCheckedHeader, Error>

check the header cryptographic properties and leadership’s schedule

on success returns the PostCheckedHeader:

  • the header,
  • the ledger state associated to the parent block
  • the leadership schedule associated to the header
source

fn apply_block_dry_run( &self, post_checked_header: &PostCheckedHeader, block: &Block ) -> Result<Ledger, Error>

source

fn apply_block_check_rewards( &self, post_checked_header: &PostCheckedHeader, ledger: &Ledger ) -> Result<(), Error>

source

async fn apply_block_finalize( &self, post_checked_header: PostCheckedHeader, new_ledger: Ledger ) -> Arc<Ref>

source

async fn store_and_apply_block_finalize( &self, post_checked_header: PostCheckedHeader, block: Block, new_ledger: Ledger ) -> Result<AppliedBlock, Error>

source

pub async fn apply_and_store_block( &self, post_checked_header: PostCheckedHeader, block: Block ) -> Result<AppliedBlock, Error>

Apply the block on the blockchain from a post checked header and add it to the storage. If the block is already present in the storage, the returned future resolves to None. Otherwise it returns the reference to the block.

source

pub async fn apply_and_store_leadership_block( &self, leadership_block: LeadershipBlock ) -> Result<AppliedBlock, Error>

Apply the block generated by this node. This should already have a valid state attached to it, so we do not need to verify this one.

source

async fn apply_block0(&self, block0: &Block) -> Result<Branch, Error>

Apply the given block0 in the blockchain (updating the RefCache and the other objects)

This function returns the created block0 branch. Having it will avoid searching for it in the blockchain’s branches and perform operations to update the branch as we move along already.

Errors

The resulted future may fail if

  • the block0 does build an invalid Ledger: Error::Block0InitialLedgerError;
source

pub async fn load_from_block0(&self, block0: Block) -> Result<Tip, Error>

function to do the initial application of the block0 in the Blockchain and its storage. We assume Block0 is not already in the Storage.

This function returns the create block0 branch. Having it will avoid searching for it in the blockchain’s branches and perform operations to update the branch as we move along already.

Errors

The resulted future may fail if

  • the block0 already exists in the storage: Error::Block0AlreadyInStorage;
  • the block0 does build a valid Ledger: Error::Block0InitialLedgerError;
  • other errors while interacting with the storage (IO errors)
source

pub(super) async fn handle_bootstrap_block( &self, block: Block, check_header: CheckHeaderProof ) -> Result<Arc<Ref>, Error>

source

pub async fn load_from_storage(&self, block0: Block) -> Result<Tip, Error>

returns a future that will propagate the initial states and leadership from the block0 to the Head of the storage (the last known block which made consensus).

The Future will returns a branch pointing to the Head.

Errors

The resulted future may fail if

  • the block0 is not already in the storage: Error::Block0NotAlreadyInStorage;
  • the block0 does build a valid Ledger: Error::Block0InitialLedgerError;
  • other errors while interacting with the storage (IO errors)
source

pub fn get_checkpoints(&self, branch: &Branch) -> Checkpoints

Trait Implementations§

source§

impl Clone for Blockchain

source§

fn clone(&self) -> Blockchain

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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.

§

impl<T> FromRef<T> for Twhere T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> Instrument for T

§

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

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

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoRequest<T> for T

source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
source§

impl<T> IntoRequest<T> for T

source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
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