Skip to content

Commit

Permalink
Merge branch 'main' into kirill/1248-sequencer-reward-addr
Browse files Browse the repository at this point in the history
  • Loading branch information
keruch committed Oct 9, 2024
2 parents f7263d5 + 234d438 commit 3d493d1
Show file tree
Hide file tree
Showing 42 changed files with 2,860 additions and 1,071 deletions.
11 changes: 4 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ require (
github.com/cosmos/cosmos-sdk v0.46.16
github.com/cosmos/gogoproto v1.5.0
github.com/cosmos/ibc-go/v6 v6.2.1
github.com/dymensionxyz/dymint v1.2.0-rc01.0.20240824093518-9aff93277837
github.com/dymensionxyz/dymint v1.2.0-rc01.0.20240919105350-66f9b353655d
github.com/dymensionxyz/gerr-cosmos v1.0.0
github.com/dymensionxyz/sdk-utils v0.1.2-0.20240905104639-19dc09f5c6f5
github.com/dymensionxyz/sdk-utils v0.1.2-0.20240909101947-e1b483ada9c8
github.com/gogo/protobuf v1.3.3
github.com/golang/protobuf v1.5.4
github.com/gorilla/mux v1.8.1
Expand Down Expand Up @@ -267,7 +267,7 @@ require (
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
github.com/tendermint/go-amino v0.16.0 // indirect
github.com/tidwall/btree v1.5.0 // indirect
github.com/tklauser/go-sysconf v0.3.11 // indirect
github.com/tklauser/numcpus v0.6.0 // indirect
github.com/ulikunitz/xz v0.5.10 // indirect
github.com/vedhavyas/go-subkey v1.0.3 // indirect
github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f // indirect
Expand Down Expand Up @@ -315,12 +315,9 @@ replace (
github.com/CosmWasm/wasmd => github.com/decentrio/wasmd v0.33.0-sdk46.2
github.com/centrifuge/go-substrate-rpc-client/v4 => github.com/availproject/go-substrate-rpc-client/v4 v4.0.12-avail-1.4.0-rc1-5e286e3
github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0
//github.com/dymensionxyz/dymint => github.com/dymensionxyz/dymint v1.2.0-rc01.0.20240906093437-dbc1b5dbf96e
github.com/dymensionxyz/dymint => ../dymint
github.com/evmos/evmos/v12 => github.com/dymensionxyz/evmos/v12 v12.1.6-dymension-v0.3
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.2-alpha.regen.4
github.com/gorilla/rpc => github.com/dymensionxyz/rpc v1.3.1
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
//github.com/tendermint/tendermint => github.com/dymensionxyz/cometbft v0.34.29-0.20240906093934-57cd50faef13
github.com/tendermint/tendermint => ../cometbft
github.com/tendermint/tendermint => github.com/dymensionxyz/cometbft v0.34.29-0.20241008141942-63af9d24107f
)
61 changes: 32 additions & 29 deletions go.sum

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions proto/hub-genesis/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package rollapp.hub_genesis;

import "gogoproto/gogo.proto";
import "hub-genesis/params.proto";
import "hub-genesis/state.proto";
import "hub-genesis/genesis_info.proto";

option go_package = "github.com/dymensionxyz/dymension-rdk/x/hub-genesis/types";

// GenesisState defines the hub-genesis module's genesis state.
message GenesisState {
// params defines all the parameters of the module.
Params params = 1 [ (gogoproto.nullable) = false ];
State state = 2 [(gogoproto.nullable) = false];
repeated uint64 unacked_transfer_seq_nums = 3 [(gogoproto.nullable) = false];

// accounts on the Hub to fund with some bootstrapping transfers
repeated GenesisAccount genesis_accounts = 2 [ (gogoproto.nullable) = false ];
}
22 changes: 22 additions & 0 deletions proto/hub-genesis/genesis_bridge_data.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

syntax = "proto3";
package rollapp.hub_genesis;

import "gogoproto/gogo.proto";
import "cosmos/bank/v1beta1/bank.proto";
import "ibc/applications/transfer/v2/packet.proto";
import "hub-genesis/genesis_info.proto";

option go_package = "github.com/dymensionxyz/dymension-rdk/x/hub-genesis/types";

// GenesisBridgeData is the data struct that is passed to the hub for the
// genesis bridge flow
message GenesisBridgeData {
// genesis_info is the genesis info of the rollapp. used for hub validation
GenesisInfo genesis_info = 1 [ (gogoproto.nullable) = false ];
// native_denom is the native denom of the rollapp. registered on the hub
cosmos.bank.v1beta1.Metadata native_denom = 2
[ (gogoproto.nullable) = false ];
// optional genesis transfer packet data
ibc.applications.transfer.v2.FungibleTokenPacketData genesis_transfer = 3;
}
45 changes: 45 additions & 0 deletions proto/hub-genesis/genesis_info.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

syntax = "proto3";
package rollapp.hub_genesis;

import "gogoproto/gogo.proto";
import "cosmos/bank/v1beta1/bank.proto";
import "hub-genesis/state.proto";

option go_package = "github.com/dymensionxyz/dymension-rdk/x/hub-genesis/types";

// The genesis info of the rollapp, that is passed to the hub for validation.
// it's populated on the InitGenesis of the rollapp
message GenesisInfo {
// checksum used to verify integrity of the genesis file. currently unused
string genesis_checksum = 1;
// unique bech32 prefix
string bech32_prefix = 2;
// native_denom is the base denom for the native token
DenomMetadata native_denom = 3;
// initial_supply is the initial supply of the native token
string initial_supply = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
// accounts on the Hub to fund with some bootstrapping transfers
repeated GenesisAccount genesis_accounts = 5 [ (gogoproto.nullable) = false ];
}

message DenomMetadata {
string display = 1;
string base = 2;
uint32 exponent = 3;
}


// GenesisAccount is a struct for the genesis account for the rollapp
message GenesisAccount {
// amount of coins to be sent to the genesis address
string amount = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
// address is a bech-32 address of the genesis account
string address = 2;
}
24 changes: 21 additions & 3 deletions proto/hub-genesis/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "hub-genesis/params.proto";
import "hub-genesis/state.proto";
import "hub-genesis/genesis_info.proto";

option go_package = "github.com/dymensionxyz/dymension-rdk/x/hub-genesis/types";

Expand All @@ -16,11 +17,17 @@ service Query {
"/dymensionxyz/dymension-rdk/hub-genesis/params";
}

// State returns the state of the genesis event.
rpc State(QueryStateRequest) returns (QueryStateResponse) {
// State returns the state of the genesis event.
rpc State(QueryStateRequest) returns (QueryStateResponse) {
option (google.api.http).get =
"/dymensionxyz/dymension-rdk/hub-genesis/state";
}

// GenesisInfo returns the genesis info of the rollapp.
rpc GenesisInfo(QueryGenesisInfoRequest) returns (QueryGenesisInfoResponse) {
option (google.api.http).get =
"/dymensionxyz/dymension-rdk/hub-genesis/genesis_info";
}
}

// QueryParamsRequest is the request type for the Query/Params RPC method.
Expand All @@ -38,5 +45,16 @@ message QueryStateRequest {}
// QueryStateResponse is the response type for the Query/State RPC method.
message QueryStateResponse {
// state holds the state of the genesis event
State state = 1 [(gogoproto.nullable) = false];
State state = 1 [ (gogoproto.nullable) = false ];
}

// QueryGenesisInfoRequest is the request type for the Query/GenesisInfo RPC
// method.
message QueryGenesisInfoRequest {}

// QueryGenesisInfoResponse is the response type for the Query/GenesisInfo RPC
// method.
message QueryGenesisInfoResponse {
// genesis_info holds the genesis info of the rollapp
GenesisInfo genesis_info = 1 [ (gogoproto.nullable) = false ];
}
22 changes: 5 additions & 17 deletions proto/hub-genesis/state.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,18 @@ syntax = "proto3";
package rollapp.hub_genesis;

import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";

option go_package = "github.com/dymensionxyz/dymension-rdk/x/hub-genesis/types";

// State holds the state of the genesis event
message State {
reserved 1;
reserved 2;
// accounts on the Hub to fund with some bootstrapping transfers
repeated GenesisAccount genesis_accounts = 3 [(gogoproto.nullable) = false];
// the number of genesis transfers for which an ack has not yet been received
uint64 num_unacked_transfers = 5;
// are outboundTransfersEnabled? This is only true if the genesis protocol has finished
reserved 1 to 5;

// are outboundTransfersEnabled? This is only true if the genesis protocol has
// finished
bool outbound_transfers_enabled = 6;
// the canonical transfer port and channel for the hub
PortAndChannel hub_port_and_channel= 7;
PortAndChannel hub_port_and_channel = 7;
}

message PortAndChannel {
Expand All @@ -26,11 +22,3 @@ message PortAndChannel {
// channel
string channel = 2;
}

// GenesisAccount is a struct for the genesis account for the rollapp
message GenesisAccount {
// amount of coins to be sent to the genesis address
cosmos.base.v1beta1.Coin amount = 1 [(gogoproto.nullable) = false];
// address is a bech-32 address of the genesis account
string address = 2;
}
93 changes: 93 additions & 0 deletions server/consensus/processor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package consensus

import (
"fmt"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/gogo/protobuf/proto"
prototypes "github.com/gogo/protobuf/types"
abci "github.com/tendermint/tendermint/abci/types"
)

// ProcessConsensusMessages processes a batch of consensus messages.
// It unpacks each message, checks if it is allowed, executes it, and returns the responses.
func ProcessConsensusMessages(
ctx sdk.Context,
appCodec codec.Codec,
admissionHandler AdmissionHandler,
msgServiceRouter *baseapp.MsgServiceRouter,
consensusMsgs []*prototypes.Any,
) []*abci.ConsensusMessageResponse {
var responses []*abci.ConsensusMessageResponse

for _, anyMsg := range consensusMsgs {
sdkAny := &types.Any{
TypeUrl: "/" + anyMsg.TypeUrl,
Value: anyMsg.Value,
}

var msg sdk.Msg
err := appCodec.UnpackAny(sdkAny, &msg)
if err != nil {
responses = append(responses, &abci.ConsensusMessageResponse{
Response: &abci.ConsensusMessageResponse_Error{
Error: fmt.Errorf("unpack consensus message: %w", err).Error(),
},
})

continue
}

cacheCtx, writeCache := ctx.CacheContext()
err = admissionHandler(cacheCtx, msg)
if err != nil {
responses = append(responses, &abci.ConsensusMessageResponse{
Response: &abci.ConsensusMessageResponse_Error{
Error: fmt.Errorf("consensus message admission: %w", err).Error(),
},
})

continue
}

resp, err := msgServiceRouter.Handler(msg)(cacheCtx, msg)
if err != nil {
responses = append(responses, &abci.ConsensusMessageResponse{
Response: &abci.ConsensusMessageResponse_Error{
Error: fmt.Errorf("execute consensus message: %w", err).Error(),
},
})

continue
}

theType, err := proto.Marshal(resp)
if err != nil {
responses = append(responses, &abci.ConsensusMessageResponse{
Response: &abci.ConsensusMessageResponse_Error{
Error: fmt.Errorf("marshal consensus message response: %w", err).Error(),
},
})

continue
}

anyResp := &prototypes.Any{
TypeUrl: proto.MessageName(resp),
Value: theType,
}

responses = append(responses, &abci.ConsensusMessageResponse{
Response: &abci.ConsensusMessageResponse_Ok{
Ok: anyResp,
},
})

writeCache()
}

return responses
}
25 changes: 15 additions & 10 deletions testutil/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,28 +454,33 @@ func NewRollapp(
keys[hubtypes.StoreKey],
)

denomMetadataMiddleware := denommetadata.NewICS4Wrapper(
app.IBCKeeper.ChannelKeeper,
app.HubKeeper,
app.BankKeeper,
app.HubGenesisKeeper.GetState,
)

app.HubGenesisKeeper = hubgenkeeper.NewKeeper(
appCodec,
keys[hubgentypes.StoreKey],
app.GetSubspace(hubgentypes.ModuleName),
app.AccountKeeper,
app.BankKeeper,
app.MintKeeper,
)

genesisTransfersBlocker := hubgenkeeper.NewICS4Wrapper(denomMetadataMiddleware, app.HubGenesisKeeper)
// The IBC tranfer submit is wrapped with:
var ics4Wrapper ibcporttypes.ICS4Wrapper
// - denom metadata middleware
ics4Wrapper = denommetadata.NewICS4Wrapper(
app.IBCKeeper.ChannelKeeper,
app.HubKeeper,
app.BankKeeper,
app.HubGenesisKeeper.GetState,
)
// - transfer rejecter until genesis bridge phase is finished
ics4Wrapper = hubgenkeeper.NewICS4Wrapper(ics4Wrapper, app.HubGenesisKeeper)

// Create Transfer Keepers
app.TransferKeeper = ibctransferkeeper.NewKeeper(
appCodec,
keys[ibctransfertypes.StoreKey],
app.GetSubspace(ibctransfertypes.ModuleName),
genesisTransfersBlocker,
ics4Wrapper,
app.IBCKeeper.ChannelKeeper,
&app.IBCKeeper.PortKeeper,
app.AccountKeeper,
Expand All @@ -494,9 +499,9 @@ func NewRollapp(
)
transferStack = hubgenkeeper.NewIBCModule(
transferStack,
app.TransferKeeper,
app.HubGenesisKeeper,
app.BankKeeper,
app.IBCKeeper.ChannelKeeper,
)

app.GaslessKeeper = gaslesskeeper.NewKeeper(
Expand Down
Loading

0 comments on commit 3d493d1

Please sign in to comment.