Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #272 from ethereum-optimism/jg/add_makefile
Browse files Browse the repository at this point in the history
Add opnode makefile, lints, and go1.18
  • Loading branch information
protolambda authored Mar 22, 2022
2 parents dd07121 + 8ac860e commit 96915eb
Show file tree
Hide file tree
Showing 18 changed files with 61 additions and 28 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/go-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.17
go-version: 1.18
- name: Checkout code
uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.43.0 # version of golangci-lint, not the action
version: v1.45.0 # version of golangci-lint, not the action
skip-go-installation: true
# rules: https://golangci-lint.run/usage/quick-start/
args: -E asciicheck,goimports
args: -E asciicheck,goimports,misspell
- name: Test and generate coverage
run: go test -coverpkg=./... -coverprofile=coverage.out -covermode=atomic ./...
- name: Upload coverage output
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/ethereum-optimism/optimistic-specs

go 1.17
go 1.18

require (
github.com/ethereum/go-ethereum v1.10.16
Expand Down
2 changes: 1 addition & 1 deletion l2os/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test:
go test -v ./...

lint:
golangci-lint run ./...
golangci-lint run -E asciicheck,goimports,misspell ./...

bindings: bindings-mock-l2-output-oracle

Expand Down
4 changes: 2 additions & 2 deletions l2os/l2_output_submitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ func dialEthClientWithTimeout(ctx context.Context, url string) (
return ethclient.DialContext(ctxt, url)
}

// parseAddress parses an ETH addres from a hex string. This method will fail if
// the address is not a valid hexidecimal address.
// parseAddress parses an ETH address from a hex string. This method will fail if
// the address is not a valid hexadecimal address.
func parseAddress(address string) (common.Address, error) {
if common.IsHexAddress(address) {
return common.HexToAddress(address), nil
Expand Down
4 changes: 2 additions & 2 deletions l2os/txmgr/send_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
// SendState tracks information about the publication state of a given txn. In
// this context, a txn may correspond to multiple different txn hashes due to
// varying gas prices, though we treat them all as the same logical txn. This
// struct is primarly used to determine whether or not the txmgr should abort a
// struct is primarily used to determine whether or not the txmgr should abort a
// given txn and retry with a higher nonce.
type SendState struct {
minedTxs map[common.Hash]struct{}
Expand Down Expand Up @@ -77,7 +77,7 @@ func (s *SendState) TxNotMined(txHash common.Hash) {
// If the txn got reorged and left us with no mined txns, reset the nonce
// too low count, otherwise we might abort too soon when processing the next
// error. If the nonce too low errors persist, we want to ensure we wait out
// the full safe abort count to enesure we have a sufficient number of
// the full safe abort count to ensure we have a sufficient number of
// observations.
if len(s.minedTxs) == 0 && wasMined {
s.nonceTooLowCount = 0
Expand Down
4 changes: 2 additions & 2 deletions l2os/txmgr/send_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ func TestSendStateMiningTxCancelsAbort(t *testing.T) {
}

// TestSendStateReorgingTxResetsAbort asserts that unmining a tx does not
// consider ErrNonceTooLow's prior to being mined when determing whether to
// abort.
// consider ErrNonceTooLow's prior to being mined when determining whether
// to abort.
func TestSendStateReorgingTxResetsAbort(t *testing.T) {
sendState := newSendState()

Expand Down
2 changes: 1 addition & 1 deletion l2os/txmgr/txmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func (m *SimpleTxManager) Send(
// Avoid republishing if we are waiting for confirmation on an
// existing tx. This is primarily an optimization to reduce the
// number of API calls we make, but also reduces the chances of
// getting a false postive reading for ShouldAbortImmediately.
// getting a false positive reading for ShouldAbortImmediately.
if sendState.IsWaitingForConfirmation() {
continue
}
Expand Down
2 changes: 1 addition & 1 deletion l2os/txmgr/txmgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func newTestHarnessWithConfig(cfg txmgr.Config) *testHarness {
}
}

// newTestHarness initializes a testHarness with a defualt configuration that is
// newTestHarness initializes a testHarness with a default configuration that is
// suitable for most tests.
func newTestHarness() *testHarness {
return newTestHarnessWithConfig(configWithNumConfs(1))
Expand Down
4 changes: 2 additions & 2 deletions meta/linting.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Justification for linting rules:

```shell
# Install linter globally (should not affect go.mod)
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.43.0
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.45.0
# run linter, add --fix option to fix problems (where supported)
golangci-lint run -E asciicheck,goimports
golangci-lint run -E asciicheck,goimports,misspell
```
1 change: 1 addition & 0 deletions opnode/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bin
26 changes: 26 additions & 0 deletions opnode/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
GITCOMMIT := $(shell git rev-parse HEAD)
GITDATE := $(shell git show -s --format='%ct')
VERSION := v0.0.0

LDFLAGSSTRING +=-X main.GitCommit=$(GITCOMMIT)
LDFLAGSSTRING +=-X main.GitDate=$(GITDATE)
LDFLAGSSTRING +=-X main.Version=$(VERSION)
LDFLAGS := -ldflags "$(LDFLAGSSTRING)"

opnode:
env GO111MODULE=on go build -v $(LDFLAGS) -o ./bin/opnode ./cmd/main.go

clean:
rm bin/opnode

test:
go test -v ./...

lint:
golangci-lint run -E asciicheck,goimports,misspell ./...

.PHONY: \
bss \
clean \
test \
lint
4 changes: 2 additions & 2 deletions opnode/backoff/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (e *ErrFailedPermanently) Error() string {
// Do performs the provided Operation up to maxAttempts times
// with delays in between each retry according to the provided
// Strategy.
func Do(maxAttempts int, strat Strategy, op Operation) error {
func Do(maxAttempts int, strategy Strategy, op Operation) error {
var attempt int

for {
Expand All @@ -39,6 +39,6 @@ func Do(maxAttempts int, strat Strategy, op Operation) error {
LastErr: err,
}
}
time.Sleep(strat.Duration(attempt - 1))
time.Sleep(strategy.Duration(attempt - 1))
}
}
6 changes: 3 additions & 3 deletions opnode/backoff/operation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (
)

func TestDo(t *testing.T) {
strat := Fixed(10 * time.Millisecond)
strategy := Fixed(10 * time.Millisecond)
dummyErr := errors.New("explode")

start := time.Now()
var i int
require.NoError(t, Do(2, strat, func() error {
require.NoError(t, Do(2, strategy, func() error {
if i == 1 {
return nil
}
Expand All @@ -26,7 +26,7 @@ func TestDo(t *testing.T) {

start = time.Now()
// add one because the first attempt counts
err := Do(3, strat, func() error {
err := Do(3, strategy, func() error {
return dummyErr
})
require.Equal(t, dummyErr, err.(*ErrFailedPermanently).LastErr)
Expand Down
4 changes: 2 additions & 2 deletions opnode/backoff/strategies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import (
)

func TestExponential(t *testing.T) {
strat := &ExponentialStrategy{
strategy := &ExponentialStrategy{
Min: 3000,
Max: 10000,
MaxJitter: 0,
}

durations := []int{4, 5, 7, 10, 10}
for i, dur := range durations {
require.Equal(t, time.Millisecond*time.Duration(dur*1000), strat.Duration(i))
require.Equal(t, time.Millisecond*time.Duration(dur*1000), strategy.Duration(i))
}
}
12 changes: 9 additions & 3 deletions opnode/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,21 @@ import (
)

var (
Version = "0.0.0"
// GitCommit = ""
// GitDate = ""
Version = "0.0.0"
GitCommit = ""
GitDate = ""
VersionMeta = "dev"
)

// VersionWithMeta holds the textual version string including the metadata.
var VersionWithMeta = func() string {
v := Version
if GitCommit != "" {
v += "-" + GitCommit[:8]
}
if GitDate != "" {
v += "-" + GitDate
}
if VersionMeta != "" {
v += "-" + VersionMeta
}
Expand Down
2 changes: 1 addition & 1 deletion opnode/rollup/derive/doc.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Package derive provides the data transformation functions that take L1 data
// and turn it into L2 blocks and results. Certian L2 data is also able to
// and turn it into L2 blocks and results. Certain L2 data is also able to
// turned back into L1 data.
//
// The flow is data is as follows
Expand Down
2 changes: 1 addition & 1 deletion opnode/rollup/driver/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ type stateTestCase struct {
}

func (tc *stateTestCase) Run(t *testing.T) {
log := testlog.Logger(t, log.LvlTrace)
log := testlog.Logger(t, log.LvlError)
chainSource := NewFakeChainSource(tc.l1Chains, tc.l2Chains, log)
l1headsCh := make(chan eth.L1BlockRef, 10)
// Unbuffered channels to force a sync point between the test and the state loop.
Expand Down
2 changes: 1 addition & 1 deletion opnode/rollup/sync/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ type syncStartTestCase struct {
GenesisL2 rune

ExpectedNextRefsL1 string // The L1 extension to follow (i.e. L1 after the L1 parent in the new L2 Head)
ExpectedRefL2 rune // The new L2 tip after a L1 change that may have occured
ExpectedRefL2 rune // The new L2 tip after a L1 change that may have occurred

ExpectedErr error
}
Expand Down

0 comments on commit 96915eb

Please sign in to comment.