diff --git a/core/listener.go b/core/listener.go index 5260067154..514d67ac7c 100644 --- a/core/listener.go +++ b/core/listener.go @@ -51,6 +51,7 @@ type Listener struct { listenerTimeout time.Duration cancel context.CancelFunc + closed chan struct{} } func NewListener( @@ -99,6 +100,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 { @@ -116,13 +118,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 { @@ -131,7 +145,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) diff --git a/go.mod b/go.mod index 5023ad6f1d..a5f5ca8133 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index b2a56315e9..c6a6efcc5e 100644 --- a/go.sum +++ b/go.sum @@ -354,8 +354,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= diff --git a/header/header.go b/header/header.go index a014864551..669061044e 100644 --- a/header/header.go +++ b/header/header.go @@ -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