forked from TrueCloudLab/neoneo-go
Merge pull request #1394 from nspcc-dev/make-free-gas-height-dependent
config: allow configuring free gas depending on height
This commit is contained in:
commit
319e3996f4
6 changed files with 52 additions and 9 deletions
|
@ -32,7 +32,7 @@ ProtocolConfiguration:
|
||||||
RegisterTransaction: 10000
|
RegisterTransaction: 10000
|
||||||
VerifyBlocks: true
|
VerifyBlocks: true
|
||||||
VerifyTransactions: false
|
VerifyTransactions: false
|
||||||
FreeGasLimit: 10.0
|
FreeGasLimit: {0: 10.0, 6200000: 50.0}
|
||||||
MaxTransactionsPerBlock: 500
|
MaxTransactionsPerBlock: 500
|
||||||
MaxFreeTransactionsPerBlock: 20
|
MaxFreeTransactionsPerBlock: 20
|
||||||
MaxFreeTransactionSize: 1024
|
MaxFreeTransactionSize: 1024
|
||||||
|
|
|
@ -32,7 +32,7 @@ ProtocolConfiguration:
|
||||||
RegisterTransaction: 100
|
RegisterTransaction: 100
|
||||||
VerifyBlocks: true
|
VerifyBlocks: true
|
||||||
VerifyTransactions: false
|
VerifyTransactions: false
|
||||||
FreeGasLimit: 10.0
|
FreeGasLimit: {0: 10.0, 4818000: 50.0}
|
||||||
MaxTransactionsPerBlock: 500
|
MaxTransactionsPerBlock: 500
|
||||||
MaxFreeTransactionsPerBlock: 20
|
MaxFreeTransactionsPerBlock: 20
|
||||||
MaxFreeTransactionSize: 1024
|
MaxFreeTransactionSize: 1024
|
||||||
|
|
|
@ -26,7 +26,9 @@ type (
|
||||||
// transactions exceeding the MaxFreeTransactionSize.
|
// transactions exceeding the MaxFreeTransactionSize.
|
||||||
FeePerExtraByte float64 `yaml:"FeePerExtraByte"`
|
FeePerExtraByte float64 `yaml:"FeePerExtraByte"`
|
||||||
// FreeGasLimit is an amount of GAS which can be spent for free.
|
// FreeGasLimit is an amount of GAS which can be spent for free.
|
||||||
FreeGasLimit util.Fixed8 `yaml:"FreeGasLimit"`
|
// It can change over time, thus it's a map of block height to the
|
||||||
|
// respective GAS limit.
|
||||||
|
FreeGasLimit map[uint32]util.Fixed8 `yaml:"FreeGasLimit"`
|
||||||
LowPriorityThreshold float64 `yaml:"LowPriorityThreshold"`
|
LowPriorityThreshold float64 `yaml:"LowPriorityThreshold"`
|
||||||
Magic NetMode `yaml:"Magic"`
|
Magic NetMode `yaml:"Magic"`
|
||||||
MaxTransactionsPerBlock int `yaml:"MaxTransactionsPerBlock"`
|
MaxTransactionsPerBlock int `yaml:"MaxTransactionsPerBlock"`
|
||||||
|
@ -61,6 +63,20 @@ type (
|
||||||
NetMode uint32
|
NetMode uint32
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// GetFreeGas returns FreeGasLimit value for given block height.
|
||||||
|
func (p *ProtocolConfiguration) GetFreeGas(block uint32) util.Fixed8 {
|
||||||
|
var gas util.Fixed8
|
||||||
|
var height uint32
|
||||||
|
for h, g := range p.FreeGasLimit {
|
||||||
|
if h > block || h < height {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
gas = g
|
||||||
|
height = h
|
||||||
|
}
|
||||||
|
return gas
|
||||||
|
}
|
||||||
|
|
||||||
// String implements the stringer interface.
|
// String implements the stringer interface.
|
||||||
func (n NetMode) String() string {
|
func (n NetMode) String() string {
|
||||||
switch n {
|
switch n {
|
||||||
|
|
25
pkg/config/protocol_config_test.go
Normal file
25
pkg/config/protocol_config_test.go
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGetFreeGas(t *testing.T) {
|
||||||
|
fixed10 := util.Fixed8FromInt64(10)
|
||||||
|
fixed50 := util.Fixed8FromInt64(50)
|
||||||
|
p := ProtocolConfiguration{
|
||||||
|
FreeGasLimit: map[uint32]util.Fixed8{
|
||||||
|
0: fixed10,
|
||||||
|
6200000: fixed50,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
require.Equal(t, fixed10, p.GetFreeGas(0))
|
||||||
|
require.Equal(t, fixed10, p.GetFreeGas(1000))
|
||||||
|
require.Equal(t, fixed10, p.GetFreeGas(1000000))
|
||||||
|
require.Equal(t, fixed10, p.GetFreeGas(6100000))
|
||||||
|
require.Equal(t, fixed50, p.GetFreeGas(6200000))
|
||||||
|
require.Equal(t, fixed50, p.GetFreeGas(7000000))
|
||||||
|
}
|
|
@ -792,8 +792,9 @@ func (bc *Blockchain) storeBlock(block *block.Block) error {
|
||||||
v.SetCheckedHash(tx.VerificationHash().BytesBE())
|
v.SetCheckedHash(tx.VerificationHash().BytesBE())
|
||||||
v.LoadScript(t.Script)
|
v.LoadScript(t.Script)
|
||||||
v.SetPriceGetter(getPrice)
|
v.SetPriceGetter(getPrice)
|
||||||
if bc.config.FreeGasLimit > 0 {
|
gasLimit := bc.config.GetFreeGas(block.Index)
|
||||||
v.SetGasLimit(bc.config.FreeGasLimit + t.Gas)
|
if gasLimit > 0 {
|
||||||
|
v.SetGasLimit(gasLimit + t.Gas)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := v.Run()
|
err := v.Run()
|
||||||
|
|
|
@ -605,7 +605,8 @@ func (ic *interopContext) contractMigrate(v *vm.VM) error {
|
||||||
v := ic.bc.GetTestVM(nil)
|
v := ic.bc.GetTestVM(nil)
|
||||||
w := io.NewBufBinWriter()
|
w := io.NewBufBinWriter()
|
||||||
emit.AppCallWithOperationAndArgs(w.BinWriter, hash, "decimals")
|
emit.AppCallWithOperationAndArgs(w.BinWriter, hash, "decimals")
|
||||||
v.SetGasLimit(ic.bc.GetConfig().FreeGasLimit)
|
conf := ic.bc.GetConfig()
|
||||||
|
v.SetGasLimit(conf.GetFreeGas(ic.bc.BlockHeight() + 1)) // BlockHeight() is already persisted, so it's either a new block or test invocation.
|
||||||
v.Load(w.Bytes())
|
v.Load(w.Bytes())
|
||||||
if err := v.Run(); err == nil && v.Estack().Len() == 1 {
|
if err := v.Run(); err == nil && v.Estack().Len() == 1 {
|
||||||
res := v.Estack().Pop().Item().ToContractParameter(map[vm.StackItem]bool{})
|
res := v.Estack().Pop().Item().ToContractParameter(map[vm.StackItem]bool{})
|
||||||
|
|
Loading…
Reference in a new issue