Skip to content

Commit

Permalink
Merge pull request Stride-Labs#70 from Stride-Labs/fix-claim-bug
Browse files Browse the repository at this point in the history
Fix claim bug
  • Loading branch information
riley-stride authored Jul 11, 2022
2 parents 3c3f6f1 + 9602070 commit 356390c
Show file tree
Hide file tree
Showing 62 changed files with 2,845 additions and 456 deletions.
2 changes: 2 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
[submodule "deps/hermes"]
path = deps/hermes
url = git@github.com:informalsystems/ibc-rs.git
branch = 4e83aae8afdc9a88a
[submodule "deps/gaia"]
path = deps/gaia
url = git@github.com:Stride-Labs/gaia.git
branch = v7.0.2-pinned
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ clean-state:
###############################################################################

test-unit:
@go test -mod=readonly -v ./x/...
@go test -mod=readonly -v ./x/$(module)/...

test-cover:
@go test -mod=readonly -race -coverprofile=coverage.out -covermode=atomic ./x/...
@go test -mod=readonly -race -coverprofile=coverage.out -covermode=atomic ./x/$(module)/...

test-integration:
sh scripts/tests/run_all_tests.sh
Expand Down
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,16 @@ An example of a PR using this strategy can be found [here](https://github.com/St
Opening a pull request (PR) will automatically create Summary and Test plan fields in the description. In the summary, add a high-level summary of what the change entails. For pull requests that scaffold ignite code, include the ignite scaffold commands run.
###### Summary
Add summary of the pull request here (*E.g. This pull request adds XYZ feature to the x/ABC module and associated unit tests.*)
###### Test plan
Add test plan here (*E.g. Test feature XYZ by executing unit tests D and E, with `sh scripts/tests/unit-test-D.sh` and `sh scripts/tests/unit-test-E.sh`*)
###### Unit tests

To run unit tests for the whole project, execute:
`make unit-test`
To run unit tests for a particular module (e.g. the stakeibc module), execute:
`make unit-test path=stakeibc`
To run unit tests for a particular package (e.g. the stakeibc module), execute:
`make unit-test path=stakeibc/types`
To inspect unit test coverage, execute:
`make test-cover`

#### Configure

Expand Down
2 changes: 1 addition & 1 deletion deps/gaia
Submodule gaia updated 0 files
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ require (
github.com/google/go-cmp v0.5.8 // indirect
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.10.3 // indirect
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect
github.com/ignite-hq/cli v0.21.0
github.com/improbable-eng/grpc-web v0.15.0 // indirect
github.com/jhump/protoreflect v1.12.0 // indirect
github.com/pkg/errors v0.9.1
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/regen-network/cosmos-proto v0.3.1 // indirect
github.com/spf13/cast v1.4.1
github.com/spf13/cobra v1.4.0
github.com/spf13/pflag v1.0.5
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,8 @@ github.com/grpc-ecosystem/grpc-gateway v1.14.7/go.mod h1:oYZKL012gGh6LMyg/xA7Q2y
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.10.0/go.mod h1:XnLCLFp3tjoZJszVKjfpyAK6J8sYIcQXWQxmqLWF21I=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.10.3 h1:BGNSrTRW4rwfhJiFwvwF4XQ0Y72Jj9YEgxVrtovbD5o=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.10.3/go.mod h1:VHn7KgNsRriXa4mcgtkpR00OXyQY6g67JWMvn+R27A4=
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
7 changes: 7 additions & 0 deletions proto/stakeibc/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ import "stakeibc/epoch_tracker.proto";

option go_package = "github.com/Stride-Labs/stride/x/stakeibc/types";

message PendingClaims {
string sequence = 1;
repeated string userRedemptionRecordIds = 2;

}

// GenesisState defines the stakeibc module's genesis state.
message GenesisState {
Params params = 1 [(gogoproto.nullable) = false];
Expand All @@ -21,6 +27,7 @@ message GenesisState {
// stores a map from hostZone base denom to hostZone
map<string, string> denomToHostZone = 9;
repeated EpochTracker epochTrackerList = 10 [(gogoproto.nullable) = false];
repeated PendingClaims pendingClaimsList = 11 [(gogoproto.nullable) = false];
// this line is used by starport scaffolding # genesis/proto/state
reserved 3;
}
6 changes: 4 additions & 2 deletions proto/stakeibc/host_zone.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import "records/genesis.proto";

option go_package = "github.com/Stride-Labs/stride/x/stakeibc/types";

// next id: 17
// next id: 18
message HostZone {
string chainId = 1;
string connectionId = 2;
string bech32prefix = 17;
string transferChannelId = 12;
repeated Validator validators = 3;
repeated Validator blacklistedValidators = 4;
Expand All @@ -38,7 +39,8 @@ message HostZone {
];
// stores how many days we should wait before issuing unbondings
uint64 unbondingFrequency = 14;
repeated string claimableRecordIds = 15;
//TODO(TEST-101) int to dec
int64 stakedBal = 13;

reserved 15;
}
29 changes: 29 additions & 0 deletions proto/stakeibc/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import "stakeibc/min_validator_requirements.proto";
import "stakeibc/ica_account.proto";
import "stakeibc/host_zone.proto";
import "stakeibc/epoch_tracker.proto";
import "stakeibc/genesis.proto";
// this line is used by starport scaffolding # 1

option go_package = "github.com/Stride-Labs/stride/x/stakeibc/types";
Expand Down Expand Up @@ -56,6 +57,16 @@ service Query {
option (google.api.http).get = "/Stride-Labs/stride/stakeibc/epoch_tracker";
}

// Queries a PendingClaims by index.
rpc PendingClaims(QueryGetPendingClaimsRequest) returns (QueryGetPendingClaimsResponse) {
option (google.api.http).get = "/Stride-Labs/stride/stakeibc/pending_claims/{sequence}";
}

// Queries a list of PendingClaims items.
rpc PendingClaimsAll(QueryAllPendingClaimsRequest) returns (QueryAllPendingClaimsResponse) {
option (google.api.http).get = "/Stride-Labs/stride/stakeibc/pending_claims";
}

// this line is used by starport scaffolding # 2
}

Expand Down Expand Up @@ -135,4 +146,22 @@ message QueryAllEpochTrackerResponse {
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

message QueryGetPendingClaimsRequest {
string sequence = 1;

}

message QueryGetPendingClaimsResponse {
PendingClaims pendingClaims = 1 [(gogoproto.nullable) = false];
}

message QueryAllPendingClaimsRequest {
cosmos.base.query.v1beta1.PageRequest pagination = 1;
}

message QueryAllPendingClaimsResponse {
repeated PendingClaims pendingClaims = 1 [(gogoproto.nullable) = false];
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// this line is used by starport scaffolding # 3
8 changes: 6 additions & 2 deletions proto/stakeibc/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,13 @@ message MsgSubmitTx {
// MsgSubmitTxResponse defines the response for Msg/SubmitTx
message MsgSubmitTxResponse {}

// next: 13
message MsgRegisterHostZone{
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

string connection_id = 2 [ (gogoproto.moretags) = "yaml:\"connection_id\"" ];
string bech32prefix = 12;
string host_denom = 4 [ (gogoproto.moretags) = "yaml:\"host_denom\"" ];
string ibc_denom = 5 [ (gogoproto.moretags) = "yaml:\"ibc_denom\"" ];
string creator = 6;
Expand All @@ -93,8 +95,10 @@ message MsgRegisterHostZoneResponse{}

message MsgClaimUndelegatedTokens {
string creator = 1;
string hostZone = 2;
uint64 maxClaims = 3;
// UserUnbondingRecords are keyed on {chain_id}.{epoch}.{sender}
string hostZoneId = 2;
uint64 epoch = 3;
string sender = 4;
}

message MsgClaimUndelegatedTokensResponse {
Expand Down
5 changes: 5 additions & 0 deletions scripts-local/create_logs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ while true; do
$STRIDE_CMD q records list-deposit-record >> $TEMP_LOGS_DIR/accounts.log
printf '\n%s\n' "LIST-EPOCH-UNBONDING-RECORDS" >>$TEMP_LOGS_DIR/accounts.log
$STRIDE_CMD q records list-epoch-unbonding-record >> $TEMP_LOGS_DIR/accounts.log

printf '\n%s\n' "LIST-USER-REDEMPTION-RECORDS" >>$TEMP_LOGS_DIR/accounts.log
$STRIDE_CMD q records list-user-redemption-record >> $TEMP_LOGS_DIR/accounts.log
# printf '\n%s\n' "LIST-PENDING-CLAIMS" >>$TEMP_LOGS_DIR/accounts.log
# $STRIDE_CMD q records list-user-redemption-record >> $TEMP_LOGS_DIR/accounts.log

mv $TEMP_LOGS_DIR/*.log $LOGS_DIR
sleep 3
Expand Down
2 changes: 1 addition & 1 deletion scripts-local/start_network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ if [ "$CACHE" != "true" ]; then
# Submit a transaction on stride to register the gaia host zone
echo "Creating host zone..."
$STRIDE_CMD tx stakeibc register-host-zone \
connection-0 $ATOM $IBCATOM channel-0 3 \
connection-0 $ATOM cosmos $IBCATOM channel-0 3 \
--chain-id $STRIDE_CHAIN --home $STATE/stride \
--keyring-backend test --from $STRIDE_VAL_ACCT --gas 1000000 -y
fi
Expand Down
4 changes: 3 additions & 1 deletion scripts-local/tests/4.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ source ${SCRIPT_DIR}/../account_vars.sh
$GAIA_CMD q bank balances cosmos1g6qdx6kdhpf000afvvpte7hp0vnpzapuyxp8uf

#claim stake
$STRIDE_CMD tx stakeibc claim-undelegated-tokens GAIA 3 --from val1 --keyring-backend test --chain-id STRIDE -y
EPOCH=9
SENDER=stride1uk4ze0x4nvh4fk0xm4jdud58eqn4yxhrt52vv7
$STRIDE_CMD tx stakeibc claim-undelegated-tokens GAIA $EPOCH $SENDER --from val1 --keyring-backend test --chain-id STRIDE -y

CSLEEP 30
# check balances after claiming redeemed stake
Expand Down
2 changes: 1 addition & 1 deletion scripts/init_main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ echo "Registering host zones..."
ATOM='uatom'
IBCATOM='ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2'
CSLEEP 60
docker-compose --ansi never exec -T $STRIDE_MAIN_NODE strided tx stakeibc register-host-zone connection-0 $ATOM $IBCATOM channel-0 --chain-id $STRIDE_CHAIN --home /stride/.strided --keyring-backend test --from val1 --gas 500000 -y
docker-compose --ansi never exec -T $STRIDE_MAIN_NODE strided tx stakeibc register-host-zone connection-0 $ATOM $IBCATOM "cosmos" channel-0 --chain-id $STRIDE_CHAIN --home /stride/.strided --keyring-backend test --from val1 --gas 500000 -y
CSLEEP 120
echo "Registered host zones:"
docker-compose --ansi never exec -T $STRIDE_MAIN_NODE strided q stakeibc list-host-zone
Expand Down
2 changes: 1 addition & 1 deletion scripts/local_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ignite chain init --home ~/.stride/
jq '.app_state.epochs.epochs[2].duration = $newVal' --arg newVal "3s" $main_config > json.tmp && mv json.tmp $main_config
strided start --home ~/.stride/

# strided tx stakeibc register-host-zone connection-0 ATOM stATOM --chain-id stride --home ~/.stride/ --from bob --gas 500000 -y
# strided tx stakeibc register-host-zone connection-0 ATOM stATOM "cosmos" --chain-id stride --home ~/.stride/ --from bob --gas 500000 -y


# BOBADDR=$(strided keys show bob -a)
Expand Down
2 changes: 1 addition & 1 deletion scripts/testnet/tests/verify_testnet_stride.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ IBCATOM="ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2"
strided q bank balances $STRIDE_ADDR
sleep 5

strided tx stakeibc register-host-zone connection-0 uatom $IBCATOM channel-0 3 --chain-id STRIDE \
strided tx stakeibc register-host-zone connection-0 uatom cosmos $IBCATOM channel-0 3 --chain-id STRIDE \
--keyring-backend test --from val2 --gas 1000000 -y

sleep 5
Expand Down
2 changes: 1 addition & 1 deletion scripts/tests/ica_redeem.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
echo "Register zone"
# setup logic on controller zone
$STRIDE1_EXEC tx stakeibc register-host-zone \
connection-0 uatom ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9 channel-0 --chain-id \
connection-0 uatom cosmos ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9 channel-0 --chain-id \
STRIDE --home /stride/.strided --keyring-backend test \
--from val1 --gas 500000 -y

Expand Down
4 changes: 4 additions & 0 deletions testutil/sample/sample.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ func AccAddress() string {
addr := pk.Address()
return sdk.AccAddress(addr).String()
}

func StrideAddress() string {
return "stride1uk4ze0x4nvh4fk0xm4jdud58eqn4yxhrt52vv7"
}
96 changes: 93 additions & 3 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@ import (
"fmt"
"strconv"

"errors"
"strings"

"github.com/cosmos/cosmos-sdk/types/address"
"github.com/cosmos/cosmos-sdk/types/bech32"

recordstypes "github.com/Stride-Labs/stride/x/records/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

var WHITELIST = map[string]bool{
var ADMINS = map[string]bool{
"stride1uk4ze0x4nvh4fk0xm4jdud58eqn4yxhrt52vv7": true,
"stride159atdlc3ksl50g0659w5tq42wwer334ajl7xnq": true,
}

Expand All @@ -25,9 +32,92 @@ func Int64ToCoinString(amount int64, denom string) string {
return strconv.FormatInt(amount, 10) + denom
}

func ValidateWhitelistedAddress(address string) error {
if !WHITELIST[address] {
func ValidateAdminAddress(address string) error {
if !ADMINS[address] {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, fmt.Sprintf("invalid creator address (%s)", address))
}
return nil
}

func Min(a int, b int) int {
if a < b {
return a
}
return b
}

//============================== ADDRESS VERIFICATION UTILS ================================
// ref: https://github.com/cosmos/cosmos-sdk/blob/b75c2ebcfab1a6b535723f1ac2889a2fc2509520/types/address.go#L177

var errBech32EmptyAddress = errors.New("decoding Bech32 address failed: must provide a non empty address")

// GetFromBech32 decodes a bytestring from a Bech32 encoded string.
func GetFromBech32(bech32str, prefix string) ([]byte, error) {
if len(bech32str) == 0 {
return nil, errBech32EmptyAddress
}

hrp, bz, err := bech32.DecodeAndConvert(bech32str)
if err != nil {
return nil, err
}

if hrp != prefix {
return nil, fmt.Errorf("invalid Bech32 prefix; expected %s, got %s", prefix, hrp)
}

return bz, nil
}

// VerifyAddressFormat verifies that the provided bytes form a valid address
// according to the default address rules or a custom address verifier set by
// GetConfig().SetAddressVerifier().
// TODO make an issue to get rid of global Config
// ref: https://github.com/cosmos/cosmos-sdk/issues/9690
func VerifyAddressFormat(bz []byte) error {
verifier := func(bz []byte) error {
n := len(bz)
if n == 20 {
return nil
}
return fmt.Errorf("incorrect address length %d", n)
}
if verifier != nil {
return verifier(bz)
}

if len(bz) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrUnknownAddress, "addresses cannot be empty")
}

if len(bz) > address.MaxAddrLen {
return sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "address max length is %d, got %d", address.MaxAddrLen, len(bz))
}

return nil
}

// AccAddress a wrapper around bytes meant to represent an account address.
// When marshaled to a string or JSON, it uses Bech32.
type AccAddress []byte

// AccAddressFromBech32 creates an AccAddress from a Bech32 string.
func AccAddressFromBech32(address string, bech32prefix string) (addr AccAddress, err error) {
if len(strings.TrimSpace(address)) == 0 {
return AccAddress{}, errors.New("empty address string is not allowed")
}

bz, err := GetFromBech32(address, bech32prefix)
if err != nil {
return nil, err
}

fmt.Sprintf("AccAddressFromBech32 | bz: %x", bz)

err = VerifyAddressFormat(bz)
if err != nil {
return nil, err
}

return AccAddress(bz), nil
}
6 changes: 6 additions & 0 deletions x/records/types/types.go
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
package types

import "fmt"

func UserRedemptionRecordKeyFormatter(chainId string, epochNumber uint64, sender string) string {
return fmt.Sprintf("%s.%d.%s", chainId, epochNumber, sender) // {chain_id}.{epoch}.{sender}
}
4 changes: 3 additions & 1 deletion x/stakeibc/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ func GetQueryCmd(queryRoute string) *cobra.Command {
cmd.AddCommand(CmdShowInterchainAccount())
cmd.AddCommand(CmdListEpochTracker())
cmd.AddCommand(CmdShowEpochTracker())
// this line is used by starport scaffolding # 1
cmd.AddCommand(CmdListPendingClaims())
cmd.AddCommand(CmdShowPendingClaims())
// this line is used by starport scaffolding # 1

return cmd
}
Loading

0 comments on commit 356390c

Please sign in to comment.