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}
17
18/// Lightweight context for transaction validation (mempool admission).
19/// Unlike [`BlockContext`], this does not require a specific block.
20#[derive(Debug, Clone, Serialize, Deserialize)]
21pub struct TxContext {
22    pub height: Height,
23    pub epoch: EpochNumber,
24}
25
26/// Owned version of [`BlockContext`] for cross-process IPC.
27///
28/// `BlockContext<'a>` borrows the `ValidatorSet`, which cannot be sent across
29/// process boundaries. This type owns all its data and is serializable.
30#[derive(Debug, Clone, Serialize, Deserialize)]
31pub struct OwnedBlockContext {
32    pub height: Height,
33    pub view: ViewNumber,
34    pub proposer: ValidatorId,
35    pub epoch: EpochNumber,
36    pub epoch_start_view: ViewNumber,
37    pub validator_set: ValidatorSet,
38}
39
40impl From<&BlockContext<'_>> for OwnedBlockContext {
41    fn from(ctx: &BlockContext<'_>) -> Self {
42        Self {
43            height: ctx.height,
44            view: ctx.view,
45            proposer: ctx.proposer,
46            epoch: ctx.epoch,
47            epoch_start_view: ctx.epoch_start_view,
48            validator_set: ctx.validator_set.clone(),
49        }
50    }
51}