Skip to content

Commit d8a693d

Browse files
committed
Fix resource leaks, dead code, and variable shadowing in frax DA integration
1 parent 1ff03ef commit d8a693d

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

frax-da/client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ func (c DAClient) Read(ctx context.Context, id []byte) ([]byte, error) {
4646
return nil, fmt.Errorf("unable to create request to fetch data from DA: %w", err)
4747
}
4848
resp, err := c.httpClient.Do(request)
49-
5049
if err != nil {
5150
return nil, fmt.Errorf("unable to fetch DA data: %w", err)
5251
}
52+
defer resp.Body.Close()
5353
if resp.StatusCode != 200 {
5454
return nil, fmt.Errorf("unable to fetch DA data, got status code %d", resp.StatusCode)
5555
}
@@ -69,10 +69,10 @@ func (c DAClient) ReadCelestia(ctx context.Context, hexString string) ([]byte, e
6969
return nil, fmt.Errorf("unable to create request to fetch celestia data from DA: %w", err)
7070
}
7171
resp, err := c.httpClient.Do(request)
72-
7372
if err != nil {
7473
return nil, fmt.Errorf("unable to fetch DA celestia data: %w", err)
7574
}
75+
defer resp.Body.Close()
7676
if resp.StatusCode != 200 {
7777
return nil, fmt.Errorf("unable to fetch DA celestia data, got status code %d", resp.StatusCode)
7878
}
@@ -94,10 +94,10 @@ func (c DAClient) Write(ctx context.Context, data []byte) ([]byte, error) {
9494
}
9595

9696
resp, err := c.httpClient.Do(request)
97-
9897
if err != nil {
9998
return nil, fmt.Errorf("unable to submit data to DA: %w", err)
10099
}
100+
defer resp.Body.Close()
101101
if resp.StatusCode > 299 {
102102
return nil, fmt.Errorf("unable to submit data to DA, got status code %d", resp.StatusCode)
103103
}

op-batcher/batcher/service.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"github.com/ethereum-optimism/optimism/op-node/chaincfg"
2121
"github.com/ethereum-optimism/optimism/op-node/params"
2222
"github.com/ethereum-optimism/optimism/op-node/rollup"
23-
"github.com/ethereum-optimism/optimism/op-service/bgpo"
2423
"github.com/ethereum-optimism/optimism/op-service/cliapp"
2524
"github.com/ethereum-optimism/optimism/op-service/dial"
2625
"github.com/ethereum-optimism/optimism/op-service/eth"
@@ -83,10 +82,7 @@ type BatcherService struct {
8382

8483
NotSubmittingOnStart bool
8584

86-
// BlobGasPriceOracle tracks blob base gas prices for dynamic pricing
87-
blobTipOracle *bgpo.BlobTipOracle
88-
oracleStopCh chan struct{}
89-
DAClient *fraxda.DAClient
85+
DAClient *fraxda.DAClient
9086
}
9187

9288
type DriverSetupOption func(setup *DriverSetup)

op-node/rollup/derive/calldata_source.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,23 +115,25 @@ func DataFromEVMTransactions(dsCfg DataSourceConfig, batcherAddr common.Address,
115115
default:
116116
switch data[0] {
117117
case fraxda.DerivationVersionFraxDa:
118-
log.Info("fraxda: requesting data", "id", hex.EncodeToString(data))
118+
id := hex.EncodeToString(data)
119+
log.Info("fraxda: requesting data", "id", id)
119120
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
120-
data, err := daClient.Read(ctx, data[1:])
121+
daData, err := daClient.Read(ctx, data[1:])
121122
cancel()
122123
if err != nil {
123-
return nil, NewResetError(fmt.Errorf("fraxda: failed to fetch data for id %s: %w", hex.EncodeToString(data), err))
124+
return nil, NewResetError(fmt.Errorf("fraxda: failed to fetch data for id %s: %w", id, err))
124125
}
125-
out = append(out, data)
126+
out = append(out, daData)
126127
case fraxda.DerivationVersionCelestia:
127-
log.Info("fraxda: requesting old celestia data", "id", hex.EncodeToString(data))
128+
id := hex.EncodeToString(data)
129+
log.Info("fraxda: requesting old celestia data", "id", id)
128130
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
129-
data, err := daClient.ReadCelestia(ctx, hex.EncodeToString(data[1:]))
131+
daData, err := daClient.ReadCelestia(ctx, hex.EncodeToString(data[1:]))
130132
cancel()
131133
if err != nil {
132-
return nil, NewResetError(fmt.Errorf("fraxda: failed to fetch celestia data for id %s: %w", hex.EncodeToString(data), err))
134+
return nil, NewResetError(fmt.Errorf("fraxda: failed to fetch celestia data for id %s: %w", id, err))
133135
}
134-
out = append(out, data)
136+
out = append(out, daData)
135137
default:
136138
out = append(out, data)
137139
log.Info("fraxda: using eth fallback")

0 commit comments

Comments
 (0)