Skip to content

Commit

Permalink
Merge branch 'main' into fault-tolerance
Browse files Browse the repository at this point in the history
  • Loading branch information
cchudant authored Jun 14, 2024
2 parents 2d83d1f + 1130e9e commit 1df4bb7
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- fix(cleanup): clean up around the Cargo.toml files, error handling and cli arguments
- fix(db): fault tolerance (database is not corrupted when the node is unexpectedly shut down / killed)
- fix(rpc): fixed state update deserialization
- fix(hashes): fixed tx by hash retrieval
- fix(logs): fixed logs and get_state_update
- refactor: remove primitives/felt
- refactor: move convert.rs to felt_wrapper.rs
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/client/db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ log = { workspace = true, default-features = true }
parity-scale-codec = { version = "3.6.5", features = ["derive"] }
rayon = { workspace = true }
rocksdb.workspace = true
serde_json = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true }
4 changes: 2 additions & 2 deletions crates/client/db/src/mapping_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,9 @@ impl MappingDb {
pub fn find_tx_hash_block(&self, tx_hash: &TransactionHash) -> Result<Option<(DeoxysBlock, TxStorageInfo)>> {
match self.tx_hash_to_block_n(tx_hash)? {
Some(block_n) => {
let Some(info) = self.get_pending_block_info()? else { return Ok(None) };
let Some(info) = self.get_block_info_from_block_n(block_n)? else { return Ok(None) };
let Some(tx_index) = info.tx_hashes().iter().position(|a| a == tx_hash) else { return Ok(None) };
let Some(inner) = self.get_pending_block_inner()? else { return Ok(None) };
let Some(inner) = self.get_block_inner_from_block_n(block_n)? else { return Ok(None) };
Ok(Some((
DeoxysBlock::new(info, inner),
TxStorageInfo { storage_type: BlockStorageType::BlockN(block_n), tx_index },
Expand Down
13 changes: 10 additions & 3 deletions crates/client/db/src/storage_handler/block_state_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ impl BlockStateDiffView {
let column = db.get_column(Column::BlockStateDiff);
let block_number: u32 = block_number.try_into().map_err(|_| DeoxysStorageError::InvalidBlockNumber)?;

let json_state_diff = serde_json::to_string(&state_diff).map_err(|_| DeoxysStorageError::StorageSerdeError)?;

let mut write_opt = WriteOptions::default(); // todo move that in db
write_opt.disable_wal(true);
db.put_cf_opt(&column, bincode::serialize(&block_number)?, bincode::serialize(&state_diff)?, &write_opt)
db.put_cf(&column, bincode::serialize(&block_number)?, bincode::serialize(&json_state_diff)?, &write_opt)
.map_err(|_| DeoxysStorageError::StorageInsertionError(StorageType::BlockStateDiff))
}

Expand All @@ -33,11 +35,16 @@ impl BlockStateDiffView {
let state_diff = db
.get_cf(&column, bincode::serialize(&block_number)?)
.map_err(|_| DeoxysStorageError::StorageRetrievalError(StorageType::BlockStateDiff))?
.map(|bytes| bincode::deserialize::<StateDiff>(&bytes[..]));
.map(|bytes| {
let bincode_decoded: String = bincode::deserialize(&bytes[..])?;
let state_diff: StateDiff =
serde_json::from_str(&bincode_decoded).map_err(|_| DeoxysStorageError::StorageSerdeError)?;
Ok(state_diff)
});

match state_diff {
Some(Ok(state_diff)) => Ok(Some(state_diff)),
Some(Err(_)) => Err(DeoxysStorageError::StorageDecodeError(StorageType::BlockStateDiff)),
Some(Err(err)) => Err(err),
None => Ok(None),
}
}
Expand Down

0 comments on commit 1df4bb7

Please sign in to comment.