Skip to content

Commit

Permalink
rename to disable_add_block, fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
sdbondi committed Dec 16, 2021
1 parent e46eaa7 commit 508f04f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,37 +158,37 @@ impl<B: BlockchainBackend + 'static> BaseNodeStateMachine<B> {
..
}),
) => {
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())
},

Expand Down
22 changes: 11 additions & 11 deletions base_layer/core/src/chain_storage/blockchain_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ pub struct BlockchainDatabase<B> {
config: BlockchainDatabaseConfig,
consensus_manager: ConsensusManager,
difficulty_calculator: Arc<DifficultyCalculator>,
add_block_lock_flag: Arc<AtomicBool>,
disable_add_block_flag: Arc<AtomicBool>,
}

#[allow(clippy::ptr_arg)]
Expand All @@ -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.");
Expand Down Expand Up @@ -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> {
Expand Down Expand Up @@ -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<Block>) -> Result<BlockAddResult, ChainStorageError> {
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()
);
Expand Down Expand Up @@ -2199,7 +2199,7 @@ impl<T> Clone for BlockchainDatabase<T> {
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(),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion comms/src/protocol/rpc/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 508f04f

Please sign in to comment.