diff --git a/jsonrpc/backend/backend.go b/jsonrpc/backend/backend.go index 4f39d852..d7245881 100644 --- a/jsonrpc/backend/backend.go +++ b/jsonrpc/backend/backend.go @@ -192,7 +192,7 @@ type AccMut struct { // acquireAccMut acquires the mutex for the account with the given senderHex // and increments the reference count. If the mutex does not exist, it is created. -func (b *JSONRPCBackend) acquireAccMut(senderHex string) { +func (b *JSONRPCBackend) acquireAccMut(senderHex string) *AccMut { // critical section for rc and create b.mut.Lock() accMut, ok := b.accMuts[senderHex] @@ -205,13 +205,13 @@ func (b *JSONRPCBackend) acquireAccMut(senderHex string) { // critical section end accMut.mut.Lock() + return accMut } // releaseAccMut releases the mutex for the account with the given senderHex // and decrements the reference count. If the reference count reaches zero, // the mutex is deleted. -func (b *JSONRPCBackend) releaseAccMut(senderHex string) { - accMut := b.accMuts[senderHex] +func (b *JSONRPCBackend) releaseAccMut(senderHex string, accMut *AccMut) { accMut.mut.Unlock() // critical section for rc and delete diff --git a/jsonrpc/backend/tx.go b/jsonrpc/backend/tx.go index 4be23ec7..b1d8f9b6 100644 --- a/jsonrpc/backend/tx.go +++ b/jsonrpc/backend/tx.go @@ -71,8 +71,8 @@ func (b *JSONRPCBackend) SendTx(tx *coretypes.Transaction) error { senderHex := hexutil.Encode(sender.Bytes()) // hold mutex for each sender - b.acquireAccMut(senderHex) - defer b.releaseAccMut(senderHex) + accMut := b.acquireAccMut(senderHex) + defer b.releaseAccMut(senderHex, accMut) checkCtx := b.app.GetContextForCheckTx(nil) if acc := b.app.AccountKeeper.GetAccount(checkCtx, sender); acc != nil {