Skip to content

Commit

Permalink
Merge branch 'develop' into feat/authority
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis committed Mar 5, 2024
2 parents a922576 + eaeabf5 commit 1f8c17b
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Dockerfile-upgrade
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ WORKDIR /go/delivery/zeta-node
RUN mkdir -p $GOPATH/bin/old
RUN mkdir -p $GOPATH/bin/new

ARG OLD_VERSION=v12.2.1
ENV NEW_VERSION=v13
ARG OLD_VERSION=v13.0.0
ENV NEW_VERSION=v14

# Build new release from the current source
COPY go.mod /go/delivery/zeta-node/
Expand Down
2 changes: 1 addition & 1 deletion app/setup_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
)

const releaseVersion = "v13"
const releaseVersion = "v14"

func SetupHandlers(app *App) {
app.UpgradeKeeper.SetUpgradeHandler(releaseVersion, func(ctx sdk.Context, plan types.Plan, vm module.VersionMap) (module.VersionMap, error) {
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# CHANGELOG
## Version: v14

### Fixes
- [1817](https://github.com/zeta-chain/node/pull/1817) - Add migration script to fix pending and chain nonces on testnet

## Unreleased

Expand Down
62 changes: 59 additions & 3 deletions x/crosschain/migrations/v5/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,69 @@ type crosschainKeeper interface {

// 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(
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 {
ctx.Logger().Info("ResetTestnetNonce: TSS not found")
return
}
for _, chainNonce := range CurrentTestnetChains() {
cn, found := observerKeeper.GetChainNonces(ctx, chainNonce.chain.ChainName.String())
if !found {
ctx.Logger().Info("ResetTestnetNonce: Chain nonce not found", "chain", chainNonce.chain.ChainName.String())
continue
}

ctx.Logger().Info("ResetTestnetNonce: Resetting chain nonce", "chain", chainNonce.chain.ChainName.String())

cn.Nonce = chainNonce.nonceHigh
observerKeeper.SetChainNonces(ctx, cn)

pn, found := observerKeeper.GetPendingNonces(ctx, tss.TssPubkey, chainNonce.chain.ChainId)
if !found {
continue
}
// #nosec G701 always in range for testnet chains
pn.NonceLow = int64(chainNonce.nonceLow)
// #nosec G701 always in range for testnet chains
pn.NonceHigh = int64(chainNonce.nonceHigh)
observerKeeper.SetPendingNonces(ctx, pn)
}
}

type TestnetNonce struct {
chain common.Chain
nonceHigh uint64
nonceLow uint64
}

func CurrentTestnetChains() []TestnetNonce {
return []TestnetNonce{
{chain: common.GoerliChain(), nonceHigh: 226841, nonceLow: 226841},
{chain: common.MumbaiChain(), nonceHigh: 200599, nonceLow: 200599},
{chain: common.BscTestnetChain(), nonceHigh: 110454, nonceLow: 110454},
{chain: 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 {
Expand Down Expand Up @@ -77,7 +134,6 @@ func MigrateStore(

return nil
}

func GetAbortedAmount(cctx types.CrossChainTx) sdkmath.Uint {
if cctx.OutboundTxParams != nil && !cctx.GetCurrentOutTxParam().Amount.IsZero() {
return cctx.GetCurrentOutTxParam().Amount
Expand Down
111 changes: 111 additions & 0 deletions x/crosschain/migrations/v5/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import (
"github.com/stretchr/testify/require"
"github.com/zeta-chain/zetacore/common"
keepertest "github.com/zeta-chain/zetacore/testutil/keeper"
"github.com/zeta-chain/zetacore/testutil/sample"
crosschainkeeper "github.com/zeta-chain/zetacore/x/crosschain/keeper"
v5 "github.com/zeta-chain/zetacore/x/crosschain/migrations/v5"
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
observertypes "github.com/zeta-chain/zetacore/x/observer/types"
)

func TestMigrateStore(t *testing.T) {
Expand Down Expand Up @@ -61,6 +63,115 @@ func TestMigrateStore(t *testing.T) {

}

func TestResetTestnetNonce(t *testing.T) {
t.Run("reset only testnet nonce without changing mainnet chains", func(t *testing.T) {
k, ctx, _, zk := keepertest.CrosschainKeeper(t)
testnetChains := []common.Chain{common.GoerliChain(), common.MumbaiChain(), common.BscTestnetChain(), common.BtcTestNetChain()}
mainnetChains := []common.Chain{common.EthChain(), common.BscMainnetChain(), common.BtcMainnetChain()}
nonceLow := int64(1)
nonceHigh := int64(10)
tss := sample.Tss()
zk.ObserverKeeper.SetTSS(ctx, tss)
for _, chain := range mainnetChains {
zk.ObserverKeeper.SetChainNonces(ctx, observertypes.ChainNonces{
Index: chain.ChainName.String(),
ChainId: chain.ChainId,
Nonce: uint64(nonceHigh),
})
zk.ObserverKeeper.SetPendingNonces(ctx, observertypes.PendingNonces{
Tss: tss.TssPubkey,
ChainId: chain.ChainId,
NonceLow: nonceLow,
NonceHigh: nonceHigh,
})
}
for _, chain := range testnetChains {
zk.ObserverKeeper.SetPendingNonces(ctx, observertypes.PendingNonces{
Tss: tss.TssPubkey,
ChainId: chain.ChainId,
NonceLow: nonceLow,
NonceHigh: nonceHigh,
})
zk.ObserverKeeper.SetChainNonces(ctx, observertypes.ChainNonces{
Index: chain.ChainName.String(),
ChainId: chain.ChainId,
Nonce: uint64(nonceHigh),
})
}
err := v5.MigrateStore(ctx, k, zk.ObserverKeeper)
require.NoError(t, err)
assertValues := map[common.Chain]int64{
common.GoerliChain(): 226841,
common.MumbaiChain(): 200599,
common.BscTestnetChain(): 110454,
common.BtcTestNetChain(): 4881,
}

for _, chain := range testnetChains {
pn, found := zk.ObserverKeeper.GetPendingNonces(ctx, tss.TssPubkey, chain.ChainId)
require.True(t, found)
require.Equal(t, assertValues[chain], pn.NonceHigh)
require.Equal(t, assertValues[chain], pn.NonceLow)
cn, found := zk.ObserverKeeper.GetChainNonces(ctx, chain.ChainName.String())
require.True(t, found)
require.Equal(t, uint64(assertValues[chain]), cn.Nonce)
}
for _, chain := range mainnetChains {
pn, found := zk.ObserverKeeper.GetPendingNonces(ctx, tss.TssPubkey, chain.ChainId)
require.True(t, found)
require.Equal(t, nonceHigh, pn.NonceHigh)
require.Equal(t, nonceLow, pn.NonceLow)
cn, found := zk.ObserverKeeper.GetChainNonces(ctx, chain.ChainName.String())
require.True(t, found)
require.Equal(t, uint64(nonceHigh), cn.Nonce)
}
})

t.Run("reset nonce even if some chain values are missing", func(t *testing.T) {
k, ctx, _, zk := keepertest.CrosschainKeeper(t)
testnetChains := []common.Chain{common.GoerliChain()}
nonceLow := int64(1)
nonceHigh := int64(10)
tss := sample.Tss()
zk.ObserverKeeper.SetTSS(ctx, tss)
for _, chain := range testnetChains {
zk.ObserverKeeper.SetPendingNonces(ctx, observertypes.PendingNonces{
Tss: tss.TssPubkey,
ChainId: chain.ChainId,
NonceLow: nonceLow,
NonceHigh: nonceHigh,
})
zk.ObserverKeeper.SetChainNonces(ctx, observertypes.ChainNonces{
Index: chain.ChainName.String(),
ChainId: chain.ChainId,
Nonce: uint64(nonceHigh),
})
}
err := v5.MigrateStore(ctx, k, zk.ObserverKeeper)
require.NoError(t, err)
assertValuesSet := map[common.Chain]int64{
common.GoerliChain(): 226841,
}
assertValuesNotSet := []common.Chain{common.MumbaiChain(), common.BscTestnetChain(), common.BtcTestNetChain()}

for _, chain := range testnetChains {
pn, found := zk.ObserverKeeper.GetPendingNonces(ctx, tss.TssPubkey, chain.ChainId)
require.True(t, found)
require.Equal(t, assertValuesSet[chain], pn.NonceHigh)
require.Equal(t, assertValuesSet[chain], pn.NonceLow)
cn, found := zk.ObserverKeeper.GetChainNonces(ctx, chain.ChainName.String())
require.True(t, found)
require.Equal(t, uint64(assertValuesSet[chain]), cn.Nonce)
}
for _, chain := range assertValuesNotSet {
_, found := zk.ObserverKeeper.GetPendingNonces(ctx, tss.TssPubkey, chain.ChainId)
require.False(t, found)
_, found = zk.ObserverKeeper.GetChainNonces(ctx, chain.ChainName.String())
require.False(t, found)
}
})
}

func CrossChainTxList(count int) []crosschaintypes.CrossChainTx {
cctxList := make([]crosschaintypes.CrossChainTx, count+100)
i := 0
Expand Down
2 changes: 1 addition & 1 deletion x/crosschain/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
}

// ConsensusVersion implements AppModule/ConsensusVersion.
func (AppModule) ConsensusVersion() uint64 { return 4 }
func (AppModule) ConsensusVersion() uint64 { return 5 }

// BeginBlock executes all ABCI BeginBlock logic respective to the crosschain module.
func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
Expand Down
3 changes: 2 additions & 1 deletion zetaclient/bitcoin/bitcoin_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ import (
)

const (
DynamicDepositorFeeHeight = 832000 // Bitcoin block height to switch to dynamic depositor fee
// The starting height (Bitcoin mainnet) from which dynamic depositor fee will take effect
DynamicDepositorFeeHeight = 834500
)

var _ interfaces.ChainClient = &BTCChainClient{}
Expand Down

0 comments on commit 1f8c17b

Please sign in to comment.