Skip to content

Commit

Permalink
update swamp shrexnd tests
Browse files Browse the repository at this point in the history
  • Loading branch information
walldiss committed Jul 7, 2023
1 parent 99c92e1 commit 05614c5
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 38 deletions.
2 changes: 0 additions & 2 deletions nodebuilder/share/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -32,7 +31,6 @@ func DefaultConfig(tp node.Type) Config {
ShrExEDSParams: shrexeds.DefaultParameters(),
ShrExNDParams: shrexnd.DefaultParameters(),
UseShareExchange: true,
UseIPLD: true,
PeerManagerParams: peers.DefaultParameters(),
}

Expand Down
7 changes: 1 addition & 6 deletions nodebuilder/share/constructors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)
}
81 changes: 51 additions & 30 deletions nodebuilder/tests/nd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@ 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"
)

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)
Expand All @@ -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)
Expand All @@ -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))
Expand All @@ -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)
Expand All @@ -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)
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
},
))
}

0 comments on commit 05614c5

Please sign in to comment.