Skip to content

Commit

Permalink
Allow using different redis keys for dataposter
Browse files Browse the repository at this point in the history
  • Loading branch information
anodar committed Sep 15, 2023
1 parent c3bd8ec commit aa3023e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 16 deletions.
13 changes: 12 additions & 1 deletion arbnode/batch_poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
39 changes: 25 additions & 14 deletions arbnode/dataposter/data_poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -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
}
Expand Down
12 changes: 11 additions & 1 deletion arbnode/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit aa3023e

Please sign in to comment.