Skip to content

Commit

Permalink
TESTING
Browse files Browse the repository at this point in the history
  • Loading branch information
VAIBHAVJINDAL3012 committed Oct 31, 2023
1 parent e3af686 commit ff33f89
Showing 1 changed file with 56 additions and 12 deletions.
68 changes: 56 additions & 12 deletions staking/side_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,47 +218,91 @@ func SideHandleMsgSignerUpdate(ctx sdk.Context, msg types.MsgSignerUpdate, k Kee
return hmCommon.ErrorSideTx(k.Codespace(), common.CodeWaitFrConfirmation)
}

newPubKey := msg.NewSignerPubKey
newSigner := newPubKey.Address()
k.Logger(ctx).Error("##########111111111111111#######")

eventLog, err := contractCaller.DecodeSignerUpdateEvent(chainParams.StakingInfoAddress.EthAddress(), receipt, msg.LogIndex)
eventLog, err := contractCaller.DecodeValidatorStakeUpdateEvent(chainParams.StakingInfoAddress.EthAddress(), receipt, msg.LogIndex)
if err != nil || eventLog == nil {
k.Logger(ctx).Error("Error fetching log from txhash")
return hmCommon.ErrorSideTx(k.Codespace(), common.CodeErrDecodeEvent)
return hmCommon.ErrorSideTx(k.Codespace(), common.CodeInvalidMsg)
}

k.Logger(ctx).Error("##########22222222222222#######")

if receipt.BlockNumber.Uint64() != msg.BlockNumber {
k.Logger(ctx).Error("BlockNumber in message doesn't match blocknumber in receipt", "MsgBlockNumber", msg.BlockNumber, "ReceiptBlockNumber", receipt.BlockNumber.Uint64)
return hmCommon.ErrorSideTx(k.Codespace(), common.CodeInvalidMsg)
}

k.Logger(ctx).Error("##########3333333333333#######")

if eventLog.ValidatorId.Uint64() != msg.ID.Uint64() {
k.Logger(ctx).Error("ID in message doesn't match with id in log", "msgId", msg.ID, "validatorIdFromTx", eventLog.ValidatorId)
return hmCommon.ErrorSideTx(k.Codespace(), common.CodeInvalidMsg)
}

if !bytes.Equal(eventLog.SignerPubkey, newPubKey.Bytes()[1:]) {
k.Logger(ctx).Error("Newsigner pubkey in txhash and msg dont match", "msgPubKey", newPubKey.String(), "pubkeyTx", hmTypes.NewPubKey(eventLog.SignerPubkey[:]).String())
return hmCommon.ErrorSideTx(k.Codespace(), common.CodeInvalidMsg)
}
k.Logger(ctx).Error("##########4444444444444#######")

// check signer corresponding to pubkey matches signer from event
if !bytes.Equal(newSigner.Bytes(), eventLog.NewSigner.Bytes()) {
k.Logger(ctx).Error("Signer Address from Pubkey does not match", "Validator", newSigner.String(), "mainchainValidator", eventLog.NewSigner.Hex())
// check Amount
if eventLog.NewAmount == big.NewInt(0) {
k.Logger(ctx).Error("##########INT -> Value of eventLog.NewAmount#############", eventLog.NewAmount)
return hmCommon.ErrorSideTx(k.Codespace(), common.CodeInvalidMsg)
}

k.Logger(ctx).Error("##########OUT -> Value of eventLog.NewAmount#############", eventLog.NewAmount)

// check nonce
if eventLog.Nonce.Uint64() != msg.Nonce {
k.Logger(ctx).Error("Nonce in message doesn't match with nonce in log", "msgNonce", msg.Nonce, "nonceFromTx", eventLog.Nonce)
return hmCommon.ErrorSideTx(k.Codespace(), common.CodeInvalidMsg)
}

k.Logger(ctx).Debug("✅ Successfully validated External call for signer update msg")
k.Logger(ctx).Debug("✅ Successfully validated External call for stake update msg")

result.Result = abci.SideTxResultType_Yes

return

// newPubKey := msg.NewSignerPubKey
// newSigner := newPubKey.Address()

// eventLog, err := contractCaller.DecodeSignerUpdateEvent(chainParams.StakingInfoAddress.EthAddress(), receipt, msg.LogIndex)
// if err != nil || eventLog == nil {
// k.Logger(ctx).Error("Error fetching log from txhash")
// return hmCommon.ErrorSideTx(k.Codespace(), common.CodeErrDecodeEvent)
// }

// if receipt.BlockNumber.Uint64() != msg.BlockNumber {
// k.Logger(ctx).Error("BlockNumber in message doesn't match blocknumber in receipt", "MsgBlockNumber", msg.BlockNumber, "ReceiptBlockNumber", receipt.BlockNumber.Uint64)
// return hmCommon.ErrorSideTx(k.Codespace(), common.CodeInvalidMsg)
// }

// if eventLog.ValidatorId.Uint64() != msg.ID.Uint64() {
// k.Logger(ctx).Error("ID in message doesn't match with id in log", "msgId", msg.ID, "validatorIdFromTx", eventLog.ValidatorId)
// return hmCommon.ErrorSideTx(k.Codespace(), common.CodeInvalidMsg)
// }

// if !bytes.Equal(eventLog.SignerPubkey, newPubKey.Bytes()[1:]) {
// k.Logger(ctx).Error("Newsigner pubkey in txhash and msg dont match", "msgPubKey", newPubKey.String(), "pubkeyTx", hmTypes.NewPubKey(eventLog.SignerPubkey[:]).String())
// return hmCommon.ErrorSideTx(k.Codespace(), common.CodeInvalidMsg)
// }

// // check signer corresponding to pubkey matches signer from event
// if !bytes.Equal(newSigner.Bytes(), eventLog.NewSigner.Bytes()) {
// k.Logger(ctx).Error("Signer Address from Pubkey does not match", "Validator", newSigner.String(), "mainchainValidator", eventLog.NewSigner.Hex())
// return hmCommon.ErrorSideTx(k.Codespace(), common.CodeInvalidMsg)
// }

// // check nonce
// if eventLog.Nonce.Uint64() != msg.Nonce {
// k.Logger(ctx).Error("Nonce in message doesn't match with nonce in log", "msgNonce", msg.Nonce, "nonceFromTx", eventLog.Nonce)
// return hmCommon.ErrorSideTx(k.Codespace(), common.CodeInvalidMsg)
// }

// k.Logger(ctx).Debug("✅ Successfully validated External call for signer update msg")

// result.Result = abci.SideTxResultType_Yes

// return
}

// SideHandleMsgValidatorExit handle side msg validator exit
Expand Down

0 comments on commit ff33f89

Please sign in to comment.