Compare commits

...
Author SHA1 Message Date
IshaVenikar bb9d7f56fe Configure pagination in gql query 2024-08-29 15:47:36 +05:30
prathamesh debfb82205 Integrate slashing module in the app (#53)
Part of [laconicd testnet validator enrollment](https://www.notion.so/laconicd-testnet-validator-enrollment-6fc1d3cafcc64fef8c5ed3affa27c675)

Add `slashing` module for penalizing / jailing offline validators
Reference: https://docs.cosmos.network/main/build/modules/slashing#liveness-tracking

Note: Breaking change, an existing chain cannot be run with the updated binary

Reviewed-on: cerc-io/laconicd#53
Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
Co-committed-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
2024-08-16 06:23:56 +00:00
prathamesh 3c5cd002e1 Add env variables to configure authority auctions in initialization script (#50)
Part of [laconicd testnet validator enrollment](https://www.notion.so/laconicd-testnet-validator-enrollment-6fc1d3cafcc64fef8c5ed3affa27c675)

Reviewed-on: cerc-io/laconicd#50
Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
Co-committed-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
2024-08-08 07:14:36 +00:00
prathamesh b5a76a920e Update node initialization script (#49)
Part of [laconicd testnet validator enrollment](https://www.notion.so/laconicd-testnet-validator-enrollment-6fc1d3cafcc64fef8c5ed3affa27c675)

Reviewed-on: cerc-io/laconicd#49
Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
Co-committed-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
2024-08-07 11:25:01 +00:00
8 changed files with 87 additions and 17 deletions
+4
View File
@@ -34,6 +34,7 @@ import (
distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
"github.com/cosmos/cosmos-sdk/x/genutil" "github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
_ "cosmossdk.io/api/cosmos/tx/config/v1" // import for side-effects _ "cosmossdk.io/api/cosmos/tx/config/v1" // import for side-effects
@@ -48,6 +49,7 @@ import (
_ "github.com/cosmos/cosmos-sdk/x/crisis" // import for side-effects _ "github.com/cosmos/cosmos-sdk/x/crisis" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/distribution" // import for side-effects _ "github.com/cosmos/cosmos-sdk/x/distribution" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/mint" // import for side-effects _ "github.com/cosmos/cosmos-sdk/x/mint" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/slashing" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/staking" // import for side-effects _ "github.com/cosmos/cosmos-sdk/x/staking" // import for side-effects
) )
@@ -76,6 +78,7 @@ type LaconicApp struct {
AccountKeeper authkeeper.AccountKeeper AccountKeeper authkeeper.AccountKeeper
BankKeeper bankkeeper.Keeper BankKeeper bankkeeper.Keeper
StakingKeeper *stakingkeeper.Keeper StakingKeeper *stakingkeeper.Keeper
SlashingKeeper slashingkeeper.Keeper
DistrKeeper distrkeeper.Keeper DistrKeeper distrkeeper.Keeper
CrisisKeeper *crisiskeeper.Keeper CrisisKeeper *crisiskeeper.Keeper
ConsensusParamsKeeper consensuskeeper.Keeper ConsensusParamsKeeper consensuskeeper.Keeper
@@ -142,6 +145,7 @@ func NewLaconicApp(
&app.AccountKeeper, &app.AccountKeeper,
&app.BankKeeper, &app.BankKeeper,
&app.StakingKeeper, &app.StakingKeeper,
&app.SlashingKeeper,
&app.DistrKeeper, &app.DistrKeeper,
&app.CrisisKeeper, &app.CrisisKeeper,
&app.ConsensusParamsKeeper, &app.ConsensusParamsKeeper,
+5 -2
View File
@@ -6,11 +6,11 @@ modules:
# During begin block slashing happens after distr.BeginBlocker so that # During begin block slashing happens after distr.BeginBlocker so that
# there is nothing left over in the validator fee pool, so as to keep the CanWithdrawInvariant invariant. # there is nothing left over in the validator fee pool, so as to keep the CanWithdrawInvariant invariant.
# NOTE: staking module is required if HistoricalEntries param > 0 # NOTE: staking module is required if HistoricalEntries param > 0
begin_blockers: [distribution, staking] begin_blockers: [distribution, slashing, staking]
end_blockers: [crisis, staking, auction, registry] end_blockers: [crisis, staking, auction, registry]
# NOTE: The genutils module must occur after staking so that pools are properly initialized with tokens from genesis accounts. # NOTE: The genutils module must occur after staking so that pools are properly initialized with tokens from genesis accounts.
# NOTE: The genutils module must also occur after auth so that it can access the params from auth. # NOTE: The genutils module must also occur after auth so that it can access the params from auth.
init_genesis: [auth, bank, distribution, staking, crisis, genutil, auction, bond, registry, onboarding] init_genesis: [auth, bank, distribution, staking, slashing, crisis, genutil, auction, bond, registry, onboarding]
override_store_keys: override_store_keys:
- module_name: auth - module_name: auth
kv_store_key: acc kv_store_key: acc
@@ -39,6 +39,9 @@ modules:
- name: staking - name: staking
config: config:
"@type": cosmos.staking.module.v1.Module "@type": cosmos.staking.module.v1.Module
- name: slashing
config:
"@type": cosmos.slashing.module.v1.Module
- name: distribution - name: distribution
config: config:
"@type": cosmos.distribution.module.v1.Module "@type": cosmos.distribution.module.v1.Module
+13
View File
@@ -10,6 +10,7 @@ import (
tmproto "github.com/cometbft/cometbft/proto/tendermint/types" tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
servertypes "github.com/cosmos/cosmos-sdk/server/types" servertypes "github.com/cosmos/cosmos-sdk/server/types"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
"github.com/cosmos/cosmos-sdk/x/staking" "github.com/cosmos/cosmos-sdk/x/staking"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
) )
@@ -221,4 +222,16 @@ func (app *LaconicApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddr
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
/* Handle slashing state. */
// reset start height on signing infos
app.SlashingKeeper.IterateValidatorSigningInfos(
ctx,
func(addr sdk.ConsAddress, info slashingtypes.ValidatorSigningInfo) (stop bool) {
info.StartHeight = 0
app.SlashingKeeper.SetValidatorSigningInfo(ctx, addr, info)
return false
},
)
} }
+1
View File
@@ -61,6 +61,7 @@ require (
github.com/agnivade/levenshtein v1.1.1 // indirect github.com/agnivade/levenshtein v1.1.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect
github.com/bits-and-blooms/bitset v1.10.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/btcsuite/btcd/btcutil v1.1.5 // indirect github.com/btcsuite/btcd/btcutil v1.1.5 // indirect
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 // indirect github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 // indirect
+2
View File
@@ -246,6 +246,8 @@ type Query {
# Whether to query all records, not just named ones (false by default). # Whether to query all records, not just named ones (false by default).
all: Boolean all: Boolean
limit: Int
offset: Int
): [Record] ): [Record]
# #
+22 -4
View File
@@ -185,7 +185,7 @@ type ComplexityRoot struct {
LookupNames func(childComplexity int, names []string) int LookupNames func(childComplexity int, names []string) int
QueryBonds func(childComplexity int, attributes []*KeyValueInput) int QueryBonds func(childComplexity int, attributes []*KeyValueInput) int
QueryBondsByOwner func(childComplexity int, ownerAddresses []string) int QueryBondsByOwner func(childComplexity int, ownerAddresses []string) int
QueryRecords func(childComplexity int, attributes []*KeyValueInput, all *bool) int QueryRecords func(childComplexity int, attributes []*KeyValueInput, all *bool, limit *int, offset *int) int
ResolveNames func(childComplexity int, names []string) int ResolveNames func(childComplexity int, names []string) int
} }
@@ -236,7 +236,7 @@ type QueryResolver interface {
QueryBonds(ctx context.Context, attributes []*KeyValueInput) ([]*Bond, error) QueryBonds(ctx context.Context, attributes []*KeyValueInput) ([]*Bond, error)
QueryBondsByOwner(ctx context.Context, ownerAddresses []string) ([]*OwnerBonds, error) QueryBondsByOwner(ctx context.Context, ownerAddresses []string) ([]*OwnerBonds, error)
GetRecordsByIds(ctx context.Context, ids []string) ([]*Record, error) GetRecordsByIds(ctx context.Context, ids []string) ([]*Record, error)
QueryRecords(ctx context.Context, attributes []*KeyValueInput, all *bool) ([]*Record, error) QueryRecords(ctx context.Context, attributes []*KeyValueInput, all *bool, limit *int, offset *int) ([]*Record, error)
GetAuthorities(ctx context.Context, owner *string) ([]*Authority, error) GetAuthorities(ctx context.Context, owner *string) ([]*Authority, error)
LookupAuthorities(ctx context.Context, names []string) ([]*AuthorityRecord, error) LookupAuthorities(ctx context.Context, names []string) ([]*AuthorityRecord, error)
LookupNames(ctx context.Context, names []string) ([]*NameRecord, error) LookupNames(ctx context.Context, names []string) ([]*NameRecord, error)
@@ -873,7 +873,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
return 0, false return 0, false
} }
return e.complexity.Query.QueryRecords(childComplexity, args["attributes"].([]*KeyValueInput), args["all"].(*bool)), true return e.complexity.Query.QueryRecords(childComplexity, args["attributes"].([]*KeyValueInput), args["all"].(*bool), args["limit"].(*int), args["offset"].(*int)), true
case "Query.resolveNames": case "Query.resolveNames":
if e.complexity.Query.ResolveNames == nil { if e.complexity.Query.ResolveNames == nil {
@@ -1330,6 +1330,24 @@ func (ec *executionContext) field_Query_queryRecords_args(ctx context.Context, r
} }
} }
args["all"] = arg1 args["all"] = arg1
var arg2 *int
if tmp, ok := rawArgs["limit"]; ok {
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("limit"))
arg2, err = ec.unmarshalOInt2ᚖint(ctx, tmp)
if err != nil {
return nil, err
}
}
args["limit"] = arg2
var arg3 *int
if tmp, ok := rawArgs["offset"]; ok {
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("offset"))
arg3, err = ec.unmarshalOInt2ᚖint(ctx, tmp)
if err != nil {
return nil, err
}
}
args["offset"] = arg3
return args, nil return args, nil
} }
@@ -4766,7 +4784,7 @@ func (ec *executionContext) _Query_queryRecords(ctx context.Context, field graph
}() }()
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
ctx = rctx // use context from middleware stack in children ctx = rctx // use context from middleware stack in children
return ec.resolvers.Query().QueryRecords(rctx, fc.Args["attributes"].([]*KeyValueInput), fc.Args["all"].(*bool)) return ec.resolvers.Query().QueryRecords(rctx, fc.Args["attributes"].([]*KeyValueInput), fc.Args["all"].(*bool), fc.Args["limit"].(*int), fc.Args["offset"].(*int))
}) })
if err != nil { if err != nil {
ec.Error(ctx, err) ec.Error(ctx, err)
+8 -1
View File
@@ -8,6 +8,7 @@ import (
"github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client"
types "github.com/cosmos/cosmos-sdk/types" types "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
@@ -136,14 +137,20 @@ func (q queryResolver) LookupNames(ctx context.Context, names []string) ([]*Name
return gqlResponse, nil return gqlResponse, nil
} }
func (q queryResolver) QueryRecords(ctx context.Context, attributes []*KeyValueInput, all *bool) ([]*Record, error) { func (q queryResolver) QueryRecords(ctx context.Context, attributes []*KeyValueInput, all *bool, limit *int, offset *int) ([]*Record, error) {
nsQueryClient := registrytypes.NewQueryClient(q.ctx) nsQueryClient := registrytypes.NewQueryClient(q.ctx)
pagination := &query.PageRequest{
Limit: uint64(*limit),
Offset: uint64(*offset),
}
res, err := nsQueryClient.Records( res, err := nsQueryClient.Records(
context.Background(), context.Background(),
&registrytypes.QueryRecordsRequest{ &registrytypes.QueryRecordsRequest{
Attributes: toRPCAttributes(attributes), Attributes: toRPCAttributes(attributes),
All: (all != nil && *all), All: (all != nil && *all),
Pagination: pagination,
}, },
) )
if err != nil { if err != nil {
+32 -10
View File
@@ -1,10 +1,12 @@
#!/bin/bash #!/bin/bash
KEY="alice" KEY="alice"
CHAINID="laconic_9000-1" CHAINID=${CHAINID:-"laconic_9000-1"}
MONIKER="localtestnet" MONIKER=${MONIKER:-"localtestnet"}
KEYRING="test" KEYRING=${KEYRING:-"test"}
LOGLEVEL="${LOGLEVEL:-info}" DENOM=${DENOM:-"alnt"}
STAKING_AMOUNT=${STAKING_AMOUNT:-"1000000000000000"}
LOGLEVEL=${LOGLEVEL:-"info"}
input_genesis_file=${GENESIS_FILE} input_genesis_file=${GENESIS_FILE}
@@ -29,9 +31,9 @@ if [ "$1" == "clean" ] || [ ! -d "$HOME/.laconicd/data/blockstore.db" ]; then
laconicd keys add $KEY --keyring-backend $KEYRING laconicd keys add $KEY --keyring-backend $KEYRING
# Set moniker and chain-id for Ethermint (Moniker can be anything, chain-id must be an integer) # Set moniker and chain-id for Ethermint (Moniker can be anything, chain-id must be an integer)
laconicd init $MONIKER --chain-id $CHAINID --default-denom alnt laconicd init $MONIKER --chain-id $CHAINID --default-denom $DENOM
if [ -f ${input_genesis_file} ]; then if [[ -f ${input_genesis_file} ]]; then
# Use provided genesis config # Use provided genesis config
cp $input_genesis_file $HOME/.laconicd/config/genesis.json cp $input_genesis_file $HOME/.laconicd/config/genesis.json
fi fi
@@ -65,6 +67,26 @@ if [ "$1" == "clean" ] || [ ! -d "$HOME/.laconicd/data/blockstore.db" ]; then
update_genesis '.app_state["onboarding"]["params"]["onboarding_enabled"]=true' update_genesis '.app_state["onboarding"]["params"]["onboarding_enabled"]=true'
fi fi
if [[ "$AUTHORITY_AUCTION_ENABLED" == "true" ]]; then
echo "Enabling authority auctions."
update_genesis '.app_state["registry"]["params"]["authority_auction_enabled"]=true'
fi
if [[ -n $AUTHORITY_AUCTION_COMMITS_DURATION ]]; then
echo "Setting authority_auction_commits_duration to $AUTHORITY_AUCTION_COMMITS_DURATION seconds."
update_genesis ".app_state[\"registry\"][\"params\"][\"authority_auction_commits_duration\"]=\"${AUTHORITY_AUCTION_COMMITS_DURATION}s\""
fi
if [[ -n $AUTHORITY_AUCTION_REVEALS_DURATION ]]; then
echo "Setting authority_auction_reveals_duration to $AUTHORITY_AUCTION_REVEALS_DURATION seconds."
update_genesis ".app_state[\"registry\"][\"params\"][\"authority_auction_reveals_duration\"]=\"${AUTHORITY_AUCTION_REVEALS_DURATION}s\""
fi
if [[ -n $AUTHORITY_GRACE_PERIOD ]]; then
echo "Setting authority_grace_period to $AUTHORITY_GRACE_PERIOD seconds."
update_genesis ".app_state[\"registry\"][\"params\"][\"authority_grace_period\"]=\"${AUTHORITY_GRACE_PERIOD}s\""
fi
# increase block time (?) # increase block time (?)
update_genesis '.consensus["params"]["block"]["time_iota_ms"]="1000"' update_genesis '.consensus["params"]["block"]["time_iota_ms"]="1000"'
@@ -94,11 +116,11 @@ if [ "$1" == "clean" ] || [ ! -d "$HOME/.laconicd/data/blockstore.db" ]; then
# Allocate genesis accounts (cosmos formatted addresses) # Allocate genesis accounts (cosmos formatted addresses)
# 10^30 alnt | 10^12 lnt # 10^30 alnt | 10^12 lnt
laconicd genesis add-genesis-account $KEY 1000000000000000000000000000000alnt --keyring-backend $KEYRING laconicd genesis add-genesis-account $KEY 1000000000000000000000000000000$DENOM --keyring-backend $KEYRING
# Sign genesis transaction # Sign genesis transaction
# 10^24 alnt | 10^6 lnt # 10^15 alnt
laconicd genesis gentx $KEY 1000000000000000000000000alnt --keyring-backend $KEYRING --chain-id $CHAINID laconicd genesis gentx $KEY $STAKING_AMOUNT$DENOM --keyring-backend $KEYRING --chain-id $CHAINID
# Collect genesis tx # Collect genesis tx
laconicd genesis collect-gentxs laconicd genesis collect-gentxs
@@ -113,7 +135,7 @@ fi
laconicd start \ laconicd start \
--pruning=nothing \ --pruning=nothing \
--log_level $LOGLEVEL \ --log_level $LOGLEVEL \
--minimum-gas-prices=1alnt \ --minimum-gas-prices=1$DENOM \
--api.enable \ --api.enable \
--rpc.laddr="tcp://0.0.0.0:26657" \ --rpc.laddr="tcp://0.0.0.0:26657" \
--gql-server --gql-playground --gql-server --gql-playground