Skip to content

Commit 208eb0b

Browse files
authored
swamp: rework fill blocks (#1000)
* swamp: rework fill blocks * swamp: attempt to fix flakiness in TestFullReconstructFromLights * swamp: subscribe on fraud proof before node starts
1 parent cb6f845 commit 208eb0b

3 files changed

Lines changed: 63 additions & 34 deletions

File tree

node/tests/fraud_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,14 @@ func TestFraudProofBroadcasting(t *testing.T) {
4444
store := node.MockStore(t, node.DefaultConfig(node.Full))
4545
full := sw.NewNodeWithStore(node.Full, store, node.WithTrustedPeers(addrs[0].String()))
4646

47-
err = full.Start(ctx)
47+
// subscribe to fraud proof before node starts helps
48+
// to prevent flakiness when fraud proof is propagating before subscribing on it
49+
subscr, err := full.FraudServ.Subscribe(fraud.BadEncoding)
4850
require.NoError(t, err)
4951

50-
subscr, err := full.FraudServ.Subscribe(fraud.BadEncoding)
52+
err = full.Start(ctx)
5153
require.NoError(t, err)
54+
5255
_, err = subscr.Proof(ctx)
5356
require.NoError(t, err)
5457

node/tests/reconstruct_test.go

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ func TestFullReconstructFromBridge(t *testing.T) {
4444
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
4545
t.Cleanup(cancel)
4646
sw := swamp.NewSwamp(t, swamp.WithBlockTime(btime))
47-
go sw.FillBlocks(ctx, t, bsize, blocks)
47+
errCh := make(chan error)
48+
go func() {
49+
errCh <- sw.FillBlocks(ctx, bsize, blocks)
50+
}()
4851

4952
bridge := sw.NewBridgeNode()
5053
err := bridge.Start(ctx)
@@ -66,9 +69,8 @@ func TestFullReconstructFromBridge(t *testing.T) {
6669
return full.ShareServ.SharesAvailable(bctx, h.DAH)
6770
})
6871
}
69-
70-
err = errg.Wait()
71-
require.NoError(t, err)
72+
require.NoError(t, <-errCh)
73+
require.NoError(t, errg.Wait())
7274
}
7375

7476
/*
@@ -79,12 +81,13 @@ Pre-Reqs:
7981
Steps:
8082
1. Create a Bridge Node(BN)
8183
2. Start a BN
82-
3. Create 69 Light Nodes(LNs) with BN as a trusted peer
83-
4. Start 69 LNs
84-
5. Create a Full Node(FN) with 69 LNs as trusted peers
85-
6. Unlink FN connection to BN
86-
7. Start a FN
87-
8. Check that a FN can retrieve shares from 1 to 20 blocks
84+
3. Create a Full Node(FN) that will act as a bootstraper
85+
4. Create 69 Light Nodes(LNs) with BN as a trusted peer and a bootstaper
86+
5. Start 69 LNs
87+
6. Create a Full Node(FN) with a bootstraper
88+
7. Unlink FN connection to BN
89+
8. Start a FN
90+
9. Check that a FN can retrieve shares from 1 to 20 blocks
8891
*/
8992
func TestFullReconstructFromLights(t *testing.T) {
9093
ipld.RetrieveQuadrantTimeout = time.Millisecond * 100
@@ -96,36 +99,52 @@ func TestFullReconstructFromLights(t *testing.T) {
9699
lnodes = 69
97100
)
98101

99-
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
102+
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
100103
t.Cleanup(cancel)
101104
sw := swamp.NewSwamp(t, swamp.WithBlockTime(btime))
102-
go sw.FillBlocks(ctx, t, bsize, blocks)
105+
errCh := make(chan error)
106+
go func() {
107+
errCh <- sw.FillBlocks(ctx, bsize, blocks)
108+
}()
103109

104-
cfg := node.DefaultConfig(node.Bridge)
105-
cfg.P2P.Bootstrapper = true
106-
const defaultTimeInterval = time.Second * 10
110+
const defaultTimeInterval = time.Second * 5
107111
var defaultOptions = []node.Option{
108112
node.WithRefreshRoutingTablePeriod(defaultTimeInterval),
109113
node.WithDiscoveryInterval(defaultTimeInterval),
110114
node.WithAdvertiseInterval(defaultTimeInterval),
111115
}
112116

113-
bridgeConfig := append([]node.Option{node.WithConfig(cfg)}, defaultOptions...)
117+
cfg := node.DefaultConfig(node.Full)
114118
cfg.P2P.Bootstrapper = true
115-
bridge := sw.NewBridgeNode(bridgeConfig...)
119+
bridge := sw.NewBridgeNode()
120+
addrsBridge, err := peer.AddrInfoToP2pAddrs(host.InfoFromHost(bridge.Host))
121+
require.NoError(t, err)
122+
bootstrapConfig := append([]node.Option{node.WithConfig(cfg)}, defaultOptions...)
123+
bootstapFN := sw.NewFullNode(bootstrapConfig...)
124+
require.NoError(t, bootstapFN.Start(ctx))
116125
require.NoError(t, bridge.Start(ctx))
117-
addr := host.InfoFromHost(bridge.Host)
126+
addrBootstrapNode := host.InfoFromHost(bootstapFN.Host)
118127

119-
nodesConfig := append([]node.Option{node.WithBootstrappers([]peer.AddrInfo{*addr})}, defaultOptions...)
128+
nodesConfig := append(
129+
[]node.Option{
130+
node.WithTrustedPeers(addrsBridge[0].String()),
131+
node.WithBootstrappers([]peer.AddrInfo{*addrBootstrapNode})},
132+
defaultOptions...,
133+
)
120134
full := sw.NewFullNode(nodesConfig...)
121135
lights := make([]*node.Node, lnodes)
122136
subs := make([]event.Subscription, lnodes)
123137
errg, errCtx := errgroup.WithContext(ctx)
124138
for i := 0; i < lnodes; i++ {
125139
i := i
126140
errg.Go(func() error {
127-
light := sw.NewLightNode(nodesConfig...)
128-
sub, err := light.Host.EventBus().Subscribe(&event.EvtPeerConnectednessChanged{})
141+
lnConfig := append(
142+
[]node.Option{
143+
node.WithTrustedPeers(addrsBridge[0].String())},
144+
nodesConfig...,
145+
)
146+
light := sw.NewLightNode(lnConfig...)
147+
sub, err := light.Host.EventBus().Subscribe(&event.EvtPeerIdentificationCompleted{})
129148
if err != nil {
130149
return err
131150
}
@@ -141,6 +160,7 @@ func TestFullReconstructFromLights(t *testing.T) {
141160
case <-ctx.Done():
142161
t.Fatal("peer was not found")
143162
case <-subs[i].Out():
163+
require.NoError(t, subs[i].Close())
144164
continue
145165
}
146166
}
@@ -156,7 +176,7 @@ func TestFullReconstructFromLights(t *testing.T) {
156176
return full.ShareServ.SharesAvailable(bctx, h.DAH)
157177
})
158178
}
159-
179+
require.NoError(t, <-errCh)
160180
require.NoError(t, errg.Wait())
161181
}
162182

node/tests/swamp/swamp_tx.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,45 @@ package swamp
22

33
import (
44
"context"
5+
"fmt"
56
"math/rand"
6-
"testing"
77
"time"
88

9-
"github.com/stretchr/testify/require"
10-
119
"github.com/celestiaorg/celestia-node/ipld"
1210
)
1311

1412
// SubmitData submits given data in the block.
1513
// TODO(@Wondertan): This must be a real PFD using celestia-app, once we able to run App
1614
// in the Swamp.
17-
func (s *Swamp) SubmitData(ctx context.Context, t *testing.T, data []byte) {
15+
func (s *Swamp) SubmitData(ctx context.Context, data []byte) error {
1816
result, err := s.CoreClient.BroadcastTxSync(ctx, append([]byte("key="), data...))
19-
require.NoError(t, err)
20-
require.Zero(t, result.Code)
17+
if err != nil {
18+
return err
19+
}
20+
if result.Code != 0 {
21+
return fmt.Errorf("invalid status code: %d", result.Code)
22+
}
23+
24+
return nil
2125
}
2226

23-
func (s *Swamp) FillBlocks(ctx context.Context, t *testing.T, bsize, blocks int) {
27+
func (s *Swamp) FillBlocks(ctx context.Context, bsize, blocks int) error {
2428
btime := s.comps.CoreCfg.Consensus.CreateEmptyBlocksInterval
2529
timer := time.NewTimer(btime)
2630
defer timer.Stop()
2731

2832
data := make([]byte, bsize*ipld.ShareSize)
2933
for range make([]int, blocks) {
3034
rand.Read(data) //nolint:gosec
31-
s.SubmitData(ctx, t, data)
32-
35+
if err := s.SubmitData(ctx, data); err != nil {
36+
return err
37+
}
3338
timer.Reset(btime)
3439
select {
3540
case <-timer.C:
3641
case <-ctx.Done():
37-
return
42+
return ctx.Err()
3843
}
3944
}
45+
return nil
4046
}

0 commit comments

Comments
 (0)