Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Commit 23d6ba4

Browse files
authored
Linting for builder (#63)
1 parent a146bfa commit 23d6ba4

File tree

12 files changed

+53
-79
lines changed

12 files changed

+53
-79
lines changed

.github/workflows/go.yml

+29-4
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,40 @@ env:
1111

1212
jobs:
1313

14+
lint:
15+
name: Lint
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Set up Go
19+
uses: actions/setup-go@v3
20+
with:
21+
go-version: ^1.20
22+
id: go
23+
24+
- name: Check out code into the Go module directory
25+
uses: actions/checkout@v2
26+
27+
- name: Install golangci-lint
28+
run: go install github.com/golangci/golangci-lint/cmd/[email protected]
29+
30+
- name: Lint
31+
run: make lint
32+
33+
- name: Ensure go mod tidy runs without changes
34+
run: |
35+
go mod tidy
36+
git diff-index HEAD
37+
git diff-index --quiet HEAD
38+
1439
build:
1540
name: Build
1641
runs-on: ubuntu-latest
1742
steps:
1843

1944
- name: Set up Go 1.x
20-
uses: actions/setup-go@v2
45+
uses: actions/setup-go@v3
2146
with:
22-
go-version: ^1.13
47+
go-version: ^1.20
2348
id: go
2449

2550
- name: Check out code into the Go module directory
@@ -38,9 +63,9 @@ jobs:
3863
steps:
3964

4065
- name: Set up Go 1.x
41-
uses: actions/setup-go@v2
66+
uses: actions/setup-go@v3
4267
with:
43-
go-version: ^1.13
68+
go-version: ^1.20
4469
id: go
4570

4671
- name: Use Node.js 12.x

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ There are two parts of the builder.
145145

146146
Main logic of the builder is in the `builder.go` file.
147147

148-
Builder is driven by the modified consensus client that calls `OnPayloadAttribute` indicating that block should be produced.
148+
Builder is driven by the consensus client SSE events that sends payload attribute events, triggering the `OnPayloadAttribute` call.
149149
After requesting additional validator data from the relay builder starts building job with `runBuildingJob`.
150150
Building job continuously makes a request to the `miner` with the correct parameters and submits produced block.
151151

builder/beacon_client.go

+2-21
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"github.com/ethereum/go-ethereum/core/types"
1818
"github.com/ethereum/go-ethereum/log"
1919
"github.com/r3labs/sse"
20-
"golang.org/x/exp/slices"
2120
)
2221

2322
type IBeaconClient interface {
@@ -33,9 +32,7 @@ type testBeaconClient struct {
3332
slot uint64
3433
}
3534

36-
func (b *testBeaconClient) Stop() {
37-
return
38-
}
35+
func (b *testBeaconClient) Stop() {}
3936

4037
func (b *testBeaconClient) isValidator(pubkey PubkeyHex) bool {
4138
return true
@@ -107,22 +104,6 @@ func (m *MultiBeaconClient) getProposerForNextSlot(requestedSlot uint64) (Pubkey
107104
return PubkeyHex(""), allErrs
108105
}
109106

110-
func payloadAttributesMatch(l types.BuilderPayloadAttributes, r types.BuilderPayloadAttributes) bool {
111-
if l.Timestamp != r.Timestamp ||
112-
l.Slot != r.Slot ||
113-
l.GasLimit != r.GasLimit ||
114-
l.Random != r.Random ||
115-
l.HeadHash != r.HeadHash {
116-
return false
117-
}
118-
119-
if !slices.Equal(l.Withdrawals, r.Withdrawals) {
120-
return false
121-
}
122-
123-
return true
124-
}
125-
126107
func (m *MultiBeaconClient) SubscribeToPayloadAttributesEvents(payloadAttrC chan types.BuilderPayloadAttributes) {
127108
for _, c := range m.clients {
128109
go c.SubscribeToPayloadAttributesEvents(payloadAttrC)
@@ -224,7 +205,7 @@ func (b *BeaconClient) UpdateValidatorMapForever() {
224205
// more frequently to avoid missing updates on errors
225206
timer := time.NewTimer(retryDelay)
226207
defer timer.Stop()
227-
for true {
208+
for {
228209
select {
229210
case <-b.ctx.Done():
230211
return

builder/eth_service.go

-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ func (s *EthereumService) BuildBlock(attrs *types.BuilderPayloadAttributes, seal
8888
log.Error("timeout waiting for block", "parent hash", attrs.HeadHash, "slot", attrs.Slot)
8989
return errors.New("timeout waiting for block result")
9090
}
91-
9291
}
9392

9493
func (s *EthereumService) GetBlockByHash(hash common.Hash) *types.Block {

core/state/metrics.go

+8-10
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,14 @@ package state
1919
import "github.com/ethereum/go-ethereum/metrics"
2020

2121
var (
22-
accountUpdatedMeter = metrics.NewRegisteredMeter("state/update/account", nil)
23-
storageUpdatedMeter = metrics.NewRegisteredMeter("state/update/storage", nil)
24-
accountDeletedMeter = metrics.NewRegisteredMeter("state/delete/account", nil)
25-
storageDeletedMeter = metrics.NewRegisteredMeter("state/delete/storage", nil)
26-
accountTrieCommittedMeter = metrics.NewRegisteredMeter("state/commit/accountnodes", nil)
27-
storageTriesCommittedMeter = metrics.NewRegisteredMeter("state/commit/storagenodes", nil)
28-
accountTrieUpdatedMeter = metrics.NewRegisteredMeter("state/update/accountnodes", nil)
29-
storageTriesUpdatedMeter = metrics.NewRegisteredMeter("state/update/storagenodes", nil)
30-
accountTrieDeletedMeter = metrics.NewRegisteredMeter("state/delete/accountnodes", nil)
31-
storageTriesDeletedMeter = metrics.NewRegisteredMeter("state/delete/storagenodes", nil)
22+
accountUpdatedMeter = metrics.NewRegisteredMeter("state/update/account", nil)
23+
storageUpdatedMeter = metrics.NewRegisteredMeter("state/update/storage", nil)
24+
accountDeletedMeter = metrics.NewRegisteredMeter("state/delete/account", nil)
25+
storageDeletedMeter = metrics.NewRegisteredMeter("state/delete/storage", nil)
26+
accountTrieUpdatedMeter = metrics.NewRegisteredMeter("state/update/accountnodes", nil)
27+
storageTriesUpdatedMeter = metrics.NewRegisteredMeter("state/update/storagenodes", nil)
28+
accountTrieDeletedMeter = metrics.NewRegisteredMeter("state/delete/accountnodes", nil)
29+
storageTriesDeletedMeter = metrics.NewRegisteredMeter("state/delete/storagenodes", nil)
3230

3331
stateCopyMeter = metrics.NewRegisteredMeter("state/copy", nil)
3432
stateSnapshotMeter = metrics.NewRegisteredMeter("state/snapshot", nil)

eth/block-validation/api_test.go

+3-20
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package blockvalidation
33
import (
44
"encoding/json"
55
"errors"
6-
"io/ioutil"
76
"math/big"
87
"os"
98
"testing"
@@ -211,22 +210,6 @@ func TestValidateBuilderSubmissionV2(t *testing.T) {
211210
}
212211
withdrawalsRoot := types.DeriveSha(types.Withdrawals(withdrawals), trie.NewStackTrie(nil))
213212

214-
blockRequest := &BuilderBlockValidationRequestV2{
215-
SubmitBlockRequest: capellaapi.SubmitBlockRequest{
216-
Signature: phase0.BLSSignature{},
217-
Message: &apiv1.BidTrace{},
218-
ExecutionPayload: &capella.ExecutionPayload{},
219-
},
220-
WithdrawalsRoot: withdrawalsRoot,
221-
}
222-
// blockRequest.ExecutionPayload.Withdrawals = WithdrawalToBlockRequestWithdrawal(withdrawals)
223-
// require.ErrorContains(t, api.ValidateBuilderSubmissionV2(blockRequest), "withdrawals before shanghai")
224-
225-
// blockRequest.ExecutionPayload.Timestamp -= 1
226-
// blockRequest.ExecutionPayload.Withdrawals = WithdrawalToBlockRequestWithdrawal(withdrawals[:1])
227-
// updatePayloadHashV2(t, blockRequest)
228-
// require.ErrorContains(t, api.ValidateBuilderSubmissionV2(blockRequest), "withdrawals mismatch")
229-
230213
execData, err := assembleBlock(api, parent.Hash(), &engine.PayloadAttributes{
231214
Timestamp: parent.Time() + 5,
232215
Withdrawals: withdrawals,
@@ -242,7 +225,7 @@ func TestValidateBuilderSubmissionV2(t *testing.T) {
242225
proposerAddr := bellatrix.ExecutionAddress{}
243226
copy(proposerAddr[:], testValidatorAddr.Bytes())
244227

245-
blockRequest = &BuilderBlockValidationRequestV2{
228+
blockRequest := &BuilderBlockValidationRequestV2{
246229
SubmitBlockRequest: capellaapi.SubmitBlockRequest{
247230
Signature: phase0.BLSSignature{},
248231
Message: &apiv1.BidTrace{
@@ -392,7 +375,7 @@ func startEthService(t *testing.T, genesis *core.Genesis, blocks []*types.Block)
392375
func assembleBlock(api *BlockValidationAPI, parentHash common.Hash, params *engine.PayloadAttributes) (*engine.ExecutableData, error) {
393376
args := &miner.BuildPayloadArgs{
394377
Parent: parentHash,
395-
Timestamp: uint64(params.Timestamp),
378+
Timestamp: params.Timestamp,
396379
FeeRecipient: params.SuggestedFeeRecipient,
397380
GasLimit: params.GasLimit,
398381
Random: params.Random,
@@ -423,7 +406,7 @@ func TestBlacklistLoad(t *testing.T) {
423406
ba := BlacklistedAddresses{common.Address{0x13}, common.Address{0x14}}
424407
bytes, err := json.MarshalIndent(ba, "", " ")
425408
require.NoError(t, err)
426-
err = ioutil.WriteFile(file.Name(), bytes, 0644)
409+
err = os.WriteFile(file.Name(), bytes, 0644)
427410
require.NoError(t, err)
428411

429412
av, err = NewAccessVerifierFromFile(file.Name())

miner/algo_contracts_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var (
3030
// 0x0b CALLER clr bal 0 0 0 0 0 0x33
3131
// 0x0c GAS gas clr bal 0 0 0 0 0 0x5a
3232
// 0x0d CALL . 0xf1
33-
contractSendBalance = parseCode("0x47600557fe5b5959595947335af100")
33+
// contractSendBalance = parseCode("0x47600557fe5b5959595947335af100")
3434
)
3535

3636
// parseCode converts a hex bytecode to a byte slice, or panics if the hex

miner/contract_simulator_test.go

+3-8
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"github.com/ethereum/go-ethereum/core/rawdb"
2121
"github.com/ethereum/go-ethereum/core/types"
2222
"github.com/ethereum/go-ethereum/crypto"
23-
"github.com/ethereum/go-ethereum/log"
2423
"github.com/ethereum/go-ethereum/params"
2524
"github.com/google/uuid"
2625
"github.com/stretchr/testify/require"
@@ -36,10 +35,6 @@ var (
3635
bigEther = big.NewInt(params.Ether)
3736
)
3837

39-
func enableLogging() {
40-
log.Root().SetHandler(log.LvlFilterHandler(log.LvlDebug, log.StreamHandler(os.Stderr, log.TerminalFormat(true))))
41-
}
42-
4338
func deployAllContracts(t *testing.T, key *ecdsa.PrivateKey, gasPrice *big.Int) []*types.Transaction {
4439
allContractsData, err := os.ReadFile("testdata/allcontracts.signeddata")
4540
require.NoError(t, err)
@@ -162,7 +157,7 @@ func TestSimulatorState(t *testing.T) {
162157
testAddress1Key, _ := crypto.GenerateKey()
163158
testAddress1 := crypto.PubkeyToAddress(testAddress1Key.PublicKey)
164159

165-
rand.Seed(10)
160+
rand.New(rand.NewSource(10))
166161

167162
deploymentTxs := deployAllContracts(t, deployerKey, b.chain.CurrentHeader().BaseFee)
168163

@@ -178,7 +173,7 @@ func TestSimulatorState(t *testing.T) {
178173
nonceModFor.Set(b.chain.CurrentHeader().Number)
179174
}
180175

181-
cm, _ := nonceMod[addr]
176+
cm := nonceMod[addr]
182177
nonceMod[addr] = cm + 1
183178
return b.txPool.Nonce(addr) + cm
184179
}
@@ -232,7 +227,6 @@ func TestSimulatorState(t *testing.T) {
232227
approveTxs = append(approveTxs, adminApproveTxDai)
233228

234229
for _, spender := range []TestParticipant{testParticipants.users[0], testParticipants.searchers[0]} {
235-
236230
mintTx := prepareContractCallTx(daiContract, deployerKey, "mint", spender.address, new(big.Int).Mul(bigEther, big.NewInt(50000)))
237231
approveTxs = append(approveTxs, mintTx)
238232

@@ -257,6 +251,7 @@ func TestSimulatorState(t *testing.T) {
257251
require.NoError(t, err)
258252

259253
backrunTx, err := types.SignTx(types.NewTransaction(getNonce(testParticipants.searchers[0].address), atomicSwapContract.address, new(big.Int), 9000000, getBaseFee(), backrunTxData), types.HomesteadSigner{}, testParticipants.searchers[0].key)
254+
require.NoError(t, err)
260255

261256
targetBlockNumber := new(big.Int).Set(b.chain.CurrentHeader().Number)
262257
targetBlockNumber.Add(targetBlockNumber, big.NewInt(1))

miner/multi_worker.go

-5
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,6 @@ func (w *multiWorker) disablePreseal() {
8686
}
8787
}
8888

89-
type resChPair struct {
90-
resCh chan *types.Block
91-
errCh chan error
92-
}
93-
9489
func (w *multiWorker) buildPayload(args *BuildPayloadArgs) (*Payload, error) {
9590
// Build the initial version with no transaction included. It should be fast
9691
// enough to run. The empty payload can at least make sure there is something

miner/worker.go

-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ const (
8484

8585
var (
8686
errCouldNotApplyTransaction = errors.New("could not apply transaction")
87-
errBundleInterrupted = errors.New("interrupt while applying bundles")
8887
errBlockInterruptedByNewHead = errors.New("new head arrived while building block")
8988
errBlockInterruptedByRecommit = errors.New("recommit interrupt while building block")
9089
errBlocklistViolation = errors.New("blocklist violation")

miner/worker_test.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ package miner
1818

1919
import (
2020
"crypto/ecdsa"
21+
"crypto/rand"
2122
"errors"
2223
"math/big"
23-
"math/rand"
24+
mrnd "math/rand"
2425
"sync/atomic"
2526
"testing"
2627
"time"
@@ -778,7 +779,7 @@ func testBundles(t *testing.T) {
778779
return len(task.receipts) == 0
779780
}
780781

781-
rand.Seed(10)
782+
mrnd.New(mrnd.NewSource(10))
782783

783784
for i := 0; i < 2; i++ {
784785
commonTxs := []*types.Transaction{
@@ -803,15 +804,15 @@ func testBundles(t *testing.T) {
803804

804805
// common transactions in 10% of the bundles, randomly
805806
for i := 0; i < nBundles/10; i++ {
806-
randomCommonIndex := rand.Intn(len(commonTxs))
807-
randomBundleIndex := rand.Intn(nBundles)
807+
randomCommonIndex := mrnd.Intn(len(commonTxs))
808+
randomBundleIndex := mrnd.Intn(nBundles)
808809
bundles[randomBundleIndex].Txs = append(bundles[randomBundleIndex].Txs, commonTxs[randomCommonIndex])
809810
}
810811

811812
// additional lower profit transactions in 10% of the bundles, randomly
812813
for _, extraKey := range extraKeys {
813814
tx := b.newRandomTx(false, testBankAddress, 1, extraKey, 0, big.NewInt(20*params.InitialBaseFee))
814-
randomBundleIndex := rand.Intn(nBundles)
815+
randomBundleIndex := mrnd.Intn(nBundles)
815816
bundles[randomBundleIndex].Txs = append(bundles[randomBundleIndex].Txs, tx)
816817
}
817818

test_utils/chan.go

-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,4 @@ func RequireChan[V any](ch chan V, timeout time.Duration) ChanResult[V] {
1515
case <-time.After(timeout):
1616
return ChanResult[V]{v, true}
1717
}
18-
19-
return ChanResult[V]{v, true}
2018
}

0 commit comments

Comments
 (0)