Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow configuration to track all accounts #430

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
24 changes: 17 additions & 7 deletions pkg/litestorage/litestorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -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
}
Expand All @@ -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
Expand Down Expand Up @@ -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](),
Expand Down Expand Up @@ -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 {
Expand Down