From 3580a3a7efc12472d7cbcd4ce3bbfa66d7aca2c6 Mon Sep 17 00:00:00 2001 From: Lawliet-Chan <1576710154@qq.com> Date: Fri, 20 Sep 2024 09:53:47 +0800 Subject: [PATCH] public txpool size --- config/config.go | 4 ++-- core/txpool/interface.go | 5 +++-- core/txpool/txpool.go | 14 +++++++++----- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/config/config.go b/config/config.go index 738a9a3a..4c72ee20 100644 --- a/config/config.go +++ b/config/config.go @@ -80,8 +80,8 @@ type BlockchainConf struct { } type TxpoolConf struct { - PoolSize uint64 `toml:"pool_size"` - TxnMaxSize int `toml:"txn_max_size"` + PoolSize int `toml:"pool_size"` + TxnMaxSize int `toml:"txn_max_size"` } func LoadTomlConf(fpath string, cfg interface{}) { diff --git a/core/txpool/interface.go b/core/txpool/interface.go index 6ce1f003..5f0e679a 100644 --- a/core/txpool/interface.go +++ b/core/txpool/interface.go @@ -6,8 +6,9 @@ import ( ) type ItxPool interface { - // PoolSize return pool Size of txpool - PoolSize() uint64 + // Capacity return pool Size of txpool + Capacity() int + Size() int WithBaseCheck(checkFn TxnChecker) ItxPool WithTripodCheck(tripodName string, checker TxnChecker) ItxPool diff --git a/core/txpool/txpool.go b/core/txpool/txpool.go index fc3646ad..2c80aeb3 100644 --- a/core/txpool/txpool.go +++ b/core/txpool/txpool.go @@ -12,7 +12,7 @@ type TxPool struct { nodeType int - poolSize uint64 + capacity int TxnMaxSize int unpackedTxns IunpackedTxns @@ -26,7 +26,7 @@ func NewTxPool(nodeType int, cfg *TxpoolConf) *TxPool { tp := &TxPool{ nodeType: nodeType, - poolSize: cfg.PoolSize, + capacity: cfg.PoolSize, TxnMaxSize: cfg.TxnMaxSize, unpackedTxns: ordered, baseChecks: make([]TxnCheckFn, 0), @@ -48,8 +48,12 @@ func (tp *TxPool) withDefaultBaseChecks() *TxPool { return tp } -func (tp *TxPool) PoolSize() uint64 { - return tp.poolSize +func (tp *TxPool) Capacity() int { + return tp.capacity +} + +func (tp *TxPool) Size() int { + return tp.unpackedTxns.Size() } func (tp *TxPool) WithBaseCheck(tc TxnChecker) ItxPool { @@ -158,7 +162,7 @@ func (tp *TxPool) NecessaryCheck(stxn *SignedTxn) (err error) { } func (tp *TxPool) checkPoolLimit(*SignedTxn) error { - if uint64(tp.unpackedTxns.Size()) >= tp.poolSize { + if tp.unpackedTxns.Size() >= tp.capacity { return PoolOverflow } return nil