Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning]https://semver.org/spec/v2.0.0.

### Unreleased

- fix: processed block wait load cache address from db for first start

### [0.9.9] - 2026-01-23

- fix: increase default page size for transaction
Expand Down
21 changes: 13 additions & 8 deletions internal/services/wallets/cacher.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,13 @@ func (s *Service) updateCacheWrapper(ctx context.Context, isEnabled bool) error
return nil
}

if err := s.cacherHandler(ctx); err != nil {
return fmt.Errorf("initial cache load: %w", err)
}

ticker := time.NewTicker(cacherInterval)
defer ticker.Stop()

// immediately process webhooks after startup service
go func() {
if err := s.cacherHandler(ctx); err != nil {
s.logger.Error(err)
}
}()

// process webhooks by ticker
for {
select {
case <-ctx.Done():
Expand Down Expand Up @@ -138,6 +134,15 @@ func (s *Service) cacherHandler(ctx context.Context) error {
return err
}

s.cacheReadyOnce.Do(func() {
s.logger.Infow("wallet cache loaded",
"hot_wallets", dbHotWalletsLength,
"processing_wallets", dbProcessingWalletsLength,
"cold_wallets", dbColdWalletsLength,
)
close(s.cacheReady)
})

now := time.Now()

// log cache sizes every 5 seconds
Expand Down
5 changes: 5 additions & 0 deletions internal/services/wallets/check_wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ func (s *Service) CheckWallet(ctx context.Context, blockchain wconstants.Blockch
}

if s.config.UseCacheForWallets {
select {
case <-s.cacheReady:
case <-ctx.Done():
return nil, ctx.Err()
}
return s.checkWalletInCache(blockchain, address)
}

Expand Down
4 changes: 4 additions & 0 deletions internal/services/wallets/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package wallets

import (
"context"
"sync"
"sync/atomic"

"github.com/dv-net/dv-processing/internal/dispatcher"
Expand All @@ -25,6 +26,8 @@ type Service struct {

cacherInUse atomic.Bool
cacheLastLogTime atomic.Int64
cacheReady chan struct{}
cacheReadyOnce sync.Once

sdk *walletsdk.SDK
}
Expand All @@ -46,6 +49,7 @@ func New(
coldWallet: newColdWallets(st, vl, sdk),
hotWallets: newHotWallets(conf, st, vl, sdk, publisher),
processingWallets: newProcessingWallets(conf, st, vl, sdk),
cacheReady: make(chan struct{}),
}
}

Expand Down