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

Deployment scripts rework to work locally. #2001

Merged
merged 8 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 2 additions & 3 deletions contracts/config/networks.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -19,6 +17,7 @@
"layer1" : "localGeth"
},
"deploy": [
"deployment_scripts/funding/layer1",
"deployment_scripts/messenger/layer1",
"deployment_scripts/messenger/layer2",
"deployment_scripts/bridge/",
Expand Down
7 changes: 6 additions & 1 deletion contracts/deployment_scripts/bridge/001_deploy_bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
10 changes: 8 additions & 2 deletions contracts/deployment_scripts/funding/layer1/002_fund_faucet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
19 changes: 19 additions & 0 deletions integration/simulation/devnetwork/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type TenConfig struct {
NumNodes int
TenGatewayEnabled bool
NumSeqEnclaves int
DeployerPK string

L1BlockTime time.Duration
}
Expand All @@ -49,6 +50,7 @@ func DefaultTenConfig() *TenConfig {
CrossChainInterval: 11 * time.Second,
TenGatewayEnabled: false,
NumSeqEnclaves: 1, // increase for HA simulation
DeployerPK: "",
}
}

Expand All @@ -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
Expand Down Expand Up @@ -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 {
StefanIliev545 marked this conversation as resolved.
Show resolved Hide resolved
return func(tc *TenConfig) {
tc.DeployerPK = "f52e5418e349dccdda29b6ac8b0abe6576bb7713886aa85abea6181ba731f9bb"
}
}
10 changes: 10 additions & 0 deletions tools/walletextension/rpcapi/net_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't this called ten_config now?
returning a TenNetworkInfo object

You can try this out in the gateway test

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just added this, the net_ namespace seemed most appropriate. It doesn't seem we currently have a ten one yet. Should I create one?

}
Loading