Skip to content

Commit

Permalink
fix(dogfood): fix the issue #164 regarding the voting power not update (
Browse files Browse the repository at this point in the history
#169)

* update the dogfood AVS info stored in the AVS module when updating the parameter through dogfood module

* return a wrapped error regarding updating the AVS info when updating the dogfood parameter

* fix git leak lint error
fix lint error regarding the ante utils import
  • Loading branch information
TimmyExogenous authored Sep 3, 2024
1 parent 2b313c4 commit 1c687b3
Show file tree
Hide file tree
Showing 17 changed files with 89 additions and 54 deletions.
7 changes: 3 additions & 4 deletions app/ante/cosmos/txsize_gas.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cosmos

import (
"github.com/ExocoreNetwork/exocore/app/ante/utils"
anteutils "github.com/ExocoreNetwork/exocore/app/ante/utils"
"github.com/cosmos/cosmos-sdk/codec/legacy"
"github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
Expand Down Expand Up @@ -40,8 +39,8 @@ func (cgts ConsumeTxSizeGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim

// Skip gas consumption if tx is an OracleCreatePriceTx
if anteutils.IsOracleCreatePriceTx(tx) {
if len(ctx.TxBytes()) > utils.TxSizeLimit {
return ctx, sdkerrors.ErrTxTooLarge.Wrapf("oracle create-price tx has exceeds size limit, limit:%d, got:%d", utils.TxSizeLimit, len(ctx.TxBytes()))
if len(ctx.TxBytes()) > anteutils.TxSizeLimit {
return ctx, sdkerrors.ErrTxTooLarge.Wrapf("oracle create-price tx has exceeds size limit, limit:%d, got:%d", anteutils.TxSizeLimit, len(ctx.TxBytes()))
}
return next(ctx, tx, simulate)
}
Expand Down Expand Up @@ -71,7 +70,7 @@ func (cgts ConsumeTxSizeGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim

// use placeholder simSecp256k1Pubkey if sig is nil
if acc == nil || acc.GetPubKey() == nil {
pubkey = simSecp256k1Pubkey
pubkey = simSecp256k1Pubkey //gitleaks:allow
} else {
pubkey = acc.GetPubKey()
}
Expand Down
1 change: 0 additions & 1 deletion precompiles/avs/avs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ func (suite *AVSManagerPrecompileSuite) TestRegisterAVS() {
for _, tc := range testcases {
tc := tc
suite.Run(tc.name, func() {

baseFee := suite.App.FeeMarketKeeper.GetBaseFee(suite.Ctx)

// malleate testcase
Expand Down
10 changes: 5 additions & 5 deletions precompiles/avs/query_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package avs_test

import (
sdkmath "cosmossdk.io/math"
"fmt"
"math/big"
"time"

sdkmath "cosmossdk.io/math"

avsManagerPrecompile "github.com/ExocoreNetwork/exocore/precompiles/avs"
exocmn "github.com/ExocoreNetwork/exocore/precompiles/common"
assetstype "github.com/ExocoreNetwork/exocore/x/assets/types"
operatorKeeper "github.com/ExocoreNetwork/exocore/x/operator/keeper"
"github.com/ExocoreNetwork/exocore/x/operator/types"
"github.com/ethereum/go-ethereum/common"
"math/big"
"time"

"github.com/ethereum/go-ethereum/core/vm"
)
Expand Down Expand Up @@ -107,7 +109,6 @@ func (suite *AVSManagerPrecompileSuite) TestGetOptedInOperatorAccAddrs() {
suite.Require().NoError(err, "failed to unpack output", err)
suite.Require().Equal(1, len(out))
suite.Require().Equal(operatorAddress, out[0])

},
100000,
false,
Expand Down Expand Up @@ -197,7 +198,6 @@ func (suite *AVSManagerPrecompileSuite) TestAVSUSDValue() {
err := s.precompile.UnpackIntoInterface(&out, avsManagerPrecompile.MethodGetAVSUSDValue, bz)
s.Require().NoError(err, "failed to unpack output", err)
s.Require().Equal(expectedUSDvalue.BigInt(), out)

},
100000,
false,
Expand Down
3 changes: 2 additions & 1 deletion precompiles/avs/setup_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package avs_test

import (
"testing"

sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
"testing"

"github.com/ExocoreNetwork/exocore/precompiles/avs"
"github.com/ExocoreNetwork/exocore/testutil"
Expand Down
14 changes: 11 additions & 3 deletions precompiles/avs/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (p Precompile) RegisterAVS(
avsParams.AvsAddress = contract.CallerAddress.String()
avsParams.Action = avskeeper.RegisterAction
// Finally, update the AVS information in the keeper.
err = p.avsKeeper.AVSInfoUpdate(ctx, avsParams)
err = p.avsKeeper.UpdateAVSInfo(ctx, avsParams)
if err != nil {
fmt.Println("Failed to update AVS info", err)
return nil, err
Expand Down Expand Up @@ -81,7 +81,7 @@ func (p Precompile) DeregisterAVS(
// validates that this is owner
avsParams.CallerAddress = sdk.AccAddress(origin[:]).String()

err := p.avsKeeper.AVSInfoUpdate(ctx, avsParams)
err := p.avsKeeper.UpdateAVSInfo(ctx, avsParams)
if err != nil {
return nil, err
}
Expand All @@ -105,7 +105,15 @@ func (p Precompile) UpdateAVS(
avsParams.AvsAddress = contract.CallerAddress.String()
avsParams.CallerAddress = sdk.AccAddress(origin[:]).String()
avsParams.Action = avskeeper.UpdateAction
err = p.avsKeeper.AVSInfoUpdate(ctx, avsParams)
previousAVSInfo, err := p.avsKeeper.GetAVSInfo(ctx, avsParams.AvsAddress)
if err != nil {
return nil, err
}
// If avs UpdateAction check CallerAddress
if !slices.Contains(previousAVSInfo.Info.AvsOwnerAddress, avsParams.CallerAddress) {
return nil, fmt.Errorf("this caller not qualified to update %s", avsParams.CallerAddress)
}
err = p.avsKeeper.UpdateAVSInfo(ctx, avsParams)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions precompiles/avs/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (suite *AVSManagerPrecompileSuite) prepare() {
}

func (suite *AVSManagerPrecompileSuite) prepareAvs(assetIDs []string) {
err := suite.App.AVSManagerKeeper.AVSInfoUpdate(suite.Ctx, &avstypes.AVSRegisterOrDeregisterParams{
err := suite.App.AVSManagerKeeper.UpdateAVSInfo(suite.Ctx, &avstypes.AVSRegisterOrDeregisterParams{
Action: avskeeper.RegisterAction,
EpochIdentifier: epochstypes.HourEpochID,
AvsAddress: suite.avsAddr,
Expand Down Expand Up @@ -173,7 +173,6 @@ func (suite *AVSManagerPrecompileSuite) TestOptInList() {
suite.NoError(err)

suite.Contains(avsList, suite.avsAddr)

}

func (suite *AVSManagerPrecompileSuite) TestOptOut() {
Expand Down
2 changes: 2 additions & 0 deletions precompiles/delegation/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func (p Precompile) AssociateOperatorWithStaker(
if !ok || staker == nil {
return nil, fmt.Errorf(exocmn.ErrContractInputParaOrType, 1, "[]byte", args[1])
}
// #nosec G115
if uint32(len(staker)) < clientChainAddrLength {
return nil, fmt.Errorf(exocmn.ErrInvalidAddrLength, len(staker), clientChainAddrLength)
}
Expand Down Expand Up @@ -176,6 +177,7 @@ func (p Precompile) DissociateOperatorFromStaker(
if !ok || staker == nil {
return nil, fmt.Errorf(exocmn.ErrContractInputParaOrType, 1, "[]byte", args[1])
}
// #nosec G115
if uint32(len(staker)) < clientChainAddrLength {
return nil, fmt.Errorf(exocmn.ErrInvalidAddrLength, len(staker), clientChainAddrLength)
}
Expand Down
1 change: 0 additions & 1 deletion precompiles/testutil/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ func CheckLogs(logArgs LogCheckArgs) error {
int64(float64(logArgs.Res.GasUsed)/float64(logArgs.Res.GasWanted)*100),
)
}
// nolint
if err := CheckVMError(logArgs.Res, logArgs.ErrContains); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion x/avs/keeper/avs.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (k Keeper) RegisterAVSWithChainID(
params.AvsAddress = avsAddr.String()
params.Action = RegisterAction

if err := k.AVSInfoUpdate(ctx, params); err != nil {
if err := k.UpdateAVSInfo(ctx, params); err != nil {
return common.Address{}, err
}
return avsAddr, nil
Expand Down
18 changes: 8 additions & 10 deletions x/avs/keeper/avs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@ func (suite *AVSTestSuite) TestAVS() {
suite.Equal(found, true)
suite.Equal(epoch.CurrentEpoch, int64(2))
suite.CommitAfter(48*time.Hour + time.Nanosecond)

}

func (suite *AVSTestSuite) TestAVSInfoUpdate_Register() {
func (suite *AVSTestSuite) TestUpdateAVSInfo_Register() {
avsName, avsAddres, slashAddress, rewardAddress := "avsTest", "exo18cggcpvwspnd5c6ny8wrqxpffj5zmhklprtnph", "0xDF907c29719154eb9872f021d21CAE6E5025d7aB", "0xDF907c29719154eb9872f021d21CAE6E5025d7aB"
avsOwnerAddress := []string{"exo13h6xg79g82e2g2vhjwg7j4r2z2hlncelwutkjr", "exo13h6xg79g82e2g2vhjwg7j4r2z2hlncelwutkj1", "exo13h6xg79g82e2g2vhjwg7j4r2z2hlncelwutkj2"}
assetID := []string{"11", "22", "33"}
Expand All @@ -77,20 +76,20 @@ func (suite *AVSTestSuite) TestAVSInfoUpdate_Register() {
EpochIdentifier: epochstypes.DayEpochID,
}

err := suite.App.AVSManagerKeeper.AVSInfoUpdate(suite.Ctx, avsParams)
err := suite.App.AVSManagerKeeper.UpdateAVSInfo(suite.Ctx, avsParams)
suite.NoError(err)

info, err := suite.App.AVSManagerKeeper.GetAVSInfo(suite.Ctx, avsAddres)

suite.NoError(err)
suite.Equal(avsAddres, info.GetInfo().AvsAddress)

err = suite.App.AVSManagerKeeper.AVSInfoUpdate(suite.Ctx, avsParams)
err = suite.App.AVSManagerKeeper.UpdateAVSInfo(suite.Ctx, avsParams)
suite.Error(err)
suite.Contains(err.Error(), types.ErrAlreadyRegistered.Error())
}

func (suite *AVSTestSuite) TestAVSInfoUpdate_DeRegister() {
func (suite *AVSTestSuite) TestUpdateAVSInfo_DeRegister() {
// Test case setup
avsName, avsAddres, slashAddress := "avsTest", suite.avsAddress.String(), "exo13h6xg79g82e2g2vhjwg7j4r2z2hlncelwutash"
avsOwnerAddress := []string{"exo13h6xg79g82e2g2vhjwg7j4r2z2hlncelwutkjr", "exo13h6xg79g82e2g2vhjwg7j4r2z2hlncelwutkj1", "exo13h6xg79g82e2g2vhjwg7j4r2z2hlncelwutkj2"}
Expand All @@ -108,26 +107,26 @@ func (suite *AVSTestSuite) TestAVSInfoUpdate_DeRegister() {
EpochIdentifier: epochstypes.DayEpochID,
}

err := suite.App.AVSManagerKeeper.AVSInfoUpdate(suite.Ctx, avsParams)
err := suite.App.AVSManagerKeeper.UpdateAVSInfo(suite.Ctx, avsParams)
suite.Error(err)
suite.Contains(err.Error(), types.ErrUnregisterNonExistent.Error())

avsParams.Action = avstypes.RegisterAction
err = suite.App.AVSManagerKeeper.AVSInfoUpdate(suite.Ctx, avsParams)
err = suite.App.AVSManagerKeeper.UpdateAVSInfo(suite.Ctx, avsParams)
suite.NoError(err)
info, err := suite.App.AVSManagerKeeper.GetAVSInfo(suite.Ctx, avsAddres)
suite.Equal(avsAddres, info.GetInfo().AvsAddress)

avsParams.Action = avstypes.DeRegisterAction
avsParams.CallerAddress = "exo13h6xg79g82e2g2vhjwg7j4r2z2hlncelwutkjr"
err = suite.App.AVSManagerKeeper.AVSInfoUpdate(suite.Ctx, avsParams)
err = suite.App.AVSManagerKeeper.UpdateAVSInfo(suite.Ctx, avsParams)
suite.NoError(err)
info, err = suite.App.AVSManagerKeeper.GetAVSInfo(suite.Ctx, avsAddres)
suite.Error(err)
suite.Contains(err.Error(), types.ErrNoKeyInTheStore.Error())
}

func (suite *AVSTestSuite) TestAVSInfoUpdateWithOperator_Register() {
func (suite *AVSTestSuite) TestUpdateAVSInfoWithOperator_Register() {
avsAddress := suite.avsAddress
operatorAddress := sdk.AccAddress(utiltx.GenerateAddress().Bytes()).String()

Expand Down Expand Up @@ -157,5 +156,4 @@ func (suite *AVSTestSuite) TestAVSInfoUpdateWithOperator_Register() {

err = suite.App.AVSManagerKeeper.OperatorOptAction(suite.Ctx, operatorParams)
suite.NoError(err)

}
16 changes: 6 additions & 10 deletions x/avs/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (k Keeper) GetOperatorKeeper() types.OperatorKeeper {
return k.operatorKeeper
}

func (k Keeper) AVSInfoUpdate(ctx sdk.Context, params *types.AVSRegisterOrDeregisterParams) error {
func (k Keeper) UpdateAVSInfo(ctx sdk.Context, params *types.AVSRegisterOrDeregisterParams) error {
avsInfo, _ := k.GetAVSInfo(ctx, params.AvsAddress)
action := params.Action
epochIdentifier := params.EpochIdentifier
Expand Down Expand Up @@ -123,15 +123,11 @@ func (k Keeper) AVSInfoUpdate(ctx sdk.Context, params *types.AVSRegisterOrDeregi
if avsInfo == nil {
return errorsmod.Wrap(types.ErrUnregisterNonExistent, fmt.Sprintf("the avsaddress is :%s", params.AvsAddress))
}
// TODO: The AvsUnbondingPeriod is used for undelegation, but this check currently blocks updates to AVS information. Remove this check to allow AVS updates, while detailed control mechanisms for updates should be considered and implemented in the future.
// If avs UpdateAction check UnbondingPeriod
// #nosec G115
if int64(avsInfo.Info.AvsUnbondingPeriod) < (epoch.CurrentEpoch - int64(avsInfo.GetInfo().StartingEpoch)) {
return errorsmod.Wrap(types.ErrUnbondingPeriod, fmt.Sprintf("not qualified to deregister %s", avsInfo))
}
// If avs UpdateAction check CallerAddress
if !slices.Contains(avsInfo.Info.AvsOwnerAddress, params.CallerAddress) {
return errorsmod.Wrap(types.ErrCallerAddressUnauthorized, fmt.Sprintf("this caller not qualified to update %s", params.CallerAddress))
}
/* if int64(avsInfo.Info.AvsUnbondingPeriod) < (epoch.CurrentEpoch - int64(avsInfo.GetInfo().StartingEpoch)) {
return errorsmod.Wrap(types.ErrUnbondingPeriod, fmt.Sprintf("not qualified to update %s", avsInfo))
}*/
avs := avsInfo.Info

if params.AvsName != "" {
Expand Down Expand Up @@ -244,7 +240,7 @@ func (k Keeper) OperatorOptAction(ctx sdk.Context, params *OperatorOptParams) er
}

if !k.operatorKeeper.IsOperator(ctx, opAccAddr) {
return errorsmod.Wrap(delegationtypes.ErrOperatorNotExist, fmt.Sprintf("AVSInfoUpdate: invalid operator address:%s", operatorAddress))
return errorsmod.Wrap(delegationtypes.ErrOperatorNotExist, fmt.Sprintf("UpdateAVSInfo: invalid operator address:%s", operatorAddress))
}

f, err := k.IsAVS(ctx, params.AvsAddress)
Expand Down
4 changes: 2 additions & 2 deletions x/dogfood/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func CmdUpdateParams() *cobra.Command {
f.Uint32(
FlagHistoricalEntries, 0, "The number of historical entries stored for IBC",
)
f.StringArray(
f.StringSlice(
FlagAssetIDs, []string{}, "The asset ids to consider for the module",
)
f.Uint64(
Expand Down Expand Up @@ -101,7 +101,7 @@ func newBuildUpdateParamsMsg(
// #nosec G703 // this only errors if the flag isn't defined.
historicalEntries, _ := fs.GetUint32(FlagHistoricalEntries)
// #nosec G703 // this only errors if the flag isn't defined.
assetIDs, _ := fs.GetStringArray(FlagAssetIDs)
assetIDs, _ := fs.GetStringSlice(FlagAssetIDs)
// #nosec G703 // this only errors if the flag isn't defined.
minSelfDelegation, _ := fs.GetUint64(FlagMinSelfDelegation)
msg := &types.MsgUpdateParams{
Expand Down
26 changes: 13 additions & 13 deletions x/dogfood/keeper/impl_epochs_hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ func (suite *KeeperTestSuite) TestDifferentEpochOperations() {
errValues: []error{nil},
expUpdatesCount: []int{1},
powers: [][]int64{
[]int64{amountUSD},
{amountUSD},
},
validatorKeys: []operatortypes.WrappedConsKey{oldKey},
ultimateKey: oldKey,
Expand All @@ -320,7 +320,7 @@ func (suite *KeeperTestSuite) TestDifferentEpochOperations() {
errValues: []error{operatortypes.ErrNotOptedIn},
expUpdatesCount: []int{0},
powers: [][]int64{
[]int64{},
{},
},
validatorKeys: []operatortypes.WrappedConsKey{nil},
ultimateKey: nil,
Expand All @@ -334,7 +334,7 @@ func (suite *KeeperTestSuite) TestDifferentEpochOperations() {
errValues: []error{operatortypes.ErrNotOptedIn},
expUpdatesCount: []int{0},
powers: [][]int64{
[]int64{},
{},
},
validatorKeys: []operatortypes.WrappedConsKey{nil},
ultimateKey: nil,
Expand All @@ -348,8 +348,8 @@ func (suite *KeeperTestSuite) TestDifferentEpochOperations() {
errValues: []error{nil, nil},
expUpdatesCount: []int{1, 2},
powers: [][]int64{
[]int64{amountUSD},
[]int64{amountUSD, 0},
{amountUSD},
{amountUSD, 0},
},
validatorKeys: []operatortypes.WrappedConsKey{
oldKey, newKey,
Expand All @@ -365,8 +365,8 @@ func (suite *KeeperTestSuite) TestDifferentEpochOperations() {
errValues: []error{nil, nil},
expUpdatesCount: []int{1, 1},
powers: [][]int64{
[]int64{amountUSD},
[]int64{0},
{amountUSD},
{0},
},
validatorKeys: []operatortypes.WrappedConsKey{oldKey, nil},
ultimateKey: nil,
Expand All @@ -380,9 +380,9 @@ func (suite *KeeperTestSuite) TestDifferentEpochOperations() {
errValues: []error{nil, nil, nil},
expUpdatesCount: []int{1, 2, 1},
powers: [][]int64{
[]int64{amountUSD},
[]int64{amountUSD, 0},
[]int64{0},
{amountUSD},
{amountUSD, 0},
{0},
},
validatorKeys: []operatortypes.WrappedConsKey{oldKey, newKey, nil},
ultimateKey: nil,
Expand All @@ -396,9 +396,9 @@ func (suite *KeeperTestSuite) TestDifferentEpochOperations() {
errValues: []error{nil, nil, operatortypes.ErrAlreadyRemovingKey},
expUpdatesCount: []int{1, 1, 0},
powers: [][]int64{
[]int64{amountUSD},
[]int64{0},
[]int64{},
{amountUSD},
{0},
{},
},
validatorKeys: []operatortypes.WrappedConsKey{oldKey, nil, nil},
ultimateKey: nil,
Expand Down
Loading

0 comments on commit 1c687b3

Please sign in to comment.