Skip to content

Commit

Permalink
Merge PR: Revert "Merge PR: add defer unlock (#947)" (#950)
Browse files Browse the repository at this point in the history
This reverts commit d20a22a.
  • Loading branch information
xiangjianmeng authored Aug 9, 2021
1 parent 41ef416 commit dcf6fc4
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions app/rpc/namespaces/eth/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -320,4 +320,5 @@ func (pool *TxPool) broadcastOnce(api *PublicEthereumAPI) {

err = pool.continueBroadcast(api, currentNonce, address)
}
pool.mu.Unlock()
}

0 comments on commit dcf6fc4

Please sign in to comment.