Skip to content

Commit

Permalink
merge main, resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
danwt committed Dec 3, 2024
2 parents 2585f05 + 29e5c75 commit 85b1e24
Show file tree
Hide file tree
Showing 34 changed files with 199 additions and 249 deletions.
9 changes: 8 additions & 1 deletion app/ante/ante_options.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ante

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
Expand All @@ -16,11 +17,17 @@ import (
txfeeskeeper "github.com/osmosis-labs/osmosis/v15/x/txfees/keeper"
)

// FeeMarketKeeper defines the expected keeper interface used on the AnteHandler
type FeeMarketKeeper interface {
ethante.FeeMarketKeeper
GetMinGasPrice(ctx sdk.Context) (minGasPrice sdk.Dec)
}

type HandlerOptions struct {
AccountKeeper *authkeeper.AccountKeeper
BankKeeper bankkeeper.Keeper
IBCKeeper *ibckeeper.Keeper
FeeMarketKeeper ethante.FeeMarketKeeper
FeeMarketKeeper FeeMarketKeeper
EvmKeeper ethante.EVMKeeper
FeegrantKeeper ante.FeegrantKeeper
TxFeesKeeper *txfeeskeeper.Keeper
Expand Down
4 changes: 2 additions & 2 deletions app/ante/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func newEthAnteHandler(options HandlerOptions) sdk.AnteHandler {
// newLegacyCosmosAnteHandlerEip712 creates an AnteHandler to process legacy EIP-712
// transactions, as defined by the presence of an ExtensionOptionsWeb3Tx extension.
func newLegacyCosmosAnteHandlerEip712(options HandlerOptions) sdk.AnteHandler {
mempoolFeeDecorator := txfeesante.NewMempoolFeeDecorator(*options.TxFeesKeeper)
mempoolFeeDecorator := txfeesante.NewMempoolFeeDecorator(*options.TxFeesKeeper, options.FeeMarketKeeper)
deductFeeDecorator := txfeesante.NewDeductFeeDecorator(*options.TxFeesKeeper, options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper)

return sdk.ChainAnteDecorators(
Expand Down Expand Up @@ -86,7 +86,7 @@ func newLegacyCosmosAnteHandlerEip712(options HandlerOptions) sdk.AnteHandler {
}

func newCosmosAnteHandler(options HandlerOptions) sdk.AnteHandler {
mempoolFeeDecorator := txfeesante.NewMempoolFeeDecorator(*options.TxFeesKeeper)
mempoolFeeDecorator := txfeesante.NewMempoolFeeDecorator(*options.TxFeesKeeper, options.FeeMarketKeeper)
deductFeeDecorator := txfeesante.NewDeductFeeDecorator(*options.TxFeesKeeper, options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper)

return sdk.ChainAnteDecorators(
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,10 @@ replace (
cosmossdk.io/api => cosmossdk.io/api v0.3.1

// use dymension forks
github.com/evmos/ethermint => github.com/dymensionxyz/ethermint v0.22.0-dymension-v1.0.0
github.com/evmos/ethermint => github.com/dymensionxyz/ethermint v0.22.0-dymension-v1.0.0.0.20241202124813-c7838a77b8f6
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/osmosis-labs/osmosis/osmomath => github.com/dymensionxyz/osmosis/osmomath v0.0.6-dymension-v0.1.0.20240820121212-c0e21fa21e43
github.com/osmosis-labs/osmosis/v15 => github.com/dymensionxyz/osmosis/v15 v15.2.1-0.20241121091134-5930c0d433a8
github.com/osmosis-labs/osmosis/v15 => github.com/dymensionxyz/osmosis/v15 v15.2.1-0.20241202152541-b4fc63e3fe20

// broken goleveldb
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -500,14 +500,14 @@ github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkp
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/dvsekhvalnov/jose2go v1.6.0 h1:Y9gnSnP4qEI0+/uQkHvFXeD2PLPJeXEL+ySMEA2EjTY=
github.com/dvsekhvalnov/jose2go v1.6.0/go.mod h1:QsHjhyTlD/lAVqn/NSbVZmSCGeDehTB/mPZadG+mhXU=
github.com/dymensionxyz/ethermint v0.22.0-dymension-v1.0.0 h1:pND0fMCE5xv2A5eyXdSCI8+a+XaxvCNvC0+4Ac7TsTg=
github.com/dymensionxyz/ethermint v0.22.0-dymension-v1.0.0/go.mod h1:aokD0im7cUMMtR/khzNsmcGtINtxCpBfcgRvJdmLymA=
github.com/dymensionxyz/ethermint v0.22.0-dymension-v1.0.0.0.20241202124813-c7838a77b8f6 h1:YHircCv0aQSIz0T8N/C8upYHfAlsY8y80hAsxqkWtfA=
github.com/dymensionxyz/ethermint v0.22.0-dymension-v1.0.0.0.20241202124813-c7838a77b8f6/go.mod h1:aokD0im7cUMMtR/khzNsmcGtINtxCpBfcgRvJdmLymA=
github.com/dymensionxyz/gerr-cosmos v1.1.0 h1:IW/P7HCB/iP9kgk3VXaWUoMoyx3vD76YO6p1fnubHVc=
github.com/dymensionxyz/gerr-cosmos v1.1.0/go.mod h1:n+0olxPogzWqFKba45mCpvrHLGmeS8W9UZjggHnWk6c=
github.com/dymensionxyz/osmosis/osmomath v0.0.6-dymension-v0.1.0.20240820121212-c0e21fa21e43 h1:EskhZ6ILN3vwJ6l8gPWPZ49RFSB52WghT5v+pmzrNCI=
github.com/dymensionxyz/osmosis/osmomath v0.0.6-dymension-v0.1.0.20240820121212-c0e21fa21e43/go.mod h1:SdGCL9CZb14twRAJUSzb7bRE0OoopRpF2Hnd1UhJpFU=
github.com/dymensionxyz/osmosis/v15 v15.2.1-0.20241121091134-5930c0d433a8 h1:AwKgKV4uBZcylJarkT+W8K5FFjH/0tu3q4pzGRJsv+A=
github.com/dymensionxyz/osmosis/v15 v15.2.1-0.20241121091134-5930c0d433a8/go.mod h1:sXttKj99Ke160CvjID+5hvOG3TEF/K1k/Eqa37EhRCc=
github.com/dymensionxyz/osmosis/v15 v15.2.1-0.20241202152541-b4fc63e3fe20 h1:HQitz73Icw+YHPg56m284yYQVwf1XhKqfbbduX5SGes=
github.com/dymensionxyz/osmosis/v15 v15.2.1-0.20241202152541-b4fc63e3fe20/go.mod h1:sXttKj99Ke160CvjID+5hvOG3TEF/K1k/Eqa37EhRCc=
github.com/dymensionxyz/sdk-utils v0.2.12 h1:wrcof+IP0AJQ7vvMRVpSekNNwa6B7ghAspHRjp/k+Lk=
github.com/dymensionxyz/sdk-utils v0.2.12/go.mod h1:it9owYOpnIe17+ftTATQNDN4z+mBQx20/2Jm8SK15Rk=
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
Expand Down
32 changes: 19 additions & 13 deletions ibctesting/light_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,14 +467,12 @@ func (s *lightClientSuite) TestAfterUpdateState_OptimisticUpdateExists_NotCompat
// - trigger rollback
// - validate rollback:
// - check if the client is frozen
// - validate IsHardForkingInProgress returns true
// - validate client updates are blocked
// - validate future consensus states are cleared
//
// - resolve hard fork
// - validate client is unfrozen and hard fork is resolved
// - validate the client is updated
// - validate the client is not in hard forking state
//
// - validate client updates are allowed
func (s *lightClientSuite) TestAfterUpdateState_Rollback() {
Expand Down Expand Up @@ -517,9 +515,14 @@ func (s *lightClientSuite) TestAfterUpdateState_Rollback() {
// get number of consensus states before rollback
csBeforeRollback := s.hubApp().IBCKeeper.ClientKeeper.GetAllConsensusStates(s.hubCtx())[0].ConsensusStates

// Trigger rollback
rollbackHeight := uint64(s.rollappChain().LastHeader.Header.Height) - 5
err := s.hubApp().LightClientKeeper.RollbackCanonicalClient(s.hubCtx(), s.rollappChain().ChainID, rollbackHeight)
// Trigger rollback / simulate fork
nRolledBack := uint64(5)
lastValidHeight := uint64(s.rollappChain().LastHeader.Header.Height) - nRolledBack
newRevisionHeight := lastValidHeight + 1
ra := s.hubApp().RollappKeeper.MustGetRollapp(s.hubCtx(), s.rollappChain().ChainID)
ra.Revisions = append(ra.Revisions, rollapptypes.Revision{StartHeight: newRevisionHeight, Number: 1})
s.hubApp().RollappKeeper.SetRollapp(s.hubCtx(), ra)
err := s.hubApp().LightClientKeeper.RollbackCanonicalClient(s.hubCtx(), s.rollappChain().ChainID, lastValidHeight)
s.Require().NoError(err)

clientState, found := s.hubApp().IBCKeeper.ClientKeeper.GetClientState(s.hubCtx(), s.path.EndpointA.ClientID)
Expand All @@ -530,15 +533,12 @@ func (s *lightClientSuite) TestAfterUpdateState_Rollback() {
// Check if the client is frozen
s.True(!tmClientState.FrozenHeight.IsZero(), "Client should be frozen after rollback")

// Check if IsHardForkingInProgress returns true
s.True(s.hubApp().LightClientKeeper.IsHardForkingInProgress(s.hubCtx(), s.rollappChain().ChainID), "Rollapp should be in hard forking state")

// Validate future consensus states are cleared
csAfterRollback := s.hubApp().IBCKeeper.ClientKeeper.GetAllConsensusStates(s.hubCtx())[0].ConsensusStates
s.Require().Less(len(csAfterRollback), len(csBeforeRollback), "Consensus states should be cleared after rollback")
for height := uint64(0); height <= uint64(s.rollappChain().LastHeader.Header.Height); height++ {
_, found := s.hubApp().IBCKeeper.ClientKeeper.GetClientConsensusState(s.hubCtx(), s.path.EndpointA.ClientID, clienttypes.NewHeight(1, height))
if height > rollbackHeight {
if height >= newRevisionHeight {
s.False(found, "Consensus state should be cleared for height %d", height)
}
}
Expand All @@ -547,7 +547,7 @@ func (s *lightClientSuite) TestAfterUpdateState_Rollback() {
cnt := 0
for _, height := range signerHeights {
_, err := s.hubApp().LightClientKeeper.GetSigner(s.hubCtx(), s.path.EndpointA.ClientID, uint64(height))
if height > int64(rollbackHeight) {
if height >= int64(lastValidHeight) {
s.Error(err, "Signer should be removed for height %d", height)
} else {
s.NoError(err, "Signer should not be removed for height %d", height)
Expand Down Expand Up @@ -578,6 +578,8 @@ func (s *lightClientSuite) TestAfterUpdateState_Rollback() {
s.ErrorIs(err, types.ErrorHardForkInProgress)

// submit a state info update to resolve the hard fork

bds.BD = bds.BD[len(bds.BD)-int(nRolledBack):]
blockDescriptors := &rollapptypes.BlockDescriptors{BD: bds.BD}
msgUpdateState := rollapptypes.NewMsgUpdateState(
s.hubChain().SenderAccount.GetAddress().String(),
Expand All @@ -587,22 +589,26 @@ func (s *lightClientSuite) TestAfterUpdateState_Rollback() {
uint64(len(bds.BD)),
blockDescriptors,
)
msgUpdateState.RollappRevision = 1
_, err = s.rollappMsgServer().UpdateState(s.hubCtx(), msgUpdateState)
s.Require().NoError(err)
s.Require().NoError(err, "update state")

// Test resolve hard fork
clientState, found = s.hubApp().IBCKeeper.ClientKeeper.GetClientState(s.hubCtx(), s.path.EndpointA.ClientID)
s.True(found)
// Verify that the client is unfrozen and hard fork is resolved
s.True(clientState.(*ibctm.ClientState).FrozenHeight.IsZero(), "Client should be unfrozen after hard fork resolution")
// Verify that the client is not in hard forking state
s.False(s.hubApp().LightClientKeeper.IsHardForkingInProgress(s.hubCtx(), s.rollappChain().ChainID), "Rollapp should not be in hard forking state")
// Verify that the client is updated with the height of the first block descriptor
s.Require().Equal(bds.BD[0].Height, clientState.GetLatestHeight().GetRevisionHeight())
_, ok = s.hubApp().IBCKeeper.ClientKeeper.GetLatestClientConsensusState(s.hubCtx(), s.path.EndpointA.ClientID)
s.True(ok)

// validate client updates are no longer blocked
s.coordinator.CommitBlock(s.rollappChain())

// a bit of a hack to make sure the ibc go testing framework can update, since we can't get inside to pass a revision
ra.Revisions = nil
s.hubApp().RollappKeeper.SetRollapp(s.hubCtx(), ra)

s.NoError(s.path.EndpointA.UpdateClient())
}
1 change: 0 additions & 1 deletion proto/dymensionxyz/dymension/lightclient/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ message HeaderSignerEntry {
message GenesisState {
repeated CanonicalClient canonical_clients = 1 [ (gogoproto.nullable) = false ];
repeated HeaderSignerEntry header_signers = 3 [ (gogoproto.nullable) = false ];
repeated string hard_fork_keys = 4;
}

message CanonicalClient {
Expand Down
4 changes: 4 additions & 0 deletions testutil/keeper/lightclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ func NewMockSequencerKeeper(sequencers map[string]*sequencertypes.Sequencer) *Mo

type MockRollappKeeper struct{}

func (m *MockRollappKeeper) IsFirstHeightOfLatestFork(ctx sdk.Context, rollappId string, revision, height uint64) bool {
return false
}

func (m *MockRollappKeeper) GetLatestHeight(ctx sdk.Context, rollappId string) (uint64, bool) {
panic("implement me")
}
Expand Down
4 changes: 2 additions & 2 deletions x/delayedack/keeper/fraud.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import (

var _ rollapptypes.RollappHooks = &Keeper{}

func (k Keeper) OnHardFork(ctx sdk.Context, rollappID string, newRevisionHeight uint64) error {
func (k Keeper) OnHardFork(ctx sdk.Context, rollappID string, lastValidHeight uint64) error {
logger := ctx.Logger().With("module", "DelayedAckMiddleware")

// Get all the pending packets from fork height inclusive
rollappPendingPackets := k.ListRollappPackets(ctx, types.PendingByRollappIDFromHeight(rollappID, newRevisionHeight))
rollappPendingPackets := k.ListRollappPackets(ctx, types.PendingByRollappIDFromHeight(rollappID, lastValidHeight+1))

// Iterate over all the pending packets and revert them
for _, rollappPacket := range rollappPendingPackets {
Expand Down
2 changes: 1 addition & 1 deletion x/delayedack/keeper/fraud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (suite *DelayedAckTestSuite) TestHandleFraud() {
suite.Require().Nil(err)

// call fraud on the 4 packet
err = keeper.OnHardFork(ctx, rollappId, 4)
err = keeper.OnHardFork(ctx, rollappId, 3)
suite.Require().NoError(err)

// expected result:
Expand Down
2 changes: 1 addition & 1 deletion x/dymns/keeper/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (h rollappHooks) BeforeUpdateState(_ sdk.Context, _ string, _ string, _ boo
return nil
}

func (h rollappHooks) AfterUpdateState(_ sdk.Context, _ string, _ *rollapptypes.StateInfo) error {
func (h rollappHooks) AfterUpdateState(ctx sdk.Context, stateInfo *rollapptypes.StateInfoMeta) error {
return nil
}

Expand Down
5 changes: 0 additions & 5 deletions x/lightclient/ante/ibc_msg_update_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@ func (i IBCMessagesDecorator) HandleMsgUpdateClient(ctx sdk.Context, msg *ibccli
return gerrc.ErrInternal.Wrapf("get rollapp from sequencer: rollapp: %s", seq.RollappId)
}

// cannot update the LC unless fork is resolved (after receiving state post fork state update)
if i.k.IsHardForkingInProgress(ctx, rollapp.RollappId) {
return types.ErrorHardForkInProgress
}

// this disallows LC updates from previous revisions but should be fine since new state roots can be used to prove
// state older than the one in the current state root.
if header.Header.Version.App != rollapp.LatestRevision().Number {
Expand Down
5 changes: 4 additions & 1 deletion x/lightclient/ante/ibc_msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ type MockRollappKeeper struct {
stateInfos map[string]map[uint64]rollapptypes.StateInfo
}

func (m *MockRollappKeeper) IsFirstHeightOfLatestFork(ctx sdk.Context, rollappId string, revision, height uint64) bool {
panic("implement me")
}

func (m *MockRollappKeeper) GetLatestHeight(ctx sdk.Context, rollappId string) (uint64, bool) {
// TODO implement me
panic("implement me")
}

Expand Down
7 changes: 7 additions & 0 deletions x/lightclient/keeper/client_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ func getClientState(clientStore sdk.KVStore, cdc codec.BinaryCodec) exported.Cli
return clienttypes.MustUnmarshalClientState(cdc, bz)
}

// must be tendermint!
func getClientStateTM(clientStore sdk.KVStore, cdc codec.BinaryCodec) *ibctm.ClientState {
c := getClientState(clientStore, cdc)
tmClientState, _ := c.(*ibctm.ClientState)
return tmClientState
}

// setClientState stores the client state
func setClientState(clientStore sdk.KVStore, cdc codec.BinaryCodec, clientState exported.ClientState) {
key := host.ClientStateKey()
Expand Down
5 changes: 0 additions & 5 deletions x/lightclient/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,13 @@ func (k Keeper) InitGenesis(ctx sdk.Context, genesisState types.GenesisState) {
panic(err)
}
}
for _, rollappID := range genesisState.HardForkKeys {
k.SetHardForkInProgress(ctx, rollappID)
}
}

func (k Keeper) ExportGenesis(ctx sdk.Context) types.GenesisState {
clients := k.GetAllCanonicalClients(ctx)
hardForkKeys := k.ListHardForkKeys(ctx)

ret := types.GenesisState{
CanonicalClients: clients,
HardForkKeys: hardForkKeys,
}

if err := k.headerSigners.Walk(ctx, nil,
Expand Down
11 changes: 0 additions & 11 deletions x/lightclient/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func TestInitGenesis(t *testing.T) {

keeper.InitGenesis(ctx, types.GenesisState{
CanonicalClients: clients,
HardForkKeys: []string{"rollapp-1", "rollapp-2"},
})

ibc, found := keeper.GetCanonicalClient(ctx, "rollapp-1")
Expand All @@ -28,19 +27,13 @@ func TestInitGenesis(t *testing.T) {
ibc, found = keeper.GetCanonicalClient(ctx, "rollapp-2")
require.True(t, found)
require.Equal(t, "client-2", ibc)
hfks := keeper.ListHardForkKeys(ctx)
require.Len(t, hfks, 2)
require.Equal(t, "rollapp-1", hfks[0])
require.Equal(t, "rollapp-2", hfks[1])
}

func TestExportGenesis(t *testing.T) {
keeper, ctx := keepertest.LightClientKeeper(t)

keeper.SetCanonicalClient(ctx, "rollapp-1", "client-1")
keeper.SetCanonicalClient(ctx, "rollapp-2", "client-2")
keeper.SetHardForkInProgress(ctx, "rollapp-1")
keeper.SetHardForkInProgress(ctx, "rollapp-2")

genesis := keeper.ExportGenesis(ctx)

Expand All @@ -49,9 +42,6 @@ func TestExportGenesis(t *testing.T) {
require.Equal(t, "client-2", genesis.CanonicalClients[1].IbcClientId)
require.Equal(t, "rollapp-1", genesis.CanonicalClients[0].RollappId)
require.Equal(t, "rollapp-2", genesis.CanonicalClients[1].RollappId)
require.Len(t, genesis.HardForkKeys, 2)
require.Equal(t, "rollapp-1", genesis.HardForkKeys[0])
require.Equal(t, "rollapp-2", genesis.HardForkKeys[1])
}

func TestImportExportGenesis(t *testing.T) {
Expand Down Expand Up @@ -80,7 +70,6 @@ func TestImportExportGenesis(t *testing.T) {
Height: 43,
},
},
HardForkKeys: []string{"rollapp-1", "rollapp-2"},
}

k.InitGenesis(ctx, g)
Expand Down
Loading

0 comments on commit 85b1e24

Please sign in to comment.