Skip to content

Commit

Permalink
Merge branch 'tiago/commit-failure' (#2657)
Browse files Browse the repository at this point in the history
* origin/tiago/commit-failure:
  Changelog for #2657
  Document fields in `commit` response
  Bump last processed Eth block before calling `commit_block`
  Remove mut response from `commit`
  Crash if committing a block fails
  • Loading branch information
Gianmarco Fraccaroli committed Feb 21, 2024
2 parents 5c73afb + 459eb72 commit 96fcafc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
3 changes: 3 additions & 0 deletions .changelog/unreleased/bug-fixes/2657-commit-failure.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Rather than allowing CometBFT to keep processing blocks after a storage write
has failed in Namada, crash the ledger to avoid any potential corruption of
state. ([\#2657](https://github.com/anoma/namada/pull/2657))
33 changes: 15 additions & 18 deletions crates/apps/src/lib/node/ledger/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -768,30 +768,27 @@ where
/// Commit a block. Persist the application state and return the Merkle root
/// hash.
pub fn commit(&mut self) -> response::Commit {
let mut response = response::Commit {
retain_height: tendermint::block::Height::from(0_u32),
..Default::default()
};
// commit block's data from write log and store the in DB
self.wl_storage.commit_block().unwrap_or_else(|e| {
tracing::error!(
"Encountered a storage error while committing a block {:?}",
e
)
});
self.bump_last_processed_eth_block();

let root = self.wl_storage.storage.merkle_root();
self.wl_storage
.commit_block()
.expect("Encountered a storage error while committing a block");

let merkle_root = self.wl_storage.storage.merkle_root();
let committed_height = self.wl_storage.storage.get_last_block_height();
tracing::info!(
"Committed block hash: {}, height: {}",
root,
self.wl_storage.storage.get_last_block_height(),
"Committed block hash: {merkle_root}, height: {committed_height}",
);
response.data = root.0.to_vec().into();

self.bump_last_processed_eth_block();
self.broadcast_queued_txs();

response
response::Commit {
// NB: by passing 0, we forbid CometBFT from deleting
// data pertaining to past blocks
retain_height: tendermint::block::Height::from(0_u32),
// NB: current application hash
data: merkle_root.0.to_vec().into(),
}
}

/// Updates the Ethereum oracle's last processed block.
Expand Down

0 comments on commit 96fcafc

Please sign in to comment.