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: last updated setting in x/marketmap keeper [DO NOT MERGE] #799

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

aljo242
Copy link
Contributor

@aljo242 aljo242 commented Oct 16, 2024

Closes CON-1839

  • call SetLastUpdated for any Set or Remove calls in the keeper. (previously these calls were only done during the MsgServer which meant that hooks, or any keeper calls that are not part of a MsgServer call were not updating LastUpdated)
  • Add more testing around the LastUpdated field. Use randomized blockheights instead of constants
  • add checks to our E2E tests to ensure that the LastUpdated field is updated for all Tx we call.

Note, this fix is only for on-chain code, so a full upgrade would be needed. This is also state-breaking, so we will need to make a new v3.x release as any v1 or v2 version of the code will result in disparate states (last updated will be updated differently).

I will make another PR that will only updates the sidecar, which can be rolled out more quickly.

Copy link

codecov bot commented Oct 16, 2024

Codecov Report

Attention: Patch coverage is 72.72727% with 3 lines in your changes missing coverage. Please review.

Project coverage is 57.40%. Comparing base (efff2b1) to head (2d6dc3a).

Files with missing lines Patch % Lines
x/marketmap/keeper/keeper.go 62.50% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #799      +/-   ##
==========================================
+ Coverage   57.39%   57.40%   +0.01%     
==========================================
  Files         214      214              
  Lines       14844    14850       +6     
==========================================
+ Hits         8520     8525       +5     
  Misses       5710     5710              
- Partials      614      615       +1     

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

Copy link
Member

@zrbecker zrbecker left a comment

Choose a reason for hiding this comment

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

Added some comments. Let's chat about how this change and how it is integrated tomorrow.

// create the mm client
client := mmtypes.NewQueryClient(cc)

ctx := context.Background()
Copy link
Member

Choose a reason for hiding this comment

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

I know this is only used in tests, but can we just pass a ctx to this function and use it. Ideally a context is defined at the beginning of tests that we can use, and it looks like there is a context for us to use in this case, so we should avoid creating this context if possible.

if err != nil {
return err
}

if resp.TxResult.Code != abcitypes.CodeTypeOK {
return fmt.Errorf(resp.TxResult.Log)
if txResp.TxResult.Code != abcitypes.CodeTypeOK {
Copy link
Member

Choose a reason for hiding this comment

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

Do proposals pass immediately with interchaintest?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, but the result of a proposal or submitted Tx will be TypeOK if it landed successfully

@@ -89,7 +89,18 @@ func (k *Keeper) GetMarket(ctx context.Context, tickerStr string) (types.Market,

// setMarket sets a market.
func (k *Keeper) setMarket(ctx context.Context, market types.Market) error {
return k.markets.Set(ctx, types.TickerString(market.Ticker.String()), market)
if err := k.markets.Set(ctx, types.TickerString(market.Ticker.String()), market); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Just curious, what are the properties of this cosmos-sdk collections map? Does it handle stuff to ensure things are deterministic? Any idea of the specifics?

@@ -85,7 +85,7 @@ func (ms msgServer) UpsertMarkets(goCtx context.Context, msg *types.MsgUpsertMar
return nil, err
}

return &types.MsgUpsertMarketsResponse{}, ms.k.SetLastUpdated(ctx, uint64(ctx.BlockHeight())) //nolint:gosec
Copy link
Member

Choose a reason for hiding this comment

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

For these functions, SetLastUpdated will not get called many times per upsert potentially. Are there gas consequences of this? Is that a problem?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are gas consequences because it is called many times yes.

This isn't a problem per-se as these transactions are only executed by gov / the mmu auth, but it is another reason why this PR is state breaking

@aljo242 aljo242 changed the title fix: last updated setting in x/marketmap keeper fix: last updated setting in x/marketmap keeper [DO NOT MERGE] Oct 22, 2024
@zrbecker zrbecker marked this pull request as draft November 8, 2024 19:33
@zrbecker zrbecker requested review from zrbecker and removed request for zrbecker, Eric-Warehime, technicallyty and wesl-ee November 8, 2024 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants