Skip to content

Commit 3bc234e

Browse files
foriequal0mergify[bot]
authored andcommitted
Remove unused insert_epoch_transition
Inserted `EpochTransition` is not read anymore and inserting it does not change state. So removing it doesn't introduce breaking change unless reusing the key index.
1 parent 864769d commit 3bc234e

File tree

7 files changed

+5
-195
lines changed

7 files changed

+5
-195
lines changed

core/src/blockchain/blockchain.rs

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,13 @@ use rlp::RlpStream;
2424

2525
use super::block_info::BestBlockChanged;
2626
use super::body_db::{BodyDB, BodyProvider};
27-
use super::extras::{BlockDetails, EpochTransitions, TransactionAddress};
27+
use super::extras::{BlockDetails, TransactionAddress};
2828
use super::headerchain::{HeaderChain, HeaderProvider};
2929
use super::invoice_db::{InvoiceDB, InvoiceProvider};
3030
use super::route::{tree_route, ImportRoute};
3131
use crate::blockchain_info::BlockChainInfo;
32-
use crate::consensus::epoch::Transition as EpochTransition;
3332
use crate::consensus::CodeChainEngine;
34-
use crate::db::{self, Readable, Writable};
33+
use crate::db;
3534
use crate::encoded;
3635
use crate::invoice::Invoice;
3736
use crate::transaction::LocalizedTransaction;
@@ -53,8 +52,6 @@ pub struct BlockChain {
5352
body_db: BodyDB,
5453
invoice_db: InvoiceDB,
5554

56-
db: Arc<KeyValueDB>,
57-
5855
pending_best_block_hash: RwLock<Option<H256>>,
5956
pending_best_proposal_block_hash: RwLock<Option<H256>>,
6057
}
@@ -96,8 +93,6 @@ impl BlockChain {
9693
body_db: BodyDB::new(&genesis_block, db.clone()),
9794
invoice_db: InvoiceDB::new(db.clone()),
9895

99-
db,
100-
10196
pending_best_block_hash: RwLock::new(None),
10297
pending_best_proposal_block_hash: RwLock::new(None),
10398
}
@@ -341,26 +336,6 @@ impl BlockChain {
341336
pub fn best_proposal_header(&self) -> encoded::Header {
342337
self.headerchain.best_proposal_header()
343338
}
344-
345-
/// Insert an epoch transition. Provide an epoch number being transitioned to
346-
/// and epoch transition object.
347-
///
348-
/// The block the transition occurred at should have already been inserted into the chain.
349-
pub fn insert_epoch_transition(&self, batch: &mut DBTransaction, epoch_num: u64, transition: EpochTransition) {
350-
let mut transitions = match self.db.read(db::COL_EXTRA, &epoch_num) {
351-
Some(existing) => existing,
352-
None => EpochTransitions {
353-
number: epoch_num,
354-
candidates: Vec::with_capacity(1),
355-
},
356-
};
357-
358-
// ensure we don't write any duplicates.
359-
if transitions.candidates.iter().find(|c| c.block_hash == transition.block_hash).is_none() {
360-
transitions.candidates.push(transition);
361-
batch.write(db::COL_EXTRA, &epoch_num, &transitions);
362-
}
363-
}
364339
}
365340

366341
/// Interface for querying blocks by hash and by number.

core/src/blockchain/extras.rs

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,11 @@
1414
// You should have received a copy of the GNU Affero General Public License
1515
// along with this program. If not, see <https://www.gnu.org/licenses/>.
1616

17-
use std::io::Write;
18-
use std::ops::{self, Add, AddAssign, Deref, Sub, SubAssign};
17+
use std::ops::{Add, AddAssign, Deref, Sub, SubAssign};
1918

2019
use ctypes::BlockNumber;
21-
use kvdb::PREFIX_LEN as DB_PREFIX_LEN;
2220
use primitives::{H256, H264, U256};
2321

24-
use crate::consensus::epoch::Transition as EpochTransition;
2522
use crate::db::Key;
2623
use crate::types::TransactionId;
2724

@@ -36,8 +33,7 @@ enum ExtrasIndex {
3633
ParcelAddress = 2,
3734
/// Transaction address index
3835
TransactionAddress = 3,
39-
/// Epoch transition data index.
40-
EpochTransitions = 4,
36+
// (Reserved) = 4,
4137
// (Reserved) = 5,
4238
}
4339

@@ -97,38 +93,6 @@ impl Key<TransactionAddresses> for H256 {
9793
}
9894
}
9995

100-
/// length of epoch keys.
101-
const EPOCH_KEY_LEN: usize = DB_PREFIX_LEN + 16;
102-
103-
/// epoch key prefix.
104-
/// used to iterate over all epoch transitions in order from genesis.
105-
pub const EPOCH_KEY_PREFIX: &[u8; DB_PREFIX_LEN] =
106-
&[ExtrasIndex::EpochTransitions as u8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
107-
108-
pub struct EpochTransitionsKey([u8; EPOCH_KEY_LEN]);
109-
110-
impl ops::Deref for EpochTransitionsKey {
111-
type Target = [u8];
112-
113-
fn deref(&self) -> &[u8] {
114-
&self.0[..]
115-
}
116-
}
117-
118-
impl Key<EpochTransitions> for u64 {
119-
type Target = EpochTransitionsKey;
120-
121-
fn key(&self) -> Self::Target {
122-
let mut arr = [0u8; EPOCH_KEY_LEN];
123-
arr[..DB_PREFIX_LEN].copy_from_slice(&EPOCH_KEY_PREFIX[..]);
124-
125-
write!(&mut arr[DB_PREFIX_LEN..], "{:016x}", self)
126-
.expect("format arg is valid; no more than 16 chars will be written; qed");
127-
128-
EpochTransitionsKey(arr)
129-
}
130-
}
131-
13296
/// Familial details concerning a block
13397
#[derive(Debug, Clone, RlpEncodable, RlpDecodable)]
13498
pub struct BlockDetails {
@@ -161,13 +125,6 @@ pub struct TransactionAddresses {
161125
addresses: Vec<TransactionAddress>,
162126
}
163127

164-
/// Candidate transitions to an epoch with specific number.
165-
#[derive(Clone, RlpEncodable, RlpDecodable)]
166-
pub struct EpochTransitions {
167-
pub number: u64,
168-
pub candidates: Vec<EpochTransition>,
169-
}
170-
171128
impl TransactionAddresses {
172129
pub fn new(address: TransactionAddress) -> Self {
173130
Self {

core/src/client/importer.rs

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ use rlp::Encodable;
2727

2828
use super::{BlockChainTrait, Client, ClientConfig};
2929
use crate::block::{enact, IsBlock, LockedBlock};
30-
use crate::blockchain::{BlockChain, BodyProvider, HeaderProvider, ImportRoute};
31-
use crate::consensus::epoch::Transition as EpochTransition;
30+
use crate::blockchain::{BodyProvider, HeaderProvider, ImportRoute};
3231
use crate::consensus::CodeChainEngine;
3332
use crate::encoded;
3433
use crate::error::Error;
@@ -207,8 +206,6 @@ impl Importer {
207206
client.db().write_buffered(batch);
208207
chain.commit();
209208

210-
self.check_epoch_end(block.header(), &chain, client);
211-
212209
if hash == chain.best_block_hash() {
213210
let mut state_db = client.state_db().write();
214211
let state = block.state();
@@ -218,27 +215,6 @@ impl Importer {
218215
route
219216
}
220217

221-
// check for ending of epoch and write transition if it occurs.
222-
fn check_epoch_end(&self, header: &Header, chain: &BlockChain, client: &Client) {
223-
let is_epoch_end = self.engine.is_epoch_end(header, &(|hash| chain.block_header(&hash)));
224-
225-
if let Some(proof) = is_epoch_end {
226-
cdebug!(CLIENT, "Epoch transition at block {}", header.hash());
227-
228-
let mut batch = DBTransaction::new();
229-
chain.insert_epoch_transition(&mut batch, header.number(), EpochTransition {
230-
block_hash: header.hash(),
231-
block_number: header.number(),
232-
proof,
233-
});
234-
235-
// always write the batch directly since epoch transition proofs are
236-
// fetched from a DB iterator and DB iterators are only available on
237-
// flushed data.
238-
client.db().write(batch).expect("DB flush failed");
239-
}
240-
}
241-
242218
fn check_and_close_block(&self, block: &PreverifiedBlock, client: &Client) -> Result<LockedBlock, ()> {
243219
let engine = &*self.engine;
244220
let header = &block.header;
@@ -424,15 +400,10 @@ impl Importer {
424400
let chain = client.block_chain();
425401

426402
let mut batch = DBTransaction::new();
427-
// FIXME: Check if this line is still necessary.
428-
// self.check_epoch_end_signal(header, &chain, &mut batch);
429403
let route = chain.insert_header(&mut batch, &HeaderView::new(&header.rlp_bytes()), self.engine.borrow());
430404
client.db().write_buffered(batch);
431405
chain.commit();
432406

433-
// FIXME: Check if this line is still necessary.
434-
// self.check_epoch_end(&header, &chain, client);
435-
436407
route
437408
}
438409
}

core/src/consensus/epoch.rs

Lines changed: 0 additions & 52 deletions
This file was deleted.

core/src/consensus/mod.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
mod blake_pow;
1818
mod cuckoo;
19-
pub mod epoch;
2019
mod null_engine;
2120
mod signer;
2221
mod simple_poa;
@@ -200,17 +199,6 @@ pub trait ConsensusEngine: Sync + Send {
200199
Ok(())
201200
}
202201

203-
/// Whether a block is the end of an epoch.
204-
///
205-
/// This either means that an immediate transition occurs or a block signalling transition
206-
/// has reached finality. The `Headers` given are not guaranteed to return any blocks
207-
/// from any epoch other than the current.
208-
///
209-
/// Return optional transition proof.
210-
fn is_epoch_end(&self, _chain_head: &Header, _chain: &Headers<Header>) -> Option<Vec<u8>> {
211-
None
212-
}
213-
214202
/// Populate a header's fields based on its parent's header.
215203
/// Usually implements the chain scoring rule based on weight.
216204
fn populate_from_parent(&self, _header: &mut Header, _parent: &Header) {}
@@ -283,9 +271,6 @@ pub trait ConsensusEngine: Sync + Send {
283271
}
284272
}
285273

286-
/// Type alias for a function we can get headers by hash through.
287-
pub type Headers<'a, H> = Fn(H256) -> Option<H> + 'a;
288-
289274
/// Voting errors.
290275
#[derive(Debug)]
291276
pub enum EngineError {

core/src/consensus/simple_poa/mod.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,6 @@ impl ConsensusEngine for SimplePoA {
117117
verify_external(header, &*self.validators)
118118
}
119119

120-
fn is_epoch_end(&self, chain_head: &Header, _chain: &super::Headers<Header>) -> Option<Vec<u8>> {
121-
let first = chain_head.number() == 0;
122-
if first {
123-
Some(Vec::new())
124-
} else {
125-
None
126-
}
127-
}
128-
129120
fn on_close_block(&self, block: &mut ExecutedBlock) -> Result<(), Error> {
130121
let author = *block.header().author();
131122
let total_reward = self.block_reward(block.header().number())

core/src/consensus/tendermint/engine.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use ckey::Address;
2222
use cnetwork::NetworkService;
2323
use crossbeam_channel as crossbeam;
2424
use cstate::ActionHandler;
25-
use ctypes::BlockNumber;
2625
use primitives::H256;
2726

2827
use super::super::stake;
@@ -114,16 +113,6 @@ impl ConsensusEngine for Tendermint {
114113
receiver.recv().unwrap()
115114
}
116115

117-
fn is_epoch_end(&self, chain_head: &Header, _chain: &super::super::Headers<Header>) -> Option<Vec<u8>> {
118-
let first = chain_head.number() == 0;
119-
if first {
120-
let change = combine_proofs(chain_head.number(), &[], &[]);
121-
return Some(change)
122-
}
123-
124-
None
125-
}
126-
127116
fn populate_from_parent(&self, header: &mut Header, _parent: &Header) {
128117
let (result, receiver) = crossbeam::bounded(1);
129118
self.inner
@@ -249,9 +238,3 @@ impl ConsensusEngine for Tendermint {
249238
&self.action_handlers
250239
}
251240
}
252-
253-
fn combine_proofs(signal_number: BlockNumber, set_proof: &[u8], finality_proof: &[u8]) -> Vec<u8> {
254-
let mut stream = ::rlp::RlpStream::new_list(3);
255-
stream.append(&signal_number).append(&set_proof).append(&finality_proof);
256-
stream.out()
257-
}

0 commit comments

Comments
 (0)