This implements orphan expiration in the mempool such that any orphans that have not had their ancestors materialize within 15 minutes of their initial arrival time will be evicted which in turn will remove any other orphans that attempted to redeem it. In order to perform the evictions with reasonable efficiency, an opportunistic scan interval of 5 minutes is used. That is to say that there is not a hard deadline on the scan interval and instead it runs when a new orphan is added to the pool if enough time has passed. The following is an example of running this code against the main network for around an hour while intentionally generating orphans to test: 2019-10-28 01:44:36.272 [DBG] TXMP: Expired 2 orphans (remaining: 46) 2019-10-28 01:49:39.915 [DBG] TXMP: Expired 17 orphans (remaining: 49) 2019-10-28 01:54:47.704 [DBG] TXMP: Expired 15 orphans (remaining: 43) 2019-10-28 01:59:53.414 [DBG] TXMP: Expired 16 orphans (remaining: 56) 2019-10-28 02:05:09.858 [DBG] TXMP: Expired 16 orphans (remaining: 68) 2019-10-28 02:10:10.567 [DBG] TXMP: Expired 16 orphans (remaining: 78) 2019-10-28 02:15:11.736 [DBG] TXMP: Expired 26 orphans (remaining: 82) 2019-10-28 02:48:34.352 [DBG] TXMP: Expired 85 orphans (remaining: 0) As can be seen from the above, without orphan expiration on this data set, the orphan pool would have grown an additional 193 entries.
41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
// Copyright (c) 2013-2016 The btcsuite developers
|
|
// Copyright (c) 2016-2019 The Decred developers
|
|
// Use of this source code is governed by an ISC
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package mempool
|
|
|
|
import (
|
|
"github.com/decred/slog"
|
|
)
|
|
|
|
// log is a logger that is initialized with no output filters. This
|
|
// means the package will not perform any logging by default until the caller
|
|
// requests it.
|
|
// The default amount of logging is none.
|
|
var log = slog.Disabled
|
|
|
|
// DisableLog disables all library log output. Logging output is disabled
|
|
// by default until UseLogger is called.
|
|
//
|
|
// Deprecated: Use UseLogger(slog.Disabled) instead.
|
|
func DisableLog() {
|
|
log = slog.Disabled
|
|
}
|
|
|
|
// UseLogger uses a specified Logger to output package logging info.
|
|
// This should be used in preference to SetLogWriter if the caller is also
|
|
// using slog.
|
|
func UseLogger(logger slog.Logger) {
|
|
log = logger
|
|
}
|
|
|
|
// pickNoun returns the singular or plural form of a noun depending
|
|
// on the count n.
|
|
func pickNoun(n int, singular, plural string) string {
|
|
if n == 1 {
|
|
return singular
|
|
}
|
|
return plural
|
|
}
|