Skip to content

Commit

Permalink
Merge branch 'main' into feat/contract-oracle
Browse files Browse the repository at this point in the history
  • Loading branch information
keruch committed Dec 26, 2024
2 parents a1f11b8 + 03bea59 commit 1910d79
Show file tree
Hide file tree
Showing 30 changed files with 2,874 additions and 111 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/generate_genesis_template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Generate Genesis Template
on: ["push"]
jobs:
build:
runs-on: ubuntu-latest
name: Generate Genesis Template
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.23.1"

- name: Install Dasel
run: |
curl -sSLf https://github.com/TomWright/dasel/releases/latest/download/dasel_linux_amd64 -o /usr/local/bin/dasel
chmod +x /usr/local/bin/dasel
- name: Generate genesis template mainnet
run: make generate-genesis env=mainnet
env:
BECH32_PREFIX: ethm

- name: Generate genesis template testnet
run: make generate-genesis env=testnet
env:
BECH32_PREFIX: ethm
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM ubuntu:latest as go-builder

# Install necessary dependencies
RUN apt-get update && apt-get install -y \
wget make git \
wget make git build-essential \
&& rm -rf /var/lib/apt/lists/*

# Download and install Go 1.21
Expand All @@ -17,8 +17,6 @@ ENV GOROOT=/usr/local/go
ENV GOPATH=$HOME/go
ENV PATH=$GOPATH/bin:$GOROOT/bin:$PATH

RUN apt-get update -y
RUN apt-get install build-essential -y
# Set the working directory
WORKDIR /app

Expand All @@ -40,6 +38,8 @@ RUN ARCH=$(uname -m) && WASMVM_VERSION=$(go list -m github.com/CosmWasm/wasmvm |
wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/libwasmvm.aarch64.so \
-O /lib/libwasmvm.aarch64.so

RUN go install -v github.com/bcdevtools/devd/v2/cmd/devd@latest

# Copy the remaining files
COPY . .

Expand All @@ -48,7 +48,9 @@ RUN make build BECH32_PREFIX=ethm
FROM ubuntu:latest

RUN apt-get update -y
RUN apt-get install -y curl

COPY --from=go-builder /go/bin/devd /usr/local/bin/devd
COPY --from=go-builder /app/build/rollapp-evm /usr/local/bin/rollappd
COPY --from=go-builder /lib/libwasmvm.x86_64.so /lib/libwasmvm.x86_64.so
COPY --from=go-builder /lib/libwasmvm.aarch64.so /lib/libwasmvm.aarch64.so
Expand Down
24 changes: 23 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ PROJECT_NAME=rollappd
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
COMMIT := $(shell git log -1 --format='%H')
LEDGER_ENABLED ?= true
DRS_VERSION = 1
DRS_VERSION = 4

#ifndef $(CELESTIA_NETWORK)
# CELESTIA_NETWORK=mock
Expand Down Expand Up @@ -173,3 +173,25 @@ release:
release --clean --skip=validate

.PHONY: release-dry-run release

# Default DRS_VERSION if not set
DRS_VERSION ?= default-drs

.PHONY: generate-genesis
generate-genesis:
@if [ -z "$(env)" ]; then \
echo "Error: 'env' parameter is required. Use 'make generate-genesis env=mainnet' or 'make generate-genesis env=testnet'"; \
exit 1; \
fi
@if [ "$(env)" != "mainnet" ] && [ "$(env)" != "testnet" ]; then \
echo "Error: 'env' must be either 'mainnet' or 'testnet'"; \
exit 1; \
fi
@echo "Building and installing rollapp-evm..."
@$(MAKE) install
@echo "Removing existing genesis file..."
@rm -f ${HOME}/.rollapp_evm/config/genesis.json
@echo "Initializing rollapp-evm..."
@rollapp-evm init test
@echo "Running genesis template script..."
@./scripts/generate-genesis-template.sh $(env) $(DRS_VERSION)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ $EXECUTABLE tx sequencer create-sequencer sequencerConsensusKey --from $KEY_NAME
### Install dymension relayer

```shell
git clone https://github.com/dymensionxyz/go-relayer.git --branch v0.3.4-v2.5.2-relayer-canon-3
git clone https://github.com/dymensionxyz/go-relayer.git --branch v0.3.4-v2.5.2-relayer-canon-6
cd go-relayer && make install
```

Expand Down
14 changes: 13 additions & 1 deletion app/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
evmosante "github.com/evmos/evmos/v12/app/ante"
evmosanteevm "github.com/evmos/evmos/v12/app/ante/evm"
evmostypes "github.com/evmos/evmos/v12/types"
erc20keeper "github.com/evmos/evmos/v12/x/erc20/keeper"
evmtypes "github.com/evmos/evmos/v12/x/evm/types"
evmosvestingtypes "github.com/evmos/evmos/v12/x/vesting/types"
tmlog "github.com/tendermint/tendermint/libs/log"
Expand All @@ -38,24 +39,29 @@ func MustCreateHandler(codec codec.BinaryCodec,
bankKeeper evmtypes.BankKeeper,
feeMarketKeeper evmosanteevm.FeeMarketKeeper,
evmKeeper evmosanteevm.EVMKeeper,
erc20Keeper erc20keeper.Keeper,
ibcKeeper *ibckeeper.Keeper,
distrKeeper distrkeeper.Keeper,
sequencerKeeper seqkeeper.Keeper,
feeGrantKeeper authante.FeegrantKeeper,
authzKeeper evmosanteevm.AuthzKeeper,
) sdk.AnteHandler {
ethOpts := evmosante.HandlerOptions{
Cdc: codec,
AccountKeeper: accountKeeper,
BankKeeper: bankKeeper,
EvmKeeper: evmKeeper,
StakingKeeper: stakingKeeper,
FeegrantKeeper: nil,
FeegrantKeeper: feeGrantKeeper,
DistributionKeeper: distrKeeper,
ERC20Keeper: erc20Keeper,
IBCKeeper: ibcKeeper,
FeeMarketKeeper: feeMarketKeeper,
SignModeHandler: txConfig.SignModeHandler(),
SigGasConsumer: evmosante.SigVerificationGasConsumer,
MaxTxGasWanted: maxGasWanted,
TxFeeChecker: evmosanteevm.NewDynamicFeeChecker(evmKeeper),
AuthzKeeper: authzKeeper,
}

opts := HandlerOptions{
Expand Down Expand Up @@ -99,12 +105,18 @@ func (o HandlerOptions) validate() error {
if o.EvmKeeper == nil {
return errorsmod.Wrap(sdkerrors.ErrLogic, "evm keeper missing")
}
if o.ERC20Keeper == nil {
return errorsmod.Wrap(sdkerrors.ErrLogic, "erc20 keeper missing")
}
if o.DistributionKeeper == nil {
return errorsmod.Wrap(sdkerrors.ErrLogic, "distribution keeper missing")
}
if o.StakingKeeper == nil {
return errorsmod.Wrap(sdkerrors.ErrLogic, "staking keeper missing")
}
if o.FeegrantKeeper == nil {
return errorsmod.Wrap(sdkerrors.ErrLogic, "feegrant keeper missing")
}

/*
Our stuff
Expand Down
5 changes: 3 additions & 2 deletions app/ante/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ func newEVMAnteHandler(options HandlerOptions) sdk.AnteHandler {
evmante.NewEthMinGasPriceDecorator(options.FeeMarketKeeper, options.EvmKeeper),
evmante.NewEthValidateBasicDecorator(options.EvmKeeper),
evmante.NewEthSigVerificationDecorator(options.EvmKeeper),
evmante.NewEthAuthorizationDecorator(options.AuthzKeeper),
evmante.NewEthAccountVerificationDecorator(options.AccountKeeper, options.EvmKeeper),
evmante.NewCanTransferDecorator(options.EvmKeeper),
// we intentionally omit the eth vesting transaction decorator
evmante.NewEthGasConsumeDecorator(options.BankKeeper, options.DistributionKeeper, options.EvmKeeper, options.StakingKeeper, options.MaxTxGasWanted),
evmante.NewEthGasConsumeDecorator(options.AccountKeeper, options.BankKeeper, options.ERC20Keeper, options.DistributionKeeper, options.EvmKeeper, options.StakingKeeper, options.MaxTxGasWanted),
evmante.NewEthIncrementSenderSequenceDecorator(options.AccountKeeper),
evmante.NewGasWantedDecorator(options.EvmKeeper, options.FeeMarketKeeper),
// emit eth tx hash and index at the very last ante handler.
Expand Down Expand Up @@ -79,7 +80,7 @@ func cosmosHandler(options HandlerOptions, sigChecker sdk.AnteDecorator) sdk.Ant
NewCreateAccountDecorator(options.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
rdkante.NewBypassIBCFeeDecorator(
cosmosante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.DistributionKeeper, options.FeegrantKeeper, options.StakingKeeper, options.TxFeeChecker),
cosmosante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.ERC20Keeper, options.DistributionKeeper, options.FeegrantKeeper, options.StakingKeeper, options.TxFeeChecker),
options.DistrKeeper,
options.SequencersKeeper,
),
Expand Down
87 changes: 50 additions & 37 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/authz"
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"
"github.com/dymensionxyz/dymension-rdk/server/proposal"
"github.com/gogo/protobuf/proto"
"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
Expand Down Expand Up @@ -131,7 +132,6 @@ import (

"github.com/evmos/evmos/v12/ethereum/eip712"
ethermint "github.com/evmos/evmos/v12/types"
claimstypes "github.com/evmos/evmos/v12/x/claims/types"
"github.com/evmos/evmos/v12/x/erc20"
erc20client "github.com/evmos/evmos/v12/x/erc20/client"
erc20keeper "github.com/evmos/evmos/v12/x/erc20/keeper"
Expand All @@ -152,11 +152,17 @@ import (
hubtypes "github.com/dymensionxyz/dymension-rdk/x/hub/types"

// Upgrade handlers
v2_2_0_upgrade "github.com/dymensionxyz/rollapp-evm/app/upgrades/v2.2.0"

// Force-load the tracer engines to trigger registration due to Go-Ethereum v1.10.15 changes
_ "github.com/ethereum/go-ethereum/eth/tracers/js"
_ "github.com/ethereum/go-ethereum/eth/tracers/native"

dymintversion "github.com/dymensionxyz/dymint/version"

"github.com/dymensionxyz/rollapp-evm/app/upgrades"
drs2 "github.com/dymensionxyz/rollapp-evm/app/upgrades/drs-2"
drs3 "github.com/dymensionxyz/rollapp-evm/app/upgrades/drs-3"
drs4 "github.com/dymensionxyz/rollapp-evm/app/upgrades/drs-4"
)

const (
Expand All @@ -181,6 +187,8 @@ var (
feemarkettypes.StoreKey,
erc20types.StoreKey,
}
// Upgrades contains the upgrade handlers for the application
Upgrades = []upgrades.Upgrade{drs2.Upgrade, drs3.Upgrade, drs4.Upgrade}
)

func getGovProposalHandlers() []govclient.ProposalHandler {
Expand Down Expand Up @@ -533,7 +541,7 @@ func NewRollapp(
govRouter := govv1beta1.NewRouter()
govRouter.
AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler).
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)).
AddRoute(paramproposal.RouterKey, proposal.NewCustomParamChangeProposalHandler(app.ParamsKeeper, app.BankKeeper)).
AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)).
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)).
AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper)).
Expand Down Expand Up @@ -564,6 +572,7 @@ func NewRollapp(
app.AccountKeeper,
app.BankKeeper,
app.MintKeeper,
app.IBCKeeper.ChannelKeeper,
)

app.HubKeeper = hubkeeper.NewKeeper(
Expand Down Expand Up @@ -614,7 +623,6 @@ func NewRollapp(
transferStack,
app.HubGenesisKeeper,
app.BankKeeper,
app.IBCKeeper.ChannelKeeper,
)

// Create static IBC router, add transfer route, then set and seal it
Expand Down Expand Up @@ -810,9 +818,12 @@ func NewRollapp(
app.BankKeeper,
app.FeeMarketKeeper,
app.EvmKeeper,
app.Erc20Keeper,
app.IBCKeeper,
app.DistrKeeper,
app.SequencersKeeper,
app.FeeGrantKeeper,
app.AuthzKeeper,
)
app.SetAnteHandler(h)
app.setPostHandler()
Expand Down Expand Up @@ -861,6 +872,13 @@ func (app *App) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.R
resp := app.mm.BeginBlock(ctx, req)
resp.ConsensusMessagesResponses = consensusResponses

drsVersion, err := dymintversion.GetDRSVersion()
if err != nil {
panic(fmt.Errorf("Unable to get DRS version from binary: %w", err))
}
if drsVersion != app.RollappParamsKeeper.Version(ctx) {
panic(fmt.Errorf("DRS version mismatch. rollapp DRS version: %d binary DRS version:%d", app.RollappParamsKeeper.Version(ctx), drsVersion))
}
return resp
}

Expand Down Expand Up @@ -1102,39 +1120,6 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
return paramsKeeper
}

func (app *App) setupUpgradeHandlers() {
UpgradeName := "v2.2.0"

app.UpgradeKeeper.SetUpgradeHandler(
UpgradeName,
v2_2_0_upgrade.CreateUpgradeHandler(
app.mm, app.configurator,
),
)

// When a planned update height is reached, the old binary will panic
// writing on disk the height and name of the update that triggered it
// This will read that value, and execute the preparations for the upgrade.
upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(fmt.Errorf("failed to read upgrade info from disk: %w", err))
}

// Pre upgrade handler
switch upgradeInfo.Name {
// do nothing
}

if upgradeInfo.Name == UpgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {

storeUpgrades := storetypes.StoreUpgrades{
Deleted: []string{claimstypes.ModuleName},
}

app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
}
}

var evmAccountName = proto.MessageName(&ethermint.EthAccount{})

func shouldBumpEvmAccountSequence(accountProtoName string, account authtypes.AccountI) (bool, error) {
Expand All @@ -1149,3 +1134,31 @@ func shouldBumpEvmAccountSequence(accountProtoName string, account authtypes.Acc
}
return evmAccount.Type() == ethermint.AccountTypeEOA, nil
}

func (app *App) setupUpgradeHandlers() {
for _, u := range Upgrades {
app.setupUpgradeHandler(u)
}
}

func (app *App) setupUpgradeHandler(upgrade upgrades.Upgrade) {
app.UpgradeKeeper.SetUpgradeHandler(
upgrade.Name,
upgrade.CreateHandler(
app.RollappParamsKeeper,
app.EvmKeeper,
app.mm,
app.configurator,
),
)

upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(fmt.Errorf("failed to read upgrade info from disk: %w", err))
}

if upgradeInfo.Name == upgrade.Name && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
// configure store loader with the store upgrades
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &upgrade.StoreUpgrades))
}
}
5 changes: 4 additions & 1 deletion app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"testing"
"time"

version "github.com/dymensionxyz/dymint/version"

appcodec "github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/crypto/codec"
Expand Down Expand Up @@ -87,8 +89,8 @@ func SetupWithGenesisValSet(t *testing.T, valSet *types2.ValidatorSet, genAccs [
app, genesisState := setup(true, 5)
genesisState = genesisStateWithValSet(t, app, genesisState, valSet, genAccs, balances...)

version.DRS = "1"
genesisState = setRollappVersion(app.appCodec, genesisState, 1)

denomMD := banktypes.Metadata{
Description: "Stake token",
DenomUnits: []*banktypes.DenomUnit{
Expand Down Expand Up @@ -121,6 +123,7 @@ func SetupWithGenesisValSet(t *testing.T, valSet *types2.ValidatorSet, genAccs [
ConsensusParams: utils.DefaultConsensusParams,
AppStateBytes: stateBytes,
ChainId: TestChainID,
GenesisChecksum: "abcdef",
},
)

Expand Down
Loading

0 comments on commit 1910d79

Please sign in to comment.