Skip to content

Commit

Permalink
merged from main.
Browse files Browse the repository at this point in the history
  • Loading branch information
omritoptix committed Nov 21, 2024
2 parents 1c42822 + 64fcbad commit 70ccfc5
Show file tree
Hide file tree
Showing 42 changed files with 1,072 additions and 325 deletions.
41 changes: 36 additions & 5 deletions Contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,29 +181,60 @@ It's encouraged to add golang and cosmos utilities and shared code to [dymension

### Proto and API definition

1. All protobuf fields should have docstrings.
1. All protobuf fields should have docstrings. The docstrings don't need to follow a particular format, but they DO need to explain the field in the context of the business logic.

2. Do not reuse protobuf field numbers when updating protos. When in doubt, reserve the old number and use a new one.
```protobuf
// ~~~~~
// bad (it's plainly obvious and useless)
// Amount of tokens claimed by user.
int claimed_tokens = 1;
// ~~~~~
// good
// Amount of tokens of original denom given to user as calculated by his shares of the alternate denom
int claimed_tokens = 1;
```

2. Do not reuse protobuf field numbers when updating protos. When in doubt, reserve the old number and use a new one. This applies even if the field is new! It just makes things a lot easier to review.

### Comments and documentation

#### General

1. Do not write obvious comments or repeat the code in English.
2. Explain WHY, not how.
3. Do not comment out code. Code is in git. You can comment a github link to a region of code at a particular commit if needed.\
There are several reasons for this: commented out code doesn't survive refactors well, and clutters up searches. It wastes time.

#### Docstrings

Do not worry about making the first word of the docstring on a public object the same as the object. Feel free to disable any linters/highlighters that pick up on it.
1. Do not describe algorithm/logic internals in docstrings. Docstrings should describe contracts and APIs.
2. Do not worry about making the first word of the docstring on a public object the same as the object. Feel free to disable any linters/highlighters that pick up on it.

In other words, we are fine with the first version here:

```go

```go
// bla bla
type Foo struct{ }

// Foo bla bla
type Foo struct{ }
```



### References

- https://github.com/dymensionxyz/sdk-utils : Dymension golang and SDK utils library
- https://github.com/dymensionxyz/gerr-cosmos : Dymension error library
- https://cloud.google.com/apis/design/errors#error_codes : Google error handling guidelines
- https://github.com/uber-go/guide/blob/master/style.md#errors : Uber Style Guide
- https://100go.co/#error-management : 100 Go Mistakes
- https://100go.co/#error-management : 100 Go Mistakes

### Appendix - instructions for AI tools

These are instructions for AI coding tools: LLM model and ML based tools. We want you to play the role of an expert software developer, who has particular expertise in Golang and its nuances and quirks, as well as the Cosmos SDK, IBC protocol, Tendermint/CometBFT algorithms and light clients, and also knowledge of the wider blockchain technology space. Please be terse, and follow all the coding guidelines in this document. Pay particular attention to security, and to make sure that the code is deterministic. Make sure to look at the context of the code to use the right library versions, and to follow typical Cosmos SDK practices like using the SDK math, coin and error handling libraries.
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func New(
bApp.SetCommitMultiStoreTracer(traceStore)
bApp.SetVersion(version.Version)
bApp.SetInterfaceRegistry(interfaceRegistry)
bApp.SetTxEncoder(encodingConfig.TxConfig.TxEncoder())

app := &App{
BaseApp: bApp,
Expand Down
25 changes: 17 additions & 8 deletions app/apptesting/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,24 +116,33 @@ func (s *KeeperTestHelper) CreateSequencerByPubkey(ctx sdk.Context, rollappId st
}

func (s *KeeperTestHelper) PostStateUpdate(ctx sdk.Context, rollappId, seqAddr string, startHeight, numOfBlocks uint64) (lastHeight uint64, err error) {
return s.PostStateUpdateWithDRSVersion(ctx, rollappId, seqAddr, startHeight, numOfBlocks, 1)
return s.PostStateUpdateWithOptions(ctx, rollappId, seqAddr, startHeight, numOfBlocks, 0, 1)
}

func (s *KeeperTestHelper) PostStateUpdateWithDRSVersion(ctx sdk.Context, rollappId, seqAddr string, startHeight, numOfBlocks uint64, drsVersion uint32) (lastHeight uint64, err error) {
return s.PostStateUpdateWithOptions(ctx, rollappId, seqAddr, startHeight, numOfBlocks, 0, drsVersion)
}

func (s *KeeperTestHelper) PostStateUpdateWithRevision(ctx sdk.Context, rollappId, seqAddr string, startHeight, numOfBlocks, revision uint64) (lastHeight uint64, err error) {
return s.PostStateUpdateWithOptions(ctx, rollappId, seqAddr, startHeight, numOfBlocks, revision, 1)
}

func (s *KeeperTestHelper) PostStateUpdateWithOptions(ctx sdk.Context, rollappId, seqAddr string, startHeight, numOfBlocks, revision uint64, drsVersion uint32) (lastHeight uint64, err error) {
var bds rollapptypes.BlockDescriptors
bds.BD = make([]rollapptypes.BlockDescriptor, numOfBlocks)
for k := uint64(0); k < numOfBlocks; k++ {
bds.BD[k] = rollapptypes.BlockDescriptor{Height: startHeight + k, Timestamp: time.Now().UTC(), DrsVersion: drsVersion}
}

updateState := rollapptypes.MsgUpdateState{
Creator: seqAddr,
RollappId: rollappId,
StartHeight: startHeight,
NumBlocks: numOfBlocks,
DAPath: "",
BDs: bds,
Last: false,
Creator: seqAddr,
RollappId: rollappId,
StartHeight: startHeight,
NumBlocks: numOfBlocks,
DAPath: "",
BDs: bds,
RollappRevision: revision,
Last: false,
}
msgServer := rollappkeeper.NewMsgServerImpl(s.App.RollappKeeper)
_, err = msgServer.UpdateState(ctx, &updateState)
Expand Down
27 changes: 27 additions & 0 deletions app/keepers/migration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package keepers

import (
"fmt"
"slices"

sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"golang.org/x/exp/maps"
)

func (a *AppKeepers) MigrateModuleAccountPerms(ctx sdk.Context) {
keys := maps.Keys(maccPerms)
slices.Sort(keys)
for _, moduleName := range keys {
perms := maccPerms[moduleName]

accI := a.AccountKeeper.GetModuleAccount(ctx, moduleName)
if accI == nil {
panic(fmt.Sprintf("module account not been set: %s", moduleName))
}
//nolint:all - we want to panic here
acc := accI.(*authtypes.ModuleAccount)
acc.Permissions = perms
a.AccountKeeper.SetModuleAccount(ctx, acc)
}
}
2 changes: 2 additions & 0 deletions app/upgrades/v4/old_rollapps.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

var (
nimRollappID = "nim_1122-1"
nimAlias = "nim"
nimGenesisInfo = rollapptypes.GenesisInfo{
GenesisChecksum: "cbff2650625cb02240757e76b3c00a0f04ff9347e51ec69eaddbc2b40f2c2335",
Bech32Prefix: "nim",
Expand Down Expand Up @@ -46,6 +47,7 @@ var (
}

mandeRollappID = "mande_18071918-1"
mandeAlias = "mande"
mandeGenesisInfo = rollapptypes.GenesisInfo{
GenesisChecksum: "7f64188a70c2b67230f6af826b33fe35f2a46c63c4838216c3ac50b8ab148632",
Bech32Prefix: "mande",
Expand Down
33 changes: 23 additions & 10 deletions app/upgrades/v4/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
commontypes "github.com/dymensionxyz/dymension/v3/x/common/types"
delayedackkeeper "github.com/dymensionxyz/dymension/v3/x/delayedack/keeper"
delayedacktypes "github.com/dymensionxyz/dymension/v3/x/delayedack/types"
dymnskeeper "github.com/dymensionxyz/dymension/v3/x/dymns/keeper"
incentiveskeeper "github.com/dymensionxyz/dymension/v3/x/incentives/keeper"
incentivestypes "github.com/dymensionxyz/dymension/v3/x/incentives/types"
lightclientkeeper "github.com/dymensionxyz/dymension/v3/x/lightclient/keeper"
Expand Down Expand Up @@ -61,14 +62,15 @@ func CreateUpgradeHandler(
return nil, err
}
migrateModuleParams(ctx, keepers)
keepers.MigrateModuleAccountPerms(ctx)

if err := deprecateCrisisModule(ctx, keepers.CrisisKeeper); err != nil {
return nil, err
}

migrateDelayedAckParams(ctx, keepers.DelayedAckKeeper)
migrateRollappParams(ctx, keepers.RollappKeeper)
if err := migrateRollapps(ctx, keepers.RollappKeeper); err != nil {
if err := migrateRollapps(ctx, keepers.RollappKeeper, keepers.DymNSKeeper); err != nil {
return nil, err
}

Expand Down Expand Up @@ -153,7 +155,7 @@ func setKeyTables(keepers *keepers.AppKeepers) {
}
}

//nolint:staticcheck
//nolint:staticcheck - note this is a cosmos SDK supplied function specifically for upgrading consensus params
func migrateModuleParams(ctx sdk.Context, keepers *keepers.AppKeepers) {
// Migrate Tendermint consensus parameters from x/params module to a dedicated x/consensus module.
baseAppLegacySS := keepers.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable())
Expand All @@ -172,7 +174,7 @@ func migrateRollappGauges(ctx sdk.Context, rollappkeeper *rollappkeeper.Keeper,
return nil
}

func migrateRollapps(ctx sdk.Context, rollappkeeper *rollappkeeper.Keeper) error {
func migrateRollapps(ctx sdk.Context, rollappkeeper *rollappkeeper.Keeper, dymnsKeeper dymnskeeper.Keeper) error {
// in theory, there should be only two rollapps in the store, but we iterate over all of them just in case
list := rollappkeeper.GetAllRollapps(ctx)
for _, oldRollapp := range list {
Expand All @@ -181,6 +183,17 @@ func migrateRollapps(ctx sdk.Context, rollappkeeper *rollappkeeper.Keeper) error
return err
}
rollappkeeper.SetRollapp(ctx, newRollapp)

switch oldRollapp.RollappId {
case nimRollappID:
if err := dymnsKeeper.SetAliasForRollAppId(ctx, oldRollapp.RollappId, nimAlias); err != nil {
return err
}
case mandeRollappID:
if err := dymnsKeeper.SetAliasForRollAppId(ctx, oldRollapp.RollappId, mandeAlias); err != nil {
return err
}
}
}
return nil
}
Expand Down Expand Up @@ -342,13 +355,13 @@ func ConvertOldRollappToNew(oldRollapp rollapptypes.Rollapp) rollapptypes.Rollap
Tagline: "",
FeeDenom: nil,
},
GenesisInfo: genesisInfo,
InitialSequencer: "*",
VmType: rollapptypes.Rollapp_EVM, // EVM for existing rollapps
Launched: true, // Existing rollapps are already launched
PreLaunchTime: nil, // We can just let it be zero. Existing rollapps are already launched.
LivenessEventHeight: 0, // Filled lazily in runtime
LastStateUpdateHeight: 0, // Filled lazily in runtime
GenesisInfo: genesisInfo,
InitialSequencer: "*",
VmType: rollapptypes.Rollapp_EVM, // EVM for existing rollapps
Launched: true, // Existing rollapps are already launched
PreLaunchTime: nil, // We can just let it be zero. Existing rollapps are already launched.
LivenessEventHeight: 0, // Filled lazily in runtime
LivenessCountdownStartHeight: 0, // Filled lazily in runtime
Revisions: []rollapptypes.Revision{{
Number: 0,
StartHeight: 0,
Expand Down
9 changes: 9 additions & 0 deletions app/upgrades/v4/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
Expand Down Expand Up @@ -150,6 +151,8 @@ func (s *UpgradeTestSuite) TestUpgrade() {

s.validateStreamerMigration()

s.validateModulePermissions()

return
},
expPass: true,
Expand All @@ -173,6 +176,12 @@ func (s *UpgradeTestSuite) TestUpgrade() {
}
}

func (s *UpgradeTestSuite) validateModulePermissions() {
// a bit hacky : just check at least one concrete example of a permission upgrade
acc := s.App.AccountKeeper.GetModuleAccount(s.Ctx, rollapptypes.ModuleName)
s.Require().True(acc.HasPermission(authtypes.Burner))
}

func (s *UpgradeTestSuite) validateDelayedAckParamsMigration() error {
delayedackParams := s.App.DelayedAckKeeper.GetParams(s.Ctx)
cond := delayedackParams.DeletePacketsEpochLimit == expectDelayedackDeletePacketsEpochLimit &&
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ replace (
github.com/evmos/ethermint => github.com/dymensionxyz/ethermint v0.22.0-dymension-v0.4.1.0.20241030105541-9d34c1e3378f
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.20241104151037-91342c9a4f57
github.com/osmosis-labs/osmosis/v15 => github.com/dymensionxyz/osmosis/v15 v15.2.1-0.20241121091134-5930c0d433a8

// broken goleveldb
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,8 @@ github.com/dymensionxyz/ibc-go-fork/v7 v7.5.2-0.20241118120532-3f2f353810f3 h1:+
github.com/dymensionxyz/ibc-go-fork/v7 v7.5.2-0.20241118120532-3f2f353810f3/go.mod h1:ktFg5GvKOyrGCqTWtW7Grj5uweU4ZapxrNeVS1CLLbo=
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.20241104151037-91342c9a4f57 h1:OOf6LO3dyMp6eJTJM/of6HAVVNBR9daW9MuycPQzmfk=
github.com/dymensionxyz/osmosis/v15 v15.2.1-0.20241104151037-91342c9a4f57/go.mod h1:sXttKj99Ke160CvjID+5hvOG3TEF/K1k/Eqa37EhRCc=
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/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
19 changes: 16 additions & 3 deletions proto/dymensionxyz/dymension/eibc/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ option go_package = "github.com/dymensionxyz/dymension/v3/x/eibc/types";
message EventDemandOrderCreated {
// order_id is the unique identifier of the demand order.
string order_id = 1;
// fulfillment_id is the unique identifier of the fulfillment.
// price is the price of the demand order.
string price = 2;
// fulfillment_amount is the amount of the fulfillment.
// fee is the fee of the demand order.
string fee = 3;
// Deprecated: orders cannot be created and fulfilled at the same time
// is_fulfilled is the flag indicating whether the order is fulfilled.
bool is_fulfilled = 4;
bool is_fulfilled = 4 [deprecated = true];
// packet_status is the status of the packet.
string packet_status = 5;
// packet_key is the base64 encoded key of the packet.
Expand All @@ -30,6 +31,8 @@ message EventDemandOrderCreated {
string packet_type = 9;
// proof_height is the height of the block when order was created.
uint64 proof_height = 10;
// amount is the amount of the IBC transfer.
string amount = 11;
}

// EventDemandOrderPacketStatusUpdate is emitted when the status of the related packet is updated.
Expand All @@ -48,6 +51,16 @@ message EventDemandOrderFeeUpdated {
string order_id = 1;
// new_fee is the new fee amount set in the order.
string new_fee = 2;
// price is the price of the demand order.
string price = 3;
// packet_status is the status of the packet.
string packet_status = 4;
// rollapp_id is the id of the rollapp.
string rollapp_id = 5;
// proof_height is the height of the block when order was created.
uint64 proof_height = 6;
// amount is the amount of the IBC transfer.
string amount = 7;
}

// EventDemandOrderFulfilled is emitted when the demand order is fulfilled.
Expand Down
15 changes: 10 additions & 5 deletions proto/dymensionxyz/dymension/eibc/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,27 @@ message MsgFulfillOrderAuthorized {
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
// amount is the amount of the IBC transfer
cosmos.base.v1beta1.IntProto amount = 4 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.IntProto"
];
// lp_address is the bech32-encoded address of the account which the authorization was granted from.
// This account will receive the price amount at the finalization phase.
string lp_address = 4;
string lp_address = 5;
// operator_fee_address is an optional bech32-encoded address of an account that would collect the operator_fee_part
// if it's empty, the operator_fee_part will go to the operator_address
string operator_fee_address = 5;
string operator_fee_address = 6;
// expected_fee is the nominal fee set in the order.
string expected_fee = 6;
string expected_fee = 7;
// operator_fee_share is the share of the fee earnings that goes to the operator
// it will be deduced from the fee of the demand order and paid out immediately
cosmos.base.v1beta1.DecProto operator_fee_share = 7 [
cosmos.base.v1beta1.DecProto operator_fee_share = 8 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecProto"
];
// settlement_validated signals if the block behind the demand order needs to be "settlement validated" or not
bool settlement_validated = 8;
bool settlement_validated = 9;
}

message MsgFulfillOrderAuthorizedResponse {}
Expand Down
6 changes: 3 additions & 3 deletions proto/dymensionxyz/dymension/rollapp/rollapp.proto
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ message Rollapp {
// LivenessEventHeight is the height on the HUB of an upcoming liveness event (slash or
// jail against the rollapp). 0 means not set
int64 liveness_event_height = 17;
// The LastStateUpdateHeight HUB height when the last state update was
// received
int64 last_state_update_height = 18;
// The height on the HUB that we start counting liveness from. If the rollapp is not active
// for a long time after this height, a liveness event will happen.
int64 liveness_countdown_start_height = 18;

// Revisions is a list of all the rollapp revisions.
repeated Revision revisions = 19 [ (gogoproto.nullable) = false ];
Expand Down
2 changes: 1 addition & 1 deletion x/eibc/client/cli/authz.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ Examples:
}

flags.AddTxFlagsToCmd(cmd)
cmd.Flags().StringSlice(FlagRollapp, []string{}, "An array of Rollapp IDs allowed")
cmd.Flags().String(FlagRollapp, "", "Allowed Rollapp ID")
cmd.Flags().StringSlice(FlagDenoms, []string{}, "An array of denoms allowed to use")
cmd.Flags().String(FlagSpendLimit, "", "An array of Coins allowed to spend")
cmd.Flags().Bool(FlagSettlementValidated, false, "Settlement validated flag")
Expand Down
Loading

0 comments on commit 70ccfc5

Please sign in to comment.