[#338] ir: Drop named named put fee

Named put fee value used only when notary disabled.

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2023-05-17 17:41:28 +03:00 committed by Evgenii Stratonikov
parent 656fd7f376
commit 81718afb39
10 changed files with 9 additions and 125 deletions

View file

@ -53,7 +53,6 @@ func setFeeDefaults(cfg *viper.Viper) {
// extra fee values for working mode without notary contract
cfg.SetDefault("fee.main_chain", 5000_0000) // 0.5 Fixed8
cfg.SetDefault("fee.side_chain", 2_0000_0000) // 2.0 Fixed8
cfg.SetDefault("fee.named_container_register", 25_0000_0000) // 25.0 Fixed8
}
func setEmitDefaults(cfg *viper.Viper) {

View file

@ -28,7 +28,6 @@ FROSTFS_IR_LOCODE_DB_PATH=/path/to/locode.db
FROSTFS_IR_FEE_MAIN_CHAIN=50000000
FROSTFS_IR_FEE_SIDE_CHAIN=200000000
FROSTFS_IR_FEE_NAMED_CONTAINER_REGISTER=2500000000
FROSTFS_IR_TIMERS_EMIT=240
FROSTFS_IR_TIMERS_STOP_ESTIMATION_MUL=1

View file

@ -49,7 +49,6 @@ locode:
fee:
main_chain: 50000000 # Fixed8 value of extra GAS fee for mainchain contract invocation; ignore if notary is enabled in mainchain
side_chain: 200000000 # Fixed8 value of extra GAS fee for sidechain contract invocation; ignore if notary is enabled in sidechain
named_container_register: 2500000000 # Fixed8 value of extra GAS fee for named conatiner registration in container contract; ignore if notary is enabled in sidechain
timers:
emit: 240 # Number of sidechain blocks between GAS emission cycles; disabled by default

View file

@ -8,17 +8,13 @@ import (
// FeeConfig is an instance that returns extra fee values for contract
// invocations without notary support.
type FeeConfig struct {
registerNamedCnr,
mainchain,
sidechain fixedn.Fixed8
}
// NewFeeConfig constructs FeeConfig from viper.Viper instance. Latter must not be nil.
//
// Fee for named container registration is taken from "fee.named_container_register" value.
func NewFeeConfig(v *viper.Viper) *FeeConfig {
return &FeeConfig{
registerNamedCnr: fixedn.Fixed8(v.GetInt64("fee.named_container_register")),
mainchain: fixedn.Fixed8(v.GetInt64("fee.main_chain")),
sidechain: fixedn.Fixed8(v.GetInt64("fee.side_chain")),
}
@ -31,8 +27,3 @@ func (f FeeConfig) MainChainFee() fixedn.Fixed8 {
func (f FeeConfig) SideChainFee() fixedn.Fixed8 {
return f.sidechain
}
// NamedContainerRegistrationFee returns additional GAS fee for named container registration in FrostFS network.
func (f FeeConfig) NamedContainerRegistrationFee() fixedn.Fixed8 {
return f.registerNamedCnr
}

View file

@ -18,7 +18,6 @@ func TestConfig(t *testing.T) {
fee:
main_chain: 50000000
side_chain: 200000000
named_container_register: 2500000000
`,
)
v := viper.New()
@ -29,7 +28,6 @@ fee:
config := NewFeeConfig(v)
require.Equal(t, fixedn.Fixed8(50000000), config.MainChainFee(), "main chain fee invalid")
require.Equal(t, fixedn.Fixed8(200000000), config.SideChainFee(), "side chain fee invalid")
require.Equal(t, fixedn.Fixed8(2500000000), config.NamedContainerRegistrationFee(), "named container register fee invalid")
})
t.Run("nothing set", func(t *testing.T) {
@ -43,7 +41,6 @@ fee:
config := NewFeeConfig(v)
require.Equal(t, fixedn.Fixed8(0), config.MainChainFee(), "main chain fee invalid")
require.Equal(t, fixedn.Fixed8(0), config.SideChainFee(), "side chain fee invalid")
require.Equal(t, fixedn.Fixed8(0), config.NamedContainerRegistrationFee(), "named container register fee invalid")
})
t.Run("partially set", func(t *testing.T) {
@ -62,7 +59,6 @@ fee:
config := NewFeeConfig(v)
require.Equal(t, fixedn.Fixed8(10), config.MainChainFee(), "main chain fee invalid")
require.Equal(t, fixedn.Fixed8(0), config.SideChainFee(), "side chain fee invalid")
require.Equal(t, fixedn.Fixed8(0), config.NamedContainerRegistrationFee(), "named container register fee invalid")
})
}

View file

@ -387,14 +387,6 @@ func (s *Server) initClientsFromMorph() (*serverMorphClients, error) {
container.AsAlphabet(),
)
if s.sideNotaryConfig.disabled {
// in non-notary environments we customize fee for named container registration
// because it takes much more additional GAS than other operations.
morphCnrOpts = append(morphCnrOpts,
container.WithCustomFeeForNamedPut(s.feeConfig.NamedContainerRegistrationFee()),
)
}
result.CnrClient, err = container.NewFromMorph(s.morphClient, s.contracts.container, fee, morphCnrOpts...)
if err != nil {
return nil, err

View file

@ -56,10 +56,6 @@ func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8,
opts[i](o)
}
if o.feePutNamedSet {
o.staticOpts = append(o.staticOpts, client.WithCustomFee(putNamedMethod, o.feePutNamed))
}
sc, err := client.NewStatic(cli, contract, fee, o.staticOpts...)
if err != nil {
return nil, fmt.Errorf("can't create container static client: %w", err)
@ -83,9 +79,6 @@ func (c Client) ContractAddress() util.Uint160 {
type Option func(*opts)
type opts struct {
feePutNamedSet bool
feePutNamed fixedn.Fixed8
staticOpts []client.StaticClientOption
}
@ -111,11 +104,3 @@ func AsAlphabet() Option {
o.staticOpts = append(o.staticOpts, client.AsAlphabet())
}
}
// WithCustomFeeForNamedPut returns option to specify custom fee for each Put operation with named container.
func WithCustomFeeForNamedPut(fee fixedn.Fixed8) Option {
return func(o *opts) {
o.feePutNamed = fee
o.feePutNamedSet = true
}
}

View file

@ -1,35 +0,0 @@
package client
import "github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
// setFeeForMethod sets fee for the operation executed using specified contract method.
func (x *fees) setFeeForMethod(method string, fee fixedn.Fixed8) {
if x.customFees == nil {
x.customFees = make(map[string]fixedn.Fixed8, 1)
}
x.customFees[method] = fee
}
// fees represents source of per-operation fees.
// Can be initialized using var declaration.
//
// Instances are not thread-safe, so they mean initially filling, and then only reading.
type fees struct {
defaultFee fixedn.Fixed8
// customFees represents source of customized per-operation fees.
customFees map[string]fixedn.Fixed8
}
// returns fee for the operation executed using specified contract method.
// Returns customized value if it is set. Otherwise, returns default value.
func (x fees) feeForMethod(method string) fixedn.Fixed8 {
if x.customFees != nil {
if fee, ok := x.customFees[method]; ok {
return fee
}
}
return x.defaultFee
}

View file

@ -1,32 +0,0 @@
package client
import (
"testing"
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
"github.com/stretchr/testify/require"
)
func TestFees(t *testing.T) {
var v fees
const method = "some method"
var (
fee fixedn.Fixed8
def = fixedn.Fixed8(13)
)
v.defaultFee = def
fee = v.feeForMethod(method)
require.True(t, fee.Equal(def))
const customFee = fixedn.Fixed8(10)
v.setFeeForMethod(method, customFee)
fee = v.feeForMethod(method)
require.Equal(t, customFee, fee)
}

View file

@ -27,7 +27,7 @@ type staticOpts struct {
tryNotary bool
alpha bool // use client's key to sign notary request's main TX
fees fees
fee fixedn.Fixed8
}
// WithNotary returns notary status of the client.
@ -63,7 +63,7 @@ func NewStatic(client *Client, scriptHash util.Uint160, fee fixedn.Fixed8, opts
scScriptHash: scriptHash,
}
c.fees.defaultFee = fee
c.fee = fee
for i := range opts {
opts[i](&c.staticOpts)
@ -125,8 +125,6 @@ func (i *InvokePrmOptional) SetControlTX(b bool) {
// If fee for the operation executed using specified method is customized, then StaticClient uses it.
// Otherwise, default fee is used.
func (s StaticClient) Invoke(prm InvokePrm) error {
fee := s.fees.feeForMethod(prm.method)
if s.tryNotary {
if s.alpha {
var (
@ -149,15 +147,15 @@ func (s StaticClient) Invoke(prm InvokePrm) error {
vubP = &vub
}
return s.client.NotaryInvoke(s.scScriptHash, fee, nonce, vubP, prm.method, prm.args...)
return s.client.NotaryInvoke(s.scScriptHash, s.fee, nonce, vubP, prm.method, prm.args...)
}
return s.client.NotaryInvokeNotAlpha(s.scScriptHash, fee, prm.method, prm.args...)
return s.client.NotaryInvokeNotAlpha(s.scScriptHash, s.fee, prm.method, prm.args...)
}
return s.client.Invoke(
s.scScriptHash,
fee,
s.fee,
prm.method,
prm.args...,
)
@ -211,11 +209,3 @@ func AsAlphabet() StaticClientOption {
o.alpha = true
}
}
// WithCustomFee returns option to specify custom fee for the operation executed using
// specified contract method.
func WithCustomFee(method string, fee fixedn.Fixed8) StaticClientOption {
return func(o *staticOpts) {
o.fees.setFeeForMethod(method, fee)
}
}