Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/apollo_consensus_manager/src/consensus_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ impl ConsensusManager {
}

pub async fn run(&self) {
if self.config.revert_config.should_revert {
self.revert_batcher_blocks(self.config.revert_config.revert_up_to_and_including).await;
if let Some(revert_up_to_and_including) = self.config.revert_config.0 {
self.revert_batcher_blocks(revert_up_to_and_including).await;
}

let mut network_manager = self.create_network_manager();
Expand Down
10 changes: 2 additions & 8 deletions crates/apollo_consensus_manager/src/consensus_manager_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ async fn revert_batcher_blocks() {
}

let manager_config = ConsensusManagerConfig {
revert_config: RevertConfig {
revert_up_to_and_including: REVERT_UP_TO_AND_INCLUDING_HEIGHT,
should_revert: true,
},
revert_config: RevertConfig(Some(REVERT_UP_TO_AND_INCLUDING_HEIGHT)),
..Default::default()
};

Expand Down Expand Up @@ -100,10 +97,7 @@ async fn revert_voted_height_when_batcher_already_at_target() {
.returning(|_| Ok(()));

let manager_config = ConsensusManagerConfig {
revert_config: RevertConfig {
revert_up_to_and_including: TARGET_HEIGHT,
should_revert: true,
},
revert_config: RevertConfig(Some(TARGET_HEIGHT)),
..Default::default()
};

Expand Down
2 changes: 1 addition & 1 deletion crates/apollo_deployments/jsonnet/lib/defaults.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
MAX_CPU_TIME: 600,
VALIDATE_RESOURCE_BOUNDS: true,
BEHAVIOR_MODE: 'starknet',
REVERT_CONFIG: { revert_up_to_and_including: 18446744073709551615, should_revert: false },
REVERT_CONFIG: null,
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,28 +149,9 @@ fn modify_revert_config(
config: &mut SequencerNodeConfig,
revert_up_to_and_including: Option<BlockNumber>,
) {
let should_revert = revert_up_to_and_including.is_some();
config.state_sync_config.as_mut().unwrap().static_config.revert_config.should_revert =
should_revert;
config.consensus_manager_config.as_mut().unwrap().revert_config.should_revert = should_revert;

// If should revert is false, the revert_up_to_and_including value is irrelevant.
if should_revert {
let revert_up_to_and_including = revert_up_to_and_including.unwrap();
config
.state_sync_config
.as_mut()
.unwrap()
.static_config
.revert_config
.revert_up_to_and_including = revert_up_to_and_including;
config
.consensus_manager_config
.as_mut()
.unwrap()
.revert_config
.revert_up_to_and_including = revert_up_to_and_including;
}
config.state_sync_config.as_mut().unwrap().static_config.revert_config.0 =
revert_up_to_and_including;
config.consensus_manager_config.as_mut().unwrap().revert_config.0 = revert_up_to_and_including;
}

fn modify_height_configs_idle_nodes(
Expand Down
26 changes: 12 additions & 14 deletions crates/apollo_reverts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,20 @@ use futures::never::Never;
use serde::{Deserialize, Serialize};
use starknet_api::block::BlockNumber;
use tracing::info;
use validator::Validate;
use validator::{Validate, ValidationErrors};

#[derive(Clone, Debug, Serialize, Deserialize, Validate, PartialEq)]
pub struct RevertConfig {
pub revert_up_to_and_including: BlockNumber,
pub should_revert: bool,
}
/// Revert target: `Some(height)` reverts blocks up to and including that height; `None` (the
/// default) never reverts.
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq)]
#[serde(transparent)]
pub struct RevertConfig(pub Option<BlockNumber>);

impl Default for RevertConfig {
fn default() -> Self {
Self {
// Use u64::MAX as a placeholder to prevent setting this value to
// a low block number by mistake, which will cause significant revert operations.
revert_up_to_and_including: BlockNumber(u64::MAX),
should_revert: false,
}
// The newtype wraps a plain `Option<BlockNumber>` with no field-level constraints;
// `#[derive(Validate)]` doesn't support tuple structs, so implement the (trivial) check by hand to
// satisfy the `#[validate(nested)]` bound on the owning configs.
impl Validate for RevertConfig {
fn validate(&self) -> Result<(), ValidationErrors> {
Ok(())
}
}

Expand Down
3 changes: 1 addition & 2 deletions crates/apollo_state_sync/src/runner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,8 @@ impl StateSyncRunner {
Some(class_manager_client.clone()),
);

if revert_config.should_revert {
if let Some(revert_up_to_and_including) = revert_config.0 {
debug!("State sync runner should revert; creating revert futures.");
let revert_up_to_and_including = revert_config.revert_up_to_and_including;
// We assume that sync always writes the headers before any other block data.
let current_header_marker = storage_reader
.begin_ro_txn()
Expand Down
24 changes: 19 additions & 5 deletions echonet/sequencer_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ def __init__(
self._apps_v1 = apps_v1
self._spec = spec
self._timing = timing
# The revert target height, remembered so revert can be re-enabled after being disabled.
# `revert_config` in the node config is a single optional value (the target, or null to
# disable), so the "disabled" state can't itself carry the target to restore.
self._revert_target: Optional[int] = None

@classmethod
def from_incluster(
Expand Down Expand Up @@ -130,23 +134,31 @@ def patch_node_config(self, mutator: ConfigMutator):
return updated

def configure_revert(self, should_revert: bool):
if should_revert:
assert self._revert_target is not None, (
"configure_revert(should_revert=True) requires a target set by a prior "
"configure_stop_sync"
)
target = self._revert_target if should_revert else None

def _mutate(config: JsonObject) -> None:
config["revert_config.should_revert"] = should_revert
config["revert_config"] = target

return self.patch_node_config(_mutate)

def configure_start_sync(self):
def _mutate(config: JsonObject) -> None:
config["revert_config.should_revert"] = False
config["revert_config"] = None
config["starknet_url"] = CONFIG.feeder.base_url
config["validator_id"] = "0x1"

return self.patch_node_config(_mutate)

def configure_stop_sync(self, block_number: int):
self._revert_target = block_number

def _mutate(config: JsonObject) -> None:
config["revert_config.should_revert"] = True
config["revert_config.revert_up_to_and_including"] = block_number
config["revert_config"] = block_number
config["starknet_url"] = "http://echonet:80"
config["validator_id"] = "0x64"

Expand Down Expand Up @@ -318,7 +330,9 @@ def _read_previous_revert_marker(self) -> int:
self._spec.configmap_name, self._namespace
)
config: JsonObject = json.loads(configmap.data["config"])
return int(config["revert_config.revert_up_to_and_including"])
revert_target = config["revert_config"]
assert revert_target is not None, "revert is not enabled; no target to read"
return int(revert_target)

def initial_revert_then_restore(self, block_number: int) -> None:
"""
Expand Down
5 changes: 3 additions & 2 deletions scripts/prod/set_node_revert_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ def set_revert_mode(
revert_up_to_block: int,
max_parallelism: int,
):
# `revert_config` is a single optional value: the target block height when reverting, or null
# to disable reverting (there is no separate `should_revert` flag).
config_overrides = {
"revert_config.should_revert": should_revert,
"revert_config.revert_up_to_and_including": revert_up_to_block,
"revert_config": revert_up_to_block if should_revert else None,
}
update_config_and_restart_nodes(
ConstConfigValuesUpdater(config_overrides),
Expand Down
Loading