From 81718afb397c8598bb43eb28d0d4cd7e9522b03a Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Wed, 17 May 2023 17:41:28 +0300 Subject: [PATCH] [#338] ir: Drop named named put fee Named put fee value used only when notary disabled. Signed-off-by: Dmitrii Stepanov --- cmd/frostfs-ir/defaults.go | 5 ++-- config/example/ir.env | 1 - config/example/ir.yaml | 1 - pkg/innerring/config/fee.go | 13 ++--------- pkg/innerring/config/fee_test.go | 4 ---- pkg/innerring/initialization.go | 8 ------- pkg/morph/client/container/client.go | 15 ------------ pkg/morph/client/fee.go | 35 ---------------------------- pkg/morph/client/fee_test.go | 32 ------------------------- pkg/morph/client/static.go | 20 ++++------------ 10 files changed, 9 insertions(+), 125 deletions(-) delete mode 100644 pkg/morph/client/fee.go delete mode 100644 pkg/morph/client/fee_test.go diff --git a/cmd/frostfs-ir/defaults.go b/cmd/frostfs-ir/defaults.go index 007bb8964..a7fe8d563 100644 --- a/cmd/frostfs-ir/defaults.go +++ b/cmd/frostfs-ir/defaults.go @@ -51,9 +51,8 @@ func setControlDefaults(cfg *viper.Viper) { 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 + cfg.SetDefault("fee.main_chain", 5000_0000) // 0.5 Fixed8 + cfg.SetDefault("fee.side_chain", 2_0000_0000) // 2.0 Fixed8 } func setEmitDefaults(cfg *viper.Viper) { diff --git a/config/example/ir.env b/config/example/ir.env index 7b8f8a89d..3f9530ab6 100644 --- a/config/example/ir.env +++ b/config/example/ir.env @@ -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 diff --git a/config/example/ir.yaml b/config/example/ir.yaml index 1130a840b..a01f3d0bb 100644 --- a/config/example/ir.yaml +++ b/config/example/ir.yaml @@ -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 diff --git a/pkg/innerring/config/fee.go b/pkg/innerring/config/fee.go index d77685643..a26a7bcc6 100644 --- a/pkg/innerring/config/fee.go +++ b/pkg/innerring/config/fee.go @@ -8,19 +8,15 @@ 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")), + 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 -} diff --git a/pkg/innerring/config/fee_test.go b/pkg/innerring/config/fee_test.go index a0c56aac1..f7330c6ca 100644 --- a/pkg/innerring/config/fee_test.go +++ b/pkg/innerring/config/fee_test.go @@ -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") }) } diff --git a/pkg/innerring/initialization.go b/pkg/innerring/initialization.go index 50ba67124..9b5634382 100644 --- a/pkg/innerring/initialization.go +++ b/pkg/innerring/initialization.go @@ -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 diff --git a/pkg/morph/client/container/client.go b/pkg/morph/client/container/client.go index 85d742328..2b5996cd7 100644 --- a/pkg/morph/client/container/client.go +++ b/pkg/morph/client/container/client.go @@ -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 - } -} diff --git a/pkg/morph/client/fee.go b/pkg/morph/client/fee.go deleted file mode 100644 index 8a38c4f55..000000000 --- a/pkg/morph/client/fee.go +++ /dev/null @@ -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 -} diff --git a/pkg/morph/client/fee_test.go b/pkg/morph/client/fee_test.go deleted file mode 100644 index 963d64ce4..000000000 --- a/pkg/morph/client/fee_test.go +++ /dev/null @@ -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) -} diff --git a/pkg/morph/client/static.go b/pkg/morph/client/static.go index 910f78537..7aa17a70f 100644 --- a/pkg/morph/client/static.go +++ b/pkg/morph/client/static.go @@ -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) - } -}