pub struct Reference {
    ledger: Ledger,
    header: Header,
    epoch_info: Arc<EpochInfo>,
    previous_epoch_state: Option<Arc<Reference>>,
}

Fields§

§ledger: Ledger

the ledger at the state of the left by applying the current block and all the previous blocks before that.

§header: Header

keeping the block’s header here to save some lookup time in the storage it contains all needed to retrieve the block from the storage (the HeaderId) but also all the metadata associated to the block (parent, date, depth…).

§epoch_info: Arc<EpochInfo>

the block’s epoch info

§previous_epoch_state: Option<Arc<Reference>>

last Ref. Every time there is a transition this value will be filled with the parent Ref. Otherwise it will be copied from Ref to Ref.

Implementations§

source§

impl Reference

source

pub fn new(block0: &Block) -> Result<Self, Error>

create a new block reference with the given block0

This will mark the beginning of a new blockchain as there is no expected parents before this block. Thought he block_parent_hash may refer to a block hash from another blockchain or may have a specific meaning

source

pub fn approximate_common_ancestor( self: &Arc<Self>, other: &Arc<Self> ) -> Option<Arc<Self>>

approximate a common ancestor between the given References

This will lead to a common ancestor within the epoch boundary as this is the only References that may be kept.

There is only 2 reasons for this function to return None:

  1. the 2 blocks are from different blockchain;
  2. one of the blocks are from the first epoch
source

pub fn select(self: &Arc<Self>, candidate: &Arc<Self>) -> Selection

compare the current Reference with the candidate one

source

pub fn chain(self: Arc<Self>, block: &Block) -> Result<Self, Error>

chain a new block, expecting the new block to be a child of the given block

This function will also perform all the necessary checks to make sure this block is valid within the initial context (parent hash, chain length, ledger and block signatures)

source

pub fn epoch_transition(&self) -> Result<Self, Error>

once we suppose the end of an epoch as come, we can compute the missing steps to finalize the epoch: apply the protocol changes and distribute the rewards

source

pub fn new_epoch_info(&self, epoch: Epoch) -> Result<Arc<EpochInfo>, Error>

compute a new epoch info from the given Reference for the given Epoch

We are not performing any checks here, merely generating a new Leadership object of the given state.

source

fn chain_epoch_info(self: Arc<Self>, block: &Block) -> Result<Arc<Self>, Error>

source

fn check_child(&self, block: &Block) -> Result<(), Error>

source

fn check_chain_length(&self, block: &Block) -> Result<(), Error>

source

fn check_block_date(&self, block: &Block) -> Result<(), Error>

source

pub fn hash(&self) -> HeaderId

retrieve the header hash of the Ref

source

pub fn block_parent_hash(&self) -> HeaderId

access the reference’s parent hash

source

pub fn block_date(&self) -> BlockDate

retrieve the block date of the Ref

source

pub fn chain_length(&self) -> ChainLength

retrieve the chain length, the number of blocks created between the block0 and this block. This is useful to compare the density of 2 branches.

source

pub fn header(&self) -> &Header

access the Header of the block pointed by this Ref

source

pub fn ledger(&self) -> &Ledger

source

pub fn epoch_info(&self) -> Arc<EpochInfo>

retrieve the block’s epoch info

source

pub fn time(&self) -> SystemTime

get the time the block was schedule for

panics

This function will panic is the block does not coincide with the epoch’s time era. This should not happen by construct as the Reference has been constructed and validated already.

source

pub fn elapsed(&self) -> Result<Duration, SystemTimeError>

retrieve the number of seconds since this block was schedule

If the block was schedule in the future, the function will return an error.

source

pub(crate) fn previous_epoch_state(&self) -> Option<&Arc<Self>>

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

§

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, 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