pow_types/
lib.rs

1// Copyright 2021 Conflux Foundation. All rights reserved.
2// Conflux is free software and distributed under GNU General Public License.
3// See http://www.gnu.org/licenses/
4
5use anyhow::Result;
6use async_trait::async_trait;
7use cfx_types::H256;
8use serde::{Deserialize, Serialize};
9
10#[async_trait]
11pub trait PowInterface: Send + Sync {
12    // TODO(lpl): Wait for new pivot decision.
13    async fn next_pivot_decision(
14        &self, parent_decision: H256,
15    ) -> Option<(u64, H256)>;
16
17    fn validate_proposal_pivot_decision(
18        &self, parent_decision: H256, me_decision: H256,
19    ) -> bool;
20
21    fn get_staking_events(
22        &self, parent_height: u64, me_height: u64, parent_decision: H256,
23        me_decision: H256,
24    ) -> Result<Vec<StakingEvent>>;
25
26    async fn wait_for_initialization(&self, last_decision: H256);
27
28    fn is_normal_phase(&self) -> bool;
29}
30
31#[derive(Debug, Eq, PartialEq, Serialize, Deserialize)]
32pub enum StakingEvent {
33    /// (address, bls_public_key, vrf_public_key)
34    Register(H256, Vec<u8>, Vec<u8>),
35    /// (address, updated_voting_power)
36    IncreaseStake(H256, u64),
37    /// (address, unlock_voting_power)
38    Retire(H256, u64),
39}
40
41/// This is just used to execute PoS genesis, where pow_handler will not be
42/// used.
43pub struct FakePowHandler {}
44
45#[async_trait]
46impl PowInterface for FakePowHandler {
47    async fn next_pivot_decision(
48        &self, _parent_decision: H256,
49    ) -> Option<(u64, H256)> {
50        todo!()
51    }
52
53    fn validate_proposal_pivot_decision(
54        &self, _parent_decision: H256, _me_decision: H256,
55    ) -> bool {
56        todo!()
57    }
58
59    fn get_staking_events(
60        &self, _parent_height: u64, _me_height: u64, _parent_decision: H256,
61        _me_decision: H256,
62    ) -> Result<Vec<StakingEvent>> {
63        todo!()
64    }
65
66    async fn wait_for_initialization(&self, _last_decision: H256) { todo!() }
67
68    fn is_normal_phase(&self) -> bool { todo!() }
69}