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

[staking] make transfering ownership back valid #4319

Merged
merged 1 commit into from
Jul 2, 2024

Conversation

envestcc
Copy link
Member

@envestcc envestcc commented Jul 1, 2024

Description

  1. ensure that there is no conflict between the owner and identifier during candidateRegister and candidateTransferOwnership.
  2. can transfer the candidate back to the previous owner.

Fixes #(issue)

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

@envestcc envestcc requested review from CoderZhi, dustinxie, Liuhaai and a team as code owners July 1, 2024 10:14
id, err := p.generateCandidateID(owner, blkCtx.BlockHeight, csm)
if err != nil {
// cannot collide with existing identifier
if csm.GetByIdentifier(owner) != nil {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is to ensure that the owner is not used as an ID for any existed candidate.

failureStatus: iotextypes.ReceiptStatus_ErrCandidateAlreadyExist,
}
}
candID = id
if csm.GetByIdentifier(candID) != nil {
Copy link
Member Author

Choose a reason for hiding this comment

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

The reason for deletion here is that there is no need to check for ID conflicts anymore, as this is already ensured in generateCandidateID.

failureStatus: iotextypes.ReceiptStatus_ErrCandidateAlreadyExist,
}
}
candID = id
if csm.GetByIdentifier(candID) != nil {
id, err := p.generateCandidateID(owner, blkCtx.BlockHeight, csm)
Copy link
Member

@dustinxie dustinxie Jul 1, 2024

Choose a reason for hiding this comment

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

by moving the conflict check ahead, generateCandidateID will always return the original owner address, the for loop will never enter. this would cause 1 address can register only once

as discussed last evening, should remove the 3 lines

if isValidID(owner) {
		return owner, nil
	}

and let for loop to generate a random identifier. Then, the same address (after transfer ownership) can register again

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, the first point is correct that only owner address will be used as identifier.
You might miss some part of the discussion. After the hard fork, preventing the same address to generate a new candidate is on purpose, to prevent confusion: CandidateByOwner and CandidateByIdentifier returns two different candidates given the same address. The reason I didn't ask @envestcc to delete the logic in generateCandidateID in this PR is that it really doesn't matter to keep it.

@envestcc envestcc merged commit 6c7e207 into iotexproject:master Jul 2, 2024
2 checks passed
@envestcc envestcc deleted the fix-transfer branch July 2, 2024 08:22
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.

3 participants