Struct grin_core::core::block::Block

source ·
pub struct Block {
    pub header: BlockHeader,
    pub body: TransactionBody,
}
Expand description

A block as expressed in the Mimblewimble protocol. The reward is non-explicit, assumed to be deducible from block height (similar to bitcoin’s schedule) and expressed as a global transaction fee (added v.H), additive to the total of fees ever collected.

Fields§

§header: BlockHeader

The header with metadata and commitments to the rest of the data

§body: TransactionBody

The body - inputs/outputs/kernels

Implementations§

source§

impl Block

source

pub fn new( prev: &BlockHeader, txs: &[Transaction], difficulty: Difficulty, reward_output: (Output, TxKernel) ) -> Result<Block, Error>

Builds a new block from the header of the previous block, a vector of transactions and the private key that will receive the reward. Checks that all transactions are valid and calculates the Merkle tree.

TODO - Move this somewhere where only tests will use it. *** Only used in tests. ***

source

pub fn hydrate_from( cb: CompactBlock, txs: &[Transaction] ) -> Result<Block, Error>

Hydrate a block from a compact block. Note: caller must validate the block themselves, we do not validate it here.

source

pub fn with_header(header: BlockHeader) -> Block

Build a new empty block from a specified header

source

pub fn from_reward( prev: &BlockHeader, txs: &[Transaction], reward_out: Output, reward_kern: TxKernel, difficulty: Difficulty ) -> Result<Block, Error>

Builds a new block ready to mine from the header of the previous block, a vector of transactions and the reward information. Checks that all transactions are valid and calculates the Merkle tree.

source

pub fn with_reward(self, reward_out: Output, reward_kern: TxKernel) -> Block

Consumes this block and returns a new block with the coinbase output and kernels added

source

pub fn inputs(&self) -> Inputs

Get inputs

source

pub fn outputs(&self) -> &[Output]

Get outputs

source

pub fn kernels(&self) -> &[TxKernel]

Get kernels

source

pub fn total_fees(&self) -> u64

Sum of all fees (inputs less outputs) in the block

source

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

“Lightweight” validation that we can perform quickly during read/deserialization. Subset of full validation that skips expensive verification steps, specifically -

  • rangeproof verification (on the body)
  • kernel signature verification (on the body)
  • coinbase sum verification
  • kernel sum verification
source

pub fn validate(&self, prev_kernel_offset: &BlindingFactor) -> Result<(), Error>

Validates all the elements in a block that can be checked without additional data. Includes commitment sums and kernels, Merkle trees, reward, etc.

source

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

Validate the coinbase.body.outputs generated by miners. Check the sum of coinbase-marked outputs match the sum of coinbase-marked kernels accounting for fees.

Trait Implementations§

source§

impl Clone for Block

source§

fn clone(&self) -> Block

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 Committed for Block

Provides all information from a block that allows the calculation of total Pedersen commitment.

source§

fn inputs_committed(&self) -> Vec<Commitment>

Vector of input commitments to verify.
source§

fn outputs_committed(&self) -> Vec<Commitment>

Vector of output commitments to verify.
source§

fn kernels_committed(&self) -> Vec<Commitment>

Vector of kernel excesses to verify.
source§

fn sum_kernel_excesses( &self, offset: &BlindingFactor ) -> Result<(Commitment, Commitment), Error>

Gather the kernel excesses and sum them.
source§

fn sum_commitments(&self, overage: i64) -> Result<Commitment, Error>

Gathers commitments and sum them.
source§

fn verify_kernel_sums( &self, overage: i64, kernel_offset: BlindingFactor ) -> Result<(Commitment, Commitment), Error>

Verify the sum of the kernel excesses equals the sum of the outputs, taking into account both the kernel_offset and overage.
source§

impl Debug for Block

source§

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

Formats the value using the given formatter. Read more
source§

impl Default for Block

Default properties for a block, everything zeroed out and empty vectors.

source§

fn default() -> Block

Returns the “default value” for a type. Read more
source§

impl From<Block> for CompactBlock

source§

fn from(block: Block) -> Self

Converts to this type from the input type.
source§

impl From<UntrustedBlock> for Block

source§

fn from(block: UntrustedBlock) -> Self

Converts to this type from the input type.
source§

impl Hashed for Block

source§

fn hash(&self) -> Hash

The hash of the underlying block.

source§

impl Readable for Block

Implementation of Readable for a block, defines how to read a full block from a binary stream.

source§

fn read<R: Reader>(reader: &mut R) -> Result<Block, Error>

Reads the data necessary to this Readable from the provided reader
source§

impl Serialize for Block

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Writeable for Block

Implementation of Writeable for a block, defines how to write the block to a binary writer. Differentiates between writing the block for the purpose of full serialization and the one of just extracting a hash.

source§

fn write<W: Writer>(&self, writer: &mut W) -> Result<(), Error>

Write the data held by this Writeable to the provided writer

Auto Trait Implementations§

§

impl Freeze for Block

§

impl RefUnwindSafe for Block

§

impl Send for Block

§

impl Sync for Block

§

impl Unpin for Block

§

impl UnwindSafe for Block

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneAny for T
where T: Any + Clone,

source§

fn clone_any(&self) -> Box<dyn CloneAny>

source§

fn clone_any_send(&self) -> Box<dyn CloneAny + Send>
where T: Send,

source§

fn clone_any_sync(&self) -> Box<dyn CloneAny + Sync>
where T: Sync,

source§

fn clone_any_send_sync(&self) -> Box<dyn CloneAny + Send + Sync>
where T: Send + Sync,

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where 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> Same for T

§

type Output = T

Should always be Self
source§

impl<H> ShortIdentifiable for H
where H: Hashed,

source§

fn short_id(&self, hash: &Hash, nonce: u64) -> ShortId

Generate a short_id via the following -

  • extract k0/k1 from block_hash hashed with the nonce (first two u64 values) * initialize a siphasher24 with k0/k1
    • self.hash() passing in the siphasher24 instance
    • drop the 2 most significant bytes (to return a 6 byte short_id)
source§

impl<T> ToOwned for T
where 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 T
where 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 T
where 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.
source§

impl<T> DebugAny for T
where T: Any + Debug,

source§

impl<T> UnsafeAny for T
where T: Any,