Merge pull request #1397 from nspcc-dev/minimum-network-fee

Minimum network fee
This commit is contained in:
Roman Khimov 2020-09-11 18:18:58 +03:00 committed by GitHub
commit a1357789cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 5 deletions

View file

@ -32,10 +32,11 @@ ProtocolConfiguration:
RegisterTransaction: 10000
VerifyBlocks: true
VerifyTransactions: false
FreeGasLimit: {0: 10.0, 6200000: 50.0}
FreeGasLimit: {0: 10.0, 6216000: 50.0}
MaxTransactionsPerBlock: 500
MaxFreeTransactionsPerBlock: 20
MaxFreeTransactionSize: 1024
MinimumNetworkFee: 0
FeePerExtraByte: 0.00001
ApplicationConfiguration:

View file

@ -32,10 +32,11 @@ ProtocolConfiguration:
RegisterTransaction: 100
VerifyBlocks: true
VerifyTransactions: false
FreeGasLimit: {0: 10.0, 4818000: 50.0}
FreeGasLimit: {0: 10.0, 5220000: 50.0}
MaxTransactionsPerBlock: 500
MaxFreeTransactionsPerBlock: 20
MaxFreeTransactionSize: 1024
MinimumNetworkFee: 0
FeePerExtraByte: 0.00001
ApplicationConfiguration:

View file

@ -36,7 +36,9 @@ type (
MaxFreeTransactionSize int `yaml:"MaxFreeTransactionSize"`
// Maximum number of low priority transactions accepted into block.
MaxFreeTransactionsPerBlock int `yaml:"MaxFreeTransactionsPerBlock"`
MemPoolSize int `yaml:"MemPoolSize"`
// MinimumNetworkFee sets the minimum required network fee for transaction to pass validation.
MinimumNetworkFee util.Fixed8 `yaml:"MinimumNetworkFee"`
MemPoolSize int `yaml:"MemPoolSize"`
// SaveStorageBatch enables storage batch saving before every persist.
SaveStorageBatch bool `yaml:"SaveStorageBatch"`
SecondsPerBlock int `yaml:"SecondsPerBlock"`

View file

@ -168,6 +168,10 @@ func NewBlockchain(s storage.Store, cfg config.ProtocolConfiguration, log *zap.L
cfg.MaxFreeTransactionSize = 0
log.Info("MaxFreeTransactionSize is not set or wrong, setting default value (unlimited)", zap.Int("MaxFreeTransactionSize", cfg.MaxFreeTransactionSize))
}
if cfg.MinimumNetworkFee < 0 {
cfg.MinimumNetworkFee = 0
log.Info("MinimumNetworkFee is not set or wrong, setting default value (0)", zap.String("MinimumNetworkFee", cfg.MinimumNetworkFee.String()))
}
if cfg.FeePerExtraByte <= 0 {
cfg.FeePerExtraByte = 0
log.Info("FeePerExtraByte is not set or wrong, setting default value", zap.Float64("FeePerExtraByte", cfg.FeePerExtraByte))
@ -1996,13 +2000,16 @@ func (bc *Blockchain) PoolTx(t *transaction.Transaction) error {
if t.Type != transaction.ClaimType {
txSize := io.GetVarSize(t)
maxFree := bc.config.MaxFreeTransactionSize
netFee := bc.NetworkFee(t)
if maxFree != 0 && txSize > maxFree {
netFee := bc.NetworkFee(t)
if bc.IsLowPriority(netFee) ||
netFee < util.Fixed8FromFloat(bc.config.FeePerExtraByte)*util.Fixed8(txSize-maxFree) {
netFee < (util.Fixed8FromFloat(bc.config.LowPriorityThreshold)+util.Fixed8FromFloat(bc.config.FeePerExtraByte)*util.Fixed8(txSize-maxFree)) {
return ErrPolicy
}
}
if t.Type == transaction.InvocationType && netFee < bc.config.MinimumNetworkFee {
return ErrPolicy
}
}
if err := bc.memPool.Add(t, bc); err != nil {
switch err {

View file

@ -89,6 +89,7 @@ var rpcHandlers = map[string]func(*Server, request.Params) (interface{}, *respon
"getclaimable": (*Server).getClaimable,
"getconnectioncount": (*Server).getConnectionCount,
"getcontractstate": (*Server).getContractState,
"getminimumnetworkfee": (*Server).getMinimumNetworkFee,
"getnep5balances": (*Server).getNEP5Balances,
"getnep5transfers": (*Server).getNEP5Transfers,
"getpeers": (*Server).getPeers,
@ -798,6 +799,10 @@ func (s *Server) getNEP5Transfers(ps request.Params) (interface{}, *response.Err
return bs, nil
}
func (s *Server) getMinimumNetworkFee(ps request.Params) (interface{}, *response.Error) {
return s.chain.GetConfig().MinimumNetworkFee, nil
}
func (s *Server) getProof(ps request.Params) (interface{}, *response.Error) {
root, err := ps.Value(0).GetUint256()
if err != nil {