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

[api] fix estimateGas for migrateStake #4377

Merged
merged 2 commits into from
Sep 3, 2024

Conversation

envestcc
Copy link
Member

Description

When estimating the gas for the MigrateStake transaction, the amount of the native bucket is not returned to the sender. If the sender's balance is insufficient for the bucket amount, an insufficient balance for transfer error will be returned.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • [] make test
  • [] fullsync
  • [] Other test (please specify)

Test Configuration:

  • Firmware version:
  • Hardware:
  • Toolchain:
  • SDK:

Checklist:

  • [] My code follows the style guidelines of this project
  • [] I have performed a self-review of my code
  • [] I have commented my code, particularly in hard-to-understand areas
  • [] I have made corresponding changes to the documentation
  • [] My changes generate no new warnings
  • [] I have added tests that prove my fix is effective or that my feature works
  • [] New and existing unit tests pass locally with my changes
  • [] Any dependent changes have been merged and published in downstream modules

exec, err := staking.FindProtocol(core.registry).ConstructExecution(ctx, ms, core.sf)
if err != nil {
return 0, err
}
gas, err := core.EstimateExecutionGasConsumption(ctx, exec, caller)
gas, err := core.EstimateExecutionGasConsumption(ctx, exec, caller, protocol.WithSimulatePreOpt(func(sm protocol.StateManager) error {
Copy link
Member

Choose a reason for hiding this comment

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

can we do this by adding a new ConstructExecutionForSimulation?

func ConstructExecutionForSimulation() {
	ConstructExecution()
	// add amount to the sender account
	sender, err := accountutil.LoadAccount(sm, caller)
	if err != nil {
		return err
	}
	if err = sender.AddBalance(exec.Amount()); err != nil {
		return err
	}
	return accountutil.StoreAccount(sm, caller, sender)
}

this way we can avoid adding SimulationConfig, which works but like an overkill

Copy link
Member Author

Choose a reason for hiding this comment

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

already discussed offline

Copy link

sonarcloud bot commented Sep 2, 2024

@envestcc envestcc merged commit de08f6b into iotexproject:master Sep 3, 2024
3 checks passed
envestcc added a commit that referenced this pull request Sep 3, 2024
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.

4 participants