6
6
"net/http"
7
7
"strings"
8
8
"sync"
9
+ "sync/atomic"
9
10
"time"
10
11
11
12
bridgeCore "github.com/axieinfinity/bridge-core"
@@ -15,7 +16,7 @@ import (
15
16
"gorm.io/gorm"
16
17
)
17
18
18
- const bridgeVersion = "v2 "
19
+ const bridgeVersion = "v0.2.7 "
19
20
20
21
type NodeInfo struct {
21
22
Organization string `json:"organization,omitempty" mapstructure:"organization"`
@@ -126,6 +127,7 @@ type Service struct {
126
127
processedBlockCh chan processedBlockMessage
127
128
quitCh chan struct {}
128
129
store stores.TaskStore
130
+ isReady atomic.Bool
129
131
}
130
132
131
133
func NewService (node , chainId , operator , host , secret string , db * gorm.DB ) {
@@ -297,6 +299,8 @@ func (s *Service) report(conn *connWrapper) error {
297
299
func (s * Service ) readLoop (conn * connWrapper ) {
298
300
// If the read loop exits, close the connection
299
301
defer conn .Close ()
302
+ // set isReady to true
303
+ s .isReady .Store (true )
300
304
log .Info ("[Bridge stats] Start read loop" )
301
305
for {
302
306
// Exit the function when receiving the quit signal
@@ -348,9 +352,17 @@ func (s *Service) setProcessedBlock(listener string, block uint64) error {
348
352
}
349
353
350
354
func (s * Service ) SendError (listener , err string ) {
355
+ if ! s .isReady .Load () {
356
+ log .Info ("Stats is not ready to broadcast error" )
357
+ return
358
+ }
351
359
s .errCh <- errorMessage {Listener : listener , Err : err }
352
360
}
353
361
354
362
func (s * Service ) SendProcessedBlock (listener string , block uint64 ) {
363
+ if ! s .isReady .Load () {
364
+ log .Info ("Stats is not ready to broadcast processed block" )
365
+ return
366
+ }
355
367
s .processedBlockCh <- processedBlockMessage {Listener : listener , ProcessedBlock : block }
356
368
}
0 commit comments