Skip to content

Commit

Permalink
Merge pull request #32 from schnetzlerjoe/main
Browse files Browse the repository at this point in the history
Fix denom checks and tests corresponding to it
  • Loading branch information
schnetzlerjoe committed Oct 24, 2022
2 parents 442c0b8 + 2a06c8a commit 1bd5789
Show file tree
Hide file tree
Showing 313 changed files with 3,704 additions and 79,896 deletions.
13 changes: 9 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,12 @@ create-connection:
@echo "Creating Defund -> Osmosis Connection"
hermes -c ./network/hermes/config.toml create connection defund osmosis

init: kill-dev
init:
@echo "Initializing both blockchains..."
./network/init.sh
@echo "Optimizing network"
./testnet/private/update_configs.sh
@echo "Starting up network"
./network/start.sh

init-rly:
Expand All @@ -224,6 +227,8 @@ init-rly:
./network/relayer/restore-keys.sh

start:
@echo "Optimizing network"
./testnet/private/update_configs.sh
@echo "Starting up network"
./network/start.sh

Expand All @@ -243,12 +248,12 @@ install-all:
./network/ts-relayer/install.sh

kill-dev:
@echo "Killing defundd, osmosis, hermes, ts-relayer and removing previous data"
@echo "Killing defundd, osmosis, hermes, ts-relayer (node processses) and removing previous data"
-@rm -rf ./network/data
-@killall defundd 2>/dev/null
-@killall node 2>/dev/null
-@killall osmosis 2>/dev/null
-@killall rly 2>/dev/null
-@killall hermes 2>/dev/null
# -@killall rly 2>/dev/null

###############################################################################
### Test ###
Expand Down
19 changes: 10 additions & 9 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ var (
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
etfmoduletypes.ModuleName: {authtypes.Minter, authtypes.Burner},
icatypes.ModuleName: nil,
brokermoduletypes.ModuleName: {authtypes.Minter, authtypes.Burner},
icatypes.ModuleName: nil,
// this line is used by starport scaffolding # stargate/app/maccPerms
}
)
Expand Down Expand Up @@ -308,9 +308,9 @@ func New(
// grant capabilities for the ibc and ibc-transfer modules
scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibchost.ModuleName)
scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
scopedBrokerKeeper := app.CapabilityKeeper.ScopeToModule(brokermoduletypes.ModuleName)
scopedICAControllerKeeper := app.CapabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName)
scopedICAHostKeeper := app.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName)
scopedBrokerKeeper := app.CapabilityKeeper.ScopeToModule(brokermoduletypes.ModuleName)
scopedETFKeeper := app.CapabilityKeeper.ScopeToModule(etfmoduletypes.ModuleName)
// this line is used by starport scaffolding # stargate/app/scopedKeeper

Expand Down Expand Up @@ -372,8 +372,7 @@ func New(
app.AccountKeeper, app.BankKeeper, scopedTransferKeeper,
)
transferModule := transfer.NewAppModule(app.TransferKeeper)
var transferStack porttypes.IBCModule
transferStack = transfer.NewIBCModule(app.TransferKeeper)
transferIBCModule := transfer.NewIBCModule(app.TransferKeeper)

app.ICAControllerKeeper = icacontrollerkeeper.NewKeeper(
appCodec, keys[icacontrollertypes.StoreKey], app.GetSubspace(icacontrollertypes.SubModuleName),
Expand All @@ -399,7 +398,7 @@ func New(
)
queryModule := querymodule.NewAppModule(appCodec, app.QueryKeeper, app.AccountKeeper)

app.BrokerKeeper = brokermodulekeeper.NewKeeper(appCodec, keys[brokermoduletypes.StoreKey], app.ICAControllerKeeper, scopedBrokerKeeper, app.TransferKeeper, app.IBCKeeper.ChannelKeeper, app.IBCKeeper.ConnectionKeeper, app.IBCKeeper.ClientKeeper, app.QueryKeeper, app.EtfKeeper, app.BankKeeper)
app.BrokerKeeper = brokermodulekeeper.NewKeeper(appCodec, keys[brokermoduletypes.StoreKey], app.GetSubspace(brokermoduletypes.ModuleName), app.ICAControllerKeeper, scopedBrokerKeeper, app.TransferKeeper, app.IBCKeeper.ChannelKeeper, app.IBCKeeper.ConnectionKeeper, app.IBCKeeper.ClientKeeper, app.QueryKeeper, app.EtfKeeper, app.BankKeeper)
brokerModule := brokermodule.NewAppModule(appCodec, app.BrokerKeeper, app.TransferKeeper)
brokerIBCModule := brokermodule.NewIBCModule(app.BrokerKeeper, app.EtfKeeper)

Expand All @@ -418,8 +417,6 @@ func New(
&stakingKeeper, govRouter,
)

transferStack = etfmodule.NewIBCMiddleware(transferStack, app.EtfKeeper)

app.EtfKeeper = *etfmodulekeeper.NewKeeper(
appCodec,
keys[etfmoduletypes.StoreKey],
Expand All @@ -437,13 +434,16 @@ func New(
)
etfModule := etfmodule.NewAppModule(appCodec, app.EtfKeeper, app.AccountKeeper, app.BankKeeper, app.QueryKeeper, app.BrokerKeeper)

// finish transfer stack
transferStack := etfmodule.NewIBCMiddleware(transferIBCModule, app.EtfKeeper)

// Create static IBC router, add transfer route, then set and seal it
ibcRouter := porttypes.NewRouter()
ibcRouter.
AddRoute(brokermoduletypes.ModuleName, icaControllerIBCModule).
AddRoute(ibctransfertypes.ModuleName, transferStack).
AddRoute(icacontrollertypes.SubModuleName, icaControllerIBCModule).
AddRoute(icahosttypes.SubModuleName, icaHostIBCModule).
AddRoute(ibctransfertypes.ModuleName, transferStack)
AddRoute(brokermoduletypes.ModuleName, icaControllerIBCModule)
app.IBCKeeper.SetRouter(ibcRouter)

// this line is used by starport scaffolding # stargate/app/keeperDefinition
Expand Down Expand Up @@ -730,6 +730,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(querymoduletypes.ModuleName)
paramsKeeper.Subspace(icacontrollertypes.SubModuleName)
paramsKeeper.Subspace(icahosttypes.SubModuleName)
paramsKeeper.Subspace(brokermoduletypes.ModuleName)
// this line is used by starport scaffolding # stargate/app/paramSubspace

return paramsKeeper
Expand Down
25 changes: 25 additions & 0 deletions app/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package app

import (
"time"

tmcfg "github.com/tendermint/tendermint/config"
)

func SetTendermintConfigs(config *tmcfg.Config) {
config.P2P.MaxNumInboundPeers = 100
config.P2P.MaxNumOutboundPeers = 100
config.P2P.SendRate = 20480000
config.P2P.RecvRate = 20480000
config.P2P.MaxPacketMsgPayloadSize = 10240
config.P2P.FlushThrottleTimeout = 10 * time.Millisecond
// Mempool configs
config.Mempool.Size = 5000
config.Mempool.MaxTxsBytes = 10737418240
config.Mempool.MaxTxBytes = 2048576
// Consensus Configs
config.Consensus.TimeoutPrevote = 250 * time.Millisecond
config.Consensus.TimeoutPrecommit = 250 * time.Millisecond
config.Consensus.TimeoutCommit = 250 * time.Millisecond
config.Consensus.SkipTimeoutCommit = true
}
158 changes: 158 additions & 0 deletions cmd/defundd/init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
package main

import (
"bufio"
"encoding/json"
"fmt"
"os"
"path/filepath"

"github.com/cosmos/go-bip39"
"github.com/defund-labs/defund/app"
"github.com/pkg/errors"
"github.com/spf13/cobra"
cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/libs/cli"
tmos "github.com/tendermint/tendermint/libs/os"
tmrand "github.com/tendermint/tendermint/libs/rand"
"github.com/tendermint/tendermint/types"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/input"
"github.com/cosmos/cosmos-sdk/server"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/genutil"
)

const (
// FlagOverwrite defines a flag to overwrite an existing genesis JSON file.
FlagOverwrite = "overwrite"

// FlagSeed defines a flag to initialize the private validator key from a specific seed.
FlagRecover = "recover"
)

type printInfo struct {
Moniker string `json:"moniker" yaml:"moniker"`
ChainID string `json:"chain_id" yaml:"chain_id"`
NodeID string `json:"node_id" yaml:"node_id"`
GenTxsDir string `json:"gentxs_dir" yaml:"gentxs_dir"`
AppMessage json.RawMessage `json:"app_message" yaml:"app_message"`
}

func newPrintInfo(moniker, chainID, nodeID, genTxsDir string, appMessage json.RawMessage) printInfo {
return printInfo{
Moniker: moniker,
ChainID: chainID,
NodeID: nodeID,
GenTxsDir: genTxsDir,
AppMessage: appMessage,
}
}

func displayInfo(info printInfo) error {
out, err := json.MarshalIndent(info, "", " ")
if err != nil {
return err
}

_, err = fmt.Fprintf(os.Stderr, "%s\n", string(sdk.MustSortJSON(out)))

return err
}

// InitCmd returns a command that initializes all files needed for Tendermint
// and the respective application.
func InitCmd(mbm module.BasicManager, defaultNodeHome string) *cobra.Command {
cmd := &cobra.Command{
Use: "init [moniker]",
Short: "Initialize private validator, p2p, genesis, and application configuration files",
Long: `Initialize validators's and node's configuration files.`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
cdc := clientCtx.Codec

serverCtx := server.GetServerContextFromCmd(cmd)
config := serverCtx.Config

app.SetTendermintConfigs(config)

config.SetRoot(clientCtx.HomeDir)

chainID, _ := cmd.Flags().GetString(flags.FlagChainID)
if chainID == "" {
chainID = fmt.Sprintf("test-chain-%v", tmrand.Str(6))
}

// Get bip39 mnemonic
var mnemonic string
recover, _ := cmd.Flags().GetBool(FlagRecover)
if recover {
inBuf := bufio.NewReader(cmd.InOrStdin())
value, err := input.GetString("Enter your bip39 mnemonic", inBuf)
if err != nil {
return err
}

mnemonic = value
if !bip39.IsMnemonicValid(mnemonic) {
return errors.New("invalid mnemonic")
}
}

nodeID, _, err := genutil.InitializeNodeValidatorFilesFromMnemonic(config, mnemonic)
if err != nil {
return err
}

config.Moniker = args[0]

genFile := config.GenesisFile()
overwrite, _ := cmd.Flags().GetBool(FlagOverwrite)

if !overwrite && tmos.FileExists(genFile) {
return fmt.Errorf("genesis.json file already exists: %v", genFile)
}

appState, err := json.MarshalIndent(mbm.DefaultGenesis(cdc), "", " ")
if err != nil {
return errors.Wrap(err, "Failed to marshall default genesis state")
}

genDoc := &types.GenesisDoc{}
if _, err := os.Stat(genFile); err != nil {
if !os.IsNotExist(err) {
return err
}
} else {
genDoc, err = types.GenesisDocFromFile(genFile)
if err != nil {
return errors.Wrap(err, "Failed to read genesis doc from file")
}
}

genDoc.ChainID = chainID
genDoc.Validators = nil
genDoc.AppState = appState

if err = genutil.ExportGenesisFile(genDoc, genFile); err != nil {
return errors.Wrap(err, "Failed to export gensis file")
}

toPrint := newPrintInfo(config.Moniker, chainID, nodeID, "", appState)

cfg.WriteConfigFile(filepath.Join(config.RootDir, "config", "config.toml"), config)
return displayInfo(toPrint)
},
}

cmd.Flags().String(cli.HomeFlag, defaultNodeHome, "node's home directory")
cmd.Flags().BoolP(FlagOverwrite, "o", false, "overwrite the genesis.json file")
cmd.Flags().Bool(FlagRecover, false, "provide seed phrase to recover existing key instead of creating")
cmd.Flags().String(flags.FlagChainID, "", "genesis file chain-id, if left blank will be randomly created")

return cmd
}
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ go 1.18

require (
github.com/cosmos/cosmos-sdk v0.45.9
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/ibc-go/v4 v4.0.1
github.com/gogo/protobuf v1.3.3
github.com/golang/protobuf v1.5.2
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/osmosis-labs/osmosis/v8 v8.0.1
github.com/pkg/errors v0.9.1
github.com/rakyll/statik v0.1.7
github.com/regen-network/cosmos-proto v0.3.1
github.com/spf13/cast v1.5.0
Expand Down Expand Up @@ -40,7 +42,6 @@ require (
github.com/coinbase/rosetta-sdk-go v0.7.9 // indirect
github.com/confio/ics23/go v0.7.0 // indirect
github.com/cosmos/btcutil v1.0.4 // indirect
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gorocksdb v1.2.0 // indirect
github.com/cosmos/iavl v0.19.3 // indirect
github.com/cosmos/ledger-cosmos-go v0.11.1 // indirect
Expand All @@ -55,6 +56,7 @@ require (
github.com/dvsekhvalnov/jose2go v1.5.0 // indirect
github.com/felixge/httpsnoop v1.0.1 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-kit/kit v0.12.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
Expand All @@ -67,6 +69,7 @@ require (
github.com/gorilla/handlers v1.5.1 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.12.0 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/gtank/merlin v0.1.1 // indirect
github.com/gtank/ristretto255 v0.1.2 // indirect
Expand All @@ -91,7 +94,6 @@ require (
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.2 // indirect
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.13.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ github.com/fzipp/gocyclo v0.3.1/go.mod h1:DJHO6AUmbdqj2ET4Z9iArSuwWgYDRryYt2wASx
github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff/go.mod h1:x7DCsMOv1taUwEWCzT4cmDeAkigA5/QCwUodaVOe8Ww=
github.com/getkin/kin-openapi v0.53.0/go.mod h1:7Yn5whZr5kJi6t+kShccXS8ae1APpYTW6yheSwk8Yi4=
github.com/getkin/kin-openapi v0.61.0/go.mod h1:7Yn5whZr5kJi6t+kShccXS8ae1APpYTW6yheSwk8Yi4=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
Expand Down Expand Up @@ -635,6 +636,8 @@ github.com/grpc-ecosystem/grpc-gateway v1.12.1/go.mod h1:8XEsbTttt/W+VvjtQhLACqC
github.com/grpc-ecosystem/grpc-gateway v1.14.7/go.mod h1:oYZKL012gGh6LMyg/xA7Q2yq6j8bu0wa+9w14EEthWU=
github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.12.0 h1:kr3j8iIMR4ywO/O0rvksXaJvauGGCMg2zAZIiNZ9uIQ=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.12.0/go.mod h1:ummNFgdgLhhX7aIiy35vVmQNS0rWXknfPE0qe6fmFXg=
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU=
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0=
github.com/gtank/merlin v0.1.1-0.20191105220539-8318aed1a79f/go.mod h1:T86dnYJhcGOh5BjZFCJWTDeTK7XW8uE+E21Cy/bIQ+s=
Expand Down
10 changes: 8 additions & 2 deletions network/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ $BINARY gentx val 7000000000ufetf --home $CHAIN_DIR/$CHAINID_1 --chain-id $CHAIN
$BINARY collect-gentxs --home $CHAIN_DIR/$CHAINID_1

echo "Changing defaults and ports in app.toml and config.toml files..."
sed -i -e 's/timeout_commit = "5s"/timeout_commit = "1s"/g' $CHAIN_DIR/$CHAINID_1/config/config.toml
sed -i -e 's/timeout_propose = "3s"/timeout_propose = "1s"/g' $CHAIN_DIR/$CHAINID_1/config/config.toml
sed -i -e 's/index_all_keys = false/index_all_keys = true/g' $CHAIN_DIR/$CHAINID_1/config/config.toml
sed -i -e 's/cors_allowed_origins = []/cors_allowed_origins = [*]/g' $CHAIN_DIR/$CHAINID_1/config/config.toml
sed -i -e 's/enable = false/enable = true/g' $CHAIN_DIR/$CHAINID_1/config/app.toml
sed -i -e 's/swagger = false/swagger = true/g' $CHAIN_DIR/$CHAINID_1/config/app.toml
sed -i -e 's/enabled-unsafe-cors = false/enabled-unsafe-cors = true/g' $CHAIN_DIR/$CHAINID_1/config/app.toml
sed -i -e 's/enable-unsafe-cors = false/enable-unsafe-cors = true/g' $CHAIN_DIR/$CHAINID_1/config/app.toml

echo "Changing Genesis File"
# Change crisis fee denom to fake detf
Expand All @@ -67,3 +68,8 @@ echo -E "${contents}" > ./network/data/defund/config/genesis.json
# Change brokers in broker in genesis file to blank so it will run broker function
contents="$(jq '.app_state.broker.brokers = []' ./network/data/defund/config/genesis.json)" && \
echo -E "${contents}" > ./network/data/defund/config/genesis.json
# Change base denoms in genesis file
contents="$(jq '.app_state.broker.params.base_denoms.AtomTrace.path = "transfer/channel-0/transfer/channel-0"' ./network/data/defund/config/genesis.json)" && \
echo -E "${contents}" > ./network/data/defund/config/genesis.json
contents="$(jq '.app_state.broker.params.base_denoms.OsmoTrace.path = "transfer/channel-0"' ./network/data/defund/config/genesis.json)" && \
echo -E "${contents}" > ./network/data/defund/config/genesis.json
Loading

0 comments on commit 1bd5789

Please sign in to comment.