From 35f7b8f3fd00b8d9214e833f85dd36710ecc51de Mon Sep 17 00:00:00 2001 From: chengzhinei Date: Mon, 9 Aug 2021 22:59:35 +0800 Subject: [PATCH] Merge PR: fix out of range, change "i++" and "err" (#952) * add defer unlock * fix defer unlock * fix defer unlock * fix out of range[] * add judge of i Co-authored-by: MengXiangJian <805442788@qq.com> --- app/rpc/namespaces/eth/tx_pool.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/rpc/namespaces/eth/tx_pool.go b/app/rpc/namespaces/eth/tx_pool.go index 7aa81629d9..fa32e3ba91 100644 --- a/app/rpc/namespaces/eth/tx_pool.go +++ b/app/rpc/namespaces/eth/tx_pool.go @@ -223,10 +223,16 @@ func (pool *TxPool) continueBroadcast(api *PublicEthereumAPI, currentNonce uint6 } if err != nil { if !strings.Contains(err.Error(), sdkerrors.ErrMempoolIsFull.Error()) { - i++ + if i >= txsLen { + return fmt.Errorf("index out of range") + } err = fmt.Errorf("%s, nonce %d of tx has been dropped, please send again", err.Error(), pool.addressTxsPool[address][i].Data.AccountNonce) + i++ } else { + if i >= txsLen { + return fmt.Errorf("index out of range") + } err = fmt.Errorf("%s, nonce %d :", err.Error(), pool.addressTxsPool[address][i].Data.AccountNonce) } api.logger.Error(err.Error()) @@ -234,6 +240,9 @@ func (pool *TxPool) continueBroadcast(api *PublicEthereumAPI, currentNonce uint6 // update txPool if i != 0 { + if i > txsLen { + return fmt.Errorf("index out of range") + } tmp := make([]*evmtypes.MsgEthereumTx, len(pool.addressTxsPool[address][i:]), viper.GetUint64(TxPoolSliceMaxLen)) copy(tmp, pool.addressTxsPool[address][i:]) pool.addressTxsPool[address] = tmp