Skip to content

Commit

Permalink
ugrain best effort fixes, but still doesn't work as expected
Browse files Browse the repository at this point in the history
  • Loading branch information
Vizualni committed Jun 21, 2022
1 parent 6f634c3 commit cc5a837
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 79 deletions.
4 changes: 2 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ var (
// and genesis verification.
ModuleBasics = module.NewBasicManager(
auth.AppModuleBasic{},
GenutilModule{},
genutil.AppModuleBasic{},
BankModule{},
capability.AppModuleBasic{},
StakingModule{},
Expand All @@ -152,7 +152,7 @@ var (
GovModule{gov.NewAppModuleBasic(getGovProposalHandlers()...)},
params.AppModuleBasic{},
CrisisModule{},
SlashingModule{},
slashing.AppModule{},
feegrantmodule.AppModuleBasic{},
ibc.AppModuleBasic{},
upgrade.AppModuleBasic{},
Expand Down
2 changes: 1 addition & 1 deletion app/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ const (
BondDenom = "ugrain"

// DisplayDenom defines the name, symbol, and display value of the paloma token.
DisplayDenom = "GRAIN"
DisplayDenom = "grain"
)
73 changes: 2 additions & 71 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,18 @@ package app

import (
"encoding/json"
"fmt"
"time"
"strings"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/bank"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/crisis"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
"github.com/cosmos/cosmos-sdk/x/gov"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmos/cosmos-sdk/x/mint"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
"github.com/cosmos/cosmos-sdk/x/slashing"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
"github.com/cosmos/cosmos-sdk/x/staking"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)
Expand All @@ -37,13 +31,12 @@ func (BankModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
Base: BondDenom,
Name: DisplayDenom,
Display: DisplayDenom,
Symbol: DisplayDenom,
Symbol: strings.ToUpper(DisplayDenom),
DenomUnits: []*banktypes.DenomUnit{
{
Denom: BondDenom,
Exponent: 0,
Aliases: []string{
"ugrain",
"micrograin",
},
},
Expand Down Expand Up @@ -118,65 +111,3 @@ func (GovModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {

return cdc.MustMarshalJSON(genState)
}

// SlashingModule defines a custom wrapper around the x/slashing module's
// AppModuleBasic implementation to provide custom default genesis state.
type SlashingModule struct {
slashing.AppModuleBasic
}

// DefaultGenesis returns custom Paloma x/slashing module genesis state.
func (SlashingModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
genState := slashingtypes.DefaultGenesisState()
genState.Params.SignedBlocksWindow = 10000
genState.Params.DowntimeJailDuration = 24 * time.Hour

return cdc.MustMarshalJSON(genState)
}

// GenutilModule defines a custom wrapper around the x/genutil module's
// AppModuleBasic implementation to provide custom genesis state validation.
type GenutilModule struct {
genutil.AppModuleBasic
}

// ValidateGenesis validates the x/genutil genesis state.
func (GenutilModule) ValidateGenesis(
cdc codec.JSONCodec,
encCfg client.TxEncodingConfig,
bz json.RawMessage,
) error {
var genState genutiltypes.GenesisState
if err := cdc.UnmarshalJSON(bz, &genState); err != nil {
return fmt.Errorf("failed to unmarshal %s genesis state: %w", genutiltypes.ModuleName, err)
}

txJSONDecoder := encCfg.TxJSONDecoder()

for i, genTx := range genState.GenTxs {
var tx sdk.Tx

tx, err := txJSONDecoder(genTx)
if err != nil {
return err
}

msgs := tx.GetMsgs()
if n := len(msgs); n != 2 {
return fmt.Errorf(
"gentx %d contains invalid number of messages; expected: 2; got: %d",
i, n,
)
}

if _, ok := msgs[0].(*stakingtypes.MsgCreateValidator); !ok {
return fmt.Errorf(
"gentx %d contains invalid message at index 0; expected: %T; got: %T",
i, &stakingtypes.MsgCreateValidator{}, msgs[0],
)
}

}

return nil
}
15 changes: 10 additions & 5 deletions scripts/setup-chain-validator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,21 @@ fi
CHAIN_ID="paloma"

VALIDATOR_ACCOUNT_NAME="my_validator"
VALIDATOR_STAKE_AMOUNT="1000000grain"
VALIDATOR_STAKE_AMOUNT="100000000ugrain"

PALOMA="${PALOMA_CMD:-go run ./cmd/palomad}"
if [[ -z ${PALOMA_CMD:-} ]]; then
echo "building palomad binary"
go build -o /tmp/palomad ./cmd/palomad
PALOMA="/tmp/palomad"
else
PALOMA="go run ./cmd/palomad"
fi

$PALOMA init my_validator --chain-id "$CHAIN_ID"

pushd ~/.paloma/config/
$SED -i 's/keyring-backend = ".*"/keyring-backend = "test"/' client.toml
$SED -i 's/minimum-gas-prices = ".*"/minimum-gas-prices = "0.001grain"/' app.toml
$SED -i 's/minimum-gas-prices = ".*"/minimum-gas-prices = "50000ugrain"/' app.toml
$SED -i 's/laddr = ".*:26657"/laddr = "tcp:\/\/0.0.0.0:26657"/' config.toml
jq ".chain_id = \"${CHAIN_ID}\"" genesis.json > temp.json && mv temp.json genesis.json
jq 'walk(if type == "string" and .. == "stake" then "grain" else . end)' genesis.json > temp.json && mv temp.json genesis.json
Expand All @@ -36,9 +42,8 @@ else
echo "$ACCOUNT_MNEMONIC" | $PALOMA keys add "$VALIDATOR_ACCOUNT_NAME" --recover
fi


validator_address="$($PALOMA keys show "$VALIDATOR_ACCOUNT_NAME" -a)"

$PALOMA add-genesis-account "$validator_address" 100000000000000grain
$PALOMA add-genesis-account "$validator_address" 100000000000000ugrain
$PALOMA gentx "$VALIDATOR_ACCOUNT_NAME" "$VALIDATOR_STAKE_AMOUNT" --chain-id "$CHAIN_ID"
$PALOMA collect-gentxs

0 comments on commit cc5a837

Please sign in to comment.