Skip to content

Commit

Permalink
Merge pull request #39 from schnetzlerjoe/main
Browse files Browse the repository at this point in the history
v0.2.2-pre1
  • Loading branch information
schnetzlerjoe committed Jan 13, 2023
2 parents 6a52fd0 + 71926bc commit 390f68a
Show file tree
Hide file tree
Showing 20 changed files with 857 additions and 209 deletions.
28 changes: 28 additions & 0 deletions Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM golang:1.19-alpine AS build-env

ARG MONIKER
ENV MONIKER moniker

ARG tag
ENV TAG tag

ENV PACKAGES curl make git libc-dev bash gcc linux-headers eudev-dev python3 lz4
RUN apk add --no-cache $PACKAGES

COPY . /go/delivery/defund

COPY ./devtools/entrypoint.sh /

RUN chmod +x /entrypoint.sh

WORKDIR /go/delivery/defund

RUN git checkout $TAG

RUN make install

RUN defundd init $MONIKER

EXPOSE 26656 26657 1317 9090

CMD ["/bin/bash", "/entrypoint.sh"]
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -865,11 +865,11 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(crisistypes.ModuleName)
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(ibchost.ModuleName)
paramsKeeper.Subspace(brokermoduletypes.ModuleName)
paramsKeeper.Subspace(etfmoduletypes.ModuleName)
paramsKeeper.Subspace(querymoduletypes.ModuleName)
paramsKeeper.Subspace(icacontrollertypes.SubModuleName)
paramsKeeper.Subspace(icahosttypes.SubModuleName)
paramsKeeper.Subspace(brokermoduletypes.ModuleName)
paramsKeeper.Subspace(wasm.ModuleName)
// this line is used by starport scaffolding # stargate/app/paramSubspace

Expand Down
487 changes: 487 additions & 0 deletions devtools/bare_entrypoint.sh

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions devtools/optimize.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash
CONFIG_PATH="./$HOME/.defund/config/config.toml"

if [[ "$OSTYPE" == "linux-gnu"* ]]; then
sed -i 's/max_num_inbound_peers =.*/max_num_inbound_peers = 150/g' $CONFIG_PATH
sed -i 's/max_num_outbound_peers =.*/max_num_outbound_peers = 150/g' $CONFIG_PATH
sed -i 's/max_packet_msg_payload_size =.*/max_packet_msg_payload_size = 10240/g' $CONFIG_PATH
sed -i 's/send_rate =.*/send_rate = 20480000/g' $CONFIG_PATH
sed -i 's/recv_rate =.*/recv_rate = 20480000/g' $CONFIG_PATH
sed -i 's/timeout_prevote =.*/timeout_prevote = "100ms"/g' $CONFIG_PATH
sed -i 's/timeout_precommit =.*/timeout_precommit = "100ms"/g' $CONFIG_PATH
sed -i 's/timeout_commit =.*/timeout_commit = "100ms"/g' $CONFIG_PATH
sed -i 's/skip_timeout_commit =.*/skip_timeout_commit = false/g' $CONFIG_PATH
elif [[ "$OSTYPE" == "darwin"* ]]; then
sed -i '' 's/max_num_inbound_peers =.*/max_num_inbound_peers = 150/g' $CONFIG_PATH
sed -i '' 's/max_num_outbound_peers =.*/max_num_outbound_peers = 150/g' $CONFIG_PATH
sed -i '' 's/max_packet_msg_payload_size =.*/max_packet_msg_payload_size = 10240/g' $CONFIG_PATH
sed -i '' 's/send_rate =.*/send_rate = 20480000/g' $CONFIG_PATH
sed -i '' 's/recv_rate =.*/recv_rate = 20480000/g' $CONFIG_PATH
sed -i '' 's/timeout_prevote =.*/timeout_prevote = "100ms"/g' $CONFIG_PATH
sed -i '' 's/timeout_precommit =.*/timeout_precommit = "100ms"/g' $CONFIG_PATH
sed -i '' 's/timeout_commit =.*/timeout_commit = "100ms"/g' $CONFIG_PATH
sed -i '' 's/skip_timeout_commit =.*/skip_timeout_commit = false/g' $CONFIG_PATH
else
printf "Platform not supported, please ensure that the following values are set in your config.toml:\n"
printf "### P2P Configuration Options ###\n"
printf "\t max_num_inbound_peers = 150\n"
printf "\t max_num_outbound_peers = 150\n"
printf "\t max_packet_msg_payload_size = 10240\n"
printf "\t send_rate = 20480000\n"
printf "\t recv_rate = 20480000\n"
printf "### Consensus Configuration Options ###\n"
printf "\t timeout_prevote = \"100ms\"\n"
printf "\t timeout_precommit = \"100ms\"\n"
printf "\t timeout_commit = \"100ms\"\n"
printf "\t skip_timeout_commit = false\n"
exit 1
fi
6 changes: 4 additions & 2 deletions proto/broker/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ message BaseDenoms{

// Params defines the parameters for the broker module.
message Params {
// set the base denoms
BaseDenoms base_denoms = 1;
// set the atom official denom path
string AtomIBCPath = 1;
// set the osmo official denom path
string OsmoIBCPath = 2;
}
22 changes: 18 additions & 4 deletions testutil/keeper/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import (

"github.com/CosmWasm/wasmd/x/wasm"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/store"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/defund-labs/defund/app"
"github.com/defund-labs/defund/x/broker/keeper"
"github.com/defund-labs/defund/x/broker/types"
Expand All @@ -21,23 +22,36 @@ import (

func BrokerKeeper(db *dbm.MemDB, t testing.TB) (*keeper.Keeper, sdk.Context) {
storeKey := sdk.NewKVStoreKey(types.StoreKey)
paramsStoreKey := sdk.NewKVStoreKey(paramstypes.StoreKey)
paramsStoreKeyT := sdk.NewTransientStoreKey(paramstypes.TStoreKey)
memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey)

stateStore := store.NewCommitMultiStore(db)
stateStore.MountStoreWithDB(storeKey, sdk.StoreTypeIAVL, db)
stateStore.MountStoreWithDB(paramsStoreKeyT, sdk.StoreTypeTransient, db)
stateStore.MountStoreWithDB(paramsStoreKey, sdk.StoreTypeIAVL, db)
stateStore.MountStoreWithDB(memStoreKey, sdk.StoreTypeMemory, nil)
require.NoError(t, stateStore.LoadLatestVersion())

registry := codectypes.NewInterfaceRegistry()
encoding := app.MakeEncodingConfig(app.ModuleBasics)

a := app.New(log.NewNopLogger(), db, nil, true, map[int64]bool{}, app.DefaultNodeHome, 0, encoding, app.GetEnabledProposals(),
simapp.EmptyAppOptions{}, []wasm.Option{})

cdc := codec.NewProtoCodec(app.MakeEncodingConfig(app.ModuleBasics).InterfaceRegistry)

paramsSubspace := paramstypes.NewSubspace(cdc,
codec.NewLegacyAmino(),
storeKey,
memStoreKey,
"DexParams",
)
_ = paramskeeper.NewKeeper(cdc, codec.NewLegacyAmino(), paramsStoreKey, paramsStoreKeyT)

k := keeper.NewKeeper(
codec.NewProtoCodec(registry),
cdc,
storeKey,
a.GetSubspace(types.ModuleName),
paramsSubspace,
a.ICAControllerKeeper,
a.TransferKeeper,
a.IBCKeeper.ChannelKeeper,
Expand Down
6 changes: 3 additions & 3 deletions x/broker/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ func AddOsmosisToBrokers(ctx sdk.Context, k keeper.Keeper) error {
// InitGenesis initializes the brokers module's state from a provided genesis
// state via a genesis file.
func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) {
// Set all the brokers Defund supports at genesis
AddOsmosisToBrokers(ctx, k)
// set the broker params
k.SetParams(ctx, genState.Params)
// Set all the brokers Defund supports at genesis
AddOsmosisToBrokers(ctx, k)
// this line is used by starport scaffolding # genesis/module/init
}

// ExportGenesis returns the brokers module's exported genesis.
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
genesis := types.DefaultGenesis()
genesis.Params = k.GetParams(ctx, types.ParamsKey)
genesis.Params = k.GetParams(ctx)

genesis.Brokers = k.GetAllBrokers(ctx)
// this line is used by starport scaffolding # genesis/module/export
Expand Down
26 changes: 26 additions & 0 deletions x/broker/genesis_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package broker_test

import (
"testing"

keepertest "github.com/defund-labs/defund/testutil/keeper"
"github.com/defund-labs/defund/x/broker"
"github.com/defund-labs/defund/x/broker/types"
"github.com/stretchr/testify/require"
dbm "github.com/tendermint/tm-db"
)

func TestGenesis(t *testing.T) {
genesisState := types.DefaultGenesis()

db := dbm.NewMemDB()
k, ctx := keepertest.BrokerKeeper(db, t)
broker.InitGenesis(ctx, *k, *genesisState)
got := broker.ExportGenesis(ctx, *k)
require.NotNil(t, got)

require.Equal(t, got.Brokers[0].Id, "osmosis")
require.Equal(t, got.Params.AtomIBCPath, types.DefaultAtomPath)
require.Equal(t, got.Params.OsmoIBCPath, types.DefaultOsmoPath)
// this line is used by starport scaffolding # genesis/test/assert
}
3 changes: 3 additions & 0 deletions x/broker/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ type Keeper struct {
}

func NewKeeper(cdc codec.Codec, storeKey sdk.StoreKey, paramstore paramtypes.Subspace, iaKeeper icacontrollerkeeper.Keeper, transferKeeper transferkeeper.Keeper, channelKeeper channelkeeper.Keeper, connectionkeeper connectionkeeper.Keeper, clientkeeper clientkeeper.Keeper, querykeeper querykeeper.Keeper, etfkeeper etfkeeper.Keeper, bankkeeper bankkeeper.Keeper) Keeper {
if !paramstore.HasKeyTable() {
paramstore = paramstore.WithKeyTable(types.ParamKeyTable())
}
return Keeper{
cdc: cdc,
storeKey: storeKey,
Expand Down
55 changes: 19 additions & 36 deletions x/broker/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,32 @@ package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"
ibctransfertypes "github.com/cosmos/ibc-go/v4/modules/apps/transfer/types"
"github.com/defund-labs/defund/x/broker/types"
)

// Gets the base denom param directly from params
func (k Keeper) GetParam(ctx sdk.Context, key []byte) (bd *types.BaseDenoms) {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.ParamsKey)
if bz == nil {
return bd
}

params := types.Params{}
k.cdc.MustUnmarshal(bz, &params)

bd = params.BaseDenoms

return bd
// GetParams get all parameters as types.Params
func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
k.paramstore.GetParamSet(ctx, &params)
return params
}

// SetParams set the params
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error {
err := params.Validate()
if err != nil {
return err
}

store := ctx.KVStore(k.storeKey)
bz, err := k.cdc.Marshal(&params)
if err != nil {
return err
}
store.Set(types.ParamsKey, bz)

return nil
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
k.paramstore.SetParamSet(ctx, &params)
}

func (k *Keeper) GetParams(ctx sdk.Context, key []byte) (params types.Params) {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.ParamsKey)
if bz == nil {
return params
func (k Keeper) GetBaseDenomParam(ctx sdk.Context) types.BaseDenoms {
params := k.GetParams(ctx)

return types.BaseDenoms{
AtomTrace: &ibctransfertypes.DenomTrace{
Path: params.AtomIBCPath,
BaseDenom: "uatom",
},
OsmoTrace: &ibctransfertypes.DenomTrace{
Path: params.OsmoIBCPath,
BaseDenom: "uosmo",
},
}

k.cdc.MustUnmarshal(bz, &params)
return params
}
21 changes: 21 additions & 0 deletions x/broker/keeper/params_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package keeper_test

import (
"testing"

"github.com/stretchr/testify/require"

testkeeper "github.com/defund-labs/defund/testutil/keeper"
"github.com/defund-labs/defund/x/broker/types"
dbm "github.com/tendermint/tm-db"
)

func TestGetParams(t *testing.T) {
db := dbm.NewMemDB()
k, ctx := testkeeper.BrokerKeeper(db, t)
params := types.DefaultParams()

k.SetParams(ctx, params)

require.EqualValues(t, params, k.GetParams(ctx))
}
11 changes: 0 additions & 11 deletions x/broker/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,6 @@ const TypeMsgAddConnectionBroker = "add_connection_broker"
var _ sdk.Msg = &MsgAddLiquiditySource{}
var _ sdk.Msg = &MsgAddConnectionBroker{}

// helper function to check if a string is within a slice
func contains(list []string, str string) bool {
for _, value := range list {
if value == str {
return true
}
}

return false
}

func NewMsgAddLiquiditySource(creator string, brokerId string, poolId uint64) *MsgAddLiquiditySource {
return &MsgAddLiquiditySource{
Creator: creator,
Expand Down
Loading

0 comments on commit 390f68a

Please sign in to comment.