From e9ba15b00b3a069b8368b402fa9b6c854a5f26c6 Mon Sep 17 00:00:00 2001 From: beer-1 Date: Sat, 16 Nov 2024 18:38:37 +0900 Subject: [PATCH] fix to pass mut in stead of reading it again --- jsonrpc/backend/backend.go | 6 +++--- jsonrpc/backend/tx.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/jsonrpc/backend/backend.go b/jsonrpc/backend/backend.go index 4f39d85..d724588 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 4be23ec..b1d8f9b 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 {