@@ -10,7 +10,7 @@ import (
10
10
"sync"
11
11
"sync/atomic"
12
12
13
- "github.com/hashicorp/golang-lru/simplelru"
13
+ "github.com/hashicorp/golang-lru/v2/ simplelru"
14
14
"sigs.k8s.io/yaml"
15
15
16
16
errorsmod "cosmossdk.io/errors"
@@ -81,11 +81,11 @@ var (
81
81
// AccAddress.String() is expensive and if unoptimized dominantly showed up in profiles,
82
82
// yet has no mechanisms to trivially cache the result given that AccAddress is a []byte type.
83
83
accAddrMu sync.Mutex
84
- accAddrCache * simplelru.LRU
84
+ accAddrCache * simplelru.LRU [ string , string ]
85
85
consAddrMu sync.Mutex
86
- consAddrCache * simplelru.LRU
86
+ consAddrCache * simplelru.LRU [ string , string ]
87
87
valAddrMu sync.Mutex
88
- valAddrCache * simplelru.LRU
88
+ valAddrCache * simplelru.LRU [ string , string ]
89
89
90
90
isCachingEnabled atomic.Bool
91
91
)
@@ -101,13 +101,13 @@ func init() {
101
101
102
102
// in total the cache size is 61k entries. Key is 32 bytes and value is around 50-70 bytes.
103
103
// That will make around 92 * 61k * 2 (LRU) bytes ~ 11 MB
104
- if accAddrCache , err = simplelru .NewLRU (60000 , nil ); err != nil {
104
+ if accAddrCache , err = simplelru .NewLRU [ string , string ] (60000 , nil ); err != nil {
105
105
panic (err )
106
106
}
107
- if consAddrCache , err = simplelru .NewLRU (500 , nil ); err != nil {
107
+ if consAddrCache , err = simplelru .NewLRU [ string , string ] (500 , nil ); err != nil {
108
108
panic (err )
109
109
}
110
- if valAddrCache , err = simplelru .NewLRU (500 , nil ); err != nil {
110
+ if valAddrCache , err = simplelru .NewLRU [ string , string ] (500 , nil ); err != nil {
111
111
panic (err )
112
112
}
113
113
}
@@ -309,7 +309,7 @@ func (aa AccAddress) String() string {
309
309
310
310
addr , ok := accAddrCache .Get (key )
311
311
if ok {
312
- return addr .( string )
312
+ return addr
313
313
}
314
314
}
315
315
return cacheBech32Addr (GetConfig ().GetBech32AccountAddrPrefix (), aa , accAddrCache , key )
@@ -463,7 +463,7 @@ func (va ValAddress) String() string {
463
463
464
464
addr , ok := valAddrCache .Get (key )
465
465
if ok {
466
- return addr .( string )
466
+ return addr
467
467
}
468
468
}
469
469
return cacheBech32Addr (GetConfig ().GetBech32ValidatorAddrPrefix (), va , valAddrCache , key )
@@ -623,7 +623,7 @@ func (ca ConsAddress) String() string {
623
623
624
624
addr , ok := consAddrCache .Get (key )
625
625
if ok {
626
- return addr .( string )
626
+ return addr
627
627
}
628
628
}
629
629
return cacheBech32Addr (GetConfig ().GetBech32ConsensusAddrPrefix (), ca , consAddrCache , key )
@@ -699,7 +699,7 @@ func addressBytesFromHexString(address string) ([]byte, error) {
699
699
}
700
700
701
701
// cacheBech32Addr is not concurrency safe. Concurrent access to cache causes race condition.
702
- func cacheBech32Addr (prefix string , addr []byte , cache * simplelru.LRU , cacheKey string ) string {
702
+ func cacheBech32Addr (prefix string , addr []byte , cache * simplelru.LRU [ string , string ] , cacheKey string ) string {
703
703
bech32Addr , err := bech32 .ConvertAndEncode (prefix , addr )
704
704
if err != nil {
705
705
panic (err )
0 commit comments