Skip to content

Commit a18d350

Browse files
authored
upgrade vendored go-ethereum to v1.15.11 (#180)
1 parent 5f0d5c5 commit a18d350

File tree

370 files changed

+80346
-11407
lines changed

Some content is hidden

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

370 files changed

+80346
-11407
lines changed

cmd/ethkit/abigen.go

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,37 @@ import (
77
"strings"
88

99
"github.com/0xsequence/ethkit/ethartifact"
10-
"github.com/0xsequence/ethkit/go-ethereum/accounts/abi/bind"
10+
geth_abigen "github.com/0xsequence/ethkit/go-ethereum/accounts/abi/abigen"
1111
"github.com/spf13/cobra"
1212
)
1313

1414
func init() {
1515
abigen := &abigen{}
1616
cmd := &cobra.Command{
1717
Use: "abigen",
18-
Short: "Generate contract Go client code from an abi or truffle artifacts file",
18+
Short: "Generate contract Go client code from an abi or contract artifact file",
1919
Run: abigen.Run,
2020
}
2121

22-
cmd.Flags().String("artifactsFile", "", "path to truffle contract artifacts file")
23-
cmd.Flags().String("abiFile", "", "path to abi json file")
24-
cmd.Flags().String("lang", "", "target language, supported: [go], default=go")
25-
cmd.Flags().String("pkg", "", "pkg (optional)")
26-
cmd.Flags().String("type", "", "type (optional)")
27-
cmd.Flags().String("outFile", "", "outFile (optional), default=stdout")
28-
cmd.Flags().Bool("includeDeployed", false, "include deployed bytecode on the generated file")
22+
cmd.Flags().String("artifactsFile", "", "path to compiled contract artifact file")
23+
cmd.Flags().String("abiFile", "", "path to abi json file (optional)")
24+
cmd.Flags().String("pkg", "", "go package name")
25+
cmd.Flags().String("type", "", "type name used in generated output")
26+
cmd.Flags().String("outFile", "", "outFile (optional, default=stdout)")
27+
cmd.Flags().Bool("includeDeployedBin", false, "include deployed bytecode in the generated file (default=false)")
28+
cmd.Flags().Bool("v2", false, "use go-ethereum abigen v2 (default=false)")
2929

3030
rootCmd.AddCommand(cmd)
3131
}
3232

3333
type abigen struct {
34-
fArtifactsFile string
35-
fAbiFile string
36-
fPkg string
37-
fType string
38-
fOutFile string
39-
fIncludeDeployed bool
34+
fArtifactsFile string
35+
fAbiFile string
36+
fPkg string
37+
fType string
38+
fOutFile string
39+
fIncludeDeployedBin bool
40+
fUseV2 bool
4041
}
4142

4243
func (c *abigen) Run(cmd *cobra.Command, args []string) {
@@ -45,7 +46,8 @@ func (c *abigen) Run(cmd *cobra.Command, args []string) {
4546
c.fPkg, _ = cmd.Flags().GetString("pkg")
4647
c.fType, _ = cmd.Flags().GetString("type")
4748
c.fOutFile, _ = cmd.Flags().GetString("outFile")
48-
c.fIncludeDeployed, _ = cmd.Flags().GetBool("includeDeployed")
49+
c.fIncludeDeployedBin, _ = cmd.Flags().GetBool("includeDeployedBin")
50+
c.fUseV2, _ = cmd.Flags().GetBool("v2")
4951

5052
if c.fArtifactsFile == "" && c.fAbiFile == "" {
5153
fmt.Println("error: please pass one of --artifactsFile or --abiFile")
@@ -92,11 +94,9 @@ func (c *abigen) generateGo(artifact ethartifact.RawArtifact) error {
9294
var (
9395
abis []string
9496
bins []string
95-
dbins []string
9697
types []string
9798
sigs []map[string]string
9899
libs = make(map[string]string)
99-
lang = bind.LangGo
100100
)
101101

102102
if strings.Contains(string(artifact.Bytecode), "//") {
@@ -122,21 +122,29 @@ func (c *abigen) generateGo(artifact ethartifact.RawArtifact) error {
122122
bins = append(bins, artifact.Bytecode)
123123
aliases := map[string]string{}
124124

125-
if c.fIncludeDeployed {
126-
dbins = append(dbins, artifact.DeployedBytecode)
125+
var code string
126+
var err error
127127

128-
if strings.Contains(string(artifact.DeployedBytecode), "//") {
129-
log.Fatal("Contract has additional library references, which is unsupported at this time.")
130-
}
128+
// NOTE: "bytecode" in an artifact contains both the constructor + the runtime code of the contract,
129+
// the "bytecode" value is what we use to deploy a new contract.
130+
//
131+
// Whereas the "deployedBytecode" is the runtime code of the contract, and can be used to verify
132+
// the contract bytecode once its been deployed. For our purposes of generating a client, we only
133+
// need the constructor code, so we use the "bytecode" value.
134+
135+
if c.fUseV2 {
136+
code, err = geth_abigen.BindV2(types, abis, bins, pkgName, libs, aliases)
131137
} else {
132-
dbins = append(dbins, "")
138+
code, err = geth_abigen.Bind(types, abis, bins, sigs, pkgName, libs, aliases)
133139
}
134-
135-
code, err := bind.Bind(types, abis, bins, dbins, sigs, pkgName, lang, libs, aliases)
136140
if err != nil {
137141
return err
138142
}
139143

144+
if c.fIncludeDeployedBin {
145+
code = fmt.Sprintf("%s\n// %sDeployedBin is the resulting bytecode of the created contract\nconst %sDeployedBin = %q\n", code, typeName, typeName, artifact.DeployedBytecode)
146+
}
147+
140148
if c.fOutFile == "" {
141149
fmt.Println(code)
142150
} else {

cmd/ethkit/block_test.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ package main
22

33
import (
44
"bytes"
5-
"fmt"
65
"strings"
76
"testing"
87

9-
"github.com/0xsequence/ethkit/go-ethereum/common/math"
108
"github.com/stretchr/testify/assert"
119
)
1210

@@ -36,11 +34,11 @@ func Test_BlockCmd_InvalidRpcUrl(t *testing.T) {
3634
}
3735

3836
// Note: this test will eventually fail
39-
func Test_BlockCmd_NotFound(t *testing.T) {
40-
res, err := execBlockCmd(fmt.Sprint(math.MaxInt64) + " --rpc-url https://nodes.sequence.app/mainnet")
41-
assert.Contains(t, err.Error(), "not found")
42-
assert.Empty(t, res)
43-
}
37+
// func Test_BlockCmd_NotFound(t *testing.T) {
38+
// res, err := execBlockCmd(fmt.Sprint(math.MaxInt64) + " --rpc-url https://nodes.sequence.app/mainnet")
39+
// assert.Contains(t, err.Error(), "not found")
40+
// assert.Empty(t, res)
41+
// }
4442

4543
func Test_BlockCmd_InvalidBlockHeight(t *testing.T) {
4644
res, err := execBlockCmd("invalid --rpc-url https://nodes.sequence.app/mainnet")

ethreceipts/ethreceipts.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ type ReceiptsListener struct {
7272
alert util.Alerter
7373
provider ethrpc.Interface
7474
monitor *ethmonitor.Monitor
75+
chainID *big.Int
7576
br *breaker.Breaker
7677

7778
// fetchSem is used to limit amount of concurrenct fetch requests
@@ -156,12 +157,14 @@ func (l *ReceiptsListener) lazyInit(ctx context.Context) error {
156157
l.mu.Lock()
157158
defer l.mu.Unlock()
158159

160+
var err error
161+
l.chainID, err = getChainID(ctx, l.provider)
162+
if err != nil {
163+
l.chainID = big.NewInt(1) // assume mainnet in case of unlikely error
164+
}
165+
159166
if l.options.NumBlocksToFinality <= 0 {
160-
chainID, err := getChainID(ctx, l.provider)
161-
if err != nil {
162-
chainID = big.NewInt(1) // assume mainnet in case of unlikely error
163-
}
164-
network, ok := ethrpc.Networks[chainID.Uint64()]
167+
network, ok := ethrpc.Networks[l.chainID.Uint64()]
165168
if ok {
166169
l.options.NumBlocksToFinality = network.NumBlocksToFinality
167170
} else {
@@ -748,7 +751,10 @@ func (l *ReceiptsListener) processBlocks(blocks ethmonitor.Blocks, subscribers [
748751
logs: txnLog,
749752
transaction: txn,
750753
}
751-
txnMsg, err := ethtxn.AsMessage(txn)
754+
755+
// TODOXXX: avoid using AsMessage as its fairly expensive operation, especially
756+
// to do it for every txn for every filter.
757+
txnMsg, err := ethtxn.AsMessage(txn, l.chainID)
752758
if err != nil {
753759
// NOTE: this should never happen, but lets log in case it does. In the
754760
// future, we should just not use go-ethereum for these types.

ethreceipts/receipt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type Receipt struct {
1515
Reorged bool // chain reorged / removed the txn
1616

1717
transaction *types.Transaction
18-
message *core.Message // TODO: this intermediate type is lame.. with new ethrpc we can remove
18+
message *core.Message // TODOXXX: this intermediate type is lame.. with new ethrpc we can remove
1919
receipt *types.Receipt
2020
logs []*types.Log
2121
}

ethtest/testchain.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,11 @@ func (c *Testchain) Deploy(t *testing.T, contractName string, contractConstructo
293293
wallet := c.GetDeployWallet()
294294
signedTxn, err := wallet.NewTransaction(context.Background(), &ethtxn.TransactionRequest{
295295
Data: data,
296+
297+
// NOTE: below are needed for geth. hardhat and anvil don't need them.
298+
// Recommendation is to use anvil for testing, or hardhat.
299+
GasLimit: 1_000_000,
300+
GasPrice: big.NewInt(1e9), // 1 gwei
296301
})
297302
if err != nil {
298303
t.Fatal(err)

ethtest/testchain/package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@
66
"scripts": {
77
"start:hardhat": "hardhat node --hostname 0.0.0.0",
88
"start:hardhat:verbose": "hardhat --verbose node --hostname 0.0.0.0",
9-
"start:geth": "docker run -p 8545:8545 --log-driver none --rm ethereum/client-go:v1.15.2 --dev --dev.period 2 --networkid ${npm_package_config_testchainChainID} --miner.gaslimit ${npm_package_config_testchainGasLimit} --miner.gasprice 1 --http --http.addr 0.0.0.0 --rpc.allow-unprotected-txs --verbosity 1",
10-
"start:geth:verbose": "docker run -p 8545:8545 --rm ethereum/client-go:v1.15.2 --dev --dev.period 2 --networkid ${npm_package_config_testchainChainID} --miner.gaslimit ${npm_package_config_testchainGasLimit} --miner.gasprice 1 --http --http.addr 0.0.0.0 --rpc.allow-unprotected-txs",
9+
"start:geth": "docker run -p 8545:8545 --rm ethereum/client-go:v1.15.11 --networkid ${npm_package_config_testchainChainID} --dev --dev.period 1 --dev.gaslimit ${npm_package_config_testchainGasLimit} --miner.gaslimit ${npm_package_config_testchainGasLimit} --miner.gasprice 1 --http --http.addr 0.0.0.0 --rpc.allow-unprotected-txs --verbosity 1",
10+
"start:geth:verbose": "docker run -p 8545:8545 --rm ethereum/client-go:v1.15.11 --networkid ${npm_package_config_testchainChainID} --dev --dev.period 1 --dev.gaslimit ${npm_package_config_testchainGasLimit} --miner.gaslimit ${npm_package_config_testchainGasLimit} --miner.gasprice 1 --http --http.addr 0.0.0.0 --rpc.allow-unprotected-txs",
1111
"start:anvil": "anvil --mnemonic \"${npm_package_config_mnemonic}\" --block-time 1 --balance ${npm_package_config_etherBalance} --host 0.0.0.0 --chain-id ${npm_package_config_testchainChainID} --gas-limit ${npm_package_config_testchainGasLimit} --gas-price ${npm_package_config_testchainGasPrice}",
12-
"start:anvil:verbose": "anvil --mnemonic \"${npm_package_config_mnemonic}\" --block-time 1 --balance ${npm_package_config_etherBalance} --host 0.0.0.0 --chain-id ${npm_package_config_testchainChainID} --gas-limit ${npm_package_config_testchainGasLimit} --gas-price ${npm_package_config_testchainGasPrice} --verbose",
12+
"start:anvil:verbose": "anvil --mnemonic \"${npm_package_config_mnemonic}\" --block-time 1 --balance ${npm_package_config_etherBalance} --host 0.0.0.0 --chain-id ${npm_package_config_testchainChainID} --gas-limit ${npm_package_config_testchainGasLimit} --gas-price ${npm_package_config_testchainGasPrice} -vvv",
13+
"install:anvil": "curl -L https://foundry.paradigm.xyz | bash; foundryup",
1314
"wait:server": "wait-on -t 120000 tcp:127.0.0.1:8545"
1415
},
1516
"devDependencies": {
1617
"concurrently": "^9.1.2",
17-
"hardhat": "^2.22.0",
18-
"wait-on": "^8.0.2"
18+
"hardhat": "^2.24.1",
19+
"wait-on": "^8.0.3"
1920
},
2021
"config": {
2122
"mnemonic": "major danger this key only test please avoid main net use okay",

0 commit comments

Comments
 (0)