Skip to content

Commit

Permalink
unbondings mostly set up, need acks
Browse files Browse the repository at this point in the history
  • Loading branch information
riley-stride committed Jun 28, 2022
1 parent 6a4ad8a commit 81809cd
Show file tree
Hide file tree
Showing 10 changed files with 258 additions and 100 deletions.
1 change: 1 addition & 0 deletions proto/records/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ message hostZoneUnbonding {
string denom = 2;
string hostZoneId = 3;
bool unbondingSent = 4;
uint64 unbondingTime = 5;
}

message EpochUnbondingRecord {
Expand Down
22 changes: 18 additions & 4 deletions scripts-local/create_logs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ while true; do
# accounts
GAIA_DELEGATE="cosmos19l6d3d7k2pel8epgcpxc9np6fsvjpaaa06nm65vagwxap0e4jezq05mmvu"
GAIA_WITHDRAWAL="cosmos1lcnmjwjy2lnqged5pnrc0cstz0r88rttunla4zxv84mee30g2q3q48fm53"
GAIA_REDEMPTION="cosmos1nc4hn8s7zp62vg4ugqzuul84zhvg5q7srq00f792zzmf5kyfre6sxfwmqw"
GAIA_REV="cosmos1wdplq6qjh2xruc7qqagma9ya665q6qhcwju3ng"
STRIDE_ADDRESS="stride1uk4ze0x4nvh4fk0xm4jdud58eqn4yxhrt52vv7"

N_VALIDATORS_STRIDE=$($STRIDE_CMD q tendermint-validator-set | grep -o address | wc -l | tr -dc '0-9')
Expand All @@ -27,15 +29,27 @@ while true; do

printf '\n%s\n' "BALANCES STRIDE" >>$TEMP_LOGS_DIR/accounts.log
$STRIDE_CMD q bank balances $STRIDE_ADDRESS >>$TEMP_LOGS_DIR/accounts.log
printf '\n%s\n' "BALANCES GAIA" >>$TEMP_LOGS_DIR/accounts.log
printf '\n%s\n' "BALANCES GAIA (DELEGATION ACCT)" >>$TEMP_LOGS_DIR/accounts.log
$GAIA_CMD q bank balances $GAIA_DELEGATE >>$TEMP_LOGS_DIR/accounts.log
printf '\n%s\n' "DELEGATIONS GAIA" >>$TEMP_LOGS_DIR/accounts.log
printf '\n%s\n' "DELEGATIONS GAIA (DELEGATION ACCT)" >>$TEMP_LOGS_DIR/accounts.log
$GAIA_CMD q staking delegations $GAIA_DELEGATE >>$TEMP_LOGS_DIR/accounts.log
printf '\n%s\n' "UNBONDING-DELEGATIONS GAIA (DELEGATION ACCT)" >>$TEMP_LOGS_DIR/accounts.log
$GAIA_CMD q staking unbonding-delegations $GAIA_DELEGATE >>$TEMP_LOGS_DIR/accounts.log

printf '\n%s\n' "BALANCES GAIA (REDEMPTION ACCT)" >>$TEMP_LOGS_DIR/accounts.log
$GAIA_CMD q staking delegations $GAIA_REDEMPTION >>$TEMP_LOGS_DIR/accounts.log
printf '\n%s\n' "BALANCES GAIA (REVENUE ACCT)" >>$TEMP_LOGS_DIR/accounts.log
$GAIA_CMD q staking delegations $GAIA_REV >>$TEMP_LOGS_DIR/accounts.log
printf '\n%s\n' "BALANCES GAIA (WITHDRAWAL ACCT)" >>$TEMP_LOGS_DIR/accounts.log
$GAIA_CMD q staking delegations $GAIA_WITHDRAWAL >>$TEMP_LOGS_DIR/accounts.log

printf '\n%s\n' "LIST-HOST-ZONES STRIDE" >>$TEMP_LOGS_DIR/accounts.log
$STRIDE_CMD q stakeibc list-host-zone | head -n 16 >>$TEMP_LOGS_DIR/accounts.log
$STRIDE_CMD q stakeibc list-host-zone | head -n 40 >>$TEMP_LOGS_DIR/accounts.log
printf '\n%s\n' "LIST-DEPOSIT-RECORDS" >>$TEMP_LOGS_DIR/accounts.log
$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

mv $TEMP_LOGS_DIR/*.log $LOGS_DIR
sleep 3
done
done
2 changes: 1 addition & 1 deletion scripts-local/start_network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ if [ "$CACHE" != "true" ]; then
$STRIDE_CMD tx stakeibc register-host-zone \
connection-0 $ATOM $IBCATOM channel-0 3 \
--chain-id $STRIDE_CHAIN --home $STATE/stride \
--keyring-backend test --from $STRIDE_VAL_ACCT --gas 500000 -y
--keyring-backend test --from $STRIDE_VAL_ACCT --gas 1000000 -y
fi

# Add more detailed log files
Expand Down
136 changes: 86 additions & 50 deletions x/records/types/genesis.pb.go

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

6 changes: 3 additions & 3 deletions x/stakeibc/client/cli/tx_redeem_stake.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ var _ = strconv.Itoa(0)

func CmdRedeemStake() *cobra.Command {
cmd := &cobra.Command{
Use: "redeem-stake [amount] [stAssetDenom] [receiver]",
Use: "redeem-stake [amount] [hostZoneID] [receiver]",
Short: "Broadcast message redeem-stake",
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {
argAmount, err := cast.ToInt64E(args[0])
if err != nil {
return err
}
argStAssetDenom := args[1]
hostZoneID := args[1]

clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
Expand All @@ -35,7 +35,7 @@ func CmdRedeemStake() *cobra.Command {
msg := types.NewMsgRedeemStake(
clientCtx.GetFromAddress().String(),
argAmount,
argStAssetDenom,
hostZoneID,
argReceiver,
)
if err := msg.ValidateBasic(); err != nil {
Expand Down
13 changes: 7 additions & 6 deletions x/stakeibc/keeper/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ func (k Keeper) BeforeEpochStart(ctx sdk.Context, epochIdentifier string, epochN
// every epoch
k.Logger(ctx).Info(fmt.Sprintf("Handling epoch start %s %d", epochIdentifier, epochNumber))

epochTracker := types.EpochTracker{
EpochIdentifier: epochIdentifier,
EpochNumber: uint64(epochNumber),
}
// deposit records *must* exist for this epoch
k.SetEpochTracker(ctx, epochTracker)

// process redemption records
if epochIdentifier == "day" {
// here, we process everything we need to for redemptions
Expand All @@ -53,12 +60,6 @@ func (k Keeper) BeforeEpochStart(ctx sdk.Context, epochIdentifier string, epochN
k.Logger(ctx).Error(fmt.Sprintf("Stride Epoch %d negative", epochNumber))
return
}
epochTracker := types.EpochTracker{
EpochIdentifier: epochIdentifier,
EpochNumber: uint64(epochNumber),
}
// deposit records *must* exist for this epoch
k.SetEpochTracker(ctx, epochTracker)

k.Logger(ctx).Info("Triggering deposits")
// Create a new deposit record for each host zone for the upcoming epoch
Expand Down
24 changes: 24 additions & 0 deletions x/stakeibc/keeper/ibc_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,33 @@ func (k Keeper) HandleUndelegate(ctx sdk.Context, msg sdk.Msg) error {
return fmt.Errorf("unable to cast source message to MsgUndelegate")
}

// CHECK ZONE
hostZoneDenom := undelegateMsg.Amount.Denom
zone, err := k.GetHostZoneFromHostDenom(ctx, hostZoneDenom)
if err != nil {
return err
}

// Implement!
// burn stAssets if successful
// return stAssets to user if unsuccessful

// set unbondingTime on EpochUnbondingRecord.hostZoneUnbonding from light client
unbondingRecord, found := k.RecordsKeeper.GetLatestEpochUnbondingRecord(ctx)
if !found {
return sdkerrors.Wrapf(sdkerrors.ErrNotFound, "No unbonding record found")
}
blockTime, found := k.GetLightClientTimeSafely(ctx, zone.ConnectionId)
if !found {
k.Logger(ctx).Error(fmt.Sprintf("Could not find blockTime for host zone %s", zone.ChainId))
}
// iterate through all unbonding record hostZone unbondings and set the unbonding times
for _, unbonding := range unbondingRecord.HostZoneUnbondings {
if unbonding.HostZoneId == zone.ChainId {
unbonding.UnbondingTime = blockTime
k.Logger(ctx).Info(fmt.Sprintf("Set unbonding time for host zone %s's unbonding for %d%s", zone.ChainId, undelegateMsg.Amount.Amount.Int64(), undelegateMsg.Amount.Denom))
}
}

return nil
}
Loading

0 comments on commit 81809cd

Please sign in to comment.