massa_models/
composite.rs

1// Copyright (c) 2022 MASSA LABS <info@massa.net>
2
3use crate::prehash::PreHashMap;
4use crate::{address::Address, block_id::BlockId, operation::SecureShareOperation};
5use massa_signature::{PublicKey, Signature};
6use serde::{Deserialize, Serialize};
7use std::fmt::Display;
8
9/// Status in which an operation can be (derived from the block status)
10#[derive(Debug, Clone, Serialize, Deserialize)]
11pub enum OperationSearchResultBlockStatus {
12    /// the block hasn't been processed by consensus yet
13    Incoming,
14    /// the block waits for it's slot for further processing
15    WaitingForSlot,
16    /// the block waits for dependencies for further processing
17    WaitingForDependencies,
18    /// the block has been processed and is valid
19    Active,
20    /// the block is discarded
21    Discarded,
22}
23
24/// Status in which an operation can be
25#[derive(Debug, Clone, Serialize, Deserialize)]
26pub enum OperationSearchResultStatus {
27    /// in pool
28    Pending,
29    /// in a block, the block being in `[OperationSearchResultBlockStatus]`
30    InBlock(OperationSearchResultBlockStatus),
31    /// discarded
32    Discarded,
33}
34
35/// operation info
36#[derive(Clone, Debug, Serialize, Deserialize)]
37pub struct OperationSearchResult {
38    /// the operation
39    pub op: SecureShareOperation,
40    /// true if in pool
41    pub in_pool: bool,
42    /// maps block id to index on the operation in the block and if it's final
43    pub in_blocks: PreHashMap<BlockId, (usize, bool)>,
44    /// operation status
45    pub status: OperationSearchResultStatus,
46}
47
48impl OperationSearchResult {
49    /// combine two operation search result
50    pub fn extend(&mut self, other: &OperationSearchResult) {
51        self.in_pool = self.in_pool || other.in_pool;
52        self.in_blocks.extend(other.in_blocks.iter());
53    }
54}
55
56/// all the production stats for every known staker
57#[derive(Clone, Debug, Serialize, Deserialize)]
58pub struct StakersCycleProductionStats {
59    /// cycle number
60    pub cycle: u64,
61    /// if that cycle is final
62    pub is_final: bool,
63    /// map address to produced valid block count and not valid but expected block count
64    /// really a re arranged `[crate::address::AddressCycleProductionStats]`
65    pub ok_nok_counts: PreHashMap<Address, (u64, u64)>,
66}
67
68/// just a public key and a signature it has produced
69/// used for serialization/deserialization purpose
70#[derive(Debug, Clone, Serialize, Deserialize)]
71pub struct PubkeySig {
72    /// public key
73    pub public_key: PublicKey,
74    /// signature
75    pub signature: Signature,
76}
77
78impl Display for PubkeySig {
79    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
80        writeln!(f, "Public key: {}", self.public_key)?;
81        writeln!(f, "Signature: {}", self.signature)
82    }
83}