near/watcher_fix: improve metrics

This commit is contained in:
Josh Siegel 2022-09-13 15:35:06 -05:00 committed by jumpsiegel
parent a4e395ada7
commit e0843bf2bc
2 changed files with 31 additions and 23 deletions

View File

@ -388,6 +388,28 @@ func (e *Watcher) Run(ctx context.Context) error {
logger.Info("Near watcher connecting to RPC node ", zap.String("url", e.nearRPC)) logger.Info("Near watcher connecting to RPC node ", zap.String("url", e.nearRPC))
go func() {
for {
select {
case <-ctx.Done():
return
case r := <-e.obsvReqC:
if vaa.ChainID(r.ChainId) != vaa.ChainIDNear {
panic("invalid chain ID")
}
txHash := base58.Encode(r.TxHash)
logger.Info("Received obsv request", zap.String("tx_hash", txHash))
err := e.inspectStatus(logger, txHash, e.wormholeContract, 0)
if err != nil {
logger.Error(fmt.Sprintf("near obsvReqC: %s", err.Error()))
}
}
}
}()
go func() { go func() {
if e.next_round == 0 { if e.next_round == 0 {
finalBody, err := e.getFinalBlock() finalBody, err := e.getFinalBlock()
@ -407,20 +429,6 @@ func (e *Watcher) Run(ctx context.Context) error {
select { select {
case <-ctx.Done(): case <-ctx.Done():
return return
case r := <-e.obsvReqC:
if vaa.ChainID(r.ChainId) != vaa.ChainIDNear {
panic("invalid chain ID")
}
txHash := base58.Encode(r.TxHash)
logger.Info("Received obsv request", zap.String("tx_hash", txHash))
err := e.inspectStatus(logger, txHash, e.wormholeContract, 0)
if err != nil {
logger.Error(fmt.Sprintf("near obsvReqC: %s", err.Error()))
}
case <-timer.C: case <-timer.C:
finalBody, err := e.getFinalBlock() finalBody, err := e.getFinalBlock()
if err != nil { if err != nil {
@ -456,6 +464,13 @@ func (e *Watcher) Run(ctx context.Context) error {
logger.Info("lastBlock", zap.Uint64("lastBlock", lastBlock), zap.Uint64("next_round", e.next_round)) logger.Info("lastBlock", zap.Uint64("lastBlock", lastBlock), zap.Uint64("next_round", e.next_round))
for ; e.next_round <= lastBlock; e.next_round = e.next_round + 1 { for ; e.next_round <= lastBlock; e.next_round = e.next_round + 1 {
currentNearHeight.Set(float64(e.next_round))
p2p.DefaultRegistry.SetNetworkStats(vaa.ChainIDNear, &gossipv1.Heartbeat_Network{
Height: int64(e.next_round),
ContractAddress: e.wormholeContract,
})
readiness.SetReady(common.ReadinessNearSyncing)
if e.next_round == lastBlock { if e.next_round == lastBlock {
err := e.inspectBody(logger, e.next_round, parsedFinalBody) err := e.inspectBody(logger, e.next_round, parsedFinalBody)
if err != nil { if err != nil {
@ -487,13 +502,6 @@ func (e *Watcher) Run(ctx context.Context) error {
} }
} }
} }
currentNearHeight.Set(float64(e.next_round - 1))
p2p.DefaultRegistry.SetNetworkStats(vaa.ChainIDNear, &gossipv1.Heartbeat_Network{
Height: int64(e.next_round - 1),
ContractAddress: e.wormholeContract,
})
readiness.SetReady(common.ReadinessNearSyncing)
} }
} }
}() }()

View File

@ -771,11 +771,11 @@ export async function transferNearFromNear(
args: { args: {
receiver: uint8ArrayToHex(receiver), receiver: uint8ArrayToHex(receiver),
chain: chain, chain: chain,
fee: fee.toString(), fee: fee.toString(10),
payload: payload, payload: payload,
message_fee: message_fee, message_fee: message_fee,
}, },
attachedDeposit: (new BN(qty.toString()).add(new BN(message_fee))), attachedDeposit: (new BN(qty.toString(10)).add(new BN(message_fee))),
gas: new BN("100000000000000"), gas: new BN("100000000000000"),
}); });