From bd3d30919d4c926a4285962a5b50737e385005d8 Mon Sep 17 00:00:00 2001 From: Daniel Liu <139250065@qq.com> Date: Fri, 14 Nov 2025 18:59:58 +0800 Subject: [PATCH] XDPoS/utils: get pool size by key, close XFN-21 (#1666) --- consensus/XDPoS/engines/engine_v2/testing_utils.go | 4 ++-- consensus/XDPoS/utils/pool.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/consensus/XDPoS/engines/engine_v2/testing_utils.go b/consensus/XDPoS/engines/engine_v2/testing_utils.go index 92c4dd7119..36d6164220 100644 --- a/consensus/XDPoS/engines/engine_v2/testing_utils.go +++ b/consensus/XDPoS/engines/engine_v2/testing_utils.go @@ -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! diff --git a/consensus/XDPoS/utils/pool.go b/consensus/XDPoS/utils/pool.go index 399db859e8..8792503b7b 100644 --- a/consensus/XDPoS/utils/pool.go +++ b/consensus/XDPoS/utils/pool.go @@ -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