Skip to content

Commit 3ac8098

Browse files
refactor(handshake): drop redundant cache purge on chequebook change
1 parent 48fd866 commit 3ac8098

2 files changed

Lines changed: 5 additions & 18 deletions

File tree

pkg/p2p/libp2p/internal/handshake/addresscache.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,3 @@ func (c *addressCache) getOrMint(key string, now int64, mint func(timestamp int6
4949

5050
return addr, nil
5151
}
52-
53-
// purge drops the cached address; the next getOrMint re-signs.
54-
func (c *addressCache) purge() {
55-
c.mu.Lock()
56-
defer c.mu.Unlock()
57-
58-
c.key, c.addr = "", nil
59-
}

pkg/p2p/libp2p/internal/handshake/handshake.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ type Service struct {
102102
mu sync.RWMutex
103103
hostAddresser Addresser
104104
now func() time.Time
105-
106-
addrCache addressCache // session-stable signed address, keyed by chequebook + underlays
105+
addrCache addressCache // session-stable signed address, keyed by chequebook + underlays
107106
}
108107

109108
// Info contains the information received from the handshake.
@@ -149,19 +148,15 @@ func New(signer crypto.Signer, advertisableAddresser AdvertisableAddressResolver
149148
}
150149

151150
// SetChequebookAddress sets the local chequebook address included in
152-
// subsequent signed BzzAddress payloads; the zero value clears it. The cached
153-
// signed address is purged so the next handshake re-signs. A mint in flight
154-
// during this call may land after the purge, but is keyed under the old
155-
// chequebook and simply gets overwritten by the next handshake.
151+
// subsequent signed BzzAddress payloads; the zero value clears it. The
152+
// chequebook is part of the signed-address cache key, so the next handshake
153+
// misses the cache and re-signs with the new chequebook.
156154
func (s *Service) SetChequebookAddress(addr common.Address) {
157155
if (addr == common.Address{}) {
158156
s.chequebookAddr.Store(nil)
159157
} else {
160-
cp := addr
161-
s.chequebookAddr.Store(&cp)
158+
s.chequebookAddr.Store(&addr)
162159
}
163-
164-
s.addrCache.purge()
165160
}
166161

167162
func (s *Service) chequebookAddress() common.Address {

0 commit comments

Comments
 (0)