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

feat: add ConsumeGas for delayed staking #102

Closed
3 of 7 tasks
dongsam opened this issue Sep 9, 2021 · 1 comment · Fixed by #175
Closed
3 of 7 tasks

feat: add ConsumeGas for delayed staking #102

dongsam opened this issue Sep 9, 2021 · 1 comment · Fixed by #175
Assignees

Comments

@dongsam
Copy link
Contributor

dongsam commented Sep 9, 2021

Summary

Problem Definition

As Delayed Staking is introduced into F1, add staking in the queue and runs in end-of-epoch, so the gas of MsgStake is consumed less than the total computation amount, which can adversely affect the chain.

Proposal

Therefore, it is necessary to add the average amount of gas to be calculated at the end-of-epoch of the end-block to the params and add the gas to the MsgStake step in the same way as ctx.GasMeter().ConsumeGas(params.EndBlockStakingGasFee, "EndBlockStakingGasFee")

Tasks

  • add ConsumeGas logic for MsgStake on msg_server
  • Calculate average amount of gas to be consumed at the end-of-epoch for QueuedStaking
  • add params.delayed_staking_gas_fee

References


For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
@dongsam dongsam added this to the Farming F1 v1.0 milestone Sep 14, 2021
@jaybxyz jaybxyz changed the title add ConsumeGas for delayed staking feat: add ConsumeGas for delayed staking Oct 5, 2021
@hallazzang
Copy link
Contributor

Using this test code:

func (suite *KeeperTestSuite) TestEstimateGasUsage_Stake() {
	for i := 1; i <= 10; i++ {
		suite.SetRatioPlan(uint64(i), suite.addrs[4], map[string]string{
			denom1: "0.5",
			denom2: "0.5",
		}, "0.01")
	}

	addrs := simapp.AddTestAddrs(suite.app, suite.ctx, 10000, sdk.ZeroInt())
	for i, addr := range addrs {
		err := simapp.FundAccount(suite.app.BankKeeper, suite.ctx, addr, sdk.NewCoins(
			sdk.NewInt64Coin(denom1, 100000000), sdk.NewInt64Coin(denom2, 100000000)))
		suite.Require().NoError(err)
		if i > 0 {
			suite.Stake(addr, sdk.NewCoins(sdk.NewInt64Coin(denom1, 100000000), sdk.NewInt64Coin(denom2, 100000000)))
		}
	}

	suite.AdvanceEpoch()
	suite.AdvanceEpoch()

	for i := 0; i < 3; i++ {
		suite.Stake(addrs[0], sdk.NewCoins(sdk.NewInt64Coin(denom1, 10000000), sdk.NewInt64Coin(denom2, 10000000)))

		err := suite.keeper.AllocateRewards(suite.ctx)
		suite.Require().NoError(err)

		suite.ctx = suite.ctx.WithGasMeter(sdk.NewInfiniteGasMeter())
		suite.keeper.ProcessQueuedCoins(suite.ctx)
		fmt.Println(suite.ctx.GasMeter().GasConsumed())
	}
}

It seems it takes about 60,000 gases to handle queued staking(with withdrawing rewards) per staking coin denom.

hallazzang added a commit to hallazzang/farming that referenced this issue Oct 15, 2021
dongsam added a commit that referenced this issue Oct 15, 2021
* feat: impose DelayedStakingGasFee when staking

See #102 for details

* chore: Update x/farming/types/params_test.go

Co-authored-by: dongsam <dongsamb@gmail.com>
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 a pull request may close this issue.

2 participants