Skip to content

Conversation

Copy link

Copilot AI commented Jan 19, 2026

Extracts a SlashingDatabase trait from the concrete SQLite implementation to enable testing with mocks or instrumentation wrappers.

Changes

  • Created SlashingDatabase trait containing all public methods (validation, registration, import/export, pruning)
  • Renamed struct SlashingDatabaseSqliteSlashingDatabase
  • Made LighthouseValidatorStore generic over the trait with Send + Sync + 'static bounds
  • Updated all call sites to use SqliteSlashingDatabase directly or accept generic S: SlashingDatabase

Example

// Before
pub struct LighthouseValidatorStore<T, E> {
    slashing_protection: SlashingDatabase,
    // ...
}

// After - generic over any SlashingDatabase implementation
pub struct LighthouseValidatorStore<T, E, S> {
    slashing_protection: S,
    // ...
}
impl<T, E, S: SlashingDatabase + Send + Sync> LighthouseValidatorStore<T, E, S> {
    // ...
}

// Production code uses concrete type
let db = SqliteSlashingDatabase::open_or_create(path)?;
let store = LighthouseValidatorStore::new(validators, db, ...);

// Tests can inject mocks
let mock_db = MockSlashingDatabase::new();
let store = LighthouseValidatorStore::new(validators, mock_db, ...);

Both trait and concrete type are re-exported from slashing_protection crate for backward compatibility.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits January 19, 2026 01:03
…base

Co-authored-by: michaelsproul <4452260+michaelsproul@users.noreply.github.com>
Co-authored-by: michaelsproul <4452260+michaelsproul@users.noreply.github.com>
Copilot AI changed the title [WIP] Add trait for SlashingDatabase implementation Extract SlashingDatabase trait to enable mock testing Jan 19, 2026
Copilot AI requested a review from michaelsproul January 19, 2026 01:19
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