diff --git a/pkg/innerring/blocktimer.go b/pkg/innerring/blocktimer.go index 1a45bf1f..2570f3ee 100644 --- a/pkg/innerring/blocktimer.go +++ b/pkg/innerring/blocktimer.go @@ -100,14 +100,7 @@ func newEpochTimer(args *epochTimerArgs) *timer.BlockTimer { return } - var err error - - if args.notaryDisabled { - err = args.cnrWrapper.StopEstimation(epochN - 1) - } else { - err = args.cnrWrapper.StopEstimationNotary(epochN - 1) - } - + err := args.cnrWrapper.StopEstimation(epochN - 1) if err != nil { args.l.Warn("can't stop epoch estimation", zap.Uint64("epoch", epochN), diff --git a/pkg/innerring/innerring.go b/pkg/innerring/innerring.go index ef3f6381..c2a82f70 100644 --- a/pkg/innerring/innerring.go +++ b/pkg/innerring/innerring.go @@ -374,12 +374,12 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error return nil, err } - balClient, err := balanceWrapper.NewFromMorph(server.morphClient, server.contracts.balance, fee) + balClient, err := balanceWrapper.NewFromMorph(server.morphClient, server.contracts.balance, fee, balanceWrapper.TryNotary()) if err != nil { return nil, err } - repClient, err := repWrapper.NewFromMorph(server.morphClient, server.contracts.reputation, fee) + repClient, err := repWrapper.NewFromMorph(server.morphClient, server.contracts.reputation, fee, repWrapper.TryNotary()) if err != nil { return nil, err } diff --git a/pkg/innerring/processors/netmap/process_epoch.go b/pkg/innerring/processors/netmap/process_epoch.go index 877c8d44..87fcc122 100644 --- a/pkg/innerring/processors/netmap/process_epoch.go +++ b/pkg/innerring/processors/netmap/process_epoch.go @@ -29,11 +29,7 @@ func (np *Processor) processNewEpoch(epoch uint64) { } if epoch > 0 { // estimates are invalid in genesis epoch - if np.notaryDisabled { - err = np.containerWrp.StartEstimation(epoch - 1) - } else { - err = np.containerWrp.StartEstimationNotary(epoch - 1) - } + err = np.containerWrp.StartEstimation(epoch - 1) if err != nil { np.log.Warn("can't start container size estimation", diff --git a/pkg/innerring/processors/reputation/process_put.go b/pkg/innerring/processors/reputation/process_put.go index 4c9ac7cf..9d76b910 100644 --- a/pkg/innerring/processors/reputation/process_put.go +++ b/pkg/innerring/processors/reputation/process_put.go @@ -41,14 +41,7 @@ func (rp *Processor) processPut(epoch uint64, id reputation.PeerID, value reputa args.SetPeerID(id) args.SetValue(value) - var err error - - if rp.notaryDisabled { - err = rp.reputationWrp.Put(args) - } else { - err = rp.reputationWrp.PutViaNotary(args) - } - + err := rp.reputationWrp.Put(args) if err != nil { rp.log.Warn("can't send approval tx for reputation value", zap.String("peer_id", hex.EncodeToString(id.ToV2().GetPublicKey())), diff --git a/pkg/innerring/settlement.go b/pkg/innerring/settlement.go index c51fa5f4..56ac48fd 100644 --- a/pkg/innerring/settlement.go +++ b/pkg/innerring/settlement.go @@ -215,14 +215,7 @@ func (s settlementDeps) Transfer(sender, recipient *owner.ID, amount *big.Int, d Details: details, } - var err error - - if s.notaryDisabled { - err = s.balanceClient.TransferX(params) - } else { - err = s.balanceClient.TransferXNotary(params) - } - + err := s.balanceClient.TransferX(params) if err != nil { log.Error("could not send transfer transaction for audit", zap.String("error", err.Error()), diff --git a/pkg/morph/client/balance/wrapper/transfer.go b/pkg/morph/client/balance/wrapper/transfer.go index d659ebcc..c6e496fa 100644 --- a/pkg/morph/client/balance/wrapper/transfer.go +++ b/pkg/morph/client/balance/wrapper/transfer.go @@ -18,6 +18,8 @@ type TransferPrm struct { // TransferX transfers p.Amount of GASe-12 from p.From to p.To // with details p.Details through direct smart contract call. +// +// If TryNotary is provided, calls notary contract. func (w *Wrapper) TransferX(p TransferPrm) error { return w.transferX(false, p) } @@ -46,11 +48,5 @@ func (w *Wrapper) transferX(notary bool, p TransferPrm) error { args.SetAmount(p.Amount) args.SetDetails(p.Details) - // invoke smart contract call - f := w.client.TransferX - if notary { - f = w.client.TransferXNotary - } - - return f(args) + return w.client.TransferX(args) } diff --git a/pkg/morph/client/balance/wrapper/wrapper.go b/pkg/morph/client/balance/wrapper/wrapper.go index 7afbc68f..d76da2da 100644 --- a/pkg/morph/client/balance/wrapper/wrapper.go +++ b/pkg/morph/client/balance/wrapper/wrapper.go @@ -22,9 +22,33 @@ type Wrapper struct { client *balance.Client } +// Option allows to set an optional +// parameter of ClientWrapper. +type Option func(*opts) + +type opts []client.StaticClientOption + +func defaultOpts() *opts { + return new(opts) +} + +// TryNotaryInvoke returns option to enable +// notary invocation tries. +func TryNotary() Option { + return func(o *opts) { + *o = append(*o, client.TryNotary()) + } +} + // NewFromMorph returns the wrapper instance from the raw morph client. -func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8) (*Wrapper, error) { - staticClient, err := client.NewStatic(cli, contract, fee) +func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8, opts ...Option) (*Wrapper, error) { + o := defaultOpts() + + for i := range opts { + opts[i](o) + } + + staticClient, err := client.NewStatic(cli, contract, fee, ([]client.StaticClientOption)(*o)...) if err != nil { return nil, fmt.Errorf("could not create static client of Balance contract: %w", err) } diff --git a/pkg/morph/client/container/wrapper/container.go b/pkg/morph/client/container/wrapper/container.go index c81fb736..30c4b510 100644 --- a/pkg/morph/client/container/wrapper/container.go +++ b/pkg/morph/client/container/wrapper/container.go @@ -58,7 +58,7 @@ func Put(w *Wrapper, cnr *container.Container) (*cid.ID, error) { // Returns calculated container identifier and any error // encountered that caused the saving to interrupt. // -// If TryNotary is provided, call notary contract. +// If TryNotary is provided, calls notary contract. func (w *Wrapper) Put(cnr, key, sig, token []byte) error { if len(sig) == 0 || len(key) == 0 { return errNilArgument diff --git a/pkg/morph/client/reputation/wrapper/put.go b/pkg/morph/client/reputation/wrapper/put.go index 5be9712c..3123e978 100644 --- a/pkg/morph/client/reputation/wrapper/put.go +++ b/pkg/morph/client/reputation/wrapper/put.go @@ -32,6 +32,8 @@ func (p *PutArgs) SetValue(v reputation.GlobalTrust) { } // Put invokes direct call of "put reputation value" method of reputation contract. +// +// If TryNotary is provided, calls notary contract. func (w *ClientWrapper) Put(v PutArgs) error { args, err := preparePutArgs(v) if err != nil { diff --git a/pkg/morph/client/reputation/wrapper/wrapper.go b/pkg/morph/client/reputation/wrapper/wrapper.go index 4fe8043f..b65ddd27 100644 --- a/pkg/morph/client/reputation/wrapper/wrapper.go +++ b/pkg/morph/client/reputation/wrapper/wrapper.go @@ -13,9 +13,33 @@ import ( // client which implements storage of reputation values. type ClientWrapper reputation.Client +// Option allows to set an optional +// parameter of ClientWrapper. +type Option func(*opts) + +type opts []client.StaticClientOption + +func defaultOpts() *opts { + return new(opts) +} + +// TryNotaryInvoke returns option to enable +// notary invocation tries. +func TryNotary() Option { + return func(o *opts) { + *o = append(*o, client.TryNotary()) + } +} + // NewFromMorph returns the wrapper instance from the raw morph client. -func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8) (*ClientWrapper, error) { - staticClient, err := client.NewStatic(cli, contract, fee) +func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8, opts ...Option) (*ClientWrapper, error) { + o := defaultOpts() + + for i := range opts { + opts[i](o) + } + + staticClient, err := client.NewStatic(cli, contract, fee, ([]client.StaticClientOption)(*o)...) if err != nil { return nil, fmt.Errorf("could not create static client of reputation contract: %w", err) } diff --git a/pkg/morph/client/static.go b/pkg/morph/client/static.go index feabf6f7..513d0a9d 100644 --- a/pkg/morph/client/static.go +++ b/pkg/morph/client/static.go @@ -99,7 +99,7 @@ func (s StaticClient) TestInvoke(method string, args ...interface{}) ([]stackite // NotaryInvoke calls NotaryInvoke method of Client with static internal // script hash. Panics if notary support was not enabled in underlying -// moprh client. +// morph client. // // Deprecated: provide TryNotary() option to NewStatic and use Invoke. func (s StaticClient) NotaryInvoke(method string, args ...interface{}) error {