Skip to content

Commit

Permalink
chore(txpool): rename ConsumptionBlocks to ConsumptionWindow
Browse files Browse the repository at this point in the history
  • Loading branch information
b00f committed Oct 20, 2024
1 parent 370d882 commit 4b77035
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
10 changes: 6 additions & 4 deletions txpool/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import (
)

type Config struct {
MaxSize int `toml:"max_size"`
Fee *FeeConfig `toml:"fee"`
ConsumptionBlocks uint32 `toml:"-"` // Private configs
MaxSize int `toml:"max_size"`
Fee *FeeConfig `toml:"fee"`

// Private configs
ConsumptionWindow uint32 `toml:"-"`
}

type FeeConfig struct {
Expand All @@ -20,7 +22,7 @@ func DefaultConfig() *Config {
return &Config{
MaxSize: 1000,
Fee: DefaultFeeConfig(),
ConsumptionBlocks: 8640,
ConsumptionWindow: 8640,
}
}

Expand Down
14 changes: 9 additions & 5 deletions txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ type txPool struct {
logger *logger.SubLogger
}

// NewTxPool constructs a new transaction pool with various sub-pools for different transaction types.
// The transaction pool also maintains a consumption map for tracking byte usage per address.
func NewTxPool(conf *Config, storeReader store.Reader, broadcastCh chan message.Message) TxPool {
pools := make(map[payload.Type]pool)
pools[payload.TypeTransfer] = newPool(conf.transferPoolSize(), conf.minFee())
Expand All @@ -51,6 +53,8 @@ func NewTxPool(conf *Config, storeReader store.Reader, broadcastCh chan message.
return pool
}

// SetNewSandboxAndRecheck updates the sandbox and rechecks all transactions,
// removing expired or invalid ones.
func (p *txPool) SetNewSandboxAndRecheck(sb sandbox.Sandbox) {
p.lk.Lock()
defer p.lk.Unlock()
Expand Down Expand Up @@ -161,14 +165,14 @@ func (p *txPool) handleIncreaseConsumption(trx *tx.Tx) {
}

func (p *txPool) handleDecreaseConsumption(height uint32) error {
// If height is less than or equal to ConsumptionBlocks, nothing to do
if height <= p.config.ConsumptionBlocks {
// If height is less than or equal to ConsumptionWindow, nothing to do.
if height <= p.config.ConsumptionWindow {
return nil
}

// Calculate the height of the old block based on ConsumptionBlocks
oldConsumptionHeight := height - p.config.ConsumptionBlocks
committedBlock, err := p.strReader.Block(oldConsumptionHeight)
// Calculate the block height that has passed out of the consumption window.
windowedBlockHeight := height - p.config.ConsumptionWindow
committedBlock, err := p.strReader.Block(windowedBlockHeight)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion txpool/txpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type testData struct {
func testConfig() *Config {
return &Config{
MaxSize: 10,
ConsumptionBlocks: 3,
ConsumptionWindow: 3,
Fee: &FeeConfig{
FixedFee: 0.000001,
DailyLimit: 280,
Expand Down

0 comments on commit 4b77035

Please sign in to comment.