Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into pathdb_fullnode
Browse files Browse the repository at this point in the history
  • Loading branch information
tsahee committed Jul 23, 2024
2 parents 6f04d12 + 76616eb commit 97b5bda
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
27 changes: 19 additions & 8 deletions das/local_file_storage_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,21 @@ func (s *LocalFileStorageService) Close(ctx context.Context) error {

func (s *LocalFileStorageService) GetByHash(ctx context.Context, key common.Hash) ([]byte, error) {
log.Trace("das.LocalFileStorageService.GetByHash", "key", pretty.PrettyHash(key), "this", s)
var batchPath string
if s.enableLegacyLayout {
batchPath = s.legacyLayout.batchPath(key)
} else {
batchPath = s.layout.batchPath(key)
}

legacyBatchPath := s.legacyLayout.batchPath(key)
batchPath := s.layout.batchPath(key)

data, err := os.ReadFile(batchPath)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
return nil, ErrNotFound
data, err = os.ReadFile(legacyBatchPath)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
return nil, ErrNotFound
}
return nil, err
}
return data, nil
}
return nil, err
}
Expand Down Expand Up @@ -225,7 +229,14 @@ func (s *LocalFileStorageService) String() string {

func (s *LocalFileStorageService) HealthCheck(ctx context.Context) error {
testData := []byte("Test-Data")
err := s.Put(ctx, testData, uint64(time.Now().Add(time.Minute).Unix()))
// Store some data with an expiry time at the start of the epoch.
// If expiry is disabled it will only create an index entry for the
// same timestamp each time the health check happens.
// If expiry is enabled, it will be cleaned up each time the pruning
// runs. There is a slight chance of a race between pruning and the
// Put and Get calls, but systems using the HealthCheck will just retry
// and succeed the next time.
err := s.Put(ctx, testData /* start of epoch */, 0)
if err != nil {
return err
}
Expand Down
8 changes: 7 additions & 1 deletion util/headerreader/header_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type Config struct {
Enable bool `koanf:"enable"`
PollOnly bool `koanf:"poll-only" reload:"hot"`
PollInterval time.Duration `koanf:"poll-interval" reload:"hot"`
PollTimeout time.Duration `koanf:"poll-timeout" reload:"hot"`
SubscribeErrInterval time.Duration `koanf:"subscribe-err-interval" reload:"hot"`
TxTimeout time.Duration `koanf:"tx-timeout" reload:"hot"`
OldHeaderTimeout time.Duration `koanf:"old-header-timeout" reload:"hot"`
Expand All @@ -80,6 +81,7 @@ var DefaultConfig = Config{
Enable: true,
PollOnly: false,
PollInterval: 15 * time.Second,
PollTimeout: 5 * time.Second,
SubscribeErrInterval: 5 * time.Minute,
TxTimeout: 5 * time.Minute,
OldHeaderTimeout: 5 * time.Minute,
Expand All @@ -94,6 +96,7 @@ func AddOptions(prefix string, f *flag.FlagSet) {
f.Bool(prefix+".poll-only", DefaultConfig.PollOnly, "do not attempt to subscribe to header events")
f.Bool(prefix+".use-finality-data", DefaultConfig.UseFinalityData, "use l1 data about finalized/safe blocks")
f.Duration(prefix+".poll-interval", DefaultConfig.PollInterval, "interval when polling endpoint")
f.Duration(prefix+".poll-timeout", DefaultConfig.PollTimeout, "timeout when polling endpoint")
f.Duration(prefix+".subscribe-err-interval", DefaultConfig.SubscribeErrInterval, "interval for subscribe error")
f.Duration(prefix+".tx-timeout", DefaultConfig.TxTimeout, "timeout when waiting for a transaction")
f.Duration(prefix+".old-header-timeout", DefaultConfig.OldHeaderTimeout, "warns if the latest l1 block is at least this old")
Expand All @@ -108,6 +111,7 @@ var TestConfig = Config{
Enable: true,
PollOnly: false,
PollInterval: time.Millisecond * 10,
PollTimeout: time.Second * 5,
TxTimeout: time.Second * 5,
OldHeaderTimeout: 5 * time.Minute,
UseFinalityData: false,
Expand Down Expand Up @@ -287,7 +291,9 @@ func (s *HeaderReader) broadcastLoop(ctx context.Context) {
s.possiblyBroadcast(h)
timer.Stop()
case <-timer.C:
h, err := s.client.HeaderByNumber(ctx, nil)
timedCtx, cancelFunc := context.WithTimeout(ctx, s.config().PollTimeout)
h, err := s.client.HeaderByNumber(timedCtx, nil)
cancelFunc()
if err != nil {
s.setError(fmt.Errorf("failed reading HeaderByNumber: %w", err))
if !errors.Is(err, context.Canceled) {
Expand Down

0 comments on commit 97b5bda

Please sign in to comment.