From fae98f940280a6f5926ec86d40653a64912b55da Mon Sep 17 00:00:00 2001 From: Lu Zhang <8418040+longbowlu@users.noreply.github.com> Date: Tue, 7 Jun 2022 09:52:34 -0700 Subject: [PATCH] add enable_event_processing option (#2462) --- crates/sui-config/src/builder.rs | 1 + crates/sui-config/src/node.rs | 3 +++ crates/sui-config/src/swarm.rs | 3 +-- crates/sui-core/src/authority.rs | 12 +++++++++--- .../gossip/configurable_batch_action_client.rs | 1 + crates/sui-core/src/authority_client.rs | 1 + .../src/checkpoints/tests/checkpoint_tests.rs | 4 ++++ crates/sui-core/src/unit_tests/authority_tests.rs | 1 + crates/sui-core/src/unit_tests/batch_tests.rs | 3 +++ crates/sui-node/src/lib.rs | 1 + crates/sui/src/benchmark/validator_preparer.rs | 1 + 11 files changed, 26 insertions(+), 5 deletions(-) diff --git a/crates/sui-config/src/builder.rs b/crates/sui-config/src/builder.rs index 3867c03764b5a..21bfde2c5cf24 100644 --- a/crates/sui-config/src/builder.rs +++ b/crates/sui-config/src/builder.rs @@ -190,6 +190,7 @@ impl ConfigBuilder { metrics_address: utils::available_local_socket_address(), json_rpc_address: utils::available_local_socket_address(), consensus_config: Some(consensus_config), + enable_event_processing: false, genesis: crate::node::Genesis::new(genesis.clone()), } }) diff --git a/crates/sui-config/src/node.rs b/crates/sui-config/src/node.rs index 38122d0e6db49..ceff5d499494a 100644 --- a/crates/sui-config/src/node.rs +++ b/crates/sui-config/src/node.rs @@ -33,6 +33,9 @@ pub struct NodeConfig { #[serde(skip_serializing_if = "Option::is_none")] pub consensus_config: Option, + #[serde(default)] + pub enable_event_processing: bool, + pub genesis: Genesis, } diff --git a/crates/sui-config/src/swarm.rs b/crates/sui-config/src/swarm.rs index 96c302163fcfc..41a4f06937fcb 100644 --- a/crates/sui-config/src/swarm.rs +++ b/crates/sui-config/src/swarm.rs @@ -68,9 +68,8 @@ impl NetworkConfig { network_address: utils::new_network_address(), metrics_address: utils::available_local_socket_address(), json_rpc_address: utils::available_local_socket_address(), - consensus_config: None, - + enable_event_processing: true, genesis: validator_config.genesis.clone(), } } diff --git a/crates/sui-core/src/authority.rs b/crates/sui-core/src/authority.rs index bb2863c11561d..4034e065c8b15 100644 --- a/crates/sui-core/src/authority.rs +++ b/crates/sui-core/src/authority.rs @@ -781,6 +781,7 @@ impl AuthorityState { indexes: Option>, checkpoints: Option>>, genesis: &Genesis, + enable_event_processing: bool, ) -> Self { let (tx, _rx) = tokio::sync::broadcast::channel(BROADCAST_CAPACITY); let native_functions = @@ -825,6 +826,11 @@ impl AuthorityState { .get_last_epoch_info() .expect("Fail to load the current epoch info"); + let event_handler = if enable_event_processing { + Some(Arc::new(EventHandler::new(store.clone()))) + } else { + None + }; let mut state = AuthorityState { name, secret, @@ -834,10 +840,10 @@ impl AuthorityState { move_vm, database: store.clone(), indexes, - module_cache: SyncModuleCache::new(AuthorityStoreWrapper(store.clone())), - // `event_handler` uses a separate in-mem cache from `module_cache` + // `module_cache` uses a separate in-mem cache from `event_handler` // this is because they largely deal with different types of MoveStructs - event_handler: Some(Arc::new(EventHandler::new(store.clone()))), + module_cache: SyncModuleCache::new(AuthorityStoreWrapper(store.clone())), + event_handler, checkpoints, batch_channels: tx, batch_notifier: Arc::new( diff --git a/crates/sui-core/src/authority_active/gossip/configurable_batch_action_client.rs b/crates/sui-core/src/authority_active/gossip/configurable_batch_action_client.rs index 3cdaaa3f6d30e..1f8ce38658aeb 100644 --- a/crates/sui-core/src/authority_active/gossip/configurable_batch_action_client.rs +++ b/crates/sui-core/src/authority_active/gossip/configurable_batch_action_client.rs @@ -76,6 +76,7 @@ impl ConfigurableBatchActionClient { None, None, &sui_config::genesis::Genesis::get_default_genesis(), + false, ) .await; diff --git a/crates/sui-core/src/authority_client.rs b/crates/sui-core/src/authority_client.rs index d58120cfd222a..bb87c2c30b996 100644 --- a/crates/sui-core/src/authority_client.rs +++ b/crates/sui-core/src/authority_client.rs @@ -352,6 +352,7 @@ impl LocalAuthorityClient { None, Some(Arc::new(Mutex::new(checkpoints))), genesis, + false, ) .await; Self { diff --git a/crates/sui-core/src/checkpoints/tests/checkpoint_tests.rs b/crates/sui-core/src/checkpoints/tests/checkpoint_tests.rs index ddf54427c6be4..e116cd0c4d348 100644 --- a/crates/sui-core/src/checkpoints/tests/checkpoint_tests.rs +++ b/crates/sui-core/src/checkpoints/tests/checkpoint_tests.rs @@ -732,6 +732,7 @@ async fn test_batch_to_checkpointing() { None, Some(checkpoints.clone()), &sui_config::genesis::Genesis::get_default_genesis(), + false, ) .await; let authority_state = Arc::new(state); @@ -820,6 +821,7 @@ async fn test_batch_to_checkpointing_init_crash() { None, None, &sui_config::genesis::Genesis::get_default_genesis(), + false, ) .await; let authority_state = Arc::new(state); @@ -900,6 +902,7 @@ async fn test_batch_to_checkpointing_init_crash() { None, Some(checkpoints.clone()), &sui_config::genesis::Genesis::get_default_genesis(), + false, ) .await; let authority_state = Arc::new(state); @@ -1388,6 +1391,7 @@ pub async fn checkpoint_tests_setup(num_objects: usize, batch_interval: Duration None, Some(checkpoint.clone()), &genesis, + false, ) .await; diff --git a/crates/sui-core/src/unit_tests/authority_tests.rs b/crates/sui-core/src/unit_tests/authority_tests.rs index de449a5df9624..419aa9591a841 100644 --- a/crates/sui-core/src/unit_tests/authority_tests.rs +++ b/crates/sui-core/src/unit_tests/authority_tests.rs @@ -1326,6 +1326,7 @@ pub async fn init_state() -> AuthorityState { None, None, &sui_config::genesis::Genesis::get_default_genesis(), + false, ) .await } diff --git a/crates/sui-core/src/unit_tests/batch_tests.rs b/crates/sui-core/src/unit_tests/batch_tests.rs index b70bee58a977b..89e88241eeae4 100644 --- a/crates/sui-core/src/unit_tests/batch_tests.rs +++ b/crates/sui-core/src/unit_tests/batch_tests.rs @@ -57,6 +57,7 @@ pub(crate) async fn init_state( None, None, &sui_config::genesis::Genesis::get_default_genesis(), + false, ) .await } @@ -770,6 +771,7 @@ async fn test_safe_batch_stream() { None, None, &sui_config::genesis::Genesis::get_default_genesis(), + false, ) .await; @@ -815,6 +817,7 @@ async fn test_safe_batch_stream() { None, None, &sui_config::genesis::Genesis::get_default_genesis(), + false, ) .await; let auth_client_from_byzantine = ByzantineAuthorityClient::new(state_b); diff --git a/crates/sui-node/src/lib.rs b/crates/sui-node/src/lib.rs index 8fbfe3a6eb36d..9a4a3d5528d0c 100644 --- a/crates/sui-node/src/lib.rs +++ b/crates/sui-node/src/lib.rs @@ -69,6 +69,7 @@ impl SuiNode { index_store, checkpoint_store, genesis, + config.enable_event_processing, ) .await, ); diff --git a/crates/sui/src/benchmark/validator_preparer.rs b/crates/sui/src/benchmark/validator_preparer.rs index 9bde8a764e26e..8cf6be2a3c056 100644 --- a/crates/sui/src/benchmark/validator_preparer.rs +++ b/crates/sui/src/benchmark/validator_preparer.rs @@ -290,6 +290,7 @@ fn make_authority_state( None, None, &sui_config::genesis::Genesis::get_default_genesis(), + false, ) .await }),