Skip to content

Commit c399c12

Browse files
committed
Merge upstream PR ethereum#27875
miner: add to build block with EIP-4844 blobs Conflicts: miner/worker.go simple conflict because we added a return param. accepted both changes.
2 parents 9e4f4f3 + feb8f41 commit c399c12

32 files changed

+259
-188
lines changed

.travis.yml

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ jobs:
6666
go: 1.21.x
6767
env:
6868
- azure-linux
69-
- GO111MODULE=on
7069
git:
7170
submodules: false # avoid cloning ethereum/tests
7271
addons:
@@ -100,7 +99,6 @@ jobs:
10099
go: 1.21.x
101100
env:
102101
- azure-osx
103-
- GO111MODULE=on
104102
git:
105103
submodules: false # avoid cloning ethereum/tests
106104
script:
@@ -113,30 +111,24 @@ jobs:
113111
arch: amd64
114112
dist: bionic
115113
go: 1.21.x
116-
env:
117-
- GO111MODULE=on
118114
script:
119-
- go run build/ci.go test $TEST_PACKAGES
115+
- travis_wait 30 go run build/ci.go test $TEST_PACKAGES
120116

121117
- stage: build
122118
if: type = pull_request
123119
os: linux
124120
arch: arm64
125121
dist: bionic
126122
go: 1.20.x
127-
env:
128-
- GO111MODULE=on
129123
script:
130-
- go run build/ci.go test $TEST_PACKAGES
124+
- travis_wait 30 go run build/ci.go test $TEST_PACKAGES
131125

132126
- stage: build
133127
os: linux
134128
dist: bionic
135129
go: 1.20.x
136-
env:
137-
- GO111MODULE=on
138130
script:
139-
- go run build/ci.go test $TEST_PACKAGES
131+
- travis_wait 30 go run build/ci.go test $TEST_PACKAGES
140132

141133
# This builder does the Ubuntu PPA nightly uploads
142134
- stage: build
@@ -146,7 +138,6 @@ jobs:
146138
go: 1.21.x
147139
env:
148140
- ubuntu-ppa
149-
- GO111MODULE=on
150141
git:
151142
submodules: false # avoid cloning ethereum/tests
152143
addons:
@@ -170,7 +161,6 @@ jobs:
170161
go: 1.21.x
171162
env:
172163
- azure-purge
173-
- GO111MODULE=on
174164
git:
175165
submodules: false # avoid cloning ethereum/tests
176166
script:
@@ -182,8 +172,6 @@ jobs:
182172
os: linux
183173
dist: bionic
184174
go: 1.21.x
185-
env:
186-
- GO111MODULE=on
187175
script:
188-
- go run build/ci.go test -race $TEST_PACKAGES
176+
- travis_wait 30 go run build/ci.go test -race $TEST_PACKAGES
189177

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
GOBIN = ./build/bin
88
GO ?= latest
9-
GORUN = env GO111MODULE=on go run
9+
GORUN = go run
1010

1111
geth:
1212
$(GORUN) build/ci.go install ./cmd/geth
@@ -23,7 +23,7 @@ lint: ## Run linters.
2323
$(GORUN) build/ci.go lint
2424

2525
clean:
26-
env GO111MODULE=on go clean -cache
26+
go clean -cache
2727
rm -fr build/_workspace/pkg/ $(GOBIN)/*
2828

2929
# The devtools target installs tools required for 'go generate'.

accounts/abi/method.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,12 @@ func NewMethod(name string, rawName string, funType FunctionType, mutability str
127127
state = state + " "
128128
}
129129
identity := fmt.Sprintf("function %v", rawName)
130-
if funType == Fallback {
130+
switch funType {
131+
case Fallback:
131132
identity = "fallback"
132-
} else if funType == Receive {
133+
case Receive:
133134
identity = "receive"
134-
} else if funType == Constructor {
135+
case Constructor:
135136
identity = "constructor"
136137
}
137138
str := fmt.Sprintf("%v(%v) %sreturns(%v)", identity, strings.Join(inputNames, ", "), state, strings.Join(outputNames, ", "))

accounts/abi/method_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,12 @@ func TestMethodString(t *testing.T) {
8484

8585
for _, test := range table {
8686
var got string
87-
if test.method == "fallback" {
87+
switch test.method {
88+
case "fallback":
8889
got = abi.Fallback.String()
89-
} else if test.method == "receive" {
90+
case "receive":
9091
got = abi.Receive.String()
91-
} else {
92+
default:
9293
got = abi.Methods[test.method].String()
9394
}
9495
if got != test.expectation {

accounts/abi/unpack.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,14 @@ func forEachUnpack(t Type, output []byte, start, size int) (interface{}, error)
160160
// this value will become our slice or our array, depending on the type
161161
var refSlice reflect.Value
162162

163-
if t.T == SliceTy {
163+
switch t.T {
164+
case SliceTy:
164165
// declare our slice
165166
refSlice = reflect.MakeSlice(t.GetType(), size, size)
166-
} else if t.T == ArrayTy {
167+
case ArrayTy:
167168
// declare our array
168169
refSlice = reflect.New(t.GetType()).Elem()
169-
} else {
170+
default:
170171
return nil, errors.New("abi: invalid type in array/slice unpacking stage")
171172
}
172173

beacon/engine/types.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"github.com/ethereum/go-ethereum/common"
2424
"github.com/ethereum/go-ethereum/common/hexutil"
2525
"github.com/ethereum/go-ethereum/core/types"
26-
"github.com/ethereum/go-ethereum/crypto/kzg4844"
2726
"github.com/ethereum/go-ethereum/trie"
2827
)
2928

@@ -237,7 +236,7 @@ func ExecutableDataToBlock(params ExecutableData, versionedHashes []common.Hash)
237236

238237
// BlockToExecutableData constructs the ExecutableData structure by filling the
239238
// fields from the given block. It assumes the given block is post-merge block.
240-
func BlockToExecutableData(block *types.Block, fees *big.Int, blobs []kzg4844.Blob, commitments []kzg4844.Commitment, proofs []kzg4844.Proof) *ExecutionPayloadEnvelope {
239+
func BlockToExecutableData(block *types.Block, fees *big.Int, sidecars []*types.BlobTxSidecar) *ExecutionPayloadEnvelope {
241240
data := &ExecutableData{
242241
BlockHash: block.Hash(),
243242
ParentHash: block.ParentHash(),
@@ -258,17 +257,19 @@ func BlockToExecutableData(block *types.Block, fees *big.Int, blobs []kzg4844.Bl
258257
ExcessBlobGas: block.ExcessBlobGas(),
259258
// TODO BeaconRoot
260259
}
261-
blobsBundle := BlobsBundleV1{
260+
bundle := BlobsBundleV1{
262261
Commitments: make([]hexutil.Bytes, 0),
263262
Blobs: make([]hexutil.Bytes, 0),
264263
Proofs: make([]hexutil.Bytes, 0),
265264
}
266-
for i := range blobs {
267-
blobsBundle.Blobs = append(blobsBundle.Blobs, hexutil.Bytes(blobs[i][:]))
268-
blobsBundle.Commitments = append(blobsBundle.Commitments, hexutil.Bytes(commitments[i][:]))
269-
blobsBundle.Proofs = append(blobsBundle.Proofs, hexutil.Bytes(proofs[i][:]))
265+
for _, sidecar := range sidecars {
266+
for j := range sidecar.Blobs {
267+
bundle.Blobs = append(bundle.Blobs, hexutil.Bytes(sidecar.Blobs[j][:]))
268+
bundle.Commitments = append(bundle.Commitments, hexutil.Bytes(sidecar.Commitments[j][:]))
269+
bundle.Proofs = append(bundle.Proofs, hexutil.Bytes(sidecar.Proofs[j][:]))
270+
}
270271
}
271-
return &ExecutionPayloadEnvelope{ExecutionPayload: data, BlockValue: fees, BlobsBundle: &blobsBundle}
272+
return &ExecutionPayloadEnvelope{ExecutionPayload: data, BlockValue: fees, BlobsBundle: &bundle}
272273
}
273274

274275
// ExecutionPayloadBodyV1 is used in the response to GetPayloadBodiesByHashV1 and GetPayloadBodiesByRangeV1

cmd/utils/flags.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2073,10 +2073,10 @@ func MakeChainDatabase(ctx *cli.Context, stack *node.Node, readonly bool) ethdb.
20732073
// tryMakeReadOnlyDatabase try to open the chain database in read-only mode,
20742074
// or fallback to write mode if the database is not initialized.
20752075
func tryMakeReadOnlyDatabase(ctx *cli.Context, stack *node.Node) ethdb.Database {
2076-
// If datadir doesn't exist we need to open db in write-mode
2077-
// so database engine can create files.
2076+
// If the database doesn't exist we need to open it in write-mode to allow
2077+
// the engine to create files.
20782078
readonly := true
2079-
if !common.FileExist(stack.ResolvePath("chaindata")) {
2079+
if rawdb.PreexistingDatabase(stack.ResolvePath("chaindata")) == "" {
20802080
readonly = false
20812081
}
20822082
return MakeChainDatabase(ctx, stack, readonly)

consensus/misc/eip4844/eip4844.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ func VerifyEIP4844Header(parent, header *types.Header) error {
4242
return errors.New("header is missing blobGasUsed")
4343
}
4444
// Verify that the blob gas used remains within reasonable limits.
45-
if *header.BlobGasUsed > params.BlobTxMaxBlobGasPerBlock {
46-
return fmt.Errorf("blob gas used %d exceeds maximum allowance %d", *header.BlobGasUsed, params.BlobTxMaxBlobGasPerBlock)
45+
if *header.BlobGasUsed > params.MaxBlobGasPerBlock {
46+
return fmt.Errorf("blob gas used %d exceeds maximum allowance %d", *header.BlobGasUsed, params.MaxBlobGasPerBlock)
4747
}
4848
if *header.BlobGasUsed%params.BlobTxBlobGasPerBlob != 0 {
4949
return fmt.Errorf("blob gas used %d not a multiple of blob gas per blob %d", header.BlobGasUsed, params.BlobTxBlobGasPerBlob)

core/blockchain_repair_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,6 +1767,7 @@ func testRepairWithScheme(t *testing.T, tt *rewindTest, snapshots bool, scheme s
17671767
db, err := rawdb.Open(rawdb.OpenOptions{
17681768
Directory: datadir,
17691769
AncientsDirectory: ancient,
1770+
Ephemeral: true,
17701771
})
17711772
if err != nil {
17721773
t.Fatalf("Failed to create persistent database: %v", err)
@@ -1851,6 +1852,7 @@ func testRepairWithScheme(t *testing.T, tt *rewindTest, snapshots bool, scheme s
18511852
db, err = rawdb.Open(rawdb.OpenOptions{
18521853
Directory: datadir,
18531854
AncientsDirectory: ancient,
1855+
Ephemeral: true,
18541856
})
18551857
if err != nil {
18561858
t.Fatalf("Failed to reopen persistent database: %v", err)
@@ -1972,6 +1974,7 @@ func testIssue23496(t *testing.T, scheme string) {
19721974
db, err = rawdb.Open(rawdb.OpenOptions{
19731975
Directory: datadir,
19741976
AncientsDirectory: ancient,
1977+
Ephemeral: true,
19751978
})
19761979
if err != nil {
19771980
t.Fatalf("Failed to reopen persistent database: %v", err)

core/blockchain_sethead_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1971,6 +1971,7 @@ func testSetHeadWithScheme(t *testing.T, tt *rewindTest, snapshots bool, scheme
19711971
db, err := rawdb.Open(rawdb.OpenOptions{
19721972
Directory: datadir,
19731973
AncientsDirectory: ancient,
1974+
Ephemeral: true,
19741975
})
19751976
if err != nil {
19761977
t.Fatalf("Failed to create persistent database: %v", err)

core/blockchain_snapshot_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func (basic *snapshotTestBasic) prepare(t *testing.T) (*BlockChain, []*types.Blo
6868
db, err := rawdb.Open(rawdb.OpenOptions{
6969
Directory: datadir,
7070
AncientsDirectory: ancient,
71+
Ephemeral: true,
7172
})
7273
if err != nil {
7374
t.Fatalf("Failed to create persistent database: %v", err)
@@ -258,6 +259,7 @@ func (snaptest *crashSnapshotTest) test(t *testing.T) {
258259
newdb, err := rawdb.Open(rawdb.OpenOptions{
259260
Directory: snaptest.datadir,
260261
AncientsDirectory: snaptest.ancient,
262+
Ephemeral: true,
261263
})
262264
if err != nil {
263265
t.Fatalf("Failed to reopen persistent database: %v", err)

core/rawdb/database.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,10 +326,10 @@ const (
326326
dbLeveldb = "leveldb"
327327
)
328328

329-
// hasPreexistingDb checks the given data directory whether a database is already
329+
// PreexistingDatabase checks the given data directory whether a database is already
330330
// instantiated at that location, and if so, returns the type of database (or the
331331
// empty string).
332-
func hasPreexistingDb(path string) string {
332+
func PreexistingDatabase(path string) string {
333333
if _, err := os.Stat(filepath.Join(path, "CURRENT")); err != nil {
334334
return "" // No pre-existing db
335335
}
@@ -352,6 +352,9 @@ type OpenOptions struct {
352352
Cache int // the capacity(in megabytes) of the data caching
353353
Handles int // number of files to be open simultaneously
354354
ReadOnly bool
355+
// Ephemeral means that filesystem sync operations should be avoided: data integrity in the face of
356+
// a crash is not important. This option should typically be used in tests.
357+
Ephemeral bool
355358
}
356359

357360
// openKeyValueDatabase opens a disk-based key-value database, e.g. leveldb or pebble.
@@ -367,14 +370,14 @@ func openKeyValueDatabase(o OpenOptions) (ethdb.Database, error) {
367370
}
368371
// Retrieve any pre-existing database's type and use that or the requested one
369372
// as long as there's no conflict between the two types
370-
existingDb := hasPreexistingDb(o.Directory)
373+
existingDb := PreexistingDatabase(o.Directory)
371374
if len(existingDb) != 0 && len(o.Type) != 0 && o.Type != existingDb {
372375
return nil, fmt.Errorf("db.engine choice was %v but found pre-existing %v database in specified data directory", o.Type, existingDb)
373376
}
374377
if o.Type == dbPebble || existingDb == dbPebble {
375378
if PebbleEnabled {
376379
log.Info("Using pebble as the backing database")
377-
return NewPebbleDBDatabase(o.Directory, o.Cache, o.Handles, o.Namespace, o.ReadOnly)
380+
return NewPebbleDBDatabase(o.Directory, o.Cache, o.Handles, o.Namespace, o.ReadOnly, o.Ephemeral)
378381
} else {
379382
return nil, errors.New("db.engine 'pebble' not supported on this platform")
380383
}
@@ -387,7 +390,7 @@ func openKeyValueDatabase(o OpenOptions) (ethdb.Database, error) {
387390
// on supported platforms and LevelDB on anything else.
388391
if PebbleEnabled {
389392
log.Info("Defaulting to pebble as the backing database")
390-
return NewPebbleDBDatabase(o.Directory, o.Cache, o.Handles, o.Namespace, o.ReadOnly)
393+
return NewPebbleDBDatabase(o.Directory, o.Cache, o.Handles, o.Namespace, o.ReadOnly, o.Ephemeral)
391394
} else {
392395
log.Info("Defaulting to leveldb as the backing database")
393396
return NewLevelDBDatabase(o.Directory, o.Cache, o.Handles, o.Namespace, o.ReadOnly)

core/rawdb/databases_64bit.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ const PebbleEnabled = true
2828

2929
// NewPebbleDBDatabase creates a persistent key-value database without a freezer
3030
// moving immutable chain segments into cold storage.
31-
func NewPebbleDBDatabase(file string, cache int, handles int, namespace string, readonly bool) (ethdb.Database, error) {
32-
db, err := pebble.New(file, cache, handles, namespace, readonly)
31+
func NewPebbleDBDatabase(file string, cache int, handles int, namespace string, readonly, ephemeral bool) (ethdb.Database, error) {
32+
db, err := pebble.New(file, cache, handles, namespace, readonly, ephemeral)
3333
if err != nil {
3434
return nil, err
3535
}

core/rawdb/databases_non64bit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ const PebbleEnabled = false
2929

3030
// NewPebbleDBDatabase creates a persistent key-value database without a freezer
3131
// moving immutable chain segments into cold storage.
32-
func NewPebbleDBDatabase(file string, cache int, handles int, namespace string, readonly bool) (ethdb.Database, error) {
32+
func NewPebbleDBDatabase(file string, cache int, handles int, namespace string, readonly, ephemeral bool) (ethdb.Database, error) {
3333
return nil, errors.New("pebble is not supported on this platform")
3434
}

core/rawdb/schema.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,11 @@ func accountSnapshotKey(hash common.Hash) []byte {
195195

196196
// storageSnapshotKey = SnapshotStoragePrefix + account hash + storage hash
197197
func storageSnapshotKey(accountHash, storageHash common.Hash) []byte {
198-
return append(append(SnapshotStoragePrefix, accountHash.Bytes()...), storageHash.Bytes()...)
198+
buf := make([]byte, len(SnapshotStoragePrefix)+common.HashLength+common.HashLength)
199+
n := copy(buf, SnapshotStoragePrefix)
200+
n += copy(buf[n:], accountHash.Bytes())
201+
copy(buf[n:], storageHash.Bytes())
202+
return buf
199203
}
200204

201205
// storageSnapshotsKey = SnapshotStoragePrefix + account hash + storage hash
@@ -259,7 +263,11 @@ func accountTrieNodeKey(path []byte) []byte {
259263

260264
// storageTrieNodeKey = trieNodeStoragePrefix + accountHash + nodePath.
261265
func storageTrieNodeKey(accountHash common.Hash, path []byte) []byte {
262-
return append(append(trieNodeStoragePrefix, accountHash.Bytes()...), path...)
266+
buf := make([]byte, len(trieNodeStoragePrefix)+common.HashLength+len(path))
267+
n := copy(buf, trieNodeStoragePrefix)
268+
n += copy(buf[n:], accountHash.Bytes())
269+
copy(buf[n:], path)
270+
return buf
263271
}
264272

265273
// IsLegacyTrieNode reports whether a provided database entry is a legacy trie

0 commit comments

Comments
 (0)