diff --git a/contrib/launchtools/README.md b/contrib/launchtools/README.md index 8d3ee01f..68211c5d 100644 --- a/contrib/launchtools/README.md +++ b/contrib/launchtools/README.md @@ -28,8 +28,8 @@ minitiad launch $TARGET_NETWORK --with-config [path-to-config] ```json { "l1_config": { - "chain_id": "initiation-1", - "rpc_url": "https://rpc.initiation-1.initia.xyz:443", + "chain_id": "initiation-2", + "rpc_url": "https://rpc.initiation-2.initia.xyz:443", "gas_prices": "0.015uinit" }, "l2_config": { @@ -38,28 +38,31 @@ minitiad launch $TARGET_NETWORK --with-config [path-to-config] "moniker": "operator" }, "op_bridge": { - "output_submission_start_height": "1", - "output_submission_interval": 3600000000000, - "output_finalization_period": 3600000000000, - "batch_submission_target": "INITIA" + "output_submission_start_height": 1, + "output_submission_interval": "1h0m0s", + "output_finalization_period": "168h0m0s", + "batch_submission_target": "INITIA", + "enable_oracle": true }, "system_keys": { "validator": { - "address": "init12z54lfqgp7zapzuuk2m4h6mjz84qzca8j0wm4x", + "l2_address": "init12z54lfqgp7zapzuuk2m4h6mjz84qzca8j0wm4x", "mnemonic": "digital kingdom slim fall cereal aspect expose trade once antique treat spatial unfair trip silver diesel other friend invest valve human blouse decrease salt" }, "bridge_executor": { - "address": "init13skjgs2x96c4sk9mfkfdzjywm75l6wy63j5gyn", + "l1_address": "init13skjgs2x96c4sk9mfkfdzjywm75l6wy63j5gyn", + "l2_address": "init13skjgs2x96c4sk9mfkfdzjywm75l6wy63j5gyn", "mnemonic": "junk aunt group member rebel dinosaur will trial jacket core club obscure morning unit fame round render napkin boy chest same patrol twelve medal" }, "output_submitter": { - "address": "init1f4lu0ze9c7zegrrjfpymjvztucqz48z3cy8p5f" + "l1_address": "init1f4lu0ze9c7zegrrjfpymjvztucqz48z3cy8p5f" }, "batch_submitter": { - "address": "init1hqv5xqt7lckdj9p5kfp2q5auc5z37p2vyt4d72" + "l1_address": "init1hqv5xqt7lckdj9p5kfp2q5auc5z37p2vyt4d72" }, "challenger": { - "address": "init1gn0yjtcma92y27c0z84ratxf6juy69lpln6u88" + "l1_address": "init1gn0yjtcma92y27c0z84ratxf6juy69lpln6u88", + "l2_address": "init1gn0yjtcma92y27c0z84ratxf6juy69lpln6u88" } }, "genesis_accounts": [ @@ -70,12 +73,6 @@ minitiad launch $TARGET_NETWORK --with-config [path-to-config] { "address": "init13skjgs2x96c4sk9mfkfdzjywm75l6wy63j5gyn" }, - { - "address": "init1f4lu0ze9c7zegrrjfpymjvztucqz48z3cy8p5f" - }, - { - "address": "init1hqv5xqt7lckdj9p5kfp2q5auc5z37p2vyt4d72" - }, { "address": "init1gn0yjtcma92y27c0z84ratxf6juy69lpln6u88" } diff --git a/contrib/launchtools/cmd.go b/contrib/launchtools/cmd.go index 3205a588..f01c0219 100644 --- a/contrib/launchtools/cmd.go +++ b/contrib/launchtools/cmd.go @@ -96,7 +96,7 @@ Artifact written to `, path.Join(clientCtx.HomeDir, artifactsDir, "config.json"), - path.Join(clientCtx.HomeDir, artifactsDir, "artifact.json"), + path.Join(clientCtx.HomeDir, artifactsDir, "artifacts.json"), ); err != nil { return errors.Wrap(err, "failed to write artifacts to stdout") } diff --git a/contrib/launchtools/config.go b/contrib/launchtools/config.go index 4721dfab..99874498 100644 --- a/contrib/launchtools/config.go +++ b/contrib/launchtools/config.go @@ -11,12 +11,15 @@ import ( "github.com/pkg/errors" + "cosmossdk.io/core/address" "github.com/cosmos/cosmos-sdk/client/input" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/go-bip39" + cmtcrypto "github.com/cometbft/cometbft/crypto" + "github.com/initia-labs/OPinit/contrib/launchtools/utils" ophosttypes "github.com/initia-labs/OPinit/x/ophost/types" ) @@ -74,7 +77,7 @@ func (i *Config) Finalize(buf *bufio.Reader) error { if err := i.OpBridge.Finalize(buf); err != nil { return err } - if err := i.SystemKeys.Finalize(buf); err != nil { + if err := i.SystemKeys.Finalize(buf, i.OpBridge.BatchSubmissionTarget); err != nil { return err } if err := i.GenesisAccounts.Finalize(*i.SystemKeys); err != nil { @@ -304,6 +307,10 @@ func (gas *GenesisAccounts) Finalize(systemKeys SystemKeys) error { return errors.New("systemKeys must be of type launcher.Account") } + if k.L2Address == "" { + continue + } + found := false for _, ga := range *gas { if ga.Address == k.L2Address { @@ -360,7 +367,37 @@ func generateMnemonic() (string, error) { return mnemonic, nil } -func deriveAddress(mnemonic string) (string, string, error) { +func deriveAddress(mnemonic string, codec address.Codec) (string, error) { + addrBz, err := deriveAddressBz(mnemonic) + if err != nil { + return "", errors.Wrap(err, "failed to convert address to bech32") + } + return codec.BytesToString(addrBz) +} + +func deriveL1L2Addresses(mnemonic string) (string, string, error) { + l1Addr, err := deriveAddress(mnemonic, utils.L1AddressCodec()) + if err != nil { + return "", "", err + } + l2Addr, err := deriveAddress(mnemonic, utils.L2AddressCodec()) + return l1Addr, l2Addr, err +} + +func deriveAddressWithChainType(mnemonic string, chainType ophosttypes.BatchInfo_ChainType) (string, error) { + var codec address.Codec + switch chainType { + case ophosttypes.BatchInfo_CHAIN_TYPE_INITIA: + codec = utils.L1AddressCodec() + case ophosttypes.BatchInfo_CHAIN_TYPE_CELESTIA: + codec = utils.CelestiaAddressCodec() + default: + return "", errors.New("unsupported chain type") + } + return deriveAddress(mnemonic, codec) +} + +func deriveAddressBz(mnemonic string) (cmtcrypto.Address, error) { algo := hd.Secp256k1 derivedPriv, err := algo.Derive()( mnemonic, @@ -368,23 +405,14 @@ func deriveAddress(mnemonic string) (string, string, error) { sdk.GetConfig().GetFullBIP44Path(), ) if err != nil { - return "", "", errors.Wrap(err, "failed to derive private key") + return nil, errors.Wrap(err, "failed to derive private key") } privKey := algo.Generate()(derivedPriv) - addrBz := privKey.PubKey().Address() - - // use init Bech32 prefix for l1 address - l1Addr, err := utils.L1AddressCodec().BytesToString(addrBz) - if err != nil { - return "", "", errors.Wrap(err, "failed to convert address to bech32") - } - - l2Addr, err := utils.L2AddressCodec().BytesToString(addrBz) - return l1Addr, l2Addr, err + return privKey.PubKey().Address(), nil } -func (systemKeys *SystemKeys) Finalize(buf *bufio.Reader) error { +func (systemKeys *SystemKeys) Finalize(buf *bufio.Reader, batchSubmissionTarget ophosttypes.BatchInfo_ChainType) error { if systemKeys.Validator == nil { mnemonic, err := generateMnemonic() if err != nil { @@ -392,13 +420,12 @@ func (systemKeys *SystemKeys) Finalize(buf *bufio.Reader) error { } // derive address - l1Addr, l2Addr, err := deriveAddress(mnemonic) + _, l2Addr, err := deriveL1L2Addresses(mnemonic) if err != nil { return errors.Wrap(err, "failed to derive address") } systemKeys.Validator = &SystemAccount{ - L1Address: l1Addr, L2Address: l2Addr, Mnemonic: mnemonic, } @@ -410,14 +437,13 @@ func (systemKeys *SystemKeys) Finalize(buf *bufio.Reader) error { } // derive address - l1Addr, l2Addr, err := deriveAddress(mnemonic) + daAddr, err := deriveAddressWithChainType(mnemonic, batchSubmissionTarget) if err != nil { return errors.Wrap(err, "failed to derive address") } systemKeys.BatchSubmitter = &SystemAccount{ - L1Address: l1Addr, - L2Address: l2Addr, + L1Address: daAddr, Mnemonic: mnemonic, } } @@ -432,7 +458,7 @@ func (systemKeys *SystemKeys) Finalize(buf *bufio.Reader) error { } // derive address - l1Addr, l2Addr, err := deriveAddress(mnemonic) + l1Addr, l2Addr, err := deriveL1L2Addresses(mnemonic) if err != nil { return errors.Wrap(err, "failed to derive address") } @@ -450,7 +476,7 @@ func (systemKeys *SystemKeys) Finalize(buf *bufio.Reader) error { } // derive address - l1Addr, l2Addr, err := deriveAddress(mnemonic) + l1Addr, l2Addr, err := deriveL1L2Addresses(mnemonic) if err != nil { return errors.Wrap(err, "failed to derive address") } @@ -468,14 +494,13 @@ func (systemKeys *SystemKeys) Finalize(buf *bufio.Reader) error { } // derive address - l1Addr, l2Addr, err := deriveAddress(mnemonic) + l1Addr, _, err := deriveL1L2Addresses(mnemonic) if err != nil { return errors.Wrap(err, "failed to derive address") } systemKeys.OutputSubmitter = &SystemAccount{ L1Address: l1Addr, - L2Address: l2Addr, Mnemonic: mnemonic, } } @@ -493,7 +518,7 @@ func (systemKeys *SystemKeys) Finalize(buf *bufio.Reader) error { if systemKeys.OutputSubmitter.L1Address == "" { return errors.New("output_submitter account not initialized") } - if systemKeys.Challenger.L1Address == "" { + if systemKeys.Challenger.L1Address == "" || systemKeys.Challenger.L2Address == "" { return errors.New("challenger account not initialized") } diff --git a/contrib/launchtools/steps/genesis.go b/contrib/launchtools/steps/genesis.go index a7d1f4b7..d849c993 100644 --- a/contrib/launchtools/steps/genesis.go +++ b/contrib/launchtools/steps/genesis.go @@ -322,7 +322,6 @@ func addFeeWhitelists(cdc codec.Codec, genesisAppState map[string]json.RawMessag ) { opchildState := opchildtypes.GetGenesisStateFromAppState(cdc, genesisAppState) opchildState.Params.FeeWhitelist = append(opchildState.Params.FeeWhitelist, whitelistAddrs...) - return opchildState, nil } diff --git a/contrib/launchtools/utils/address.go b/contrib/launchtools/utils/address.go index 9ced3f40..2892dbc3 100644 --- a/contrib/launchtools/utils/address.go +++ b/contrib/launchtools/utils/address.go @@ -14,6 +14,10 @@ func L2AddressCodec() address.Codec { return authcodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()) } +func CelestiaAddressCodec() address.Codec { + return authcodec.NewBech32Codec("celestia") +} + func HackBech32Prefix(prefix string) func() { originPrefix := sdk.GetConfig().GetBech32AccountAddrPrefix() originPubPrefix := sdk.GetConfig().GetBech32AccountPubPrefix()