-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
optional strategy for maintaining app versions
- Loading branch information
Showing
9 changed files
with
438 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,5 @@ var ( | |
CommitHash = "" | ||
BuildTime = "" | ||
) | ||
|
||
const AppVersion = 14 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
package v14 | ||
|
||
import ( | ||
"fmt" | ||
|
||
sdkmath "cosmossdk.io/math" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
storetypes "github.com/cosmos/cosmos-sdk/store/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/zeta-chain/zetacore/common" | ||
"github.com/zeta-chain/zetacore/x/crosschain/types" | ||
) | ||
|
||
// crosschainKeeper is an interface to prevent cyclic dependency | ||
type crosschainKeeper interface { | ||
GetStoreKey() storetypes.StoreKey | ||
GetCodec() codec.Codec | ||
GetAllCrossChainTx(ctx sdk.Context) []types.CrossChainTx | ||
|
||
SetCrossChainTx(ctx sdk.Context, cctx types.CrossChainTx) | ||
AddFinalizedInbound(ctx sdk.Context, inboundTxHash string, senderChainID int64, height uint64) | ||
|
||
SetZetaAccounting(ctx sdk.Context, accounting types.ZetaAccounting) | ||
} | ||
|
||
// MigrateStore migrates the x/crosschain module state from the consensus version 4 to 5 | ||
// It resets the aborted zeta amount to use the inbound tx amount instead in situations where the outbound cctx is never created. | ||
func MigrateStore(ctx sdk.Context, crosschainKeeper crosschainKeeper, observerKeeper types.ObserverKeeper) error { | ||
err := SetZetaAccounting(ctx, crosschainKeeper, observerKeeper) | ||
if err != nil { | ||
return err | ||
} | ||
ResetTestnetNonce(ctx, observerKeeper) | ||
|
||
return nil | ||
} | ||
|
||
func ResetTestnetNonce( | ||
ctx sdk.Context, | ||
observerKeeper types.ObserverKeeper, | ||
) { | ||
tss, found := observerKeeper.GetTSS(ctx) | ||
if !found { | ||
return | ||
} | ||
for chain, nonce := range CurrentTestnetChains() { | ||
cn, found := observerKeeper.GetChainNonces(ctx, chain.ChainName.String()) | ||
if !found { | ||
continue | ||
} | ||
cn.Nonce = nonce.nonceHigh | ||
observerKeeper.SetChainNonces(ctx, cn) | ||
pn, found := observerKeeper.GetPendingNonces(ctx, tss.TssPubkey, chain.ChainId) | ||
if !found { | ||
continue | ||
} | ||
pn.NonceLow = int64(nonce.nonceLow) | ||
pn.NonceHigh = int64(nonce.nonceHigh) | ||
observerKeeper.SetPendingNonces(ctx, pn) | ||
} | ||
} | ||
|
||
type Nonce struct { | ||
nonceHigh uint64 | ||
nonceLow uint64 | ||
} | ||
|
||
func CurrentTestnetChains() map[common.Chain]Nonce { | ||
return map[common.Chain]Nonce{ | ||
common.GoerliChain(): {nonceHigh: 226841, nonceLow: 226841}, | ||
common.MumbaiChain(): {nonceHigh: 200599, nonceLow: 200599}, | ||
common.BscTestnetChain(): {nonceHigh: 110454, nonceLow: 110454}, | ||
common.BtcTestNetChain(): {nonceHigh: 4881, nonceLow: 4881}, | ||
} | ||
} | ||
|
||
func SetZetaAccounting( | ||
ctx sdk.Context, | ||
crosschainKeeper crosschainKeeper, | ||
observerKeeper types.ObserverKeeper, | ||
) error { | ||
ccctxList := crosschainKeeper.GetAllCrossChainTx(ctx) | ||
abortedAmountZeta := sdkmath.ZeroUint() | ||
for _, cctx := range ccctxList { | ||
if cctx.CctxStatus.Status == types.CctxStatus_Aborted { | ||
|
||
switch cctx.InboundTxParams.CoinType { | ||
case common.CoinType_ERC20: | ||
{ | ||
receiverChain := observerKeeper.GetSupportedChainFromChainID(ctx, cctx.GetCurrentOutTxParam().ReceiverChainId) | ||
if receiverChain == nil { | ||
ctx.Logger().Error(fmt.Sprintf("Error getting chain from chain id: %d , cctx index", cctx.GetCurrentOutTxParam().ReceiverChainId), cctx.Index) | ||
continue | ||
} | ||
// There is a chance that this cctx has already been refunded, so we set the isRefunded flag to true. | ||
// Even though, there is a slight possibility that the refund tx failed when doing an auto refund; there is no way for us to know. Which is why we can mark this type of cctx as non-refundable | ||
// Auto refunds are done for ERC20 cctx's when the receiver chain is a zeta chain. | ||
if receiverChain.IsZetaChain() { | ||
cctx.CctxStatus.IsAbortRefunded = true | ||
} else { | ||
cctx.CctxStatus.IsAbortRefunded = false | ||
} | ||
} | ||
case common.CoinType_Zeta: | ||
{ | ||
// add the required amount into the zeta accounting. | ||
// GetAbortedAmount replaces using Outbound Amount directly, to make sure we refund the amount deposited by the user if the outbound is never created and the cctx is aborted. | ||
// For these cctx's we allow the refund to be processed later and the Aborted amount would be adjusted when the refund is processed. | ||
abortedValue := GetAbortedAmount(cctx) | ||
abortedAmountZeta = abortedAmountZeta.Add(abortedValue) | ||
cctx.CctxStatus.IsAbortRefunded = false | ||
|
||
} | ||
case common.CoinType_Gas: | ||
{ | ||
// CointType gas can be processed as normal and we can issue the refund using the admin refund tx . | ||
cctx.CctxStatus.IsAbortRefunded = false | ||
} | ||
} | ||
crosschainKeeper.SetCrossChainTx(ctx, cctx) | ||
} | ||
|
||
} | ||
crosschainKeeper.SetZetaAccounting(ctx, types.ZetaAccounting{AbortedZetaAmount: abortedAmountZeta}) | ||
|
||
return nil | ||
} | ||
func GetAbortedAmount(cctx types.CrossChainTx) sdkmath.Uint { | ||
if cctx.OutboundTxParams != nil && !cctx.GetCurrentOutTxParam().Amount.IsZero() { | ||
return cctx.GetCurrentOutTxParam().Amount | ||
} | ||
if cctx.InboundTxParams != nil { | ||
return cctx.InboundTxParams.Amount | ||
} | ||
|
||
return sdkmath.ZeroUint() | ||
} |
Oops, something went wrong.