Skip to content

Commit

Permalink
op-deployer: Most implementation addresses not set in state.json when…
Browse files Browse the repository at this point in the history
… standard release tag used (ethereum-optimism#12434)

* op-deployer: Most implementation addresses not set in state.json when standard release tag used

* Update op-chain-ops/deployer/pipeline/opchain.go

Co-authored-by: Matt Solomon <matt@mattsolomon.dev>

* fix: parallel execution of commands.

* fix: tests added

* fix: vscode revert

* use channel approach

---------

Co-authored-by: Matt Solomon <matt@mattsolomon.dev>
Co-authored-by: Matthew Slipper <me@matthewslipper.com>
  • Loading branch information
3 people authored and samlaf committed Nov 10, 2024
1 parent 8062a3e commit 4bac1d2
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 6 deletions.
10 changes: 10 additions & 0 deletions op-deployer/pkg/deployer/integration_test/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,16 @@ func validateOPChainDeployment(t *testing.T, ctx context.Context, l1Client *ethc
})
}

require.NotEmpty(t, st.ImplementationsDeployment.DelayedWETHImplAddress, "DelayedWETHImplAddress should be set")
require.NotEmpty(t, st.ImplementationsDeployment.OptimismPortalImplAddress, "OptimismPortalImplAddress should be set")
require.NotEmpty(t, st.ImplementationsDeployment.SystemConfigImplAddress, "SystemConfigImplAddress should be set")
require.NotEmpty(t, st.ImplementationsDeployment.L1CrossDomainMessengerImplAddress, "L1CrossDomainMessengerImplAddress should be set")
require.NotEmpty(t, st.ImplementationsDeployment.L1ERC721BridgeImplAddress, "L1ERC721BridgeImplAddress should be set")
require.NotEmpty(t, st.ImplementationsDeployment.L1StandardBridgeImplAddress, "L1StandardBridgeImplAddress should be set")
require.NotEmpty(t, st.ImplementationsDeployment.OptimismMintableERC20FactoryImplAddress, "OptimismMintableERC20FactoryImplAddress should be set")
require.NotEmpty(t, st.ImplementationsDeployment.DisputeGameFactoryImplAddress, "DisputeGameFactoryImplAddress should be set")
// TODO: Need to check that 'mipsSingletonAddress' and 'preimageOracleSingletonAddress' are set

t.Run("l2 genesis", func(t *testing.T) {
require.Greater(t, len(chainState.Allocs), 0)
l2Allocs, _ := chainState.UnmarshalAllocs()
Expand Down
24 changes: 20 additions & 4 deletions op-deployer/pkg/deployer/opcm/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,30 @@ func (c *Contract) ProtocolVersions(ctx context.Context) (common.Address, error)
}

func (c *Contract) getAddress(ctx context.Context, name string) (common.Address, error) {
return c.callContractMethod(ctx, name, abi.Arguments{})
}

// Used to call getAddress(string) on legacy ResolvedDelegateProxy contract
func (c *Contract) GetAddressByName(ctx context.Context, name string) (common.Address, error) {
inputs := abi.Arguments{
abi.Argument{
Name: "_name",
Type: mustType("string"),
Indexed: false,
},
}
return c.callContractMethod(ctx, "getAddress", inputs, name)
}

func (c *Contract) callContractMethod(ctx context.Context, methodName string, inputs abi.Arguments, args ...interface{}) (common.Address, error) {
method := abi.NewMethod(
name,
name,
methodName,
methodName,
abi.Function,
"view",
true,
false,
abi.Arguments{},
inputs,
abi.Arguments{
abi.Argument{
Name: "address",
Expand All @@ -46,7 +62,7 @@ func (c *Contract) getAddress(ctx context.Context, name string) (common.Address,
},
)

calldata, err := method.Inputs.Pack()
calldata, err := method.Inputs.Pack(args...)
if err != nil {
return common.Address{}, fmt.Errorf("failed to pack inputs: %w", err)
}
Expand Down
85 changes: 83 additions & 2 deletions op-deployer/pkg/deployer/pipeline/opchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ package pipeline

import (
"context"
"encoding/hex"
"fmt"
"math/big"

"github.com/ethereum-optimism/optimism/op-chain-ops/genesis"
"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/broadcaster"
"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/opcm"
"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/state"
state2 "github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/state"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
)

func DeployOPChain(ctx context.Context, env *Env, bundle ArtifactsBundle, intent *state2.Intent, st *state2.State, chainID common.Hash) error {
Expand Down Expand Up @@ -91,10 +94,88 @@ func DeployOPChain(ctx context.Context, env *Env, bundle ArtifactsBundle, intent
DelayedWETHPermissionlessGameProxyAddress: dco.DelayedWETHPermissionlessGameProxy,
})

currentBlock, _ := env.L1Client.BlockNumber(ctx)
block, _ := env.L1Client.BlockByNumber(ctx, big.NewInt(int64(currentBlock)))
currentBlockHash := block.Hash()

errCh := make(chan error, 8)

// If any of the implementations addresses (excluding OpcmProxy) are empty,
// we need to set them using the implementation address read from their corresponding proxy.
// The reason these might be empty is because we're only invoking DeployOPChain.s.sol as part of the pipeline.
// TODO: Need to initialize 'mipsSingletonAddress' and 'preimageOracleSingletonAddress'
setImplementationAddressTasks := []func(){
func() {
setEIP1967ImplementationAddress(ctx, env.L1Client, errCh, dco.DelayedWETHPermissionedGameProxy, currentBlockHash, &st.ImplementationsDeployment.DelayedWETHImplAddress)
},
func() {
setEIP1967ImplementationAddress(ctx, env.L1Client, errCh, dco.OptimismPortalProxy, currentBlockHash, &st.ImplementationsDeployment.OptimismPortalImplAddress)
},
func() {
setEIP1967ImplementationAddress(ctx, env.L1Client, errCh, dco.SystemConfigProxy, currentBlockHash, &st.ImplementationsDeployment.SystemConfigImplAddress)
},
func() {
setRDPImplementationAddress(ctx, env.L1Client, errCh, dco.AddressManager, &st.ImplementationsDeployment.L1CrossDomainMessengerImplAddress)
},
func() {
setEIP1967ImplementationAddress(ctx, env.L1Client, errCh, dco.L1ERC721BridgeProxy, currentBlockHash, &st.ImplementationsDeployment.L1ERC721BridgeImplAddress)
},
func() {
setEIP1967ImplementationAddress(ctx, env.L1Client, errCh, dco.L1StandardBridgeProxy, currentBlockHash, &st.ImplementationsDeployment.L1StandardBridgeImplAddress)
},
func() {
setEIP1967ImplementationAddress(ctx, env.L1Client, errCh, dco.OptimismMintableERC20FactoryProxy, currentBlockHash, &st.ImplementationsDeployment.OptimismMintableERC20FactoryImplAddress)
},
func() {
setEIP1967ImplementationAddress(ctx, env.L1Client, errCh, dco.DisputeGameFactoryProxy, currentBlockHash, &st.ImplementationsDeployment.DisputeGameFactoryImplAddress)
},
}
for _, task := range setImplementationAddressTasks {
go task()
}

var lastTaskErr error
for i := 0; i < len(setImplementationAddressTasks); i++ {
taskErr := <-errCh
if lastTaskErr != nil {
lastTaskErr = taskErr
}
}
if lastTaskErr != nil {
return fmt.Errorf("failed to set implementation addresses: %w", lastTaskErr)
}

return nil
}

func shouldDeployOPChain(intent *state2.Intent, st *state2.State, chainID common.Hash) bool {
func setRDPImplementationAddress(ctx context.Context, client *ethclient.Client, errCh chan error, addressManager common.Address, implAddress *common.Address) {
if *implAddress != (common.Address{}) {
errCh <- nil
return
}

contract := opcm.NewContract(addressManager, client)
address, err := contract.GetAddressByName(ctx, "OVM_L1CrossDomainMessenger")
if err == nil {
*implAddress = address
}
errCh <- err
}

func setEIP1967ImplementationAddress(ctx context.Context, client *ethclient.Client, errCh chan error, proxy common.Address, currentBlockHash common.Hash, implAddress *common.Address) {
if *implAddress != (common.Address{}) {
errCh <- nil
return
}

storageValue, err := client.StorageAtHash(ctx, proxy, genesis.ImplementationSlot, currentBlockHash)
if err == nil {
*implAddress = common.HexToAddress(hex.EncodeToString(storageValue))
}
errCh <- err
}

func shouldDeployOPChain(intent *state.Intent, st *state.State, chainID common.Hash) bool {
for _, chain := range st.Chains {
if chain.ID == chainID {
return false
Expand Down

0 comments on commit 4bac1d2

Please sign in to comment.