Skip to content

Commit

Permalink
Fixing Bug 6856 (#6857)
Browse files Browse the repository at this point in the history
  • Loading branch information
joeabbey authored and ValarDragon committed Nov 10, 2023
1 parent c7f2795 commit 54faf8f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
2 changes: 2 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ func NewOsmosisApp(
}

app.homePath = homePath
dataDir := filepath.Join(homePath, "data")
wasmDir := filepath.Join(homePath, "wasm")
wasmConfig, err := wasm.ReadWasmConfig(appOpts)
// Uncomment this for debugging contracts. In the future this could be made into a param passed by the tests
Expand All @@ -285,6 +286,7 @@ func NewOsmosisApp(
encodingConfig,
bApp,
maccPerms,
dataDir,
wasmDir,
wasmConfig,
wasmEnabledProposals,
Expand Down
2 changes: 2 additions & 0 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ func (appKeepers *AppKeepers) InitNormalKeepers(
encodingConfig appparams.EncodingConfig,
bApp *baseapp.BaseApp,
maccPerms map[string][]string,
dataDir string,
wasmDir string,
wasmConfig wasm.Config,
wasmEnabledProposals []wasm.ProposalType,
Expand Down Expand Up @@ -402,6 +403,7 @@ func (appKeepers *AppKeepers) InitNormalKeepers(
appKeepers.GAMMKeeper,
appKeepers.ProtoRevKeeper,
appKeepers.DistrKeeper,
dataDir,
)
appKeepers.TxFeesKeeper = &txFeesKeeper
appKeepers.ProtoRevKeeper.SetTxFeesKeeper(appKeepers.TxFeesKeeper)
Expand Down
5 changes: 5 additions & 0 deletions x/txfees/keeper/feedecorator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"fmt"
"path/filepath"

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -27,6 +28,10 @@ type MempoolFeeDecorator struct {
}

func NewMempoolFeeDecorator(txFeesKeeper Keeper, opts types.MempoolFeeOptions) MempoolFeeDecorator {
if opts.Mempool1559Enabled {
mempool1559.CurEipState.BackupFilePath = filepath.Join(txFeesKeeper.dataDir, mempool1559.BackupFilename)
}

return MempoolFeeDecorator{
TxFeesKeeper: txFeesKeeper,
Opts: opts,
Expand Down
3 changes: 3 additions & 0 deletions x/txfees/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Keeper struct {
spotPriceCalculator types.SpotPriceCalculator
protorevKeeper types.ProtorevKeeper
distributionKeeper types.DistributionKeeper
dataDir string
}

var _ types.TxFeesKeeper = (*Keeper)(nil)
Expand All @@ -34,6 +35,7 @@ func NewKeeper(
spotPriceCalculator types.SpotPriceCalculator,
protorevKeeper types.ProtorevKeeper,
distributionKeeper types.DistributionKeeper,
dataDir string,
) Keeper {
return Keeper{
accountKeeper: accountKeeper,
Expand All @@ -43,6 +45,7 @@ func NewKeeper(
spotPriceCalculator: spotPriceCalculator,
protorevKeeper: protorevKeeper,
distributionKeeper: distributionKeeper,
dataDir: dataDir,
}
}

Expand Down
11 changes: 6 additions & 5 deletions x/txfees/keeper/mempool-1559/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ var (
)

const (
BackupFile = "eip1559state.json"
BackupFilename = "eip1559state.json"
)

// EipState tracks the current base fee and totalGasWantedThisBlock
// this structure is never written to state
type EipState struct {
lastBlockHeight int64
totalGasWantedThisBlock int64

CurBaseFee osmomath.Dec `json:"cur_base_fee"`
BackupFilePath string
CurBaseFee osmomath.Dec `json:"cur_base_fee"`
}

// CurEipState is a global variable used in the BeginBlock, EndBlock and
Expand All @@ -73,6 +73,7 @@ type EipState struct {
var CurEipState = EipState{
lastBlockHeight: 0,
totalGasWantedThisBlock: 0,
BackupFilePath: "",
CurBaseFee: sdk.NewDec(0),
}

Expand Down Expand Up @@ -156,7 +157,7 @@ func (e *EipState) tryPersist() {
return
}

err = os.WriteFile(BackupFile, bz, 0644)
err = os.WriteFile(e.BackupFilePath, bz, 0644)
if err != nil {
fmt.Println("Error writing eip1559 state", err)
return
Expand All @@ -166,7 +167,7 @@ func (e *EipState) tryPersist() {
// tryLoad reads eip1559 state from disk and initializes the CurEipState to
// the previous state when a node is restarted
func (e *EipState) tryLoad() osmomath.Dec {
bz, err := os.ReadFile(BackupFile)
bz, err := os.ReadFile(e.BackupFilePath)
if err != nil {
fmt.Println("Error reading eip1559 state", err)
fmt.Println("Setting eip1559 state to default value", MinBaseFee)
Expand Down

0 comments on commit 54faf8f

Please sign in to comment.