-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add LimitMempoolSize logic for mempool #179
Conversation
@@ -72,6 +73,16 @@ func (coinsCache *CoinsLruCache) HaveCoin(point *outpoint.OutPoint) bool { | |||
return coin != nil && !coin.IsSpent() | |||
} | |||
|
|||
func (coinsCache *CoinsLruCache) RemoveCoins(point *outpoint.OutPoint) error { | |||
coinsCache.cacheCoins.Remove(*point) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we check whether point exists in cache and do a log before removing it?
coinsTipHash, _ := coinsTip.GetBestBlock() | ||
coinsTipHash, err := coinsTip.GetBestBlock() | ||
if err != nil { | ||
log.Error("get best block error:%s", err.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return an error on error?
@@ -164,6 +164,7 @@ func RemoveForReorg(nMemPoolHeight int32, flag int) { | |||
pool.CalculateDescendants(it, allRemoves) | |||
} | |||
pool.RemoveStaged(allRemoves, false, mempool.REORG) | |||
pool.LimitMempoolSize(conf.Cfg.Mempool.MaxPoolSize, int64(conf.Cfg.Mempool.MaxPoolExpiry)*60*60) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no reason to do trim when a TX is evicted from pool. Whey should we trim it after removing some?
@@ -128,6 +128,7 @@ func (m *TxMempool) AddTx(txEntry *TxEntry, ancestors map[*TxEntry]struct{}) err | |||
if txEntry.SumTxCountWithAncestors == 1 { | |||
m.rootTx[txEntry.Tx.GetHash()] = txEntry | |||
} | |||
m.LimitMempoolSize(conf.Cfg.Mempool.MaxPoolSize, int64(conf.Cfg.Mempool.MaxPoolExpiry)*60*60) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Newly added tx may be evicted. We should check whether it still exists to return different error.
@qiwei9743 @ludete @fffreedom PTAL