Skip to content

Commit

Permalink
chain: allow chain_tail to be set w/o tail being set on archival nodes (
Browse files Browse the repository at this point in the history
#6563)

Since commit 6be2e0e: ‘gc partial chunks on archival nodes (#6439)’,
archival nodes set chunk_tail without setting tail.  However, store
validation expects both of those to be set or unset.  Change the code
to allow unset tail on archival nodes.

Issue: #6242
  • Loading branch information
mina86 authored Apr 11, 2022
1 parent dede047 commit 6a00c11
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 5 deletions.
1 change: 1 addition & 0 deletions chain/chain/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3664,6 +3664,7 @@ mod tests {
genesis.clone(),
chain.runtime_adapter.clone(),
chain.store().store().clone(),
false,
);
store_validator.validate();
println!("errors = {:?}", store_validator.errors);
Expand Down
6 changes: 5 additions & 1 deletion chain/chain/src/store_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ pub struct StoreValidator {
inner: StoreValidatorCache,
timeout: Option<u64>,
start_time: Instant,
pub is_archival: bool,

pub errors: Vec<ErrorMessage>,
tests: u64,
Expand All @@ -89,6 +90,7 @@ impl StoreValidator {
config: GenesisConfig,
runtime_adapter: Arc<dyn RuntimeAdapter>,
store: Store,
is_archival: bool,
) -> Self {
StoreValidator {
me,
Expand All @@ -98,6 +100,7 @@ impl StoreValidator {
inner: StoreValidatorCache::new(),
timeout: None,
start_time: Clock::instant(),
is_archival,
errors: vec![],
tests: 0,
}
Expand Down Expand Up @@ -337,6 +340,7 @@ impl StoreValidator {
}
Ok(())
}

pub fn validate(&mut self) {
self.start_time = Clock::instant();

Expand Down Expand Up @@ -425,7 +429,7 @@ mod tests {
true,
)
.unwrap();
(chain, StoreValidator::new(None, genesis, runtime_adapter, store))
(chain, StoreValidator::new(None, genesis, runtime_adapter, store, false))
}

#[test]
Expand Down
8 changes: 5 additions & 3 deletions chain/chain/src/store_validator/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,11 @@ pub(crate) fn head_tail_validity(sv: &mut StoreValidator) -> Result<(), StoreVal
sv.store.get_ser::<BlockHeight>(ColBlockMisc, FORK_TAIL_KEY),
"Can't get Chunk Tail from storage"
);
if tail_db.is_none() && chunk_tail_db.is_some() || tail_db.is_some() && chunk_tail_db.is_none()
{
err!("Tail is {:?} and Chunk Tail is {:?}", tail_db, chunk_tail_db);
if tail_db.is_none() != chunk_tail_db.is_none() {
// Archival nodes can have chunk_tail set without tail being set.
if !sv.is_archival || chunk_tail_db.is_none() {
err!("Tail is {:?} and Chunk Tail is {:?}", tail_db, chunk_tail_db);
}
}
if tail_db.is_some() && fork_tail_db.is_none() {
err!("Tail is {:?} but fork tail is None", tail_db);
Expand Down
1 change: 1 addition & 0 deletions chain/client/src/client_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ impl ClientActor {
genesis,
self.client.runtime_adapter.clone(),
self.client.chain.store().store().clone(),
self.adv.read().unwrap().is_archival,
);
store_validator.set_timeout(timeout);
store_validator.validate();
Expand Down
8 changes: 8 additions & 0 deletions chain/client/src/view_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ pub struct AdversarialControls {
pub adv_disable_header_sync: bool,
pub adv_disable_doomslug: bool,
pub adv_sync_height: Option<u64>,
pub is_archival: bool,
}

#[cfg(feature = "test_features")]
impl AdversarialControls {
pub fn new(is_archival: bool) -> Self {
Self { is_archival, ..Self::default() }
}
}

/// View client provides currently committed (to the storage) view of the current chain and state.
Expand Down
3 changes: 2 additions & 1 deletion nearcore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,8 @@ pub fn start_with_config_and_synchronization(
let node_id = PeerId::new(config.network_config.public_key.clone().into());
let network_adapter = Arc::new(NetworkRecipient::default());
#[cfg(feature = "test_features")]
let adv = Arc::new(std::sync::RwLock::new(AdversarialControls::default()));
let adv =
Arc::new(std::sync::RwLock::new(AdversarialControls::new(config.client_config.archive)));

let view_client = start_view_client(
config.validator_signer.as_ref().map(|signer| signer.validator_id().clone()),
Expand Down
1 change: 1 addition & 0 deletions test-utils/store-validator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ fn main() {
near_config.genesis.config,
runtime_adapter.clone(),
store,
false,
);
store_validator.validate();

Expand Down

0 comments on commit 6a00c11

Please sign in to comment.