From 05614c51edfcc62f37d779ffd630ed1db94243ec Mon Sep 17 00:00:00 2001 From: Vlad Date: Fri, 7 Jul 2023 19:21:22 +0300 Subject: [PATCH] update swamp shrexnd tests --- nodebuilder/share/config.go | 2 - nodebuilder/share/constructors.go | 7 +-- nodebuilder/tests/nd_test.go | 81 +++++++++++++++++++------------ 3 files changed, 52 insertions(+), 38 deletions(-) diff --git a/nodebuilder/share/config.go b/nodebuilder/share/config.go index aae9871985..7fd845a672 100644 --- a/nodebuilder/share/config.go +++ b/nodebuilder/share/config.go @@ -14,7 +14,6 @@ import ( // TODO: some params are pointers and other are not, Let's fix this. type Config struct { UseShareExchange bool - UseIPLD bool // ShrExEDSParams sets shrexeds client and server configuration parameters ShrExEDSParams *shrexeds.Parameters // ShrExNDParams sets shrexnd client and server configuration parameters @@ -32,7 +31,6 @@ func DefaultConfig(tp node.Type) Config { ShrExEDSParams: shrexeds.DefaultParameters(), ShrExNDParams: shrexnd.DefaultParameters(), UseShareExchange: true, - UseIPLD: true, PeerManagerParams: peers.DefaultParameters(), } diff --git a/nodebuilder/share/constructors.go b/nodebuilder/share/constructors.go index fb6e84c5d3..5cb0e41e53 100644 --- a/nodebuilder/share/constructors.go +++ b/nodebuilder/share/constructors.go @@ -80,9 +80,7 @@ func lightGetter( if cfg.UseShareExchange { cascade = append(cascade, shrexGetter) } - if cfg.UseIPLD { - cascade = append(cascade, ipldGetter) - } + cascade = append(cascade, ipldGetter) return getters.NewCascadeGetter(cascade) } @@ -98,9 +96,6 @@ func fullGetter( if cfg.UseShareExchange { cascade = append(cascade, getters.NewTeeGetter(shrexGetter, store)) } - if cfg.UseIPLD { - cascade = append(cascade, ipldGetter) - } cascade = append(cascade, getters.NewTeeGetter(ipldGetter, store)) return getters.NewCascadeGetter(cascade) } diff --git a/nodebuilder/tests/nd_test.go b/nodebuilder/tests/nd_test.go index 83b93e78f9..8c78739f47 100644 --- a/nodebuilder/tests/nd_test.go +++ b/nodebuilder/tests/nd_test.go @@ -17,6 +17,7 @@ import ( "github.com/celestiaorg/celestia-node/nodebuilder/node" "github.com/celestiaorg/celestia-node/nodebuilder/p2p" "github.com/celestiaorg/celestia-node/nodebuilder/tests/swamp" + "github.com/celestiaorg/celestia-node/share" "github.com/celestiaorg/celestia-node/share/eds" "github.com/celestiaorg/celestia-node/share/getters" "github.com/celestiaorg/celestia-node/share/p2p/shrexnd" @@ -24,9 +25,10 @@ import ( func TestShrexNDFromLights(t *testing.T) { const ( - blocks = 5 - btime = time.Millisecond * 300 - bsize = 16 + blocks = 10 + btime = time.Millisecond * 300 + bsize = 16 + testTimeout = time.Second * 10 ) ctx, cancel := context.WithTimeout(context.Background(), swamp.DefaultTestTimeout) @@ -40,21 +42,20 @@ func TestShrexNDFromLights(t *testing.T) { require.NoError(t, err) os.Setenv(p2p.EnvKeyCelestiaBootstrapper, "true") - const defaultTimeInterval = time.Second * 5 - - light := newLightNode(sw, addrsBridge[0].String(), defaultTimeInterval, 1) + light := newLightNode(sw, addrsBridge[0].String(), testTimeout, 1) require.NoError(t, bridge.Start(ctx)) require.NoError(t, startLightNodes(ctx, light)) require.NoError(t, <-fillDn) - for i := 1; i < blocks; i++ { + // first 2 blocks are not filled with data + for i := 3; i < blocks; i++ { h, err := bridge.HeaderServ.GetByHeight(ctx, uint64(i)) require.NoError(t, err) - nID := h.DAH.RowsRoots[0][:8] + namespace := h.DAH.RowRoots[0][:share.NamespaceSize] reqCtx, cancel := context.WithTimeout(ctx, time.Second*5) - sh, err := light.ShareServ.GetSharesByNamespace(reqCtx, h.DAH, nID) + sh, err := light.ShareServ.GetSharesByNamespace(reqCtx, h.DAH, namespace) cancel() require.NoError(t, err) require.True(t, len(sh[0].Shares) > 0) @@ -63,14 +64,14 @@ func TestShrexNDFromLights(t *testing.T) { func TestShrexNDFromLightsWithBadFulls(t *testing.T) { const ( - blocks = 5 - btime = time.Millisecond * 300 - bsize = 16 - amountOfFulls = 25 - defaultTimeInterval = time.Second * 5 + blocks = 10 + btime = time.Millisecond * 300 + bsize = 16 + amountOfFulls = 5 + testTimeout = time.Second * 10 ) - ctx, cancel := context.WithTimeout(context.Background(), swamp.DefaultTestTimeout) + ctx, cancel := context.WithTimeout(context.Background(), testTimeout) t.Cleanup(cancel) sw := swamp.NewSwamp(t, swamp.WithBlockTime(btime)) @@ -82,30 +83,35 @@ func TestShrexNDFromLightsWithBadFulls(t *testing.T) { os.Setenv(p2p.EnvKeyCelestiaBootstrapper, "true") + // create full nodes with basic stream.reset handler ndHandler := func(stream network.Stream) { _ = stream.Reset() } - - // create full nodes with basic reset handler fulls := make([]*nodebuilder.Node, 0, amountOfFulls) for i := 0; i < amountOfFulls; i++ { - fulls = append(fulls, newFullNodeWithNDHandler(sw, addrsBridge[0].String(), defaultTimeInterval, ndHandler)) - } + full := newFullNodeWithNDHandler( + sw, + addrsBridge[0].String(), + testTimeout, + ndHandler) - light := newLightNode(sw, addrsBridge[0].String(), defaultTimeInterval, amountOfFulls+1) + fulls = append(fulls, full) + } + light := newLightNode(sw, addrsBridge[0].String(), testTimeout, amountOfFulls+1) require.NoError(t, bridge.Start(ctx)) require.NoError(t, startFullNodes(ctx, fulls...)) require.NoError(t, startLightNodes(ctx, light)) require.NoError(t, <-fillDn) - for i := 1; i < blocks; i++ { + // first 2 blocks are not filled with data + for i := 3; i < blocks; i++ { h, err := bridge.HeaderServ.GetByHeight(ctx, uint64(i)) require.NoError(t, err) - nID := h.DAH.RowsRoots[0][:8] + namespace := h.DAH.RowRoots[0][:share.NamespaceSize] reqCtx, cancel := context.WithTimeout(ctx, time.Second*5) - sh, err := light.ShareServ.GetSharesByNamespace(reqCtx, h.DAH, nID) + sh, err := light.ShareServ.GetSharesByNamespace(reqCtx, h.DAH, namespace) cancel() require.NoError(t, err) require.True(t, len(sh[0].Shares) > 0) @@ -114,15 +120,14 @@ func TestShrexNDFromLightsWithBadFulls(t *testing.T) { func newLightNode( sw *swamp.Swamp, - bootstarpperAddr string, + bootstrapperAddr string, defaultTimeInterval time.Duration, amountOfFulls int, ) *nodebuilder.Node { lnConfig := nodebuilder.DefaultConfig(node.Light) - lnConfig.Share.UseIPLD = false lnConfig.Share.Discovery.PeersLimit = uint(amountOfFulls) setTimeInterval(lnConfig, defaultTimeInterval) - lnConfig.Header.TrustedPeers = append(lnConfig.Header.TrustedPeers, bootstarpperAddr) + lnConfig.Header.TrustedPeers = append(lnConfig.Header.TrustedPeers, bootstrapperAddr) return sw.NewNodeWithConfig(node.Light, lnConfig) } @@ -151,19 +156,18 @@ func startLightNodes(ctx context.Context, nodes ...*nodebuilder.Node) error { func newFullNodeWithNDHandler( sw *swamp.Swamp, - bootstarpperAddr string, + bootstrapperAddr string, defaultTimeInterval time.Duration, handler network.StreamHandler, ) *nodebuilder.Node { cfg := nodebuilder.DefaultConfig(node.Full) - cfg.Share.UseIPLD = false setTimeInterval(cfg, defaultTimeInterval) cfg.Header.TrustedPeers = []string{ "/ip4/1.2.3.4/tcp/12345/p2p/12D3KooWNaJ1y1Yio3fFJEXCZyd1Cat3jmrPdgkYCrHfKD3Ce21p", } - cfg.Header.TrustedPeers = append(cfg.Header.TrustedPeers, bootstarpperAddr) + cfg.Header.TrustedPeers = append(cfg.Header.TrustedPeers, bootstrapperAddr) - return sw.NewNodeWithConfig(node.Full, cfg, replaceNDServer(cfg, handler)) + return sw.NewNodeWithConfig(node.Full, cfg, replaceNDServer(cfg, handler), replaceShareGetter()) } func startFullNodes(ctx context.Context, fulls ...*nodebuilder.Node) error { @@ -197,3 +201,20 @@ func replaceNDServer(cfg *nodebuilder.Config, handler network.StreamHandler) fx. }), )) } + +func replaceShareGetter() fx.Option { + return fx.Decorate(fx.Annotate( + func( + host host.Host, + store *eds.Store, + storeGetter *getters.StoreGetter, + shrexGetter *getters.ShrexGetter, + network p2p.Network, + ) share.Getter { + cascade := make([]share.Getter, 0, 2) + cascade = append(cascade, storeGetter) + cascade = append(cascade, getters.NewTeeGetter(shrexGetter, store)) + return getters.NewCascadeGetter(cascade) + }, + )) +}