From 4eec5bd23cd71ddb94dbd6e97f100f69b133c1b6 Mon Sep 17 00:00:00 2001 From: StefanIliev545 Date: Tue, 30 Jul 2024 17:40:08 +0300 Subject: [PATCH] Rework to use config endpoint. --- contracts/config/networks.json | 5 ++--- .../bridge/001_deploy_bridge.ts | 7 ++++++- .../funding/layer1/001_fund_accounts.ts | 7 ++++++- .../funding/layer1/002_fund_faucet.ts | 10 ++++++++-- .../layer1/001_deploy_cross_chain_messenger.ts | 17 +++++++++++++---- .../layer2/001_deploy_cross_chain_messenger.ts | 7 ++++++- .../tests/helpful/spin_up_local_network_test.go | 4 ++-- integration/simulation/devnetwork/config.go | 17 +++++++++++++++++ integration/simulation/transaction_injector.go | 10 +++++----- tools/walletextension/rpcapi/net_api.go | 9 +++++++++ 10 files changed, 74 insertions(+), 19 deletions(-) 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..91495307e9 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(); 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..b962a7371c 100644 --- a/integration/networktest/tests/helpful/spin_up_local_network_test.go +++ b/integration/networktest/tests/helpful/spin_up_local_network_test.go @@ -32,9 +32,9 @@ const ( // Spins up a local network with a gateway, with all processes debuggable. The network will run until the test is stopped. // Note: If you want to access the gateway frontend you need to `npm run build` its frontend with NEXT_PUBLIC_API_GATEWAY_URL=http://localhost:11180 func TestRunLocalNetwork(t *testing.T) { - networktest.TestOnlyRunsInIDE(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..70d3fbb2a8 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,9 @@ func WithHASequencer() TenConfigOption { tc.NumSeqEnclaves = 2 } } + +func WithPredictableDeployer() TenConfigOption { + return func(tc *TenConfig) { + tc.DeployerPK = "f52e5418e349dccdda29b6ac8b0abe6576bb7713886aa85abea6181ba731f9bb" + } +} diff --git a/integration/simulation/transaction_injector.go b/integration/simulation/transaction_injector.go index 0b1a3ce907..a72c54dbe2 100644 --- a/integration/simulation/transaction_injector.go +++ b/integration/simulation/transaction_injector.go @@ -126,7 +126,7 @@ func NewTransactionInjector( func (ti *TransactionInjector) Start() { var wg errgroup.Group wg.Go(func() error { - ti.issueRandomDeposits() + // ti.issueRandomDeposits() return nil }) @@ -139,23 +139,23 @@ func (ti *TransactionInjector) Start() { // to do complex bridge transactions if !ti.params.IsInMem { wg.Go(func() error { - ti.bridgeRandomGasTransfers() + // ti.bridgeRandomGasTransfers() return nil }) } wg.Go(func() error { - ti.issueRandomTransfers() + // ti.issueRandomTransfers() return nil }) wg.Go(func() error { - ti.issueRandomValueTransfers() + // ti.issueRandomValueTransfers() return nil }) wg.Go(func() error { - ti.issueInvalidL2Txs() + // ti.issueInvalidL2Txs() return nil }) diff --git a/tools/walletextension/rpcapi/net_api.go b/tools/walletextension/rpcapi/net_api.go index 855c5b7a42..93a4a3d0af 100644 --- a/tools/walletextension/rpcapi/net_api.go +++ b/tools/walletextension/rpcapi/net_api.go @@ -15,3 +15,12 @@ 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 +} + +func (api *NetAPI) Config(ctx context.Context) (*ConfigResponseJson, error) { + return UnauthenticatedTenRPCCall[ConfigResponseJson](ctx, api.we, &CacheCfg{CacheType: LongLiving}, "obscuro_config") +}