From 6437f4b32ed215a5457bfbda40c91f379ac8450a Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Mon, 8 Jun 2020 12:35:39 +0300 Subject: [PATCH] core: respect MaxFreeTransactionsPerBlock setting Fix #1019. --- pkg/core/blockchain.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index 4c6247faf..1e984f14e 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -1528,12 +1528,13 @@ func (bc *Blockchain) ApplyPolicyToTxSet(txes []mempool.TxWithFee) []mempool.TxW txes = txes[:bc.config.MaxTransactionsPerBlock] } maxFree := bc.config.MaxFreeTransactionsPerBlock - if maxFree != 0 { - lowStart := sort.Search(len(txes), func(i int) bool { - return bc.IsLowPriority(txes[i].Fee) + if maxFree != 0 && len(txes) > maxFree { + // Transactions are sorted by fee, so we just find the first free one. + freeStart := sort.Search(len(txes), func(i int) bool { + return txes[i].Fee == 0 }) - if lowStart+maxFree < len(txes) { - txes = txes[:lowStart+maxFree] + if freeStart+maxFree < len(txes) { + txes = txes[:freeStart+maxFree] } } return txes