Skip to content

Commit

Permalink
public txpool size
Browse files Browse the repository at this point in the history
  • Loading branch information
Lawliet-Chan committed Sep 20, 2024
1 parent c660b3f commit 3580a3a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}) {
Expand Down
5 changes: 3 additions & 2 deletions core/txpool/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 9 additions & 5 deletions core/txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type TxPool struct {

nodeType int

poolSize uint64
capacity int
TxnMaxSize int

unpackedTxns IunpackedTxns
Expand All @@ -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),
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3580a3a

Please sign in to comment.