Skip to content

Commit

Permalink
tested.works
Browse files Browse the repository at this point in the history
  • Loading branch information
brenzi committed Feb 26, 2025
1 parent 3e628c6 commit 4fbd6bb
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 44 deletions.
16 changes: 8 additions & 8 deletions app-libs/parentchain-specs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ impl MinimalChainSpec {
}

pub fn is_known_production_chain(genesis_hash: Hash) -> bool {
match genesis_hash.into() {
matches!(
genesis_hash.into(),
POLKADOT_RELAY_GENESIS_HASH_HEX
| ASSET_HUB_POLKADOT_GENESIS_HASH_HEX
| KUSAMA_RELAY_GENESIS_HASH_HEX
| ASSET_HUB_KUSAMA_GENESIS_HASH_HEX
| INTEGRITEE_KUSAMA_GENESIS_HASH_HEX
| INTEGRITEE_POLKADOT_GENESIS_HASH_HEX => true,
_ => false,
}
| ASSET_HUB_POLKADOT_GENESIS_HASH_HEX
| KUSAMA_RELAY_GENESIS_HASH_HEX
| ASSET_HUB_KUSAMA_GENESIS_HASH_HEX
| INTEGRITEE_KUSAMA_GENESIS_HASH_HEX
| INTEGRITEE_POLKADOT_GENESIS_HASH_HEX
)
}
}
4 changes: 2 additions & 2 deletions app-libs/stf/src/stf_sgx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,10 @@ fn retire_account<NodeMetadataRepository>(
call: TrustedCall::force_unshield_all(enclave_signer_account(), account.clone(), None),
nonce: *enclave_nonce, //nonce will no longer increase as we bypass signature check
delegate: None,
signature: fake_signature.clone(),
signature: fake_signature,
};
// Replace with `inspect_err` once it's stable.
tcs.execute(calls, shard, node_metadata_repo.clone())
tcs.execute(calls, shard, node_metadata_repo)
.map_err(|e| {
error!(
"Failed to force-unshield native for {:?}: {:?}",
Expand Down
20 changes: 9 additions & 11 deletions app-libs/stf/src/trusted_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1225,26 +1225,24 @@ fn may_execute(tcs: &TrustedCallSigned) -> bool {
TrustedCall::balance_shield(..) => true,
TrustedCall::balance_shield_through_enclave_bridge_pallet(..) => true,
TrustedCall::assets_shield(..) => true,
// permissioned calls are ok
TrustedCall::timestamp_set(..) => true,
TrustedCall::force_unshield_all(..) => true,
// this would cause nonce clashes during retirement. safer to filter
TrustedCall::timestamp_set(..) => false,
// everything else is disabled during maintenance mode
_ => false,
}
}
}
if MinimalChainSpec::is_known_production_chain(
shielding_target_genesis_hash().unwrap_or_default(),
) && matches!(
tcs.call,
TrustedCall::waste_time(..)
| TrustedCall::note_bloat(..)
| TrustedCall::spam_extrinsics(..)
) {
if matches!(
tcs.call,
TrustedCall::waste_time(..)
| TrustedCall::note_bloat(..)
| TrustedCall::spam_extrinsics(..)
) {
warn!("preventing execution of call {:?} on production chain", tcs.call);
return false
}
warn!("preventing execution of call {:?} on production chain", tcs.call);
return false
}
true
}
Expand Down
50 changes: 27 additions & 23 deletions core-primitives/stf-executor/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,29 +289,6 @@ where
},
);

if maintenance_mode {
info!("Maintenance mode is active.");
let mut extrinsic_call_backs: Vec<ParentchainCall> = Vec::new();
Stf::maintenance_mode_tasks(
&mut state,
&shard,
*header.number(),
&mut extrinsic_call_backs,
self.node_metadata_repo.clone(),
)
.map_err(|e| error!("maintenance_mode tasks failed: {:?}", e))
.ok();
info!(
"maintenance tasks have triggered {} parentchain calls",
extrinsic_call_backs.len()
);
// we're hacking our unshielding calls into the queue
executed_and_failed_calls.push(ExecutedOperation::success(
H256::default(),
TrustedOperationOrHash::Hash(H256::default()),
extrinsic_call_backs,
));
}
// Iterate through all calls until time is over.
for trusted_call_signed in trusted_calls.into_iter() {
// Break if allowed time window is over.
Expand All @@ -336,6 +313,33 @@ where
};
}

// Execute maintenance tasks if maintenance mode is active
// This has to execute after the top-pool calls because enclave signer nonce clashes can occur otherwise (e.g. shielding calls).
// the risk of overdue block production is minimal as all user calls are filtered during maintenance mode anyway
if maintenance_mode {
info!("Maintenance mode is active.");
let mut extrinsic_call_backs: Vec<ParentchainCall> = Vec::new();
Stf::maintenance_mode_tasks(
&mut state,
&shard,
*header.number(),
&mut extrinsic_call_backs,
self.node_metadata_repo.clone(),
)
.map_err(|e| error!("maintenance_mode tasks failed: {:?}", e))
.ok();
info!(
"maintenance tasks have triggered {} parentchain calls",
extrinsic_call_backs.len()
);
// we're hacking our unshielding calls into the queue
executed_and_failed_calls.push(ExecutedOperation::success(
H256::default(),
TrustedOperationOrHash::Hash(H256::default()),
extrinsic_call_backs,
));
}

Stf::on_finalize(&mut state).unwrap_or_else(|e| {
error!("on_finalize failed: {:?}", e);
});
Expand Down

0 comments on commit 4fbd6bb

Please sign in to comment.