Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade geth to 1.13 #2416

Merged
merged 27 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion agents/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/brianvoe/gofakeit/v6 v6.27.0
github.com/coinbase/rosetta-sdk-go v0.8.1
github.com/davecgh/go-spew v1.1.1
github.com/ethereum/go-ethereum v1.11.6
github.com/ethereum/go-ethereum v1.13.0
github.com/hedzr/log v1.6.3
github.com/imkira/go-interpol v1.1.0
github.com/ipfs/go-log v1.0.5
Expand Down
4 changes: 2 additions & 2 deletions agents/testutil/simulated_backends_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,12 +417,12 @@ func (a *SimulatedBackendsTestSuite) SetupBackends() {
defer wg.Done()
if useAnvil {
anvilOptsOrigin := anvil.NewAnvilOptionBuilder()
anvilOptsOrigin.SetChainID(uint64(params.RinkebyChainConfig.ChainID.Int64()))
anvilOptsOrigin.SetChainID(uint64(params.SepoliaChainConfig.ChainID.Int64()))
anvilOptsOrigin.SetBlockTime(1 * time.Second)
a.TestBackendOrigin = anvil.NewAnvilBackend(a.GetTestContext(), a.T(), anvilOptsOrigin)
a.TestSuite.DeferAfterTest(a.TestBackendOrigin.(*anvil.Backend).TearDown)
} else {
a.TestBackendOrigin = preset.GetRinkeby().Geth(a.GetTestContext(), a.T())
a.TestBackendOrigin = preset.GetSepolia().Geth(a.GetTestContext(), a.T())
}
}()
go func() {
Expand Down
2 changes: 1 addition & 1 deletion committee/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
github.com/Flaque/filet v0.0.0-20201012163910-45f684403088
github.com/brianvoe/gofakeit/v6 v6.27.0
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0
github.com/ethereum/go-ethereum v1.11.6
github.com/ethereum/go-ethereum v1.13.0
github.com/hsanjuan/ipfs-lite v1.8.2
github.com/ipfs/go-datastore v0.6.0
github.com/ipfs/go-ds-crdt v0.5.2
Expand Down
2 changes: 1 addition & 1 deletion contrib/git-changes-action/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/Flaque/filet v0.0.0-20201012163910-45f684403088
github.com/avast/retry-go v3.0.0+incompatible
github.com/brianvoe/gofakeit/v6 v6.27.0
github.com/ethereum/go-ethereum v1.11.6
github.com/ethereum/go-ethereum v1.13.0
github.com/go-git/go-git/v5 v5.11.0
github.com/google/go-github/v41 v41.0.0
github.com/kendru/darwin/go/depgraph v0.0.0-20221105232959-877d6a81060c
Expand Down
2 changes: 1 addition & 1 deletion contrib/promexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/Flaque/filet v0.0.0-20201012163910-45f684403088
github.com/Yamashou/gqlgenc v0.10.0
github.com/creasty/defaults v1.7.0
github.com/ethereum/go-ethereum v1.11.6
github.com/ethereum/go-ethereum v1.13.0
github.com/gin-gonic/gin v1.9.1
github.com/integralist/go-findroot v0.0.0-20160518114804-ac90681525dc
github.com/ipfs/go-log v1.0.5
Expand Down
2 changes: 1 addition & 1 deletion contrib/screener-api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ require (
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/ethereum/go-ethereum v1.11.6 // indirect
github.com/ethereum/go-ethereum v1.13.0 // indirect
github.com/fatih/structtag v1.2.0 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
Expand Down
2 changes: 1 addition & 1 deletion core/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/c-bata/go-prompt v0.2.6
github.com/cheekybits/genny v1.0.0
github.com/danielkov/gin-helmet v0.0.0-20171108135313-1387e224435e
github.com/ethereum/go-ethereum v1.11.6
github.com/ethereum/go-ethereum v1.13.0
github.com/fatih/structtag v1.2.0
github.com/gin-contrib/cors v1.4.0
github.com/gin-contrib/requestid v0.0.6
Expand Down
12 changes: 7 additions & 5 deletions ethergo/backends/anvil/anvil.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import (
"context"
"errors"
"fmt"
"github.com/ipfs/go-log"
"github.com/lmittmann/w3/w3types"
"github.com/ory/dockertest/v3"
"math"
"math/big"
"strings"
"sync"
"testing"

"github.com/ipfs/go-log"
"github.com/lmittmann/w3/w3types"
"github.com/ory/dockertest/v3"

"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/keystore"
Expand Down Expand Up @@ -286,10 +287,11 @@ func (f *Backend) ChainConfig() *params.ChainConfig {

// Signer gets the signer for the chain.
func (f *Backend) Signer() types.Signer {
latestBlock, err := f.BlockNumber(f.Context())
// Get latest block by nil
latestBlock, err := f.BlockByNumber(f.Context(), nil)
require.Nil(f.T(), err)

return types.MakeSigner(f.ChainConfig(), new(big.Int).SetUint64(latestBlock))
return types.MakeSigner(f.ChainConfig(), latestBlock.Number(), latestBlock.Time())
}

// FundAccount funds an account with the given amount.
Expand Down
7 changes: 4 additions & 3 deletions ethergo/backends/geth/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package geth

import (
"math/big"
"testing"

"github.com/Flaque/filet"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
Expand All @@ -9,8 +12,6 @@ import (
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/params"
"github.com/phayes/freeport"
"math/big"
"testing"
)

// makeNodeConfig makes the config for a full backend.
Expand Down Expand Up @@ -45,7 +46,7 @@ func makeNodeConfig(tb testing.TB) *node.Config {
func makeEthConfig(address common.Address, config *params.ChainConfig) *ethconfig.Config {
ethConfig := ethconfig.Defaults
ethConfig.NetworkId = config.ChainID.Uint64()
ethConfig.Genesis = core.DeveloperGenesisBlock(0, 10000000, address)
ethConfig.Genesis = core.DeveloperGenesisBlock(10000000, address)
ethConfig.Genesis.Config = config
ethConfig.Miner.Etherbase = address
ethConfig.SyncMode = downloader.FullSync
Expand Down
14 changes: 7 additions & 7 deletions ethergo/backends/geth/geth.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const gasLimit = 10000000
func NewEmbeddedBackendForChainID(ctx context.Context, t *testing.T, chainID *big.Int) *Backend {
t.Helper()
// get the default config
config := ethCore.DeveloperGenesisBlock(0, gasLimit, common.Address{}).Config
config := ethCore.DeveloperGenesisBlock(gasLimit, common.Address{}).Config
config.ChainID = chainID
return NewEmbeddedBackendWithConfig(ctx, t, config)
}
Expand Down Expand Up @@ -118,8 +118,8 @@ func NewEmbeddedBackendWithConfig(ctx context.Context, t *testing.T, config *par
embedded.ethBackend.AccountManager().AddBackend(keystoreBackend)
embedded.ethBackend.SetEtherbase(acct.Address)

embedded.ethBackend.TxPool().SetGasPrice(big.NewInt(0))
err = embedded.ethBackend.APIBackend.StartMining(0)
embedded.ethBackend.TxPool().SetGasTip(big.NewInt(0))
err = embedded.ethBackend.APIBackend.StartMining()
assert.Nil(t, err)

// add debugger for node stop
Expand All @@ -139,7 +139,7 @@ func NewEmbeddedBackendWithConfig(ctx context.Context, t *testing.T, config *par
if embedded.ethBackend.IsMining() {
cancelMiningCtx()
} else {
_ = embedded.ethBackend.APIBackend.StartMining(0)
_ = embedded.ethBackend.APIBackend.StartMining()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handle potential failure from StartMining in the retry logic.

- _ = embedded.ethBackend.APIBackend.StartMining()
+ if err := embedded.ethBackend.APIBackend.StartMining(); err != nil {
+     logger.Error("Failed to start mining: ", err)
+     return
+ }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
_ = embedded.ethBackend.APIBackend.StartMining()
if err := embedded.ethBackend.APIBackend.StartMining(); err != nil {
logger.Error("Failed to start mining: ", err)
return
}

}
}, time.Millisecond*50)

Expand Down Expand Up @@ -182,7 +182,7 @@ func (f *Backend) Signer() types.Signer {
latestBlock, err := f.BlockByNumber(f.Context(), nil)
assert.Nil(f.T(), err)

return types.MakeSigner(f.ChainConfig(), latestBlock.Number())
return types.MakeSigner(f.ChainConfig(), latestBlock.Number(), latestBlock.Time())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure the latest block is successfully retrieved before using it.

- latestBlock, err := f.BlockByNumber(f.Context(), nil)
- return types.MakeSigner(f.ChainConfig(), latestBlock.Number(), latestBlock.Time())
+ latestBlock, err := f.BlockByNumber(f.Context(), nil)
+ if err != nil {
+     f.T().Error("Failed to retrieve latest block: ", err)
+     return nil
+ }
+ return types.MakeSigner(f.ChainConfig(), latestBlock.Number(), latestBlock.Time())
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
return types.MakeSigner(f.ChainConfig(), latestBlock.Number(), latestBlock.Time())
latestBlock, err := f.BlockByNumber(f.Context(), nil)
if err != nil {
f.T().Error("Failed to retrieve latest block: ", err)
return nil
}
return types.MakeSigner(f.ChainConfig(), latestBlock.Number(), latestBlock.Time())

}

// GethBackendName is the name of the geth backend.
Expand Down Expand Up @@ -220,7 +220,7 @@ func (f *Backend) GetTxContext(ctx context.Context, address *common.Address) (re
err = f.Chain.GasSetter().SetGasFee(ctx, auth, latestBlock.NumberU64(), core.CopyBigInt(gasprice.DefaultMaxPrice))
assert.Nil(f.T(), err)

auth.GasLimit = ethCore.DeveloperGenesisBlock(0, gasLimit, f.faucetAddr.Address).GasLimit / 2
auth.GasLimit = ethCore.DeveloperGenesisBlock(gasLimit, f.faucetAddr.Address).GasLimit / 2

return backends.AuthType{
TransactOpts: auth,
Expand Down Expand Up @@ -282,7 +282,7 @@ func (f *Backend) getFaucetTxContext(ctx context.Context) *bind.TransactOpts {
auth.GasPrice, err = f.Client().SuggestGasPrice(ctx)
assert.Nil(f.T(), err)

auth.GasLimit = ethCore.DeveloperGenesisBlock(0, gasLimit, f.faucetAddr.Address).GasLimit / 2
auth.GasLimit = ethCore.DeveloperGenesisBlock(gasLimit, f.faucetAddr.Address).GasLimit / 2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate logic for setting GasLimit. Consider refactoring to avoid code duplication.

- auth.GasLimit = ethCore.DeveloperGenesisBlock(gasLimit, f.faucetAddr.Address).GasLimit / 2
+ auth.GasLimit = calculateOptimalGasLimit(gasLimit, f.faucetAddr.Address)

And define a new function calculateOptimalGasLimit that encapsulates the logic for determining the gas limit.

Committable suggestion was skipped due to low confidence.


return auth
}
Expand Down
12 changes: 6 additions & 6 deletions ethergo/backends/preset/presets.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (
"github.com/synapsecns/sanguine/ethergo/chain/client"
)

// GetRinkeby gets the rinkeby preset backend.
func GetRinkeby() Backend {
// GetSepolia gets the rinkeby preset backend.
func GetSepolia() Backend {
chainConfig := *params.AllCliqueProtocolChanges
chainConfig.ChainID = params.RinkebyChainConfig.ChainID
chainConfig.ChainID = params.SepoliaChainConfig.ChainID

return Backend{
config: &chainConfig,
rpcURL: core.GetEnv("RINEKBY_RPC_URL", "ws://0.0.0.0:8045"),
name: "Rinkeby",
rpcURL: core.GetEnv("SEPOLIA_RPC_URL", "ws://0.0.0.0:8045"),
name: "Sepolia",
privateKey: os.Getenv("EXPORT_KEY"),
}
}
Expand All @@ -42,7 +42,7 @@ func GetMaticMumbai() Backend {
chainConfig := *params.AllCliqueProtocolChanges
chainConfig.ChainID = client.MaticMainnetConfig.ChainID
// london is not activated on bsc
chainConfig.LondonBlock = nil
chainConfig.LondonBlock = big.NewInt(0)

return Backend{
config: &chainConfig,
Expand Down
7 changes: 5 additions & 2 deletions ethergo/backends/simulated/multibackend/chainid.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package multibackend

import (
"math/big"

"github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/eth/filters"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/trie"
util "github.com/synapsecns/sanguine/core"
"math/big"
)

// NewConfigWithChainID creates a new *params.ChainConfig and changes only the chain id
Expand Down Expand Up @@ -46,9 +48,10 @@ func NewConfigWithChainID(chainID *big.Int) *params.ChainConfig {
// NewSimulatedBackendWithConfig creates a new simulated backend with the given chain id.
func NewSimulatedBackendWithConfig(alloc core.GenesisAlloc, gasLimit uint64, config *params.ChainConfig) *SimulatedBackend {
database := rawdb.NewMemoryDatabase()
triedb := trie.NewDatabase(database, nil)

genesis := core.Genesis{Config: config, GasLimit: gasLimit, Alloc: alloc}
genesis.MustCommit(database)
genesis.MustCommit(database, triedb)
blockchain, _ := core.NewBlockChain(database, nil, &genesis, nil, ethash.NewFaker(), vm.Config{}, nil, nil)

backend := &SimulatedBackend{
Expand Down
6 changes: 3 additions & 3 deletions ethergo/backends/simulated/multibackend/simulated_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions ethergo/backends/simulated/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ package simulated
import (
"context"
"errors"
"math/big"
"testing"
"time"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/common"
Expand All @@ -20,9 +24,6 @@ import (
"github.com/synapsecns/sanguine/ethergo/chain/client"
"github.com/synapsecns/sanguine/ethergo/signer/nonce"
"github.com/teivah/onecontext"
"math/big"
"testing"
"time"
)

var logger = log.Logger("simulated-logger")
Expand Down Expand Up @@ -51,7 +52,7 @@ func (s *Backend) Signer() types.Signer {
latestBlock, err := s.BlockByNumber(s.Context(), nil)
assert.Nil(s.T(), err)

return types.MakeSigner(s.chainConfig, latestBlock.Number())
return types.MakeSigner(s.chainConfig, latestBlock.Number(), latestBlock.Time())
}

// T gets the testing object for the backend.
Expand Down
2 changes: 1 addition & 1 deletion ethergo/chain/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func (s *ChainSuite) TestChainWatcher() {

// make sure a chain client can be started form a url.
func (s *ChainSuite) TestNewFromURL() {
rinkeby := preset.GetRinkeby().Geth(s.GetTestContext(), s.T())
rinkeby := preset.GetSepolia().Geth(s.GetTestContext(), s.T())
chnRPC, err := chain.NewFromURL(s.GetTestContext(), rinkeby.RPCAddress())
Nil(s.T(), err)

Expand Down
7 changes: 4 additions & 3 deletions ethergo/chain/client/client_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package client_test

import (
"os"
"time"

"github.com/ethereum/go-ethereum/core/types"
"github.com/lmittmann/w3/module/eth"
"github.com/lmittmann/w3/w3types"
Expand All @@ -10,8 +13,6 @@ import (
"github.com/synapsecns/sanguine/ethergo/chain/client"
"github.com/synapsecns/sanguine/ethergo/mocks"
"go.uber.org/atomic"
"os"
"time"
)

// TestAttemptReconnect tests the rehupping process. You may notice that in the below test, if the first connection
Expand All @@ -22,7 +23,7 @@ func (c *ClientSuite) TestAttemptReconnect() {
if os.Getenv("ATTEMPT_CONNECT_ENABLED") != "" {
c.T().Skip("deprecated")
}
testBackend := preset.GetRinkeby().Geth(c.GetTestContext(), c.T())
testBackend := preset.GetSepolia().Geth(c.GetTestContext(), c.T())

// make sure the client doesn't reset on us during the test
client.SetResetTimeout(time.Hour)
Expand Down
6 changes: 3 additions & 3 deletions ethergo/chain/client/config.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package client

import (
"math/big"

ethCommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/params"
"math/big"
)

// Config contains the configuration needed to connect to the chain.
Expand Down Expand Up @@ -333,8 +334,7 @@ var (

// chainConfigs is a list of chain configs.
var chainConfigs = []*params.ChainConfig{
params.MainnetChainConfig, params.SepoliaChainConfig,
params.RinkebyChainConfig, params.RinkebyChainConfig, params.GoerliChainConfig,
params.MainnetChainConfig, params.SepoliaChainConfig, params.GoerliChainConfig,
params.AllEthashProtocolChanges, BSCChainConfig, ChapelChainConfig, RialtoChainConfig,
SimulatedConfig, MaticMumbaiConfig, MaticMainnetConfig, AvalancheMainnetChainConfig, AvalancheLocalChainConfig,
ArbitrumMainnetConfig, FtmMainnetConfig, HarmonyConfig, BobaConfig, MoonRiverConfig, OptimisticEthereum,
Expand Down
8 changes: 5 additions & 3 deletions ethergo/chain/client/config_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package client_test

import (
"math"
"math/big"
"time"

"github.com/ethereum/go-ethereum/core/types"
. "github.com/stretchr/testify/assert"
"github.com/synapsecns/sanguine/core/testsuite"
"github.com/synapsecns/sanguine/ethergo/chain/client"
"github.com/synapsecns/sanguine/ethergo/mocks"
"gotest.tools/assert"
"math"
"math/big"
)

// TestConfigFromID makes sure configs are properly returned by id.
Expand Down Expand Up @@ -37,7 +39,7 @@ func (c ClientSuite) TestConfig() {
// TestChainSigner is a sanity check that our configs correctly use the signer.
func (c ClientSuite) TestChainSigner() {
for _, config := range client.ChainConfigs {
signer := types.MakeSigner(config, big.NewInt(0).SetUint64(math.MaxUint64))
signer := types.MakeSigner(config, big.NewInt(0).SetUint64(math.MaxUint64), uint64(time.Now().Unix()))
False(c.T(), signer.Equal(types.FrontierSigner{}))
False(c.T(), signer.Equal(types.HomesteadSigner{}))
}
Expand Down
Loading
Loading