juptierv6

This commit is contained in:
thloyi
2026-01-07 11:18:02 +08:00
parent c732bb2b46
commit 2d3f46ebbf
3 changed files with 123 additions and 32 deletions

View File

@@ -14,6 +14,7 @@ import (
type AddressTables struct {
rpcClient *rpc.Client
mux sync.RWMutex
loadMux sync.Mutex
tables *lru.Cache[solana.PublicKey, []solana.PublicKey]
loading map[solana.PublicKey]struct{}
@@ -60,32 +61,34 @@ func (at *AddressTables) GetAddressTable(tablePubkey solana.PublicKey, idx []uin
if !ok {
at.mux.RUnlock()
_ = at.pool.Submit(func() {
at.mux.RLock()
at.loadMux.Lock()
_, loading := at.loading[tablePubkey]
if loading {
at.mux.RUnlock()
at.loadMux.Unlock()
return
}
at.mux.RUnlock()
at.mux.Lock()
at.loading[tablePubkey] = struct{}{}
at.mux.Unlock()
at.loadMux.Unlock()
table, err := at.loadAddressTable(tablePubkey)
if err != nil {
logger.Error("loadAddressTable failed", "err", err, "table", tablePubkey)
at.mux.Lock()
at.loadMux.Lock()
delete(at.loading, tablePubkey)
at.mux.Unlock()
at.loadMux.Unlock()
return
}
at.loadMux.Lock()
delete(at.loading, tablePubkey)
at.loadMux.Unlock()
at.mux.Lock()
at.tables.Add(tablePubkey, table)
total := at.tables.Len()
delete(at.loading, tablePubkey)
at.mux.Unlock()
logger.Info("loadAddressTable", "table", tablePubkey.String(), "table count:", total)
})
return nil
}
at.mux.RUnlock()
@@ -93,6 +96,8 @@ func (at *AddressTables) GetAddressTable(tablePubkey solana.PublicKey, idx []uin
var result solana.PublicKeySlice = make([]solana.PublicKey, 0, len(idx))
for _, i := range idx {
if int(i) >= len(addresses) {
logger.Error("over loadAddressTable failed", "idx", i, "table", tablePubkey)
//todo... update table?
continue
}
result = append(result, addresses[i])