Skip to content

fix(consensus-db): declare PendingProposalsRepository::count with Self::Error - #393

Open
Dusk1e wants to merge 1 commit into
circlefin:mainfrom
Dusk1e:fix/pending-proposals-count-error-type
Open

fix(consensus-db): declare PendingProposalsRepository::count with Self::Error#393
Dusk1e wants to merge 1 commit into
circlefin:mainfrom
Dusk1e:fix/pending-proposals-count-error-type

Conversation

@Dusk1e

@Dusk1e Dusk1e commented Sep 12, 2026

Copy link
Copy Markdown

Every method across the six repository traits in repositories/ and the PruningService trait is declared with Self::Error. PendingProposalsRepository::count is the one exception:

pub trait PendingProposalsRepository {
    type Error: std::error::Error + Send + Sync + 'static;

    async fn enforce_limit(...) -> Result<Vec<(Height, Round, BlockHash)>, Self::Error>;

    async fn count(&self) -> Result<usize, StoreError>;
}

That is not only a style difference. The trait cannot be implemented by anything whose Error is not StoreError — an implementor returning its own error type from count fails to compile:

error[E0271]: expected `impl Future<Output = Result<usize, <FailingCount as PendingProposalsRepository>::Error>>`
to be a future that resolves to `Result<usize, StoreError>`, but it resolves to `Result<usize, CountError>`

So the associated Error type is honoured by one of the trait's two methods, and MockPendingProposalsRepository, generated with Error = std::io::Error, returns io::Error from enforce_limit and StoreError from count.

The blanket impl for &T carried the same hardcoded signature and now forwards Self::Error too. Store is unaffected: its Error already is StoreError. The one caller, consensus_ready.rs, goes through wrap_err, which the trait's existing Error bound already satisfies.

The test is the implementor from the error above: it fails to compile on main and passes with the change. cargo test -p arc-consensus-db is green (107 tests), as is cargo check -p arc-consensus-db --features mock.

Every method across the six repository traits and the pruning service is
declared with Self::Error. PendingProposalsRepository::count is the one
exception: it hardcodes StoreError.

That is a compile error rather than a style point. The trait cannot be
implemented by anything whose Error is not StoreError — an implementor
returning its own error type from count fails with E0271. It also leaves the
generated mock, built with Error = std::io::Error, returning io::Error from
enforce_limit and StoreError from count.

The blanket impl for &T carried the same signature and now forwards
Self::Error as well. Store is unaffected, its Error already is StoreError.
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.

1 participant