namada_node/shell/block_alloc/states/
normal_txs.rs1use std::marker::PhantomData;
2
3use super::super::{AllocFailure, BlockAllocator, TxBin};
4use super::{
5 BuildingNormalTxBatch, BuildingProtocolTxBatch, NextStateImpl, TryAlloc,
6 WithoutNormalTxs,
7};
8use crate::shell::block_alloc::BlockResources;
9
10impl TryAlloc for BlockAllocator<BuildingNormalTxBatch> {
11 type Resources<'tx> = BlockResources<'tx>;
12
13 #[inline]
14 fn try_alloc(
15 &mut self,
16 resource_required: Self::Resources<'_>,
17 ) -> Result<(), AllocFailure> {
18 self.normal_txs.space.try_dump(resource_required.tx)?;
19 self.normal_txs.gas.try_dump(resource_required.gas)
20 }
21}
22
23impl NextStateImpl for BlockAllocator<BuildingNormalTxBatch> {
24 type Next = BlockAllocator<BuildingProtocolTxBatch<WithoutNormalTxs>>;
25
26 #[inline]
27 fn next_state_impl(mut self) -> Self::Next {
28 let remaining_free_space = self.unoccupied_space_in_bytes();
29 self.protocol_txs = TxBin::init(remaining_free_space);
30 let Self {
32 block,
33 protocol_txs,
34 normal_txs,
35 ..
36 } = self;
37
38 BlockAllocator {
39 _state: PhantomData,
40 block,
41 protocol_txs,
42 normal_txs,
43 }
44 }
45}