Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add events for sequencer rewards #335

Merged
merged 36 commits into from
Mar 23, 2024
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
8e72ba0
cleanup before changes
mtsitrin Feb 29, 2024
b8915c8
genereated new proto
mtsitrin Mar 13, 2024
3a4224d
added logic
mtsitrin Mar 13, 2024
695fa8c
starting writing tests
mtsitrin Mar 13, 2024
64ff826
moved test app to be part of this repo
mtsitrin Mar 13, 2024
acb80af
minting UT
mtsitrin Mar 13, 2024
8c2444d
renamed field
mtsitrin Mar 13, 2024
a25f7b8
fixed inflation change. added UT
mtsitrin Mar 13, 2024
c86de44
fixed test and mint hooks
mtsitrin Mar 14, 2024
4c6b8cb
removed readme for now
mtsitrin Mar 14, 2024
04c6685
Removed epochProvisionQueries
mtsitrin Mar 14, 2024
ae4ec48
cleanup and fixed tests
mtsitrin Mar 14, 2024
bf199e2
moved test app to seperate package
mtsitrin Mar 14, 2024
293b0f0
linter
mtsitrin Mar 14, 2024
eccb825
adding annual epoch by default
mtsitrin Mar 14, 2024
958571e
validating epoch identifiers exists
mtsitrin Mar 14, 2024
fbc2d8f
fixed init genesis order
mtsitrin Mar 14, 2024
9c1282d
clearing expected keepers from sequencer module
mtsitrin Mar 14, 2024
e309c4c
rollapp loads sequencers from dymint on beginBlock
mtsitrin Mar 14, 2024
04797d5
removed sequencers tx
mtsitrin Mar 14, 2024
70029e8
more cleanup
mtsitrin Mar 14, 2024
9eed0a3
setting const proposer for UT
mtsitrin Mar 14, 2024
25d084b
renamed methods to sequencer instead of validator
mtsitrin Mar 14, 2024
6b43ebf
fixed dist UT
mtsitrin Mar 14, 2024
86d23e9
fixed compilation with rollapp-evm
mtsitrin Mar 14, 2024
70a418e
fixed linter
mtsitrin Mar 14, 2024
69bc565
add sequencer rewards event
mtsitrin Mar 17, 2024
edbf425
uncommented some validation code
mtsitrin Mar 17, 2024
6ad2f94
better checking for genesis block
mtsitrin Mar 17, 2024
2d79ce3
fixed linter
mtsitrin Mar 18, 2024
66cc84c
getting operator addr on initchain
mtsitrin Mar 18, 2024
7d4bebe
fixed UT
mtsitrin Mar 18, 2024
2c113bd
Merge branch 'refactor/sequencers_module' into 51-add-events-for-sequ…
mtsitrin Mar 19, 2024
1a9c32a
Merge branch 'main' into 51-add-events-for-sequencer-rewards
mtsitrin Mar 20, 2024
43687e0
changed to errorsmod
mtsitrin Mar 20, 2024
228b8b0
Update x/dist/keeper/proposal_handler.go
omritoptix Mar 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions x/dist/keeper/allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
disttypes "github.com/dymensionxyz/dymension-rdk/x/dist/types"
)

// AllocateTokens handles distribution of the collected fees
Expand All @@ -28,21 +29,28 @@ func (k Keeper) AllocateTokens(ctx sdk.Context, blockProposer sdk.ConsAddress) {

/* ---------------------------- Pay the proposer ---------------------------- */
// calculate and pay proposer reward
proposerValidator, found := k.seqKeeper.GetSequencerByConsAddr(ctx, blockProposer)
proposer, found := k.seqKeeper.GetSequencerByConsAddr(ctx, blockProposer)
if !found {
logger.Error("failed to find the validator for this block. reward not allocated")
} else {
proposerReward := feesCollected.MulDecTruncate(k.GetBaseProposerReward(ctx))
proposerCoins, proposerRemainder := proposerReward.TruncateDecimal()
if !proposerCoins.IsZero() {
err := k.AllocateTokensToSequencer(ctx, proposerValidator, proposerCoins)
err := k.AllocateTokensToSequencer(ctx, proposer, proposerCoins)
if err != nil {
logger.Error("failed to reward the proposer")
}

remainingFees = feesCollected.Sub(proposerReward).Add(proposerRemainder...)

//TODO: emit event for sequencer reward
// update outstanding rewards
ctx.EventManager().EmitEvent(
sdk.NewEvent(
disttypes.EventTypeDistSequencerRewards,
sdk.NewAttribute(sdk.AttributeKeyAmount, proposerCoins.String()),
sdk.NewAttribute(disttypes.AttributeKeySequencer, proposer.GetOperator().String()),
),
)
}
}

Expand Down
8 changes: 5 additions & 3 deletions x/dist/keeper/proposal_handler.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package keeper

import (
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
)

Expand All @@ -12,9 +14,9 @@ func HandleCommunityPoolSpendProposal(ctx sdk.Context, k Keeper, p *types.Commun
return addrErr
}

// if k.bankKeeper.BlockedAddr(recipient) {
// return errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive external funds", p.Recipient)
// }
if k.bankKeeper.BlockedAddr(recipient) {
omritoptix marked this conversation as resolved.
Show resolved Hide resolved
return errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive external funds", p.Recipient)
}
omritoptix marked this conversation as resolved.
Show resolved Hide resolved

err := k.DistributeFromFeePool(ctx, p.Amount, recipient)
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions x/dist/types/events.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package types

// Minting module event types.
const (
EventTypeDistSequencerRewards = "sequencer_rewards"
AttributeKeySequencer = "sequencer"
)
10 changes: 6 additions & 4 deletions x/hub-genesis/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package keeper
import (
"context"

errorsmod "cosmossdk.io/errors"

danwt marked this conversation as resolved.
Show resolved Hide resolved
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
tenderminttypes "github.com/cosmos/ibc-go/v6/modules/light-clients/07-tendermint/types"
Expand Down Expand Up @@ -31,16 +33,16 @@ func (m msgServer) TriggerGenesisEvent(goCtx context.Context, msg *types.MsgHubG

_, clientState, err := m.channelKeeper.GetChannelClientState(ctx, "transfer", msg.ChannelId)
if err != nil {
return nil, sdkerrors.Wrapf(types.ErrInvalidGenesisChannelId, "failed to get client state for channel %s", msg.ChannelId)
return nil, errorsmod.Wrapf(types.ErrInvalidGenesisChannelId, "failed to get client state for channel %s", msg.ChannelId)
}

tmClientState, ok := clientState.(*tenderminttypes.ClientState)
if !ok {
return nil, sdkerrors.Wrapf(types.ErrInvalidGenesisChannelId, "expected tendermint client state, got %T", clientState)
return nil, errorsmod.Wrapf(types.ErrInvalidGenesisChannelId, "expected tendermint client state, got %T", clientState)
}

if tmClientState.GetChainID() != msg.HubId {
return nil, sdkerrors.Wrapf(types.ErrInvalidGenesisChainId, "channel %s is connected to chain ID %s, expected %s",
return nil, errorsmod.Wrapf(types.ErrInvalidGenesisChainId, "channel %s is connected to chain ID %s, expected %s",
msg.ChannelId, tmClientState.GetChainID(), msg.HubId)
}

Expand All @@ -53,7 +55,7 @@ func (m msgServer) TriggerGenesisEvent(goCtx context.Context, msg *types.MsgHubG
hub := types.NewHub(msg.HubId, msg.ChannelId)

if err := m.lockRollappGenesisTokens(ctx, hub.ChannelId); err != nil {
return nil, sdkerrors.Wrapf(types.ErrLockingGenesisTokens, "failed to lock tokens: %v", err)
return nil, errorsmod.Wrapf(types.ErrLockingGenesisTokens, "failed to lock tokens: %v", err)
}

// we save the hub in order to prevent the genesis event from being triggered again
Expand Down
8 changes: 5 additions & 3 deletions x/hub-genesis/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/dymensionxyz/dymension-rdk/testutil/utils"
"github.com/stretchr/testify/suite"

errorsmod "cosmossdk.io/errors"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/dymensionxyz/dymension-rdk/testutil/app"
"github.com/dymensionxyz/dymension-rdk/testutil/ibctest"
Expand Down Expand Up @@ -135,7 +137,7 @@ func (suite *HubGenesisMsgServerTestSuite) TestTriggerGenesisEvent() {
rollappBalanceAfter: initialRollappBalance,
rollappEscrowBalanceAfter: sdk.NewCoin(rollappDenom, sdk.NewInt(0)),
hubPersisted: false,
expErr: sdkerrors.Wrapf(types.ErrInvalidGenesisChannelId, "failed to get client state for channel %s", "invalid-channel"),
expErr: errorsmod.Wrapf(types.ErrInvalidGenesisChannelId, "failed to get client state for channel %s", "invalid-channel"),
}, {
name: "invalid rollapp genesis event - invalid chain id",
genesisState: &types.GenesisState{
Expand All @@ -152,7 +154,7 @@ func (suite *HubGenesisMsgServerTestSuite) TestTriggerGenesisEvent() {
rollappBalanceAfter: initialRollappBalance,
rollappEscrowBalanceAfter: sdk.NewCoin(rollappDenom, sdk.NewInt(0)),
hubPersisted: false,
expErr: sdkerrors.Wrapf(types.ErrInvalidGenesisChainId, "channel %s is connected to chain ID %s, expected %s", path.EndpointA.ChannelID, "invalid-chain-id", path.EndpointB.Chain.ChainID),
expErr: errorsmod.Wrapf(types.ErrInvalidGenesisChainId, "channel %s is connected to chain ID %s, expected %s", path.EndpointA.ChannelID, "invalid-chain-id", path.EndpointB.Chain.ChainID),
}, {
name: "invalid rollapp genesis event - module account has no coins",
genesisState: &types.GenesisState{
Expand All @@ -174,7 +176,7 @@ func (suite *HubGenesisMsgServerTestSuite) TestTriggerGenesisEvent() {
suite.Require().NoError(err)
},
hubPersisted: false,
expErr: sdkerrors.Wrapf(types.ErrLockingGenesisTokens, "failed to lock tokens: %v", types.ErrGenesisNoCoinsOnModuleAcc),
expErr: errorsmod.Wrapf(types.ErrLockingGenesisTokens, "failed to lock tokens: %v", types.ErrGenesisNoCoinsOnModuleAcc),
},
}

Expand Down
7 changes: 4 additions & 3 deletions x/hub-genesis/types/message_hub_genesis_event.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types

import (
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
Expand Down Expand Up @@ -41,15 +42,15 @@ func (msg *MsgHubGenesisEvent) GetSignBytes() []byte {
func (msg *MsgHubGenesisEvent) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Address)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid address (%s)", err)
return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid address (%s)", err)
}

if msg.ChannelId == "" {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "channel id cannot be empty")
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "channel id cannot be empty")
}

if msg.HubId == "" {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "hub id cannot be empty")
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "hub id cannot be empty")
}

return nil
Expand Down
Loading