Skip to content

Commit

Permalink
add index to migrate CCTX
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD committed Oct 11, 2023
1 parent 0f7cb3d commit a669d19
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 26 deletions.
2 changes: 1 addition & 1 deletion x/crosschain/keeper/migrate_tss_funds.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (k Keeper) MigrateTSSFundsForChain(ctx sdk.Context, chainID int64, amount s
if !isFound {
return types.ErrUnableToGetGasPrice
}
indexString := fmt.Sprintf("%s-%s-%d-%s", currentTss.TssPubkey, newTss.TssPubkey, chainID, amount.String())
indexString := fmt.Sprintf("%s-%s-%d-%s-%d", currentTss.TssPubkey, newTss.TssPubkey, chainID, amount.String(), ctx.BlockHeight())
hash := crypto.Keccak256Hash([]byte(indexString))
index := hash.Hex()
cctx := types.CrossChainTx{
Expand Down
22 changes: 11 additions & 11 deletions x/crosschain/keeper/msg_tss_voter.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,17 @@ func (k msgServer) MigrateTssFunds(goCtx context.Context, msg *types.MsgMigrateT
if k.zetaObserverKeeper.IsInboundEnabled(ctx) {
return nil, errorsmod.Wrap(types.ErrUnableToUpdateTss, "cannot migrate funds while inbound is enabled")
}
//tss, found := k.GetTSS(ctx)
//if !found {
// return nil, errorsmod.Wrap(types.ErrUnableToUpdateTss, "cannot find current TSS")
//}
//pendingNonces, found := k.GetPendingNonces(ctx, tss.TssPubkey, msg.ChainId)
//if !found {
// return nil, errorsmod.Wrap(types.ErrUnableToUpdateTss, "cannot find pending nonces for chain")
//}
//if pendingNonces.NonceLow != pendingNonces.NonceHigh {
// return nil, errorsmod.Wrap(types.ErrUnableToUpdateTss, "cannot migrate funds when there are pending nonces")
//}
tss, found := k.GetTSS(ctx)
if !found {
return nil, errorsmod.Wrap(types.ErrUnableToUpdateTss, "cannot find current TSS")
}
pendingNonces, found := k.GetPendingNonces(ctx, tss.TssPubkey, msg.ChainId)
if !found {
return nil, errorsmod.Wrap(types.ErrUnableToUpdateTss, "cannot find pending nonces for chain")
}
if pendingNonces.NonceLow != pendingNonces.NonceHigh {
return nil, errorsmod.Wrap(types.ErrUnableToUpdateTss, "cannot migrate funds when there are pending nonces")
}
err := k.MigrateTSSFundsForChain(ctx, msg.ChainId, msg.Amount)
if err != nil {
return nil, err
Expand Down
6 changes: 1 addition & 5 deletions zetaclient/evm_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ func (ob *EVMChainClient) IsSendOutTxProcessed(sendHash string, nonce uint64, co
receipt, found1 := ob.outTXConfirmedReceipts[ob.GetTxID(nonce)]
transaction, found2 := ob.outTXConfirmedTransaction[ob.GetTxID(nonce)]
ob.mu.Unlock()
fmt.Println("IsSendOutTxProcessed ::::", sendHash, nonce, cointype, found1, found2)
found := found1 && found2
if !found {
return false, false, nil
Expand All @@ -242,7 +241,6 @@ func (ob *EVMChainClient) IsSendOutTxProcessed(sendHash string, nonce uint64, co
if receipt.Status == 1 {
recvStatus = common.ReceiveStatus_Success
}
fmt.Println("Posting Confirmations to ZetaCore")
zetaHash, err := ob.zetaClient.PostReceiveConfirmation(
sendHash,
receipt.TxHash.Hex(),
Expand Down Expand Up @@ -464,7 +462,7 @@ func (ob *EVMChainClient) IsSendOutTxProcessed(sendHash string, nonce uint64, co

// The lowest nonce we observe outTx for each chain
var lowestOutTxNonceToObserve = map[int64]uint64{
5: 0, // Goerli
5: 70000, // Goerli
97: 95000, // BSC testnet
80001: 120000, // Mumbai
}
Expand Down Expand Up @@ -500,13 +498,11 @@ func (ob *EVMChainClient) observeOutTx() {
// Skip old gabbage trackers as we spent too much time on querying them
for _, tracker := range trackers {
nonceInt := tracker.Nonce
fmt.Println("nonceInt:lowestOutTxNonceToObserve", nonceInt, lowestOutTxNonceToObserve[ob.chain.ChainId])
if nonceInt < lowestOutTxNonceToObserve[ob.chain.ChainId] {
continue
}
TXHASHLOOP:
for _, txHash := range tracker.HashList {
ob.logger.ObserveOutTx.Info().Msgf("Iterating tracker list:nonce %d txhash %s", nonceInt, txHash.TxHash)
//inTimeout := time.After(3000 * time.Millisecond)
select {
case <-outTimeout:
Expand Down
13 changes: 7 additions & 6 deletions zetaclient/evm_signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ func (signer *EVMSigner) TryProcessOutTx(send *types.CrossChainTx, outTxMan *Out
logger.Error().Err(err).Msg("ParseChain fail; skip")
return
}
fmt.Println("Trying to process out tx")
// Early return if the cctx is already processed
included, confirmed, err := evmClient.IsSendOutTxProcessed(send.Index, send.GetCurrentOutTxParam().OutboundTxTssNonce, send.GetCurrentOutTxParam().CoinType, logger)
if err != nil {
Expand All @@ -310,12 +309,14 @@ func (signer *EVMSigner) TryProcessOutTx(send *types.CrossChainTx, outTxMan *Out
logger.Info().Msgf("CCTX already processed; exit signer")
return
}

//message, err := base64.StdEncoding.DecodeString(send.RelayedMessage)
//if err != nil {
// logger.Err(err).Msgf("decode CCTX.Message %s error", send.RelayedMessage)
//}
message, err := base64.StdEncoding.DecodeString("")
if send.GetCurrentOutTxParam().CoinType != common.CoinType_Cmd {
message, err = base64.StdEncoding.DecodeString(send.RelayedMessage)
if err != nil {
logger.Err(err).Msgf("decode CCTX.Message %s error", send.RelayedMessage)
}
}

if err != nil {
logger.Err(err).Msgf("decode CCTX.Message %s error", send.RelayedMessage)
}
Expand Down
4 changes: 1 addition & 3 deletions zetaclient/zetacore_observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,9 @@ func (co *CoreObserver) startSendScheduler() {
co.logger.ZetaChainWatcher.Error().Err(err).Msgf("failed to GetAllPendingCctx for chain %s", c.ChainName.String())
continue
}
fmt.Println("zetcoreobserver : cctxList: ", cctxList)
ob, err := co.getUpdatedChainOb(c.ChainId)
if err != nil {
//co.logger.ZetaChainWatcher.Error().Err(err).Msgf("getTargetChainOb fail, Chain ID: %s", c.ChainName)
co.logger.ZetaChainWatcher.Error().Err(err).Msgf("getTargetChainOb fail, Chain ID: %s", c.ChainName)
continue
}
chain, err := common.GetChainNameFromChainID(c.ChainId)
Expand Down Expand Up @@ -171,7 +170,6 @@ func (co *CoreObserver) startSendScheduler() {
currentHeight := uint64(bn)
nonce := params.OutboundTxTssNonce
outTxID := fmt.Sprintf("%s-%d-%d", cctx.Index, params.ReceiverChainId, nonce) // would outTxID a better ID?
fmt.Println("zetcoreobserver : outTxID: ", outTxID)
// Process Bitcoin OutTx
if common.IsBitcoinChain(c.ChainId) && !outTxMan.IsOutTxActive(outTxID) {
// #nosec G701 positive
Expand Down

0 comments on commit a669d19

Please sign in to comment.