alchemyplatform / rundler

An ERC-4337 Bundler in Rust
GNU Lesser General Public License v3.0
268 stars 39 forks source link

fix(pool): fix race condition in paymaster tracking #728

Closed dancoombs closed 3 months ago

dancoombs commented 3 months ago

Proposed Changes

Race

  1. Paymaster sends deposit transaction
  2. UO uses paymaster, paymaster is new to the pool, queries chain for balance and adds to cache, sees the balance from 1
  3. Deposit event from (1) is notified to the pool, balance is added to the balance from (2)

Since there is no ordering guarantee between (2) and (3) you can end up with either balance or 2x balance in the cache. Instead process events as a reset event, and just query the chain for a balance after an event.

codecov[bot] commented 3 months ago

Codecov Report

Attention: Patch coverage is 98.91892% with 2 lines in your changes missing coverage. Please review.

Project coverage is 55.31%. Comparing base (98f8e2c) to head (bc64d0a).

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/alchemyplatform/rundler/pull/728/graphs/tree.svg?width=650&height=150&src=pr&token=FQKCPQJU2X&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=alchemyplatform)](https://app.codecov.io/gh/alchemyplatform/rundler/pull/728?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=alchemyplatform) | [Files](https://app.codecov.io/gh/alchemyplatform/rundler/pull/728?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=alchemyplatform) | Coverage Δ | | |---|---|---| | [crates/pool/src/mempool/paymaster.rs](https://app.codecov.io/gh/alchemyplatform/rundler/pull/728?src=pr&el=tree&filepath=crates%2Fpool%2Fsrc%2Fmempool%2Fpaymaster.rs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=alchemyplatform#diff-Y3JhdGVzL3Bvb2wvc3JjL21lbXBvb2wvcGF5bWFzdGVyLnJz) | `93.40% <100.00%> (-0.22%)` | :arrow_down: | | [crates/pool/src/mempool/uo\_pool.rs](https://app.codecov.io/gh/alchemyplatform/rundler/pull/728?src=pr&el=tree&filepath=crates%2Fpool%2Fsrc%2Fmempool%2Fuo_pool.rs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=alchemyplatform#diff-Y3JhdGVzL3Bvb2wvc3JjL21lbXBvb2wvdW9fcG9vbC5ycw==) | `95.09% <99.31%> (+0.34%)` | :arrow_up: | | [crates/rpc/src/eth/error.rs](https://app.codecov.io/gh/alchemyplatform/rundler/pull/728?src=pr&el=tree&filepath=crates%2Frpc%2Fsrc%2Feth%2Ferror.rs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=alchemyplatform#diff-Y3JhdGVzL3JwYy9zcmMvZXRoL2Vycm9yLnJz) | `0.00% <0.00%> (ø)` | | | [Flag](https://app.codecov.io/gh/alchemyplatform/rundler/pull/728/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=alchemyplatform) | Coverage Δ | | |---|---|---| | [unit-tests](https://app.codecov.io/gh/alchemyplatform/rundler/pull/728/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=alchemyplatform) | `55.31% <98.91%> (+0.10%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=alchemyplatform#carryforward-flags-in-the-pull-request-comment) to find out more. | [Components](https://app.codecov.io/gh/alchemyplatform/rundler/pull/728/components?src=pr&el=components&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=alchemyplatform) | Coverage Δ | | |---|---|---| | [rundler binary](https://app.codecov.io/gh/alchemyplatform/rundler/pull/728/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=alchemyplatform) | `0.00% <ø> (ø)` | | | [builder](https://app.codecov.io/gh/alchemyplatform/rundler/pull/728/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=alchemyplatform) | `50.00% <ø> (ø)` | | | [dev](https://app.codecov.io/gh/alchemyplatform/rundler/pull/728/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=alchemyplatform) | `0.00% <ø> (ø)` | | | [pool](https://app.codecov.io/gh/alchemyplatform/rundler/pull/728/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=alchemyplatform) | `64.64% <99.45%> (+0.26%)` | :arrow_up: | | [provider](https://app.codecov.io/gh/alchemyplatform/rundler/pull/728/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=alchemyplatform) | `16.68% <ø> (ø)` | | | [rpc](https://app.codecov.io/gh/alchemyplatform/rundler/pull/728/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=alchemyplatform) | `25.66% <0.00%> (-0.02%)` | :arrow_down: | | [sim](https://app.codecov.io/gh/alchemyplatform/rundler/pull/728/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=alchemyplatform) | `77.86% <ø> (ø)` | | | [tasks](https://app.codecov.io/gh/alchemyplatform/rundler/pull/728/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=alchemyplatform) | `∅ <ø> (∅)` | | | [types](https://app.codecov.io/gh/alchemyplatform/rundler/pull/728/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=alchemyplatform) | `65.45% <ø> (ø)` | | | [utils](https://app.codecov.io/gh/alchemyplatform/rundler/pull/728/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=alchemyplatform) | `18.28% <ø> (ø)` | |