Skip to content

Commit

Permalink
[Epoch Sync] Remove previous new_epoch_sync code. (#11929)
Browse files Browse the repository at this point in the history
The new design has little overlap with the old, so this PR removes the
old code, in order to avoid confusion with the new one. This also gets
rid of the insidious new_epoch_sync feature.

This is all fine because most of this code was guarded by the
new_epoch_sync feature. So almost none of these are compiled. What did
get compiled were:
- Client had an EpochSync struct, but without the feature, it didn't do
anything.
- The config had an epoch_sync_enabled flag, but without the feature,
that flag isn't used.
- Some integration tests supplied epoch_sync_enabled = true. I either
removed the test or made it false.
  • Loading branch information
robin-near authored Aug 14, 2024
1 parent 5c1c632 commit 2394e0c
Show file tree
Hide file tree
Showing 56 changed files with 47 additions and 1,797 deletions.
16 changes: 0 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ nearcore = { path = "nearcore" }
near-crypto = { path = "core/crypto", default-features = false }
near-dyn-configs = { path = "core/dyn-configs" }
near-epoch-manager = { path = "chain/epoch-manager" }
near-epoch-sync-tool = { path = "tools/epoch-sync" }
near-flat-storage = { path = "tools/flat-storage" }
near-fork-network = { path = "tools/fork-network" }
near-fmt = { path = "utils/fmt" }
Expand Down
2 changes: 0 additions & 2 deletions chain/chain-primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,3 @@ near-time.workspace = true
near-primitives.workspace = true
near-crypto.workspace = true

[features]
new_epoch_sync = []
13 changes: 0 additions & 13 deletions chain/chain-primitives/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,16 +452,3 @@ pub enum BlockKnownError {
#[error("already known in invalid blocks")]
KnownAsInvalid,
}

#[cfg(feature = "new_epoch_sync")]
pub mod epoch_sync {
#[derive(thiserror::Error, std::fmt::Debug)]
pub enum EpochSyncInfoError {
#[error(transparent)]
EpochSyncInfoErr(#[from] near_primitives::errors::epoch_sync::EpochSyncInfoError),
#[error(transparent)]
IOErr(#[from] std::io::Error),
#[error(transparent)]
ChainErr(#[from] crate::Error),
}
}
6 changes: 0 additions & 6 deletions chain/chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,6 @@ test_features = [
]
shadow_chunk_validation = []
no_cache = ["near-store/no_cache"]
new_epoch_sync = [
"near-store/new_epoch_sync",
"near-primitives/new_epoch_sync",
"near-epoch-manager/new_epoch_sync",
"near-chain-primitives/new_epoch_sync",
]

protocol_feature_reject_blocks_with_outdated_protocol_version = [
"near-primitives/protocol_feature_reject_blocks_with_outdated_protocol_version",
Expand Down
110 changes: 0 additions & 110 deletions chain/chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ use near_async::time::{Clock, Duration, Instant};
use near_chain_configs::{
MutableConfigValue, MutableValidatorSigner, ReshardingConfig, ReshardingHandle,
};
#[cfg(feature = "new_epoch_sync")]
use near_chain_primitives::error::epoch_sync::EpochSyncInfoError;
use near_chain_primitives::error::{BlockKnownError, Error, LogTransientStorageError};
use near_epoch_manager::shard_tracker::ShardTracker;
use near_epoch_manager::types::BlockHeaderInfo;
Expand All @@ -58,10 +56,6 @@ use near_primitives::challenge::{
};
use near_primitives::checked_feature;
use near_primitives::congestion_info::CongestionInfo;
#[cfg(feature = "new_epoch_sync")]
use near_primitives::epoch_manager::epoch_sync::EpochSyncInfo;
#[cfg(feature = "new_epoch_sync")]
use near_primitives::errors::epoch_sync::EpochSyncHashType;
use near_primitives::errors::EpochError;
use near_primitives::hash::{hash, CryptoHash};
use near_primitives::merkle::{
Expand Down Expand Up @@ -89,8 +83,6 @@ use near_primitives::types::{
NumBlocks, ShardId, StateRoot,
};
use near_primitives::unwrap_or_return;
#[cfg(feature = "new_epoch_sync")]
use near_primitives::utils::index_to_bytes;
use near_primitives::utils::MaybeValidated;
use near_primitives::version::{ProtocolFeature, ProtocolVersion, PROTOCOL_VERSION};
use near_primitives::views::{
Expand Down Expand Up @@ -1577,14 +1569,6 @@ impl Chain {
.add_validator_proposals(BlockHeaderInfo::new(header, last_finalized_height))?;
chain_store_update.merge(epoch_manager_update);
chain_store_update.commit()?;

#[cfg(feature = "new_epoch_sync")]
{
// At this point BlockInfo for this header should be in DB and in `epoch_manager`s cache because of `add_validator_proposals` call.
let mut chain_update = self.chain_update();
chain_update.save_epoch_sync_info_if_finalised(header)?;
chain_update.commit()?;
}
}

let mut chain_update = self.chain_update();
Expand Down Expand Up @@ -4615,100 +4599,6 @@ impl Chain {
}
}

/// Epoch sync specific functions.
#[cfg(feature = "new_epoch_sync")]
impl Chain {
/// TODO(posvyatokum): validate `epoch_sync_info` before `store_update` commit.
pub fn validate_and_record_epoch_sync_info(
&mut self,
epoch_sync_info: &EpochSyncInfo,
) -> Result<(), EpochSyncInfoError> {
let store = self.chain_store().store().clone();
let epoch_manager = self.epoch_manager.clone();
let mut chain_store_update = self.chain_store.store_update();
let mut store_update = store.store_update();

let epoch_id = epoch_sync_info.get_epoch_id()?;
// save EpochSyncInfo

store_update.set_ser(DBCol::EpochSyncInfo, epoch_id.as_ref(), epoch_sync_info)?;

// save EpochInfo's

store_update.set_ser(DBCol::EpochInfo, epoch_id.as_ref(), &epoch_sync_info.epoch_info)?;
store_update.set_ser(
DBCol::EpochInfo,
epoch_sync_info.get_next_epoch_id()?.as_ref(),
&epoch_sync_info.next_epoch_info,
)?;
store_update.set_ser(
DBCol::EpochInfo,
epoch_sync_info.get_next_next_epoch_id()?.as_ref(),
&epoch_sync_info.next_next_epoch_info,
)?;

// construct and save all new BlockMerkleTree's

let mut cur_block_merkle_tree = (*chain_store_update
.get_block_merkle_tree(epoch_sync_info.get_epoch_first_header()?.prev_hash())?)
.clone();
let mut prev_hash = epoch_sync_info.get_epoch_first_header()?.prev_hash();
for hash in &epoch_sync_info.all_block_hashes {
cur_block_merkle_tree.insert(*prev_hash);
chain_store_update.save_block_merkle_tree(*hash, cur_block_merkle_tree.clone());
prev_hash = hash;
}

// save all block data in headers_to_save

for hash in &epoch_sync_info.headers_to_save {
let header = epoch_sync_info.get_header(*hash, EpochSyncHashType::BlockToSave)?;
// check that block is not known already
if store.exists(DBCol::BlockHeader, hash.as_ref())? {
continue;
}

store_update.insert_ser(DBCol::BlockHeader, header.hash().as_ref(), header)?;
store_update.set_ser(
DBCol::NextBlockHashes,
header.prev_hash().as_ref(),
header.hash(),
)?;
store_update.set_ser(
DBCol::BlockHeight,
&index_to_bytes(header.height()),
header.hash(),
)?;
store_update.set_ser(
DBCol::BlockOrdinal,
&index_to_bytes(header.block_ordinal()),
&header.hash(),
)?;

store_update.insert_ser(
DBCol::BlockInfo,
hash.as_ref(),
&epoch_sync_info.get_block_info(hash)?,
)?;
}

// save header head, final head, update epoch_manager aggregator
chain_store_update
.force_save_header_head(&Tip::from_header(epoch_sync_info.get_epoch_last_header()?))?;
chain_store_update.save_final_head(&Tip::from_header(
epoch_sync_info.get_epoch_last_finalised_header()?,
))?;
epoch_manager
.force_update_aggregator(epoch_id, epoch_sync_info.get_epoch_last_finalised_hash()?);

// TODO(posvyatokum): add EpochSyncInfo validation.

chain_store_update.merge(store_update);
chain_store_update.commit()?;
Ok(())
}
}

pub fn do_apply_chunks(
block_hash: CryptoHash,
block_height: BlockHeight,
Expand Down
Loading

0 comments on commit 2394e0c

Please sign in to comment.