Skip to main content

hotmint_types/
context.rs

1use serde::{Deserialize, Serialize};
2
3use crate::block::Height;
4use crate::epoch::EpochNumber;
5use crate::validator::{ValidatorId, ValidatorSet};
6use crate::view::ViewNumber;
7
8/// Context provided to Application trait methods during block processing.
9pub struct BlockContext<'a> {
10    pub height: Height,
11    pub view: ViewNumber,
12    pub proposer: ValidatorId,
13    pub epoch: EpochNumber,
14    pub epoch_start_view: ViewNumber,
15    pub validator_set: &'a ValidatorSet,
16    /// Aggregated vote extensions from the previous round's Vote2 messages.
17    /// Only populated for `create_payload` when the previous round committed
18    /// via a DoubleCertificate whose Vote2 round carried extensions.
19    pub vote_extensions: Vec<(ValidatorId, Vec<u8>)>,
20}
21
22/// Lightweight context for transaction validation (mempool admission).
23/// Unlike [`BlockContext`], this does not require a specific block.
24#[derive(Debug, Clone, Serialize, Deserialize)]
25pub struct TxContext {
26    pub height: Height,
27    pub epoch: EpochNumber,
28}
29
30/// Owned version of [`BlockContext`] for cross-process IPC.
31///
32/// `BlockContext<'a>` borrows the `ValidatorSet`, which cannot be sent across
33/// process boundaries. This type owns all its data and is serializable.
34#[derive(Debug, Clone, Serialize, Deserialize)]
35pub struct OwnedBlockContext {
36    pub height: Height,
37    pub view: ViewNumber,
38    pub proposer: ValidatorId,
39    pub epoch: EpochNumber,
40    pub epoch_start_view: ViewNumber,
41    pub validator_set: ValidatorSet,
42    #[serde(default)]
43    pub vote_extensions: Vec<(ValidatorId, Vec<u8>)>,
44}
45
46impl From<&BlockContext<'_>> for OwnedBlockContext {
47    fn from(ctx: &BlockContext<'_>) -> Self {
48        Self {
49            height: ctx.height,
50            view: ctx.view,
51            proposer: ctx.proposer,
52            epoch: ctx.epoch,
53            epoch_start_view: ctx.epoch_start_view,
54            validator_set: ctx.validator_set.clone(),
55            vote_extensions: ctx.vote_extensions.clone(),
56        }
57    }
58}