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

update launch command; adding celestia codec, several bug fix #116

Merged
merged 3 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
31 changes: 14 additions & 17 deletions contrib/launchtools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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",
beer-1 marked this conversation as resolved.
Show resolved Hide resolved
"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": [
Expand All @@ -70,12 +73,6 @@ minitiad launch $TARGET_NETWORK --with-config [path-to-config]
{
"address": "init13skjgs2x96c4sk9mfkfdzjywm75l6wy63j5gyn"
},
{
"address": "init1f4lu0ze9c7zegrrjfpymjvztucqz48z3cy8p5f"
},
{
"address": "init1hqv5xqt7lckdj9p5kfp2q5auc5z37p2vyt4d72"
},
{
"address": "init1gn0yjtcma92y27c0z84ratxf6juy69lpln6u88"
}
Expand Down
2 changes: 1 addition & 1 deletion contrib/launchtools/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
73 changes: 49 additions & 24 deletions contrib/launchtools/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -360,45 +367,65 @@ 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,
keyring.DefaultBIP39Passphrase,
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 {
return errors.New("failed to generate mnemonic")
}

// 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,
}
Expand All @@ -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,
}
}
Expand All @@ -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")
}
Expand All @@ -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")
}
Expand All @@ -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,
}
}
Expand All @@ -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")
}

Expand Down
1 change: 0 additions & 1 deletion contrib/launchtools/steps/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 4 additions & 0 deletions contrib/launchtools/utils/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions x/ophost/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ func (ms MsgServer) FinalizeTokenWithdrawal(ctx context.Context, req *types.MsgF
return &types.MsgFinalizeTokenWithdrawalResponse{}, nil
}

//nolint:dupl
func (ms MsgServer) UpdateProposer(ctx context.Context, req *types.MsgUpdateProposer) (*types.MsgUpdateProposerResponse, error) {
if err := req.Validate(ms.authKeeper.AddressCodec()); err != nil {
return nil, err
Expand Down Expand Up @@ -391,6 +392,7 @@ func (ms MsgServer) UpdateProposer(ctx context.Context, req *types.MsgUpdateProp
}, nil
}

//nolint:dupl
func (ms MsgServer) UpdateChallenger(ctx context.Context, req *types.MsgUpdateChallenger) (*types.MsgUpdateChallengerResponse, error) {
if err := req.Validate(ms.authKeeper.AddressCodec()); err != nil {
return nil, err
Expand Down
Loading