Skip to content

Commit d239616

Browse files
fix: broken shutdown for services on fraud proofs receival (#1220)
Closes #1205 Co-authored-by: Wondertan <[email protected]>
1 parent 7fcb0f3 commit d239616

File tree

9 files changed

+23
-29
lines changed

9 files changed

+23
-29
lines changed

nodebuilder/daser/module.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77

88
"github.com/celestiaorg/celestia-node/das"
99
"github.com/celestiaorg/celestia-node/fraud"
10-
"github.com/celestiaorg/celestia-node/libs/fxutil"
1110
fraudServ "github.com/celestiaorg/celestia-node/nodebuilder/fraud"
1211
"github.com/celestiaorg/celestia-node/nodebuilder/node"
1312
)
@@ -19,9 +18,8 @@ func ConstructModule(tp node.Type) fx.Option {
1918
"daser",
2019
fx.Provide(fx.Annotate(
2120
NewDASer,
22-
fx.OnStart(func(ctx context.Context, lc fx.Lifecycle, fservice fraudServ.Module, das *das.DASer) error {
23-
lifecycleCtx := fxutil.WithLifecycle(ctx, lc)
24-
return fraudServ.Lifecycle(ctx, lifecycleCtx, fraud.BadEncoding, fservice,
21+
fx.OnStart(func(startCtx, ctx context.Context, fservice fraudServ.Module, das *das.DASer) error {
22+
return fraudServ.Lifecycle(startCtx, ctx, fraud.BadEncoding, fservice,
2523
das.Start, das.Stop)
2624
}),
2725
fx.OnStop(func(ctx context.Context, das *das.DASer) error {

nodebuilder/header/module.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/celestiaorg/celestia-node/header/p2p"
1212
"github.com/celestiaorg/celestia-node/header/store"
1313
"github.com/celestiaorg/celestia-node/header/sync"
14-
"github.com/celestiaorg/celestia-node/libs/fxutil"
1514
fraudServ "github.com/celestiaorg/celestia-node/nodebuilder/fraud"
1615
"github.com/celestiaorg/celestia-node/nodebuilder/node"
1716
"github.com/celestiaorg/celestia-node/params"
@@ -43,7 +42,7 @@ func ConstructModule(tp node.Type, cfg *Config) fx.Option {
4342
}),
4443
fx.Provide(fx.Annotate(
4544
newSyncer,
46-
fx.OnStart(func(ctx context.Context, lc fx.Lifecycle, fservice fraudServ.Module, syncer *sync.Syncer) error {
45+
fx.OnStart(func(startCtx, ctx context.Context, fservice fraudServ.Module, syncer *sync.Syncer) error {
4746
syncerStartFunc := func(ctx context.Context) error {
4847
err := syncer.Start(ctx)
4948
switch err {
@@ -55,8 +54,7 @@ func ConstructModule(tp node.Type, cfg *Config) fx.Option {
5554
}
5655
return nil
5756
}
58-
lifecycleCtx := fxutil.WithLifecycle(ctx, lc)
59-
return fraudServ.Lifecycle(ctx, lifecycleCtx, fraud.BadEncoding, fservice,
57+
return fraudServ.Lifecycle(startCtx, ctx, fraud.BadEncoding, fservice,
6058
syncerStartFunc, syncer.Stop)
6159
}),
6260
fx.OnStop(func(ctx context.Context, syncer *sync.Syncer) error {

nodebuilder/module.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"go.uber.org/fx"
77

8+
"github.com/celestiaorg/celestia-node/libs/fxutil"
89
"github.com/celestiaorg/celestia-node/nodebuilder/core"
910
"github.com/celestiaorg/celestia-node/nodebuilder/daser"
1011
"github.com/celestiaorg/celestia-node/nodebuilder/fraud"
@@ -21,7 +22,9 @@ func ConstructModule(tp node.Type, cfg *Config, store Store) fx.Option {
2122
baseComponents := fx.Options(
2223
fx.Provide(params.DefaultNetwork),
2324
fx.Provide(params.BootstrappersFor),
24-
fx.Provide(context.Background),
25+
fx.Provide(func(lc fx.Lifecycle) context.Context {
26+
return fxutil.WithLifecycle(context.Background(), lc)
27+
}),
2528
fx.Supply(cfg),
2629
fx.Supply(store.Config),
2730
fx.Provide(store.Datastore),

nodebuilder/p2p/bitswap.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
routinghelpers "github.com/libp2p/go-libp2p-routing-helpers"
1515
"go.uber.org/fx"
1616

17-
"github.com/celestiaorg/celestia-node/libs/fxutil"
1817
nparams "github.com/celestiaorg/celestia-node/params"
1918
)
2019

@@ -29,9 +28,8 @@ const (
2928

3029
// DataExchange provides a constructor for IPFS block's DataExchange over BitSwap.
3130
func DataExchange(params bitSwapParams) (exchange.Interface, blockstore.Blockstore, error) {
32-
ctx := fxutil.WithLifecycle(params.Ctx, params.Lc)
3331
bs, err := blockstore.CachedBlockstore(
34-
ctx,
32+
params.Ctx,
3533
blockstore.NewBlockstore(params.Ds),
3634
blockstore.CacheOpts{
3735
HasBloomFilterSize: defaultBloomFilterSize,
@@ -44,7 +42,7 @@ func DataExchange(params bitSwapParams) (exchange.Interface, blockstore.Blocksto
4442
}
4543
prefix := protocol.ID(fmt.Sprintf("/celestia/%s", params.Net))
4644
return bitswap.New(
47-
ctx,
45+
params.Ctx,
4846
network.NewFromIpfsHost(params.Host, &routinghelpers.Null{}, network.Prefix(prefix)),
4947
bs,
5048
bitswap.ProvideEnabled(false),
@@ -60,7 +58,6 @@ type bitSwapParams struct {
6058

6159
Ctx context.Context
6260
Net nparams.Network
63-
Lc fx.Lifecycle
6461
Host host.Host
6562
Ds datastore.Batching
6663
}

nodebuilder/p2p/pubsub.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import (
88
pubsub_pb "github.com/libp2p/go-libp2p-pubsub/pb"
99
"go.uber.org/fx"
1010
"golang.org/x/crypto/blake2b"
11-
12-
"github.com/celestiaorg/celestia-node/libs/fxutil"
1311
)
1412

1513
// PubSub provides a constructor for PubSub protocol with GossipSub routing.
@@ -34,7 +32,7 @@ func PubSub(cfg Config, params pubSubParams) (*pubsub.PubSub, error) {
3432
}
3533

3634
return pubsub.NewGossipSub(
37-
fxutil.WithLifecycle(params.Ctx, params.Lc),
35+
params.Ctx,
3836
params.Host,
3937
opts...,
4038
)
@@ -49,6 +47,5 @@ type pubSubParams struct {
4947
fx.In
5048

5149
Ctx context.Context
52-
Lc fx.Lifecycle
5350
Host host.Host
5451
}

nodebuilder/p2p/routing.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
dht "github.com/libp2p/go-libp2p-kad-dht"
1212
"go.uber.org/fx"
1313

14-
"github.com/celestiaorg/celestia-node/libs/fxutil"
1514
nparams "github.com/celestiaorg/celestia-node/params"
1615
)
1716

@@ -42,7 +41,7 @@ func PeerRouting(cfg Config, params routingParams) (routing.PeerRouting, error)
4241
)
4342
}
4443

45-
d, err := dht.New(fxutil.WithLifecycle(params.Ctx, params.Lc), params.Host, opts...)
44+
d, err := dht.New(params.Ctx, params.Host, opts...)
4645
if err != nil {
4746
return nil, err
4847
}

nodebuilder/state/module.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"go.uber.org/fx"
88

99
"github.com/celestiaorg/celestia-node/fraud"
10-
"github.com/celestiaorg/celestia-node/libs/fxutil"
1110
fraudServ "github.com/celestiaorg/celestia-node/nodebuilder/fraud"
1211
"github.com/celestiaorg/celestia-node/nodebuilder/node"
1312
"github.com/celestiaorg/celestia-node/state"
@@ -27,9 +26,8 @@ func ConstructModule(tp node.Type, cfg *Config) fx.Option {
2726
fx.Provide(Keyring),
2827
fx.Provide(fx.Annotate(
2928
CoreAccessor,
30-
fx.OnStart(func(ctx context.Context, lc fx.Lifecycle, fservice fraudServ.Module, ca *state.CoreAccessor) error {
31-
lifecycleCtx := fxutil.WithLifecycle(ctx, lc)
32-
return fraudServ.Lifecycle(ctx, lifecycleCtx, fraud.BadEncoding, fservice, ca.Start, ca.Stop)
29+
fx.OnStart(func(startCtx, ctx context.Context, fservice fraudServ.Module, ca *state.CoreAccessor) error {
30+
return fraudServ.Lifecycle(startCtx, ctx, fraud.BadEncoding, fservice, ca.Start, ca.Stop)
3331
}),
3432
fx.OnStop(func(ctx context.Context, ca *state.CoreAccessor) error {
3533
return ca.Stop(ctx)

nodebuilder/tests/fraud_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func TestFraudProofSyncing(t *testing.T) {
107107
store := nodebuilder.MockStore(t, cfg)
108108
bridge := sw.NewNodeWithStore(node.Bridge, store, core.WithHeaderConstructFn(header.FraudMaker(t, 10)))
109109

110-
ctx, cancel := context.WithTimeout(context.Background(), time.Minute*5)
110+
ctx, cancel := context.WithTimeout(context.Background(), swamp.DefaultTestTimeout)
111111
t.Cleanup(cancel)
112112

113113
err := bridge.Start(ctx)
@@ -123,21 +123,24 @@ func TestFraudProofSyncing(t *testing.T) {
123123
lightCfg := nodebuilder.DefaultConfig(node.Light)
124124
lightCfg.P2P.RoutingTableRefreshPeriod = defaultTimeInterval
125125
lightCfg.Share.DiscoveryInterval = defaultTimeInterval
126-
ln := sw.NewNodeWithStore(node.Light, nodebuilder.MockStore(t, lightCfg),
127-
nodebuilder.WithBootstrappers([]peer.AddrInfo{*addr}))
126+
lightCfg.Header.TrustedPeers = append(lightCfg.Header.TrustedPeers, addrs[0].String())
127+
ln := sw.NewNodeWithStore(node.Light, nodebuilder.MockStore(t, lightCfg))
128128

129129
require.NoError(t, full.Start(ctx))
130+
require.NoError(t, ln.Start(ctx))
130131
subsFn, err := full.FraudServ.Subscribe(fraud.BadEncoding)
131132
require.NoError(t, err)
132133
defer subsFn.Cancel()
133134
_, err = subsFn.Proof(ctx)
134135
require.NoError(t, err)
135136

136-
require.NoError(t, ln.Start(ctx))
137137
// internal subscription for the fraud proof is done in order to ensure that light node
138138
// receives the BEFP.
139139
subsLn, err := ln.FraudServ.Subscribe(fraud.BadEncoding)
140140
require.NoError(t, err)
141+
142+
err = ln.Host.Connect(ctx, *host.InfoFromHost(full.Host))
143+
require.NoError(t, err)
141144
_, err = subsLn.Proof(ctx)
142145
require.NoError(t, err)
143146
subsLn.Cancel()

state/core_access.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ func (ca *CoreAccessor) Start(ctx context.Context) error {
9898
func (ca *CoreAccessor) Stop(context.Context) error {
9999
defer ca.cancel()
100100
if ca.coreConn == nil {
101-
return fmt.Errorf("core-access: no connection found to close")
101+
log.Warn("no connection found to close")
102+
return nil
102103
}
103104
// close out core connection
104105
err := ca.coreConn.Close()

0 commit comments

Comments
 (0)