Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: tss migration e2e test #2440

Merged
merged 45 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
aa45d2f
add new runner for migration tests
kingpinXD Jun 21, 2024
a1b4c4c
skip adding new keygen
kingpinXD Jun 21, 2024
ed3b964
skip adding new keygen
kingpinXD Jun 21, 2024
2d360bc
modify btc runner
kingpinXD Jun 21, 2024
405d4ef
tss fund migrate test for eth
kingpinXD Jun 21, 2024
b1dc7ff
add queries for tss funds migrator info
kingpinXD Jun 21, 2024
635e110
add changelog
kingpinXD Jun 21, 2024
cf6696e
fix lint messages
kingpinXD Jun 21, 2024
40f5478
Merge branch 'query-tss-funds-migrator' into tss-migration-e2e-test
kingpinXD Jun 24, 2024
1a6a23e
refactor keygen
kingpinXD Jun 26, 2024
6811b04
refactor keygen
kingpinXD Jun 26, 2024
1894cb5
rearrange keygen creations
kingpinXD Jun 27, 2024
a4547a9
rearrange keygen creations
kingpinXD Jun 27, 2024
9d77dba
modify accounting
kingpinXD Jun 27, 2024
9616475
rebase develop
kingpinXD Jun 28, 2024
2a6e72f
rebase develop
kingpinXD Jun 28, 2024
522c248
add retest after migration
kingpinXD Jul 4, 2024
d4741de
add checks for error messages
kingpinXD Jul 7, 2024
d10de0d
Merge branch 'develop' into tss-migration-test
kingpinXD Jul 7, 2024
0dca846
add unit test for CheckMigration
kingpinXD Jul 7, 2024
1469b73
fix unit tests for update msgUpdateTSS
kingpinXD Jul 7, 2024
353f962
fix some lint issues and rename all runners to r
kingpinXD Jul 7, 2024
4ff9b04
fix some lint issues and rename all runners to r
kingpinXD Jul 7, 2024
897fdb3
add changelog
kingpinXD Jul 7, 2024
263131c
fix lint errors
kingpinXD Jul 8, 2024
6f5de14
fix lint errors
kingpinXD Jul 8, 2024
db6735c
removed debug logs
kingpinXD Jul 8, 2024
614eae6
add comments for zetasupervisor lib
kingpinXD Jul 8, 2024
f487487
add new user for migration tests
kingpinXD Jul 8, 2024
3b095a5
add new user for migration tests
kingpinXD Jul 8, 2024
248aa74
change name to start-tss-migration-test
kingpinXD Jul 9, 2024
aba4198
add changes for comments 1
kingpinXD Jul 11, 2024
ba3540d
add changes for comments 1
kingpinXD Jul 11, 2024
8ca3864
rename to CheckIfMigrationDeposit
kingpinXD Jul 11, 2024
69bfc25
rename to CheckIfMigrationDeposit
kingpinXD Jul 11, 2024
e248ad0
use cctx_Gateway to check cctx
kingpinXD Jul 11, 2024
1ffe907
add Tss migration to e2e.yml
kingpinXD Jul 12, 2024
be5054d
move to a sub function
kingpinXD Jul 14, 2024
43073d4
resolve comments 2
kingpinXD Jul 15, 2024
825ed46
rebase develop
kingpinXD Jul 15, 2024
e429152
resolve comments 3
kingpinXD Jul 16, 2024
a50d868
add todo
kingpinXD Jul 16, 2024
c2eced5
resolve comments 4
kingpinXD Jul 16, 2024
f9f2a38
rebase develop 2
kingpinXD Jul 16, 2024
cb07bdb
Update .github/workflows/e2e.yml
kingpinXD Jul 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ build-testnet-ubuntu: go.sum
docker rm temp-container

install: go.sum
@echo "--> Installing zetacored & zetaclientd"
@echo "--> Installing zetacored ,zetaclientd and zetaclientd-supervisor"
@go install -mod=readonly $(BUILD_FLAGS) ./cmd/zetacored
@go install -mod=readonly $(BUILD_FLAGS) ./cmd/zetaclientd
@go install -mod=readonly $(BUILD_FLAGS) ./cmd/zetaclientd-supervisor
Expand Down Expand Up @@ -254,6 +254,11 @@ start-stress-test: zetanode
@echo "--> Starting stress test"
cd contrib/localnet/ && $(DOCKER) compose --profile stress -f docker-compose.yml up -d

start-tss-migration-test: zetanode
@echo "--> Starting migration test"
export E2E_ARGS="--test-migration" && \
cd contrib/localnet/ && $(DOCKER) compose up -d

###############################################################################
### Upgrade Tests ###
###############################################################################
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
* [2349](https://github.com/zeta-chain/node/pull/2349) - add TestBitcoinDepositRefund and WithdrawBitcoinMultipleTimes E2E tests
* [2368](https://github.com/zeta-chain/node/pull/2368) - eliminate panic usage across testing suite
* [2369](https://github.com/zeta-chain/node/pull/2369) - fix random cross-chain swap failure caused by using tiny UTXO
* [2440](https://github.com/zeta-chain/node/pull/2440) - Add e2e test for Tss migration


### Fixes
Expand Down
126 changes: 125 additions & 1 deletion cmd/zetaclientd-supervisor/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"runtime"
"strings"
"sync"
"syscall"
"time"

"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
Expand All @@ -20,6 +21,7 @@ import (
"github.com/rs/zerolog"
"google.golang.org/grpc"

observertypes "github.com/zeta-chain/zetacore/x/observer/types"
"github.com/zeta-chain/zetacore/zetaclient/config"
)

Expand Down Expand Up @@ -66,6 +68,7 @@ type zetaclientdSupervisor struct {
upgradesDir string
upgradePlanName string
enableAutoDownload bool
restartChan chan os.Signal
}

func newZetaclientdSupervisor(
Expand All @@ -81,19 +84,24 @@ func newZetaclientdSupervisor(
if err != nil {
return nil, fmt.Errorf("grpc dial: %w", err)
}

// these signals will result in the supervisor process only restarting zetaclientd
restartChan := make(chan os.Signal, 1)
return &zetaclientdSupervisor{
zetacoredConn: conn,
logger: logger,
reloadSignals: make(chan bool, 1),
upgradesDir: defaultUpgradesDir,
enableAutoDownload: enableAutoDownload,
restartChan: restartChan,
}, nil
}

func (s *zetaclientdSupervisor) Start(ctx context.Context) {
go s.watchForVersionChanges(ctx)
go s.handleCoreUpgradePlan(ctx)
go s.handleNewKeygen(ctx)
go s.handleNewTssKeyGeneration(ctx)
go s.handleTssUpdate(ctx)
}

func (s *zetaclientdSupervisor) WaitForReloadSignal(ctx context.Context) {
Expand Down Expand Up @@ -169,6 +177,122 @@ func (s *zetaclientdSupervisor) watchForVersionChanges(ctx context.Context) {
}
}

func (s *zetaclientdSupervisor) handleTssUpdate(ctx context.Context) {
maxRetries := 11
retryInterval := 5 * time.Second

for i := 0; i < maxRetries; i++ {
client := observertypes.NewQueryClient(s.zetacoredConn)
tss, err := client.TSS(ctx, &observertypes.QueryGetTSSRequest{})
if err != nil {
s.logger.Warn().Err(err).Msg("unable to get original tss")
time.Sleep(retryInterval)
continue
}
i = 0
for {
select {
case <-time.After(time.Second):
case <-ctx.Done():
return
}
tssNew, err := client.TSS(ctx, &observertypes.QueryGetTSSRequest{})
if err != nil {
s.logger.Warn().Err(err).Msg("unable to get tss")
continue
}

if tssNew.TSS.TssPubkey == tss.TSS.TssPubkey {
continue
}

tss = tssNew
s.logger.Info().
Msgf("tss address is updated from %s to %s", tss.TSS.TssPubkey, tssNew.TSS.TssPubkey)
time.Sleep(6 * time.Second)
s.logger.Info().Msg("restarting zetaclientd to update tss address")
s.restartChan <- syscall.SIGHUP
}
}
s.logger.Warn().Msg("handleTssUpdate exiting without success")
}

func (s *zetaclientdSupervisor) handleNewTssKeyGeneration(ctx context.Context) {
maxRetries := 11
retryInterval := 5 * time.Second

for i := 0; i < maxRetries; i++ {
client := observertypes.NewQueryClient(s.zetacoredConn)
alltss, err := client.TssHistory(ctx, &observertypes.QueryTssHistoryRequest{})
if err != nil {
s.logger.Warn().Err(err).Msg("unable to get tss original history")
time.Sleep(retryInterval)
continue
}
i = 0
tssLenCurrent := len(alltss.TssList)
for {
select {
case <-time.After(time.Second):
case <-ctx.Done():
return
}
tssListNew, err := client.TssHistory(ctx, &observertypes.QueryTssHistoryRequest{})
if err != nil {
s.logger.Warn().Err(err).Msg("unable to get tss new history")
continue
}
tssLenUpdated := len(tssListNew.TssList)

if tssLenUpdated == tssLenCurrent {
continue
}
if tssLenUpdated < tssLenCurrent {
tssLenCurrent = len(tssListNew.TssList)
continue
}

tssLenCurrent = tssLenUpdated
s.logger.Info().Msgf("tss list updated from %d to %d", tssLenCurrent, tssLenUpdated)
time.Sleep(5 * time.Second)
s.logger.Info().Msg("restarting zetaclientd to update tss list")
s.restartChan <- syscall.SIGHUP
}
}
s.logger.Warn().Msg("handleNewTssKeyGeneration exiting without success")
}

func (s *zetaclientdSupervisor) handleNewKeygen(ctx context.Context) {
client := observertypes.NewQueryClient(s.zetacoredConn)
prevKeygenBlock := int64(0)
for {
select {
case <-time.After(time.Second):
case <-ctx.Done():
return
}
resp, err := client.Keygen(ctx, &observertypes.QueryGetKeygenRequest{})
if err != nil {
s.logger.Warn().Err(err).Msg("unable to get keygen")
continue
}
if resp.Keygen == nil {
s.logger.Warn().Err(err).Msg("keygen is nil")
continue
}

if resp.Keygen.Status != observertypes.KeygenStatus_PendingKeygen {
continue
}
keygenBlock := resp.Keygen.BlockNumber
if prevKeygenBlock == keygenBlock {
continue
}
prevKeygenBlock = keygenBlock
s.logger.Info().Msgf("got new keygen at block %d", keygenBlock)
s.restartChan <- syscall.SIGHUP
}
}
func (s *zetaclientdSupervisor) handleCoreUpgradePlan(ctx context.Context) {
client := upgradetypes.NewQueryClient(s.zetacoredConn)

Expand Down
7 changes: 2 additions & 5 deletions cmd/zetaclientd-supervisor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ func main() {
shutdownChan := make(chan os.Signal, 1)
signal.Notify(shutdownChan, syscall.SIGINT, syscall.SIGTERM)

// these signals will result in the supervisor process only restarting zetaclientd
restartChan := make(chan os.Signal, 1)
signal.Notify(restartChan, syscall.SIGHUP)

hotkeyPassword, tssPassword, err := promptPasswords()
if err != nil {
logger.Error().Err(err).Msg("unable to get passwords")
Expand All @@ -53,6 +49,7 @@ func main() {
os.Exit(1)
}
supervisor.Start(ctx)
signal.Notify(supervisor.restartChan, syscall.SIGHUP)

shouldRestart := true
for shouldRestart {
Expand Down Expand Up @@ -82,7 +79,7 @@ func main() {
select {
case <-ctx.Done():
return nil
case sig := <-restartChan:
case sig := <-supervisor.restartChan:
logger.Info().Msgf("got signal %d, sending SIGINT to zetaclientd", sig)
case sig := <-shutdownChan:
logger.Info().Msgf("got signal %d, shutting down", sig)
Expand Down
Loading
Loading