XDPoS/utils: get pool size by key, close XFN-21 (#1666)

This commit is contained in:
Daniel Liu 2025-11-14 18:59:58 +08:00 committed by GitHub
parent 4faefad7a5
commit bd3d30919d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 4 deletions

View file

@ -36,12 +36,12 @@ func (x *XDPoS_v2) GetCurrentRoundFaker() types.Round {
// Utils for test to get current Pool size
func (x *XDPoS_v2) GetVotePoolSizeFaker(vote *types.Vote) int {
return x.votePool.Size(vote)
return x.votePool.Size(vote.PoolKey())
}
// Utils for test to get Timeout Pool Size
func (x *XDPoS_v2) GetTimeoutPoolSizeFaker(timeout *types.Timeout) int {
return x.timeoutPool.Size(timeout)
return x.timeoutPool.Size(timeout.PoolKey())
}
// WARN: This function is designed for testing purpose only!

View file

@ -59,10 +59,10 @@ func (p *Pool) Add(obj PoolObj) (int, map[common.Hash]PoolObj) {
return numOfItems, dataCopy
}
func (p *Pool) Size(obj PoolObj) int {
func (p *Pool) Size(poolKey string) int {
p.lock.RLock()
defer p.lock.RUnlock()
poolKey := obj.PoolKey()
objListKeyed, ok := p.objList[poolKey]
if !ok {
return 0