From 70005090bff88a17bfdbc2a9ad710c7c8f55dcba Mon Sep 17 00:00:00 2001 From: p0p3yee Date: Fri, 5 Apr 2024 12:21:48 -0400 Subject: [PATCH] Add handle override pubkey event --- cmd/version.go | 2 +- internal/fairyringclient/fairyringclient.go | 27 +++++++++++++++++++++ internal/fairyringclient/types.go | 5 ++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/cmd/version.go b/cmd/version.go index cac8fbf..e12cc91 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -5,7 +5,7 @@ import ( "github.com/spf13/cobra" ) -const ClientVersion = "v0.5.1" +const ClientVersion = "v0.5.2" // configCmd represents the config command var versionCmd = &cobra.Command{ diff --git a/internal/fairyringclient/fairyringclient.go b/internal/fairyringclient/fairyringclient.go index 28c8269..f00cf59 100644 --- a/internal/fairyringclient/fairyringclient.go +++ b/internal/fairyringclient/fairyringclient.go @@ -284,6 +284,9 @@ func handleTxEvents(txOut <-chan coretypes.ResultEvent) { case "queued-pubkey-created.pubkey": handleNewPubKeyEvent(result.Events) break + case "pubkey-overrode.pubkey": + handlePubKeyOverrodeEvent(result.Events) + break } } } @@ -343,6 +346,30 @@ func handleStartSubmitGeneralKeyShareEvent(identity string) { log.Printf("Submit General KeyShare for Identity %s Confirmed\n", identity) } +func handlePubKeyOverrodeEvent(data map[string][]string) { + pubKey, found := data["pubkey-overrode.pubkey"] + if !found { + return + } + + log.Printf("Old Pubkey Overrode, New Pubkey found: %s\n", pubKey[0]) + + for { + err := validatorCosmosClient.UpdateKeyShareFromChain(false) + if err != nil { + time.Sleep(3 * time.Second) + continue + } + log.Printf( + "Successfully Updated Shares for the current overrode round: %s | Index: %d", + validatorCosmosClient.CurrentShare.Share.Value.String(), + validatorCosmosClient.CurrentShare.Index, + ) + validatorCosmosClient.RemovePendingShare() + break + } +} + func handleNewPubKeyEvent(data map[string][]string) { pubKey, found := data["queued-pubkey-created.pubkey"] if !found { diff --git a/internal/fairyringclient/types.go b/internal/fairyringclient/types.go index 9fbcbcc..4b193fe 100644 --- a/internal/fairyringclient/types.go +++ b/internal/fairyringclient/types.go @@ -91,6 +91,11 @@ func (v *ValidatorClients) RemoveCurrentShare() { v.CurrentShareExpiryBlock = 0 } +func (v *ValidatorClients) RemovePendingShare() { + v.PendingShare = nil + v.PendingShareExpiryBlock = 0 +} + func (v *ValidatorClients) UpdateKeyShareFromChain(forNextRound bool) error { share, shareIndex, expiry, err := v.CosmosClient.GetKeyShare(forNextRound) if err != nil {