mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-12 11:10:35 +00:00
core|config: make max(free)txperblock height-dependent
See neo-project/neo-modules#336.
This commit is contained in:
parent
a1357789cf
commit
4f7fa732cf
4 changed files with 37 additions and 20 deletions
|
@ -33,8 +33,8 @@ ProtocolConfiguration:
|
|||
VerifyBlocks: true
|
||||
VerifyTransactions: false
|
||||
FreeGasLimit: {0: 10.0, 6216000: 50.0}
|
||||
MaxTransactionsPerBlock: 500
|
||||
MaxFreeTransactionsPerBlock: 20
|
||||
MaxTransactionsPerBlock: {0: 500, 6216000: 200}
|
||||
MaxFreeTransactionsPerBlock: {0: 20, 6216000: 199}
|
||||
MaxFreeTransactionSize: 1024
|
||||
MinimumNetworkFee: 0
|
||||
FeePerExtraByte: 0.00001
|
||||
|
|
|
@ -33,8 +33,8 @@ ProtocolConfiguration:
|
|||
VerifyBlocks: true
|
||||
VerifyTransactions: false
|
||||
FreeGasLimit: {0: 10.0, 5220000: 50.0}
|
||||
MaxTransactionsPerBlock: 500
|
||||
MaxFreeTransactionsPerBlock: 20
|
||||
MaxTransactionsPerBlock: {0: 500, 5220000: 200}
|
||||
MaxFreeTransactionsPerBlock: {0: 20, 5220000: 199}
|
||||
MaxFreeTransactionSize: 1024
|
||||
MinimumNetworkFee: 0
|
||||
FeePerExtraByte: 0.00001
|
||||
|
|
|
@ -31,11 +31,12 @@ type (
|
|||
FreeGasLimit map[uint32]util.Fixed8 `yaml:"FreeGasLimit"`
|
||||
LowPriorityThreshold float64 `yaml:"LowPriorityThreshold"`
|
||||
Magic NetMode `yaml:"Magic"`
|
||||
MaxTransactionsPerBlock int `yaml:"MaxTransactionsPerBlock"`
|
||||
// Maximum number of transactions allowed to be packed into block.
|
||||
MaxTransactionsPerBlock map[uint32]int `yaml:"MaxTransactionsPerBlock"`
|
||||
// Maximum size of low priority transaction in bytes.
|
||||
MaxFreeTransactionSize int `yaml:"MaxFreeTransactionSize"`
|
||||
// Maximum number of low priority transactions accepted into block.
|
||||
MaxFreeTransactionsPerBlock int `yaml:"MaxFreeTransactionsPerBlock"`
|
||||
MaxFreeTransactionsPerBlock map[uint32]int `yaml:"MaxFreeTransactionsPerBlock"`
|
||||
// MinimumNetworkFee sets the minimum required network fee for transaction to pass validation.
|
||||
MinimumNetworkFee util.Fixed8 `yaml:"MinimumNetworkFee"`
|
||||
MemPoolSize int `yaml:"MemPoolSize"`
|
||||
|
@ -79,6 +80,29 @@ func (p *ProtocolConfiguration) GetFreeGas(block uint32) util.Fixed8 {
|
|||
return gas
|
||||
}
|
||||
|
||||
func getIntFromMap(m map[uint32]int, block uint32) int {
|
||||
var res int
|
||||
var height uint32
|
||||
for h, i := range m {
|
||||
if h > block || h < height || i < 0 {
|
||||
continue
|
||||
}
|
||||
res = i
|
||||
height = h
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// GetMaxTxPerBlock returns MaxTransactionsPerBlock value for given block height.
|
||||
func (p *ProtocolConfiguration) GetMaxTxPerBlock(block uint32) int {
|
||||
return getIntFromMap(p.MaxTransactionsPerBlock, block)
|
||||
}
|
||||
|
||||
// GetMaxFreeTxPerBlock returns MaxFreeTransactionsPerBlock value for given block height.
|
||||
func (p *ProtocolConfiguration) GetMaxFreeTxPerBlock(block uint32) int {
|
||||
return getIntFromMap(p.MaxFreeTransactionsPerBlock, block)
|
||||
}
|
||||
|
||||
// String implements the stringer interface.
|
||||
func (n NetMode) String() string {
|
||||
switch n {
|
||||
|
|
|
@ -156,14 +156,6 @@ func NewBlockchain(s storage.Store, cfg config.ProtocolConfiguration, log *zap.L
|
|||
cfg.MemPoolSize = defaultMemPoolSize
|
||||
log.Info("mempool size is not set or wrong, setting default value", zap.Int("MemPoolSize", cfg.MemPoolSize))
|
||||
}
|
||||
if cfg.MaxTransactionsPerBlock <= 0 {
|
||||
cfg.MaxTransactionsPerBlock = 0
|
||||
log.Info("MaxTransactionsPerBlock is not set or wrong, setting default value (unlimited)", zap.Int("MaxTransactionsPerBlock", cfg.MaxTransactionsPerBlock))
|
||||
}
|
||||
if cfg.MaxFreeTransactionsPerBlock <= 0 {
|
||||
cfg.MaxFreeTransactionsPerBlock = 0
|
||||
log.Info("MaxFreeTransactionsPerBlock is not set or wrong, setting default value (unlimited)", zap.Int("MaxFreeTransactionsPerBlock", cfg.MaxFreeTransactionsPerBlock))
|
||||
}
|
||||
if cfg.MaxFreeTransactionSize <= 0 {
|
||||
cfg.MaxFreeTransactionSize = 0
|
||||
log.Info("MaxFreeTransactionSize is not set or wrong, setting default value (unlimited)", zap.Int("MaxFreeTransactionSize", cfg.MaxFreeTransactionSize))
|
||||
|
@ -1646,10 +1638,11 @@ func (bc *Blockchain) GetMemPool() *mempool.Pool {
|
|||
// ApplyPolicyToTxSet applies configured policies to given transaction set. It
|
||||
// expects slice to be ordered by fee and returns a subslice of it.
|
||||
func (bc *Blockchain) ApplyPolicyToTxSet(txes []mempool.TxWithFee) []mempool.TxWithFee {
|
||||
if bc.config.MaxTransactionsPerBlock != 0 && len(txes) > bc.config.MaxTransactionsPerBlock {
|
||||
txes = txes[:bc.config.MaxTransactionsPerBlock]
|
||||
maxTx := bc.config.GetMaxTxPerBlock(bc.BlockHeight())
|
||||
if maxTx != 0 && len(txes) > maxTx {
|
||||
txes = txes[:maxTx]
|
||||
}
|
||||
maxFree := bc.config.MaxFreeTransactionsPerBlock
|
||||
maxFree := bc.config.GetMaxFreeTxPerBlock(bc.BlockHeight())
|
||||
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 {
|
||||
|
|
Loading…
Reference in a new issue