From 315d381603ab81a8888d4d45eb0e77109c394e56 Mon Sep 17 00:00:00 2001 From: maskpp Date: Tue, 1 Jul 2025 11:26:01 +0800 Subject: [PATCH] delete the certain value of id --- core/txpool/reserver.go | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/core/txpool/reserver.go b/core/txpool/reserver.go index b6ecef9f1a..4fc107bdf9 100644 --- a/core/txpool/reserver.go +++ b/core/txpool/reserver.go @@ -39,14 +39,14 @@ var ( // the account and ensure that one address cannot initiate transactions, authorizations, // and other state-changing behaviors in different pools at the same time. type ReservationTracker struct { - accounts map[common.Address]int + accounts map[common.Address]struct{} lock sync.RWMutex } // NewReservationTracker initializes the account reservation tracker. func NewReservationTracker() *ReservationTracker { return &ReservationTracker{ - accounts: make(map[common.Address]int), + accounts: make(map[common.Address]struct{}), } } @@ -88,15 +88,11 @@ func (h *ReservationHandle) Hold(addr common.Address) error { // Double reservations are forbidden even from the same pool to // avoid subtle bugs in the long term. - owner, exists := h.tracker.accounts[addr] + _, exists := h.tracker.accounts[addr] if exists { - if owner == h.id { - log.Error("pool attempted to reserve already-owned address", "address", addr) - return nil // Ignore fault to give the pool a chance to recover while the bug gets fixed - } return ErrAlreadyReserved } - h.tracker.accounts[addr] = h.id + h.tracker.accounts[addr] = struct{}{} if metrics.Enabled() { m := fmt.Sprintf("%s/%d", reservationsGaugeName, h.id) metrics.GetOrRegisterGauge(m, nil).Inc(1) @@ -111,15 +107,11 @@ func (h *ReservationHandle) Release(addr common.Address) error { // Ensure subpools only attempt to unreserve their own owned addresses, // otherwise flag as a programming error. - owner, exists := h.tracker.accounts[addr] + _, exists := h.tracker.accounts[addr] if !exists { log.Error("pool attempted to unreserve non-reserved address", "address", addr) return errors.New("address not reserved") } - if owner != h.id { - log.Error("pool attempted to unreserve non-owned address", "address", addr) - return errors.New("address not owned") - } delete(h.tracker.accounts, addr) if metrics.Enabled() { m := fmt.Sprintf("%s/%d", reservationsGaugeName, h.id) @@ -133,6 +125,6 @@ func (h *ReservationHandle) Has(address common.Address) bool { h.tracker.lock.RLock() defer h.tracker.lock.RUnlock() - id, exists := h.tracker.accounts[address] - return exists && id != h.id + _, exists := h.tracker.accounts[address] + return exists }