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

F/rewards generation #61

Closed
wants to merge 7 commits into from
Closed

F/rewards generation #61

wants to merge 7 commits into from

Conversation

maurolacy
Copy link
Contributor

@maurolacy maurolacy commented Oct 30, 2024

Implements finality block reward minting based on inflation rate target, expected number of blocks, and total supply.

@@ -106,6 +107,8 @@ func (s *BabylonSDKTestSuite) Test1ContractDeployment() {
msgUpdateParams := &bbntypes.MsgUpdateParams{
Authority: s.ConsumerApp.BabylonKeeper.GetAuthority(),
Params: bbntypes.Params{
FinalityInflationRate: sdkmath.LegacyNewDecWithPrec(7, 2),
BlocksPerYear: 60 * 60 * 25 * 365 / 5, // 5 seconds per block
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be obtained from x/mint's MintKeeper so the Babylon SDK module does not need to have it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, will refactor.

Comment on lines +4 to +10
type (
CustomMsg struct {
MintRewards *MintRewardsMsg `json:"mint_rewards,omitempty"`
}
// MintRewardsMsg mints block rewards to the staking contract
MintRewardsMsg struct{}
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since these will be triggered upon BeginBlock anyway, wdyt about doing the inflation entirely in BeginBlock rather than going through the "module -> contract -> module" workflow?

Copy link
Contributor Author

@maurolacy maurolacy Oct 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did it this way because I want rewards to be minted only on block finalisation. See babylonlabs-io/babylon-contract#80.

Probably there are simpler ways to detect we have an active FP set that is signing blocks, but this is the strongest one I can see. And yes, it depends on the finality contract.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did it this way because I want rewards to be minted only on block finalisation. See babylonlabs-io/babylon-contract#80.

This is a product design that I'm not entirely sure. IMO, since every block is expected to be finalised anyway, it's okay to mint tokens upon every block. If we don't want to distribute tokens when no block is finalised, we could instead distribute tokens upon finalising a block. Wdyt?

}

func (h CustomMsgHandler) handleTestMsg(ctx sdk.Context, actor sdk.AccAddress, testMsg *contract.TestMsg) ([]sdk.Event, [][]byte, [][]*codectypes.Any, error) {
return []sdk.Event{}, nil, nil, nil
func (h CustomMsgHandler) handleMintRewardsMsg(ctx sdk.Context, actor sdk.AccAddress, _ *contract.MintRewardsMsg) ([]sdk.Event, [][]byte, [][]*codectypes.Any, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah basically this can be invoked inside BeginBlock

Copy link
Contributor Author

@maurolacy maurolacy Oct 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not so sure. What if the FP set is inactive? What if they are not submitting signatures at all, or not enough signatures for finalisation? Etc.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the FP set is inactive? What if they are not submitting signatures at all, or not enough signatures for finalisation? Etc.

We could distribute tokens upon finalising a block. Basically this can be approached in the reward distribution but not reward generation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the problem with this design? Do you think it's too complicated?

In my opinion, it's better to mint rewards related to block finalisation only when such blocks are being effectively finalised. But I can refactor, if we agree it's worth it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those contract <-> blockchain messages are very efficient by the way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is in fact being executed at the end blocker. The current sequence is blockchain -> end_block -> contract -> blockchain.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per offline discussion, it is necessary to mint tokens only upon finalising a block. If the protocol mints tokens only upon BeginBlock, then it's possible that the finality contract admin moves all the inflation at wish, e.g., rugpull, bridging it to other contracts, etc.. This is a security critical issue. Babylon does not have this problem because it 1) the inflation is in the fee collector account controlled by gov prop, rather than sth like a contract admin, and 2) people only recognise BTC stake finalised prefix as finalised, but this might not be the case in consumer chains.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After discussion, closed in favour of #62.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we document this in a ADR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. ADR is to come.

@maurolacy maurolacy mentioned this pull request Nov 7, 2024
3 tasks
@maurolacy maurolacy closed this Nov 7, 2024
maurolacy added a commit that referenced this pull request Nov 8, 2024
Thin layer impl of the finalisation block rewards generation. Supersedes
/ replaces #61
@maurolacy maurolacy deleted the f/rewards-generation branch November 8, 2024 04:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants