diff --git a/pkg/innerring/innerring.go b/pkg/innerring/innerring.go index 06310dae1..7c3ebb787 100644 --- a/pkg/innerring/innerring.go +++ b/pkg/innerring/innerring.go @@ -196,6 +196,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error AuditContract: server.contracts.audit, MorphClient: server.morphClient, IRList: server, + ClientCache: newClientCache(server.key), }) if err != nil { return nil, err diff --git a/pkg/innerring/processors/audit/processor.go b/pkg/innerring/processors/audit/processor.go index 1ec32d5c7..d018d08f0 100644 --- a/pkg/innerring/processors/audit/processor.go +++ b/pkg/innerring/processors/audit/processor.go @@ -2,6 +2,7 @@ package audit import ( "github.com/nspcc-dev/neo-go/pkg/util" + SDKClient "github.com/nspcc-dev/neofs-api-go/pkg/client" "github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/nspcc-dev/neofs-node/pkg/morph/event" "github.com/panjf2000/ants/v2" @@ -16,6 +17,11 @@ type ( InnerRingSize() int32 } + // NeoFSClientCache is an interface for cache of neofs RPC clients + NeoFSClientCache interface { + Get(address string, opts ...SDKClient.Option) (*SDKClient.Client, error) + } + // Processor of events related with data audit. Processor struct { log *zap.Logger @@ -24,6 +30,7 @@ type ( auditContract util.Uint160 morphClient *client.Client irList Indexer + clientCache NeoFSClientCache } // Params of the processor constructor. @@ -33,6 +40,7 @@ type ( AuditContract util.Uint160 MorphClient *client.Client IRList Indexer + ClientCache NeoFSClientCache } ) @@ -50,6 +58,8 @@ func New(p *Params) (*Processor, error) { return nil, errors.New("ir/audit: neo:morph client is not set") case p.IRList == nil: return nil, errors.New("ir/audit: global state is not set") + case p.ClientCache == nil: + return nil, errors.New("ir/audit: neofs RPC client cache is not set") } pool, err := ants.NewPool(ProcessorPoolSize, ants.WithNonblocking(true)) @@ -64,6 +74,7 @@ func New(p *Params) (*Processor, error) { auditContract: p.AuditContract, morphClient: p.MorphClient, irList: p.IRList, + clientCache: p.ClientCache, }, nil } diff --git a/pkg/innerring/rpc.go b/pkg/innerring/rpc.go new file mode 100644 index 000000000..5c12ae5b5 --- /dev/null +++ b/pkg/innerring/rpc.go @@ -0,0 +1,24 @@ +package innerring + +import ( + "crypto/ecdsa" + + "github.com/nspcc-dev/neofs-api-go/pkg/client" + "github.com/nspcc-dev/neofs-node/pkg/network/cache" +) + +type ClientCache struct { + cache *cache.ClientCache + key *ecdsa.PrivateKey +} + +func newClientCache(key *ecdsa.PrivateKey) *ClientCache { + return &ClientCache{ + cache: cache.NewSDKClientCache(), + key: key, + } +} + +func (c *ClientCache) Get(address string, opts ...client.Option) (*client.Client, error) { + return c.cache.Get(c.key, address, opts...) +}