Avoid losing values in intermediate take (#4833)

This commit is contained in:
Wei Tang
2020-02-05 17:26:07 +01:00
committed by GitHub
parent 54c10893ab
commit c0af995362
@@ -228,15 +228,14 @@ impl<Block: BlockT, Transaction> BlockImportParams<Block, Transaction> {
/// Take interemdiate by given key, and remove it from the processing list.
pub fn take_intermediate<T: 'static>(&mut self, key: &[u8]) -> Result<Box<T>, Error> {
if self.intermediates.contains_key(key) {
self.intermediates.remove(key)
.ok_or(Error::NoIntermediate)
.and_then(|value| {
value.downcast::<T>()
.map_err(|_| Error::InvalidIntermediate)
})
} else {
Err(Error::NoIntermediate)
let (k, v) = self.intermediates.remove_entry(key).ok_or(Error::NoIntermediate)?;
match v.downcast::<T>() {
Ok(v) => Ok(v),
Err(v) => {
self.intermediates.insert(k, v);
Err(Error::InvalidIntermediate)
},
}
}