Skip to content

Commit

Permalink
Mark priority mempool config fields as deprecated (#365)
Browse files Browse the repository at this point in the history
* Mark priority mempool config fields as deprecated

* fix linting

* Warn when deprecated keys are present

* Fix lint staticcheck

---------

Co-authored-by: Lasaro <[email protected]>
  • Loading branch information
hvanz and lasarojc authored Feb 23, 2023
1 parent bef9a83 commit 5fe38d7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
12 changes: 12 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ func (cfg *Config) CheckDeprecated() []string {
if cfg.Mempool.Version == MempoolV1 {
warnings = append(warnings, "prioritized mempool detected. This version of the mempool will be removed in the next major release.")
}
if cfg.Mempool.TTLNumBlocks != 0 {
warnings = append(warnings, "prioritized mempool key detected. This key, together with this version of the mempool, will be removed in the next major release.")
}
if cfg.Mempool.TTLDuration != 0 {
warnings = append(warnings, "prioritized mempool key detected. This key, together with this version of the mempool, will be removed in the next major release.")
}
if cfg.DeprecatedFastSyncConfig != nil {
warnings = append(warnings, "[fastsync] table detected. This section has been renamed to [blocksync]. The values in this deprecated section will be disregarded.")
}
Expand Down Expand Up @@ -756,6 +762,9 @@ type MempoolConfig struct {
// Note, if TTLNumBlocks is also defined, a transaction will be removed if it
// has existed in the mempool at least TTLNumBlocks number of blocks or if it's
// insertion time into the mempool is beyond TTLDuration.
//
// Deprecated: Only used by priority mempool, which will be removed in the
// next major release.
TTLDuration time.Duration `mapstructure:"ttl-duration"`

// TTLNumBlocks, if non-zero, defines the maximum number of blocks a transaction
Expand All @@ -764,6 +773,9 @@ type MempoolConfig struct {
// Note, if TTLDuration is also defined, a transaction will be removed if it
// has existed in the mempool at least TTLNumBlocks number of blocks or if
// it's insertion time into the mempool is beyond TTLDuration.
//
// Deprecated: Only used by priority mempool, which will be removed in the
// next major release.
TTLNumBlocks int64 `mapstructure:"ttl-num-blocks"`
}

Expand Down
6 changes: 3 additions & 3 deletions mempool/v1/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ func (txmp *TxMempool) canAddTx(wtx *WrappedTx) error {
//
// The caller must hold txmp.mtx exclusively.
func (txmp *TxMempool) purgeExpiredTxs(blockHeight int64) {
if txmp.config.TTLNumBlocks == 0 && txmp.config.TTLDuration == 0 {
if txmp.config.TTLNumBlocks == 0 && txmp.config.TTLDuration == 0 { //nolint:staticcheck // SA1019 Priority mempool deprecated but still supported in this release.
return // nothing to do
}

Expand All @@ -740,11 +740,11 @@ func (txmp *TxMempool) purgeExpiredTxs(blockHeight int64) {
next := cur.Next()

w := cur.Value.(*WrappedTx)
if txmp.config.TTLNumBlocks > 0 && (blockHeight-w.height) > txmp.config.TTLNumBlocks {
if txmp.config.TTLNumBlocks > 0 && (blockHeight-w.height) > txmp.config.TTLNumBlocks { //nolint:staticcheck // SA1019 Priority mempool deprecated but still supported in this release.
txmp.removeTxByElement(cur)
txmp.cache.Remove(w.tx)
txmp.metrics.EvictedTxs.Add(1)
} else if txmp.config.TTLDuration > 0 && now.Sub(w.timestamp) > txmp.config.TTLDuration {
} else if txmp.config.TTLDuration > 0 && now.Sub(w.timestamp) > txmp.config.TTLDuration { //nolint:staticcheck // SA1019 Priority mempool deprecated but still supported in this release.
txmp.removeTxByElement(cur)
txmp.cache.Remove(w.tx)
txmp.metrics.EvictedTxs.Add(1)
Expand Down
4 changes: 2 additions & 2 deletions mempool/v1/mempool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ func TestTxMempool_ConcurrentTxs(t *testing.T) {

func TestTxMempool_ExpiredTxs_Timestamp(t *testing.T) {
txmp := setup(t, 5000)
txmp.config.TTLDuration = 5 * time.Millisecond
txmp.config.TTLDuration = 5 * time.Millisecond //nolint:staticcheck // SA1019 Priority mempool deprecated but still supported in this release.

added1 := checkTxs(t, txmp, 10, 0)
require.Equal(t, len(added1), txmp.Size())
Expand Down Expand Up @@ -570,7 +570,7 @@ func TestTxMempool_ExpiredTxs_Timestamp(t *testing.T) {
func TestTxMempool_ExpiredTxs_NumBlocks(t *testing.T) {
txmp := setup(t, 500)
txmp.height = 100
txmp.config.TTLNumBlocks = 10
txmp.config.TTLNumBlocks = 10 //nolint:staticcheck // SA1019 Priority mempool deprecated but still supported in this release.

tTxs := checkTxs(t, txmp, 100, 0)
require.Equal(t, len(tTxs), txmp.Size())
Expand Down

0 comments on commit 5fe38d7

Please sign in to comment.