Skip to content

Commit

Permalink
fix(rpc): fix for updating code hashes in rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
pashinov authored and Rexagon committed Dec 26, 2024
1 parent 063f10f commit 62730ec
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
15 changes: 14 additions & 1 deletion rpc/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ pub enum RpcStorage {
///
/// `None` to disable garbage collection.
gc: Option<TransactionsGcConfig>,

/// Reset all accounts.
///
/// Default: `false`.
force_reindex: bool,
},
/// Only store the state, no transactions and code hashes.
StateOnly,
Expand All @@ -46,7 +51,14 @@ impl RpcStorage {
}
pub fn gc_is_enabled(&self) -> bool {
match self {
Self::Full { gc } => gc.is_some(),
Self::Full { gc, .. } => gc.is_some(),
Self::StateOnly => false,
}
}

pub fn is_force_reindex(&self) -> bool {
match self {
Self::Full { force_reindex, .. } => *force_reindex,
Self::StateOnly => false,
}
}
Expand All @@ -60,6 +72,7 @@ impl Default for RpcConfig {
shard_split_depth: 4,
storage: RpcStorage::Full {
gc: Some(Default::default()),
force_reindex: false,
},
}
}
Expand Down
4 changes: 2 additions & 2 deletions rpc/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl RpcStateBuilder {

let gc_notify = Arc::new(Notify::new());
let gc_handle = match &self.config.storage {
RpcStorage::Full { gc } => gc.as_ref().map(|config| {
RpcStorage::Full { gc, .. } => gc.as_ref().map(|config| {
tokio::spawn(transactions_gc(
config.clone(),
storage.clone(),
Expand Down Expand Up @@ -316,7 +316,7 @@ impl Inner {
let node_instance_id = self.storage.node_state().load_instance_id();
let rpc_instance_id = rpc_storage.load_instance_id();

if node_instance_id != rpc_instance_id {
if node_instance_id != rpc_instance_id || self.config.storage.is_force_reindex() {
let make_cached_accounts = |state: &ShardStateStuff| -> Result<CachedAccounts> {
let state_info = state.as_ref();
Ok(CachedAccounts {
Expand Down
4 changes: 0 additions & 4 deletions storage/src/store/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1000,10 +1000,6 @@ fn extract_code_hash(account: &ShardAccount) -> Result<ExtractedCodeHash> {
if let Some(account) = account.load_account()? {
if let AccountState::Active(state_init) = &account.state {
if let Some(code) = &state_init.code {
if code.descriptor().is_pruned_branch() {
return Ok(ExtractedCodeHash::Skip);
}

return Ok(ExtractedCodeHash::Exact(Some(*code.repr_hash())));
}
}
Expand Down

0 comments on commit 62730ec

Please sign in to comment.