pub struct Consensus {
    pub parameters: ChainParams,
}
Expand description

This struct contains all the information and methods needed to validate a block, it is used by the [ChainState] to validate blocks and transactions.

Fields§

§parameters: ChainParams

The parameters of the chain we are validating, it is usually hardcoded constants. See ChainParams for more information.

Implementations§

source§

impl Consensus

source

pub fn get_subsidy(&self, height: u32) -> u64

Returns the amount of block subsidy to be paid in a block, given it’s height. Bitcoin Core source: https://github.com/bitcoin/bitcoin/blob/2b211b41e36f914b8d0487e698b619039cc3c8e2/src/validation.cpp#L1501-L1512

source

pub fn verify_block_transactions( height: u32, utxos: HashMap<OutPoint, TxOut>, transactions: &[Transaction], subsidy: u64, verify_script: bool, flags: c_uint ) -> Result<(), BlockchainError>

Verify if all transactions in a block are valid. Here we check the following:

  • The block must contain at least one transaction, and this transaction must be coinbase
  • The first transaction in the block must be coinbase
  • The coinbase transaction must have the correct value (subsidy + fees)
  • The block must not create more coins than allowed
  • All transactions must be valid:
    • The transaction must not be coinbase (already checked)
    • The transaction must not have duplicate inputs
    • The transaction must not spend more coins than it claims in the inputs
    • The transaction must have valid scripts
source

pub fn calc_next_work_required( last_block: &BlockHeader, first_block: &BlockHeader, params: ChainParams ) -> Target

Calculates the next target for the proof of work algorithm, given the current target and the time it took to mine the last 2016 blocks.

source

pub fn update_acc( acc: &Stump, block: &Block, height: u32, proof: Proof, del_hashes: Vec<Hash> ) -> Result<Stump, BlockchainError>

Updates our accumulator with the new block. This is done by calculating the new root hash of the accumulator, and then verifying the proof of inclusion of the deleted nodes. If the proof is valid, we return the new accumulator. Otherwise, we return an error. This function is pure, it doesn’t modify the accumulator, but returns a new one.

Trait Implementations§

source§

impl Clone for Consensus

source§

fn clone(&self) -> Consensus

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

impl Debug for Consensus

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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.

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> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

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

Initializes a with the given initializer. Read more
source§

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

Dereferences the given pointer. Read more
source§

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

Mutably dereferences the given pointer. Read more
source§

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.