diff --git a/contracts/config/networks.json b/contracts/config/networks.json index 889a53d724..6b63a7eade 100644 --- a/contracts/config/networks.json +++ b/contracts/config/networks.json @@ -2,9 +2,7 @@ "localGeth": { "url": "http://127.0.0.1:17000", "deploy": [ - "deployment_scripts/core/layer1/", - "deployment_scripts/testnet/layer1/", - "deployment_scripts/bridge/layer1/" + "deployment_scripts/core" ], "accounts": [ "f52e5418e349dccdda29b6ac8b0abe6576bb7713886aa85abea6181ba731f9bb", @@ -19,6 +17,7 @@ "layer1" : "localGeth" }, "deploy": [ + "deployment_scripts/funding/layer1", "deployment_scripts/messenger/layer1", "deployment_scripts/messenger/layer2", "deployment_scripts/bridge/", diff --git a/contracts/deployment_scripts/bridge/001_deploy_bridge.ts b/contracts/deployment_scripts/bridge/001_deploy_bridge.ts index 4445679da3..056bc2a6e4 100644 --- a/contracts/deployment_scripts/bridge/001_deploy_bridge.ts +++ b/contracts/deployment_scripts/bridge/001_deploy_bridge.ts @@ -12,7 +12,12 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { deployments, getNamedAccounts } = hre; - const mgmtContractAddress = process.env.MGMT_CONTRACT_ADDRESS!! + var mgmtContractAddress = process.env.MGMT_CONTRACT_ADDRESS!! + if (mgmtContractAddress === undefined) { + const networkConfig : any = await hre.network.provider.request({method: 'net_config'}); + mgmtContractAddress = networkConfig.ManagementContractAddress; + console.log(`Fallback read of management contract address = ${mgmtContractAddress}`); + } // L2 address of a prefunded deployer account to be used in smart contracts const accountsL2 = await getNamedAccounts(); diff --git a/contracts/deployment_scripts/funding/layer1/001_fund_accounts.ts b/contracts/deployment_scripts/funding/layer1/001_fund_accounts.ts index 7d6429b620..2b329e10f9 100644 --- a/contracts/deployment_scripts/funding/layer1/001_fund_accounts.ts +++ b/contracts/deployment_scripts/funding/layer1/001_fund_accounts.ts @@ -8,7 +8,12 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { const {deployer} = await hre.getNamedAccounts(); const l1Accs = await layer1.getNamedAccounts(); - const messageBusAddress = process.env.MESSAGE_BUS_ADDRESS!! + var messageBusAddress = process.env.MESSAGE_BUS_ADDRESS!! + if (messageBusAddress === undefined) { + const networkConfig : any = await hre.network.provider.request({method: 'net_config'}); + messageBusAddress = networkConfig.MessageBusAddress; + console.log(`Fallback read of message bus address = ${messageBusAddress}`); + } const messageBus = (await hre.ethers.getContractFactory('MessageBus')).attach(messageBusAddress) const prefundAmount = hre.ethers.parseEther("0.5"); diff --git a/contracts/deployment_scripts/funding/layer1/002_fund_faucet.ts b/contracts/deployment_scripts/funding/layer1/002_fund_faucet.ts index ec4eedab98..3e274e62d6 100644 --- a/contracts/deployment_scripts/funding/layer1/002_fund_faucet.ts +++ b/contracts/deployment_scripts/funding/layer1/002_fund_faucet.ts @@ -8,8 +8,14 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { const {deployer} = await hre.getNamedAccounts(); const l1Accs = await layer1.getNamedAccounts(); - const messageBusAddress = process.env.MESSAGE_BUS_ADDRESS!!// || "0xFD03804faCA2538F4633B3EBdfEfc38adafa259B" - const prefundAmountStr = process.env.PREFUND_FAUCET_AMOUNT!!// || "1" + var messageBusAddress = process.env.MESSAGE_BUS_ADDRESS!! + if (messageBusAddress === undefined) { + const networkConfig : any = await hre.network.provider.request({method: 'net_config'}); + messageBusAddress = networkConfig.MessageBusAddress; + console.log(`Fallback read of message bus address = ${messageBusAddress}`); + } + + const prefundAmountStr = process.env.PREFUND_FAUCET_AMOUNT!! || "1" if (prefundAmountStr == "0") { return; diff --git a/contracts/deployment_scripts/messenger/layer1/001_deploy_cross_chain_messenger.ts b/contracts/deployment_scripts/messenger/layer1/001_deploy_cross_chain_messenger.ts index 5a742677e9..9bf9e3aaca 100644 --- a/contracts/deployment_scripts/messenger/layer1/001_deploy_cross_chain_messenger.ts +++ b/contracts/deployment_scripts/messenger/layer1/001_deploy_cross_chain_messenger.ts @@ -14,8 +14,19 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { const { deployer } = await hre.companionNetworks.layer1.getNamedAccounts(); // Use the contract addresses from the management contract deployment. - const mgmtContractAddress = process.env.MGMT_CONTRACT_ADDRESS!! - const messageBusAddress : string = process.env.MESSAGE_BUS_ADDRESS!! + var mgmtContractAddress = process.env.MGMT_CONTRACT_ADDRESS!! + if (mgmtContractAddress === undefined) { + const networkConfig : any = await hre.network.provider.request({method: 'net_config'}); + mgmtContractAddress = networkConfig.ManagementContractAddress; + console.log(`Fallback read of management contract address = ${mgmtContractAddress}`); + } + + var messageBusAddress : string = process.env.MESSAGE_BUS_ADDRESS!! + if (messageBusAddress === undefined) { + const networkConfig : any = await hre.network.provider.request({method: 'net_config'}); + messageBusAddress = networkConfig.MessageBusAddress; + console.log(`Fallback read of message bus address = ${messageBusAddress}`); + } console.log(`Management Contract address ${mgmtContractAddress}`); console.log(`Message Bus address ${messageBusAddress}`); @@ -34,8 +45,6 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { } }); - - console.log(`Management Contract address ${mgmtContractAddress}`); // get management contract and write the cross chain messenger address to it const mgmtContract = (await hre.ethers.getContractFactory('ManagementContract')).attach(mgmtContractAddress) const tx = await mgmtContract.getFunction("SetImportantContractAddress").populateTransaction("L1CrossChainMessenger", crossChainDeployment.address); diff --git a/contracts/deployment_scripts/messenger/layer2/001_deploy_cross_chain_messenger.ts b/contracts/deployment_scripts/messenger/layer2/001_deploy_cross_chain_messenger.ts index eba3c0b8b7..43f6e4d869 100644 --- a/contracts/deployment_scripts/messenger/layer2/001_deploy_cross_chain_messenger.ts +++ b/contracts/deployment_scripts/messenger/layer2/001_deploy_cross_chain_messenger.ts @@ -15,7 +15,12 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { companionNetworks, } = hre; // Use the contract addresses from the management contract deployment. - const mgmtContractAddress = process.env.MGMT_CONTRACT_ADDRESS!! + var mgmtContractAddress = process.env.MGMT_CONTRACT_ADDRESS!! + if (mgmtContractAddress === undefined) { + const networkConfig : any = await hre.network.provider.request({method: 'net_config'}); + mgmtContractAddress = networkConfig.ManagementContractAddress; + console.log(`Fallback read of management contract address = ${mgmtContractAddress}`); + } // Get the prefunded L2 deployer account to use for deploying. const {deployer} = await getNamedAccounts(); @@ -24,7 +29,12 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { console.log(`Script: 001_deploy_cross_chain_messenger.ts - address used: ${deployer}`); // TODO: Remove hardcoded L2 message bus address when properly exposed. - const messageBusAddress = hre.ethers.getAddress("0x526c84529b2b8c11f57d93d3f5537aca3aecef9b"); + + const networkConfig : any = await hre.network.provider.request({method: 'net_config'}); + console.log(`L2 MessageBus = ${networkConfig.L2MessageBusAddress}`); + var l2MessageBus = networkConfig.L2MessageBusAddress; + + const messageBusAddress = hre.ethers.getAddress(l2MessageBus); console.log(`Deploying l2 cross chain messenger.`) // Deploy the L2 Cross chain messenger and use the L2 bus for validation const crossChainDeployment = await deployments.deploy('CrossChainMessenger', { diff --git a/contracts/deployment_scripts/testnet/layer2/001_whitelist_tokens.ts b/contracts/deployment_scripts/testnet/layer2/001_whitelist_tokens.ts index 44cef522bb..2b3064758c 100644 --- a/contracts/deployment_scripts/testnet/layer2/001_whitelist_tokens.ts +++ b/contracts/deployment_scripts/testnet/layer2/001_whitelist_tokens.ts @@ -117,6 +117,11 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { }); // Perform message relay. This will forward the whitelist command to the L2 subordinate bridge. + // Get the balance of l2Accounts.deployer using provider + const provider = l2Network.ethers.provider; + const balance = await provider.getBalance(l2Accounts.deployer); + console.log(`Balance of l2Accounts.deployer: ${balance}`); + console.log(`Relaying messages using account ${l2Accounts.deployer}`); const relayMsg = async (msg: any) => { return l2Network.deployments.execute("CrossChainMessenger", { diff --git a/integration/networktest/tests/helpful/spin_up_local_network_test.go b/integration/networktest/tests/helpful/spin_up_local_network_test.go index 9e96230a50..0b357108c9 100644 --- a/integration/networktest/tests/helpful/spin_up_local_network_test.go +++ b/integration/networktest/tests/helpful/spin_up_local_network_test.go @@ -34,7 +34,7 @@ const ( func TestRunLocalNetwork(t *testing.T) { networktest.TestOnlyRunsInIDE(t) networktest.EnsureTestLogsSetUp("local-geth-network") - networkConnector, cleanUp, err := env.LocalDevNetwork(devnetwork.WithGateway()).Prepare() + networkConnector, cleanUp, err := env.LocalDevNetwork(devnetwork.WithGateway(), devnetwork.WithPredictableDeployer()).Prepare() if err != nil { t.Fatal(err) } diff --git a/integration/simulation/devnetwork/config.go b/integration/simulation/devnetwork/config.go index 9ff45f3cb1..1602b3b7d8 100644 --- a/integration/simulation/devnetwork/config.go +++ b/integration/simulation/devnetwork/config.go @@ -35,6 +35,7 @@ type TenConfig struct { NumNodes int TenGatewayEnabled bool NumSeqEnclaves int + DeployerPK string L1BlockTime time.Duration } @@ -49,6 +50,7 @@ func DefaultTenConfig() *TenConfig { CrossChainInterval: 11 * time.Second, TenGatewayEnabled: false, NumSeqEnclaves: 1, // increase for HA simulation + DeployerPK: "", } } @@ -60,6 +62,15 @@ func LocalDevNetwork(tenConfigOpts ...TenConfigOption) *InMemDevNetwork { // 1 wallet per node nodeOpL1Wallets := params.NewSimWallets(0, tenConfig.NumNodes, integration.EthereumChainID, integration.TenChainID) + + if tenConfig.DeployerPK != "" { + privKey, err := crypto.HexToECDSA(tenConfig.DeployerPK) + if err != nil { + panic("could not initialise deployer private key") + } + nodeOpL1Wallets.MCOwnerWallet = wallet.NewInMemoryWalletFromPK(big.NewInt(integration.EthereumChainID), privKey, testlog.Logger()) + } + l1Config := &L1Config{ PortStart: integration.StartPortNetworkTests, NumNodes: tenConfig.NumNodes, // we'll have 1 L1 node per L2 node @@ -130,3 +141,11 @@ func WithHASequencer() TenConfigOption { tc.NumSeqEnclaves = 2 } } + +// WithPredictableDeployer - will use a known private key for the deployer instead of generating a random one. +// Useful for being able to run administrative functions from hardhat when debugging on the deployed network. +func WithPredictableDeployer() TenConfigOption { + return func(tc *TenConfig) { + tc.DeployerPK = "f52e5418e349dccdda29b6ac8b0abe6576bb7713886aa85abea6181ba731f9bb" + } +} diff --git a/tools/walletextension/rpcapi/net_api.go b/tools/walletextension/rpcapi/net_api.go index 855c5b7a42..208995747a 100644 --- a/tools/walletextension/rpcapi/net_api.go +++ b/tools/walletextension/rpcapi/net_api.go @@ -15,3 +15,13 @@ func NewNetAPI(we *Services) *NetAPI { func (api *NetAPI) Version(ctx context.Context) (*string, error) { return UnauthenticatedTenRPCCall[string](ctx, api.we, &CacheCfg{CacheType: LongLiving}, "net_version") } + +type ConfigResponseJson struct { + ManagementContractAddress string + MessageBusAddress string + L2MessageBusAddress string +} + +func (api *NetAPI) Config(ctx context.Context) (*ConfigResponseJson, error) { + return UnauthenticatedTenRPCCall[ConfigResponseJson](ctx, api.we, &CacheCfg{CacheType: LongLiving}, "obscuro_config") +}