Skip to content

Commit

Permalink
feat: relay to EVM via ABCI (#525)
Browse files Browse the repository at this point in the history
Co-authored-by: ryanbajollari <[email protected]>
  • Loading branch information
adamewozniak and rbajollari authored Oct 2, 2024
1 parent 1dc2b32 commit b16218c
Show file tree
Hide file tree
Showing 81 changed files with 7,097 additions and 168 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
if: env.GIT_DIFF
uses: actions/setup-go@v5
with:
go-version: '1.22.1'
go-version: '1.23'
cache: true
env:
GOOS: ${{ matrix.targetos }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/code-ql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.22.1'
go-go-version: '1.23'
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
steps:
- uses: actions/setup-go@v5
with:
go-version: '1.22.1'
go-go-version: '1.23'
cache: true

- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
steps:
- uses: actions/setup-go@v5
with:
go-version: '1.22.1'
go-go-version: '1.23'
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version: '1.22.1'
go-go-version: '1.23'
cache: true

- name: Set Env
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/simulations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
steps:
- uses: actions/setup-go@v5
with:
go-version: '1.22.1'
go-go-version: '1.23'

- name: Install runsim
run: export GO111MODULE="on" && go install github.com/cosmos/tools/cmd/[email protected]
Expand All @@ -38,7 +38,7 @@ jobs:
- uses: actions/setup-go@v5
if: env.GIT_DIFF
with:
go-version: '1.22.1'
go-go-version: '1.23'
cache: true
- name: Test application non-determinism
if: env.GIT_DIFF
Expand All @@ -60,7 +60,7 @@ jobs:
- uses: actions/setup-go@v5
if: env.GIT_DIFF
with:
go-version: '1.22.1'
go-go-version: '1.23'
cache: true
- uses: actions/cache@v4
if: env.GIT_DIFF
Expand All @@ -87,7 +87,7 @@ jobs:
- uses: actions/setup-go@v5
if: env.GIT_DIFF
with:
go-version: '1.22.1'
go-go-version: '1.23'
cache: true
- uses: actions/cache@v4
if: env.GIT_DIFF
Expand All @@ -113,7 +113,7 @@ jobs:
- uses: actions/setup-go@v5
if: env.GIT_DIFF
with:
go-version: '1.22.1'
go-go-version: '1.23'
cache: true
- uses: actions/cache@v4
if: env.GIT_DIFF
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
steps:
- uses: actions/setup-go@v5
with:
go-version: '1.22.1'
go-go-version: '1.23'
- name: Display Go Version
run: go version
- uses: actions/cache@v4
Expand All @@ -38,7 +38,7 @@ jobs:
- uses: actions/setup-go@v5
if: env.GIT_DIFF
with:
go-version: '1.22.1'
go-go-version: '1.23'
cache: true
- name: Test and Create Coverage Report
if: env.GIT_DIFF
Expand Down Expand Up @@ -100,7 +100,7 @@ jobs:
- uses: actions/setup-go@v5
if: env.GIT_DIFF
with:
go-version: '1.22.1'
go-go-version: '1.23'
cache: true

- name: Test E2E
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Builder
FROM golang:1.22.1-alpine AS builder
FROM golang:1.23-alpine AS builder

RUN apk add --no-cache \
ca-certificates \
Expand Down
24 changes: 22 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ import (
gmpkeeper "github.com/ojo-network/ojo/x/gmp/keeper"
gmptypes "github.com/ojo-network/ojo/x/gmp/types"

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

"github.com/ojo-network/ojo/x/airdrop"
airdropkeeper "github.com/ojo-network/ojo/x/airdrop/keeper"
airdroptypes "github.com/ojo-network/ojo/x/airdrop/types"
Expand Down Expand Up @@ -145,6 +149,7 @@ var (
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
oracletypes.ModuleName: {authtypes.Minter},
gmptypes.ModuleName: {authtypes.Minter},
gasestimatetypes.ModuleName: {authtypes.Burner},
airdroptypes.ModuleName: {authtypes.Minter},
}
)
Expand Down Expand Up @@ -201,6 +206,7 @@ type App struct {
GroupKeeper groupkeeper.Keeper
OracleKeeper oraclekeeper.Keeper
GmpKeeper gmpkeeper.Keeper
GasEstimateKeeper gasestimatekeeper.Keeper
AirdropKeeper airdropkeeper.Keeper
ConsensusParamsKeeper consensusparamkeeper.Keeper

Expand Down Expand Up @@ -264,7 +270,7 @@ func New(
govtypes.StoreKey, paramstypes.StoreKey, ibcexported.StoreKey, upgradetypes.StoreKey,
feegrant.StoreKey, evidencetypes.StoreKey, ibctransfertypes.StoreKey, capabilitytypes.StoreKey,
consensusparamtypes.StoreKey, group.StoreKey, oracletypes.StoreKey, gmptypes.StoreKey,
airdroptypes.StoreKey,
gasestimatetypes.ModuleName, airdroptypes.StoreKey,
)
tkeys := storetypes.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := storetypes.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -409,6 +415,12 @@ func New(
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

app.GasEstimateKeeper = gasestimatekeeper.NewKeeper(
appCodec,
keys[gasestimatetypes.ModuleName],
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

app.OracleKeeper = oraclekeeper.NewKeeper(
appCodec,
keys[oracletypes.ModuleName],
Expand All @@ -417,6 +429,7 @@ func New(
app.BankKeeper,
app.DistrKeeper,
app.StakingKeeper,
app.GasEstimateKeeper,
distrtypes.ModuleName,
cast.ToBool(appOpts.Get("telemetry.enabled")),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
Expand All @@ -428,6 +441,8 @@ func New(
app.OracleKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
app.TransferKeeper,
app.BankKeeper,
app.GasEstimateKeeper,
)

app.AirdropKeeper = airdropkeeper.NewKeeper(
Expand Down Expand Up @@ -580,6 +595,7 @@ func New(
ibctm.NewAppModule(),
oracle.NewAppModule(appCodec, app.OracleKeeper, app.AccountKeeper, app.BankKeeper),
gmp.NewAppModule(appCodec, app.GmpKeeper, app.OracleKeeper),
gasestimate.NewAppModule(appCodec, app.GasEstimateKeeper),
airdrop.NewAppModule(appCodec, app.AirdropKeeper, app.AccountKeeper, app.BankKeeper),
consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper),
)
Expand Down Expand Up @@ -631,6 +647,7 @@ func New(
vestingtypes.ModuleName,
oracletypes.ModuleName,
gmptypes.ModuleName,
gasestimatetypes.ModuleName,
airdroptypes.ModuleName,
consensusparamtypes.ModuleName,
)
Expand All @@ -657,6 +674,7 @@ func New(
vestingtypes.ModuleName,
oracletypes.ModuleName,
gmptypes.ModuleName,
gasestimatetypes.ModuleName,
airdroptypes.ModuleName,
consensusparamtypes.ModuleName,
)
Expand All @@ -672,7 +690,8 @@ func New(
minttypes.ModuleName, crisistypes.ModuleName, genutiltypes.ModuleName, ibctransfertypes.ModuleName,
ibcexported.ModuleName, evidencetypes.ModuleName, authz.ModuleName, feegrant.ModuleName,
group.ModuleName, paramstypes.ModuleName, upgradetypes.ModuleName, vestingtypes.ModuleName,
oracletypes.ModuleName, gmptypes.ModuleName, airdroptypes.ModuleName, consensusparamtypes.ModuleName,
oracletypes.ModuleName, gmptypes.ModuleName, gasestimatetypes.ModuleName,
airdroptypes.ModuleName, consensusparamtypes.ModuleName,
}
app.mm.SetOrderInitGenesis(genesisModuleOrder...)
app.mm.SetOrderExportGenesis(genesisModuleOrder...)
Expand Down Expand Up @@ -991,6 +1010,7 @@ func initParamsKeeper(
paramsKeeper.Subspace(govtypes.ModuleName)
paramsKeeper.Subspace(crisistypes.ModuleName)
paramsKeeper.Subspace(oracletypes.ModuleName)
paramsKeeper.Subspace(gasestimatetypes.ModuleName)

// register the key tables for legacy param subspaces
keyTable := ibcclienttypes.ParamKeyTable()
Expand Down
14 changes: 10 additions & 4 deletions app/preblocker.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ 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 @@ -50,9 +52,6 @@ func (app *App) PreBlocker(ctx sdk.Context, req *cometabci.RequestFinalizeBlock)
app.Logger().Error("failed to decode injected vote extension tx", "err", err)
return nil, err
}

// set oracle exchange rate votes using the passed in context, which will make
// these votes available in the current block.
for _, exchangeRateVote := range injectedVoteExtTx.ExchangeRateVotes {
valAddr, err := sdk.ValAddressFromBech32(exchangeRateVote.Voter)
if err != nil {
Expand All @@ -61,10 +60,17 @@ 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(
"oracle preblocker executed",
"preblocker executed",
"vote_extensions_enabled", voteExtensionsEnabled,
)

Expand Down
21 changes: 21 additions & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
gmptypes "github.com/ojo-network/ojo/x/gmp/types"

gasestimatetypes "github.com/ojo-network/ojo/x/gasestimate/types"
oraclekeeper "github.com/ojo-network/ojo/x/oracle/keeper"
oracletypes "github.com/ojo-network/ojo/x/oracle/types"
)
Expand All @@ -47,6 +48,7 @@ func (app App) RegisterUpgradeHandlers() {
app.registerUpgrade0_3_2(upgradeInfo)
app.registerUpgrade0_4_0(upgradeInfo)
app.registerUpgrade0_4_1(upgradeInfo)
app.registerUpgrade0_5_0(upgradeInfo)
}

// performs upgrade from v0.1.3 to v0.1.4
Expand Down Expand Up @@ -333,6 +335,25 @@ func (app *App) registerUpgrade0_4_1(upgradeInfo upgradetypes.Plan) {
})
}

// performs upgrade from v0.4.x to v0.5.0
func (app *App) registerUpgrade0_5_0(upgradeInfo upgradetypes.Plan) {
const planName = "v0.5.0"
app.UpgradeKeeper.SetUpgradeHandler(planName,
func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
sdkCtx := sdk.UnwrapSDKContext(ctx)
sdkCtx.Logger().Info("Upgrade handler execution", "name", planName)
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
},
)

// REF: https://github.com/cosmos/cosmos-sdk/blob/a32186608aab0bd436049377ddb34f90006fcbf7/simapp/upgrades.go
app.storeUpgrade(planName, upgradeInfo, storetypes.StoreUpgrades{
Added: []string{
gasestimatetypes.ModuleName,
},
})
}

// helper function to check if the store loader should be upgraded
func (app *App) storeUpgrade(planName string, ui upgradetypes.Plan, stores storetypes.StoreUpgrades) {
if ui.Name == planName && !app.UpgradeKeeper.IsSkipHeight(ui.Height) {
Expand Down
27 changes: 27 additions & 0 deletions client/query/gasestimation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package query

import (
"context"

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

// GovQueryClient returns the govtypes.QueryClient
// initialized with the clients grpc connection
func (c *Client) GasEstimateClient() gasestimatetypes.QueryClient {
return gasestimatetypes.NewQueryClient(c.grpcConn)
}

func (c *Client) GetGasEstimate(ctx context.Context, network string) (int64, error) {
queryClient := c.GasEstimateClient()
query := &gasestimatetypes.GasEstimateRequest{
Network: network,
}

res, err := queryClient.GasEstimate(ctx, query)
if err != nil {
return 0, err
}

return res.GasEstimate, nil
}
23 changes: 23 additions & 0 deletions client/query/gmp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package query

import (
"context"

gmptypes "github.com/ojo-network/ojo/x/gmp/types"
)

func (c *Client) GmpQueryClient() gmptypes.QueryClient {
return gmptypes.NewQueryClient(c.grpcConn)
}

func (c *Client) QueryPayments() (*gmptypes.AllPaymentsResponse, error) {
ctx, cancel := context.WithTimeout(context.Background(), queryTimeout)
defer cancel()

queryResponse, err := c.GmpQueryClient().AllPayments(
ctx,
&gmptypes.AllPaymentsRequest{},
)

return queryResponse, err
}
26 changes: 26 additions & 0 deletions client/tx/gmp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package tx

import (
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
gmptypes "github.com/ojo-network/ojo/x/gmp/types"
)

// TxCreatePayment creates a gmp payment transaction
func (c *Client) TxCreatePayment() (*sdk.TxResponse, error) {
fromAddr, err := c.keyringRecord.GetAddress()
if err != nil {
return nil, err
}

msg := gmptypes.NewMsgCreatePayment(
fromAddr.String(),
"Arbitrum",
"BTC",
sdk.NewCoin("uojo", math.NewInt(1_000_000_000)),
math.LegacyOneDec(),
100,
)

return c.BroadcastTx(msg)
}
Loading

0 comments on commit b16218c

Please sign in to comment.