1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use fuel_core_interfaces::{
    common::{
        fuel_asm::Word,
        fuel_tx::{
            Receipt,
            Transaction,
        },
    },
    db::DatabaseTransaction,
    executor::UncommittedResult,
    model::{
        BlockHeight,
        BlockId,
        FuelBlockConsensus,
    },
};

pub trait BlockDb: Send + Sync {
    fn block_height(&self) -> anyhow::Result<BlockHeight>;

    // Returns error if already sealed
    fn seal_block(
        &mut self,
        block_id: BlockId,
        consensus: FuelBlockConsensus,
    ) -> anyhow::Result<()>;
}

// TODO: Replace by the analog from the `fuel-core-storage`.
pub type DBTransaction<Database> = Box<dyn DatabaseTransaction<Database>>;

#[async_trait::async_trait]
pub trait BlockProducer<Database>: Send + Sync {
    // TODO: Right now production and execution of the block is one step, but in the future,
    //  `produce_block` should only produce a block without affecting the blockchain state.
    async fn produce_and_execute_block(
        &self,
        height: BlockHeight,
        max_gas: Word,
    ) -> anyhow::Result<UncommittedResult<DBTransaction<Database>>>;

    async fn dry_run(
        &self,
        transaction: Transaction,
        height: Option<BlockHeight>,
        utxo_validation: Option<bool>,
    ) -> anyhow::Result<Vec<Receipt>>;
}