Skip to content

Refund gas fees if concurrent TX fails#444

Merged
BrandonWeng merged 4 commits intomasterfrom
bweng-ctx-cache
Dec 3, 2022
Merged

Refund gas fees if concurrent TX fails#444
BrandonWeng merged 4 commits intomasterfrom
bweng-ctx-cache

Conversation

@BrandonWeng
Copy link
Contributor

@BrandonWeng BrandonWeng commented Dec 2, 2022

Describe your changes and provide context

We already reset the cacheKv (by not writing it) if the transactions fail, but we also need to reset the in-mem values to as those are different from the store

Previously we didn't clear the state so the deferred sends from the previous call carried over

Testing performed to validate your change

Unit tests

app/app.go Outdated

ctx.Logger().Error("Concurrent Execution failed, retrying with Synchronous")
// Clear the memcache context from the previous state as it failed, we no longer need to commit the data
ctx = ctx.WithContextMemCache(sdk.NewContextMemCache())
Copy link
Collaborator

Choose a reason for hiding this comment

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

just to confirm, is this the step that we need in order to reset the in memory state prior to rerunning txs synchronously?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this resets the state for the rerun of TXs synchronously

ctx sdk.Context,
txs [][]byte,
dependencyDag *acltypes.Dag,
processBlockConcurrentFunction ProcessBlockConcurrentFunction,
Copy link
Collaborator

Choose a reason for hiding this comment

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

why do we pass the the function instead of directly calling the ProcessBlockConcurrent? is it primarily for the mocking purposes in testing? if so, isn't that an antipattern? (I don't have strong feelings one way or the other on whether we keep it this way, just looking to better understand this & golang best practices.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this is mainly for testing, I was following this: https://www.myhatchpad.com/insight/mocking-techniques-for-go/

app/app_test.go Outdated
Denom: "test",
Amount: sdk.NewInt(1),
}))
// It should be reset if it fails to prevent any values from being written
Copy link
Contributor

Choose a reason for hiding this comment

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

is this comment correct? i think the function succeeds?

BrandonWeng added a commit to sei-protocol/sei-cosmos that referenced this pull request Dec 3, 2022
## Describe your changes and provide context
Adds a method for us to reset the cache instead of creating a new one.
Makes it easier for testing

## Testing performed to validate your change
For this PR: sei-protocol/sei-chain#444
@github-actions
Copy link

github-actions bot commented Dec 3, 2022

Code Coverage

Package Line Rate Complexity Health
github.com/sei-protocol/sei-chain/aclmapping/bank 100% 0
github.com/sei-protocol/sei-chain/aclmapping/dex 97% 0
github.com/sei-protocol/sei-chain/aclmapping/oracle 100% 0
github.com/sei-protocol/sei-chain/aclmapping/staking 82% 0
github.com/sei-protocol/sei-chain/aclmapping/tokenfactory 96% 0
github.com/sei-protocol/sei-chain/aclmapping/utils 0% 0
github.com/sei-protocol/sei-chain/aclmapping/wasm 83% 0
github.com/sei-protocol/sei-chain/app 52% 0
github.com/sei-protocol/sei-chain/app/antedecorators 89% 0
github.com/sei-protocol/sei-chain/oracle/price-feeder/config 85% 0
github.com/sei-protocol/sei-chain/oracle/price-feeder/oracle 73% 0
github.com/sei-protocol/sei-chain/oracle/price-feeder/oracle/provider 49% 0
github.com/sei-protocol/sei-chain/oracle/price-feeder/router/v1 45% 0
github.com/sei-protocol/sei-chain/store/whitelist/cachemulti 100% 0
github.com/sei-protocol/sei-chain/store/whitelist/kv 100% 0
github.com/sei-protocol/sei-chain/store/whitelist/multi 100% 0
github.com/sei-protocol/sei-chain/utils 46% 0
github.com/sei-protocol/sei-chain/utils/datastructures 90% 0
github.com/sei-protocol/sei-chain/x/dex 59% 0
github.com/sei-protocol/sei-chain/x/dex/cache 86% 0
github.com/sei-protocol/sei-chain/x/dex/client/cli/query 23% 0
github.com/sei-protocol/sei-chain/x/dex/contract 52% 0
github.com/sei-protocol/sei-chain/x/dex/exchange 89% 0
github.com/sei-protocol/sei-chain/x/dex/keeper 61% 0
github.com/sei-protocol/sei-chain/x/dex/keeper/abci 30% 0
github.com/sei-protocol/sei-chain/x/dex/keeper/msgserver 78% 0
github.com/sei-protocol/sei-chain/x/dex/keeper/query 82% 0
github.com/sei-protocol/sei-chain/x/dex/migrations 85% 0
github.com/sei-protocol/sei-chain/x/dex/types 1% 0
github.com/sei-protocol/sei-chain/x/dex/types/utils 100% 0
github.com/sei-protocol/sei-chain/x/dex/types/wasm 83% 0
github.com/sei-protocol/sei-chain/x/epoch 11% 0
github.com/sei-protocol/sei-chain/x/epoch/keeper 66% 0
github.com/sei-protocol/sei-chain/x/epoch/types 2% 0
github.com/sei-protocol/sei-chain/x/mint 0% 0
github.com/sei-protocol/sei-chain/x/mint/keeper 75% 0
github.com/sei-protocol/sei-chain/x/mint/simulation 95% 0
github.com/sei-protocol/sei-chain/x/mint/types 2% 0
github.com/sei-protocol/sei-chain/x/nitro/client/cli 45% 0
github.com/sei-protocol/sei-chain/x/nitro/keeper 80% 0
github.com/sei-protocol/sei-chain/x/nitro/replay 63% 0
github.com/sei-protocol/sei-chain/x/oracle 63% 0
github.com/sei-protocol/sei-chain/x/oracle/keeper 82% 0
github.com/sei-protocol/sei-chain/x/oracle/simulation 18% 0
github.com/sei-protocol/sei-chain/x/oracle/types 3% 0
github.com/sei-protocol/sei-chain/x/tokenfactory/keeper 85% 0
github.com/sei-protocol/sei-chain/x/tokenfactory/types 2% 0
Summary 15% (4926 / 33806) 0

@BrandonWeng BrandonWeng merged commit 0bb3c30 into master Dec 3, 2022
@BrandonWeng BrandonWeng deleted the bweng-ctx-cache branch December 3, 2022 22:20
masih pushed a commit that referenced this pull request Sep 29, 2025
## Describe your changes and provide context
Adds a method for us to reset the cache instead of creating a new one.
Makes it easier for testing

## Testing performed to validate your change
For this PR: #444
masih pushed a commit that referenced this pull request Sep 29, 2025
## Describe your changes and provide context
This adds CI to seiv2 branch

## Testing performed to validate your change
CI
masih pushed a commit that referenced this pull request Sep 30, 2025
## Describe your changes and provide context
Adds a method for us to reset the cache instead of creating a new one.
Makes it easier for testing

## Testing performed to validate your change
For this PR: #444
masih pushed a commit that referenced this pull request Sep 30, 2025
## Describe your changes and provide context
This adds CI to seiv2 branch

## Testing performed to validate your change
CI
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