From 0c42db2c3c286168228d0806309fe4ee799c9a72 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Thu, 29 Oct 2020 18:57:55 +0300 Subject: [PATCH] [#132] Add cleanup table in netmap processor Signed-off-by: Alex Vanin --- .../processors/netmap/cleanup_table.go | 2 +- .../processors/netmap/cleanup_table_test.go | 7 +++---- pkg/innerring/processors/netmap/processor.go | 19 ++++++++++++------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/pkg/innerring/processors/netmap/cleanup_table.go b/pkg/innerring/processors/netmap/cleanup_table.go index 203394654..7a41d7a80 100644 --- a/pkg/innerring/processors/netmap/cleanup_table.go +++ b/pkg/innerring/processors/netmap/cleanup_table.go @@ -4,7 +4,7 @@ import ( "encoding/hex" "sync" - "github.com/nspcc-dev/neofs-api-go/v2/netmap/grpc" + netmap "github.com/nspcc-dev/neofs-api-go/v2/netmap/grpc" ) type ( diff --git a/pkg/innerring/processors/netmap/cleanup_table_test.go b/pkg/innerring/processors/netmap/cleanup_table_test.go index 7a9c3dea3..4f1375ef1 100644 --- a/pkg/innerring/processors/netmap/cleanup_table_test.go +++ b/pkg/innerring/processors/netmap/cleanup_table_test.go @@ -4,20 +4,20 @@ import ( "encoding/hex" "testing" - "github.com/nspcc-dev/neofs-api-go/v2/netmap/grpc" + netmap "github.com/nspcc-dev/neofs-api-go/v2/netmap/grpc" crypto "github.com/nspcc-dev/neofs-crypto" "github.com/nspcc-dev/neofs-node/pkg/util/test" "github.com/stretchr/testify/require" ) func TestCleanupTable(t *testing.T) { - var infos = []netmap.NodeInfo{ + infos := []netmap.NodeInfo{ {PublicKey: crypto.MarshalPublicKey(&test.DecodeKey(1).PublicKey)}, {PublicKey: crypto.MarshalPublicKey(&test.DecodeKey(2).PublicKey)}, {PublicKey: crypto.MarshalPublicKey(&test.DecodeKey(3).PublicKey)}, } - var mapInfos = map[string]struct{}{ + mapInfos := map[string]struct{}{ hex.EncodeToString(infos[0].PublicKey): {}, hex.EncodeToString(infos[1].PublicKey): {}, hex.EncodeToString(infos[2].PublicKey): {}, @@ -110,6 +110,5 @@ func TestCleanupTable(t *testing.T) { })) require.EqualValues(t, len(infos)-1, cnt) }) - }) } diff --git a/pkg/innerring/processors/netmap/processor.go b/pkg/innerring/processors/netmap/processor.go index 2827523b0..e406d0896 100644 --- a/pkg/innerring/processors/netmap/processor.go +++ b/pkg/innerring/processors/netmap/processor.go @@ -38,17 +38,21 @@ type ( epochState EpochState activeState ActiveState morphClient *client.Client + + netmapSnapshot cleanupTable } // Params of the processor constructor. Params struct { - Log *zap.Logger - PoolSize int - NetmapContract util.Uint160 - EpochTimer EpochTimerReseter - MorphClient *client.Client - EpochState EpochState - ActiveState ActiveState + Log *zap.Logger + PoolSize int + NetmapContract util.Uint160 + EpochTimer EpochTimerReseter + MorphClient *client.Client + EpochState EpochState + ActiveState ActiveState + CleanupEnabled bool + CleanupThreshold uint64 // in epochs } ) @@ -88,6 +92,7 @@ func New(p *Params) (*Processor, error) { epochState: p.EpochState, activeState: p.ActiveState, morphClient: p.MorphClient, + netmapSnapshot: newCleanupTable(p.CleanupEnabled, p.CleanupThreshold), }, nil }