hotshot_builder_api/v0_1/
data_source.rs

1// Copyright (c) 2021-2024 Espresso Systems (espressosys.com)
2// This file is part of the HotShot repository.
3
4// You should have received a copy of the MIT License
5// along with the HotShot repository. If not, see <https://mit-license.org/>.
6
7use async_trait::async_trait;
8use committable::Commitment;
9use hotshot_types::{
10    data::VidCommitment,
11    traits::{node_implementation::NodeType, signature_key::SignatureKey},
12    utils::BuilderCommitment,
13};
14
15use super::{
16    block_info::{AvailableBlockData, AvailableBlockHeaderInputV1, AvailableBlockInfo},
17    builder::{BuildError, TransactionStatus},
18};
19
20#[async_trait]
21pub trait BuilderDataSource<TYPES: NodeType> {
22    /// To get the list of available blocks
23    async fn available_blocks(
24        &self,
25        for_parent: &VidCommitment,
26        view_number: u64,
27        sender: TYPES::SignatureKey,
28        signature: &<TYPES::SignatureKey as SignatureKey>::PureAssembledSignatureType,
29    ) -> Result<Vec<AvailableBlockInfo<TYPES>>, BuildError>;
30
31    /// To claim a block from the list of provided available blocks
32    async fn claim_block(
33        &self,
34        block_hash: &BuilderCommitment,
35        view_number: u64,
36        sender: TYPES::SignatureKey,
37        signature: &<TYPES::SignatureKey as SignatureKey>::PureAssembledSignatureType,
38    ) -> Result<AvailableBlockData<TYPES>, BuildError>;
39
40    /// To claim a block from the list of provided available blocks and provide the number of nodes
41    /// information to the builder for VID computation.
42    async fn claim_block_with_num_nodes(
43        &self,
44        block_hash: &BuilderCommitment,
45        view_number: u64,
46        sender: TYPES::SignatureKey,
47        signature: &<TYPES::SignatureKey as SignatureKey>::PureAssembledSignatureType,
48        num_nodes: usize,
49    ) -> Result<AvailableBlockData<TYPES>, BuildError>;
50
51    /// To claim a block header input
52    async fn claim_block_header_input(
53        &self,
54        block_hash: &BuilderCommitment,
55        view_number: u64,
56        sender: TYPES::SignatureKey,
57        signature: &<TYPES::SignatureKey as SignatureKey>::PureAssembledSignatureType,
58    ) -> Result<AvailableBlockHeaderInputV1<TYPES>, BuildError>;
59
60    /// To get the builder's address
61    async fn builder_address(&self) -> Result<TYPES::BuilderSignatureKey, BuildError>;
62}
63
64#[async_trait]
65pub trait AcceptsTxnSubmits<I>
66where
67    I: NodeType,
68{
69    async fn submit_txns(
70        &self,
71        txns: Vec<<I as NodeType>::Transaction>,
72    ) -> Result<Vec<Commitment<<I as NodeType>::Transaction>>, BuildError>;
73
74    async fn txn_status(
75        &self,
76        txn_hash: Commitment<<I as NodeType>::Transaction>,
77    ) -> Result<TransactionStatus, BuildError>;
78}