Skip to content

Commit 249bc93

Browse files
authored
Unavailable currencies will no longer cache negative support value (#116)
1 parent b8506a5 commit 249bc93

1 file changed

Lines changed: 27 additions & 12 deletions

File tree

ocp/common/mint.go

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
commonpb "github.com/code-payments/ocp-protobuf-api/generated/go/common/v1"
1111
"github.com/code-payments/ocp-server/ocp/config"
1212
ocp_data "github.com/code-payments/ocp-server/ocp/data"
13+
"github.com/code-payments/ocp-server/ocp/data/currency"
1314
"github.com/code-payments/ocp-server/solana/currencycreator"
1415
"github.com/code-payments/ocp-server/usdc"
1516
"github.com/code-payments/ocp-server/usdf"
@@ -80,31 +81,45 @@ func IsSupportedMint(ctx context.Context, data ocp_data.Provider, mintAccount *A
8081
return entry.isSupported, nil
8182
}
8283

83-
isSupported, err := isSupportedMint(ctx, data, mintAccount)
84+
isSupported, canCache, err := isSupportedMint(ctx, data, mintAccount)
8485
if err != nil {
8586
return false, err
8687
}
8788

88-
supportedMintCacheMu.Lock()
89-
supportedMintCache[mintAddress] = supportedMintCacheEntry{
90-
isSupported: isSupported,
91-
cachedAt: time.Now(),
89+
if canCache {
90+
supportedMintCacheMu.Lock()
91+
supportedMintCache[mintAddress] = supportedMintCacheEntry{
92+
isSupported: isSupported,
93+
cachedAt: time.Now(),
94+
}
95+
supportedMintCacheMu.Unlock()
9296
}
93-
supportedMintCacheMu.Unlock()
9497

9598
return isSupported, nil
9699
}
97100

98-
func isSupportedMint(ctx context.Context, data ocp_data.Provider, mintAccount *Account) (bool, error) {
101+
func isSupportedMint(ctx context.Context, data ocp_data.Provider, mintAccount *Account) (isSupported bool, canCache bool, err error) {
99102
if !IsCoreMint(mintAccount) && !IsCoreMintUsdStableCoin() {
100-
return false, nil
103+
return false, true, nil
101104
}
102105

103-
_, err := GetVmConfigForMint(ctx, data, mintAccount)
106+
_, err = GetVmConfigForMint(ctx, data, mintAccount)
104107
if err == ErrUnsupportedMint {
105-
return false, nil
108+
// Don't cache supported=false for launchpad currencies that exist
109+
// but aren't in the available state yet, since they may become
110+
// available at any time.
111+
canCache = true
112+
if !IsCoreMint(mintAccount) {
113+
_, err := data.GetCurrencyMetadata(ctx, mintAccount.PublicKey().ToBase58())
114+
if err == nil {
115+
canCache = false
116+
} else if err != currency.ErrNotFound {
117+
return false, false, err
118+
}
119+
}
120+
return false, canCache, nil
106121
} else if err != nil {
107-
return false, err
122+
return false, false, err
108123
}
109-
return true, nil
124+
return true, true, nil
110125
}

0 commit comments

Comments
 (0)