Skip to content

Commit 21d73e3

Browse files
Merge branch 'master' into time-based-pruning
2 parents e6d8faa + 06351ac commit 21d73e3

File tree

267 files changed

+5018
-4893
lines changed

Some content is hidden

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

267 files changed

+5018
-4893
lines changed

.golangci.yml

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,16 @@ linters:
2828
- durationcheck
2929
- exportloopref
3030
- gosec
31+
- whitespace
3132

32-
#- structcheck # lots of false positives
33-
#- errcheck #lot of false positives
34-
# - contextcheck
35-
# - errchkjson # lots of false positives
36-
# - errorlint # this check crashes
37-
# - exhaustive # silly check
38-
# - makezero # false positives
39-
# - nilerr # several intentional
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
4041

4142
linters-settings:
4243
gofmt:
@@ -46,9 +47,9 @@ linters-settings:
4647
min-occurrences: 6 # minimum number of occurrences
4748
gosec:
4849
excludes:
49-
- G404 # Use of weak random number generator - lots of FP
50-
- G107 # Potential http request -- those are intentional
51-
- G306 # G306: Expect WriteFile permissions to be 0600 or less
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
5253

5354
issues:
5455
exclude-rules:
@@ -67,5 +68,6 @@ issues:
6768
exclude:
6869
- 'SA1019: event.TypeMux is deprecated: use Feed'
6970
- '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.'
7072
- 'SA1029: should not use built-in type string as key for value'
71-
- 'G306: Expect WriteFile permissions to be 0600 or less'
73+
- 'G306: Expect WriteFile permissions to be 0600 or less'

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,20 @@ func (b *SimulatedBackend) Close() error {
106106

107107
// Commit imports all the pending transactions as a single block and starts a
108108
// fresh new state.
109-
func (b *SimulatedBackend) Commit() {
109+
func (b *SimulatedBackend) Commit() common.Hash {
110110
b.mu.Lock()
111111
defer b.mu.Unlock()
112112

113113
if _, err := b.blockchain.InsertChain([]*types.Block{b.pendingBlock}); err != nil {
114114
panic(err) // This cannot happen unless the simulator is wrong, fail in that case
115115
}
116+
blockHash := b.pendingBlock.Hash()
117+
116118
// Using the last inserted block here makes it possible to build on a side
117119
// chain after a fork.
118120
b.rollback(b.pendingBlock)
121+
122+
return blockHash
119123
}
120124

121125
// Rollback aborts all pending transactions, reverting to the last committed state.

accounts/abi/bind/backends/simulated_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,3 +1335,42 @@ func TestForkResendTx(t *testing.T) {
13351335
t.Errorf("TX included in wrong block: %d", h)
13361336
}
13371337
}
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},

accounts/abi/bind/bind.go

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,43 @@ const (
4343
LangObjC
4444
)
4545

46+
func isKeyWord(arg string) bool {
47+
switch arg {
48+
case "break":
49+
case "case":
50+
case "chan":
51+
case "const":
52+
case "continue":
53+
case "default":
54+
case "defer":
55+
case "else":
56+
case "fallthrough":
57+
case "for":
58+
case "func":
59+
case "go":
60+
case "goto":
61+
case "if":
62+
case "import":
63+
case "interface":
64+
case "iota":
65+
case "map":
66+
case "make":
67+
case "new":
68+
case "package":
69+
case "range":
70+
case "return":
71+
case "select":
72+
case "struct":
73+
case "switch":
74+
case "type":
75+
case "var":
76+
default:
77+
return false
78+
}
79+
80+
return true
81+
}
82+
4683
// Bind generates a Go wrapper around a contract ABI. This wrapper isn't meant
4784
// to be used as is in client code, but rather as an intermediate struct which
4885
// enforces compile time type safety and naming convention opposed to having to
@@ -114,7 +151,7 @@ func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string]
114151
normalized.Inputs = make([]abi.Argument, len(original.Inputs))
115152
copy(normalized.Inputs, original.Inputs)
116153
for j, input := range normalized.Inputs {
117-
if input.Name == "" {
154+
if input.Name == "" || isKeyWord(input.Name) {
118155
normalized.Inputs[j].Name = fmt.Sprintf("arg%d", j)
119156
}
120157
if hasStruct(input.Type) {
@@ -158,7 +195,7 @@ func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string]
158195
normalized.Inputs = make([]abi.Argument, len(original.Inputs))
159196
copy(normalized.Inputs, original.Inputs)
160197
for j, input := range normalized.Inputs {
161-
if input.Name == "" {
198+
if input.Name == "" || isKeyWord(input.Name) {
162199
normalized.Inputs[j].Name = fmt.Sprintf("arg%d", j)
163200
}
164201
// Event is a bit special, we need to define event struct in binding,

accounts/abi/bind/bind_test.go

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1971,7 +1971,7 @@ var bindTests = []struct {
19711971
}
19721972
}
19731973
`,
1974-
bytecode: []string{`0x608060405234801561001057600080fd5b5061042b806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c8063c2bb515f1461003b578063cce7b04814610059575b600080fd5b610043610075565b60405161005091906101af565b60405180910390f35b610073600480360381019061006e91906103ac565b6100b5565b005b61007d6100b8565b604051806040016040528060405180602001604052806000815250815260200160405180602001604052806000815250815250905090565b50565b604051806040016040528060608152602001606081525090565b600081519050919050565b600082825260208201905092915050565b60005b8381101561010c5780820151818401526020810190506100f1565b8381111561011b576000848401525b50505050565b6000601f19601f8301169050919050565b600061013d826100d2565b61014781856100dd565b93506101578185602086016100ee565b61016081610121565b840191505092915050565b600060408301600083015184820360008601526101888282610132565b915050602083015184820360208601526101a28282610132565b9150508091505092915050565b600060208201905081810360008301526101c9818461016b565b905092915050565b6000604051905090565b600080fd5b600080fd5b600080fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b61022282610121565b810181811067ffffffffffffffff82111715610241576102406101ea565b5b80604052505050565b60006102546101d1565b90506102608282610219565b919050565b600080fd5b600080fd5b600080fd5b600067ffffffffffffffff82111561028f5761028e6101ea565b5b61029882610121565b9050602081019050919050565b82818337600083830152505050565b60006102c76102c284610274565b61024a565b9050828152602081018484840111156102e3576102e261026f565b5b6102ee8482856102a5565b509392505050565b600082601f83011261030b5761030a61026a565b5b813561031b8482602086016102b4565b91505092915050565b60006040828403121561033a576103396101e5565b5b610344604061024a565b9050600082013567ffffffffffffffff81111561036457610363610265565b5b610370848285016102f6565b600083015250602082013567ffffffffffffffff81111561039457610393610265565b5b6103a0848285016102f6565b60208301525092915050565b6000602082840312156103c2576103c16101db565b5b600082013567ffffffffffffffff8111156103e0576103df6101e0565b5b6103ec84828501610324565b9150509291505056fea264697066735822122033bca1606af9b6aeba1673f98c52003cec19338539fb44b86690ce82c51483b564736f6c634300080e0033`},
1974+
bytecode: []string{"0x608060405234801561001057600080fd5b5061042b806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c8063c2bb515f1461003b578063cce7b04814610059575b600080fd5b610043610075565b60405161005091906101af565b60405180910390f35b610073600480360381019061006e91906103ac565b6100b5565b005b61007d6100b8565b604051806040016040528060405180602001604052806000815250815260200160405180602001604052806000815250815250905090565b50565b604051806040016040528060608152602001606081525090565b600081519050919050565b600082825260208201905092915050565b60005b8381101561010c5780820151818401526020810190506100f1565b8381111561011b576000848401525b50505050565b6000601f19601f8301169050919050565b600061013d826100d2565b61014781856100dd565b93506101578185602086016100ee565b61016081610121565b840191505092915050565b600060408301600083015184820360008601526101888282610132565b915050602083015184820360208601526101a28282610132565b9150508091505092915050565b600060208201905081810360008301526101c9818461016b565b905092915050565b6000604051905090565b600080fd5b600080fd5b600080fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b61022282610121565b810181811067ffffffffffffffff82111715610241576102406101ea565b5b80604052505050565b60006102546101d1565b90506102608282610219565b919050565b600080fd5b600080fd5b600080fd5b600067ffffffffffffffff82111561028f5761028e6101ea565b5b61029882610121565b9050602081019050919050565b82818337600083830152505050565b60006102c76102c284610274565b61024a565b9050828152602081018484840111156102e3576102e261026f565b5b6102ee8482856102a5565b509392505050565b600082601f83011261030b5761030a61026a565b5b813561031b8482602086016102b4565b91505092915050565b60006040828403121561033a576103396101e5565b5b610344604061024a565b9050600082013567ffffffffffffffff81111561036457610363610265565b5b610370848285016102f6565b600083015250602082013567ffffffffffffffff81111561039457610393610265565b5b6103a0848285016102f6565b60208301525092915050565b6000602082840312156103c2576103c16101db565b5b600082013567ffffffffffffffff8111156103e0576103df6101e0565b5b6103ec84828501610324565b9150509291505056fea264697066735822122033bca1606af9b6aeba1673f98c52003cec19338539fb44b86690ce82c51483b564736f6c634300080e0033"},
19751975
abi: []string{`[ { "anonymous": false, "inputs": [ { "indexed": false, "internalType": "int256", "name": "msg", "type": "int256" }, { "indexed": false, "internalType": "int256", "name": "_msg", "type": "int256" } ], "name": "log", "type": "event" }, { "inputs": [ { "components": [ { "internalType": "bytes", "name": "data", "type": "bytes" }, { "internalType": "bytes", "name": "_data", "type": "bytes" } ], "internalType": "struct oracle.request", "name": "req", "type": "tuple" } ], "name": "addRequest", "outputs": [], "stateMutability": "pure", "type": "function" }, { "inputs": [], "name": "getRequest", "outputs": [ { "components": [ { "internalType": "bytes", "name": "data", "type": "bytes" }, { "internalType": "bytes", "name": "_data", "type": "bytes" } ], "internalType": "struct oracle.request", "name": "", "type": "tuple" } ], "stateMutability": "pure", "type": "function" } ]`},
19761976
imports: `
19771977
"math/big"
@@ -2002,6 +2002,43 @@ var bindTests = []struct {
20022002
}
20032003
`,
20042004
},
2005+
{
2006+
name: "RangeKeyword",
2007+
contract: `
2008+
// SPDX-License-Identifier: GPL-3.0
2009+
pragma solidity >=0.4.22 <0.9.0;
2010+
contract keywordcontract {
2011+
function functionWithKeywordParameter(range uint256) public pure {}
2012+
}
2013+
`,
2014+
bytecode: []string{"0x608060405234801561001057600080fd5b5060dc8061001f6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063527a119f14602d575b600080fd5b60436004803603810190603f9190605b565b6045565b005b50565b6000813590506055816092565b92915050565b600060208284031215606e57606d608d565b5b6000607a848285016048565b91505092915050565b6000819050919050565b600080fd5b6099816083565b811460a357600080fd5b5056fea2646970667358221220d4f4525e2615516394055d369fb17df41c359e5e962734f27fd683ea81fd9db164736f6c63430008070033"},
2015+
abi: []string{`[{"inputs":[{"internalType":"uint256","name":"range","type":"uint256"}],"name":"functionWithKeywordParameter","outputs":[],"stateMutability":"pure","type":"function"}]`},
2016+
imports: `
2017+
"math/big"
2018+
2019+
"github.com/ethereum/go-ethereum/accounts/abi/bind"
2020+
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
2021+
"github.com/ethereum/go-ethereum/core"
2022+
"github.com/ethereum/go-ethereum/crypto"
2023+
"github.com/ethereum/go-ethereum/eth/ethconfig"
2024+
`,
2025+
tester: `
2026+
var (
2027+
key, _ = crypto.GenerateKey()
2028+
user, _ = bind.NewKeyedTransactorWithChainID(key, big.NewInt(1337))
2029+
sim = backends.NewSimulatedBackend(core.GenesisAlloc{user.From: {Balance: big.NewInt(1000000000000000000)}}, ethconfig.Defaults.Miner.GasCeil)
2030+
)
2031+
_, tx, _, err := DeployRangeKeyword(user, sim)
2032+
if err != nil {
2033+
t.Fatalf("error deploying contract: %v", err)
2034+
}
2035+
sim.Commit()
2036+
2037+
if _, err = bind.WaitDeployed(nil, sim, tx); err != nil {
2038+
t.Errorf("error deploying the contract: %v", err)
2039+
}
2040+
`,
2041+
},
20052042
}
20062043

20072044
// Tests that packages generated by the binder can be successfully compiled and

accounts/abi/error_handling.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ func typeCheck(t Type, value reflect.Value) error {
7373
} else {
7474
return nil
7575
}
76-
7776
}
7877

7978
// typeErr returns a formatted type casting error.

accounts/abi/event_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ func TestEventMultiValueWithArrayUnpack(t *testing.T) {
161161
}
162162

163163
func TestEventTupleUnpack(t *testing.T) {
164-
165164
type EventTransfer struct {
166165
Value *big.Int
167166
}

0 commit comments

Comments
 (0)