iotexproject / iotex-core

Official implementation of IoTeX blockchain protocol in Go. An ultra-efficient EVM blockchain offering 1000 TPS with instant 1-block finality. Perfect for DeFi, DePIN tokenomics, Identities, and any trusted logic requiring Web3 composability
https://iotex.io
Apache License 2.0
1.55k stars 324 forks source link

[staking] ReadState API support Candidate ID #4276

Closed envestcc closed 3 months ago

envestcc commented 4 months ago

Description

Due to the introduction of a new ID as a unique identifier by the Candidate, the following modifications need to be made to the API:

It's based on https://github.com/iotexproject/iotex-proto/pull/151

Type of change

Please delete options that are not relevant.

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

Test Configuration:

Checklist:

dustinxie commented 3 months ago

can you rebase this PR? i think lots of code has already checked in

CoderZhi commented 3 months ago

As discussed offline, let's change the logic of creating delegate to:

if delegateByOwner(creator) != nil {
    return duplicate error
}
id := creator
while delegateByIdentifier(id) != nil { // up to N = 1000 times
    id = hash(id)
}
create delegate with id

such that an account who doesn't own a delegate could always create a delegate.

Make sure the scenario works in this PR.

dustinxie commented 3 months ago

Member

As discussed offline, let's change the logic of creating delegate to:

if delegateByOwner(creator) != nil {
    return duplicate error
}
id := creator
while delegateByIdentifier(id) != nil { // up to N = 1000 times
    id = hash(id)
}
create delegate with id

such that an account who doesn't own a delegate could always create a delegate.

Make sure the scenario works in this PR.

agreed, discussed offline we can use logic similar to id = hash(address, blockheight)

sonarcloud[bot] commented 3 months ago

Quality Gate Failed Quality Gate failed

Failed conditions
24.9% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud