juptierv6
This commit is contained in:
@@ -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])
|
||||
|
||||
Reference in New Issue
Block a user