Skip to content

Commit

Permalink
resolve comments 3
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD committed Jul 16, 2024
1 parent 825ed46 commit e429152
Show file tree
Hide file tree
Showing 13 changed files with 114 additions and 70 deletions.
2 changes: 1 addition & 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 and zetaclientd-supervisor"
@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
22 changes: 13 additions & 9 deletions cmd/zetaclientd/keygen_tss.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/zeta-chain/zetacore/pkg/chains"
observertypes "github.com/zeta-chain/zetacore/x/observer/types"
"github.com/zeta-chain/zetacore/zetaclient/chains/interfaces"
"github.com/zeta-chain/zetacore/zetaclient/context"
zctx "github.com/zeta-chain/zetacore/zetaclient/context"
"github.com/zeta-chain/zetacore/zetaclient/metrics"
mc "github.com/zeta-chain/zetacore/zetaclient/tss"
Expand All @@ -30,12 +29,15 @@ import (
// In case of a successful keygen a TSS success vote is broadcasted to zetacore and the newly generate TSS is tested. The generated keyshares are stored in the correct directory
// In case of a failed keygen a TSS failed vote is broadcasted to zetacore.
func GenerateTSS(
appContext *context.AppContext,
ctx context.Context,
logger zerolog.Logger,
zetaCoreClient *zetacore.Client,
keygenTssServer *tss.TssServer) error {
keygenLogger := logger.With().Str("module", "keygen").Logger()

app, err := zctx.FromContext(ctx)
if err != nil {
return err
}
// If Keygen block is set it will try to generate new TSS at the block
// This is a blocking thread and will wait until the ceremony is complete successfully
// If the TSS generation is unsuccessful , it will loop indefinitely until a new TSS is generated
Expand All @@ -62,7 +64,7 @@ func GenerateTSS(
// Try generating TSS at keygen block , only when status is pending keygen and generation has not been tried at the block
if keyGen.Status == observertypes.KeygenStatus_PendingKeygen {
// Return error if RPC is not working
currentBlock, err := zetaCoreClient.GetBlockHeight()
currentBlock, err := zetaCoreClient.GetBlockHeight(ctx)
if err != nil {
keygenLogger.Error().Err(err).Msg("GetBlockHeight RPC error")
continue
Expand All @@ -83,10 +85,11 @@ func GenerateTSS(
}
// Try keygen only once at a particular block, irrespective of whether it is successful or failure
triedKeygenAtBlock = true
newPubkey, err := keygenTss(keyGen, *keygenTssServer, zetaCoreClient, keygenLogger)
newPubkey, err := keygenTss(ctx, keyGen, *keygenTssServer, zetaCoreClient, keygenLogger)
if err != nil {
keygenLogger.Error().Err(err).Msg("keygenTss error")
tssFailedVoteHash, err := zetaCoreClient.SetTSS("", keyGen.BlockNumber, chains.ReceiveStatus_failed)
tssFailedVoteHash, err := zetaCoreClient.PostVoteTSS(ctx,
"", keyGen.BlockNumber, chains.ReceiveStatus_failed)
if err != nil {
keygenLogger.Error().Err(err).Msg("Failed to broadcast Failed TSS Vote to zetacore")
return err
Expand All @@ -95,7 +98,7 @@ func GenerateTSS(
continue
}
// If TSS is successful , broadcast the vote to zetacore and also set the Pubkey
tssSuccessVoteHash, err := zetaCoreClient.SetTSS(
tssSuccessVoteHash, err := zetaCoreClient.PostVoteTSS(ctx,
newPubkey,
keyGen.BlockNumber,
chains.ReceiveStatus_success,
Expand Down Expand Up @@ -123,6 +126,7 @@ func GenerateTSS(
// If the keygen is successful, the function returns the new TSS pubkey.
// If the keygen is unsuccessful, the function posts blame and returns an error.
func keygenTss(
ctx context.Context,
keyGen observertypes.Keygen,
tssServer tss.TssServer,
zetacoreClient interfaces.ZetacoreClient,
Expand All @@ -140,10 +144,10 @@ func keygenTss(
return "", err
}
index := fmt.Sprintf("keygen-%s-%d", digest, keyGen.BlockNumber)
zetaHash, err := tss.ZetacoreClient.PostVoteBlameData(
zetaHash, err := zetacoreClient.PostVoteBlameData(
ctx,
&res.Blame,
tss.ZetacoreClient.Chain().ChainId,
zetacoreClient.Chain().ChainId,
index,
)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/zetaclientd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func start(_ *cobra.Command, _ []string) error {

// Generate a new TSS if keygen is set and add it into the tss server
// If TSS has already been generated, and keygen was successful ; we use the existing TSS
err = GenerateTSS(appContext, masterLogger, zetacoreClient, server)
err = GenerateTSS(ctx, masterLogger, zetacoreClient, server)
if err != nil {
return err
}
Expand All @@ -223,7 +223,7 @@ func start(_ *cobra.Command, _ []string) error {
bitcoinChainID = btcChain.ChainId
}
tss, err := mc.NewTSS(
appContext,
ctx,
zetacoreClient,
tssHistoricalList,
bitcoinChainID,
Expand Down
2 changes: 1 addition & 1 deletion cmd/zetae2e/config/localnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ additional_accounts:
private_key: "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
user_migration:
bech32_address: "zeta1pvtxa708yvdmszn687nne6nl8qn704daf420xz"
evm_address: "0x0b166ef9e7231bb80a7a3fa73cea7f3827e7d5bd"
evm_address: "0x0B166ef9e7231Bb80A7A3FA73CEA7F3827E7D5BD"
private_key: "0bcc2fa28b526f90e1d54648d612db901e860bf68248555593f91ea801c6b482"
policy_accounts:
emergency_policy_account:
Expand Down
1 change: 0 additions & 1 deletion cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,6 @@ func runTSSMigrationTest(deployerRunner *runner.E2ERunner, logger *runner.Logger
logger.Print("❌ post migration tests failed")
os.Exit(1)
}

}

func must[T any](v T, err error) T {
Expand Down
6 changes: 3 additions & 3 deletions cmd/zetae2e/local/post_migration.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package local

import (
"fmt"
"time"

"github.com/fatih/color"
"github.com/pkg/errors"

"github.com/zeta-chain/zetacore/e2e/config"
"github.com/zeta-chain/zetacore/e2e/e2etests"
Expand Down Expand Up @@ -40,11 +40,11 @@ func postMigrationTestRoutine(
testNames...,
)
if err != nil {
return fmt.Errorf("postMigrationRunner tests failed: %v", err)
return errors.Wrap(err, "postMigrationRunner tests failed")
}

if err := postMigrationRunner.RunE2ETests(testsToRun); err != nil {
return fmt.Errorf("postMigrationRunner tests failed: %v", err)
return errors.Wrap(err, "postMigrationRunner tests failed")
}

if err := postMigrationRunner.CheckBtcTSSBalance(); err != nil {
Expand Down
10 changes: 6 additions & 4 deletions e2e/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ func (a AdditionalAccounts) AsSlice() []Account {
a.UserEther,
a.UserMisc,
a.UserAdmin,
a.UserMigration,
}
}

Expand Down Expand Up @@ -283,19 +284,20 @@ func (c *Config) GenerateKeys() error {
if err != nil {
return err
}
c.PolicyAccounts.EmergencyPolicyAccount, err = generateAccount()
c.AdditionalAccounts.UserMigration, err = generateAccount()
if err != nil {
return err

Check warning on line 289 in e2e/config/config.go

View check run for this annotation

Codecov / codecov/patch

e2e/config/config.go#L289

Added line #L289 was not covered by tests
}
c.PolicyAccounts.OperationalPolicyAccount, err = generateAccount()

c.PolicyAccounts.EmergencyPolicyAccount, err = generateAccount()
if err != nil {
return err
}
c.PolicyAccounts.AdminPolicyAccount, err = generateAccount()
c.PolicyAccounts.OperationalPolicyAccount, err = generateAccount()
if err != nil {
return err
}
c.AdditionalAccounts.UserMigration, err = generateAccount()
c.PolicyAccounts.AdminPolicyAccount, err = generateAccount()
if err != nil {
return err
}
Expand Down
20 changes: 10 additions & 10 deletions e2e/e2etests/test_migrate_tss.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ func TestMigrateTSS(r *runner.E2ERunner, _ []string) {
// Pause inbound procoessing for tss migration
r.Logger.Info("Pause inbound processing")
msg := observertypes.NewMsgDisableCCTX(
r.ZetaTxServer.GetAccountAddress(0),
r.ZetaTxServer.MustGetAccountAddressFromName(utils.EmergencyPolicyName),
false,
true)
_, err := r.ZetaTxServer.BroadcastTx(utils.FungibleAdminName, msg)
_, err := r.ZetaTxServer.BroadcastTx(utils.EmergencyPolicyName, msg)
require.NoError(r, err)

Check warning on line 35 in e2e/e2etests/test_migrate_tss.go

View check run for this annotation

Codecov / codecov/patch

e2e/e2etests/test_migrate_tss.go#L29-L35

Added lines #L29 - L35 were not covered by tests

// Migrate btc
Expand All @@ -53,11 +53,11 @@ func TestMigrateTSS(r *runner.E2ERunner, _ []string) {
// #nosec G701 e2eTest - always in range
migrationAmountBTC := sdkmath.NewUint(uint64(btcBalance * 1e8))
msgMigrateFunds := crosschaintypes.NewMsgMigrateTssFunds(
r.ZetaTxServer.GetAccountAddress(0),
r.ZetaTxServer.MustGetAccountAddressFromName(utils.AdminPolicyName),
btcChain,
migrationAmountBTC,
)
_, err = r.ZetaTxServer.BroadcastTx(utils.FungibleAdminName, msgMigrateFunds)
_, err = r.ZetaTxServer.BroadcastTx(utils.AdminPolicyName, msgMigrateFunds)
require.NoError(r, err)

Check warning on line 61 in e2e/e2etests/test_migrate_tss.go

View check run for this annotation

Codecov / codecov/patch

e2e/e2etests/test_migrate_tss.go#L54-L61

Added lines #L54 - L61 were not covered by tests

// Fetch migrator cctx for btc migration
Expand All @@ -78,11 +78,11 @@ func TestMigrateTSS(r *runner.E2ERunner, _ []string) {

// Migrate TSS funds for the eth chain
msgMigrateFunds = crosschaintypes.NewMsgMigrateTssFunds(
r.ZetaTxServer.GetAccountAddress(0),
r.ZetaTxServer.MustGetAccountAddressFromName(utils.AdminPolicyName),
evmChainID.Int64(),
tssBalanceUint,
)
_, err = r.ZetaTxServer.BroadcastTx(utils.FungibleAdminName, msgMigrateFunds)
_, err = r.ZetaTxServer.BroadcastTx(utils.AdminPolicyName, msgMigrateFunds)
require.NoError(r, err)

Check warning on line 86 in e2e/e2etests/test_migrate_tss.go

View check run for this annotation

Codecov / codecov/patch

e2e/e2etests/test_migrate_tss.go#L80-L86

Added lines #L80 - L86 were not covered by tests

// Fetch migrator cctx for eth migration
Expand Down Expand Up @@ -110,10 +110,10 @@ func TestMigrateTSS(r *runner.E2ERunner, _ []string) {
return allTss.TssList[i].FinalizedZetaHeight < allTss.TssList[j].FinalizedZetaHeight
})
msgUpdateTss := crosschaintypes.NewMsgUpdateTssAddress(
r.ZetaTxServer.GetAccountAddress(0),
r.ZetaTxServer.MustGetAccountAddressFromName(utils.AdminPolicyName),
allTss.TssList[1].TssPubkey,
)
_, err = r.ZetaTxServer.BroadcastTx(utils.FungibleAdminName, msgUpdateTss)
_, err = r.ZetaTxServer.BroadcastTx(utils.AdminPolicyName, msgUpdateTss)
require.NoError(r, err)

Check warning on line 117 in e2e/e2etests/test_migrate_tss.go

View check run for this annotation

Codecov / codecov/patch

e2e/e2etests/test_migrate_tss.go#L109-L117

Added lines #L109 - L117 were not covered by tests

// Wait for atleast one block for the TSS to be updated
Expand Down Expand Up @@ -174,9 +174,9 @@ func TestMigrateTSS(r *runner.E2ERunner, _ []string) {
require.True(r, ethTSSBalanceNew.Cmp(ethTSSBalanceOld) < 0)

Check warning on line 174 in e2e/e2etests/test_migrate_tss.go

View check run for this annotation

Codecov / codecov/patch

e2e/e2etests/test_migrate_tss.go#L173-L174

Added lines #L173 - L174 were not covered by tests

msgEnable := observertypes.NewMsgEnableCCTX(
r.ZetaTxServer.GetAccountAddress(0),
r.ZetaTxServer.MustGetAccountAddressFromName(utils.OperationalPolicyName),
true,
true)
_, err = r.ZetaTxServer.BroadcastTx(utils.FungibleAdminName, msgEnable)
_, err = r.ZetaTxServer.BroadcastTx(utils.OperationalPolicyName, msgEnable)
require.NoError(r, err)

Check warning on line 181 in e2e/e2etests/test_migrate_tss.go

View check run for this annotation

Codecov / codecov/patch

e2e/e2etests/test_migrate_tss.go#L176-L181

Added lines #L176 - L181 were not covered by tests
}
1 change: 0 additions & 1 deletion x/crosschain/keeper/cctx_orchestrator_validate_inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ func (k Keeper) CheckIfMigrationTransfer(ctx sdk.Context, msg *types.MsgVoteInbo
if ethTssAddress.Hex() == msg.Sender {
return types.ErrMigrationFromOldTss
}

}
case chains.IsBitcoinChain(chain.ChainId, additionalChains):
bitcoinParams, err := chains.BitcoinNetParamsFromChainID(chain.ChainId)
Expand Down
10 changes: 5 additions & 5 deletions zetaclient/chains/bitcoin/observer/outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,11 @@ func (ob *Observer) IsOutboundProcessed(
// It's safe to use cctx's amount to post confirmation because it has already been verified in observeOutbound()
amountInSat := params.Amount.BigInt()
if res.Confirmations < ob.ConfirmationsThreshold(amountInSat) {
ob.logger.Outbound.Debug().Msgf(
"IsOutboundProcessed: outbound not confirmed yet %d: %d",
res.Confirmations,
ob.ConfirmationsThreshold(amountInSat),
)
ob.logger.Outbound.Debug().
Int64("currentConfirmations", res.Confirmations).
Int64("requiredConfirmations", ob.ConfirmationsThreshold(amountInSat)).
Msg("IsOutboundProcessed: outbound not confirmed yet")

Check warning on line 190 in zetaclient/chains/bitcoin/observer/outbound.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/bitcoin/observer/outbound.go#L187-L190

Added lines #L187 - L190 were not covered by tests

return true, false, nil
}

Expand Down
Loading

0 comments on commit e429152

Please sign in to comment.