Skip to content

Commit

Permalink
Merge branch 'main' into discovery-nitpick
Browse files Browse the repository at this point in the history
  • Loading branch information
Wondertan authored Sep 26, 2024
2 parents 464b2a4 + 98a127b commit 180e06d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
20 changes: 17 additions & 3 deletions core/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type Listener struct {

listenerTimeout time.Duration
cancel context.CancelFunc
closed chan struct{}
}

func NewListener(
Expand Down Expand Up @@ -97,6 +98,7 @@ func (cl *Listener) Start(context.Context) error {

ctx, cancel := context.WithCancel(context.Background())
cl.cancel = cancel
cl.closed = make(chan struct{})

sub, err := cl.fetcher.SubscribeNewBlockEvent(ctx)
if err != nil {
Expand All @@ -114,13 +116,25 @@ func (cl *Listener) Stop(ctx context.Context) error {
}

cl.cancel()
cl.cancel = nil
return cl.metrics.Close()
select {
case <-cl.closed:
cl.cancel = nil
cl.closed = nil
case <-ctx.Done():
return ctx.Err()
}

err = cl.metrics.Close()
if err != nil {
log.Warnw("listener: closing metrics", "err", err)
}
return nil
}

// runSubscriber runs a subscriber to receive event data of new signed blocks. It will attempt to
// resubscribe in case error happens during listening of subscription
func (cl *Listener) runSubscriber(ctx context.Context, sub <-chan types.EventDataSignedBlock) {
defer close(cl.closed)
for {
err := cl.listen(ctx, sub)
if ctx.Err() != nil {
Expand All @@ -129,7 +143,7 @@ func (cl *Listener) runSubscriber(ctx context.Context, sub <-chan types.EventDat
}
if errors.Is(err, errInvalidSubscription) {
// stop node if there is a critical issue with the block subscription
log.Fatalf("listener: %v", err)
log.Fatalf("listener: %v", err) //nolint:gocritic
}

log.Warnw("listener: subscriber error, resubscribing...", "err", err)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/BurntSushi/toml v1.4.0
github.com/alecthomas/jsonschema v0.0.0-20220216202328-9eeeec9d044b
github.com/benbjohnson/clock v1.3.5
github.com/celestiaorg/celestia-app/v2 v2.1.2
github.com/celestiaorg/celestia-app/v2 v2.2.0-arabica
github.com/celestiaorg/go-fraud v0.2.1
github.com/celestiaorg/go-header v0.6.2
github.com/celestiaorg/go-libp2p-messenger v0.2.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ github.com/c-bata/go-prompt v0.2.2/go.mod h1:VzqtzE2ksDBcdln8G7mk2RX9QyGjH+OVqOC
github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ=
github.com/celestiaorg/blobstream-contracts/v3 v3.1.0 h1:h1Y4V3EMQ2mFmNtWt2sIhZIuyASInj1a9ExI8xOsTOw=
github.com/celestiaorg/blobstream-contracts/v3 v3.1.0/go.mod h1:x4DKyfKOSv1ZJM9NwV+Pw01kH2CD7N5zTFclXIVJ6GQ=
github.com/celestiaorg/celestia-app/v2 v2.1.2 h1:/3NhEPkVHahKrJ3blehDPjy7AzWq8z68afgvEmor/tk=
github.com/celestiaorg/celestia-app/v2 v2.1.2/go.mod h1:qraGN1WNAtIFwGWB0NWnZ3tGPL5joPlbLStSZ4k6niQ=
github.com/celestiaorg/celestia-app/v2 v2.2.0-arabica h1:EbcV7BVOs8oaN4DFO76B9dKOJtZu1DH8yLSGcwejIKU=
github.com/celestiaorg/celestia-app/v2 v2.2.0-arabica/go.mod h1:+7xlXlBA3Tx9u1LxZF/4QAaAGfBIXv8JPrrFQAbLiWA=
github.com/celestiaorg/celestia-core v1.40.0-tm-v0.34.29 h1:J79TAjizxwIvm7/k+WI3PPH1aFj4AjOSjajoq5UzAwI=
github.com/celestiaorg/celestia-core v1.40.0-tm-v0.34.29/go.mod h1:5jJ5magtH7gQOwSYfS/m5fliIS7irKunLV7kLNaD8o0=
github.com/celestiaorg/cosmos-sdk v1.24.1-sdk-v0.46.16 h1:SeQ7Y/CyOcUMKo7mQiexaj/pZ/xIgyuZFIwYZwpSkWE=
Expand Down
2 changes: 1 addition & 1 deletion header/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (eh *ExtendedHeader) Verify(untrst *ExtendedHeader) error {
if err := eh.ValidatorSet.VerifyCommitLightTrusting(eh.ChainID(), untrst.Commit, light.DefaultTrustLevel); err != nil {
return &libhead.VerifyError{
Reason: fmt.Errorf("%w: %w", ErrVerifyCommitLightTrustingFailed, err),
SoftFailure: true,
SoftFailure: core.IsErrNotEnoughVotingPowerSigned(err),
}
}
return nil
Expand Down

0 comments on commit 180e06d

Please sign in to comment.