@@ -18,6 +18,7 @@ import (
1818 "time"
1919
2020 "github.com/coocood/freecache"
21+ "github.com/davecgh/go-spew/spew"
2122 "github.com/ethereum/go-ethereum/common"
2223 "github.com/go-redis/redis/v8"
2324 "github.com/gobitfly/beaconchain/cmd/misc/commands"
@@ -32,6 +33,7 @@ import (
3233 edb "github.com/gobitfly/beaconchain/pkg/exporter/db"
3334 "github.com/gobitfly/beaconchain/pkg/exporter/modules"
3435 "github.com/gobitfly/beaconchain/pkg/exporter/services"
36+ "github.com/gobitfly/beaconchain/pkg/notification"
3537 _ "github.com/jackc/pgx/v5/stdlib"
3638 "github.com/pkg/errors"
3739 utilMath "github.com/protolambda/zrnt/eth2/util/math"
@@ -75,7 +77,7 @@ func Run() {
7577 }
7678
7779 configPath := fs .String ("config" , "config/default.config.yml" , "Path to the config file" )
78- fs .StringVar (& opts .Command , "command" , "" , "command to run, available: updateAPIKey, applyDbSchema, initBigtableSchema, epoch-export, debug-rewards, debug-blocks, clear-bigtable, index-old-eth1-blocks, update-aggregation-bits, historic-prices-export, index-missing-blocks, export-epoch-missed-slots, migrate-last-attestation-slot-bigtable, export-genesis-validators, update-block-finalization-sequentially, nameValidatorsByRanges, export-stats-totals, export-sync-committee-periods, export-sync-committee-validator-stats, partition-validator-stats, migrate-app-purchases" )
80+ fs .StringVar (& opts .Command , "command" , "" , "command to run, available: updateAPIKey, applyDbSchema, initBigtableSchema, epoch-export, debug-rewards, debug-blocks, clear-bigtable, index-old-eth1-blocks, update-aggregation-bits, historic-prices-export, index-missing-blocks, export-epoch-missed-slots, migrate-last-attestation-slot-bigtable, export-genesis-validators, update-block-finalization-sequentially, nameValidatorsByRanges, export-stats-totals, export-sync-committee-periods, export-sync-committee-validator-stats, partition-validator-stats, migrate-app-purchases, collect-notifications, collect-user-db-notifications " )
7981 fs .Uint64Var (& opts .StartEpoch , "start-epoch" , 0 , "start epoch" )
8082 fs .Uint64Var (& opts .EndEpoch , "end-epoch" , 0 , "end epoch" )
8183 fs .Uint64Var (& opts .User , "user" , 0 , "user id" )
@@ -181,27 +183,27 @@ func Run() {
181183 defer db .FrontendWriterDB .Close ()
182184
183185 // clickhouse
184- db .ClickHouseWriter , db .ClickHouseReader = db .MustInitDB (& types.DatabaseConfig {
185- Username : cfg .ClickHouse .WriterDatabase .Username ,
186- Password : cfg .ClickHouse .WriterDatabase .Password ,
187- Name : cfg .ClickHouse .WriterDatabase .Name ,
188- Host : cfg .ClickHouse .WriterDatabase .Host ,
189- Port : cfg .ClickHouse .WriterDatabase .Port ,
190- MaxOpenConns : cfg .ClickHouse .WriterDatabase .MaxOpenConns ,
191- SSL : true ,
192- MaxIdleConns : cfg .ClickHouse .WriterDatabase .MaxIdleConns ,
193- }, & types.DatabaseConfig {
194- Username : cfg .ClickHouse .ReaderDatabase .Username ,
195- Password : cfg .ClickHouse .ReaderDatabase .Password ,
196- Name : cfg .ClickHouse .ReaderDatabase .Name ,
197- Host : cfg .ClickHouse .ReaderDatabase .Host ,
198- Port : cfg .ClickHouse .ReaderDatabase .Port ,
199- MaxOpenConns : cfg .ClickHouse .ReaderDatabase .MaxOpenConns ,
200- SSL : true ,
201- MaxIdleConns : cfg .ClickHouse .ReaderDatabase .MaxIdleConns ,
202- }, "clickhouse" , "clickhouse" )
203- defer db .ClickHouseReader .Close ()
204- defer db .ClickHouseWriter .Close ()
186+ // db.ClickHouseWriter, db.ClickHouseReader = db.MustInitDB(&types.DatabaseConfig{
187+ // Username: cfg.ClickHouse.WriterDatabase.Username,
188+ // Password: cfg.ClickHouse.WriterDatabase.Password,
189+ // Name: cfg.ClickHouse.WriterDatabase.Name,
190+ // Host: cfg.ClickHouse.WriterDatabase.Host,
191+ // Port: cfg.ClickHouse.WriterDatabase.Port,
192+ // MaxOpenConns: cfg.ClickHouse.WriterDatabase.MaxOpenConns,
193+ // SSL: true,
194+ // MaxIdleConns: cfg.ClickHouse.WriterDatabase.MaxIdleConns,
195+ // }, &types.DatabaseConfig{
196+ // Username: cfg.ClickHouse.ReaderDatabase.Username,
197+ // Password: cfg.ClickHouse.ReaderDatabase.Password,
198+ // Name: cfg.ClickHouse.ReaderDatabase.Name,
199+ // Host: cfg.ClickHouse.ReaderDatabase.Host,
200+ // Port: cfg.ClickHouse.ReaderDatabase.Port,
201+ // MaxOpenConns: cfg.ClickHouse.ReaderDatabase.MaxOpenConns,
202+ // SSL: true,
203+ // MaxIdleConns: cfg.ClickHouse.ReaderDatabase.MaxIdleConns,
204+ // }, "clickhouse", "clickhouse")
205+ // defer db.ClickHouseReader.Close()
206+ // defer db.ClickHouseWriter.Close()
205207
206208 // Initialize the persistent redis client
207209 rdc := redis .NewClient (& redis.Options {
@@ -216,6 +218,14 @@ func Run() {
216218 db .PersistentRedisDbClient = rdc
217219 defer db .PersistentRedisDbClient .Close ()
218220
221+ if utils .Config .TieredCacheProvider != "redis" {
222+ log .Fatal (nil , "no cache provider set, please set TierdCacheProvider (redis)" , 0 )
223+ }
224+ if utils .Config .TieredCacheProvider == "redis" || len (utils .Config .RedisCacheEndpoint ) != 0 {
225+ cache .MustInitTieredCache (utils .Config .RedisCacheEndpoint )
226+ log .Infof ("tiered Cache initialized, latest finalized epoch: %v" , cache .LatestFinalizedEpoch .Get ())
227+ }
228+
219229 switch opts .Command {
220230 case "nameValidatorsByRanges" :
221231 err := nameValidatorsByRanges (opts .ValidatorNameRanges )
@@ -456,6 +466,10 @@ func Run() {
456466 err = fixEns (erigonClient )
457467 case "fix-ens-addresses" :
458468 err = fixEnsAddresses (erigonClient )
469+ case "collect-notifications" :
470+ err = collectNotifications (opts .StartEpoch )
471+ case "collect-user-db-notifications" :
472+ err = collectUserDbNotifications (opts .StartEpoch )
459473 default :
460474 log .Fatal (nil , fmt .Sprintf ("unknown command %s" , opts .Command ), 0 )
461475 }
@@ -467,6 +481,35 @@ func Run() {
467481 }
468482}
469483
484+ func collectNotifications (startEpoch uint64 ) error {
485+ epoch := startEpoch
486+
487+ log .Infof ("collecting notifications for epoch %v" , epoch )
488+ notifications , err := notification .GetNotificationsForEpoch (utils .Config .Notifications .PubkeyCachePath , epoch )
489+ if err != nil {
490+ return err
491+ }
492+
493+ log .Infof ("found %v notifications for epoch %v with %v notifications for user 0" , len (notifications ), epoch , len (notifications [0 ]))
494+ if len (notifications [0 ]) > 0 {
495+ spew .Dump (notifications [0 ])
496+ }
497+ return nil
498+ }
499+
500+ func collectUserDbNotifications (startEpoch uint64 ) error {
501+ epoch := startEpoch
502+
503+ log .Infof ("collecting notifications for epoch %v" , epoch )
504+ notifications , err := notification .GetUserNotificationsForEpoch (utils .Config .Notifications .PubkeyCachePath , epoch )
505+ if err != nil {
506+ return err
507+ }
508+
509+ log .Infof ("found %v notifications for epoch %v" , len (notifications ), epoch )
510+ return nil
511+ }
512+
470513func fixEns (erigonClient * rpc.ErigonClient ) error {
471514 log .Infof ("command: fix-ens" )
472515 addrs := []struct {
0 commit comments