From 2e15f2d91d211d3fc88cc239f155a31c978f5f81 Mon Sep 17 00:00:00 2001 From: Daniel Katzan Date: Wed, 7 Aug 2024 12:25:05 +0300 Subject: [PATCH] Allow configuration to track all accounts --- cmd/api/main.go | 1 + pkg/config/config.go | 1 + pkg/litestorage/litestorage.go | 24 +++++++++++++++++------- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/cmd/api/main.go b/cmd/api/main.go index 1ceff7ce..08c00150 100644 --- a/cmd/api/main.go +++ b/cmd/api/main.go @@ -46,6 +46,7 @@ func main() { log, client, litestorage.WithPreloadAccounts(cfg.App.Accounts), + litestorage.WithTrackAllAccounts(cfg.App.TrackAllAccounts), litestorage.WithTFPools(book.TFPools()), litestorage.WithKnownJettons(maps.Keys(book.GetKnownJettons())), litestorage.WithBlockChannel(storageBlockCh), diff --git a/pkg/config/config.go b/pkg/config/config.go index d10c735f..78103fbf 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -19,6 +19,7 @@ type Config struct { LogLevel string `env:"LOG_LEVEL" envDefault:"INFO"` MetricsPort int `env:"METRICS_PORT" envDefault:"9010"` Accounts accountsList `env:"ACCOUNTS"` + TrackAllAccounts bool `env:"TRACK_ALL_ACCOUNTS" envDefault:"false"` LiteServers []config.LiteServer `env:"LITE_SERVERS"` SendingLiteservers []config.LiteServer `env:"SENDING_LITE_SERVERS"` IsTestnet bool `env:"IS_TESTNET" envDefault:"false"` diff --git a/pkg/litestorage/litestorage.go b/pkg/litestorage/litestorage.go index 2b0f37e2..a4ea8338 100644 --- a/pkg/litestorage/litestorage.go +++ b/pkg/litestorage/litestorage.go @@ -67,7 +67,9 @@ type LiteStorage struct { // maxGoroutines specifies a number of goroutines used to perform some time-consuming operations. maxGoroutines int // trackingAccounts is a list of accounts we track. Defined with ACCOUNTS env variable. - trackingAccounts map[tongo.AccountID]struct{} + trackingAccounts map[tongo.AccountID]struct{} + // trackAllAccounts can be configure with TRACK_ALL_ACCOUNTS env variable, to track all accounts instead of specific ones. + trackAllAccounts bool pubKeyByAccountID *xsync.MapOf[tongo.AccountID, ed25519.PublicKey] configCache cache.Cache[int, ton.BlockchainConfig] @@ -81,11 +83,12 @@ type LiteStorage struct { } type Options struct { - preloadAccounts []tongo.AccountID - preloadBlocks []tongo.BlockID - tfPools []tongo.AccountID - jettons []tongo.AccountID - executor abi.Executor + preloadAccounts []tongo.AccountID + trackAllAccounts bool + preloadBlocks []tongo.BlockID + tfPools []tongo.AccountID + jettons []tongo.AccountID + executor abi.Executor // blockCh is used to receive new blocks in the blockchain, if set. blockCh <-chan indexer.IDandBlock } @@ -96,6 +99,12 @@ func WithPreloadAccounts(a []tongo.AccountID) Option { } } +func WithTrackAllAccounts(trackAllAccounts bool) Option { + return func(o *Options) { + o.trackAllAccounts = trackAllAccounts + } +} + func WithPreloadBlocks(ids []tongo.BlockID) Option { return func(o *Options) { o.preloadBlocks = ids @@ -141,6 +150,7 @@ func NewLiteStorage(log *zap.Logger, cli *liteapi.Client, opts ...Option) (*Lite // read-only data knownAccounts: make(map[string][]tongo.AccountID), trackingAccounts: map[tongo.AccountID]struct{}{}, + trackAllAccounts: o.trackAllAccounts, // data for concurrent access // TODO: implement expiration logic for the caches below. jettonMetaCache: xsync.NewMapOf[tep64.Metadata](), @@ -196,7 +206,7 @@ func (s *LiteStorage) run(ch <-chan indexer.IDandBlock) { for block := range ch { for _, tx := range block.Block.AllTransactions() { accountID := *ton.NewAccountID(block.ID.Workchain, tx.AccountAddr) - if _, ok := s.trackingAccounts[accountID]; ok { + if _, ok := s.trackingAccounts[accountID]; ok || s.trackAllAccounts { hash := tongo.Bits256(tx.Hash()) transaction, err := core.ConvertTransaction(accountID.Workchain, tongo.Transaction{Transaction: *tx, BlockID: block.ID}) if err != nil {