diff --git a/CHANGELOG.md b/CHANGELOG.md index 26a40ff72..da7e04062 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - fix: rejected transaction block production panic - fix(sync): pending block retrying mechanism +- feat(clean): dc_db: rename `DbBlockId::BlockN` to `DbBlockId::Number` - feat(cli): Environment variables can be used to specify Madara parameters - fix:(tests): Add testing feature to mc-db dev dependency (#294) - feat: new crate gateway client & server diff --git a/crates/client/db/src/block_db.rs b/crates/client/db/src/block_db.rs index 30e542d14..37a5db49a 100644 --- a/crates/client/db/src/block_db.rs +++ b/crates/client/db/src/block_db.rs @@ -264,9 +264,9 @@ impl MadaraBackend { pub(crate) fn id_to_storage_type(&self, id: &BlockId) -> Result> { match id { - BlockId::Hash(hash) => Ok(self.block_hash_to_block_n(hash)?.map(DbBlockId::BlockN)), - BlockId::Number(block_n) => Ok(Some(DbBlockId::BlockN(*block_n))), - BlockId::Tag(BlockTag::Latest) => Ok(self.get_latest_block_n()?.map(DbBlockId::BlockN)), + BlockId::Hash(hash) => Ok(self.block_hash_to_block_n(hash)?.map(DbBlockId::Number)), + BlockId::Number(block_n) => Ok(Some(DbBlockId::Number(*block_n))), + BlockId::Tag(BlockTag::Latest) => Ok(self.get_latest_block_n()?.map(DbBlockId::Number)), BlockId::Tag(BlockTag::Pending) => Ok(Some(DbBlockId::Pending)), } } @@ -274,7 +274,7 @@ impl MadaraBackend { fn storage_to_info(&self, id: &DbBlockId) -> Result> { match id { DbBlockId::Pending => Ok(Some(MadaraMaybePendingBlockInfo::Pending(self.get_pending_block_info()?))), - DbBlockId::BlockN(block_n) => { + DbBlockId::Number(block_n) => { Ok(self.get_block_info_from_block_n(*block_n)?.map(MadaraMaybePendingBlockInfo::NotPending)) } } @@ -283,7 +283,7 @@ impl MadaraBackend { fn storage_to_inner(&self, id: &DbBlockId) -> Result> { match id { DbBlockId::Pending => Ok(Some(self.get_pending_block_inner()?)), - DbBlockId::BlockN(block_n) => self.get_block_inner_from_block_n(*block_n), + DbBlockId::Number(block_n) => self.get_block_inner_from_block_n(*block_n), } } @@ -292,7 +292,7 @@ impl MadaraBackend { pub fn get_block_n(&self, id: &impl DbBlockIdResolvable) -> Result> { let Some(ty) = id.resolve_db_block_id(self)? else { return Ok(None) }; match &ty { - DbBlockId::BlockN(block_id) => Ok(Some(*block_id)), + DbBlockId::Number(block_id) => Ok(Some(*block_id)), DbBlockId::Pending => Ok(None), } } @@ -301,7 +301,7 @@ impl MadaraBackend { let Some(ty) = id.resolve_db_block_id(self)? else { return Ok(None) }; match &ty { // TODO: fast path if id is already a block hash.. - DbBlockId::BlockN(block_n) => Ok(self.get_block_info_from_block_n(*block_n)?.map(|b| b.block_hash)), + DbBlockId::Number(block_n) => Ok(self.get_block_info_from_block_n(*block_n)?.map(|b| b.block_hash)), DbBlockId::Pending => Ok(None), } } @@ -310,7 +310,7 @@ impl MadaraBackend { let Some(ty) = id.resolve_db_block_id(self)? else { return Ok(None) }; match ty { DbBlockId::Pending => Ok(Some(self.get_pending_block_state_update()?)), - DbBlockId::BlockN(block_n) => self.get_state_update(block_n), + DbBlockId::Number(block_n) => self.get_state_update(block_n), } } diff --git a/crates/client/db/src/class_db.rs b/crates/client/db/src/class_db.rs index c1c285064..aa57efd80 100644 --- a/crates/client/db/src/class_db.rs +++ b/crates/client/db/src/class_db.rs @@ -67,7 +67,7 @@ impl MadaraBackend { let valid = match (requested_id, info.block_id) { (DbBlockId::Pending, _) => true, - (DbBlockId::BlockN(block_n), DbBlockId::BlockN(real_block_n)) => real_block_n <= block_n, + (DbBlockId::Number(block_n), DbBlockId::Number(real_block_n)) => real_block_n <= block_n, _ => false, }; if !valid { @@ -174,7 +174,7 @@ impl MadaraBackend { block_number: u64, converted_classes: &[ConvertedClass], ) -> Result<(), MadaraStorageError> { - self.store_classes(DbBlockId::BlockN(block_number), converted_classes, Column::ClassInfo, Column::ClassCompiled) + self.store_classes(DbBlockId::Number(block_number), converted_classes, Column::ClassInfo, Column::ClassCompiled) } /// NB: This functions needs to run on the rayon thread pool diff --git a/crates/client/db/src/contract_db.rs b/crates/client/db/src/contract_db.rs index 7c6069516..fa3f53724 100644 --- a/crates/client/db/src/contract_db.rs +++ b/crates/client/db/src/contract_db.rs @@ -51,7 +51,7 @@ impl MadaraBackend { let Some(block_n) = self.get_latest_block_n()? else { return Ok(None) }; block_n } - DbBlockId::BlockN(block_n) => block_n, + DbBlockId::Number(block_n) => block_n, }; // We try to find history values. diff --git a/crates/client/db/src/db_block_id.rs b/crates/client/db/src/db_block_id.rs index 4f75c5c9c..75471719b 100644 --- a/crates/client/db/src/db_block_id.rs +++ b/crates/client/db/src/db_block_id.rs @@ -7,7 +7,7 @@ use crate::{MadaraBackend, MadaraStorageError}; #[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)] pub enum DbBlockId { Pending, - BlockN(u64), + Number(u64), } impl DbBlockId { @@ -42,7 +42,7 @@ impl fmt::Display for DbBlockId { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::Pending => write!(f, "#"), - Self::BlockN(block_n) => write!(f, "#{block_n}"), + Self::Number(block_n) => write!(f, "#{block_n}"), } } } @@ -60,6 +60,6 @@ mod test { #[test] fn test_db_block_id() { assert!(DbBlockId::Pending.is_pending()); - assert!(!DbBlockId::BlockN(0).is_pending()); + assert!(!DbBlockId::Number(0).is_pending()); } } diff --git a/crates/client/db/src/tests/test_block.rs b/crates/client/db/src/tests/test_block.rs index 810789721..f9531b401 100644 --- a/crates/client/db/src/tests/test_block.rs +++ b/crates/client/db/src/tests/test_block.rs @@ -28,8 +28,8 @@ mod block_tests { backend.store_block(block.clone(), state_diff.clone(), vec![]).unwrap(); backend.store_block(pending_block_one(), pending_state_diff_one(), vec![]).unwrap(); - assert_eq!(backend.resolve_block_id(&BlockId::Hash(block_hash)).unwrap().unwrap(), DbBlockId::BlockN(0)); - assert_eq!(backend.resolve_block_id(&BlockId::Number(0)).unwrap().unwrap(), DbBlockId::BlockN(0)); + assert_eq!(backend.resolve_block_id(&BlockId::Hash(block_hash)).unwrap().unwrap(), DbBlockId::Number(0)); + assert_eq!(backend.resolve_block_id(&BlockId::Number(0)).unwrap().unwrap(), DbBlockId::Number(0)); assert_eq!(backend.resolve_block_id(&DbBlockId::Pending).unwrap().unwrap(), DbBlockId::Pending); } @@ -43,7 +43,7 @@ mod block_tests { #[tokio::test] async fn test_store_block() { - const BLOCK_ID_0: DbBlockId = DbBlockId::BlockN(0); + const BLOCK_ID_0: DbBlockId = DbBlockId::Number(0); let db = temp_db().await; let backend = db.backend(); diff --git a/crates/client/exec/src/block_context.rs b/crates/client/exec/src/block_context.rs index 51c4a5c33..8ba86fc3f 100644 --- a/crates/client/exec/src/block_context.rs +++ b/crates/client/exec/src/block_context.rs @@ -35,9 +35,9 @@ impl ExecutionContext { pub fn init_cached_state(&self) -> CachedState { let on_top_of = match self.db_id { DbBlockId::Pending => Some(DbBlockId::Pending), - DbBlockId::BlockN(block_n) => { + DbBlockId::Number(block_n) => { // We exec on top of the previous block. None means we are executing genesis. - block_n.checked_sub(1).map(DbBlockId::BlockN) + block_n.checked_sub(1).map(DbBlockId::Number) } }; @@ -70,7 +70,7 @@ impl ExecutionContext { block.header.l1_da_mode, ), MadaraMaybePendingBlockInfo::NotPending(block) => ( - DbBlockId::BlockN(block.header.block_number), + DbBlockId::Number(block.header.block_number), block.header.protocol_version, block.header.block_number, block.header.block_timestamp, diff --git a/crates/client/rpc/src/versions/v0_7_1/methods/read/get_state_update.rs b/crates/client/rpc/src/versions/v0_7_1/methods/read/get_state_update.rs index ac87ff3c7..3786fc765 100644 --- a/crates/client/rpc/src/versions/v0_7_1/methods/read/get_state_update.rs +++ b/crates/client/rpc/src/versions/v0_7_1/methods/read/get_state_update.rs @@ -61,7 +61,7 @@ pub fn get_state_update(starknet: &Starknet, block_id: BlockId) -> StarknetRpcRe // Get the old root from the previous block if it exists, otherwise default to zero. let old_root = if let Some(val) = block_info.header.block_number.checked_sub(1) { - let prev_block_info = &starknet.get_block_info(&DbBlockId::BlockN(val))?; + let prev_block_info = &starknet.get_block_info(&DbBlockId::Number(val))?; let prev_block_info = prev_block_info.as_nonpending().ok_or_internal_server_error("Block should not be pending")?; diff --git a/crates/client/sync/src/l2.rs b/crates/client/sync/src/l2.rs index 179d0d1d8..5b7873804 100644 --- a/crates/client/sync/src/l2.rs +++ b/crates/client/sync/src/l2.rs @@ -325,7 +325,7 @@ mod tests { Err(_) => panic!("Timeout reached while waiting for task completion"), } - let applied_block = backend.get_block(&DbBlockId::BlockN(0)).unwrap(); + let applied_block = backend.get_block(&DbBlockId::Number(0)).unwrap(); assert!(applied_block.is_some(), "The block was not applied correctly"); let applied_block = MadaraBlock::try_from(applied_block.unwrap()).unwrap();