diff --git a/accountresolver/resolver.go b/accountresolver/resolver.go index 1713e4dc..d7673a5b 100644 --- a/accountresolver/resolver.go +++ b/accountresolver/resolver.go @@ -62,7 +62,7 @@ func (r *KVDBAccountsResolver) CommitBlock(ctx context.Context, blockNum uint64) return fmt.Errorf("flushing extended accounts for tableKey %q: %w", tableKey, err) } - r.pushToCache(blockNum, tableKey.Base58(), extendedAccounts) + r.prependToCache(blockNum, tableKey.Base58(), extendedAccounts) } r.toCommit = make(map[string][]Account) return nil @@ -91,7 +91,7 @@ func (r *KVDBAccountsResolver) Resolve(ctx context.Context, atBlockNum uint64, k _, keyBlockNum := Keys.UnpackTableLookup(item.Key) accounts := DecodeAccounts(item.Value) - r.pushToCache(keyBlockNum, key.Base58(), accounts) + r.appendToCache(keyBlockNum, key.Base58(), accounts) if keyBlockNum < atBlockNum && resolvedAccounts == nil { resolvedAccounts = accounts @@ -124,7 +124,7 @@ func (r *KVDBAccountsResolver) ResolveWithBlock(ctx context.Context, atBlockNum _, keyBlockNum = Keys.UnpackTableLookup(item.Key) accounts := DecodeAccounts(item.Value) - r.pushToCache(keyBlockNum, key.Base58(), accounts) + r.appendToCache(keyBlockNum, key.Base58(), accounts) if keyBlockNum <= atBlockNum && resolvedAccounts == nil { resolvedAccounts = accounts @@ -168,7 +168,22 @@ func (r *KVDBAccountsResolver) GetCursor(ctx context.Context, readerName string) return NewCursor(blockNum), nil } -func (r *KVDBAccountsResolver) pushToCache(blockNum uint64, key string, accounts Accounts) { +func (r *KVDBAccountsResolver) appendToCache(blockNum uint64, key string, accounts Accounts) { + if cacheItems, found := r.cache[key]; found { + for _, ci := range cacheItems { + if ci.blockNum == blockNum { + return + } + } + } + r.cache[key] = append(r.cache[key], []*cacheItem{ + { + blockNum: blockNum, + accounts: accounts, + }, + }...) +} +func (r *KVDBAccountsResolver) prependToCache(blockNum uint64, key string, accounts Accounts) { if cacheItems, found := r.cache[key]; found { for _, ci := range cacheItems { if ci.blockNum == blockNum { diff --git a/accountresolver/resolver_test.go b/accountresolver/resolver_test.go index 38798b01..674c7422 100644 --- a/accountresolver/resolver_test.go +++ b/accountresolver/resolver_test.go @@ -9,6 +9,7 @@ import ( "github.com/streamingfast/kvdb/store" _ "github.com/streamingfast/kvdb/store/badger3" + _ "github.com/streamingfast/kvdb/store/bigkv" "github.com/stretchr/testify/require" ) @@ -18,6 +19,22 @@ var a3 = "5J7HHVuLb1kUn9q4PZgGYsLm4DNRg1dcmB5FENuM7wQz" var a4 = "9hT5nqawMAn4xgCcjCmiPDXzVqECQTap3c3wHk6dxyFx" var a5 = "A8YFwAca6hSp9Xw1RcqUcdXuVgMvQbT2yYLmArCFKxfD" +func TestKVDBAccountsResolver_WTF(t *testing.T) { + + db, err := store.New("bigkv://dfuseio-global.dfuse-saas/sol-account-lookup-v1.1") + require.NoError(t, err) + + resolver := NewKVDBAccountsResolver(db, zap.NewNop()) + accounts, _, err := resolver.Resolve(context.Background(), 154804305, MustFromBase58("2yEiJNpLnFPizeXzpFSGwBC6idLfNYCJ2h42EqqdJ19h")) + require.NoError(t, err) + require.Equal(t, 254, len(accounts)) + + accounts, _, err = resolver.Resolve(context.Background(), 154804305, MustFromBase58("2yEiJNpLnFPizeXzpFSGwBC6idLfNYCJ2h42EqqdJ19h")) + require.NoError(t, err) + require.Equal(t, 254, len(accounts)) + +} + func TestKVDBAccountsResolver_Extended(t *testing.T) { err := os.RemoveAll("/tmp/my-badger.db") require.NoError(t, err) diff --git a/cmd/firesol/validate_resolved_accounts.go b/cmd/firesol/validate_resolved_accounts.go index 0e09a9e1..8977b306 100644 --- a/cmd/firesol/validate_resolved_accounts.go +++ b/cmd/firesol/validate_resolved_accounts.go @@ -121,7 +121,7 @@ func processValidateAllResolvedAddressesE(chain *firecore.Chain[*pbsolv1.Block], fmt.Println("Saved validation state file", keyCount, notFoundCount) } - time.Sleep(time.Second / 10) + time.Sleep(time.Second / 5) item := iter.Item() tableAccount, atBlock := accountsresolver.Keys.UnpackTableLookup(item.Key)