Skip to content

Commit

Permalink
fix snapshot process
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauthamastro committed May 22, 2024
1 parent 7f61c7d commit aaddc02
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
16 changes: 16 additions & 0 deletions pallets/ocex/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,22 @@ pub mod pallet {
Self::start_new_epoch(current_blk);
Ok(())
}


/// Governance endpoint for submit Snapshot Summary
#[pallet::call_index(24)]
#[pallet::weight(< T as Config >::WeightInfo::submit_snapshot())]
pub fn force_submit_snapshot(
origin: OriginFor<T>,
summary: SnapshotSummary<T::AccountId>,
) -> DispatchResult {
ensure_root(origin)?;
let id = summary.snapshot_id;
<SnapshotNonce<T>>::put(id);
<Snapshots<T>>::insert(id, summary);
Self::deposit_event(crate::pallet::Event::<T>::SnapshotProcessed(id));
Ok(())
}
}

/// Events are a simple means of reporting specific conditions and
Expand Down
23 changes: 21 additions & 2 deletions pallets/ocex/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,31 @@ impl<T: Config> Pallet<T> {
let next_nonce = <SnapshotNonce<T>>::get().saturating_add(1);
let mut root = crate::storage::load_trie_root();
log::info!(target:"ocex","block: {:?}, state_root {:?}", block_num, root);

let mut storage = crate::storage::State;
let root_clone = root.clone();
let mut state = OffchainState::load(&mut storage, &mut root);
// Load the state to memory
let mut state_info = match Self::load_state_info(&mut state) {
Ok(info) => info,
Ok(info) => {
// Check if last processed snapshot id root from on-chain is same as our offchain root
if let Some(summary) = <Snapshots<T>>::get(info.snapshot_id){
if summary.state_hash != root_clone {
log::error!(target:"ocex","Last processed snapshot root is not same as on-chain root");
store_trie_root(H256::zero());
return Err("Last processed snapshot root is not same as on-chain root");
}
info
}else {
if info.snapshot_id != 0 {
log::error!(target:"ocex","Unable to load last processed snapshot summary from on-chain: {:?}",info.snapshot_id);
store_trie_root(H256::zero());
return Err("Unable to load last processed snapshot summary from on-chain");
}else {
info
}
}
},
Err(err) => {
log::error!(target:"ocex","Err loading state info from storage: {:?}",err);
store_trie_root(H256::zero());
Expand Down Expand Up @@ -184,7 +204,6 @@ impl<T: Config> Pallet<T> {
sp_runtime::print(nonce);
match Self::process_batch(&mut state, &batch, &mut state_info) {
Ok(_) => {
Self::clear_lmp_storages(&mut state)?;
state_info.stid = batch.stid;
state_info.snapshot_id = batch.snapshot_id;
Self::store_state_info(state_info, &mut state);
Expand Down
2 changes: 1 addition & 1 deletion runtimes/mainnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
// and set impl_version to 0. If only runtime
// implementation changes and behavior does not, then leave spec_version as
// is and increment impl_version.
spec_version: 355,
spec_version: 358,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 2,
Expand Down

0 comments on commit aaddc02

Please sign in to comment.