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