Skip to content

Commit

Permalink
resource usage cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
roberto-bayardo committed Mar 22, 2024
1 parent 36325bf commit 48de350
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 28 deletions.
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,9 @@ require (
rsc.io/tmplfunc v0.0.3 // indirect
)

replace github.com/ethereum/go-ethereum v1.13.9 => github.com/roberto-bayardo/op-geth v0.0.0-20240321212348-438dd5ed418e
replace github.com/ethereum/go-ethereum v1.13.9 => github.com/roberto-bayardo/op-geth v0.0.0-20240322182619-a9d8432e3ecb

//replace github.com/ethereum/go-ethereum v1.13.9 => ../op-geth

// replace github.com/ethereum-optimism/superchain-registry/superchain => ../superchain-registry/superchain

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -679,8 +679,8 @@ github.com/raulk/go-watchdog v1.3.0/go.mod h1:fIvOnLbF0b0ZwkB9YU4mOW9Did//4vPZtD
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.3 h1:utMvzDsuh3suAEnhH0RdHmoPbU648o6CvXxTx4SBMOw=
github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/roberto-bayardo/op-geth v0.0.0-20240321212348-438dd5ed418e h1:DJb7sxdfBGUJbXZ8pTfqTfALvIbSp2yypsRfIHUS9g4=
github.com/roberto-bayardo/op-geth v0.0.0-20240321212348-438dd5ed418e/go.mod h1:k0UbrLuOITLD8goCyA2xWebAL03n2BZUCfwos0rxz60=
github.com/roberto-bayardo/op-geth v0.0.0-20240322182619-a9d8432e3ecb h1:60DzuEzOMfKmUeg2paCELBUb2Hhb/ZlgUcealH/av4Y=
github.com/roberto-bayardo/op-geth v0.0.0-20240322182619-a9d8432e3ecb/go.mod h1:k0UbrLuOITLD8goCyA2xWebAL03n2BZUCfwos0rxz60=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
Expand Down
33 changes: 19 additions & 14 deletions op-chain-ops/deployer/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"math/big"
"time"

"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
Expand Down Expand Up @@ -46,23 +47,16 @@ type Deployment struct {

type Deployer func(*backends.SimulatedBackend, *bind.TransactOpts, Constructor) (*types.Transaction, error)

// NewL1Backend returns a SimulatedBackend suitable for L1. It has
// the latest L1 hardforks enabled.
func NewL1Backend() (*backends.SimulatedBackend, error) {
backend, err := NewBackendWithGenesisTimestamp(ChainID, 0, nil)
return backend, err
}

// NewL2Backend returns a SimulatedBackend suitable for L2.
// NewBackend returns a SimulatedBackend suitable for L2.
// It has the latest L2 hardforks enabled.
func NewL2Backend() (*backends.SimulatedBackend, error) {
func NewBackend() (*backends.SimulatedBackend, error) {
backend, err := NewBackendWithGenesisTimestamp(ChainID, 0, nil)
return backend, err
}

// NewL2BackendWithChainIDAndPredeploys returns a SimulatedBackend suitable for L2.
// NewBackendWithChainIDAndPredeploys returns a SimulatedBackend suitable for L2.
// It has the latest L2 hardforks enabled, and allows for the configuration of the network's chain ID and predeploys.
func NewL2BackendWithChainIDAndPredeploys(chainID *big.Int, predeploys map[string]*common.Address) (*backends.SimulatedBackend, error) {
func NewBackendWithChainIDAndPredeploys(chainID *big.Int, predeploys map[string]*common.Address) (*backends.SimulatedBackend, error) {
backend, err := NewBackendWithGenesisTimestamp(chainID, 0, predeploys)
return backend, err
}
Expand All @@ -86,6 +80,7 @@ func NewBackendWithGenesisTimestamp(chainID *big.Int, ts uint64, predeploys map[
cfg := ethconfig.Defaults
cfg.Preimages = true
config := params.AllDevChainProtocolChanges
config.MergeNetsplitBlock = big.NewInt(0)
config.Ethash = new(params.EthashConfig)
cfg.Genesis = &core.Genesis{
Config: config,
Expand Down Expand Up @@ -117,7 +112,11 @@ func Deploy(backend *backends.SimulatedBackend, constructors []Constructor, cb D
// The simulator performs asynchronous processing,
// so we need to both commit the change here as
// well as wait for the transaction receipt.

// give transaction time to hit mempool otherwise we might commit an empty block
time.Sleep(100 * time.Millisecond)
backend.Commit()

addr, err := bind.WaitDeployed(ctx, backend, tx)
if err != nil {
return nil, fmt.Errorf("%s: %w", deployment.Name, err)
Expand Down Expand Up @@ -147,7 +146,7 @@ func Deploy(backend *backends.SimulatedBackend, constructors []Constructor, cb D
//
// Parameters:
// - backend: A pointer to backends.SimulatedBackend, representing the simulated Ethereum blockchain.
// Expected to have Arachnid's proxy deployer predeploys at 0x4e59b44847b379578588920cA78FbF26c0B4956C, NewL2BackendWithChainIDAndPredeploys handles this for you.
// Expected to have Arachnid's proxy deployer predeploys at 0x4e59b44847b379578588920cA78FbF26c0B4956C, NewBackendWithChainIDAndPredeploys handles this for you.
// - contractName: A string representing the name of the contract to be deployed.
//
// Returns:
Expand All @@ -163,7 +162,7 @@ func DeployWithDeterministicDeployer(backend *backends.SimulatedBackend, contrac
}
opts, err := bind.NewKeyedTransactorWithChainID(TestKey, cid)
if err != nil {
return nil, err
return nil, fmt.Errorf("NewKeyedTransactorWithChainID failed: %w", err)
}

deployerAddress, err := bindings.GetDeployerAddress(contractName)
Expand All @@ -186,11 +185,17 @@ func DeployWithDeterministicDeployer(backend *backends.SimulatedBackend, contrac
return nil, fmt.Errorf("failed to initialize deployment proxy transactor at %s: %w", deployerAddress, err)
}

// give contract code time to become pending otherwise we risk it not being found.
time.Sleep(100 * time.Millisecond)

tx, err := transactor.Fallback(opts, append(deploymentSalt, initBytecode...))
if err != nil {
return nil, err
return nil, fmt.Errorf("Fallback failed: %w", err)
}

// give transaction time to hit mempool otherwise we might commit an empty block
time.Sleep(100 * time.Millisecond)

backend.Commit()

receipt, err := bind.WaitMined(context.Background(), backend, tx)
Expand Down
11 changes: 6 additions & 5 deletions op-chain-ops/genesis/layer_two.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func BuildL2Genesis(config *DeployConfig, l1StartBlock *types.Block) (*core.Gene
// Set up the implementations that contain immutables
deployResults, err := immutables.Deploy(immutableConfig)
if err != nil {
return nil, err
return nil, fmt.Errorf("immutables.Deploy failed: %w", err)
}
for name, predeploy := range predeploys.Predeploys {
if predeploy.Enabled != nil && !predeploy.Enabled(config) {
Expand All @@ -72,17 +72,18 @@ func BuildL2Genesis(config *DeployConfig, l1StartBlock *types.Block) (*core.Gene
predeploys := map[string]*common.Address{
"DeterministicDeploymentProxy": &deployerAddress,
}
backend, err := deployer.NewL2BackendWithChainIDAndPredeploys(
backend, err := deployer.NewBackendWithChainIDAndPredeploys(
new(big.Int).SetUint64(config.L2ChainID),
predeploys,
)
if err != nil {
return nil, err
return nil, fmt.Errorf("NewBAckendWithChainIDAndPredeploys failed: %w", err)
}
deployedBin, err := deployer.DeployWithDeterministicDeployer(backend, name)
if err != nil {
return nil, err
return nil, fmt.Errorf("DeployWithDeterministicDeployer failed: %w", err)
}
backend.Close()
deployResults[name] = deployedBin
fallthrough
case "MultiCall3", "Create2Deployer", "Safe_v130",
Expand All @@ -106,7 +107,7 @@ func BuildL2Genesis(config *DeployConfig, l1StartBlock *types.Block) (*core.Gene
}

if err := setupPredeploy(db, deployResults, storage, name, predeploy.Address, codeAddr); err != nil {
return nil, err
return nil, fmt.Errorf("setupPredeploy failed: %w", err)
}
code := db.GetCode(codeAddr)
if len(code) == 0 {
Expand Down
3 changes: 2 additions & 1 deletion op-chain-ops/genesis/setters.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package genesis

import (
"errors"
"fmt"
"math/big"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -73,7 +74,7 @@ func setupPredeploy(db vm.StateDB, deployResults immutables.DeploymentResults, s
} else {
depBytecode, err := bindings.GetDeployedBytecode(name)
if err != nil {
return err
return fmt.Errorf("GetDeployedBytecode failed: %w", err)
}
log.Info("Setting deployed bytecode from solc compiler output", "name", name, "address", implAddr)
db.SetCode(implAddr, depBytecode)
Expand Down
3 changes: 2 additions & 1 deletion op-chain-ops/immutables/immutables.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,11 @@ func Deploy(config *PredeploysImmutableConfig) (DeploymentResults, error) {
// can be properly set. The bytecode returned in the results is suitable to be
// inserted into the state via state surgery.
func deployContractsWithImmutables(constructors []deployer.Constructor) (DeploymentResults, error) {
backend, err := deployer.NewL2Backend()
backend, err := deployer.NewBackend()
if err != nil {
return nil, err
}
defer backend.Close()
deployments, err := deployer.Deploy(backend, constructors, l2ImmutableDeployer)
if err != nil {
return nil, err
Expand Down
1 change: 0 additions & 1 deletion op-e2e/actions/l2_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ func newBackend(t e2eutils.TestingBase, genesis *core.Genesis, jwtPath string, o
backend, err := geth.New(n, ethCfg)
require.NoError(t, err)
n.RegisterAPIs(tracers.APIs(backend.APIBackend))

chain := backend.BlockChain()
db := backend.ChainDb()
apiBackend := &engineApiBackend{
Expand Down
2 changes: 1 addition & 1 deletion op-ufm/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,6 @@ require (
rsc.io/tmplfunc v0.0.3 // indirect
)

replace github.com/ethereum/go-ethereum v1.13.9 => github.com/roberto-bayardo/op-geth v0.0.0-20240321212348-438dd5ed418e
replace github.com/ethereum/go-ethereum v1.13.9 => github.com/roberto-bayardo/op-geth v0.0.0-20240322182619-a9d8432e3ecb

replace github.com/ethereum-optimism/optimism => ../.
4 changes: 2 additions & 2 deletions op-ufm/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3c
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.3 h1:utMvzDsuh3suAEnhH0RdHmoPbU648o6CvXxTx4SBMOw=
github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/roberto-bayardo/op-geth v0.0.0-20240321212348-438dd5ed418e h1:DJb7sxdfBGUJbXZ8pTfqTfALvIbSp2yypsRfIHUS9g4=
github.com/roberto-bayardo/op-geth v0.0.0-20240321212348-438dd5ed418e/go.mod h1:k0UbrLuOITLD8goCyA2xWebAL03n2BZUCfwos0rxz60=
github.com/roberto-bayardo/op-geth v0.0.0-20240322182619-a9d8432e3ecb h1:60DzuEzOMfKmUeg2paCELBUb2Hhb/ZlgUcealH/av4Y=
github.com/roberto-bayardo/op-geth v0.0.0-20240322182619-a9d8432e3ecb/go.mod h1:k0UbrLuOITLD8goCyA2xWebAL03n2BZUCfwos0rxz60=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
Expand Down

0 comments on commit 48de350

Please sign in to comment.