Skip to content

Comments

fix(database): make DatabaseCommit dyn-compatible#3264

Merged
rakita merged 3 commits intobluealloy:mainfrom
haythemsellami:fix/database-commit-dyn-compatibility
Jan 8, 2026
Merged

fix(database): make DatabaseCommit dyn-compatible#3264
rakita merged 3 commits intobluealloy:mainfrom
haythemsellami:fix/database-commit-dyn-compatibility

Conversation

@haythemsellami
Copy link
Contributor

@haythemsellami haythemsellami commented Dec 30, 2025

Summary

This PR fixes dyn-compatibility of DatabaseCommit for downstream users like Foundry that use dyn DatabaseExt (which extends DatabaseCommit).

Problem

While integrating recent revm codebase with Foundry, I discovered that DatabaseCommit is not dyn-compatible due to how #[auto_impl] generates implementations.

Foundry defines DatabaseExt which extends DatabaseCommit:

pub trait DatabaseExt: Database<Error = DatabaseError> + DatabaseCommit + Debug { ... }

And uses it as a trait object throughout the codebase:

  pub struct FoundryEvm<'db, I: InspectorExt> {
      db: &'db mut dyn DatabaseExt,
      // ...
  }

The issue is that #[auto_impl(&mut, Box)] generates implementations like:

  impl<T: DatabaseCommit + ?Sized> DatabaseCommit for &mut T {
      fn commit_iter(&mut self, changes: impl IntoIterator<Item = (Address, Account)>) {
          T::commit_iter(*self, changes) 
      }
  }

This fails because commit_iter uses impl Trait in argument position (which requires Self: Sized). When T is ?Sized (like dyn DatabaseCommit), the generated code tries to call a method that requires Sized on a ?Sized type.

Solution

  1. commit_iter now uses &mut dyn Iterator: this keeps the method in the vtable and callable on trait objects
  2. impl dyn DatabaseCommit provides ergonomic commit_from_iter(impl IntoIterator) wrapper
  3. Add tests for dyn-compatibility including a compile-time check mirroring Foundry's approach

@codspeed-hq
Copy link

codspeed-hq bot commented Dec 30, 2025

CodSpeed Performance Report

Merging #3264 will not alter performance

Comparing haythemsellami:fix/database-commit-dyn-compatibility (4feef37) with main (191e2e3)

Summary

✅ 173 untouched

@haythemsellami haythemsellami force-pushed the fix/database-commit-dyn-compatibility branch from 90ba596 to 373c38a Compare January 2, 2026 07:16
Comment on lines 116 to 118
fn commit_iter(&mut self, changes: impl IntoIterator<Item = (Address, Account)>)
where
Self: Sized,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a &mut dyn IntoIterator so we can remove Self: Sized and allow usage of this function in parent traits

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do u mean here &mut dyn Iterator ?

})
// Unfortunately must collect here to short circuit on error
.collect::<Result<Vec<_>, _>>()?;
.collect::<Result<_, _>>()?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should revert this to vec, collecting to HashMap is a lot more expensive than collecting Vec.

I would try using commit_from_iter or figure out what needs to be changed here

@haythemsellami
Copy link
Contributor Author

@rakita Lmk if the below is a good path, will update the PR description later:

  1. commit_iter now uses &mut dyn Iterator instead of impl IntoIterator with Self: Sized
    - This keeps the method in the vtable and callable on trait objects
    - No more Self: Sized bound needed
  2. Re-enabled #[auto_impl(&mut, Box)] on DatabaseCommit: manual impls no longer needed
  3. increment_balances / drain_balances reverted to collect to Vec, then call commit_iter
  4. impl dyn DatabaseCommit provides ergonomic commit_from_iter(impl IntoIterator) wrapper

@haythemsellami haythemsellami force-pushed the fix/database-commit-dyn-compatibility branch from f769ed3 to 4feef37 Compare January 6, 2026 08:36
@rakita rakita merged commit b336d9d into bluealloy:main Jan 8, 2026
31 checks passed
@github-actions github-actions bot mentioned this pull request Jan 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants