Skip to content

Conversation

@ali-behjati
Copy link
Collaborator

@ali-behjati ali-behjati commented Jun 27, 2023

Because of the storage design there was a race condition happening that both wh and pythnet try to store their state in the accumulator state and they ignore the other one because fetch and store are not done together consistently. This PR fixes that by adding update_accumulator_state to the Storage interface which takes a callback to apply.

@ali-behjati ali-behjati requested review from Reisen and jayantk June 27, 2023 15:32
@vercel
Copy link

vercel bot commented Jun 27, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Ignored Deployments
Name Status Preview Updated (UTC)
example-oracle-amm ⬜️ Ignored (Inspect) Jun 27, 2023 3:32pm
xc-admin-frontend ⬜️ Ignored (Inspect) Jun 27, 2023 3:32pm

Copy link
Contributor

@jayantk jayantk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a fine solution to the problem, though it's a little awkward that the storage doesn't work the same for the two different types of values it stores (see inline comment). Not a big deal though, so up to you whether you want to change it.

/// Store the accumulator state. Please note that this call will replace the
/// existing accumulator state for the given state's slot. If you wish to
/// update the accumulator state, use `update_accumulator_state` instead.
async fn store_accumulator_state(&self, state: AccumulatorState) -> Result<()>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple thoughts on this change:

  1. is there ever a situation where it's safe to use this store function? Maybe you'd be better off deleting it?
  2. Does the same change need to be done to storing the message_states above? I think the answer is "no", because you never mutate the content of MessageState. But then it's a little weird that the two types of stored values require different handling. You could make this consistent by splitting out the two components of AccumulatorState and fetching/storing them separately. That would be easy to do if you created a cache abstraction that handled the insertion / eviction logic (which would be good anyway, because i see that code is repeated for messages and accumulator states below).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you and David suggested the same. I will do it in another PR. having a proper abstraction for the simple ordered cache makes sense too.

@ali-behjati ali-behjati merged commit 96cb221 into main Jun 28, 2023
@ali-behjati ali-behjati deleted the hermes/fix-concurrency-bug branch June 28, 2023 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants