Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,40 @@ env:

jobs:

lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ^1.20
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Install golangci-lint
run: go install github.com/golangci/golangci-lint/cmd/[email protected]

- name: Lint
run: make lint

- name: Ensure go mod tidy runs without changes
run: |
go mod tidy
git diff-index HEAD
git diff-index --quiet HEAD

build:
name: Build
runs-on: ubuntu-latest
steps:

- name: Set up Go 1.x
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: ^1.13
go-version: ^1.20
id: go

- name: Check out code into the Go module directory
Expand All @@ -38,9 +63,9 @@ jobs:
steps:

- name: Set up Go 1.x
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: ^1.13
go-version: ^1.20
id: go

- name: Use Node.js 12.x
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ There are two parts of the builder.

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

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

Expand Down
23 changes: 2 additions & 21 deletions builder/beacon_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/r3labs/sse"
"golang.org/x/exp/slices"
)

type IBeaconClient interface {
Expand All @@ -33,9 +32,7 @@ type testBeaconClient struct {
slot uint64
}

func (b *testBeaconClient) Stop() {
return
}
func (b *testBeaconClient) Stop() {}

func (b *testBeaconClient) isValidator(pubkey PubkeyHex) bool {
return true
Expand Down Expand Up @@ -107,22 +104,6 @@ func (m *MultiBeaconClient) getProposerForNextSlot(requestedSlot uint64) (Pubkey
return PubkeyHex(""), allErrs
}

func payloadAttributesMatch(l types.BuilderPayloadAttributes, r types.BuilderPayloadAttributes) bool {
if l.Timestamp != r.Timestamp ||
l.Slot != r.Slot ||
l.GasLimit != r.GasLimit ||
l.Random != r.Random ||
l.HeadHash != r.HeadHash {
return false
}

if !slices.Equal(l.Withdrawals, r.Withdrawals) {
return false
}

return true
}

func (m *MultiBeaconClient) SubscribeToPayloadAttributesEvents(payloadAttrC chan types.BuilderPayloadAttributes) {
for _, c := range m.clients {
go c.SubscribeToPayloadAttributesEvents(payloadAttrC)
Expand Down Expand Up @@ -224,7 +205,7 @@ func (b *BeaconClient) UpdateValidatorMapForever() {
// more frequently to avoid missing updates on errors
timer := time.NewTimer(retryDelay)
defer timer.Stop()
for true {
for {
select {
case <-b.ctx.Done():
return
Expand Down
1 change: 0 additions & 1 deletion builder/eth_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ func (s *EthereumService) BuildBlock(attrs *types.BuilderPayloadAttributes, seal
log.Error("timeout waiting for block", "parent hash", attrs.HeadHash, "slot", attrs.Slot)
return errors.New("timeout waiting for block result")
}

}

func (s *EthereumService) GetBlockByHash(hash common.Hash) *types.Block {
Expand Down
18 changes: 8 additions & 10 deletions core/state/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@ package state
import "github.com/ethereum/go-ethereum/metrics"

var (
accountUpdatedMeter = metrics.NewRegisteredMeter("state/update/account", nil)
storageUpdatedMeter = metrics.NewRegisteredMeter("state/update/storage", nil)
accountDeletedMeter = metrics.NewRegisteredMeter("state/delete/account", nil)
storageDeletedMeter = metrics.NewRegisteredMeter("state/delete/storage", nil)
accountTrieCommittedMeter = metrics.NewRegisteredMeter("state/commit/accountnodes", nil)
storageTriesCommittedMeter = metrics.NewRegisteredMeter("state/commit/storagenodes", nil)
accountTrieUpdatedMeter = metrics.NewRegisteredMeter("state/update/accountnodes", nil)
storageTriesUpdatedMeter = metrics.NewRegisteredMeter("state/update/storagenodes", nil)
accountTrieDeletedMeter = metrics.NewRegisteredMeter("state/delete/accountnodes", nil)
storageTriesDeletedMeter = metrics.NewRegisteredMeter("state/delete/storagenodes", nil)
accountUpdatedMeter = metrics.NewRegisteredMeter("state/update/account", nil)
storageUpdatedMeter = metrics.NewRegisteredMeter("state/update/storage", nil)
accountDeletedMeter = metrics.NewRegisteredMeter("state/delete/account", nil)
storageDeletedMeter = metrics.NewRegisteredMeter("state/delete/storage", nil)
accountTrieUpdatedMeter = metrics.NewRegisteredMeter("state/update/accountnodes", nil)
storageTriesUpdatedMeter = metrics.NewRegisteredMeter("state/update/storagenodes", nil)
accountTrieDeletedMeter = metrics.NewRegisteredMeter("state/delete/accountnodes", nil)
storageTriesDeletedMeter = metrics.NewRegisteredMeter("state/delete/storagenodes", nil)

stateCopyMeter = metrics.NewRegisteredMeter("state/copy", nil)
stateSnapshotMeter = metrics.NewRegisteredMeter("state/snapshot", nil)
Expand Down
23 changes: 3 additions & 20 deletions eth/block-validation/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package blockvalidation
import (
"encoding/json"
"errors"
"io/ioutil"
"math/big"
"os"
"testing"
Expand Down Expand Up @@ -211,22 +210,6 @@ func TestValidateBuilderSubmissionV2(t *testing.T) {
}
withdrawalsRoot := types.DeriveSha(types.Withdrawals(withdrawals), trie.NewStackTrie(nil))

blockRequest := &BuilderBlockValidationRequestV2{
SubmitBlockRequest: capellaapi.SubmitBlockRequest{
Signature: phase0.BLSSignature{},
Message: &apiv1.BidTrace{},
ExecutionPayload: &capella.ExecutionPayload{},
},
WithdrawalsRoot: withdrawalsRoot,
}
// blockRequest.ExecutionPayload.Withdrawals = WithdrawalToBlockRequestWithdrawal(withdrawals)
// require.ErrorContains(t, api.ValidateBuilderSubmissionV2(blockRequest), "withdrawals before shanghai")

// blockRequest.ExecutionPayload.Timestamp -= 1
// blockRequest.ExecutionPayload.Withdrawals = WithdrawalToBlockRequestWithdrawal(withdrawals[:1])
// updatePayloadHashV2(t, blockRequest)
// require.ErrorContains(t, api.ValidateBuilderSubmissionV2(blockRequest), "withdrawals mismatch")

execData, err := assembleBlock(api, parent.Hash(), &engine.PayloadAttributes{
Timestamp: parent.Time() + 5,
Withdrawals: withdrawals,
Expand All @@ -242,7 +225,7 @@ func TestValidateBuilderSubmissionV2(t *testing.T) {
proposerAddr := bellatrix.ExecutionAddress{}
copy(proposerAddr[:], testValidatorAddr.Bytes())

blockRequest = &BuilderBlockValidationRequestV2{
blockRequest := &BuilderBlockValidationRequestV2{
SubmitBlockRequest: capellaapi.SubmitBlockRequest{
Signature: phase0.BLSSignature{},
Message: &apiv1.BidTrace{
Expand Down Expand Up @@ -392,7 +375,7 @@ func startEthService(t *testing.T, genesis *core.Genesis, blocks []*types.Block)
func assembleBlock(api *BlockValidationAPI, parentHash common.Hash, params *engine.PayloadAttributes) (*engine.ExecutableData, error) {
args := &miner.BuildPayloadArgs{
Parent: parentHash,
Timestamp: uint64(params.Timestamp),
Timestamp: params.Timestamp,
FeeRecipient: params.SuggestedFeeRecipient,
GasLimit: params.GasLimit,
Random: params.Random,
Expand Down Expand Up @@ -423,7 +406,7 @@ func TestBlacklistLoad(t *testing.T) {
ba := BlacklistedAddresses{common.Address{0x13}, common.Address{0x14}}
bytes, err := json.MarshalIndent(ba, "", " ")
require.NoError(t, err)
err = ioutil.WriteFile(file.Name(), bytes, 0644)
err = os.WriteFile(file.Name(), bytes, 0644)
require.NoError(t, err)

av, err = NewAccessVerifierFromFile(file.Name())
Expand Down
2 changes: 1 addition & 1 deletion miner/algo_contracts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var (
// 0x0b CALLER clr bal 0 0 0 0 0 0x33
// 0x0c GAS gas clr bal 0 0 0 0 0 0x5a
// 0x0d CALL . 0xf1
contractSendBalance = parseCode("0x47600557fe5b5959595947335af100")
// contractSendBalance = parseCode("0x47600557fe5b5959595947335af100")
)

// parseCode converts a hex bytecode to a byte slice, or panics if the hex
Expand Down
11 changes: 3 additions & 8 deletions miner/contract_simulator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/google/uuid"
"github.com/stretchr/testify/require"
Expand All @@ -36,10 +35,6 @@ var (
bigEther = big.NewInt(params.Ether)
)

func enableLogging() {
log.Root().SetHandler(log.LvlFilterHandler(log.LvlDebug, log.StreamHandler(os.Stderr, log.TerminalFormat(true))))
}

func deployAllContracts(t *testing.T, key *ecdsa.PrivateKey, gasPrice *big.Int) []*types.Transaction {
allContractsData, err := os.ReadFile("testdata/allcontracts.signeddata")
require.NoError(t, err)
Expand Down Expand Up @@ -162,7 +157,7 @@ func TestSimulatorState(t *testing.T) {
testAddress1Key, _ := crypto.GenerateKey()
testAddress1 := crypto.PubkeyToAddress(testAddress1Key.PublicKey)

rand.Seed(10)
rand.New(rand.NewSource(10))

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

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

cm, _ := nonceMod[addr]
cm := nonceMod[addr]
nonceMod[addr] = cm + 1
return b.txPool.Nonce(addr) + cm
}
Expand Down Expand Up @@ -232,7 +227,6 @@ func TestSimulatorState(t *testing.T) {
approveTxs = append(approveTxs, adminApproveTxDai)

for _, spender := range []TestParticipant{testParticipants.users[0], testParticipants.searchers[0]} {

mintTx := prepareContractCallTx(daiContract, deployerKey, "mint", spender.address, new(big.Int).Mul(bigEther, big.NewInt(50000)))
approveTxs = append(approveTxs, mintTx)

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

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)
require.NoError(t, err)

targetBlockNumber := new(big.Int).Set(b.chain.CurrentHeader().Number)
targetBlockNumber.Add(targetBlockNumber, big.NewInt(1))
Expand Down
5 changes: 0 additions & 5 deletions miner/multi_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,6 @@ func (w *multiWorker) disablePreseal() {
}
}

type resChPair struct {
resCh chan *types.Block
errCh chan error
}

func (w *multiWorker) buildPayload(args *BuildPayloadArgs) (*Payload, error) {
// Build the initial version with no transaction included. It should be fast
// enough to run. The empty payload can at least make sure there is something
Expand Down
1 change: 0 additions & 1 deletion miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ const (

var (
errCouldNotApplyTransaction = errors.New("could not apply transaction")
errBundleInterrupted = errors.New("interrupt while applying bundles")
errBlockInterruptedByNewHead = errors.New("new head arrived while building block")
errBlockInterruptedByRecommit = errors.New("recommit interrupt while building block")
errBlocklistViolation = errors.New("blocklist violation")
Expand Down
11 changes: 6 additions & 5 deletions miner/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ package miner

import (
"crypto/ecdsa"
"crypto/rand"
"errors"
"math/big"
"math/rand"
mrnd "math/rand"
"sync/atomic"
"testing"
"time"
Expand Down Expand Up @@ -778,7 +779,7 @@ func testBundles(t *testing.T) {
return len(task.receipts) == 0
}

rand.Seed(10)
mrnd.New(mrnd.NewSource(10))

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

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

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

Expand Down
2 changes: 0 additions & 2 deletions test_utils/chan.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,4 @@ func RequireChan[V any](ch chan V, timeout time.Duration) ChanResult[V] {
case <-time.After(timeout):
return ChanResult[V]{v, true}
}

return ChanResult[V]{v, true}
}