Skip to content

Commit

Permalink
take out more gas estimate stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
rbajollari committed Jan 8, 2025
1 parent ec052ff commit e8f4301
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 390 deletions.
9 changes: 0 additions & 9 deletions app/preblocker.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ojo-network/ojo/x/oracle/abci"
"github.com/ojo-network/ojo/x/oracle/types"

gasestimatetypes "github.com/ojo-network/ojo/x/gasestimate/types"
)

// PreBlocker is run before finalize block to update the aggregrate exchange rate votes on the oracle module
Expand Down Expand Up @@ -60,13 +58,6 @@ func (app *App) PreBlocker(ctx sdk.Context, req *cometabci.RequestFinalizeBlock)
}
app.OracleKeeper.SetAggregateExchangeRateVote(ctx, valAddr, exchangeRateVote)
}
for _, gasEstimate := range injectedVoteExtTx.GasEstimateMedians {
app.GasEstimateKeeper.SetGasEstimate(ctx, gasestimatetypes.GasEstimate{
Network: gasEstimate.Network,
GasEstimate: gasEstimate.GasEstimation,
})
}
app.Logger().Info("gas estimates updated", "gasestimates", injectedVoteExtTx.GasEstimateMedians)
}

app.Logger().Info(
Expand Down
8 changes: 0 additions & 8 deletions proto/ojo/oracle/v1/abci.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ message OracleVoteExtension {
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins",
(gogoproto.nullable) = false
];
repeated GasEstimate gas_estimates = 3 [(gogoproto.nullable) = false];
}

// InjectedVoteExtensionTx defines the vote extension tx injected by the prepare
Expand All @@ -27,11 +26,4 @@ message InjectedVoteExtensionTx {
(gogoproto.nullable) = false
];
bytes extended_commit_info = 2;
repeated GasEstimate gas_estimate_medians = 3 [(gogoproto.nullable) = false];
}

// GasEstimate defines a gas estimate for a given network.
message GasEstimate {
int64 gas_estimation = 1;
string network = 2;
}
13 changes: 0 additions & 13 deletions x/oracle/abci/proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,6 @@ import (
oracletypes "github.com/ojo-network/ojo/x/oracle/types"
)

var testGasEstimates = []oracletypes.GasEstimate{
{
GasEstimation: 300,
Network: "Ethereum",
},
{
GasEstimation: 100,
Network: "Arbitrum",
},
}

func (s *IntegrationTestSuite) TestPrepareProposalHandler() {
app, ctx, keys := s.app, s.ctx, s.keys

Expand Down Expand Up @@ -183,7 +172,6 @@ func (s *IntegrationTestSuite) TestProcessProposalHandler() {
injectedVoteExtTx := oracletypes.InjectedVoteExtensionTx{
ExchangeRateVotes: exchangeRateVotes,
ExtendedCommitInfo: localCommitInfoBz,
GasEstimateMedians: testGasEstimates,
}
bz, err := injectedVoteExtTx.Marshal()
s.Require().NoError(err)
Expand Down Expand Up @@ -320,7 +308,6 @@ func buildLocalCommitInfo(
voteExt := oracletypes.OracleVoteExtension{
ExchangeRates: exchangeRates,
Height: ctx.BlockHeight(),
GasEstimates: testGasEstimates,
}
bz, err := voteExt.Marshal()
if err != nil {
Expand Down
23 changes: 0 additions & 23 deletions x/oracle/abci/util.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package abci

import (
"fmt"
"sort"

sdk "github.com/cosmos/cosmos-sdk/types"
oracletypes "github.com/ojo-network/ojo/x/oracle/types"
)

// VoteExtensionsEnabled determines if vote extensions are enabled for the current block.
Expand All @@ -25,22 +21,3 @@ func VoteExtensionsEnabled(ctx sdk.Context) bool {

return cp.Abci.VoteExtensionsEnableHeight < ctx.BlockHeight()
}

func calculateMedian(gasEstimates []oracletypes.GasEstimate) (median oracletypes.GasEstimate, err error) {
if len(gasEstimates) == 0 {
return oracletypes.GasEstimate{}, fmt.Errorf("cannot calculate median of empty slice")
}

sort.Slice(gasEstimates, func(i, j int) bool {
return gasEstimates[i].GasEstimation < gasEstimates[j].GasEstimation
})

mid := len(gasEstimates) / 2
if len(gasEstimates)%2 == 0 {
return oracletypes.GasEstimate{
GasEstimation: (gasEstimates[mid-1].GasEstimation + gasEstimates[mid].GasEstimation) / 2,
Network: gasEstimates[mid-1].Network, // or gasEstimates[mid].Network, choose consistently
}, nil
}
return gasEstimates[mid], nil
}
Loading

0 comments on commit e8f4301

Please sign in to comment.