diff --git a/base_layer/core/src/base_node/comms_interface/inbound_handlers.rs b/base_layer/core/src/base_node/comms_interface/inbound_handlers.rs index d157d9162b..5120c35103 100644 --- a/base_layer/core/src/base_node/comms_interface/inbound_handlers.rs +++ b/base_layer/core/src/base_node/comms_interface/inbound_handlers.rs @@ -407,7 +407,7 @@ where T: BlockchainBackend + 'static ) -> Result<(), CommsInterfaceError> { let NewBlock { block_hash } = new_block; - if self.blockchain_db.inner().is_add_block_locked() { + if self.blockchain_db.inner().is_add_block_disabled() { info!( target: LOG_TARGET, "Ignoring block message ({}) because add_block is locked", diff --git a/base_layer/core/src/base_node/state_machine_service/state_machine.rs b/base_layer/core/src/base_node/state_machine_service/state_machine.rs index 4f440a74dc..4ec0f8b757 100644 --- a/base_layer/core/src/base_node/state_machine_service/state_machine.rs +++ b/base_layer/core/src/base_node/state_machine_service/state_machine.rs @@ -158,37 +158,37 @@ impl BaseNodeStateMachine { .. }), ) => { - db.set_add_block_lock_flag(); + db.set_disable_add_block_flag(); HeaderSync(HeaderSyncState::new(sync_peers, local_metadata)) }, (HeaderSync(s), HeaderSyncFailed) => { - db.clear_add_block_lock_flag(); + db.clear_disable_add_block_flag(); Waiting(s.into()) }, (HeaderSync(s), Continue | NetworkSilence) => { - db.clear_add_block_lock_flag(); + db.clear_disable_add_block_flag(); Listening(s.into()) }, (HeaderSync(s), HeadersSynchronized(_)) => DecideNextSync(s.into()), (DecideNextSync(_), ProceedToHorizonSync(peer)) => HorizonStateSync(peer.into()), (DecideNextSync(s), Continue) => { - db.clear_add_block_lock_flag(); + db.clear_disable_add_block_flag(); Listening(s.into()) }, (HorizonStateSync(s), HorizonStateSynchronized) => BlockSync(s.into()), (HorizonStateSync(s), HorizonStateSyncFailure) => { - db.clear_add_block_lock_flag(); + db.clear_disable_add_block_flag(); Waiting(s.into()) }, (DecideNextSync(_), ProceedToBlockSync(peer)) => BlockSync(peer.into()), (BlockSync(s), BlocksSynchronized) => { - db.clear_add_block_lock_flag(); + db.clear_disable_add_block_flag(); Listening(s.into()) }, (BlockSync(s), BlockSyncFailed) => { - db.clear_add_block_lock_flag(); + db.clear_disable_add_block_flag(); Waiting(s.into()) }, diff --git a/base_layer/core/src/chain_storage/blockchain_database.rs b/base_layer/core/src/chain_storage/blockchain_database.rs index 04f385fe5d..67ff5324b8 100644 --- a/base_layer/core/src/chain_storage/blockchain_database.rs +++ b/base_layer/core/src/chain_storage/blockchain_database.rs @@ -185,7 +185,7 @@ pub struct BlockchainDatabase { config: BlockchainDatabaseConfig, consensus_manager: ConsensusManager, difficulty_calculator: Arc, - add_block_lock_flag: Arc, + disable_add_block_flag: Arc, } #[allow(clippy::ptr_arg)] @@ -209,7 +209,7 @@ where B: BlockchainBackend config, consensus_manager, difficulty_calculator: Arc::new(difficulty_calculator), - add_block_lock_flag: Arc::new(AtomicBool::new(false)), + disable_add_block_flag: Arc::new(AtomicBool::new(false)), }; if is_empty { info!(target: LOG_TARGET, "Blockchain db is empty. Adding genesis block."); @@ -288,16 +288,16 @@ where B: BlockchainBackend }) } - pub(crate) fn is_add_block_locked(&self) -> bool { - self.add_block_lock_flag.load(atomic::Ordering::Acquire) + pub(crate) fn is_add_block_disabled(&self) -> bool { + self.disable_add_block_flag.load(atomic::Ordering::Acquire) } - pub(crate) fn set_add_block_lock_flag(&self) { - self.add_block_lock_flag.store(true, atomic::Ordering::Release); + pub(crate) fn set_disable_add_block_flag(&self) { + self.disable_add_block_flag.store(true, atomic::Ordering::Release); } - pub(crate) fn clear_add_block_lock_flag(&self) { - self.add_block_lock_flag.store(false, atomic::Ordering::Release); + pub(crate) fn clear_disable_add_block_flag(&self) { + self.disable_add_block_flag.store(false, atomic::Ordering::Release); } pub fn write(&self, transaction: DbTransaction) -> Result<(), ChainStorageError> { @@ -820,10 +820,10 @@ where B: BlockchainBackend /// /// If an error does occur while writing the new block parts, all changes are reverted before returning. pub fn add_block(&self, block: Arc) -> Result { - if self.add_block_lock_flag.load(atomic::Ordering::Acquire) { + if self.is_add_block_disabled() { warn!( target: LOG_TARGET, - "add_block called while locked with block #{} ({})", + "add_block is disabled. Ignoring candidate block #{} ({})", block.header.height, block.hash().to_hex() ); @@ -2199,7 +2199,7 @@ impl Clone for BlockchainDatabase { config: self.config, consensus_manager: self.consensus_manager.clone(), difficulty_calculator: self.difficulty_calculator.clone(), - add_block_lock_flag: self.add_block_lock_flag.clone(), + disable_add_block_flag: self.disable_add_block_flag.clone(), } } } diff --git a/comms/src/protocol/rpc/status.rs b/comms/src/protocol/rpc/status.rs index 77b457cc5e..43504ca982 100644 --- a/comms/src/protocol/rpc/status.rs +++ b/comms/src/protocol/rpc/status.rs @@ -271,7 +271,7 @@ mod test { assert_eq!(RpcStatusCode::from(InvalidRpcStatusCode as u32), InvalidRpcStatusCode); assert_eq!(RpcStatusCode::from(ProtocolError as u32), ProtocolError); assert_eq!(RpcStatusCode::from(Forbidden as u32), Forbidden); - assert_eq!(RpcStatusCode::from(Conflict as u32), Forbidden); + assert_eq!(RpcStatusCode::from(Conflict as u32), Conflict); assert_eq!(RpcStatusCode::from(123), InvalidRpcStatusCode); } }