From dcf6fc4c74aa294dd88a275491c72513bb46086a Mon Sep 17 00:00:00 2001 From: MengXiangJian <805442788@qq.com> Date: Mon, 9 Aug 2021 17:38:04 +0800 Subject: [PATCH] Merge PR: Revert "Merge PR: add defer unlock (#947)" (#950) This reverts commit d20a22a278822b74e9105b13c841555c3268743a. --- app/rpc/namespaces/eth/tx_pool.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/rpc/namespaces/eth/tx_pool.go b/app/rpc/namespaces/eth/tx_pool.go index 3a39a9a1a1..217fc0ccdd 100644 --- a/app/rpc/namespaces/eth/tx_pool.go +++ b/app/rpc/namespaces/eth/tx_pool.go @@ -125,11 +125,12 @@ func broadcastTxByTxPool(api *PublicEthereumAPI, tx *evmtypes.MsgEthereumTx, txB } api.txPool.mu.Lock() - defer api.txPool.mu.Unlock() if err = api.txPool.CacheAndBroadcastTx(api, from, tx); err != nil { api.logger.Error("eth_sendRawTransaction txPool err:", err.Error()) + api.txPool.mu.Unlock() return common.Hash{}, err } + api.txPool.mu.Unlock() return common.HexToHash(strings.ToUpper(hex.EncodeToString(tmhash.Sum(txBytes)))), nil } @@ -295,7 +296,6 @@ func (pool *TxPool) broadcastPeriod(api *PublicEthereumAPI) { for { time.Sleep(time.Second * time.Duration(viper.GetInt(BroadcastPeriodSecond))) pool.mu.Lock() - defer pool.mu.Unlock() for address, _ := range pool.addressTxsPool { pCurrentNonce, err := api.GetTransactionCount(address, rpctypes.PendingBlockNumber) if err != nil { @@ -305,12 +305,12 @@ func (pool *TxPool) broadcastPeriod(api *PublicEthereumAPI) { pool.continueBroadcast(api, currentNonce, address) } + pool.mu.Unlock() } } func (pool *TxPool) broadcastOnce(api *PublicEthereumAPI) { pool.mu.Lock() - defer pool.mu.Unlock() for address, _ := range pool.addressTxsPool { pCurrentNonce, err := api.GetTransactionCount(address, rpctypes.PendingBlockNumber) if err != nil { @@ -320,4 +320,5 @@ func (pool *TxPool) broadcastOnce(api *PublicEthereumAPI) { err = pool.continueBroadcast(api, currentNonce, address) } + pool.mu.Unlock() }