From 9a86fff7e011b9915c2aa5c277c6747da8a72b13 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 29 Dec 2020 18:50:41 +0300 Subject: [PATCH] [#291] Remove some unused code from repository Signed-off-by: Leonard Lyubich --- cmd/neofs-cli/modules/util.go | 3 - cmd/neofs-node/config.go | 22 --- cmd/neofs-node/grpc.go | 3 +- cmd/neofs-node/object.go | 77 ----------- misc/build.go | 1 - pkg/core/netmap/storage.go | 5 - pkg/innerring/innerring.go | 14 +- pkg/innerring/invoke/balance.go | 22 --- pkg/innerring/invoke/container.go | 3 - pkg/innerring/invoke/neofs.go | 21 --- pkg/innerring/processors/audit/handlers.go | 7 +- .../blobovnicza/blobovnicza.go | 7 - .../blobovnicza/blobovnicza_test.go | 20 --- pkg/network/listen.go | 18 --- pkg/services/audit/taskmanager/manager.go | 2 - pkg/services/object/acl/acl.go | 1 - pkg/services/object/delete/exec.go | 10 -- pkg/services/object/get/get_test.go | 13 -- pkg/services/object/get/util.go | 4 +- pkg/services/object/transport_splitter.go | 12 -- pkg/services/object/util/chain.go | 127 ------------------ pkg/services/object_manager/gc/gc.go | 11 -- .../placement/traverser_test.go | 10 -- 23 files changed, 14 insertions(+), 399 deletions(-) delete mode 100644 pkg/network/listen.go diff --git a/cmd/neofs-cli/modules/util.go b/cmd/neofs-cli/modules/util.go index 01d38bcd30..de32c0aa60 100644 --- a/cmd/neofs-cli/modules/util.go +++ b/cmd/neofs-cli/modules/util.go @@ -220,9 +220,6 @@ func completeBearerToken(btok *token.BearerToken) error { // set eACL table version, because it usually omitted table := v2.GetBody().GetEACL() table.SetVersion(pkg.SDKVersion().ToV2()) - - // back to SDK token - btok = token.NewBearerTokenFromV2(v2) } else { return errors.New("unsupported bearer token version") } diff --git a/cmd/neofs-node/config.go b/cmd/neofs-node/config.go index f4181ceb36..6b01b3891b 100644 --- a/cmd/neofs-node/config.go +++ b/cmd/neofs-node/config.go @@ -20,8 +20,6 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/core/container" netmapCore "github.com/nspcc-dev/neofs-node/pkg/core/netmap" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor" - "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/bucket" - "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/bucket/fsbucket" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine" meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard" @@ -562,26 +560,6 @@ func configPath(sections ...string) string { return strings.Join(sections, ".") } -func initBucket(prefix string, c *cfg) (bucket bucket.Bucket, err error) { - const inmemory = "inmemory" - - switch c.viper.GetString(prefix + ".type") { - case inmemory: - bucket = newBucket() - c.log.Info("using in-memory bucket", zap.String("storage", prefix)) - case fsbucket.Name: - bucket, err = fsbucket.NewBucket(prefix, c.viper) - if err != nil { - return nil, errors.Wrap(err, "can't create fs bucket") - } - c.log.Info("using filesystem bucket", zap.String("storage", prefix)) - default: - return nil, errors.New("unknown storage type") - } - - return bucket, nil -} - func initObjectPool(cfg *viper.Viper) (pool cfgObjectRoutines) { var err error diff --git a/cmd/neofs-node/grpc.go b/cmd/neofs-node/grpc.go index d3f5ea61bc..f757871bef 100644 --- a/cmd/neofs-node/grpc.go +++ b/cmd/neofs-node/grpc.go @@ -20,8 +20,9 @@ func initGRPC(c *cfg) { } func serveGRPC(c *cfg) { + c.wg.Add(1) + go func() { - c.wg.Add(1) defer func() { c.wg.Done() }() diff --git a/cmd/neofs-node/object.go b/cmd/neofs-node/object.go index 1c9ef9ecda..223da2e112 100644 --- a/cmd/neofs-node/object.go +++ b/cmd/neofs-node/object.go @@ -2,17 +2,13 @@ package main import ( "context" - "errors" - "sync" - "github.com/mr-tron/base58" "github.com/nspcc-dev/neofs-api-go/pkg/client" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-api-go/pkg/owner" "github.com/nspcc-dev/neofs-api-go/v2/object" objectGRPC "github.com/nspcc-dev/neofs-api-go/v2/object/grpc" objectCore "github.com/nspcc-dev/neofs-node/pkg/core/object" - "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/bucket" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine" "github.com/nspcc-dev/neofs-node/pkg/morph/event" "github.com/nspcc-dev/neofs-node/pkg/network/cache" @@ -48,12 +44,6 @@ type objectSvc struct { delete *deletesvcV2.Service } -type inMemBucket struct { - bucket.Bucket - *sync.RWMutex - items map[string][]byte -} - func (c *cfg) MaxObjectSize() uint64 { sz, err := c.cfgNetmap.wrapper.MaxObjectSize() if err != nil { @@ -65,73 +55,6 @@ func (c *cfg) MaxObjectSize() uint64 { return sz } -func newBucket() bucket.Bucket { - return &inMemBucket{ - RWMutex: new(sync.RWMutex), - items: map[string][]byte{}, - } -} - -func (b *inMemBucket) Del(key []byte) error { - b.Lock() - delete(b.items, base58.Encode(key)) - b.Unlock() - - return nil -} - -func (b *inMemBucket) Get(key []byte) ([]byte, error) { - b.RLock() - v, ok := b.items[base58.Encode(key)] - b.RUnlock() - - if !ok { - return nil, errors.New("not found") - } - - return v, nil -} - -func (b *inMemBucket) Set(key, value []byte) error { - k := base58.Encode(key) - - b.Lock() - b.items[k] = makeCopy(value) - b.Unlock() - - return nil -} - -func (b *inMemBucket) Iterate(handler bucket.FilterHandler) error { - if handler == nil { - return bucket.ErrNilFilterHandler - } - - b.RLock() - for key, val := range b.items { - k, err := base58.Decode(key) - if err != nil { - panic(err) - } - - v := makeCopy(val) - - if !handler(k, v) { - return bucket.ErrIteratingAborted - } - } - b.RUnlock() - - return nil -} - -func makeCopy(val []byte) []byte { - tmp := make([]byte, len(val)) - copy(tmp, val) - - return tmp -} - func (s *objectSvc) Put(ctx context.Context) (object.PutObjectStreamer, error) { return s.put.Put(ctx) } diff --git a/misc/build.go b/misc/build.go index 243977986b..234d2afb51 100644 --- a/misc/build.go +++ b/misc/build.go @@ -25,4 +25,3 @@ var ( // Debug is an application debug mode flag. Debug = "false" ) - diff --git a/pkg/core/netmap/storage.go b/pkg/core/netmap/storage.go index a03f7dcdea..e06af189b1 100644 --- a/pkg/core/netmap/storage.go +++ b/pkg/core/netmap/storage.go @@ -1,8 +1,6 @@ package netmap import ( - "errors" - "github.com/nspcc-dev/neofs-api-go/pkg/netmap" ) @@ -21,9 +19,6 @@ type Source interface { GetNetMap(diff uint64) (*netmap.Netmap, error) } -// ErrNotFound is the error returned when network map was not found in storage. -var ErrNotFound = errors.New("network map not found") - // GetLatestNetworkMap requests and returns latest network map from storage. func GetLatestNetworkMap(src Source) (*netmap.Netmap, error) { return src.GetNetMap(0) diff --git a/pkg/innerring/innerring.go b/pkg/innerring/innerring.go index 8ad75e4888..16bd12858c 100644 --- a/pkg/innerring/innerring.go +++ b/pkg/innerring/innerring.go @@ -60,14 +60,12 @@ type ( } contracts struct { - neofs util.Uint160 // in mainnet - netmap util.Uint160 // in morph - balance util.Uint160 // in morph - container util.Uint160 // in morph - audit util.Uint160 // in morph - reputation util.Uint160 // in morph - neofsid util.Uint160 // in morph - gas util.Uint160 // native contract in both chains + neofs util.Uint160 // in mainnet + netmap util.Uint160 // in morph + balance util.Uint160 // in morph + container util.Uint160 // in morph + audit util.Uint160 // in morph + gas util.Uint160 // native contract in both chains alphabet [alphabetContractsN]util.Uint160 // in morph } diff --git a/pkg/innerring/invoke/balance.go b/pkg/innerring/invoke/balance.go index 4e708f7de9..fd32f133d0 100644 --- a/pkg/innerring/invoke/balance.go +++ b/pkg/innerring/invoke/balance.go @@ -6,14 +6,6 @@ import ( ) type ( - // TransferXParams for TransferBalanceX invocation. - TransferXParams struct { - Sender []byte - Receiver []byte - Amount int64 // in Fixed16 - Comment []byte - } - // LockParams for LockAsset invocation. LockParams struct { ID []byte @@ -39,20 +31,6 @@ const ( precisionMethod = "decimals" ) -// TransferBalanceX invokes transferX method. -func TransferBalanceX(cli *client.Client, con util.Uint160, p *TransferXParams) error { - if cli == nil { - return client.ErrNilClient - } - - return cli.Invoke(con, extraFee, transferXMethod, - p.Sender, - p.Receiver, - p.Amount, - p.Comment, - ) -} - // Mint assets in contract. func Mint(cli *client.Client, con util.Uint160, p *MintBurnParams) error { if cli == nil { diff --git a/pkg/innerring/invoke/container.go b/pkg/innerring/invoke/container.go index 1d4aeb36fc..181d5118c4 100644 --- a/pkg/innerring/invoke/container.go +++ b/pkg/innerring/invoke/container.go @@ -4,7 +4,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neofs-node/pkg/morph/client" - "github.com/pkg/errors" ) type ( @@ -22,8 +21,6 @@ type ( } ) -var ErrParseTestInvoke = errors.New("can't parse NEO node response") - const ( putContainerMethod = "put" deleteContainerMethod = "delete" diff --git a/pkg/innerring/invoke/neofs.go b/pkg/innerring/invoke/neofs.go index b33a040a42..74e639d056 100644 --- a/pkg/innerring/invoke/neofs.go +++ b/pkg/innerring/invoke/neofs.go @@ -39,27 +39,6 @@ const ( chequeMethod = "cheque" ) -// IsInnerRing returns true if 'key' is presented in inner ring list. -func IsInnerRing(cli *client.Client, con util.Uint160, key *ecdsa.PublicKey) (bool, error) { - if cli == nil { - return false, client.ErrNilClient - } - - pubKey := crypto.MarshalPublicKey(key) - - val, err := cli.TestInvoke(con, checkIsInnerRingMethod, pubKey) - if err != nil { - return false, err - } - - isInnerRing, err := client.BoolFromStackItem(val[0]) - if err != nil { - return false, err - } - - return isInnerRing, nil -} - // CashOutCheque invokes Cheque method. func CashOutCheque(cli *client.Client, con util.Uint160, p *ChequeParams) error { if cli == nil { diff --git a/pkg/innerring/processors/audit/handlers.go b/pkg/innerring/processors/audit/handlers.go index 53a5a1eaee..9ba7bdcd95 100644 --- a/pkg/innerring/processors/audit/handlers.go +++ b/pkg/innerring/processors/audit/handlers.go @@ -7,11 +7,14 @@ import ( func (ap *Processor) handleNewAuditRound(ev event.Event) { auditEvent := ev.(Start) - ap.log.Info("new round of audit", zap.Uint64("epoch", auditEvent.epoch)) + + epoch := auditEvent.Epoch() + + ap.log.Info("new round of audit", zap.Uint64("epoch", epoch)) // send event to the worker pool - err := ap.pool.Submit(func() { ap.processStartAudit(auditEvent.epoch) }) + err := ap.pool.Submit(func() { ap.processStartAudit(epoch) }) if err != nil { ap.log.Warn("previous round of audit prepare hasn't finished yet") } diff --git a/pkg/local_object_storage/blobovnicza/blobovnicza.go b/pkg/local_object_storage/blobovnicza/blobovnicza.go index 4f10a1fadf..b03359720f 100644 --- a/pkg/local_object_storage/blobovnicza/blobovnicza.go +++ b/pkg/local_object_storage/blobovnicza/blobovnicza.go @@ -101,10 +101,3 @@ func WithLogger(l *logger.Logger) Option { c.log = l.With(zap.String("component", "Blobovnicza")) } } - -// WithBoltDBOptions returns option to specify BoltDB options. -func WithBoltDBOptions(opts *bbolt.Options) Option { - return func(c *cfg) { - c.boltOptions = opts - } -} diff --git a/pkg/local_object_storage/blobovnicza/blobovnicza_test.go b/pkg/local_object_storage/blobovnicza/blobovnicza_test.go index 8521481098..c603479ce5 100644 --- a/pkg/local_object_storage/blobovnicza/blobovnicza_test.go +++ b/pkg/local_object_storage/blobovnicza/blobovnicza_test.go @@ -34,26 +34,6 @@ func testAddress() *objectSDK.Address { return addr } -func testObject(sz uint64) *object.Object { - raw := object.NewRaw() - - addr := testAddress() - raw.SetID(addr.ObjectID()) - raw.SetContainerID(addr.ContainerID()) - - raw.SetPayload(make([]byte, sz)) - - // fit the binary size to the required - data, _ := raw.Marshal() - if ln := uint64(len(data)); ln > sz { - raw.SetPayload(raw.Payload()[:sz-(ln-sz)]) - } - - raw.SetAttributes() // for require.Equal - - return raw.Object() -} - func testPutGet(t *testing.T, blz *Blobovnicza, sz uint64, expPut, expGet error) *objectSDK.Address { // create binary object data := make([]byte, sz) diff --git a/pkg/network/listen.go b/pkg/network/listen.go deleted file mode 100644 index 0834ac5865..0000000000 --- a/pkg/network/listen.go +++ /dev/null @@ -1,18 +0,0 @@ -package network - -import ( - "net" - - "github.com/multiformats/go-multiaddr" - manet "github.com/multiformats/go-multiaddr-net" -) - -// Listen announces on the local network address. -func Listen(addr multiaddr.Multiaddr) (net.Listener, error) { - mLis, err := manet.Listen(addr) - if err != nil { - return nil, err - } - - return manet.NetListener(mLis), nil -} diff --git a/pkg/services/audit/taskmanager/manager.go b/pkg/services/audit/taskmanager/manager.go index 22d64f9f14..ffc8d3a761 100644 --- a/pkg/services/audit/taskmanager/manager.go +++ b/pkg/services/audit/taskmanager/manager.go @@ -27,8 +27,6 @@ type cfg struct { ctxPrm auditor.ContextPrm - reporter audit.Reporter - workerPool util.WorkerPool pdpPoolGenerator, porPoolGenerator func() (util.WorkerPool, error) diff --git a/pkg/services/object/acl/acl.go b/pkg/services/object/acl/acl.go index a1156710a5..795a8ac1c2 100644 --- a/pkg/services/object/acl/acl.go +++ b/pkg/services/object/acl/acl.go @@ -113,7 +113,6 @@ type accessErr struct { var ( ErrMalformedRequest = errors.New("malformed request") - ErrInternal = errors.New("internal error") ErrUnknownRole = errors.New("can't classify request sender") ErrUnknownContainer = errors.New("can't fetch container info") ) diff --git a/pkg/services/object/delete/exec.go b/pkg/services/object/delete/exec.go index 3da6249e8d..fa4afc9a95 100644 --- a/pkg/services/object/delete/exec.go +++ b/pkg/services/object/delete/exec.go @@ -2,9 +2,7 @@ package deletesvc import ( "context" - "crypto/ecdsa" - "github.com/nspcc-dev/neofs-api-go/pkg/client" "github.com/nspcc-dev/neofs-api-go/pkg/container" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-node/pkg/core/object" @@ -59,10 +57,6 @@ func (exec execCtx) isLocal() bool { return exec.prm.common.LocalOnly() } -func (exec *execCtx) key() *ecdsa.PrivateKey { - return exec.prm.common.PrivateKey() -} - func (exec *execCtx) address() *objectSDK.Address { return exec.prm.Address() } @@ -75,10 +69,6 @@ func (exec *execCtx) commonParameters() *util.CommonPrm { return exec.prm.common } -func (exec execCtx) callOptions() []client.CallOption { - return exec.prm.common.RemoteCallOptions() -} - func (exec *execCtx) newAddress(id *objectSDK.ID) *objectSDK.Address { a := objectSDK.NewAddress() a.SetObjectID(id) diff --git a/pkg/services/object/get/get_test.go b/pkg/services/object/get/get_test.go index 6bb2d78a60..63bea462e7 100644 --- a/pkg/services/object/get/get_test.go +++ b/pkg/services/object/get/get_test.go @@ -106,19 +106,6 @@ func (c *testClient) getObject(exec *execCtx) (*objectSDK.Object, error) { return cutToRange(v.obj.Object(), exec.ctxRange()).SDK(), nil } -func (c *testClient) head(_ context.Context, p Prm) (*object.Object, error) { - v, ok := c.results[p.Address().String()] - if !ok { - return nil, object.ErrNotFound - } - - if v.err != nil { - return nil, v.err - } - - return v.obj.CutPayload().Object(), nil -} - func (c *testClient) addResult(addr *objectSDK.Address, obj *object.RawObject, err error) { c.results[addr.String()] = struct { obj *object.RawObject diff --git a/pkg/services/object/get/util.go b/pkg/services/object/get/util.go index 4947e47865..82a20ec1b5 100644 --- a/pkg/services/object/get/util.go +++ b/pkg/services/object/get/util.go @@ -104,9 +104,7 @@ func (c *clientWrapper) getObject(exec *execCtx) (*objectSDK.Object, error) { return payloadOnlyObject(data), nil } else { return c.client.GetObject(exec.context(), - new(client.GetObjectParams). - WithAddress(exec.address()). - WithRawFlag(exec.isRaw()), + exec.remotePrm(), exec.callOptions()..., ) } diff --git a/pkg/services/object/transport_splitter.go b/pkg/services/object/transport_splitter.go index b3b9ad0bcc..1753abe0ca 100644 --- a/pkg/services/object/transport_splitter.go +++ b/pkg/services/object/transport_splitter.go @@ -6,11 +6,6 @@ import ( "github.com/nspcc-dev/neofs-api-go/v2/object" "github.com/nspcc-dev/neofs-node/pkg/services/util" - "github.com/pkg/errors" -) - -var ( - errChunking = errors.New("can't split message to stream chunks") ) type ( @@ -183,10 +178,3 @@ func (s *searchStreamMsgSizeCtrl) Send(resp *object.SearchResponse) error { return nil } - -func min(a, b int) int { - if a > b { - return b - } - return a -} diff --git a/pkg/services/object/util/chain.go b/pkg/services/object/util/chain.go index a54af59c7a..ffa3a0428f 100644 --- a/pkg/services/object/util/chain.go +++ b/pkg/services/object/util/chain.go @@ -9,24 +9,6 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/core/object" ) -type RangeTraverser struct { - chain *rangeChain - - seekBounds *rangeBounds -} - -type rangeBounds struct { - left, right uint64 -} - -type rangeChain struct { - next, prev *rangeChain - - bounds *rangeBounds - - id *objectSDK.ID -} - // HeadReceiver is an interface of entity that can receive // object header or the information about the object relations. type HeadReceiver interface { @@ -188,112 +170,3 @@ func traverseSplitChain(r HeadReceiver, addr *objectSDK.Address, h SplitMemberHa return false, nil } - -func NewRangeTraverser(originSize uint64, rightElement *object.Object, rngSeek *objectSDK.Range) *RangeTraverser { - right := &rangeChain{ - bounds: &rangeBounds{ - left: originSize - rightElement.PayloadSize(), - right: originSize, - }, - id: rightElement.ID(), - } - - left := &rangeChain{ - id: rightElement.PreviousID(), - } - - left.next, right.prev = right, left - - return &RangeTraverser{ - chain: right, - seekBounds: &rangeBounds{ - left: rngSeek.GetOffset(), - right: rngSeek.GetOffset() + rngSeek.GetLength(), - }, - } -} - -func (c *RangeTraverser) Next() (id *objectSDK.ID, rng *objectSDK.Range) { - left := c.chain.bounds.left - seekLeft := c.seekBounds.left - - if left > seekLeft { - id = c.chain.prev.id - } else { - id = c.chain.id - rng = objectSDK.NewRange() - rng.SetOffset(seekLeft - left) - rng.SetLength(min(c.chain.bounds.right, c.seekBounds.right) - seekLeft) - } - - return -} - -func min(a, b uint64) uint64 { - if a < b { - return a - } - - return b -} - -func (c *RangeTraverser) PushHeader(obj *object.Object) { - id := obj.ID() - if !id.Equal(c.chain.prev.id) { - panic(fmt.Sprintf("(%T) unexpected identifier in header", c)) - } - - sz := obj.PayloadSize() - - c.chain.prev.bounds = &rangeBounds{ - left: c.chain.bounds.left - sz, - right: c.chain.bounds.left, - } - - c.chain = c.chain.prev - - if prev := obj.PreviousID(); prev != nil { - c.chain.prev = &rangeChain{ - next: c.chain, - id: prev, - } - } -} - -func (c *RangeTraverser) PushSuccessSize(sz uint64) { - c.seekBounds.left += sz - - if c.seekBounds.left >= c.chain.bounds.right && c.chain.next != nil { - c.chain = c.chain.next - } -} - -// SetSeekRange moves the chain to the specified range. -// The range is expected to be within the filled chain. -func (c *RangeTraverser) SetSeekRange(r *objectSDK.Range) { - ln, off := r.GetLength(), r.GetOffset() - - for { - if off < c.chain.bounds.left { - if c.chain.prev == nil { - break - } - - c.chain = c.chain.prev - } else if off >= c.chain.bounds.left && off < c.chain.bounds.right { - break - } else if off >= c.chain.bounds.right { - if c.chain.next == nil { - break - } - - c.chain = c.chain.next - } - } - - if c.seekBounds == nil { - c.seekBounds = new(rangeBounds) - } - - c.seekBounds.left, c.seekBounds.right = off, off+ln -} diff --git a/pkg/services/object_manager/gc/gc.go b/pkg/services/object_manager/gc/gc.go index 72515aa9db..e52ee84cff 100644 --- a/pkg/services/object_manager/gc/gc.go +++ b/pkg/services/object_manager/gc/gc.go @@ -135,14 +135,3 @@ func stringifyID(addr *object.ID) string { func stringifyCID(addr *container.ID) string { return base58.Encode(addr.ToV2().GetValue()) } - -// DeleteObjects adds list of adresses to delete queue. -func (gc *GC) DeleteObjects(list ...*object.Address) { - for i := range list { - select { - case gc.queue <- list[i]: - default: - gc.log.Info("queue for deletion is full") - } - } -} diff --git a/pkg/services/object_manager/placement/traverser_test.go b/pkg/services/object_manager/placement/traverser_test.go index 42a427f689..0cba8c3fc5 100644 --- a/pkg/services/object_manager/placement/traverser_test.go +++ b/pkg/services/object_manager/placement/traverser_test.go @@ -25,16 +25,6 @@ func testNode(v uint32) (n netmap.NodeInfo) { return n } -func flattenVectors(vs []netmap.Nodes) netmap.Nodes { - v := make(netmap.Nodes, 0) - - for i := range vs { - v = append(v, vs[i]...) - } - - return v -} - func copyVectors(v []netmap.Nodes) []netmap.Nodes { vc := make([]netmap.Nodes, 0, len(v))