Skip to content

Commit

Permalink
refactor: overwrite ArbitrageMinGasPrice config from .005 to 0.1 (bac…
Browse files Browse the repository at this point in the history
…kport #7368) (#7383)

* refactor: overwrite ArbitrageMinGasPrice config from .005 to 0.1 (#7368)

Closes: #XXX

## What is the purpose of the change

To address the failing arbitrage spam taking up block space, we will increase [arbitrage-min-gas-fee](https://github.com/osmosis-labs/osmosis/blob/3aaf5d117f96df0092b0375d0c8de0a12850d092/cmd/osmosisd/cmd/root.go#L540) to be near the order of magnitude of 0.1 OSMO.

CL Swap is around 600K gas wanted and 340K gas used. Let's assume a middle ground of 450K and aim to have the arb pay approximately 0.05 OSMO.
```
0.045 = 450_000 * 0.1 / 10**6
```
 As a result, 0.1 is an appropriate choice.

## Testing and Verifying

Tested the following vectors:
- new config
- does no overwrite other values
- old value is "0.005" -> overwritten
- old value is ".005" -> overwritten
- old value is something else -> does not change

## Documentation and Release Note

  - [ ] Does this pull request introduce a new feature or user-facing behavior changes?
  - [ ] Changelog entry added to `Unreleased` section of `CHANGELOG.md`?

Where is the change documented?
  - [ ] Specification (`x/{module}/README.md`)
  - [ ] Osmosis documentation site
  - [ ] Code comments?
  - [ ] N/A

(cherry picked from commit af1ed8c)

* changelog

---------

Co-authored-by: Roman <roman@osmosis.team>
  • Loading branch information
mergify[bot] and p0mvn authored Feb 1, 2024
1 parent a467e7c commit 7af3665
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Config

* [#7368](https://github.com/osmosis-labs/osmosis/pull/7368) Overwrite ArbitrageMinGasPriceconfig from .005 to 0.1.

## v22.0.1

### Bug Fixes
Expand Down
90 changes: 87 additions & 3 deletions cmd/osmosisd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ type DenomUnitMap struct {
}

const (
mempoolConfigName = "osmosis-mempool"
arbitrageMinGasFeeConfigName = "arbitrage-min-gas-fee"
oldArbitrageMinGasFeeValue = ".005"
newArbitrageMinGasFeeValue = "0.1"

consensusConfigName = "consensus"
timeoutCommitConfigName = "timeout_commit"
)
Expand Down Expand Up @@ -477,6 +482,79 @@ func overwriteConfigTomlValues(serverCtx *server.Context) error {
return nil
}

// overwrites app.toml values. Returns error if app.toml does not exist
//
// Currently, overwrites arbitrage-min-gas-fee value in app.toml if it is set to 0.005. Similarly,
// overwrites the given viper config value.
// Silently handles and skips any error/panic due to write permission issues.
// No-op otherwise.
func overwriteAppTomlValues(serverCtx *server.Context) error {
// Get paths to config.toml and config parent directory
rootDir := serverCtx.Viper.GetString(tmcli.HomeFlag)

configParentDirPath := filepath.Join(rootDir, "config")
configFilePath := filepath.Join(configParentDirPath, "app.toml")

fileInfo, err := os.Stat(configFilePath)
if err != nil {
return fmt.Errorf("failed to read in %s: %w", configFilePath, err)
} else {
// app.toml exists

// Get setting
currentArbitrageMinGasFeeValue := serverCtx.Viper.Get(mempoolConfigName + "." + arbitrageMinGasFeeConfigName)

// .x format at 0.x format are both valid.
if currentArbitrageMinGasFeeValue == oldArbitrageMinGasFeeValue || currentArbitrageMinGasFeeValue == "0"+oldArbitrageMinGasFeeValue {
// Set new value in viper
serverCtx.Viper.Set(mempoolConfigName+"."+arbitrageMinGasFeeConfigName, newArbitrageMinGasFeeValue)

defer func() {
if err := recover(); err != nil {
fmt.Printf("failed to write to %s: %s\n", configFilePath, err)
}
}()

// Check if the file is writable
if fileInfo.Mode()&os.FileMode(0200) != 0 {
// Read the entire content of the file
content, err := os.ReadFile(configFilePath)
if err != nil {
return err
}

// Convert the content to a string
fileContent := string(content)

// Find the index of the search line
index := strings.Index(fileContent, arbitrageMinGasFeeConfigName)
if index == -1 {
return fmt.Errorf("search line not found in the file")
}

// Find the opening and closing quotes
openQuoteIndex := strings.Index(fileContent[index:], "\"")
openQuoteIndex += index

closingQuoteIndex := strings.Index(fileContent[openQuoteIndex+1:], "\"")
closingQuoteIndex += openQuoteIndex + 1

// Replace the old value with the new value
newFileContent := fileContent[:openQuoteIndex+1] + newArbitrageMinGasFeeValue + fileContent[closingQuoteIndex:]

// Write the modified content back to the file
err = os.WriteFile(configFilePath, []byte(newFileContent), 0644)
if err != nil {
return err
}
} else {
fmt.Println("app.toml is not writable. Cannot apply update. Please consder manually changing arbitrage-min-gas-fee to " + newArbitrageMinGasFeeValue)
}
}
}
return nil
}

func getHomeEnvironment() string {
envPath := filepath.Join(osmosis.DefaultNodeHome, ".env")

Expand Down Expand Up @@ -519,7 +597,7 @@ func initAppConfig() (string, interface{}) {
// 128MB IAVL cache
srvCfg.IAVLCacheSize = 781250

memCfg := OsmosisMempoolConfig{ArbitrageMinGasPrice: "0.01"}
memCfg := OsmosisMempoolConfig{ArbitrageMinGasPrice: "0.1"}

sqsConfig := sqs.DefaultConfig

Expand All @@ -536,8 +614,8 @@ func initAppConfig() (string, interface{}) {
max-gas-wanted-per-tx = "25000000"
# This is the minimum gas fee any arbitrage tx should have, denominated in uosmo per gas
# Default value of ".005" then means that a tx with 1 million gas costs (.005 uosmo/gas) * 1_000_000 gas = .005 osmo
arbitrage-min-gas-fee = ".005"
# Default value of ".1" then means that a tx with 1 million gas costs (.1 uosmo/gas) * 1_000_000 gas = .1 osmo
arbitrage-min-gas-fee = ".1"
# This is the minimum gas fee any tx with high gas demand should have, denominated in uosmo per gas
# Default value of ".0025" then means that a tx with 1 million gas costs (.0025 uosmo/gas) * 1_000_000 gas = .0025 osmo
Expand Down Expand Up @@ -619,6 +697,12 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
return err
}

// overwrite app.toml values
err = overwriteAppTomlValues(serverCtx)
if err != nil {
return err
}

return startRunE(cmd, args)
}

Expand Down

0 comments on commit 7af3665

Please sign in to comment.