From aa3023e859594cdb3b9e867544cf1abda86af405 Mon Sep 17 00:00:00 2001 From: Nodar Date: Fri, 15 Sep 2023 16:18:51 +0200 Subject: [PATCH] Allow using different redis keys for dataposter --- arbnode/batch_poster.go | 13 ++++++++++- arbnode/dataposter/data_poster.go | 39 ++++++++++++++++++++----------- arbnode/node.go | 12 +++++++++- 3 files changed, 48 insertions(+), 16 deletions(-) diff --git a/arbnode/batch_poster.go b/arbnode/batch_poster.go index 89a36eba91..a96f569be2 100644 --- a/arbnode/batch_poster.go +++ b/arbnode/batch_poster.go @@ -253,7 +253,18 @@ func NewBatchPoster(dataPosterDB ethdb.Database, l1Reader *headerreader.HeaderRe dataPosterConfigFetcher := func() *dataposter.DataPosterConfig { return &config().DataPoster } - b.dataPoster, err = dataposter.NewDataPoster(dataPosterDB, l1Reader, transactOpts, redisClient, redisLock, dataPosterConfigFetcher, b.getBatchPosterPosition) + b.dataPoster, err = dataposter.NewDataPoster( + &dataposter.DataPosterOpts{ + Database: dataPosterDB, + HeaderReader: l1Reader, + Auth: transactOpts, + RedisClient: redisClient, + RedisLock: redisLock, + Config: dataPosterConfigFetcher, + MetadataRetriever: b.getBatchPosterPosition, + RedisKey: "data-poster.queue", + }, + ) if err != nil { return nil, err } diff --git a/arbnode/dataposter/data_poster.go b/arbnode/dataposter/data_poster.go index b1e6555b26..d9e10b2434 100644 --- a/arbnode/dataposter/data_poster.go +++ b/arbnode/dataposter/data_poster.go @@ -91,18 +91,29 @@ func parseReplacementTimes(val string) ([]time.Duration, error) { return append(res, time.Hour*24*365*10), nil } -func NewDataPoster(db ethdb.Database, headerReader *headerreader.HeaderReader, auth *bind.TransactOpts, redisClient redis.UniversalClient, redisLock AttemptLocker, config ConfigFetcher, metadataRetriever func(ctx context.Context, blockNum *big.Int) ([]byte, error)) (*DataPoster, error) { - initConfig := config() +type DataPosterOpts struct { + Database ethdb.Database + HeaderReader *headerreader.HeaderReader + Auth *bind.TransactOpts + RedisClient redis.UniversalClient + RedisLock AttemptLocker + Config ConfigFetcher + MetadataRetriever func(ctx context.Context, blockNum *big.Int) ([]byte, error) + RedisKey string // Redis storage key +} + +func NewDataPoster(opts *DataPosterOpts) (*DataPoster, error) { + initConfig := opts.Config() replacementTimes, err := parseReplacementTimes(initConfig.ReplacementTimes) if err != nil { return nil, err } - if headerReader.IsParentChainArbitrum() && !initConfig.UseNoOpStorage { + if opts.HeaderReader.IsParentChainArbitrum() && !initConfig.UseNoOpStorage { initConfig.UseNoOpStorage = true log.Info("Disabling data poster storage, as parent chain appears to be an Arbitrum chain without a mempool") } encF := func() storage.EncoderDecoderInterface { - if config().LegacyStorageEncoding { + if opts.Config().LegacyStorageEncoding { return &storage.LegacyEncoderDecoder{} } return &storage.EncoderDecoder{} @@ -111,27 +122,27 @@ func NewDataPoster(db ethdb.Database, headerReader *headerreader.HeaderReader, a switch { case initConfig.UseNoOpStorage: queue = &noop.Storage{} - case redisClient != nil: + case opts.RedisClient != nil: var err error - queue, err = redisstorage.NewStorage(redisClient, "data-poster.queue", &initConfig.RedisSigner, encF) + queue, err = redisstorage.NewStorage(opts.RedisClient, opts.RedisKey, &initConfig.RedisSigner, encF) if err != nil { return nil, err } case initConfig.UseLevelDB: - queue = leveldb.New(db, func() storage.EncoderDecoderInterface { return &storage.EncoderDecoder{} }) + queue = leveldb.New(opts.Database, func() storage.EncoderDecoderInterface { return &storage.EncoderDecoder{} }) default: queue = slice.NewStorage(func() storage.EncoderDecoderInterface { return &storage.EncoderDecoder{} }) } return &DataPoster{ - headerReader: headerReader, - client: headerReader.Client(), - sender: auth.From, - signer: auth.Signer, - config: config, + headerReader: opts.HeaderReader, + client: opts.HeaderReader.Client(), + sender: opts.Auth.From, + signer: opts.Auth.Signer, + config: opts.Config, replacementTimes: replacementTimes, - metadataRetriever: metadataRetriever, + metadataRetriever: opts.MetadataRetriever, queue: queue, - redisLock: redisLock, + redisLock: opts.RedisLock, errorCount: make(map[uint64]int), }, nil } diff --git a/arbnode/node.go b/arbnode/node.go index 5bdc716264..3fc1f556f3 100644 --- a/arbnode/node.go +++ b/arbnode/node.go @@ -564,7 +564,17 @@ func StakerDataposter( dpCfg := func() *dataposter.DataPosterConfig { return &cfg.Staker.DataPoster } - return dataposter.NewDataPoster(db, l1Reader, transactOpts, redisC, redisLock, dpCfg, mdRetriever) + return dataposter.NewDataPoster( + &dataposter.DataPosterOpts{ + Database: db, + HeaderReader: l1Reader, + Auth: transactOpts, + RedisClient: redisC, + RedisLock: redisLock, + Config: dpCfg, + MetadataRetriever: mdRetriever, + RedisKey: "staker-data-poster.queue", + }) } func createNodeImpl(