Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ABCI Removal Fix of Currency Pairs #300

Merged
merged 3 commits into from
Apr 11, 2024
Merged

fix: ABCI Removal Fix of Currency Pairs #300

merged 3 commits into from
Apr 11, 2024

Conversation

davidterpay
Copy link
Contributor

@davidterpay davidterpay commented Apr 1, 2024

Let's walk through a few scenarios:

Example 1

Height = H. With no removals in H.
N currency pairs in state.

  • Extend vote with N CPs.
  • Verify Vote with N CPs.
  • H is committed.
  • PrepareProposal checking that each VE has N CPs maximally in H + 1.
  • ProcessProposal checking that each VE has N CPs maximally in H + 1.

Example 2

Height = H. With M removals in H.
N currency pairs in state.

  • Extend Vote with N CPs.
  • Verify Vote with N CPs.
  • H is committed. This updates the num removed to M. This updates current amount stored to Z = N - M.
  • PrepareProposal checking each VE has Z + M CPs maximally in H+1.
  • ProcessProposal checking each VE has Z + M CPs maximally in H+1.

Example 3

Height = H. With removals in H+1.
N currency pairs in state.

  • Extend vote with N CPs.
  • Verify Vote with N CPs.
  • H is committed.
  • PrepareProposal checking that each VE has N CPs maximally in H+1.
  • ProcessProposal checking that each VE has N CPs maximally in H+1.
  • Extend Vote / Verify Vote logic is repeated in example 2.

@@ -120,11 +120,3 @@ func (s *DeltaCurrencyPairStrategy) getOnChainPrice(ctx sdk.Context, cp slinkyty
s.cache[cp] = currentPrice
return currentPrice, nil
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We inherit the default one so we don't need this since the check is the same.

@davidterpay davidterpay marked this pull request as ready for review April 1, 2024 15:38
Copy link

codecov bot commented Apr 1, 2024

Codecov Report

Attention: Patch coverage is 63.63636% with 8 lines in your changes are missing coverage. Please review.

Project coverage is 56.82%. Comparing base (043ce53) to head (eb68c2c).

Files Patch % Lines
abci/strategies/currencypair/default.go 55.55% 2 Missing and 2 partials ⚠️
x/oracle/keeper/keeper.go 69.23% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #300      +/-   ##
==========================================
+ Coverage   56.74%   56.82%   +0.07%     
==========================================
  Files         227      227              
  Lines       10756    10761       +5     
==========================================
+ Hits         6104     6115      +11     
+ Misses       4139     4134       -5     
+ Partials      513      512       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

}

if mode := ctx.ExecMode(); mode == sdk.ExecModePrepareProposal || mode == sdk.ExecModeProcessProposal {
removed, err := s.oracleKeeper.GetNumRemovedCurrencyPairs(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
removed, err := s.oracleKeeper.GetNumRemovedCurrencyPairs(ctx)
removed, err := s.oracleKeeper.GetNumRemovedCurrencyPairsInBlock(ctx)

I think let's be as pedantic as possible here since this is tricky enough to reason about

Copy link
Contributor

@nivasan1 nivasan1 Apr 1, 2024

Choose a reason for hiding this comment

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

Instead of implicitly casing on the exec-mode, I'd ideally like to expose to the caller whether they want the value of cps in state before the block was executed (specifically in Prepare / Process), or whether they want the # of cps in state (Verify)

Copy link
Contributor

Choose a reason for hiding this comment

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

This function has two diff behaviors AFAICT:

  1. Get the # of cps in state before the block was executed (+ all cps added in the last block executed)
  2. Get the current # of cps in state

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that would a breaking change with the current dYdX integration so im in favor of keeping it as is.

Copy link
Contributor

Choose a reason for hiding this comment

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

This alr is a breaking change, no? Only the GetPrevBlockCPCounter is implemented in dydx

@@ -113,10 +113,19 @@ func NewKeeper(

// RemoveCurrencyPair removes a given CurrencyPair from state, i.e. removes its nonce + QuotePrice from the module's store.
func (k *Keeper) RemoveCurrencyPair(ctx sdk.Context, cp slinkytypes.CurrencyPair) error {
// check if the currency pair exists.
if !k.HasCurrencyPair(ctx, cp) {
return types.NewCurrencyPairNotExistError(cp)
Copy link
Contributor

Choose a reason for hiding this comment

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

goated

if !k.HasCurrencyPair(ctx, cp) {
return types.NewCurrencyPairNotExistError(cp)
}

if err := k.currencyPairs.Remove(ctx, cp.String()); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

this is just for knowledge sake - if this does not return an error if the key does not exist, what are the cases where this does error?

@nivasan1
Copy link
Contributor

nivasan1 commented Apr 1, 2024

So in this case, we're leaving (numRemoved + numAddedCPs) * 33bz bytes unaccounted for (if we're j checking the size of the vote-extension. What is the advantage of doing this, in comparison to checking per ID whether the cp reported for either existed in state or was removed (we originally proposed this)?

Copy link
Contributor

@nivasan1 nivasan1 left a comment

Choose a reason for hiding this comment

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

left comment

@aljo242
Copy link
Contributor

aljo242 commented Apr 2, 2024

So in this case, we're leaving (numRemoved + numAddedCPs) * 33bz bytes unaccounted for (if we're j checking the size of the vote-extension. What is the advantage of doing this, in comparison to checking per ID whether the cp reported for either existed in state or was removed (we originally proposed this)?

The main one in my mind is that we are doing significantly less state reads this way. O(1) v O(n)

@davidterpay
Copy link
Contributor Author

@nivasan1 we originally had alignment that we would check only the size, you proposed the other idea but we decided to go with the simpler approach. I suggest we leave this as is and ask ottersec to take a deeper dive into this. More likely than not I can see the possibility of us moving into checking the IDs.

Copy link
Contributor

@aljo242 aljo242 left a comment

Choose a reason for hiding this comment

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

Approving for now but @davidterpay can you create an issue to clean this up / rename functions / doc this?

@nivasan1 nivasan1 force-pushed the terpay/removal-fix branch from 9f9f72b to eb68c2c Compare April 11, 2024 01:59
@nivasan1 nivasan1 self-requested a review April 11, 2024 02:07
Copy link
Contributor

@nivasan1 nivasan1 left a comment

Choose a reason for hiding this comment

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

lgtm

@nivasan1 nivasan1 merged commit d13181b into main Apr 11, 2024
15 checks passed
@zrbecker zrbecker deleted the terpay/removal-fix branch November 5, 2024 21:06
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.

4 participants