Skip to content

Commit ec47394

Browse files
committed
abort on DB error
1 parent 48a4fa8 commit ec47394

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

storage/txpool/src/service/write.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,22 @@ fn promote(
112112
let env_inner = env.env_inner();
113113
let tx_rw = env_inner.tx_rw()?;
114114

115-
let mut tx_infos = env_inner.open_db_rw::<TransactionInfos>(&tx_rw)?;
115+
let res = || {
116+
let mut tx_infos = env_inner.open_db_rw::<TransactionInfos>(&tx_rw)?;
116117

117-
tx_infos.update(tx_hash, |mut info| {
118-
info.flags.remove(TxStateFlags::STATE_STEM);
119-
Some(info)
120-
})?;
118+
tx_infos.update(tx_hash, |mut info| {
119+
info.flags.remove(TxStateFlags::STATE_STEM);
120+
Some(info)
121+
})
122+
};
123+
124+
if let Err(e) = res() {
125+
// error promoting the tx, abort the DB transaction.
126+
TxRw::abort(tx_rw)
127+
.expect("could not maintain database atomicity by aborting write transaction");
121128

122-
drop(tx_infos);
129+
return Err(e);
130+
}
123131

124132
TxRw::commit(tx_rw)?;
125133
Ok(TxpoolWriteResponse::Ok)

0 commit comments

Comments
 (0)