-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
prover.rs
185 lines (154 loc) · 6.74 KB
/
prover.rs
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
// Copyright (C) 2019-2023 Aleo Systems Inc.
// This file is part of the snarkOS library.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use crate::LedgerService;
use snarkvm::{
ledger::{
block::{Block, Transaction},
committee::Committee,
narwhal::{BatchCertificate, Data, Subdag, Transmission, TransmissionID},
puzzle::{Solution, SolutionID},
},
prelude::{bail, Address, Field, Network, Result},
};
use indexmap::IndexMap;
use std::ops::Range;
/// A ledger service for a prover.
#[derive(Clone, Debug, Default)]
pub struct ProverLedgerService<N: Network> {
_network: std::marker::PhantomData<N>,
}
impl<N: Network> ProverLedgerService<N> {
/// Initializes a new prover ledger service.
pub fn new() -> Self {
Self { _network: Default::default() }
}
}
#[async_trait]
impl<N: Network> LedgerService<N> for ProverLedgerService<N> {
/// Returns the latest round in the ledger.
fn latest_round(&self) -> u64 {
0u64
}
/// Returns the latest block height in the ledger.
fn latest_block_height(&self) -> u32 {
0u32
}
/// Returns the latest block in the ledger.
fn latest_block(&self) -> Block<N> {
unreachable!("Latest block does not exist in prover")
}
/// Returns the latest cached leader and its associated round.
fn latest_leader(&self) -> Option<(u64, Address<N>)> {
unreachable!("Latest leader does not exist in prover");
}
/// Updates the latest cached leader and its associated round.
fn update_latest_leader(&self, _round: u64, _leader: Address<N>) {
unreachable!("Latest leader does not exist in prover");
}
/// Returns `true` if the given block height exists in the ledger.
fn contains_block_height(&self, _height: u32) -> bool {
false
}
/// Returns the block height for the given block hash, if it exists.
fn get_block_height(&self, hash: &N::BlockHash) -> Result<u32> {
bail!("Block hash '{hash}' does not exist in prover")
}
/// Returns the block hash for the given block height, if it exists.
fn get_block_hash(&self, height: u32) -> Result<N::BlockHash> {
bail!("Block {height} does not exist in prover")
}
/// Returns the block round for the given block height, if it exists.
fn get_block_round(&self, height: u32) -> Result<u64> {
bail!("Block {height} does not exist in prover")
}
/// Returns the block for the given block height.
fn get_block(&self, height: u32) -> Result<Block<N>> {
bail!("Block {height} does not exist in prover")
}
/// Returns the blocks in the given block range.
/// The range is inclusive of the start and exclusive of the end.
fn get_blocks(&self, heights: Range<u32>) -> Result<Vec<Block<N>>> {
bail!("Blocks {heights:?} do not exist in prover")
}
/// Returns the solution for the given solution ID.
fn get_solution(&self, solution_id: &SolutionID<N>) -> Result<Solution<N>> {
bail!("Solution '{solution_id}' does not exist in prover")
}
/// Returns the unconfirmed transaction for the given transaction ID.
fn get_unconfirmed_transaction(&self, transaction_id: N::TransactionID) -> Result<Transaction<N>> {
bail!("Transaction '{transaction_id}' does not exist in prover")
}
/// Returns the batch certificate for the given batch certificate ID.
fn get_batch_certificate(&self, certificate_id: &Field<N>) -> Result<BatchCertificate<N>> {
bail!("Batch certificate '{certificate_id}' does not exist in prover")
}
/// Returns the current committee.
fn current_committee(&self) -> Result<Committee<N>> {
bail!("Committee does not exist in prover")
}
/// Returns the committee for the given round.
/// If the given round is in the future, then the current committee is returned.
fn get_committee_for_round(&self, round: u64) -> Result<Committee<N>> {
bail!("Committee for round {round} does not exist in prover")
}
/// Returns the committee lookback for the given round.
/// If the committee lookback round is in the future, then the current committee is returned.
fn get_committee_lookback_for_round(&self, round: u64) -> Result<Committee<N>> {
bail!("Previous committee for round {round} does not exist in prover")
}
/// Returns `true` if the ledger contains the given certificate ID in block history.
fn contains_certificate(&self, certificate_id: &Field<N>) -> Result<bool> {
bail!("Certificate '{certificate_id}' does not exist in prover")
}
/// Returns `true` if the transmission exists in the ledger.
fn contains_transmission(&self, transmission_id: &TransmissionID<N>) -> Result<bool> {
bail!("Transmission '{transmission_id}' does not exist in prover")
}
/// Ensures that the given transmission is not a fee and matches the given transmission ID.
fn ensure_transmission_is_well_formed(
&self,
_transmission_id: TransmissionID<N>,
_transmission: &mut Transmission<N>,
) -> Result<()> {
Ok(())
}
/// Checks the given solution is well-formed.
async fn check_solution_basic(&self, _solution_id: SolutionID<N>, _solution: Data<Solution<N>>) -> Result<()> {
Ok(())
}
/// Checks the given transaction is well-formed and unique.
async fn check_transaction_basic(
&self,
_transaction_id: N::TransactionID,
_transaction: Data<Transaction<N>>,
) -> Result<()> {
Ok(())
}
/// Checks the given block is valid next block.
fn check_next_block(&self, _block: &Block<N>) -> Result<()> {
Ok(())
}
/// Returns a candidate for the next block in the ledger, using a committed subdag and its transmissions.
#[cfg(feature = "ledger-write")]
fn prepare_advance_to_next_quorum_block(
&self,
_subdag: Subdag<N>,
_transmissions: IndexMap<TransmissionID<N>, Transmission<N>>,
) -> Result<Block<N>> {
bail!("Cannot prepare advance to next quorum block in prover")
}
/// Adds the given block as the next block in the ledger.
#[cfg(feature = "ledger-write")]
fn advance_to_next_block(&self, block: &Block<N>) -> Result<()> {
bail!("Cannot advance to next block in prover - {block}")
}
}