Skip to content

Commit

Permalink
Merge pull request #192 from Fairblock/update-target-height-logic-check
Browse files Browse the repository at this point in the history
Update to check chain height instead of latest height on src chain
  • Loading branch information
p0p3yee authored Oct 8, 2024
2 parents e7ae8a2 + 59c98f6 commit 2bf5f39
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion scripts/tests/keyshare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ fi


CURRENT_BLOCK=$($BINARY query consensus comet block-latest --home $CHAIN_DIR/$CHAINID_1 --node tcp://localhost:16657 -o json | jq -r '.block.header.height')
TARGET_HEIGHT=$((CURRENT_BLOCK+1))
TARGET_HEIGHT=$((CURRENT_BLOCK+2))
EXTRACTED_RESULT=$($BINARY share-generation derive $GENERATED_SHARE 1 $TARGET_HEIGHT)
EXTRACTED_SHARE=$(echo "$EXTRACTED_RESULT" | jq -r '.KeyShare')

Expand Down
16 changes: 8 additions & 8 deletions scripts/tests/pep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@ CURRENT_BLOCK=$($BINARY query consensus comet block-latest --home $CHAIN_DIR/$CH
RESULT=$($BINARY query keyshare list-aggregated-key-share --node $CHAIN1_NODE -o json)
AGG_KEY_HEIGHT=$(echo "$RESULT" | jq -r '.aggregatedKeyShare | last | .height')
AGG_KEY=$(echo "$RESULT" | jq -r '.aggregatedKeyShare | last | .data')
if [ "$CURRENT_BLOCK" -gt "$AGG_KEY_HEIGHT" ]; then
echo "ERROR: Height of the aggregated key from key share module '$AGG_KEY_HEIGHT' is less than current block height '$CURRENT_BLOCK'"
exit 1
fi
#if [ "$CURRENT_BLOCK" -gt "$AGG_KEY_HEIGHT" ]; then
# echo "ERROR: Height of the aggregated key from key share module '$AGG_KEY_HEIGHT' is less than current block height '$CURRENT_BLOCK'"
# exit 1
#fi

CURRENT_BLOCK=$($BINARY query consensus comet block-latest --home $CHAIN_DIR/$CHAINID_2 --node $CHAIN2_NODE -o json | jq -r '.block.header.height')
echo "Chain 2 Current Block: $CURRENT_BLOCK"
Expand All @@ -188,10 +188,10 @@ CURRENT_BLOCK=$($BINARY query consensus comet block-latest --home $CHAIN_DIR/$CH
RESULT=$($BINARY query keyshare list-aggregated-key-share --node $CHAIN1_NODE -o json)
AGG_KEY_HEIGHT=$(echo "$RESULT" | jq -r '.aggregatedKeyShare | last | .height')
AGG_KEY=$(echo "$RESULT" | jq -r '.aggregatedKeyShare | last | .data')
if [ "$CURRENT_BLOCK" -gt "$AGG_KEY_HEIGHT" ]; then
echo "ERROR: Height of the aggregated key from key share module '$AGG_KEY_HEIGHT' is less than current block height '$CURRENT_BLOCK'"
exit 1
fi
#if [ "$CURRENT_BLOCK" -gt "$AGG_KEY_HEIGHT" ]; then
# echo "ERROR: Height of the aggregated key from key share module '$AGG_KEY_HEIGHT' is less than current block height '$CURRENT_BLOCK'"
# exit 1
#fi


echo "Encrypting signed tx with Pub key: '$PUB_KEY'"
Expand Down
2 changes: 2 additions & 0 deletions testutil/keeper/keyshare.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ func KeyshareKeeper(t testing.TB) (keeper.Keeper, sdk.Context, pepkeeper.Keeper,
pepScopedKeeper,
accountKeeper,
nil,
nil,
nil,
)

stakingKeeper := stakingkeeper.NewKeeper(
Expand Down
13 changes: 9 additions & 4 deletions x/pep/keeper/msg_submit_encrypted_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@ import (

func (k msgServer) SubmitEncryptedTx(goCtx context.Context, msg *types.MsgSubmitEncryptedTx) (*types.MsgSubmitEncryptedTxResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
params := k.GetParams(ctx)

strHeight := k.GetLatestHeight(ctx)
height, err := strconv.ParseUint(strHeight, 10, 64)
height := uint64(ctx.BlockHeight())

if err != nil {
height = uint64(ctx.BlockHeight())
if !params.IsSourceChain {
strHeight := k.GetLatestHeight(ctx)
latestHeight, err := strconv.ParseUint(strHeight, 10, 64)

if err == nil {
height = latestHeight
}
}

if msg.TargetBlockHeight <= height {
Expand Down

0 comments on commit 2bf5f39

Please sign in to comment.