-
Notifications
You must be signed in to change notification settings - Fork 324
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] persist cand center to statedb and patchfile #3661
Conversation
d5a0db6
to
69fc63f
Compare
func (cb *candBase) ownersList() CandidateList { | ||
cb.lock.RLock() | ||
defer cb.lock.RUnlock() | ||
if len(cb.owners) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zhi: delete
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if ownerList()
is called before recordOwner()
, cb.owners
is nil, so need to populate it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
} | ||
for i, d := range cb.owners { | ||
if d.Owner.String() == c.Owner.String() { | ||
cb.owners[i] = c.Clone() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zhi: if nameMap
and operatorMap
could be type of map, why owners
is a list?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
b/c outside calls GetByName()
and GetByOperator()
, map better suits that need.
owners
is only updated by candidate update/register tx, a list is easier and suffices for the use-case
delCandBucketIndex(addr address.Address, index uint64) error | ||
putCandidate(*Candidate) error | ||
delCandidate(address.Address) error | ||
putCandidateList(CandidateList, []byte) error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zhi: why putCandidateList
is a function of interface?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
b/c we are calling it from the CandidateStateManager
interface, for the same reason why putCandidate
is a func of interface here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to add. They are under the same pkg
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -684,6 +684,7 @@ func (p *Protocol) handleCandidateRegister(ctx context.Context, act *action.Cand | |||
if err := csm.Upsert(c); err != nil { | |||
return log, nil, csmErrorToHandleError(owner.String(), err) | |||
} | |||
csm.DirtyView().candCenter.base.recordOwner(c) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zhi: put into csm.Upsert
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also hesitate to do this, but we need to change to Upsert(*Candidate, bool)
- a bool flag to indicate a specific purpose (save the correct candidate) is kind of weird here
- too many changes
Let me know if you have a better option, or Upsert(*Candidate, bool)
is fine, I can modify
action/protocol/staking/protocol.go
Outdated
var ( | ||
_nameKey = []byte("name") | ||
_operatorKey = []byte("oper") | ||
_ownerKey = []byte("owne") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zhi: using names, operators, owners
won't take too many disk spaces
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, disk space is not a concern here
I prefer for these meta keys to have the same length, similar to namespace in filedaov2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
im also confused here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
action/protocol/staking/protocol.go
Outdated
name := base.candsInNameMap() | ||
op := base.candsInOperatorMap() | ||
owners := base.ownersList() | ||
if len(name) == 0 || len(op) == 0 || len(owners) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zhi: invalid checking
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for our real use-case, it is true.
I'd just keep it for safety
blockchain/config.go
Outdated
@@ -76,6 +81,7 @@ var ( | |||
ChainDBPath: "/var/data/chain.db", | |||
TrieDBPatchFile: "/var/data/trie.db.patch", | |||
TrieDBPath: "/var/data/trie.db", | |||
CandsMapPatchFile: "/var/data/candsmap.patch", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@CoderZhi is this name good? it will create file like candsmap.patch-19xxxx
|
||
package staking | ||
|
||
func (cb *candBase) clone() *candBase { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't create two files for same class.Create another class if a new file is wanted
Codecov Report
@@ Coverage Diff @@
## master #3661 +/- ##
==========================================
- Coverage 74.95% 74.47% -0.49%
==========================================
Files 269 269
Lines 23819 23925 +106
==========================================
- Hits 17854 17818 -36
- Misses 5039 5174 +135
- Partials 926 933 +7
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
action/protocol/staking/protocol.go
Outdated
@@ -81,6 +83,9 @@ type ( | |||
candBucketsIndexer *CandidatesBucketsIndexer | |||
voteReviser *VoteReviser | |||
patch *PatchStore | |||
_nameHash string | |||
_opHash string | |||
_ownerHash string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
debug code, will be removed before check-in
action/protocol/staking/protocol.go
Outdated
println("======= same owner list", p._ownerHash) | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
debug code, will be removed before check-in
action/protocol/staking/protocol.go
Outdated
BootstrapCandidates: cfg.BootstrapCandidates, | ||
BootstrapCandidates: cfg.Staking.BootstrapCandidates, | ||
PersistCandsMapBlock: cfg.PersistCandsMapBlock, | ||
CandsMapPatchDir: cfg.CandsMapPatchDir, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete
},
patch: NewPatchStore(cfg.CandsMapPatchDir),
action/protocol/staking/protocol.go
Outdated
if p.patch == nil { | ||
p.patch = NewPatchStore(p.config.CandsMapPatchDir) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete
blockchain/config.go
Outdated
@@ -28,6 +28,7 @@ type ( | |||
ChainDBPath string `yaml:"chainDBPath"` | |||
TrieDBPatchFile string `yaml:"trieDBPatchFile"` | |||
TrieDBPath string `yaml:"trieDBPath"` | |||
CandsMapPatchDir string `yaml:"candsMapPatchDir"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
StakingPatchDir string
yaml:"stakingPatchDir"`
blockchain/config.go
Outdated
@@ -67,6 +68,8 @@ type ( | |||
WorkingSetCacheSize uint64 `yaml:"workingSetCacheSize"` | |||
// StreamingBlockBufferSize | |||
StreamingBlockBufferSize uint64 `yaml:"streamingBlockBufferSize"` | |||
// PersistCandsMapBlock is the block to persist candidates map | |||
PersistCandsMapBlock uint64 `yaml:"persistCandsMapBlock"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PersistStakingPatchBlock
func (cb *candBase) ownersList() CandidateList { | ||
cb.lock.RLock() | ||
defer cb.lock.RUnlock() | ||
return cb.owners |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for read, if we do clone in https://github.com/iotexproject/iotex-core/pull/3661/files#diff-17d187e581661db50bb29a2354c11c2d8e05245a5d4ad4a27f9619f6affb6ee7R56, https://github.com/iotexproject/iotex-core/pull/3661/files#diff-17d187e581661db50bb29a2354c11c2d8e05245a5d4ad4a27f9619f6affb6ee7R42, what about here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name, op := candsInNameMap(), candsInOperatorMap()
name, op will be serialized and saved to DB, so actually no need to clone()
for the 2 places you mentioned, clone()
is for safety I believe since we don't want to touch the *Candidate
in these 2 maps.
for ownerList
, the only use of it is to serialize and save to DB, so I think no need to clone the list here (b/c when we add a *Candidate
to ownerList
, we make a clone, L77 below)
if err := d.Validate(); err != nil { | ||
return err | ||
} | ||
cb.nameMap[d.Name] = d |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for write, if we do clone in https://github.com/iotexproject/iotex-core/pull/3661/files#diff-17d187e581661db50bb29a2354c11c2d8e05245a5d4ad4a27f9619f6affb6ee7R72 and https://github.com/iotexproject/iotex-core/pull/3661/files#diff-17d187e581661db50bb29a2354c11c2d8e05245a5d4ad4a27f9619f6affb6ee7R77, we may do the same thing in https://github.com/iotexproject/iotex-core/pull/3661/files#diff-17d187e581661db50bb29a2354c11c2d8e05245a5d4ad4a27f9619f6affb6ee7R77 and https://github.com/iotexproject/iotex-core/pull/3661/files#diff-17d187e581661db50bb29a2354c11c2d8e05245a5d4ad4a27f9619f6affb6ee7R97 as well
} | ||
cb.operatorMap[d.Operator.String()] = d | ||
} | ||
cb.owners = owners |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
owners
at right side is created by de-serializing data read from DB, it is a new instance of list, so no need to clone here
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
Description
Please include a summary of the changes and the related issue. Please also include relevant motivation and context. List any dependencies that are required for this change.
Fixes #(issue)
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
Checklist: