Asynchronously fetch Terra block height (#177)

This commit is contained in:
Leopold Schabel 2021-02-05 15:16:31 +01:00 committed by GitHub
parent c51a2da83f
commit b0a9e98648
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 18 deletions

View File

@ -92,6 +92,8 @@ func (s *SolanaWatcher) Run(ctx context.Context) error {
}
currentSolanaHeight.Set(float64(slot))
logger.Info("current Solana height", zap.Uint64("slot", uint64(slot)))
// Find TransferOutProposal accounts without a VAA
rCtx, cancel = context.WithTimeout(ctx, time.Second*5)
defer cancel()

View File

@ -118,6 +118,37 @@ func (e *BridgeWatcher) Run(ctx context.Context) error {
readiness.SetReady(common.ReadinessTerraSyncing)
go func() {
t := time.NewTicker(5 * time.Second)
client := &http.Client{
Timeout: time.Second * 5,
}
for {
<-t.C
// Query and report height and set currentTerraHeight
resp, err := client.Get(fmt.Sprintf("%s/blocks/latest", e.urlLCD))
if err != nil {
logger.Error("query latest block response error", zap.Error(err))
continue
}
blocksBody, err := ioutil.ReadAll(resp.Body)
if err != nil {
logger.Error("query guardian set error", zap.Error(err))
errC <- err
resp.Body.Close()
continue
}
resp.Body.Close()
blockJSON := string(blocksBody)
latestBlock := gjson.Get(blockJSON, "block.header.height")
logger.Info("current Terra height", zap.Int64("block", latestBlock.Int()))
currentTerraHeight.Set(float64(latestBlock.Int()))
}
}()
go func() {
defer close(errC)
@ -199,24 +230,6 @@ func (e *BridgeWatcher) Run(ctx context.Context) error {
client := &http.Client{
Timeout: time.Second * 15,
}
// Query and report height and set currentTerraHeight
blocksResp, err := client.Get(fmt.Sprintf("%s/blocks/latest", e.urlLCD))
if err != nil {
logger.Error("query latest block response error", zap.Error(err))
errC <- err
return
}
blocksBody, err := ioutil.ReadAll(blocksResp.Body)
if err != nil {
logger.Error("query guardian set error", zap.Error(err))
errC <- err
blocksResp.Body.Close()
return
}
blockJSON := string(blocksBody)
latestBlock := gjson.Get(blockJSON, "block.header.height")
logger.Info("Current Terra height", zap.Int64("block", latestBlock.Int()))
currentTerraHeight.Set(float64(latestBlock.Int()))
// Query and report guardian set status
requestURL := fmt.Sprintf("%s/wasm/contracts/%s/store?query_msg={\"guardian_set_info\":{}}", e.urlLCD, e.bridge)