Skip to content

Commit

Permalink
Fix metadata update race condition (#1187)
Browse files Browse the repository at this point in the history
* Fix metadata update race condition

* fix formatting

* Nit

Co-authored-by: Christian Poveda <christian.poveda@iota.org>
  • Loading branch information
thibault-martinez and pvdrz committed Mar 1, 2022
1 parent 2a65fd7 commit 4cd8d50
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
25 changes: 14 additions & 11 deletions bee-protocol/src/workers/propagator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ async fn propagate<B: StorageBackend>(
// Note: There are two types of solidity carriers:
// * solid messages (with available history)
// * solid entry points / sep (with verified history)
// Because we know both parents are solid, we also know that they have set OMRSI/YMRSI values, hence
// we can simply unwrap. We also try to minimise unnecessary Tangle API calls if - for example - the
// parent in question turns out to be a SEP.
// Because we know all parents are solid, we also know that they have set OMRSI/YMRSI values, hence we can
// simply unwrap. We also try to minimise unnecessary Tangle API calls if - for example - the parent in
// question turns out to be a SEP.

let mut parent_omrsis = Vec::new();
let mut parent_ymrsis = Vec::new();
Expand All @@ -62,14 +62,17 @@ async fn propagate<B: StorageBackend>(
.await
{
Some(parent_sepi) => (IndexId::new(parent_sepi, *parent), IndexId::new(parent_sepi, *parent)),
None => match tangle.get_metadata(parent).await {
// 'unwrap' is safe (see explanation above)
Some(parent_md) => (
parent_md.omrsi().expect("solid msg with unset omrsi"),
parent_md.ymrsi().expect("solid msg with unset ymrsi"),
),
None => continue 'outer,
},
// SAFETY: 'unwrap' is safe, see explanation above.
None => tangle
.get_metadata(parent)
.await
.map(|parent_md| {
(
parent_md.omrsi().expect("solid msg with unset omrsi"),
parent_md.ymrsi().expect("solid msg with unset ymrsi"),
)
})
.unwrap(),
};
parent_omrsis.push(parent_omrsi);
parent_ymrsis.push(parent_ymrsi);
Expand Down
4 changes: 2 additions & 2 deletions bee-tangle/src/tangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,10 +500,10 @@ impl<B: StorageBackend> Tangle<B> {
if let Some((msg, meta)) = vertex.message_and_metadata() {
let (msg, meta) = ((&**msg).clone(), *meta);

drop(vertex);

self.storage_insert(*message_id, msg, meta)
.unwrap_or_else(|e| info!("Failed to update metadata for message {:?}", e));

drop(vertex);
}

r
Expand Down

0 comments on commit 4cd8d50

Please sign in to comment.