From bba03f87c4b2352e355eb226d60ca557020fd44e Mon Sep 17 00:00:00 2001 From: Garry Sharp <> Date: Thu, 3 Jul 2025 13:38:04 +0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Fee=20log=20cleanup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/verifierapi/fees.go | 10 ---- internal/verifierapi/verifierapi.go | 1 - plugin/fees/fees.go | 77 ++++++----------------------- plugin/fees/transaction.go | 19 +++---- 4 files changed, 23 insertions(+), 84 deletions(-) diff --git a/internal/verifierapi/fees.go b/internal/verifierapi/fees.go index 8f77eef..ab8fc8b 100644 --- a/internal/verifierapi/fees.go +++ b/internal/verifierapi/fees.go @@ -59,16 +59,13 @@ func (v VerifierApi) GetPluginPolicyFees(policyId uuid.UUID) (FeeHistoryDto, err v.logger.Debug("URL: ", url) response, err := v.get(url) if err != nil { - v.logger.WithError(err).Error("failed to get plugin policy fees") return FeeHistoryDto{}, fmt.Errorf("failed to get plugin policy fees: %w", err) } if response.StatusCode == http.StatusNotFound { - v.logger.WithError(fmt.Errorf("policy not found")).Error("policy not found for id: ", policyId.String()) return FeeHistoryDto{}, fmt.Errorf("policy not found") } if response.StatusCode != http.StatusOK { - v.logger.WithError(err).Error("failed to get plugin policy fees") return FeeHistoryDto{}, fmt.Errorf("failed to get plugin policy fees, status code: %d", response.StatusCode) } @@ -87,22 +84,17 @@ func (v VerifierApi) GetPluginPolicyFees(policyId uuid.UUID) (FeeHistoryDto, err // TODO add auth func (v VerifierApi) GetPublicKeysFees(ecdsaPublicKey string) (FeeHistoryDto, error) { url := fmt.Sprintf("/fees/publickey/%s", ecdsaPublicKey) - v.logger.Debug("Getting public key fees for public key: ", ecdsaPublicKey) - v.logger.Debug("URL: ", url) response, err := v.get(url) if err != nil { - v.logger.WithError(err).Error("failed to get public key fees") return FeeHistoryDto{}, fmt.Errorf("failed to get public key fees: %w", err) } //TODO - this probably shouldn't be a 404, just an empty wrapped response with 0 if response.StatusCode == http.StatusNotFound { - v.logger.WithError(fmt.Errorf("public key not found")).Error("public key not found for id: ", ecdsaPublicKey) return FeeHistoryDto{}, fmt.Errorf("public key not found") } if response.StatusCode != http.StatusOK { - v.logger.WithError(err).Error("failed to get public key fees") return FeeHistoryDto{}, fmt.Errorf("failed to get public key fees, status code: %d", response.StatusCode) } @@ -124,12 +116,10 @@ func (v VerifierApi) GetAllPublicKeysFees() (map[string]FeeHistoryDto, error) { v.logger.Debug("URL: ", url) response, err := v.get(url) if err != nil { - v.logger.WithError(err).Error("failed to get all public key fees") return map[string]FeeHistoryDto{}, fmt.Errorf("failed to get all public key fees: %w", err) } if response.StatusCode != http.StatusOK { - v.logger.WithError(err).Error("failed to get all public key fees") return map[string]FeeHistoryDto{}, fmt.Errorf("failed to get all public key fees, status code: %d", response.StatusCode) } diff --git a/internal/verifierapi/verifierapi.go b/internal/verifierapi/verifierapi.go index 566d9c6..b5fb932 100644 --- a/internal/verifierapi/verifierapi.go +++ b/internal/verifierapi/verifierapi.go @@ -30,7 +30,6 @@ type VerifierApi struct { } func NewVerifierApi(url string, logger *logrus.Logger) *VerifierApi { - logger.Debug("New Verifier API created with URL: ", url) return &VerifierApi{ URL: url, logger: logger, diff --git a/plugin/fees/fees.go b/plugin/fees/fees.go index 5f5e1f2..3793a06 100644 --- a/plugin/fees/fees.go +++ b/plugin/fees/fees.go @@ -142,14 +142,6 @@ func (fp FeePlugin) GetRecipeSpecification() rtypes.RecipeSchema { } } -// This wraps the logger with the plugin name and context "i.e the worker execution". -func (fp *FeePlugin) Log(level logrus.Level, args ...interface{}) { - fp.logger.WithFields(logrus.Fields{ - "plugin": "fees", - "context": "execution", - }).Log(level, args...) -} - func (fp *FeePlugin) GetPolicyFees(cfg BaseConfig) error { return nil } @@ -167,7 +159,7 @@ func (fp *FeePlugin) SigningComplete(ctx context.Context, signature tss.KeysignR // HANDLER FUNCTIONS func (fp *FeePlugin) HandleCollections(ctx context.Context, task *asynq.Task) error { - fp.Log(logrus.InfoLevel, "Starting Fee Collection Job") + fp.logger.Info("Starting Fee Collection Job") // Figure out if we're collecting fees by public key, policy, or plugin id feeCollectionFormat := FeeCollectionFormat{ @@ -175,25 +167,23 @@ func (fp *FeePlugin) HandleCollections(ctx context.Context, task *asynq.Task) er } if len(task.Payload()) != 0 { if err := json.Unmarshal(task.Payload(), &feeCollectionFormat); err != nil { - fp.Log(logrus.ErrorLevel, "Failed to unmarshal fee collection config") - return err + return fmt.Errorf("fp.HandleCollections, failed to unmarshall asynq task payload, %w", err) } } switch feeCollectionFormat.FeeCollectionType { case FeeCollectionTypeByPublicKey: - fp.Log(logrus.InfoLevel, "Collecting fees by public key") + fp.logger.Info("Collecting fees by public key") return fp.collectFeesByPublicKey(feeCollectionFormat.Value) case FeeCollectionTypeByPolicy: - fp.Log(logrus.InfoLevel, "Collecting fees by policy") + fp.logger.Info("Collecting fees by policy") return fp.collectFeesByPolicy(feeCollectionFormat.Value) case FeeCollectionTypeByPluginID: - fp.Log(logrus.InfoLevel, "Collecting fees by plugin id") + fp.logger.Info("Collecting fees by plugin id") case FeeCollectionTypeAll: - fp.Log(logrus.InfoLevel, "Collecting fees by all") + fp.logger.Info("Collecting fees by all") return fp.collectAllFees() default: - fp.Log(logrus.ErrorLevel, "Invalid fee collection type") return fmt.Errorf("invalid fee collection type") } @@ -204,45 +194,38 @@ func (fp *FeePlugin) HandleCollections(ctx context.Context, task *asynq.Task) er // Collects fee data by ... Should only be called by HandleFeeCollections func (fp *FeePlugin) collectFeesByPublicKey(publicKey string) error { - fp.Log(logrus.DebugLevel, "Collecting fees by policy: ") feesResponse, err := fp.verifierApi.GetPublicKeysFees(publicKey) if err != nil { return fmt.Errorf("failed to get plugin policy fees: %w", err) } - fp.logger.Debug("Fees response: ", feesResponse) - if feesResponse.FeesPendingCollection > 0 { - fp.Log(logrus.InfoLevel, "Fees pending collection: ", feesResponse.FeesPendingCollection) + fp.logger.Info("Fees pending collection: ", feesResponse.FeesPendingCollection) feesToCollect := []uuid.UUID{} checkAmount := 0 for _, fee := range feesResponse.Fees { - fp.Log(logrus.DebugLevel, "Fee: ", fee) if !fee.Collected { feesToCollect = append(feesToCollect, fee.ID) checkAmount += fee.Amount } } if checkAmount != feesResponse.FeesPendingCollection { - fp.Log(logrus.ErrorLevel, "Fees pending collection amount does not match the sum of the fees") return fmt.Errorf("fees pending collection amount does not match the sum of the fees") } - fp.Log(logrus.InfoLevel, "Fees to collect: ", feesToCollect) + fp.logger.Info("Fees to collect: ", feesToCollect) } else { - fp.Log(logrus.InfoLevel, "No fees pending collection") + fp.logger.Info("No fees pending collection") } return nil } // Collects fee data by ... Should only be called by HandleFeeCollections -// Not yet working func (fp *FeePlugin) collectFeesByPolicy(policyIdString string) error { - // TODO: implement logic - fp.Log(logrus.DebugLevel, "Collecting fees by policy: ") + policyId, err := uuid.Parse(policyIdString) if err != nil { return fmt.Errorf("failed to parse policy id: %w", err) @@ -252,31 +235,23 @@ func (fp *FeePlugin) collectFeesByPolicy(policyIdString string) error { return fmt.Errorf("failed to get plugin policy fees: %w", err) } - fp.logger.Debug("Fees response: ", feesResponse) - if feesResponse.FeesPendingCollection > 0 { - fp.Log(logrus.InfoLevel, "Fees pending collection: ", feesResponse.FeesPendingCollection) + fp.logger.Info("Fees pending collection: ", feesResponse.FeesPendingCollection) feesToCollect := []uuid.UUID{} checkAmount := 0 for _, fee := range feesResponse.Fees { - fp.Log(logrus.DebugLevel, "Fee: ", fee) if !fee.Collected { feesToCollect = append(feesToCollect, fee.ID) checkAmount += fee.Amount } } if checkAmount != feesResponse.FeesPendingCollection { - fp.Log(logrus.ErrorLevel, "Fees pending collection amount does not match the sum of the fees") return fmt.Errorf("fees pending collection amount does not match the sum of the fees") } - // fp.buildUSDCEthFeeTransaction(feesToCollect) - - // fp.Log(logrus.InfoLevel, "Fees to collect: ", feesToCollect) - } else { - fp.Log(logrus.InfoLevel, "No fees pending collection") + fp.logger.Info("No fees pending collection") } return nil @@ -285,38 +260,32 @@ func (fp *FeePlugin) collectFeesByPolicy(policyIdString string) error { // Collects fee data by ... Should only be called by HandleFeeCollections func (fp *FeePlugin) collectAllFees() error { ctx := context.Background() - fp.Log(logrus.DebugLevel, "Collecting all fees") feesResponse, err := fp.verifierApi.GetAllPublicKeysFees() if err != nil { - fp.Log(logrus.ErrorLevel, "Failed to get plugin policy fees: ", err) return fmt.Errorf("failed to get plugin policy fees: %w", err) } - fp.logger.Debug("Fees response: ", feesResponse) - for publicKey, feeHistory := range feesResponse { //TODO just for testing if feeHistory.FeesPendingCollection > 0 { - fp.Log(logrus.InfoLevel, "Fees pending collection: ", feeHistory.FeesPendingCollection) + fp.logger.Info("Fees pending collection: ", feeHistory.FeesPendingCollection) checkAmount := 0 for _, fee := range feeHistory.Fees { - fp.Log(logrus.DebugLevel, "Fee: ", fee) if !fee.Collected { checkAmount += fee.Amount } } if checkAmount != feeHistory.FeesPendingCollection { - fp.Log(logrus.ErrorLevel, "Fees pending collection amount does not match the sum of the fees") return fmt.Errorf("fees pending collection amount does not match the sum of the fees") } fp.executeFeeCollection(ctx, publicKey, feeHistory.Fees) } else { - fp.Log(logrus.InfoLevel, "No fees pending collection for public key: ", publicKey) + fp.logger.Info("No fees pending collection for public key: ", publicKey) } } @@ -325,53 +294,40 @@ func (fp *FeePlugin) collectAllFees() error { func (fp *FeePlugin) executeFeeCollection(ctx context.Context, ecdsaPublicKey string, feeIds []verifierapi.FeeDto) error { - fp.Log(logrus.DebugLevel, "Executing fee collection for public key: ", ecdsaPublicKey) - //Get fee policy document feePolicies, err := fp.db.GetAllPluginPolicies(ctx, ecdsaPublicKey, vtypes.PluginVultisigFees_feee, true) - fp.Log(logrus.DebugLevel, "Fee policies: ", len(feePolicies)) if err != nil { - fp.Log(logrus.DebugLevel, "Failed to get fee policies: ", err) return fmt.Errorf("failed to get fee policies: %w", err) } if len(feePolicies) == 0 { - fp.Log(logrus.DebugLevel, "No fee policies found") return fmt.Errorf("no fee policies found") } else if len(feePolicies) > 1 { - fp.Log(logrus.DebugLevel, "Multiple fee policies found") return fmt.Errorf("multiple fee policies found") } feePolicy := feePolicies[0] - fp.Log(logrus.DebugLevel, "Fee policy: ", feePolicy) //Here we check if the fee collection is already in progress for the public key. feeRun, err := fp.db.CreateFeeRun(ctx, feePolicy.ID, types.FeeRunStateDraft, feeIds) if err != nil { - fp.Log(logrus.DebugLevel, "Failed to create fee run: ", err) return fmt.Errorf("failed to create fee run: %w", err) } - fp.Log(logrus.DebugLevel, "Fee run created: ", feeRun) + fp.logger.Info("Fee run created: ", feeRun) //Get vault and check it exists vaultFileName := vcommon.GetVaultBackupFilename(ecdsaPublicKey, vtypes.PluginVultisigFees_feee.String()) vaultContent, err := fp.vaultStorage.GetVault(vaultFileName) if err != nil { - // TODO some real error handling here - fp.Log(logrus.DebugLevel, "Failed to get vault: ", err) return fmt.Errorf("failed to get vault: %w", err) } if vaultContent == nil { - // TODO some real error handling here - fp.Log(logrus.DebugLevel, "Vault not found") return fmt.Errorf("vault not found") } keySignRequests, err := fp.ProposeTransactions(feePolicy) if err != nil { - fp.Log(logrus.DebugLevel, "Failed to propose transactions: ", err) + return fmt.Errorf("failed to propose transactions: %w", err) } - fp.Log(logrus.DebugLevel, "keySignRequest: ", keySignRequests) var eg errgroup.Group for _, keySignRequest := range keySignRequests { @@ -382,7 +338,6 @@ func (fp *FeePlugin) executeFeeCollection(ctx context.Context, ecdsaPublicKey st } err = eg.Wait() if err != nil { - fp.logger.WithError(err).Error("eg.Wait") return fmt.Errorf("eg.Wait: %s, %w", err, asynq.SkipRetry) } diff --git a/plugin/fees/transaction.go b/plugin/fees/transaction.go index 06ba634..8e87ac7 100644 --- a/plugin/fees/transaction.go +++ b/plugin/fees/transaction.go @@ -121,7 +121,7 @@ func (fp *FeePlugin) ProposeTransactions(policy vtypes.PluginPolicy) ([]vtypes.P nonce, err := fp.nonceManager.GetNextNonce(ethAddress) if err != nil { - return []vtypes.PluginKeysignRequest{}, fmt.Errorf("p.nonceManager.GetNextNonce: %w", err) + return []vtypes.PluginKeysignRequest{}, fmt.Errorf("plugincommon.nonceManager.GetNextNonce: %w", err) } tx, e := plugincommon.GenUnsignedTx( @@ -136,7 +136,7 @@ func (fp *FeePlugin) ProposeTransactions(policy vtypes.PluginPolicy) ([]vtypes.P ) if e != nil { - return []vtypes.PluginKeysignRequest{}, fmt.Errorf("p.genUnsignedTx: %w", e) + return []vtypes.PluginKeysignRequest{}, fmt.Errorf("plugincommon.genUnsignedTx: %w", e) } txHex := hex.EncodeToString(tx) @@ -151,7 +151,7 @@ func (fp *FeePlugin) ProposeTransactions(policy vtypes.PluginPolicy) ([]vtypes.P ProposedTxHex: txHex, }) if e != nil { - return []vtypes.PluginKeysignRequest{}, fmt.Errorf("p.txIndexerService.CreateTx: %w", e) + return []vtypes.PluginKeysignRequest{}, fmt.Errorf("fp.tx_indexer.CreateTx: %w", e) } // Create signing request @@ -220,7 +220,7 @@ func (fp *FeePlugin) IsAlreadyProposed( if errors.Is(err, storage.ErrNoTx) { return false, nil } - return false, fmt.Errorf("p.txIndexerService.GetTxInTimeRange: %w", err) + return false, fmt.Errorf("fp.txIndexerService.GetTxInTimeRange: %w", err) } func (fp *FeePlugin) initSign( @@ -230,7 +230,6 @@ func (fp *FeePlugin) initSign( ) error { buf, e := json.Marshal(req) if e != nil { - fp.logger.WithError(e).Error("json.Marshal") return fmt.Errorf("json.Marshal: %w", e) } @@ -242,8 +241,7 @@ func (fp *FeePlugin) initSign( asynq.Queue(tasks.QUEUE_NAME), ) if e != nil { - fp.logger.WithError(e).Error("p.client.Enqueue") - return fmt.Errorf("p.client.Enqueue: %w", e) + return fmt.Errorf("fp.client.Enqueue: %w", e) } for { @@ -253,8 +251,7 @@ func (fp *FeePlugin) initSign( case <-time.After(3 * time.Second): taskInfo, er := fp.asynqInspector.GetTaskInfo(tasks.QUEUE_NAME, task.ID) if er != nil { - fp.logger.WithError(er).Error("p.inspector.GetTaskInfo(tasks.QUEUE_NAME, task.ID)") - return fmt.Errorf("p.inspector.GetTaskInfo: %w", er) + return fmt.Errorf("fp.inspector.GetTaskInfo: %w", er) } if taskInfo.State != asynq.TaskStateCompleted { continue @@ -267,7 +264,6 @@ func (fp *FeePlugin) initSign( var res map[string]tss.KeysignResponse er = json.Unmarshal(taskInfo.Result, &res) if er != nil { - fp.logger.WithError(er).Error("json.Unmarshal(taskInfo.Result, &res)") return fmt.Errorf("json.Unmarshal(taskInfo.Result, &res): %w", er) } @@ -278,8 +274,7 @@ func (fp *FeePlugin) initSign( er = fp.SigningComplete(ctx, sig, req, pluginPolicy) if er != nil { - fp.logger.WithError(er).Error("p.SigningComplete") - return fmt.Errorf("p.SigningComplete: %w", er) + return fmt.Errorf("fp.SigningComplete: %w", er) } fp.logger.WithField("public_key", req.PublicKey).