Skip to content

Commit

Permalink
fix: relax mutability requirements on key structs (#414)
Browse files Browse the repository at this point in the history
  • Loading branch information
scarmuega authored Dec 23, 2024
1 parent c838208 commit ad28f87
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/bin/dolos/doctor/rebuild_ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub fn run(config: &crate::Config, _args: &Args, feedback: &Feedback) -> miette:
.into_diagnostic()
.context("creating in-memory state store")?;

let mut light = dolos::state::LedgerStore::Redb(light);
let light = dolos::state::LedgerStore::Redb(light);

if light
.is_empty()
Expand Down Expand Up @@ -81,7 +81,7 @@ pub fn run(config: &crate::Config, _args: &Args, feedback: &Feedback) -> miette:
.into_diagnostic()
.context("decoding blocks")?;

dolos::state::apply_block_batch(&blocks, &mut light, &genesis)
dolos::state::apply_block_batch(&blocks, &light, &genesis)
.into_diagnostic()
.context("importing blocks to ledger store")?;

Expand Down
4 changes: 2 additions & 2 deletions src/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ impl Mempool {
}
}

pub fn apply_block(&mut self, block: &MultiEraBlock) {
pub fn apply_block(&self, block: &MultiEraBlock) {
let mut state = self.mempool.write().unwrap();

if state.acknowledged.is_empty() {
Expand All @@ -229,7 +229,7 @@ impl Mempool {
}
}

pub fn undo_block(&mut self, block: &MultiEraBlock) {
pub fn undo_block(&self, block: &MultiEraBlock) {
let mut state = self.mempool.write().unwrap();

if state.acknowledged.is_empty() {
Expand Down
6 changes: 3 additions & 3 deletions src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ impl LedgerStore {
}
}

pub fn apply(&mut self, deltas: &[LedgerDelta]) -> Result<(), LedgerError> {
pub fn apply(&self, deltas: &[LedgerDelta]) -> Result<(), LedgerError> {
match self {
LedgerStore::Redb(x) => x.apply(deltas),
}
}

pub fn finalize(&mut self, until: BlockSlot) -> Result<(), LedgerError> {
pub fn finalize(&self, until: BlockSlot) -> Result<(), LedgerError> {
match self {
LedgerStore::Redb(x) => x.finalize(until),
}
Expand Down Expand Up @@ -215,7 +215,7 @@ pub fn load_slice_for_block(

pub fn apply_block_batch<'a>(
blocks: impl IntoIterator<Item = &'a MultiEraBlock<'a>>,
store: &mut LedgerStore,
store: &LedgerStore,
genesis: &Genesis,
) -> Result<(), LedgerError> {
let mut deltas: Vec<LedgerDelta> = vec![];
Expand Down
4 changes: 2 additions & 2 deletions src/state/redb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,15 @@ impl LedgerStore {
}
}

pub fn apply(&mut self, deltas: &[LedgerDelta]) -> Result<(), LedgerError> {
pub fn apply(&self, deltas: &[LedgerDelta]) -> Result<(), LedgerError> {
match self {
LedgerStore::SchemaV1(x) => Ok(x.apply(deltas)?),
LedgerStore::SchemaV2(x) => Ok(x.apply(deltas)?),
LedgerStore::SchemaV2Light(x) => Ok(x.apply(deltas)?),
}
}

pub fn finalize(&mut self, until: BlockSlot) -> Result<(), LedgerError> {
pub fn finalize(&self, until: BlockSlot) -> Result<(), LedgerError> {
match self {
LedgerStore::SchemaV1(x) => Ok(x.finalize(until)?),
LedgerStore::SchemaV2(x) => Ok(x.finalize(until)?),
Expand Down
4 changes: 2 additions & 2 deletions src/state/redb/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl LedgerStore {
tables::BlocksTable::last(&rx)
}

pub fn apply(&mut self, deltas: &[LedgerDelta]) -> Result<(), Error> {
pub fn apply(&self, deltas: &[LedgerDelta]) -> Result<(), Error> {
let mut wx = self.db().begin_write()?;
wx.set_durability(Durability::Eventual);

Expand All @@ -57,7 +57,7 @@ impl LedgerStore {
Ok(())
}

pub fn finalize(&mut self, until: BlockSlot) -> Result<(), Error> {
pub fn finalize(&self, until: BlockSlot) -> Result<(), Error> {
let rx = self.db().begin_read()?;
let tss = tables::TombstonesTable::get_range(&rx, until)?;

Expand Down
4 changes: 2 additions & 2 deletions src/state/redb/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl LedgerStore {
Ok(last)
}

pub fn apply(&mut self, deltas: &[LedgerDelta]) -> Result<(), Error> {
pub fn apply(&self, deltas: &[LedgerDelta]) -> Result<(), Error> {
let mut wx = self.db().begin_write()?;
wx.set_durability(Durability::Eventual);

Expand All @@ -64,7 +64,7 @@ impl LedgerStore {
Ok(())
}

pub fn finalize(&mut self, until: BlockSlot) -> Result<(), Error> {
pub fn finalize(&self, until: BlockSlot) -> Result<(), Error> {
let rx = self.db().begin_read()?;
let cursors = tables::CursorTable::get_range(&rx, until)?;

Expand Down
4 changes: 2 additions & 2 deletions src/state/redb/v2light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl LedgerStore {
Ok(last)
}

pub fn apply(&mut self, deltas: &[LedgerDelta]) -> Result<(), Error> {
pub fn apply(&self, deltas: &[LedgerDelta]) -> Result<(), Error> {
let mut wx = self.db().begin_write()?;
wx.set_durability(Durability::Eventual);

Expand All @@ -63,7 +63,7 @@ impl LedgerStore {
Ok(())
}

pub fn finalize(&mut self, until: BlockSlot) -> Result<(), Error> {
pub fn finalize(&self, until: BlockSlot) -> Result<(), Error> {
let rx = self.db().begin_read()?;
let cursors = tables::CursorTable::get_range(&rx, until)?;

Expand Down

0 comments on commit ad28f87

Please sign in to comment.