diff --git a/app/app.go b/app/app.go index c69e14b3..64513892 100644 --- a/app/app.go +++ b/app/app.go @@ -429,7 +429,6 @@ func New( app.BankKeeper, app.DistrKeeper, app.StakingKeeper, - app.GasEstimateKeeper, distrtypes.ModuleName, cast.ToBool(appOpts.Get("telemetry.enabled")), authtypes.NewModuleAddress(govtypes.ModuleName).String(), diff --git a/x/oracle/abci/proposal.go b/x/oracle/abci/proposal.go index 5bc1db7c..42892d7a 100644 --- a/x/oracle/abci/proposal.go +++ b/x/oracle/abci/proposal.go @@ -73,14 +73,9 @@ func (h *ProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHandler { return &cometabci.ResponsePrepareProposal{Txs: make([][]byte, 0)}, err } - medianGasEstimates, err := h.generateMedianGasEstimates(ctx, req.LocalLastCommit) - if err != nil { - return &cometabci.ResponsePrepareProposal{Txs: make([][]byte, 0)}, err - } injectedVoteExtTx := oracletypes.InjectedVoteExtensionTx{ ExchangeRateVotes: exchangeRateVotes, ExtendedCommitInfo: extendedCommitInfoBz, - GasEstimateMedians: medianGasEstimates, } bz, err := injectedVoteExtTx.Marshal() @@ -176,14 +171,6 @@ func (h *ProposalHandler) ProcessProposalHandler() sdk.ProcessProposalHandler { if err := h.verifyExchangeRateVotes(injectedVoteExtTx.ExchangeRateVotes, exchangeRateVotes); err != nil { return &cometabci.ResponseProcessProposal{Status: cometabci.ResponseProcessProposal_REJECT}, err } - // Verify the proposer's gas estimation by computing the same median. - gasEstimateMedians, err := h.generateMedianGasEstimates(ctx, extendedCommitInfo) - if err != nil { - return &cometabci.ResponseProcessProposal{Status: cometabci.ResponseProcessProposal_REJECT}, err - } - if err := h.verifyMedianGasEstimations(injectedVoteExtTx.GasEstimateMedians, gasEstimateMedians); err != nil { - return &cometabci.ResponseProcessProposal{Status: cometabci.ResponseProcessProposal_REJECT}, err - } } h.logger.Info( @@ -266,97 +253,3 @@ func (h *ProposalHandler) verifyExchangeRateVotes( return nil } - -func (h *ProposalHandler) generateMedianGasEstimates( - ctx sdk.Context, - ci cometabci.ExtendedCommitInfo, -) ([]oracletypes.GasEstimate, error) { - gasEstimates := []oracletypes.GasEstimate{} - - for _, vote := range ci.Votes { - if vote.BlockIdFlag != cmtproto.BlockIDFlagCommit { - continue - } - - var valConsAddr sdk.ConsAddress - if err := valConsAddr.Unmarshal(vote.Validator.Address); err != nil { - h.logger.Error( - "failed to unmarshal validator consensus address", - "err", err, - ) - return gasEstimates, err - } - val, err := h.stakingKeeper.GetValidatorByConsAddr(ctx, valConsAddr) - if err != nil { - h.logger.Error( - "failed to get consensus validator from staking keeper", - "err", err, - ) - return gasEstimates, err - } - _, err = sdk.ValAddressFromBech32(val.OperatorAddress) - if err != nil { - return gasEstimates, err - } - } - - networks := []string{} - // get contracts on registry list - params := h.oracleKeeper.GasEstimateKeeper.GetParams(ctx) - for _, contract := range params.ContractRegistry { - networks = append(networks, contract.Network) - } - - for _, network := range networks { - networkEstimates := []oracletypes.GasEstimate{} - - for _, vote := range ci.Votes { - var voteExt oracletypes.OracleVoteExtension - if err := voteExt.Unmarshal(vote.VoteExtension); err != nil { - h.logger.Error( - "failed to decode vote extension", - "err", err, - ) - continue - } - - for _, estimate := range voteExt.GasEstimates { - if estimate.Network == network { - networkEstimates = append(networkEstimates, estimate) - } - } - } - - median, err := calculateMedian(networkEstimates) - if err != nil { - continue - } - gasEstimates = append(gasEstimates, median) - } - - return gasEstimates, nil -} - -func (h *ProposalHandler) verifyMedianGasEstimations( - injectedEstimates []oracletypes.GasEstimate, - generatedEstimates []oracletypes.GasEstimate, -) error { - if len(injectedEstimates) != len(generatedEstimates) { - return oracletypes.ErrNonEqualInjVotesLen - } - - for i := range injectedEstimates { - injectedEstimate := injectedEstimates[i] - generatedEstimate := generatedEstimates[i] - - if injectedEstimate.Network != generatedEstimate.Network { - return oracletypes.ErrNonEqualInjVotesRates - } - - if injectedEstimate.GasEstimation != generatedEstimate.GasEstimation { - return oracletypes.ErrNonEqualInjVotesRates - } - } - - return nil -} diff --git a/x/oracle/abci/voteextension.go b/x/oracle/abci/voteextension.go index e4da6a30..5f864cc2 100644 --- a/x/oracle/abci/voteextension.go +++ b/x/oracle/abci/voteextension.go @@ -7,7 +7,6 @@ import ( cometabci "github.com/cometbft/cometbft/abci/types" sdk "github.com/cosmos/cosmos-sdk/types" - relayerClient "github.com/ojo-network/ojo-evm/relayer/relayer/client" "github.com/ojo-network/ojo/x/oracle/keeper" "github.com/ojo-network/ojo/x/oracle/types" "github.com/ojo-network/price-feeder/oracle" @@ -82,29 +81,9 @@ func (h *VoteExtensionHandler) ExtendVoteHandler() sdk.ExtendVoteHandler { } } - gasEstimates := []types.GasEstimate{} - estimateParams := h.oracleKeeper.GasEstimateKeeper.GetParams(ctx) - for _, contract := range estimateParams.ContractRegistry { - resp, err := relayerClient.EstimateGasFee( - contract.Network, - contract.Address, - estimateParams.GasLimit, - estimateParams.GasAdjustment, - ) - if err != nil { - h.logger.Error("error estimating gas fee", "error", err) - continue - } - gasEstimates = append(gasEstimates, types.GasEstimate{ - GasEstimation: resp.Int64(), - Network: contract.Network, - }) - } - voteExt := types.OracleVoteExtension{ Height: req.Height, ExchangeRates: filteredDecCoins, - GasEstimates: gasEstimates, } bz, err := voteExt.Marshal() diff --git a/x/oracle/keeper/keeper.go b/x/oracle/keeper/keeper.go index 05a9fbc8..f9ef8f5f 100644 --- a/x/oracle/keeper/keeper.go +++ b/x/oracle/keeper/keeper.go @@ -25,11 +25,10 @@ type Keeper struct { storeKey storetypes.StoreKey paramSpace paramstypes.Subspace - accountKeeper types.AccountKeeper - bankKeeper types.BankKeeper - distrKeeper types.DistributionKeeper - StakingKeeper types.StakingKeeper - GasEstimateKeeper types.GasEstimateKeeper + accountKeeper types.AccountKeeper + bankKeeper types.BankKeeper + distrKeeper types.DistributionKeeper + StakingKeeper types.StakingKeeper PriceFeeder *pricefeeder.PriceFeeder @@ -49,7 +48,6 @@ func NewKeeper( bankKeeper types.BankKeeper, distrKeeper types.DistributionKeeper, stakingKeeper types.StakingKeeper, - gasEstimateKeeper types.GasEstimateKeeper, distrName string, telemetryEnabled bool, authority string, @@ -65,18 +63,17 @@ func NewKeeper( } return Keeper{ - cdc: cdc, - storeKey: storeKey, - paramSpace: paramspace, - accountKeeper: accountKeeper, - bankKeeper: bankKeeper, - distrKeeper: distrKeeper, - StakingKeeper: stakingKeeper, - GasEstimateKeeper: gasEstimateKeeper, - PriceFeeder: &pricefeeder.PriceFeeder{}, - distrName: distrName, - telemetryEnabled: telemetryEnabled, - authority: authority, + cdc: cdc, + storeKey: storeKey, + paramSpace: paramspace, + accountKeeper: accountKeeper, + bankKeeper: bankKeeper, + distrKeeper: distrKeeper, + StakingKeeper: stakingKeeper, + PriceFeeder: &pricefeeder.PriceFeeder{}, + distrName: distrName, + telemetryEnabled: telemetryEnabled, + authority: authority, } }