Skip to content

Commit

Permalink
make OPinit to fit staking keeper interface
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Jan 4, 2024
1 parent 1308559 commit 890ca8e
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 30 deletions.
7 changes: 6 additions & 1 deletion x/opchild/ante/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ func (mfd MempoolFeeChecker) CheckTxFeeWithMinGasPrices(ctx sdk.Context, tx sdk.

minGasPrices := ctx.MinGasPrices()
if mfd.keeper != nil {
minGasPrices = CombinedMinGasPrices(minGasPrices, mfd.keeper.MinGasPrices(ctx))
paramsMinGasPrices, err := mfd.keeper.MinGasPrices(ctx)
if err != nil {
return nil, 0, err
}

minGasPrices = CombinedMinGasPrices(minGasPrices, paramsMinGasPrices)
}

if !minGasPrices.IsZero() {
Expand Down
6 changes: 4 additions & 2 deletions x/opchild/ante/fee_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package ante_test

import (
"context"

"github.com/initia-labs/OPinit/x/opchild/ante"

"cosmossdk.io/math"
Expand All @@ -15,8 +17,8 @@ type TestAnteKeeper struct {
minGasPrices sdk.DecCoins
}

func (k TestAnteKeeper) MinGasPrices(ctx sdk.Context) sdk.DecCoins {
return k.minGasPrices
func (k TestAnteKeeper) MinGasPrices(ctx context.Context) (sdk.DecCoins, error) {
return k.minGasPrices, nil
}

func (suite *AnteTestSuite) TestEnsureMempoolFees() {
Expand Down
21 changes: 6 additions & 15 deletions x/opchild/keeper/historical_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,8 @@ import (
)

// GetHistoricalInfo gets the historical info at a given height
func (k Keeper) GetHistoricalInfo(ctx context.Context, height int64) (*cosmostypes.HistoricalInfo, bool, error) {
historicalInfo, err := k.HistoricalInfos.Get(ctx, height)
if err != nil {
if errors.Is(err, collections.ErrNotFound) {
return nil, false, nil
}

return nil, false, err
}

return &historicalInfo, true, nil
func (k Keeper) GetHistoricalInfo(ctx context.Context, height int64) (cosmostypes.HistoricalInfo, error) {
return k.HistoricalInfos.Get(ctx, height)
}

// SetHistoricalInfo sets the historical info at a given height
Expand Down Expand Up @@ -51,13 +42,13 @@ func (k Keeper) TrackHistoricalInfo(ctx context.Context) error {
// over the historical entries starting from the most recent version to be pruned
// and then return at the first empty entry.
for i := sdkCtx.BlockHeight() - int64(entryNum); i >= 0; i-- {
_, found, err := k.GetHistoricalInfo(ctx, i)
if err != nil {
return err
} else if found {
_, err := k.GetHistoricalInfo(ctx, i)
if err == nil {
if err := k.DeleteHistoricalInfo(ctx, i); err != nil {
return err
}
} else if err != nil && !errors.Is(err, collections.ErrNotFound) {
return err
} else {
break
}
Expand Down
16 changes: 7 additions & 9 deletions x/opchild/keeper/historical_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper_test
import (
"testing"

"cosmossdk.io/collections"
"github.com/stretchr/testify/require"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -22,23 +23,20 @@ func Test_HistoricalInfo(t *testing.T) {
input.OPChildKeeper.TrackHistoricalInfo(sdkCtx.WithBlockHeight(2))
input.OPChildKeeper.TrackHistoricalInfo(sdkCtx.WithBlockHeight(3))

_, found, err := input.OPChildKeeper.GetHistoricalInfo(ctx, 1)
require.NoError(t, err)
require.False(t, found)
_, err = input.OPChildKeeper.GetHistoricalInfo(ctx, 1)
require.ErrorIs(t, err, collections.ErrNotFound)

historicalInfo, found, err := input.OPChildKeeper.GetHistoricalInfo(ctx, 2)
historicalInfo, err := input.OPChildKeeper.GetHistoricalInfo(ctx, 2)
require.NoError(t, err)
require.True(t, found)
require.Equal(t, cosmostypes.HistoricalInfo{
Header: sdkCtx.WithBlockHeight(2).BlockHeader(),
Valset: nil,
}, *historicalInfo)
}, historicalInfo)

historicalInfo, found, err = input.OPChildKeeper.GetHistoricalInfo(ctx, 3)
historicalInfo, err = input.OPChildKeeper.GetHistoricalInfo(ctx, 3)
require.NoError(t, err)
require.True(t, found)
require.Equal(t, cosmostypes.HistoricalInfo{
Header: sdkCtx.WithBlockHeight(3).BlockHeader(),
Valset: nil,
}, *historicalInfo)
}, historicalInfo)
}
2 changes: 2 additions & 0 deletions x/opchild/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
"github.com/initia-labs/OPinit/x/opchild/types"
)

var _ types.AnteKeeper = Keeper{}

type Keeper struct {
cdc codec.Codec
storeService corestoretypes.KVStoreService
Expand Down
4 changes: 2 additions & 2 deletions x/opchild/keeper/staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ func (k Keeper) HistoricalEntries(ctx context.Context) (uint32, error) {
}

// UnbondingTime - The time duration for unbonding
func (k Keeper) UnbondingTime(ctx context.Context) time.Duration {
return unbondingTime
func (k Keeper) UnbondingTime(ctx context.Context) (time.Duration, error) {
return unbondingTime, nil
}
4 changes: 3 additions & 1 deletion x/opchild/types/exported.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package types

import (
context "context"

tmprotocrypto "github.com/cometbft/cometbft/proto/tendermint/crypto"

"cosmossdk.io/math"
Expand All @@ -27,5 +29,5 @@ type ValidatorI interface {
}

type AnteKeeper interface {
MinGasPrices(ctx sdk.Context) sdk.DecCoins
MinGasPrices(ctx context.Context) (sdk.DecCoins, error)
}

0 comments on commit 890ca8e

Please sign in to comment.