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

add implementations to support gov-tx-proposal #240

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions local_node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ if [[ $overwrite == "y" || $overwrite == "Y" ]]; then
jq '.app_state["oracle"]["params"]["tokens"][1]["asset_id"]="0xdac17f958d2ee523a2206206994597c13d831ec7_0x65"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state["oracle"]["params"]["token_feeders"][1]["start_base_block"]="20"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"

# x/feemarket
jq '.app_state["feemarket"]["params"]["base_fee"]="10"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"

# x/operator
jq '.app_state["operator"]["operators"][0]["operator_address"]="'"$LOCAL_ADDRESS_EXO"'"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state["operator"]["operators"][0]["operator_info"]["earnings_addr"]="'"$LOCAL_ADDRESS_EXO"'"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
Expand Down
8 changes: 3 additions & 5 deletions x/delegation/keeper/delegation_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

type DelegationOpFunc func(keys *delegationtype.SingleDelegationInfoReq, amounts *delegationtype.DelegationAmounts) (bool, error)

func (k Keeper) AllDelegationStates(ctx sdk.Context) (delegationStates []delegationtype.DelegationStates, err error) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), delegationtype.KeyPrefixRestakerDelegationInfo)
iterator := sdk.KVStorePrefixIterator(store, []byte{})
Expand Down Expand Up @@ -41,7 +39,7 @@ func (k Keeper) SetAllDelegationStates(ctx sdk.Context, delegationStates []deleg
return nil
}

func (k Keeper) IterateDelegations(ctx sdk.Context, iteratorPrefix []byte, opFunc DelegationOpFunc) error {
func (k Keeper) IterateDelegations(ctx sdk.Context, iteratorPrefix []byte, opFunc delegationtype.DelegationOpFunc) error {
store := prefix.NewStore(ctx.KVStore(k.storeKey), delegationtype.KeyPrefixRestakerDelegationInfo)
iterator := sdk.KVStorePrefixIterator(store, iteratorPrefix)
defer iterator.Close()
Expand All @@ -66,11 +64,11 @@ func (k Keeper) IterateDelegations(ctx sdk.Context, iteratorPrefix []byte, opFun

// IterateDelegationsForStakerAndAsset processes all operations
// that require iterating over delegations for a specified staker and asset.
func (k Keeper) IterateDelegationsForStakerAndAsset(ctx sdk.Context, stakerID string, assetID string, opFunc DelegationOpFunc) error {
func (k Keeper) IterateDelegationsForStakerAndAsset(ctx sdk.Context, stakerID string, assetID string, opFunc delegationtype.DelegationOpFunc) error {
return k.IterateDelegations(ctx, delegationtype.IteratorPrefixForStakerAsset(stakerID, assetID), opFunc)
}

func (k Keeper) IterateDelegationsForStaker(ctx sdk.Context, stakerID string, opFunc DelegationOpFunc) error {
func (k Keeper) IterateDelegationsForStaker(ctx sdk.Context, stakerID string, opFunc delegationtype.DelegationOpFunc) error {
return k.IterateDelegations(ctx, []byte(stakerID), opFunc)
}

Expand Down
3 changes: 3 additions & 0 deletions x/delegation/types/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package types

type DelegationOpFunc func(keys *SingleDelegationInfoReq, amounts *DelegationAmounts) (bool, error)
18 changes: 13 additions & 5 deletions x/dogfood/keeper/impl_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ func (k Keeper) Unjail(ctx sdk.Context, addr sdk.ConsAddress) {
// module. The slashing module uses it to obtain the delegation information of a validator
// before unjailing it. If the slashing module's unjail function is never called, this
// function will never be called either.
// NOTE: this is not a universal function, it not actually get delegation for {delegator, validator}, but only returns {validator}'s self delegation, only suites for special invoke
func (k Keeper) Delegation(
ctx sdk.Context, delegator sdk.AccAddress, validator sdk.ValAddress,
) stakingtypes.DelegationI {
Expand Down Expand Up @@ -230,15 +231,22 @@ func (k Keeper) IterateBondedValidatorsByPower(
// TotalBondedTokens is an implementation of the staking interface expected by the SDK's
// gov module. This is not implemented intentionally, since the tokens securing this chain
// are many and span across multiple chains and assets.
func (k Keeper) TotalBondedTokens(sdk.Context) math.Int {
panic("unimplemented on this keeper")
func (k Keeper) TotalBondedTokens(ctx sdk.Context) math.Int {
// TODO: return totalBondedPower(virtual tokens from power) compatible with multi-assets staking
totalPower := math.ZeroInt()
k.IterateBondedValidatorsByPower(ctx, func(_ int64, v stakingtypes.ValidatorI) bool {
totalPower = totalPower.Add(v.GetTokens())
return false
})
return totalPower
}

// IterateDelegations is an implementation of the staking interface expected by the SDK's
// gov module. See note above to understand why this is not implemented.
func (k Keeper) IterateDelegations(
sdk.Context, sdk.AccAddress,
func(int64, stakingtypes.DelegationI) bool,
ctx sdk.Context, _ sdk.AccAddress,
_ func(int64, stakingtypes.DelegationI) bool,
) {
panic("unimplemented on this keeper")
// for now we don't have mechabnism to bond delegatorAddress from clientChain to their cosmossdk address(for EVM when can force user use the same ethsecp256k1 instead of secp256k1 to retrieve default bonded addresses, but that not a universal approach), we'll just ignore any delegator's vote, and validator will have the total power including all the delegated assts, and that's reasonanble
ctx.Logger().Info("IterateDelegations from gov tally will just return, which means operator/validator will have all the powers delegated to them when voting proposal")
}
3 changes: 2 additions & 1 deletion x/feedistribution/types/genesis.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion x/operator/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type DelegationKeeper interface {
) error
DeleteStakersListForOperator(ctx sdk.Context, operator, assetID string) error

IterateDelegationsForStaker(ctx sdk.Context, stakerID string, opFunc delegationkeeper.DelegationOpFunc) error
IterateDelegationsForStaker(ctx sdk.Context, stakerID string, opFunc delegationtype.DelegationOpFunc) error
}

type PriceChange struct {
Expand Down
Loading