Skip to content

Commit 61e353e

Browse files
authored
style(batch-submitter,bss-core,proxyd): Fix lint Go (ethereum-optimism#3328)
* style(batch-submitter): fix lint * style(bss-core): fix lint * chore(proxyd): use io and os instead of deprecated ioutil methods, fixes lint
1 parent c97312a commit 61e353e

File tree

11 files changed

+43
-45
lines changed

11 files changed

+43
-45
lines changed

batch-submitter/drivers/sequencer/encoding.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ func (c BatchContext) MarkerBatchType() BatchType {
6868

6969
// Write encodes the BatchContext into a 16-byte stream using the following
7070
// encoding:
71-
// - num_sequenced_txs: 3 bytes
72-
// - num_subsequent_queue_txs: 3 bytes
73-
// - timestamp: 5 bytes
74-
// - block_number: 5 bytes
71+
// - num_sequenced_txs: 3 bytes
72+
// - num_subsequent_queue_txs: 3 bytes
73+
// - timestamp: 5 bytes
74+
// - block_number: 5 bytes
7575
//
7676
// Note that writing to a bytes.Buffer cannot
7777
// error, so errors are ignored here
@@ -85,10 +85,10 @@ func (c *BatchContext) Write(w *bytes.Buffer) {
8585
// Read decodes the BatchContext from the passed reader. If fewer than 16-bytes
8686
// remain, an error is returned. Otherwise the first 16-bytes will be read using
8787
// the expected encoding:
88-
// - num_sequenced_txs: 3 bytes
89-
// - num_subsequent_queue_txs: 3 bytes
90-
// - timestamp: 5 bytes
91-
// - block_number: 5 bytes
88+
// - num_sequenced_txs: 3 bytes
89+
// - num_subsequent_queue_txs: 3 bytes
90+
// - timestamp: 5 bytes
91+
// - block_number: 5 bytes
9292
func (c *BatchContext) Read(r io.Reader) error {
9393
if err := readUint64(r, &c.NumSequencedTxs, 3); err != nil {
9494
return err
@@ -188,13 +188,13 @@ type AppendSequencerBatchParams struct {
188188
}
189189

190190
// Write encodes the AppendSequencerBatchParams using the following format:
191-
// - should_start_at_element: 5 bytes
192-
// - total_elements_to_append: 3 bytes
193-
// - num_contexts: 3 bytes
194-
// - num_contexts * batch_context: num_contexts * 16 bytes
195-
// - [num txs omitted]
196-
// - tx_len: 3 bytes
197-
// - tx_bytes: tx_len bytes
191+
// - should_start_at_element: 5 bytes
192+
// - total_elements_to_append: 3 bytes
193+
// - num_contexts: 3 bytes
194+
// - num_contexts * batch_context: num_contexts * 16 bytes
195+
// - [num txs omitted]
196+
// - tx_len: 3 bytes
197+
// - tx_bytes: tx_len bytes
198198
//
199199
// Typed batches include a dummy context as the first context
200200
// where the timestamp is 0. The blocknumber is interpreted
@@ -288,13 +288,13 @@ func (p *AppendSequencerBatchParams) Serialize(
288288
// stream does not terminate cleanly with an EOF while reading a tx_len, this
289289
// method will return an error. Otherwise, the stream will be parsed according
290290
// to the following format:
291-
// - should_start_at_element: 5 bytes
292-
// - total_elements_to_append: 3 bytes
293-
// - num_contexts: 3 bytes
294-
// - num_contexts * batch_context: num_contexts * 16 bytes
295-
// - [num txs omitted]
296-
// - tx_len: 3 bytes
297-
// - tx_bytes: tx_len bytes
291+
// - should_start_at_element: 5 bytes
292+
// - total_elements_to_append: 3 bytes
293+
// - num_contexts: 3 bytes
294+
// - num_contexts * batch_context: num_contexts * 16 bytes
295+
// - [num txs omitted]
296+
// - tx_len: 3 bytes
297+
// - tx_bytes: tx_len bytes
298298
func (p *AppendSequencerBatchParams) Read(r io.Reader) error {
299299
if err := readUint64(r, &p.ShouldStartAtElement, 5); err != nil {
300300
return err

batch-submitter/drivers/sequencer/encoding_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ import (
1515

1616
// TestBatchContextEncodeDecode tests the (de)serialization of a BatchContext
1717
// against the spec test vector. The encoding should be:
18-
// - num_sequenced_txs: 3 bytes
19-
// - num_subsequent_queue_txs: 3 bytes
20-
// - timestamp: 5 bytes
21-
// - block_number: 5 bytes
18+
// - num_sequenced_txs: 3 bytes
19+
// - num_subsequent_queue_txs: 3 bytes
20+
// - timestamp: 5 bytes
21+
// - block_number: 5 bytes
2222
func TestBatchContextEncodeDecode(t *testing.T) {
2323
t.Parallel()
2424

bss-core/crypto.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ func ParseAddress(address string) (common.Address, error) {
3232

3333
// GetConfiguredPrivateKey computes the private key for our configured services.
3434
// The two supported methods are:
35-
// - Derived from BIP39 mnemonic and BIP32 HD derivation path.
36-
// - Directly from a serialized private key.
35+
// - Derived from BIP39 mnemonic and BIP32 HD derivation path.
36+
// - Directly from a serialized private key.
3737
func GetConfiguredPrivateKey(mnemonic, hdPath, privKeyStr string) (
3838
*ecdsa.PrivateKey, error) {
3939

bss-core/crypto_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,9 @@ func TestParsePrivateKeyStr(t *testing.T) {
209209
}
210210

211211
// TestGetConfiguredPrivateKey asserts that GetConfiguredPrivateKey either:
212-
// 1) Derives the correct private key assuming the BIP39 mnemonic and BIP32
212+
// 1. Derives the correct private key assuming the BIP39 mnemonic and BIP32
213213
// derivation path are both present and the private key string is omitted.
214-
// 2) Parses the correct private key assuming only the private key string is
214+
// 2. Parses the correct private key assuming only the private key string is
215215
// present, but the BIP39 mnemonic and BIP32 derivation path are omitted.
216216
func TestGetConfiguredPrivateKey(t *testing.T) {
217217
tests := []struct {

bss-core/txmgr/txmgr.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,8 @@ func waitMined(
330330

331331
// CalcGasFeeCap deterministically computes the recommended gas fee cap given
332332
// the base fee and gasTipCap. The resulting gasFeeCap is equal to:
333-
// gasTipCap + 2*baseFee.
333+
//
334+
// gasTipCap + 2*baseFee.
334335
func CalcGasFeeCap(baseFee, gasTipCap *big.Int) *big.Int {
335336
return new(big.Int).Add(
336337
gasTipCap,

proxyd/backend.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"errors"
99
"fmt"
1010
"io"
11-
"io/ioutil"
1211
"math"
1312
"math/rand"
1413
"net/http"
@@ -408,7 +407,7 @@ func (b *Backend) doForward(ctx context.Context, rpcReqs []*RPCReq, isBatch bool
408407
}
409408

410409
defer httpRes.Body.Close()
411-
resB, err := ioutil.ReadAll(io.LimitReader(httpRes.Body, b.maxResponseSize))
410+
resB, err := io.ReadAll(io.LimitReader(httpRes.Body, b.maxResponseSize))
412411
if err != nil {
413412
return nil, wrapErr(err, "error reading response body")
414413
}

proxyd/integration_tests/mock_backend_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"bytes"
55
"context"
66
"encoding/json"
7-
"io/ioutil"
7+
"io"
88
"net/http"
99
"net/http/httptest"
1010
"strings"
@@ -122,7 +122,7 @@ func (h *BatchRPCResponseRouter) ServeHTTP(w http.ResponseWriter, r *http.Reques
122122
h.mtx.Lock()
123123
defer h.mtx.Unlock()
124124

125-
body, err := ioutil.ReadAll(r.Body)
125+
body, err := io.ReadAll(r.Body)
126126
if err != nil {
127127
panic(err)
128128
}
@@ -241,12 +241,12 @@ func (m *MockBackend) Requests() []*RecordedRequest {
241241

242242
func (m *MockBackend) wrappedHandler(w http.ResponseWriter, r *http.Request) {
243243
m.mtx.Lock()
244-
body, err := ioutil.ReadAll(r.Body)
244+
body, err := io.ReadAll(r.Body)
245245
if err != nil {
246246
panic(err)
247247
}
248248
clone := r.Clone(context.Background())
249-
clone.Body = ioutil.NopCloser(bytes.NewReader(body))
249+
clone.Body = io.NopCloser(bytes.NewReader(body))
250250
m.requests = append(m.requests, &RecordedRequest{
251251
Method: r.Method,
252252
Headers: r.Header.Clone(),

proxyd/integration_tests/util_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"bytes"
55
"encoding/json"
66
"fmt"
7-
"io/ioutil"
7+
"io"
88
"net/http"
99
"os"
1010
"testing"
@@ -67,7 +67,7 @@ func (p *ProxydHTTPClient) SendRequest(body []byte) ([]byte, int, error) {
6767
}
6868
defer res.Body.Close()
6969
code := res.StatusCode
70-
resBody, err := ioutil.ReadAll(res.Body)
70+
resBody, err := io.ReadAll(res.Body)
7171
if err != nil {
7272
panic(err)
7373
}

proxyd/rpc.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package proxyd
33
import (
44
"encoding/json"
55
"io"
6-
"io/ioutil"
76
"strings"
87
)
98

@@ -103,7 +102,7 @@ func ParseBatchRPCReq(body []byte) ([]json.RawMessage, error) {
103102
}
104103

105104
func ParseRPCRes(r io.Reader) (*RPCRes, error) {
106-
body, err := ioutil.ReadAll(r)
105+
body, err := io.ReadAll(r)
107106
if err != nil {
108107
return nil, wrapErr(err, "error reading RPC response")
109108
}

proxyd/server.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"errors"
77
"fmt"
88
"io"
9-
"io/ioutil"
109
"math"
1110
"net/http"
1211
"strconv"
@@ -236,7 +235,7 @@ func (s *Server) HandleRPC(w http.ResponseWriter, r *http.Request) {
236235
"user_agent", userAgent,
237236
)
238237

239-
body, err := ioutil.ReadAll(io.LimitReader(r.Body, s.maxBodySize))
238+
body, err := io.ReadAll(io.LimitReader(r.Body, s.maxBodySize))
240239
if err != nil {
241240
log.Error("error reading request body", "err", err)
242241
writeRPCError(ctx, w, nil, ErrInternal)

0 commit comments

Comments
 (0)