Skip to content

Commit

Permalink
Persist changes from successful transactions (#163)
Browse files Browse the repository at this point in the history
* apply to store after tx success

* rm redundant write_access

* comments on redundant main store reset and apply
  • Loading branch information
rnbguy authored Apr 26, 2024
1 parent 97611fb commit 6697611
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
25 changes: 23 additions & 2 deletions basecoin/app/src/abci/v0_37/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub fn init_chain<S: Default + ProvableStore>(
ResponseInitChain {
consensus_params: request.consensus_params,
validators: vec![], // use validator set proposed by tendermint (ie. in the genesis file)
app_hash: app.store.write_access().root_hash().into(),
app_hash: app.store.read_access().root_hash().into(),
}
}

Expand Down Expand Up @@ -209,12 +209,33 @@ pub fn deliver_tx<S: Default + Debug + ProvableStore>(
for IdentifiedModule { module, .. } in modules.iter_mut() {
module.store_mut().reset();
}

// probably the main store doesn't need to be reset.
// currently the only time it is written while committing a block.
// but doing it nonetheless, just in case.
app.store.write_access().reset();
return ResponseDeliverTx::from_error(2, format!("deliver failed with error: {e}"));
}
}
}

// persists changes from all the messages in this tx
let mut modules = app.modules.write_access();
for IdentifiedModule { module, .. } in modules.iter_mut() {
module
.store_mut()
.apply()
.expect("failed to apply to module state");
}

// probably the main store doesn't need to be applied.
// currently the only time it is written while committing a block.
// but doing it nonetheless, just in case.
app.store
.write_access()
.apply()
.expect("failed to commit to state");

ResponseDeliverTx {
log: "success".to_owned(),
events,
Expand All @@ -228,7 +249,7 @@ pub fn commit<S: Default + ProvableStore>(app: &BaseCoinApp<S>) -> ResponseCommi
module
.store_mut()
.commit()
.expect("failed to commit to state");
.expect("failed to commit to module state");
let mut state = app.store.write_access();
state
.set(id.clone().into(), module.store().root_hash())
Expand Down
2 changes: 1 addition & 1 deletion basecoin/app/src/abci/v0_38/tendermint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl<S: Debug + ProvableStore> Application for BaseCoinApp<S> {
module
.store_mut()
.commit()
.expect("failed to commit to state");
.expect("failed to commit to module state");
let mut state = self.store.write_access();
state
.set(id.clone().into(), module.store().root_hash())
Expand Down

0 comments on commit 6697611

Please sign in to comment.