Skip to content

Commit

Permalink
solve remaining
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis committed Sep 25, 2023
1 parent fcbc3d6 commit 35b4812
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
9 changes: 6 additions & 3 deletions zetaclient/bitcoin_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -662,17 +662,20 @@ func (ob *BitcoinChainClient) refreshPendingNonce() {
pendingNonce := ob.pendingNonce
ob.mu.Unlock()

if p.NonceLow > 0 && uint64(p.NonceLow) >= pendingNonce {
// #nosec G701 always positive
nonceLow := uint64(p.NonceLow)

if nonceLow > 0 && nonceLow >= pendingNonce {
// get the last included outTx hash
txid, err := ob.getOutTxidByNonce(uint64(p.NonceLow)-1, false)
txid, err := ob.getOutTxidByNonce(nonceLow-1, false)
if err != nil {
ob.logger.ChainLogger.Error().Err(err).Msg("refreshPendingNonce: error getting last outTx txid")
}

// set 'NonceLow' as the new pending nonce
ob.mu.Lock()
defer ob.mu.Unlock()
ob.pendingNonce = uint64(p.NonceLow)
ob.pendingNonce = nonceLow
ob.logger.ChainLogger.Info().Msgf("refreshPendingNonce: increase pending nonce to %d with txid %s", ob.pendingNonce, txid)
}
}
Expand Down
9 changes: 6 additions & 3 deletions zetaclient/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,9 @@ func (b *ZetaCoreBridge) GetCctxByNonce(chainID int64, nonce uint64) (*types.Cro
}

func (b *ZetaCoreBridge) GetObserverList(chain common.Chain) ([]string, error) {
var err error

client := zetaObserverTypes.NewQueryClient(b.grpcConn)
err := error(nil)
for i := 0; i <= DefaultRetryCount; i++ {
resp, err := client.ObserversByChain(context.Background(), &zetaObserverTypes.QueryObserversByChainRequest{ObservationChain: chain.ChainName.String()})
if err == nil {
Expand Down Expand Up @@ -164,8 +165,9 @@ func (b *ZetaCoreBridge) GetLatestZetaBlock() (*tmtypes.Block, error) {
}

func (b *ZetaCoreBridge) GetNodeInfo() (*tmservice.GetNodeInfoResponse, error) {
var err error

client := tmservice.NewServiceClient(b.grpcConn)
err := error(nil)
for i := 0; i <= DefaultRetryCount; i++ {
res, err := client.GetNodeInfo(context.Background(), &tmservice.GetNodeInfoRequest{})
if err == nil {
Expand Down Expand Up @@ -214,8 +216,9 @@ func (b *ZetaCoreBridge) GetAllNodeAccounts() ([]*zetaObserverTypes.NodeAccount,
}

func (b *ZetaCoreBridge) GetKeyGen() (*zetaObserverTypes.Keygen, error) {
var err error

client := zetaObserverTypes.NewQueryClient(b.grpcConn)
err := error(nil)
for i := 0; i <= ExtendedRetryCount; i++ {
resp, err := client.Keygen(context.Background(), &zetaObserverTypes.QueryGetKeygenRequest{})
if err == nil {
Expand Down
12 changes: 8 additions & 4 deletions zetaclient/zetacore_observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ func (co *CoreObserver) startSendScheduler() {

// Process Bitcoin OutTx
if common.IsBitcoinChain(c.ChainId) && !outTxMan.IsOutTxActive(outTxID) {
if stop := co.processBitcoinOutTx(outTxMan, idx, cctx, signer, ob, currentHeight); stop {
// #nosec G701 positive
if stop := co.processBitcoinOutTx(outTxMan, uint64(idx), cctx, signer, ob, currentHeight); stop {
break
}
continue
Expand All @@ -190,6 +191,7 @@ func (co *CoreObserver) startSendScheduler() {
continue
}

// #nosec G701 positive
interval := uint64(ob.GetCoreParams().OutboundTxScheduleInterval)
lookahead := ob.GetCoreParams().OutboundTxScheduleLookahead

Expand Down Expand Up @@ -221,6 +223,7 @@ func (co *CoreObserver) startSendScheduler() {
go signer.TryProcessOutTx(cctx, outTxMan, outTxID, ob, co.bridge, currentHeight)
}

// #nosec G701 always in range
if int64(idx) >= lookahead-1 { // only look at 30 sends per chain
break
}
Expand All @@ -242,10 +245,10 @@ func (co *CoreObserver) startSendScheduler() {
// 3. stop processing when pendingNonce/lookahead is reached
//
// Returns whether to stop processing
func (co *CoreObserver) processBitcoinOutTx(outTxMan *OutTxProcessorManager, idx int, send *types.CrossChainTx, signer ChainSigner, ob ChainClient, currentHeight uint64) bool {
func (co *CoreObserver) processBitcoinOutTx(outTxMan *OutTxProcessorManager, idx uint64, send *types.CrossChainTx, signer ChainSigner, ob ChainClient, currentHeight uint64) bool {
params := send.GetCurrentOutTxParam()
nonce := params.OutboundTxTssNonce
lookahead := uint64(ob.GetCoreParams().OutboundTxScheduleLookahead)
lookahead := ob.GetCoreParams().OutboundTxScheduleLookahead
outTxID := fmt.Sprintf("%s-%d-%d", send.Index, params.ReceiverChainId, nonce)

// start go routine to process outtx
Expand All @@ -264,7 +267,8 @@ func (co *CoreObserver) processBitcoinOutTx(outTxMan *OutTxProcessorManager, idx
return true
}
// stop if lookahead is reached. 2 bitcoin confirmations span is 20 minutes on average. We look ahead up to 100 pending cctx to target TPM of 5.
if idx >= int(lookahead)-1 {
// #nosec G701 always in range
if int64(idx) >= lookahead-1 {
return true
}
return false // otherwise, continue
Expand Down

0 comments on commit 35b4812

Please sign in to comment.