Skip to content

Commit 219d446

Browse files
Merge pull request #13 from roberto-bayardo/eip4844-rebase
rebase eip-4844 branch with latest geth master
2 parents d704423 + 39d6ce1 commit 219d446

File tree

439 files changed

+9225
-8147
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

439 files changed

+9225
-8147
lines changed

.golangci.yml

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,55 @@ linters:
1919
- govet
2020
- ineffassign
2121
- misspell
22-
# - staticcheck
2322
- unconvert
24-
# - unused
2523
- varcheck
24+
- typecheck
25+
- unused
26+
- staticcheck
27+
- bidichk
28+
- durationcheck
29+
- exportloopref
30+
- gosec
31+
- whitespace
32+
33+
# - structcheck # lots of false positives
34+
# - errcheck #lot of false positives
35+
# - contextcheck
36+
# - errchkjson # lots of false positives
37+
# - errorlint # this check crashes
38+
# - exhaustive # silly check
39+
# - makezero # false positives
40+
# - nilerr # several intentional
2641

2742
linters-settings:
2843
gofmt:
2944
simplify: true
3045
goconst:
3146
min-len: 3 # minimum length of string constant
3247
min-occurrences: 6 # minimum number of occurrences
48+
gosec:
49+
excludes:
50+
- G404 # Use of weak random number generator - lots of FP
51+
- G107 # Potential http request -- those are intentional
52+
- G306 # G306: Expect WriteFile permissions to be 0600 or less
3353

3454
issues:
3555
exclude-rules:
36-
- path: crypto/blake2b/
37-
linters:
38-
- deadcode
39-
- path: crypto/bn256/cloudflare
40-
linters:
41-
- deadcode
42-
- path: p2p/discv5/
43-
linters:
44-
- deadcode
45-
- path: core/vm/instructions_test.go
46-
linters:
47-
- goconst
48-
- path: cmd/faucet/
56+
- path: crypto/bn256/cloudflare/optate.go
4957
linters:
5058
- deadcode
59+
- staticcheck
60+
- path: internal/build/pgp.go
61+
text: 'SA1019: package golang.org/x/crypto/openpgp is deprecated'
62+
- path: core/vm/contracts.go
63+
text: 'SA1019: package golang.org/x/crypto/ripemd160 is deprecated'
64+
- path: accounts/usbwallet/trezor.go
65+
text: 'SA1019: package github.com/golang/protobuf/proto is deprecated'
66+
- path: accounts/usbwallet/trezor/
67+
text: 'SA1019: package github.com/golang/protobuf/proto is deprecated'
68+
exclude:
69+
- 'SA1019: event.TypeMux is deprecated: use Feed'
70+
- 'SA1019: strings.Title is deprecated'
71+
- 'SA1019: strings.Title has been deprecated since Go 1.18 and an alternative has been available since Go 1.0: The rule Title uses for word boundaries does not handle Unicode punctuation properly. Use golang.org/x/text/cases instead.'
72+
- 'SA1029: should not use built-in type string as key for value'
73+
- 'G306: Expect WriteFile permissions to be 0600 or less'

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ COPY go.sum /go-ethereum/
1414
RUN cd /go-ethereum && go mod download
1515

1616
ADD . /go-ethereum
17-
RUN cd /go-ethereum && go run build/ci.go install ./cmd/geth
17+
RUN cd /go-ethereum && go run build/ci.go install -static ./cmd/geth
1818

1919
# Pull Geth into a second stage deploy alpine container
2020
FROM alpine:latest

Dockerfile.alltools

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ COPY go.sum /go-ethereum/
1414
RUN cd /go-ethereum && go mod download
1515

1616
ADD . /go-ethereum
17-
RUN cd /go-ethereum && go run build/ci.go install
17+
RUN cd /go-ethereum && go run build/ci.go install -static
1818

1919
# Pull all binaries into a second stage deploy alpine container
2020
FROM alpine:latest

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ directory.
4242
| `abigen` | Source code generator to convert Ethereum contract definitions into easy to use, compile-time type-safe Go packages. It operates on plain [Ethereum contract ABIs](https://docs.soliditylang.org/en/develop/abi-spec.html) with expanded functionality if the contract bytecode is also available. However, it also accepts Solidity source files, making development much more streamlined. Please see our [Native DApps](https://geth.ethereum.org/docs/dapp/native-bindings) page for details. |
4343
| `bootnode` | Stripped down version of our Ethereum client implementation that only takes part in the network node discovery protocol, but does not run any of the higher level application protocols. It can be used as a lightweight bootstrap node to aid in finding peers in private networks. |
4444
| `evm` | Developer utility version of the EVM (Ethereum Virtual Machine) that is capable of running bytecode snippets within a configurable environment and execution mode. Its purpose is to allow isolated, fine-grained debugging of EVM opcodes (e.g. `evm --code 60ff60ff --debug run`). |
45-
| `rlpdump` | Developer utility tool to convert binary RLP ([Recursive Length Prefix](https://eth.wiki/en/fundamentals/rlp)) dumps (data encoding used by the Ethereum protocol both network as well as consensus wise) to user-friendlier hierarchical representation (e.g. `rlpdump --hex CE0183FFFFFFC4C304050583616263`). |
45+
| `rlpdump` | Developer utility tool to convert binary RLP ([Recursive Length Prefix](https://ethereum.org/en/developers/docs/data-structures-and-encoding/rlp)) dumps (data encoding used by the Ethereum protocol both network as well as consensus wise) to user-friendlier hierarchical representation (e.g. `rlpdump --hex CE0183FFFFFFC4C304050583616263`). |
4646
| `puppeth` | a CLI wizard that aids in creating a new Ethereum network. |
4747

4848
## Running `geth`
@@ -188,7 +188,7 @@ accessible from the outside.
188188

189189
As a developer, sooner rather than later you'll want to start interacting with `geth` and the
190190
Ethereum network via your own programs and not manually through the console. To aid
191-
this, `geth` has built-in support for a JSON-RPC based APIs ([standard APIs](https://eth.wiki/json-rpc/API)
191+
this, `geth` has built-in support for a JSON-RPC based APIs ([standard APIs](https://ethereum.github.io/execution-apis/api-documentation/)
192192
and [`geth` specific APIs](https://geth.ethereum.org/docs/rpc/server)).
193193
These can be exposed via HTTP, WebSockets and IPC (UNIX sockets on UNIX based
194194
platforms, and named pipes on Windows).
@@ -211,7 +211,7 @@ HTTP based JSON-RPC API options:
211211
* `--ws.api` API's offered over the WS-RPC interface (default: `eth,net,web3`)
212212
* `--ws.origins` Origins from which to accept websockets requests
213213
* `--ipcdisable` Disable the IPC-RPC server
214-
* `--ipcapi` API's offered over the IPC-RPC interface (default: `admin,debug,eth,miner,net,personal,shh,txpool,web3`)
214+
* `--ipcapi` API's offered over the IPC-RPC interface (default: `admin,debug,eth,miner,net,personal,txpool,web3`)
215215
* `--ipcpath` Filename for IPC socket/pipe within the datadir (explicit paths escape it)
216216

217217
You'll need to use your own programming environments' capabilities (libraries, tools, etc) to
@@ -297,7 +297,7 @@ $ bootnode --genkey=boot.key
297297
$ bootnode --nodekey=boot.key
298298
```
299299

300-
With the bootnode online, it will display an [`enode` URL](https://eth.wiki/en/fundamentals/enode-url-format)
300+
With the bootnode online, it will display an [`enode` URL](https://ethereum.org/en/developers/docs/networking-layer/network-addresses/#enode)
301301
that other nodes can use to connect to it and exchange peer information. Make sure to
302302
replace the displayed IP address information (most probably `[::]`) with your externally
303303
accessible IP to get the actual `enode` URL.

accounts/abi/abi.go

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func (abi ABI) getArguments(name string, data []byte) (Arguments, error) {
9595
args = event.Inputs
9696
}
9797
if args == nil {
98-
return nil, errors.New("abi: could not locate named method or event")
98+
return nil, fmt.Errorf("abi: could not locate named method or event: %s", name)
9999
}
100100
return args, nil
101101
}
@@ -164,7 +164,7 @@ func (abi *ABI) UnmarshalJSON(data []byte) error {
164164
case "constructor":
165165
abi.Constructor = NewMethod("", "", Constructor, field.StateMutability, field.Constant, field.Payable, field.Inputs, nil)
166166
case "function":
167-
name := overloadedName(field.Name, func(s string) bool { _, ok := abi.Methods[s]; return ok })
167+
name := ResolveNameConflict(field.Name, func(s string) bool { _, ok := abi.Methods[s]; return ok })
168168
abi.Methods[name] = NewMethod(name, field.Name, Function, field.StateMutability, field.Constant, field.Payable, field.Inputs, field.Outputs)
169169
case "fallback":
170170
// New introduced function type in v0.6.0, check more detail
@@ -184,9 +184,11 @@ func (abi *ABI) UnmarshalJSON(data []byte) error {
184184
}
185185
abi.Receive = NewMethod("", "", Receive, field.StateMutability, field.Constant, field.Payable, nil, nil)
186186
case "event":
187-
name := overloadedName(field.Name, func(s string) bool { _, ok := abi.Events[s]; return ok })
187+
name := ResolveNameConflict(field.Name, func(s string) bool { _, ok := abi.Events[s]; return ok })
188188
abi.Events[name] = NewEvent(name, field.Name, field.Anonymous, field.Inputs)
189189
case "error":
190+
// Errors cannot be overloaded or overridden but are inherited,
191+
// no need to resolve the name conflict here.
190192
abi.Errors[field.Name] = NewError(field.Name, field.Inputs)
191193
default:
192194
return fmt.Errorf("abi: could not recognize type %v of field %v", field.Type, field.Name)
@@ -251,20 +253,3 @@ func UnpackRevert(data []byte) (string, error) {
251253
}
252254
return unpacked[0].(string), nil
253255
}
254-
255-
// overloadedName returns the next available name for a given thing.
256-
// Needed since solidity allows for overloading.
257-
//
258-
// e.g. if the abi contains Methods send, send1
259-
// overloadedName would return send2 for input send.
260-
//
261-
// overloadedName works for methods, events and errors.
262-
func overloadedName(rawName string, isAvail func(string) bool) string {
263-
name := rawName
264-
ok := isAvail(name)
265-
for idx := 0; ok; idx++ {
266-
name = fmt.Sprintf("%s%d", rawName, idx)
267-
ok = isAvail(name)
268-
}
269-
return name
270-
}

accounts/abi/abi_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,9 +1038,7 @@ func TestABI_EventById(t *testing.T) {
10381038
}
10391039
if event == nil {
10401040
t.Errorf("We should find a event for topic %s, test #%d", topicID.Hex(), testnum)
1041-
}
1042-
1043-
if event.ID != topicID {
1041+
} else if event.ID != topicID {
10441042
t.Errorf("Event id %s does not match topic %s, test #%d", event.ID.Hex(), topicID.Hex(), testnum)
10451043
}
10461044

accounts/abi/argument.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package abi
1818

1919
import (
2020
"encoding/json"
21+
"errors"
2122
"fmt"
2223
"reflect"
2324
"strings"
@@ -79,7 +80,7 @@ func (arguments Arguments) isTuple() bool {
7980
func (arguments Arguments) Unpack(data []byte) ([]interface{}, error) {
8081
if len(data) == 0 {
8182
if len(arguments.NonIndexed()) != 0 {
82-
return nil, fmt.Errorf("abi: attempting to unmarshall an empty string while arguments are expected")
83+
return nil, errors.New("abi: attempting to unmarshall an empty string while arguments are expected")
8384
}
8485
return make([]interface{}, 0), nil
8586
}
@@ -90,11 +91,11 @@ func (arguments Arguments) Unpack(data []byte) ([]interface{}, error) {
9091
func (arguments Arguments) UnpackIntoMap(v map[string]interface{}, data []byte) error {
9192
// Make sure map is not nil
9293
if v == nil {
93-
return fmt.Errorf("abi: cannot unpack into a nil map")
94+
return errors.New("abi: cannot unpack into a nil map")
9495
}
9596
if len(data) == 0 {
9697
if len(arguments.NonIndexed()) != 0 {
97-
return fmt.Errorf("abi: attempting to unmarshall an empty string while arguments are expected")
98+
return errors.New("abi: attempting to unmarshall an empty string while arguments are expected")
9899
}
99100
return nil // Nothing to unmarshal, return
100101
}
@@ -116,7 +117,7 @@ func (arguments Arguments) Copy(v interface{}, values []interface{}) error {
116117
}
117118
if len(values) == 0 {
118119
if len(arguments.NonIndexed()) != 0 {
119-
return fmt.Errorf("abi: attempting to copy no values while arguments are expected")
120+
return errors.New("abi: attempting to copy no values while arguments are expected")
120121
}
121122
return nil // Nothing to copy, return
122123
}

accounts/abi/bind/backends/simulated.go

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ type SimulatedBackend struct {
6363
database ethdb.Database // In memory database to store our testing data
6464
blockchain *core.BlockChain // Ethereum blockchain to handle the consensus
6565

66-
mu sync.Mutex
67-
pendingBlock *types.Block // Currently pending block that will be imported on request
68-
pendingState *state.StateDB // Currently pending state that will be the active on request
66+
mu sync.Mutex
67+
pendingBlock *types.Block // Currently pending block that will be imported on request
68+
pendingState *state.StateDB // Currently pending state that will be the active on request
69+
pendingReceipts types.Receipts // Currently receipts for the pending block
6970

7071
events *filters.EventSystem // Event system for filtering log events live
7172

@@ -84,8 +85,8 @@ func NewSimulatedBackendWithDatabase(database ethdb.Database, alloc core.Genesis
8485
database: database,
8586
blockchain: blockchain,
8687
config: genesis.Config,
87-
events: filters.NewEventSystem(&filterBackend{database, blockchain}, false),
8888
}
89+
backend.events = filters.NewEventSystem(&filterBackend{database, blockchain, backend}, false)
8990
backend.rollback(blockchain.CurrentBlock())
9091
return backend
9192
}
@@ -105,16 +106,20 @@ func (b *SimulatedBackend) Close() error {
105106

106107
// Commit imports all the pending transactions as a single block and starts a
107108
// fresh new state.
108-
func (b *SimulatedBackend) Commit() {
109+
func (b *SimulatedBackend) Commit() common.Hash {
109110
b.mu.Lock()
110111
defer b.mu.Unlock()
111112

112113
if _, err := b.blockchain.InsertChain([]*types.Block{b.pendingBlock}); err != nil {
113114
panic(err) // This cannot happen unless the simulator is wrong, fail in that case
114115
}
116+
blockHash := b.pendingBlock.Hash()
117+
115118
// Using the last inserted block here makes it possible to build on a side
116119
// chain after a fork.
117120
b.rollback(b.pendingBlock)
121+
122+
return blockHash
118123
}
119124

120125
// Rollback aborts all pending transactions, reverting to the last committed state.
@@ -662,7 +667,7 @@ func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx *types.Transa
662667
return fmt.Errorf("invalid transaction nonce: got %d, want %d", tx.Nonce(), nonce)
663668
}
664669
// Include tx in chain
665-
blocks, _ := core.GenerateChain(b.config, block, ethash.NewFaker(), b.database, 1, func(number int, block *core.BlockGen) {
670+
blocks, receipts := core.GenerateChain(b.config, block, ethash.NewFaker(), b.database, 1, func(number int, block *core.BlockGen) {
666671
for _, tx := range b.pendingBlock.Transactions() {
667672
block.AddTxWithChain(b.blockchain, tx)
668673
}
@@ -672,6 +677,7 @@ func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx *types.Transa
672677

673678
b.pendingBlock = blocks[0]
674679
b.pendingState, _ = state.New(b.pendingBlock.Root(), stateDB.Database(), nil)
680+
b.pendingReceipts = receipts[0]
675681
return nil
676682
}
677683

@@ -683,7 +689,7 @@ func (b *SimulatedBackend) FilterLogs(ctx context.Context, query ethereum.Filter
683689
var filter *filters.Filter
684690
if query.BlockHash != nil {
685691
// Block filter requested, construct a single-shot filter
686-
filter = filters.NewBlockFilter(&filterBackend{b.database, b.blockchain}, *query.BlockHash, query.Addresses, query.Topics)
692+
filter = filters.NewBlockFilter(&filterBackend{b.database, b.blockchain, b}, *query.BlockHash, query.Addresses, query.Topics)
687693
} else {
688694
// Initialize unset filter boundaries to run from genesis to chain head
689695
from := int64(0)
@@ -695,7 +701,7 @@ func (b *SimulatedBackend) FilterLogs(ctx context.Context, query ethereum.Filter
695701
to = query.ToBlock.Int64()
696702
}
697703
// Construct the range filter
698-
filter = filters.NewRangeFilter(&filterBackend{b.database, b.blockchain}, from, to, query.Addresses, query.Topics)
704+
filter = filters.NewRangeFilter(&filterBackend{b.database, b.blockchain, b}, from, to, query.Addresses, query.Topics)
699705
}
700706
// Run the filter and return all the logs
701707
logs, err := filter.Logs(ctx)
@@ -817,8 +823,9 @@ func (m callMsg) DataHashes() []common.Hash { return m.CallMsg.DataHashes }
817823
// filterBackend implements filters.Backend to support filtering for logs without
818824
// taking bloom-bits acceleration structures into account.
819825
type filterBackend struct {
820-
db ethdb.Database
821-
bc *core.BlockChain
826+
db ethdb.Database
827+
bc *core.BlockChain
828+
backend *SimulatedBackend
822829
}
823830

824831
func (fb *filterBackend) ChainDb() ethdb.Database { return fb.db }
@@ -835,6 +842,10 @@ func (fb *filterBackend) HeaderByHash(ctx context.Context, hash common.Hash) (*t
835842
return fb.bc.GetHeaderByHash(hash), nil
836843
}
837844

845+
func (fb *filterBackend) PendingBlockAndReceipts() (*types.Block, types.Receipts) {
846+
return fb.backend.pendingBlock, fb.backend.pendingReceipts
847+
}
848+
838849
func (fb *filterBackend) GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) {
839850
number := rawdb.ReadHeaderNumber(fb.db, hash)
840851
if number == nil {

accounts/abi/bind/backends/simulated_test.go

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,8 +655,7 @@ func TestHeaderByNumber(t *testing.T) {
655655
}
656656
if latestBlockHeader == nil {
657657
t.Errorf("received a nil block header")
658-
}
659-
if latestBlockHeader.Number.Uint64() != uint64(0) {
658+
} else if latestBlockHeader.Number.Uint64() != uint64(0) {
660659
t.Errorf("expected block header number 0, instead got %v", latestBlockHeader.Number.Uint64())
661660
}
662661

@@ -1336,3 +1335,42 @@ func TestForkResendTx(t *testing.T) {
13361335
t.Errorf("TX included in wrong block: %d", h)
13371336
}
13381337
}
1338+
1339+
func TestCommitReturnValue(t *testing.T) {
1340+
testAddr := crypto.PubkeyToAddress(testKey.PublicKey)
1341+
sim := simTestBackend(testAddr)
1342+
defer sim.Close()
1343+
1344+
startBlockHeight := sim.blockchain.CurrentBlock().NumberU64()
1345+
1346+
// Test if Commit returns the correct block hash
1347+
h1 := sim.Commit()
1348+
if h1 != sim.blockchain.CurrentBlock().Hash() {
1349+
t.Error("Commit did not return the hash of the last block.")
1350+
}
1351+
1352+
// Create a block in the original chain (containing a transaction to force different block hashes)
1353+
head, _ := sim.HeaderByNumber(context.Background(), nil) // Should be child's, good enough
1354+
gasPrice := new(big.Int).Add(head.BaseFee, big.NewInt(1))
1355+
_tx := types.NewTransaction(0, testAddr, big.NewInt(1000), params.TxGas, gasPrice, nil)
1356+
tx, _ := types.SignTx(_tx, types.HomesteadSigner{}, testKey)
1357+
sim.SendTransaction(context.Background(), tx)
1358+
h2 := sim.Commit()
1359+
1360+
// Create another block in the original chain
1361+
sim.Commit()
1362+
1363+
// Fork at the first bock
1364+
if err := sim.Fork(context.Background(), h1); err != nil {
1365+
t.Errorf("forking: %v", err)
1366+
}
1367+
1368+
// Test if Commit returns the correct block hash after the reorg
1369+
h2fork := sim.Commit()
1370+
if h2 == h2fork {
1371+
t.Error("The block in the fork and the original block are the same block!")
1372+
}
1373+
if sim.blockchain.GetHeader(h2fork, startBlockHeight+2) == nil {
1374+
t.Error("Could not retrieve the just created block (side-chain)")
1375+
}
1376+
}

accounts/abi/bind/base_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ func (mc *mockPendingCaller) PendingCallContract(ctx context.Context, call ether
115115
}
116116

117117
func TestPassingBlockNumber(t *testing.T) {
118-
119118
mc := &mockPendingCaller{
120119
mockCaller: &mockCaller{
121120
codeAtBytes: []byte{1, 2, 3},

0 commit comments

Comments
 (0)