diff --git a/cmd/main.go b/cmd/main.go index 0f97d72f3..9bfafe500 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -74,7 +74,9 @@ var command = cobra.Command{ } } - zap.L().Info("logger initialized", zap.String("environment", environment)) + zap.L().Info("starting RSS3 Node", + zap.String("version", constant.BuildVersion()), + zap.String("environment", environment)) if err = config.HasOneWorker(configFile); err != nil { return err @@ -212,8 +214,6 @@ var command = cobra.Command{ if err := tx.Commit(); err != nil { return fmt.Errorf("commit transaction: %w", err) } - - zap.L().Info("database transaction committed successfully") } switch module { @@ -270,7 +270,7 @@ func runCoreService(ctx context.Context, configFile *config.File, databaseClient if !config.IsRSSComponentOnly(configFile) { go func() { if err := node.CheckParams(checkCtx, redisClient, networkParamsCaller, settlementCaller); err != nil { - fmt.Printf("Error checking parameters: %v\n", err) + zap.L().Error("error checking parameters", zap.Error(err)) } }() } @@ -288,7 +288,6 @@ func runCoreService(ctx context.Context, configFile *config.File, databaseClient select { case sig := <-stopChan: zap.L().Info("shutdown signal received", zap.String("signal", sig.String())) - fmt.Printf("Shutdown signal received: %v.\n", sig) case err := <-apiErrChan: zap.L().Error("core service encountered an error", zap.Error(err)) cancel() // signal all goroutines to stop on error @@ -304,13 +303,10 @@ func runCoreService(ctx context.Context, configFile *config.File, databaseClient // findModuleByID find and returns the specified worker ID in all components. func findModuleByID(configFile *config.File, workerID string) (*config.Module, error) { - zap.L().Debug("searching for module", zap.String("workerID", workerID)) - // find the module in a specific component list findInComponent := func(components []*config.Module) (*config.Module, bool) { for _, module := range components { if strings.EqualFold(module.ID, workerID) { - zap.L().Debug("module found", zap.String("moduleID", module.ID)) return module, true } } @@ -424,7 +420,7 @@ func setOpenTelemetry(config *config.File) error { }() } - zap.L().Debug("OpenTelemetry setup completed") + zap.L().Debug("openTelemetry setup completed") return nil } @@ -453,7 +449,7 @@ func initializePyroscope() { ProfileTypes: append(pyroscope.DefaultProfileTypes, pyroscope.ProfileGoroutines), }) } else { - zap.L().Debug("Pyroscope endpoint not configured, skipping initialization") + zap.L().Debug("pyroscope endpoint not configured, skipping initialization") } } } diff --git a/config/config.go b/config/config.go index 02b7562f0..ed5f33e82 100644 --- a/config/config.go +++ b/config/config.go @@ -227,7 +227,7 @@ func _Setup(configName, configType string, v *viper.Viper) (*File, error) { v.AddConfigPath(path.Join(currentDir, "deploy")) zap.L().Debug("added current directory config paths", zap.String("currentDir", currentDir)) } else { - zap.L().Warn("failed to get current directory", zap.Error(err)) + zap.L().Error("failed to get current directory", zap.Error(err)) } v.SetEnvPrefix(EnvPrefix) diff --git a/internal/database/dialer/postgres/client.go b/internal/database/dialer/postgres/client.go index 0c8c7a62b..120a740ff 100644 --- a/internal/database/dialer/postgres/client.go +++ b/internal/database/dialer/postgres/client.go @@ -71,8 +71,6 @@ func (c *client) WithTransaction(ctx context.Context, transactionFunction func(c return fmt.Errorf("begin transaction: %w", err) } - zap.L().Debug("transaction began successfully") - if err := transactionFunction(ctx, transaction); err != nil { _ = transaction.Rollback() diff --git a/internal/database/dialer/postgres/client_partitioned.go b/internal/database/dialer/postgres/client_partitioned.go index a1b7e0631..bdfea5210 100644 --- a/internal/database/dialer/postgres/client_partitioned.go +++ b/internal/database/dialer/postgres/client_partitioned.go @@ -27,7 +27,7 @@ var indexesTables sync.Map func (c *client) createPartitionTable(ctx context.Context, name, template string) error { statement := fmt.Sprintf(`CREATE TABLE IF NOT EXISTS "%s" (LIKE "%s" INCLUDING ALL);`, name, template) - zap.L().Debug("Creating partition table", + zap.L().Debug("creating partition table", zap.String("statement", statement)) err := c.database.WithContext(ctx).Exec(statement).Error @@ -39,7 +39,7 @@ func (c *client) createPartitionTable(ctx context.Context, name, template string indexesTables.Store(name, struct{}{}) } - zap.L().Debug("Successfully created partition table", + zap.L().Debug("successfully created partition table", zap.String("statement", statement)) return nil @@ -49,7 +49,7 @@ func (c *client) createPartitionTable(ctx context.Context, name, template string func (c *client) findPartitionTableExists(ctx context.Context, name string) (bool, error) { statement := fmt.Sprintf(`SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_name = '%s')`, name) - zap.L().Debug("Checking if partition table exists", + zap.L().Debug("checking if partition table exists", zap.String("statement", statement)) var exists bool @@ -58,7 +58,7 @@ func (c *client) findPartitionTableExists(ctx context.Context, name string) (boo return false, err } - zap.L().Debug("Successfully checked partition table existence", + zap.L().Debug("successfully checked partition table existence", zap.String("name", name), zap.Bool("exists", exists)) @@ -67,20 +67,20 @@ func (c *client) findPartitionTableExists(ctx context.Context, name string) (boo // findIndexesPartitionTable finds partition table names of indexes in the past year. func (c *client) findIndexesPartitionTables(_ context.Context, index table.Index) []string { - zap.L().Debug("Finding index partition tables", + zap.L().Debug("finding index partition tables", zap.Time("timestamp", index.Timestamp)) partitionedNames := make([]string, 0) for i := 0; i <= 4; i++ { if index.Timestamp.Unix() < time.Now().AddDate(-1, 0, 0).Unix() { - zap.L().Debug("Index timestamp is older than 1 year, stopping search", + zap.L().Debug("index timestamp is older than 1 year, stopping search", zap.Time("timestamp", index.Timestamp)) break } if _, exists := indexesTables.Load(index.PartitionName()); exists { - zap.L().Debug("Found existing partition table", + zap.L().Debug("found existing partition table", zap.String("partition_name", index.PartitionName())) partitionedNames = append(partitionedNames, index.PartitionName()) @@ -91,11 +91,11 @@ func (c *client) findIndexesPartitionTables(_ context.Context, index table.Index index.Timestamp = time.Date(lo.Ternary(month < 3, year-1, year), lo.Ternary(month < 3, month+9, month-3), index.Timestamp.Day(), 23, 59, 59, 1e9-1, time.Local) - zap.L().Debug("Updated timestamp for next iteration", + zap.L().Debug("updated timestamp for next iteration", zap.Time("new_timestamp", index.Timestamp)) } - zap.L().Debug("Completed finding index partition tables", + zap.L().Debug("completed finding index partition tables", zap.Any("found_tables", partitionedNames)) return partitionedNames @@ -116,7 +116,7 @@ func (c *client) loadIndexesPartitionTables(ctx context.Context) { // saveActivitiesPartitioned saves Activities in partitioned tables. func (c *client) saveActivitiesPartitioned(ctx context.Context, activities []*activityx.Activity, lowPriority bool) error { - zap.L().Debug("Starting to save activities in partitioned tables", + zap.L().Debug("starting to save activities in partitioned tables", zap.Int("activity_count", len(activities)), zap.Bool("low_priority", lowPriority)) @@ -142,7 +142,7 @@ func (c *client) saveActivitiesPartitioned(ctx context.Context, activities []*ac name, activities := name, activities errorGroup.Go(func() error { - zap.L().Debug("Processing partition", + zap.L().Debug("processing partition", zap.String("partition_name", name), zap.Int("activity_count", len(activities))) @@ -153,7 +153,7 @@ func (c *client) saveActivitiesPartitioned(ctx context.Context, activities []*ac } if len(tableActivities) == 0 { - zap.L().Debug("No activities to save for partition", + zap.L().Debug("no activities to save for partition", zap.String("partition_name", name)) return nil } @@ -188,7 +188,7 @@ func (c *client) saveActivitiesPartitioned(ctx context.Context, activities []*ac return item.ID }) - zap.L().Debug("Saving activities to database", + zap.L().Debug("saving activities to database", zap.String("partition_name", name), zap.Int("activity_count", len(activityIDs))) @@ -202,7 +202,7 @@ func (c *client) saveActivitiesPartitioned(ctx context.Context, activities []*ac return err } - zap.L().Debug("Successfully saved activities", + zap.L().Debug("successfully saved activities", zap.String("partition_name", name), zap.Int("affected_count", len(affectedActivities))) @@ -214,14 +214,14 @@ func (c *client) saveActivitiesPartitioned(ctx context.Context, activities []*ac return err } - zap.L().Debug("Successfully saved all activities in partitioned tables", zap.Int("total_count", len(activities))) + zap.L().Debug("successfully saved all activities in partitioned tables", zap.Int("total_count", len(activities))) return nil } // findActivityPartitioned finds an activity by id. func (c *client) findActivityPartitioned(ctx context.Context, query model.ActivityQuery) (*activityx.Activity, *int, error) { - zap.L().Debug("Finding activity in partitioned table", + zap.L().Debug("finding activity in partitioned table", zap.Any("query", query)) matchedActivity, err := c.findIndexPartitioned(ctx, query) @@ -230,7 +230,6 @@ func (c *client) findActivityPartitioned(ctx context.Context, query model.Activi } if matchedActivity == nil { - zap.L().Debug("No matching activity found") return nil, nil, nil } @@ -253,7 +252,7 @@ func (c *client) findActivityPartitioned(ctx context.Context, query model.Activi activity.Actions = lo.Slice(activity.Actions, query.ActionLimit*(query.ActionPage-1), query.ActionLimit*query.ActionPage) - zap.L().Debug("Successfully found and exported activity", + zap.L().Debug("successfully found and exported activity", zap.String("id", result.ID), zap.String("network", result.Network.String()), zap.Int("action_count", len(activity.Actions))) @@ -263,7 +262,7 @@ func (c *client) findActivityPartitioned(ctx context.Context, query model.Activi // findActivitiesPartitioned finds activities. func (c *client) findActivitiesPartitioned(ctx context.Context, query model.ActivitiesQuery) ([]*activityx.Activity, error) { - zap.L().Debug("Finding activities in partitioned tables", + zap.L().Debug("finding activities in partitioned tables", zap.Any("query", query)) indexes, err := c.findIndexesPartitioned(ctx, query) @@ -295,7 +294,7 @@ func (c *client) findActivitiesPartitioned(ctx context.Context, query model.Acti return index.ID }) - zap.L().Debug("Processing partition", + zap.L().Debug("processing partition", zap.String("table", tableName), zap.Int("id_count", len(ids))) @@ -316,7 +315,7 @@ func (c *client) findActivitiesPartitioned(ctx context.Context, query model.Acti result = append(result, activities...) - zap.L().Debug("Successfully processed partition", + zap.L().Debug("successfully processed partition", zap.String("table", tableName), zap.Int("activity_count", len(activities))) @@ -336,7 +335,7 @@ func (c *client) findActivitiesPartitioned(ctx context.Context, query model.Acti return result[i].Timestamp > result[j].Timestamp }) - zap.L().Debug("Successfully found all activities", + zap.L().Debug("successfully found all activities", zap.Int("total_count", len(result))) return result, nil @@ -411,7 +410,7 @@ func (c *client) findFederatedActivitiesPartitioned(ctx context.Context, query m // saveIndexesPartitioned saves indexes in partitioned tables. func (c *client) saveIndexesPartitioned(ctx context.Context, activities []*activityx.Activity) error { - zap.L().Debug("Starting to save indexes in partitioned tables", + zap.L().Debug("starting to save indexes in partitioned tables", zap.Int("activity_count", len(activities))) indexes := make(table.Indexes, 0) @@ -421,7 +420,7 @@ func (c *client) saveIndexesPartitioned(ctx context.Context, activities []*activ } if len(indexes) == 0 { - zap.L().Info("No indexes to save") + zap.L().Info("no indexes to save") return nil } @@ -448,7 +447,7 @@ func (c *client) saveIndexesPartitioned(ctx context.Context, activities []*activ return value }) - zap.L().Debug("Deleting existing indexes", + zap.L().Debug("deleting existing indexes", zap.Any("condition", conditions)) errorPool := pool.New().WithContext(ctx).WithMaxGoroutines(10).WithCancelOnError().WithFirstError() @@ -485,7 +484,7 @@ func (c *client) saveIndexesPartitioned(ctx context.Context, activities []*activ UpdateAll: true, } - zap.L().Debug("Saving new indexes", + zap.L().Debug("saving new indexes", zap.Any("indexes", indexes)) errorPool = pool.New().WithContext(ctx).WithMaxGoroutines(10).WithCancelOnError().WithFirstError() @@ -506,7 +505,7 @@ func (c *client) saveIndexesPartitioned(ctx context.Context, activities []*activ return fmt.Errorf("failed to save indexes: %w", err) } - zap.L().Debug("Successfully saved indexes in partitioned tables", + zap.L().Debug("successfully saved indexes in partitioned tables", zap.Int("total_count", len(indexes))) return nil @@ -514,7 +513,7 @@ func (c *client) saveIndexesPartitioned(ctx context.Context, activities []*activ // findIndexPartitioned finds an activity by id. func (c *client) findIndexPartitioned(ctx context.Context, query model.ActivityQuery) (*table.Index, error) { - zap.L().Debug("Finding index in partitioned tables", + zap.L().Debug("finding index in partitioned tables", zap.Any("query", query)) index := table.Index{ @@ -567,11 +566,11 @@ func (c *client) findIndexPartitioned(ctx context.Context, query model.ActivityQ case data := <-resultChan: count++ - zap.L().Debug("Found index in partition table", + zap.L().Debug("found index in partition table", zap.Any("data", data)) if data != nil && lo.IsNotEmpty(data.ID) { - zap.L().Debug("Successfully found index", + zap.L().Debug("successfully found index", zap.String("id", data.ID)) close(stopChan) @@ -580,7 +579,7 @@ func (c *client) findIndexPartitioned(ctx context.Context, query model.ActivityQ } if count == len(tables) { - zap.L().Debug("No index found in any partition table") + zap.L().Debug("no index found in any partition table") return nil, nil } } @@ -591,7 +590,7 @@ func (c *client) findIndexPartitioned(ctx context.Context, query model.ActivityQ // //nolint:gocognit func (c *client) findIndexesPartitioned(ctx context.Context, query model.ActivitiesQuery) ([]*table.Index, error) { - zap.L().Debug("Finding indexes in partitioned tables", + zap.L().Debug("finding indexes in partitioned tables", zap.Any("query", query)) index := table.Index{ @@ -609,7 +608,6 @@ func (c *client) findIndexesPartitioned(ctx context.Context, query model.Activit partitionedNames := c.findIndexesPartitionTables(ctx, index) if len(partitionedNames) == 0 { - zap.L().Debug("No partition tables found") return nil, nil } @@ -667,9 +665,6 @@ func (c *client) findIndexesPartitioned(ctx context.Context, query model.Activit result := make([]*table.Index, 0, query.Limit) flag := true - zap.L().Debug("Found indexes in partition tables", - zap.Any("indexes", indexes)) - mutex.RLock() for _, data := range indexes { @@ -683,7 +678,7 @@ func (c *client) findIndexesPartitioned(ctx context.Context, query model.Activit result = append(result, data...) if len(result) >= query.Limit { - zap.L().Debug("Found indexes up to limit", + zap.L().Debug("found indexes up to limit", zap.Int("count", query.Limit)) close(stopChan) mutex.RUnlock() @@ -695,7 +690,7 @@ func (c *client) findIndexesPartitioned(ctx context.Context, query model.Activit mutex.RUnlock() if flag { - zap.L().Debug("Successfully found all indexes", + zap.L().Debug("successfully found all indexes", zap.Int("count", len(result))) return result, nil } @@ -814,7 +809,7 @@ func (c *client) deleteExpiredActivitiesPartitioned(ctx context.Context, network checkTablesTimestamp = []time.Time{timestamp} ) - zap.L().Debug("Starting to delete expired activities", + zap.L().Debug("starting to delete expired activities", zap.String("network", network.String()), zap.Time("timestamp", timestamp), zap.Int("batch_size", batchSize)) @@ -839,19 +834,19 @@ func (c *client) deleteExpiredActivitiesPartitioned(ctx context.Context, network } if !indexTableExists { - zap.L().Debug("Index table does not exist, skipping", + zap.L().Debug("index table does not exist, skipping", zap.String("table", indexTable)) continue } _, dropActivity := dropActivitiesTableMap[activityTable] - zap.L().Info("Beginning to delete expired activities", + zap.L().Info("beginning to delete expired activities", zap.String("activity_table", activityTable), zap.String("index_table", indexTable)) for { - zap.L().Debug("Deleting expired activities", + zap.L().Debug("deleting expired activities", zap.String("activity_table", activityTable), zap.String("index_table", indexTable), zap.String("network", network.String()), @@ -865,7 +860,7 @@ func (c *client) deleteExpiredActivitiesPartitioned(ctx context.Context, network } if done { - zap.L().Debug("Successfully deleted expired activities", + zap.L().Debug("successfully deleted expired activities", zap.String("activity_table", activityTable), zap.String("index_table", indexTable)) @@ -874,7 +869,7 @@ func (c *client) deleteExpiredActivitiesPartitioned(ctx context.Context, network } if dropActivity { - zap.L().Debug("Dropping activity table", + zap.L().Debug("dropping activity table", zap.String("table", activityTable)) if err := c.database.WithContext(ctx).Exec(fmt.Sprintf(`DROP TABLE IF EXISTS "%s"`, activityTable)).Error; err != nil { @@ -883,7 +878,7 @@ func (c *client) deleteExpiredActivitiesPartitioned(ctx context.Context, network } } - zap.L().Debug("Successfully deleted expired activities", + zap.L().Debug("successfully deleted expired activities", zap.String("network", network.String()), zap.Time("timestamp", timestamp)) @@ -898,7 +893,7 @@ func (c *client) batchDeleteExpiredActivities(ctx context.Context, network netwo var transactionIDs []string - zap.L().Debug("Finding expired activities", + zap.L().Debug("finding expired activities", zap.String("index_table", *indexTable), zap.Int("batch_size", batchSize)) @@ -909,11 +904,11 @@ func (c *client) batchDeleteExpiredActivities(ctx context.Context, network netwo } if len(transactionIDs) == 0 { - zap.L().Debug("No expired activities found") + zap.L().Debug("no expired activities found") return true, nil } - zap.L().Debug("Deleting expired indexes", + zap.L().Debug("deleting expired indexes", zap.String("table", *indexTable), zap.Int("count", len(transactionIDs))) @@ -922,7 +917,7 @@ func (c *client) batchDeleteExpiredActivities(ctx context.Context, network netwo } if activityTable != nil { - zap.L().Debug("Deleting expired activities", + zap.L().Debug("deleting expired activities", zap.String("table", *activityTable), zap.Int("count", len(transactionIDs))) @@ -935,7 +930,7 @@ func (c *client) batchDeleteExpiredActivities(ctx context.Context, network netwo return false, fmt.Errorf("commit transaction: %w", err) } - zap.L().Debug("Successfully deleted batch of expired records", + zap.L().Debug("successfully deleted batch of expired records", zap.Int("count", len(transactionIDs))) return false, nil diff --git a/internal/engine/protocol/activitypub/data_source.go b/internal/engine/protocol/activitypub/data_source.go index f5affe42b..e790c301e 100644 --- a/internal/engine/protocol/activitypub/data_source.go +++ b/internal/engine/protocol/activitypub/data_source.go @@ -142,7 +142,7 @@ func (s *dataSource) handleMessage(ctx context.Context, msg string) *engine.Task } // Log the accept message and current domains list - zap.L().Info("Relay Subscription request has been approved", + zap.L().Info("relay subscription request has been approved", zap.String("relayObjectID", relayObjectID), zap.String("acceptingDomain", domain), zap.Strings("allAcceptDomains", s.acceptDomains)) @@ -150,12 +150,12 @@ func (s *dataSource) handleMessage(ctx context.Context, msg string) *engine.Task } objectID := gjson.Get(msg, "object").String() - zap.L().Info("Found object ID", zap.String("objectID", objectID)) + zap.L().Info("found object ID", zap.String("objectID", objectID)) // Attempt to fetch the detailed ActivityPub object within the relay message. fetchedObject, err := s.mastodonClient.FetchAnnouncedObject(ctx, objectID) if err != nil { - zap.L().Error("Failed to fetch announced object", + zap.L().Error("failed to fetch announced object", zap.String("objectID", objectID), zap.Error(err)) return nil } @@ -166,7 +166,7 @@ func (s *dataSource) handleMessage(ctx context.Context, msg string) *engine.Task // If the message is not a relay message, attempt to unmarshal it directly into an ActivityPub object. var fetchedObject activitypub.Object if err := json.Unmarshal([]byte(msg), &fetchedObject); err != nil { - zap.L().Error("Error unmarshalling message", zap.Error(err)) + zap.L().Error("error unmarshalling message", zap.Error(err)) return nil } @@ -201,17 +201,17 @@ func isRelayMessage(id string) bool { } if parsedURL.Host == "" { - zap.L().Warn("Parsed URL has an empty host", zap.String("id", id)) + zap.L().Debug("parsed URL has an empty host", zap.String("id", id)) return false } if strings.HasPrefix(parsedURL.Host, "relay.") || strings.HasPrefix(parsedURL.Host, "rel.") { - zap.L().Info("URL identified as a relay message", zap.String("id", id)) + zap.L().Info("url identified as a relay message", zap.String("id", id)) return true } - zap.L().Info("URL is not a relay message", zap.String("id", id)) + zap.L().Info("url is not a relay message", zap.String("id", id)) return false } @@ -238,13 +238,13 @@ func (s *dataSource) buildMastodonMessageTasks(_ context.Context, object activit // If the object is empty, return an empty task if object.Type == "" { - zap.L().Warn("skipping empty object") + zap.L().Debug("skipping mastodon message object with empty type") return nil } if object.Published == "" { - zap.L().Warn("missing published timestamp", + zap.L().Debug("skipping mastodon message object with missing published timestamp", zap.String("objectID", object.ID), ) @@ -255,7 +255,7 @@ func (s *dataSource) buildMastodonMessageTasks(_ context.Context, object activit zap.L().Info("object.Published value before calling ValidatePublicationTimestamp", zap.String("published", object.Published)) if !ValidatePublicationTimestamp(object.Published) { // ToDo: Verify if this is the correct location to validate timestamps on incoming AP messages; Cannot have it in mastodon/client.go due to the message-parsing process. - zap.L().Warn("skipping message: timestamp is not valid", + zap.L().Debug("skipping mastodon message object with invalid published timestamp", zap.String("objectID", object.ID), zap.String("publishedTime", object.Published), ) @@ -337,12 +337,12 @@ func ValidatePublicationTimestamp(publicationTimestamp string) bool { return false } - zap.L().Info("Parsed publication timestamp", zap.Time("publicationTime", publicationTime)) + zap.L().Info("parsed publication timestamp", zap.Time("publicationTime", publicationTime)) // In this case, we subtract 3 months from current time cutoffTime := time.Now().AddDate(0, -3, 0) - zap.L().Info("Calculated cutoff time", zap.Time("cutoffTime", cutoffTime)) + zap.L().Info("calculated cutoff time", zap.Time("cutoffTime", cutoffTime)) // Compares if publicationTime is chronologically later than cutoffTime isValid := publicationTime.After(cutoffTime) diff --git a/internal/engine/protocol/activitypub/option.go b/internal/engine/protocol/activitypub/option.go index d12437d90..a112d1682 100644 --- a/internal/engine/protocol/activitypub/option.go +++ b/internal/engine/protocol/activitypub/option.go @@ -42,12 +42,12 @@ func NewOption(n network.Network, parameters *config.Parameters, isMonitor bool) // Apply defaults if RelayURLList or Port are not set if len(option.RelayURLList) == 0 { option.RelayURLList = mastodon.DefaultRelayURLList - zap.L().Info("RelayURLList not specified, using default", zap.Strings("defaultRelayURLList", mastodon.DefaultRelayURLList)) + zap.L().Info("relay URL list not specified, using default", zap.Strings("defaultRelayURLList", mastodon.DefaultRelayURLList)) } if option.Port == 0 { option.Port = mastodon.DefaultServerPort - zap.L().Info("Port not specified, using default", zap.Int64("defaultPort", mastodon.DefaultServerPort)) + zap.L().Info("port not specified, using default", zap.Int64("defaultPort", mastodon.DefaultServerPort)) } zap.L().Info("option:", zap.Any("option", option)) diff --git a/internal/engine/protocol/activitypub/task.go b/internal/engine/protocol/activitypub/task.go index 694223825..f588a9d8a 100644 --- a/internal/engine/protocol/activitypub/task.go +++ b/internal/engine/protocol/activitypub/task.go @@ -40,7 +40,7 @@ func (t Task) GetTimestamp() uint64 { parsedTime, err := time.Parse(time.RFC3339, timeStr) if err != nil { - zap.L().Error("Error parsing time") + zap.L().Error("failed to parse time", zap.Error(err)) return 0 } diff --git a/internal/engine/protocol/arweave/data_source.go b/internal/engine/protocol/arweave/data_source.go index 3945d7871..0b1a18dab 100644 --- a/internal/engine/protocol/arweave/data_source.go +++ b/internal/engine/protocol/arweave/data_source.go @@ -55,7 +55,7 @@ func (s *dataSource) State() json.RawMessage { } func (s *dataSource) Start(ctx context.Context, tasksChan chan<- *engine.Tasks, errorChan chan<- error) { - zap.L().Debug("Starting Arweave data source") + zap.L().Debug("starting arweave data source") // Initialize dataSource. if err := s.initialize(); err != nil { @@ -64,20 +64,20 @@ func (s *dataSource) Start(ctx context.Context, tasksChan chan<- *engine.Tasks, return } - zap.L().Info("Successfully initialized Arweave data source") + zap.L().Info("successfully initialized arweave data source") // Start a goroutine to poll blocks. go func() { retryableFunc := func() error { switch { case s.filter.BundlrOnly: - zap.L().Debug("Starting to poll transactions from Irys") + zap.L().Debug("starting to poll transactions from irys") if err := s.pollTransactionsFromIrys(ctx, tasksChan, s.filter); err != nil { return fmt.Errorf("poll transaction froms irys: %w", err) } default: - zap.L().Debug("Starting to poll blocks") + zap.L().Debug("starting to poll blocks") if err := s.pollBlocks(ctx, tasksChan, s.filter); err != nil { return fmt.Errorf("poll blocks: %w", err) @@ -101,7 +101,7 @@ func (s *dataSource) Start(ctx context.Context, tasksChan chan<- *engine.Tasks, } }() - zap.L().Info("Successfully started Arweave data source") + zap.L().Info("successfully started arweave data source") } // initialize initializes the dataSource. @@ -132,7 +132,7 @@ func (s *dataSource) updateBlockHeight(ctx context.Context) { if remoteBlockStart > s.state.BlockHeight { s.state.BlockHeight = remoteBlockStart - zap.L().Info("Updated block height from remote", zap.Uint64("newBlockHeight", s.state.BlockHeight)) + zap.L().Info("updated block height from remote", zap.Uint64("newBlockHeight", s.state.BlockHeight)) } } @@ -150,7 +150,7 @@ func (s *dataSource) pollBlocks(ctx context.Context, tasksChan chan<- *engine.Ta // Get target block height from config // if not set, use the latest block height from arweave network if s.option.BlockTarget != nil { - zap.L().Info("Using configured block height target", + zap.L().Info("using configured block height target", zap.Uint64("block_height_target", s.option.BlockTarget.Uint64())) blockHeightLatestRemote = int64(s.option.BlockTarget.Uint64()) @@ -161,13 +161,13 @@ func (s *dataSource) pollBlocks(ctx context.Context, tasksChan chan<- *engine.Ta return fmt.Errorf("get latest block height: %w", err) } - zap.L().Info("Retrieved latest block height from Arweave network", + zap.L().Info("retrieved latest block height from arweave network", zap.Int64("block_height", blockHeightLatestRemote)) } for { if s.option.BlockTarget != nil && s.option.BlockTarget.Uint64() <= s.state.BlockHeight { - zap.L().Info("Reached target block height, stopping poll", + zap.L().Info("reached target block height, stopping poll", zap.Uint64("target", s.option.BlockTarget.Uint64()), zap.Uint64("current", s.state.BlockHeight)) @@ -185,11 +185,11 @@ func (s *dataSource) pollBlocks(ctx context.Context, tasksChan chan<- *engine.Ta return fmt.Errorf("get latest block height: %w", err) } - zap.L().Debug("Reconfirmed latest block height", + zap.L().Debug("reconfirmed latest block height", zap.Int64("block_height", blockHeightLatestRemote)) if s.state.BlockHeight >= uint64(blockHeightLatestRemote) { - zap.L().Debug("Waiting for next block", + zap.L().Debug("waiting for next block", zap.Duration("wait_time", defaultBlockTime)) // Wait for the next block on arweave network. time.Sleep(defaultBlockTime) @@ -207,7 +207,7 @@ func (s *dataSource) pollBlocks(ctx context.Context, tasksChan chan<- *engine.Ta blockHeightStart + *s.option.ConcurrentBlockRequests, }) - zap.L().Debug("Pulling blocks by range", + zap.L().Debug("pulling blocks by range", zap.Uint64("start", blockHeightStart), zap.Uint64("end", blockHeightEnd)) @@ -222,7 +222,7 @@ func (s *dataSource) pollBlocks(ctx context.Context, tasksChan chan<- *engine.Ta return block.Txs }) - zap.L().Debug("Pulling transactions", + zap.L().Debug("pulling transactions", zap.Int("transaction_count", len(transactionIDs))) // Batch pull transactions by ids. @@ -243,7 +243,7 @@ func (s *dataSource) pollBlocks(ctx context.Context, tasksChan chan<- *engine.Ta for index, block := range blocks { bundleTransactionIDs := s.GroupBundleTransactions(transactions, block) - zap.L().Debug("Processing bundle transactions", + zap.L().Debug("processing bundle transactions", zap.Int("bundle_transaction_count", len(bundleTransactionIDs))) bundleTransactions, err := s.batchPullBundleTransactions(ctx, bundleTransactionIDs) @@ -271,7 +271,7 @@ func (s *dataSource) pollBlocks(ctx context.Context, tasksChan chan<- *engine.Ta tasks := s.buildTasks(ctx, blocks, transactions) - zap.L().Info("Built tasks from blocks and transactions", + zap.L().Info("built tasks from blocks and transactions", zap.Int("block_count", len(blocks)), zap.Int("transaction_count", len(transactions))) @@ -280,7 +280,7 @@ func (s *dataSource) pollBlocks(ctx context.Context, tasksChan chan<- *engine.Ta // Update block height to state. s.state.BlockHeight = blockHeightEnd - zap.L().Debug("Updated state block height", + zap.L().Debug("updated state block height", zap.Uint64("new_block_height", blockHeightEnd)) } @@ -289,7 +289,7 @@ func (s *dataSource) pollBlocks(ctx context.Context, tasksChan chan<- *engine.Ta // pollTransactionsFromIrys polls transactions from Irys GraphQL endpoint. func (s *dataSource) pollTransactionsFromIrys(ctx context.Context, tasksChan chan<- *engine.Tasks, filter *Filter) error { - zap.L().Info("Starting to poll transactions from Irys", + zap.L().Info("starting to poll transactions from irys", zap.Any("filter", filter)) // Initialize Irys GraphQL client. @@ -304,7 +304,7 @@ func (s *dataSource) pollTransactionsFromIrys(ctx context.Context, tasksChan cha for { // Get transactions from Irys GraphQL endpoint. - zap.L().Debug("Fetching transactions from Irys GraphQL", + zap.L().Debug("fetching transactions from irys graphql", zap.Strings("owners", filter.OwnerAddresses), zap.String("cursor", s.state.Cursor)) @@ -343,7 +343,7 @@ func (s *dataSource) pollTransactionsFromIrys(ctx context.Context, tasksChan cha blocks := lo.Values(blockMap) - zap.L().Debug("Batch pulling transactions from Irys gateway", + zap.L().Debug("batch pulling transactions from irys gateway", zap.Int("transaction_count", len(transactionIDs))) // Batch pull transactions from Irys gateway. @@ -364,7 +364,7 @@ func (s *dataSource) pollTransactionsFromIrys(ctx context.Context, tasksChan cha return transaction }) - zap.L().Debug("Batch pulling transaction data from Irys gateway", + zap.L().Debug("batch pulling transaction data from irys gateway", zap.Int("transaction_count", len(transactions))) // Batch pull transaction data from Irys gateway. @@ -374,7 +374,7 @@ func (s *dataSource) pollTransactionsFromIrys(ctx context.Context, tasksChan cha tasks := s.buildTasks(ctx, blocks, transactions) - zap.L().Info("Successfully built tasks from Irys transactions", + zap.L().Info("successfully built tasks from irys transactions", zap.Int("block_count", len(blocks)), zap.Int("transaction_count", len(transactions))) @@ -383,14 +383,14 @@ func (s *dataSource) pollTransactionsFromIrys(ctx context.Context, tasksChan cha // Update cursor to state. s.state.Cursor = transactionsResponse.Transactions.PageInfo.EndCursor - zap.L().Debug("Updated state cursor", + zap.L().Debug("updated state cursor", zap.String("new_cursor", s.state.Cursor)) } } // batchPullBlocksByRange pulls blocks by range, from local state block height to remote block height. func (s *dataSource) batchPullBlocksByRange(ctx context.Context, blockHeightStart, blockHeightEnd uint64) ([]*arweave.Block, error) { - zap.L().Info("Starting to batch pull blocks by range", + zap.L().Info("starting to batch pull blocks by range", zap.Uint64("start_block_height", blockHeightStart), zap.Uint64("end_block_height", blockHeightEnd)) @@ -404,7 +404,7 @@ func (s *dataSource) batchPullBlocksByRange(ctx context.Context, blockHeightStar return nil, fmt.Errorf("batch pull blocks: %w", err) } - zap.L().Info("Successfully pulled blocks by range", + zap.L().Info("successfully pulled blocks by range", zap.Int("block_count", len(blocks)), zap.Uint64("start_block_height", blockHeightStart), zap.Uint64("end_block_height", blockHeightEnd)) @@ -414,7 +414,7 @@ func (s *dataSource) batchPullBlocksByRange(ctx context.Context, blockHeightStar // batchPullBlocks pulls blocks by block heights. func (s *dataSource) batchPullBlocks(ctx context.Context, blockHeights []*big.Int) ([]*arweave.Block, error) { - zap.L().Debug("Starting to batch pull blocks", + zap.L().Debug("starting to batch pull blocks", zap.Any("block_heights", blockHeights)) resultPool := pool.NewWithResults[*arweave.Block](). @@ -435,7 +435,7 @@ func (s *dataSource) batchPullBlocks(ctx context.Context, blockHeights []*big.In retry.Delay(defaultRetryDelay), retry.DelayType(retry.BackOffDelay), retry.OnRetry(func(attempt uint, err error) { - zap.L().Error("Failed to pull block, retrying", + zap.L().Error("failed to pull block, retrying", zap.Stringer("block_height", blockHeight), zap.Uint("attempt", attempt), zap.Error(err)) @@ -444,7 +444,7 @@ func (s *dataSource) batchPullBlocks(ctx context.Context, blockHeights []*big.In }) } - zap.L().Debug("Successfully pulled blocks", + zap.L().Debug("successfully pulled blocks", zap.Any("block_heights", blockHeights)) return resultPool.Wait() @@ -452,7 +452,7 @@ func (s *dataSource) batchPullBlocks(ctx context.Context, blockHeights []*big.In // batchPullTransactions pulls transactions by transaction ids. func (s *dataSource) batchPullTransactions(ctx context.Context, arweaveClient arweave.Client, transactionIDs []string) ([]*arweave.Transaction, error) { - zap.L().Debug("Starting to batch pull transactions", + zap.L().Debug("starting to batch pull transactions", zap.Int("transaction_count", len(transactionIDs))) resultPool := pool.NewWithResults[*arweave.Transaction](). @@ -474,7 +474,7 @@ func (s *dataSource) batchPullTransactions(ctx context.Context, arweaveClient ar retry.Delay(defaultRetryDelay), retry.DelayType(retry.BackOffDelay), retry.OnRetry(func(attempt uint, err error) { - zap.L().Error("Failed to pull transaction, retrying", + zap.L().Error("failed to pull transaction, retrying", zap.String("transaction_id", transactionID), zap.Uint("attempt", attempt), zap.Error(err)) @@ -488,7 +488,7 @@ func (s *dataSource) batchPullTransactions(ctx context.Context, arweaveClient ar return nil, err } - zap.L().Debug("Successfully pulled transactions", + zap.L().Debug("successfully pulled transactions", zap.Int("transaction_count", len(transactions))) return transactions, nil @@ -497,7 +497,7 @@ func (s *dataSource) batchPullTransactions(ctx context.Context, arweaveClient ar // batchPullData pulls data by transactions. // It will discard the transaction if the owner is bundlr node. func (s *dataSource) batchPullData(ctx context.Context, arweaveClient arweave.Client, transactions []*arweave.Transaction, skipBundler bool) error { - zap.L().Debug("Starting to batch pull transaction data", + zap.L().Debug("starting to batch pull transaction data", zap.Int("transaction_count", len(transactions)), zap.Bool("skip_bundler", skipBundler)) @@ -516,7 +516,7 @@ func (s *dataSource) batchPullData(ctx context.Context, arweaveClient arweave.Cl // If `skipBundler` is true, skip the transaction if the owner is Bundlr node. if skipBundler && lo.Contains(s.filter.BundlrAddresses, owner) { - zap.L().Debug("Skipping bundler transaction", + zap.L().Debug("skipping bundler transaction", zap.String("transaction_id", transaction.ID), zap.String("owner", owner)) @@ -528,7 +528,7 @@ func (s *dataSource) batchPullData(ctx context.Context, arweaveClient arweave.Cl response, err := arweaveClient.GetTransactionData(ctx, transaction.ID) if err != nil { if errors.Is(err, arweave.ErrorNotFound) { - zap.L().Warn("Transaction data not found", + zap.L().Error("transaction data not found", zap.String("transaction_id", transaction.ID)) return "", nil } @@ -552,7 +552,7 @@ func (s *dataSource) batchPullData(ctx context.Context, arweaveClient arweave.Cl retry.Delay(defaultRetryDelay), retry.DelayType(retry.BackOffDelay), retry.OnRetry(func(attempt uint, err error) { - zap.L().Error("Failed to pull transaction data, retrying", + zap.L().Error("failed to pull transaction data, retrying", zap.String("transaction_id", transaction.ID), zap.Uint("attempt", attempt), zap.Error(err)) @@ -563,7 +563,7 @@ func (s *dataSource) batchPullData(ctx context.Context, arweaveClient arweave.Cl }) } - zap.L().Debug("Successfully batch pull transaction data", + zap.L().Debug("successfully batch pull transaction data", zap.Int("transaction_count", len(transactions))) return resultPool.Wait() @@ -571,7 +571,7 @@ func (s *dataSource) batchPullData(ctx context.Context, arweaveClient arweave.Cl // batchPullBundleTransactions pulls bundle transactions by transaction ids. func (s *dataSource) batchPullBundleTransactions(ctx context.Context, transactionIDs []string) ([]*arweave.Transaction, error) { - zap.L().Debug("Starting to batch pull bundle transactions", + zap.L().Debug("starting to batch pull bundle transactions", zap.Int("transaction_count", len(transactionIDs))) resultPool := pool.NewWithResults[[]*arweave.Transaction](). @@ -598,7 +598,7 @@ func (s *dataSource) batchPullBundleTransactions(ctx context.Context, transactio retry.Delay(defaultRetryDelay), retry.DelayType(retry.BackOffDelay), retry.OnRetry(func(attempt uint, err error) { - zap.L().Error("Failed to pull bundle transaction, retrying", + zap.L().Error("failed to pull bundle transaction, retrying", zap.String("transaction_id", transactionID), zap.Uint("attempt", attempt), zap.Error(err)) @@ -612,7 +612,7 @@ func (s *dataSource) batchPullBundleTransactions(ctx context.Context, transactio return nil, fmt.Errorf("wait result pool: %w", err) } - zap.L().Debug("Successfully batch pull bundle transactions", + zap.L().Debug("successfully batch pull bundle transactions", zap.Int("transaction_count", len(bundleTransactions))) return lo.Flatten(bundleTransactions), nil @@ -620,14 +620,14 @@ func (s *dataSource) batchPullBundleTransactions(ctx context.Context, transactio // pullBundleTransactions pulls bundle transactions by transaction id. func (s *dataSource) pullBundleTransactions(ctx context.Context, transactionID string) ([]*arweave.Transaction, error) { - zap.L().Debug("Starting to pull bundle transactions", zap.String("transaction_id", transactionID)) + zap.L().Debug("starting to pull bundle transactions", zap.String("transaction_id", transactionID)) bundleTransactions := make([]*arweave.Transaction, 0) response, err := s.arweaveClient.GetTransactionData(ctx, transactionID) if err != nil { if errors.Is(err, arweave.ErrorNotFound) { - zap.L().Warn("Bundle transaction not found", + zap.L().Error("bundle transaction not found", zap.String("transaction_id", transactionID)) return nil, nil } @@ -642,7 +642,7 @@ func (s *dataSource) pullBundleTransactions(ctx context.Context, transactionID s header, err := decoder.DecodeHeader() if err != nil { // Ignore invalid bundle transaction. - zap.L().Error("Failed to decode bundle header, discarding invalid bundle transaction", + zap.L().Error("failed to decode bundle header, discarding invalid bundle transaction", zap.String("transaction_id", transactionID), zap.Error(err)) @@ -655,7 +655,7 @@ func (s *dataSource) pullBundleTransactions(ctx context.Context, transactionID s dataItem, err := decoder.DecodeDataItem() if err != nil { // Ignore invalid signature and data length. - zap.L().Error("Failed to decode data item", + zap.L().Error("failed to decode data item", zap.Error(err), zap.String("transaction_id", transactionID)) @@ -678,7 +678,7 @@ func (s *dataSource) pullBundleTransactions(ctx context.Context, transactionID s transactionOwner, err := arweave.PublicKeyToAddress(bundleTransaction.Owner) if err != nil { - zap.L().Error("Invalid owner of transaction", + zap.L().Error("invalid owner of transaction", zap.String("id", dataItemInfo.ID), zap.Any("owner", bundleTransaction.Owner), zap.Error(err)) @@ -688,7 +688,7 @@ func (s *dataSource) pullBundleTransactions(ctx context.Context, transactionID s // Filter owner addresses. if !lo.Contains(s.filter.OwnerAddresses, transactionOwner) { - zap.L().Debug("Skipping transaction with non-matching owner", + zap.L().Debug("skipping transaction with non-matching owner", zap.String("id", dataItemInfo.ID), zap.String("owner", transactionOwner)) @@ -703,7 +703,7 @@ func (s *dataSource) pullBundleTransactions(ctx context.Context, transactionID s if err != nil { // when pull data from arweave, sometimes it will return INTERNAL_ERROR; received from peer, we can ignore it. if strings.Contains(err.Error(), "INTERNAL_ERROR; received from peer") { - zap.L().Warn("Ignoring INTERNAL_ERROR from peer", + zap.L().Warn("ignoring internal error from peer", zap.String("data_item_id", dataItemInfo.ID)) continue @@ -718,7 +718,7 @@ func (s *dataSource) pullBundleTransactions(ctx context.Context, transactionID s bundleTransactions = append(bundleTransactions, &bundleTransaction) } - zap.L().Debug("Successfully pull bundle transactions", + zap.L().Debug("successfully pull bundle transactions", zap.String("transaction_id", transactionID)) return bundleTransactions, nil @@ -726,14 +726,14 @@ func (s *dataSource) pullBundleTransactions(ctx context.Context, transactionID s // GroupBundleTransactions groups bundle transactions by block. func (s *dataSource) GroupBundleTransactions(transactions []*arweave.Transaction, block *arweave.Block) []string { - zap.L().Debug("Grouping bundle transactions by block", + zap.L().Debug("grouping bundle transactions by block", zap.Int("transaction_count", len(transactions))) filtered := lo.FilterMap(transactions, func(transaction *arweave.Transaction, _ int) (string, bool) { hasBundleFormatTag := lo.ContainsBy(transaction.Tags, func(tag arweave.Tag) bool { tagName, err := base64.RawURLEncoding.DecodeString(tag.Name) if err != nil { - zap.L().Error("Failed to decode bundle format tag name", + zap.L().Error("failed to decode bundle format tag name", zap.String("transaction_id", transaction.ID), zap.Error(err)) @@ -742,7 +742,7 @@ func (s *dataSource) GroupBundleTransactions(transactions []*arweave.Transaction tagValue, err := base64.RawURLEncoding.DecodeString(tag.Value) if err != nil { - zap.L().Error("Failed to decode bundle format tag value", + zap.L().Error("failed to decode bundle format tag value", zap.String("transaction_id", transaction.ID), zap.Error(err)) @@ -755,7 +755,7 @@ func (s *dataSource) GroupBundleTransactions(transactions []*arweave.Transaction hasBundleVersionTag := lo.ContainsBy(transaction.Tags, func(tag arweave.Tag) bool { tagName, err := base64.RawURLEncoding.DecodeString(tag.Name) if err != nil { - zap.L().Error("Failed to decode bundle version tag name", + zap.L().Error("failed to decode bundle version tag name", zap.String("transaction_id", transaction.ID), zap.Error(err)) @@ -765,7 +765,7 @@ func (s *dataSource) GroupBundleTransactions(transactions []*arweave.Transaction tagValue, err := base64.RawURLEncoding.DecodeString(tag.Value) if err != nil { - zap.L().Error("Failed to decode bundle version tag value", + zap.L().Error("failed to decode bundle version tag value", zap.String("transaction_id", transaction.ID), zap.Error(err)) @@ -776,20 +776,20 @@ func (s *dataSource) GroupBundleTransactions(transactions []*arweave.Transaction }) if !(hasBundleFormatTag && hasBundleVersionTag) { - zap.L().Debug("Transaction missing required bundle tags", + zap.L().Debug("transaction missing required bundle tags", zap.String("transaction_id", transaction.ID)) return "", false } if !lo.Contains(block.Txs, transaction.ID) { - zap.L().Debug("Transaction not found in block", + zap.L().Debug("transaction not found in block", zap.String("transaction_id", transaction.ID)) return "", false } owner, err := arweave.PublicKeyToAddress(transaction.Owner) if err != nil { - zap.L().Error("Invalid owner of transaction", + zap.L().Error("invalid owner of transaction", zap.String("transaction_id", transaction.ID), zap.Error(err)) @@ -799,7 +799,7 @@ func (s *dataSource) GroupBundleTransactions(transactions []*arweave.Transaction return transaction.ID, lo.Contains(s.filter.BundlrAddresses, owner) }) - zap.L().Debug("Successfully grouped bundle transactions", + zap.L().Debug("successfully grouped bundle transactions", zap.Int("filtered_count", len(filtered))) return filtered @@ -807,13 +807,13 @@ func (s *dataSource) GroupBundleTransactions(transactions []*arweave.Transaction // discardRootBundleTransaction discards the root bundle transaction. func (s *dataSource) discardRootBundleTransaction(transactions []*arweave.Transaction) []*arweave.Transaction { - zap.L().Debug("Discarding root bundle transactions", + zap.L().Debug("discarding root bundle transactions", zap.Int("transaction_count", len(transactions))) filtered := lo.Filter(transactions, func(transaction *arweave.Transaction, _ int) bool { transactionOwner, err := arweave.PublicKeyToAddress(transaction.Owner) if err != nil { - zap.L().Error("Invalid transaction owner", + zap.L().Error("invalid transaction owner", zap.String("transaction_id", transaction.ID), zap.Error(err)) @@ -823,7 +823,7 @@ func (s *dataSource) discardRootBundleTransaction(transactions []*arweave.Transa return !lo.Contains(s.filter.BundlrAddresses, transactionOwner) }) - zap.L().Debug("Successfully discarded root bundle transactions", + zap.L().Debug("successfully discarded root bundle transactions", zap.Int("original_count", len(transactions)), zap.Int("filtered_count", len(filtered))) @@ -832,7 +832,7 @@ func (s *dataSource) discardRootBundleTransaction(transactions []*arweave.Transa // discardDuplicateBundleTransaction discards duplicate bundle transactions. func (s *dataSource) discardDuplicateBundleTransaction(transactions []*arweave.Transaction) []*arweave.Transaction { - zap.L().Debug("Discarding duplicate bundle transactions", + zap.L().Debug("discarding duplicate bundle transactions", zap.Int("transaction_count", len(transactions))) var ( @@ -842,7 +842,7 @@ func (s *dataSource) discardDuplicateBundleTransaction(transactions []*arweave.T for index := range transactions { if _, found := cache[transactions[index].ID]; found { - zap.L().Debug("Found duplicate transaction", + zap.L().Debug("found duplicate transaction", zap.String("transaction_id", transactions[index].ID)) continue @@ -853,7 +853,7 @@ func (s *dataSource) discardDuplicateBundleTransaction(transactions []*arweave.T results = append(results, transactions[index]) } - zap.L().Debug("Successfully discarded duplicate bundle transactions", + zap.L().Debug("successfully discarded duplicate bundle transactions", zap.Int("original_count", len(transactions)), zap.Int("filtered_count", len(results))) @@ -862,14 +862,14 @@ func (s *dataSource) discardDuplicateBundleTransaction(transactions []*arweave.T // filterOwnerTransaction filters owner transactions. func (s *dataSource) filterOwnerTransaction(transactions []*arweave.Transaction, ownerAddress []string) []*arweave.Transaction { - zap.L().Debug("Filtering transactions by owner", + zap.L().Debug("filtering transactions by owner", zap.Int("transaction_count", len(transactions)), zap.Strings("owner_addresses", ownerAddress)) filtered := lo.Filter(transactions, func(transaction *arweave.Transaction, _ int) bool { transactionOwner, err := arweave.PublicKeyToAddress(transaction.Owner) if err != nil { - zap.L().Error("Invalid transaction owner", + zap.L().Error("invalid transaction owner", zap.String("transaction_id", transaction.ID), zap.Error(err)) @@ -879,7 +879,7 @@ func (s *dataSource) filterOwnerTransaction(transactions []*arweave.Transaction, return lo.Contains(ownerAddress, transactionOwner) }) - zap.L().Debug("Successfully filtered transactions by owner", + zap.L().Debug("successfully filtered transactions by owner", zap.Int("original_count", len(transactions)), zap.Int("filtered_count", len(filtered))) @@ -888,7 +888,7 @@ func (s *dataSource) filterOwnerTransaction(transactions []*arweave.Transaction, // buildTasks builds tasks from blocks and transactions. func (s *dataSource) buildTasks(_ context.Context, blocks []*arweave.Block, transactions []*arweave.Transaction) *engine.Tasks { - zap.L().Debug("Building tasks from blocks and transactions", + zap.L().Debug("building tasks from blocks and transactions", zap.Int("block_count", len(blocks)), zap.Int("transaction_count", len(transactions))) @@ -906,7 +906,7 @@ func (s *dataSource) buildTasks(_ context.Context, blocks []*arweave.Block, tran }) } - zap.L().Debug("Successfully built tasks", + zap.L().Debug("successfully built tasks", zap.Int("task_count", len(tasks.Tasks))) return &tasks @@ -914,7 +914,7 @@ func (s *dataSource) buildTasks(_ context.Context, blocks []*arweave.Block, tran // NewSource creates a new arweave dataSource. func NewSource(config *config.Module, sourceFilter engine.DataSourceFilter, checkpoint *engine.Checkpoint, redisClient rueidis.Client) (engine.DataSource, error) { - zap.L().Debug("Creating new Arweave data source") + zap.L().Debug("creating new arweave data source") var ( state State @@ -947,7 +947,7 @@ func NewSource(config *config.Module, sourceFilter engine.DataSourceFilter, chec return nil, fmt.Errorf("parse config: %w", err) } - zap.L().Info("Successfully created new Arweave data source") + zap.L().Info("successfully created new arweave data source") return &instance, nil } diff --git a/internal/engine/protocol/ethereum/data_source.go b/internal/engine/protocol/ethereum/data_source.go index da9c248f5..fdde53bb4 100644 --- a/internal/engine/protocol/ethereum/data_source.go +++ b/internal/engine/protocol/ethereum/data_source.go @@ -86,7 +86,7 @@ func (s *dataSource) Start(ctx context.Context, tasksChan chan<- *engine.Tasks, } }() - zap.L().Info("Successfully started Ethereum data source") + zap.L().Info("successfully started ethereum data source") } func (s *dataSource) initialize(ctx context.Context) (err error) { @@ -104,7 +104,7 @@ func (s *dataSource) pollBlocks(ctx context.Context, tasksChan chan<- *engine.Ta // Set the block number to the start block number if it is greater than the current block number. if s.option.BlockStart != nil && s.option.BlockStart.Uint64() > s.state.BlockNumber { s.state.BlockNumber = s.option.BlockStart.Uint64() - zap.L().Debug("Updated block number from start block", + zap.L().Debug("updated block number from start block", zap.Uint64("block.number.start", s.option.BlockStart.Uint64()), zap.Uint64("block.number.current", s.state.BlockNumber)) } @@ -127,7 +127,7 @@ func (s *dataSource) pollBlocks(ctx context.Context, tasksChan chan<- *engine.Ta if remoteBlockStart > s.state.BlockNumber { s.state.BlockNumber = remoteBlockStart - zap.L().Debug("Updated block number from remote", zap.Uint64("newBlockNumber", s.state.BlockNumber)) + zap.L().Debug("updated block number from remote", zap.Uint64("newBlockNumber", s.state.BlockNumber)) } blockNumberStart := s.state.BlockNumber + 1 @@ -141,7 +141,7 @@ func (s *dataSource) pollBlocks(ctx context.Context, tasksChan chan<- *engine.Ta return fmt.Errorf("get latest block number: %w", err) } - zap.L().Debug("Retrieved latest block number from remote", + zap.L().Debug("retrieved latest block number from remote", zap.Uint64("block.number.remote", blockNumber.Uint64())) blockNumberLatestRemote = blockNumber.Uint64() @@ -165,7 +165,7 @@ func (s *dataSource) pollBlocks(ctx context.Context, tasksChan chan<- *engine.Ta return blockNumber.Uint64() <= blockNumberLatestRemote }) - zap.L().Debug("Processing block range", + zap.L().Debug("processing block range", zap.String("block.number.start", blockNumbers[0].String()), zap.String("block.number.end", blockNumbers[len(blockNumbers)-1].String())) @@ -208,7 +208,7 @@ func (s *dataSource) pollBlocks(ctx context.Context, tasksChan chan<- *engine.Ta s.state.BlockHash = latestBlock.Hash s.state.BlockNumber = latestBlock.Number.Uint64() - zap.L().Debug("Successfully polled blocks", + zap.L().Debug("successfully polled blocks", zap.String("block.hash", s.state.BlockHash.String()), zap.Uint64("block.number", s.state.BlockNumber), zap.Int("tasks.count", len(tasks.Tasks))) @@ -222,7 +222,7 @@ func (s *dataSource) pollLogs(ctx context.Context, tasksChan chan<- *engine.Task if s.option.BlockStart != nil && s.option.BlockStart.Uint64() > s.state.BlockNumber { s.state.BlockNumber = s.option.BlockStart.Uint64() - zap.L().Debug("Updated initial block number from BlockStart option", + zap.L().Debug("updated initial block number from block start option", zap.Uint64("block.number", s.state.BlockNumber)) } @@ -246,7 +246,7 @@ func (s *dataSource) pollLogs(ctx context.Context, tasksChan chan<- *engine.Task if remoteBlockStart > s.state.BlockNumber { s.state.BlockNumber = remoteBlockStart - zap.L().Debug("Updated block number from remote", + zap.L().Debug("updated block number from remote", zap.Uint64("newBlockNumber", s.state.BlockNumber)) } @@ -279,7 +279,7 @@ func (s *dataSource) pollLogs(ctx context.Context, tasksChan chan<- *engine.Task // The block number end is the start block number plus the number of blocks to be processed in parallel. blockNumberEnd := min(blockNumberStart+*s.option.ConcurrentBlockRequests-1, blockNumberStart) - zap.L().Debug("Processing block range", + zap.L().Debug("processing block range", zap.Uint64("block.start", blockNumberStart), zap.Uint64("block.end", blockNumberEnd)) @@ -305,7 +305,7 @@ func (s *dataSource) pollLogs(ctx context.Context, tasksChan chan<- *engine.Task var latestBlock *ethereum.Block if len(logs) == 0 { - zap.L().Debug("No logs found in block range", + zap.L().Debug("no logs found in block range", zap.Uint64("block.start", blockNumberStart), zap.Uint64("block.end", blockNumberEnd)) @@ -318,7 +318,7 @@ func (s *dataSource) pollLogs(ctx context.Context, tasksChan chan<- *engine.Task s.pushTasks(ctx, tasksChan, new(engine.Tasks)) } else { - zap.L().Debug("Found logs in block range", + zap.L().Debug("found logs in block range", zap.Int("logs.count", len(logs)), zap.Uint64("block.start", blockNumberStart), zap.Uint64("block.end", blockNumberEnd)) @@ -354,7 +354,7 @@ func (s *dataSource) processLogs(ctx context.Context, logs []*ethereum.Log, task return transactionHash }) - zap.L().Debug("Processing unique transaction hashes", + zap.L().Debug("processing unique transaction hashes", zap.Int("transaction.hashes.count", len(transactionHashes))) blockNumbers := lo.Map(logs, func(log *ethereum.Log, _ int) *big.Int { @@ -365,7 +365,7 @@ func (s *dataSource) processLogs(ctx context.Context, logs []*ethereum.Log, task return blockNumber.Uint64() }) - zap.L().Debug("Processing unique block numbers", + zap.L().Debug("processing unique block numbers", zap.Int("block.numbers.count", len(blockNumbers))) blocks, err := s.getBlocks(ctx, blockNumbers) @@ -383,7 +383,6 @@ func (s *dataSource) processLogs(ctx context.Context, logs []*ethereum.Log, task latestBlock, exist := lo.Last(blocks) if !exist { - zap.L().Warn("No blocks found after filtering") return nil, fmt.Errorf("empty blocks") } @@ -403,7 +402,7 @@ func (s *dataSource) processLogs(ctx context.Context, logs []*ethereum.Log, task tasks.Tasks = append(tasks.Tasks, lo.Map(blockTasks, func(blockTask *Task, _ int) engine.Task { return blockTask })...) } - zap.L().Debug("Successfully built tasks from logs", + zap.L().Debug("successfully built tasks from logs", zap.Int("tasks.count", len(tasks.Tasks)), zap.Int("blocks.count", len(blocks))) @@ -420,7 +419,7 @@ func (s *dataSource) getBlocks(ctx context.Context, blockNumbers []*big.Int) ([] WithCancelOnError() batches := lo.Chunk(blockNumbers, int(*s.option.BlockBatchSize)) - zap.L().Debug("Processing block batches", + zap.L().Debug("processing block batches", zap.Int("batches.count", len(batches)), zap.Int("batch.size", int(*s.option.BlockBatchSize))) @@ -444,7 +443,7 @@ func (s *dataSource) getBlocks(ctx context.Context, blockNumbers []*big.Int) ([] return blocks[left].Number.Cmp(blocks[right].Number) == -1 }) - zap.L().Debug("Successfully retrieved blocks", + zap.L().Debug("successfully retrieved blocks", zap.Int("blocks.count", len(blocks))) return blocks, nil @@ -464,7 +463,7 @@ func (s *dataSource) getReceipts(ctx context.Context, blocks []*ethereum.Block) }) }) - zap.L().Debug("Getting receipts by transaction hashes", + zap.L().Debug("getting receipts by transaction hashes", zap.Int("transaction.count", len(lo.Flatten(transactionHashes)))) return s.getReceiptsByTransactionHashes(ctx, lo.Flatten(transactionHashes)) @@ -473,7 +472,7 @@ func (s *dataSource) getReceipts(ctx context.Context, blocks []*ethereum.Block) return block.Number }) - zap.L().Debug("Getting receipts by block numbers", + zap.L().Debug("getting receipts by block numbers", zap.Int("block.count", len(blockNumbers))) return s.getReceiptsByBlockNumbers(ctx, blockNumbers) @@ -487,7 +486,7 @@ func (s *dataSource) getReceiptsByBlockNumbers(ctx context.Context, blockNumbers WithCancelOnError() batches := lo.Chunk(blockNumbers, int(*s.option.BlockReceiptsBatchSize)) - zap.L().Debug("Processing receipt batches by block numbers", + zap.L().Debug("processing receipt batches by block numbers", zap.Int("batches.count", len(batches)), zap.Int("batch.size", int(*s.option.BlockReceiptsBatchSize))) @@ -510,7 +509,7 @@ func (s *dataSource) getReceiptsByBlockNumbers(ctx context.Context, blockNumbers } receipts := lo.Flatten(batchResults) - zap.L().Debug("Successfully retrieved receipts by block numbers", + zap.L().Debug("successfully retrieved receipts by block numbers", zap.Int("receipts.count", len(receipts))) return receipts, nil @@ -523,7 +522,7 @@ func (s *dataSource) getReceiptsByTransactionHashes(ctx context.Context, transac WithCancelOnError() batches := lo.Chunk(transactionHashes, int(*s.option.BlockReceiptsBatchSize)) - zap.L().Debug("Processing receipt batches by transaction hashes", + zap.L().Debug("processing receipt batches by transaction hashes", zap.Int("batches.count", len(batches)), zap.Int("batch.size", int(*s.option.BlockReceiptsBatchSize))) @@ -546,7 +545,7 @@ func (s *dataSource) getReceiptsByTransactionHashes(ctx context.Context, transac } receipts := lo.Flatten(batchResults) - zap.L().Debug("Successfully retrieved receipts by transaction hashes", + zap.L().Debug("successfully retrieved receipts by transaction hashes", zap.Int("receipts.count", len(receipts))) return receipts, nil @@ -558,7 +557,7 @@ func (s *dataSource) buildTasks(block *ethereum.Block, receipts []*ethereum.Rece header = block.Header() ) - zap.L().Debug("Building tasks for block", + zap.L().Debug("building tasks for block", zap.String("block.hash", block.Hash.String()), zap.Uint64("block.number", block.Number.Uint64()), zap.Int("transactions.count", len(block.Transactions))) @@ -592,7 +591,7 @@ func (s *dataSource) buildTasks(block *ethereum.Block, receipts []*ethereum.Rece tasks[index] = &task } - zap.L().Debug("Successfully built tasks for block", + zap.L().Debug("successfully built tasks for block", zap.String("block.hash", block.Hash.String()), zap.Int("tasks.count", len(tasks))) @@ -605,14 +604,14 @@ func (s *dataSource) pushTasks(ctx context.Context, tasksChan chan<- *engine.Tas _, span := otel.Tracer("").Start(ctx, "DataSource pushTasks", trace.WithSpanKind(trace.SpanKindProducer)) defer span.End() - zap.L().Debug("Pushing tasks to channel", + zap.L().Debug("pushing tasks to channel", zap.Int("tasks.count", len(tasks.Tasks))) tasksChan <- tasks } func NewSource(config *config.Module, sourceFilter engine.DataSourceFilter, checkpoint *engine.Checkpoint, redisClient rueidis.Client) (engine.DataSource, error) { - zap.L().Debug("Creating new Ethereum data source") + zap.L().Debug("creating new ethereum data source") var ( state State @@ -645,7 +644,7 @@ func NewSource(config *config.Module, sourceFilter engine.DataSourceFilter, chec return nil, fmt.Errorf("parse config: %w", err) } - zap.L().Info("Successfully initialized data source", + zap.L().Info("successfully initialized data source", zap.Any("option", instance.option), zap.String("network", config.Network.String())) diff --git a/internal/engine/protocol/ethereum/task.go b/internal/engine/protocol/ethereum/task.go index bc8a7e921..71bfca922 100644 --- a/internal/engine/protocol/ethereum/task.go +++ b/internal/engine/protocol/ethereum/task.go @@ -8,6 +8,7 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core/types" "github.com/rss3-network/node/internal/engine" + "github.com/rss3-network/node/internal/utils" "github.com/rss3-network/node/provider/ethereum" activityx "github.com/rss3-network/protocol-go/schema/activity" "github.com/rss3-network/protocol-go/schema/network" @@ -83,7 +84,7 @@ func (t Task) BuildActivity(options ...activityx.Option) (*activityx.Activity, e To: to.String(), Type: typex.Unknown, Fee: &activityx.Fee{ - Amount: decimal.NewFromBigInt(feeAmount, 0), + Amount: decimal.NewFromBigInt(utils.GetBigInt(feeAmount), 0), Decimal: defaultFeeDecimal, }, Calldata: &activityx.Calldata{ @@ -126,11 +127,11 @@ func (t Task) buildFeeDefault() (*big.Int, error) { ) if t.Receipt.EffectiveGasPrice != nil { - gasPrice = decimal.NewFromBigInt(t.Receipt.EffectiveGasPrice, 0) + gasPrice = decimal.NewFromBigInt(utils.GetBigInt(t.Receipt.EffectiveGasPrice), 0) } else { var ( - baseFee = decimal.NewFromBigInt(t.Header.BaseFee, 0) - gasTipCap = decimal.NewFromBigInt(t.Transaction.GasTipCap, 0) + baseFee = decimal.NewFromBigInt(utils.GetBigInt(t.Header.BaseFee), 0) + gasTipCap = decimal.NewFromBigInt(utils.GetBigInt(t.Transaction.GasTipCap), 0) ) gasPrice = baseFee.Add(gasTipCap) diff --git a/internal/engine/protocol/farcaster/data_source.go b/internal/engine/protocol/farcaster/data_source.go index 9b9251035..c731104ca 100644 --- a/internal/engine/protocol/farcaster/data_source.go +++ b/internal/engine/protocol/farcaster/data_source.go @@ -46,7 +46,7 @@ func (s *dataSource) State() json.RawMessage { } func (s *dataSource) Start(ctx context.Context, tasksChan chan<- *engine.Tasks, errorChan chan<- error) { - zap.L().Debug("Starting Farcaster data source") + zap.L().Debug("starting farcaster data source") if err := s.initialize(); err != nil { errorChan <- fmt.Errorf("initialize dataSource: %w", err) @@ -54,7 +54,7 @@ func (s *dataSource) Start(ctx context.Context, tasksChan chan<- *engine.Tasks, return } - zap.L().Debug("Starting historical casts polling") + zap.L().Debug("starting historical casts polling") // poll historical casts go func() { if err := retryOperation(ctx, func(ctx context.Context) error { @@ -62,12 +62,12 @@ func (s *dataSource) Start(ctx context.Context, tasksChan chan<- *engine.Tasks, }); err != nil { errorChan <- err } else { - zap.L().Debug("Completed polling historical casts") + zap.L().Debug("completed polling historical casts") return } }() - zap.L().Debug("Starting historical reactions polling") + zap.L().Debug("starting historical reactions polling") // poll historical reactions go func() { if err := retryOperation(ctx, func(ctx context.Context) error { @@ -75,12 +75,12 @@ func (s *dataSource) Start(ctx context.Context, tasksChan chan<- *engine.Tasks, }); err != nil { errorChan <- err } else { - zap.L().Debug("Completed polling historical reactions") + zap.L().Debug("completed polling historical reactions") return } }() - zap.L().Debug("Starting latest events polling") + zap.L().Debug("starting latest events polling") // poll latest events go func() { if err := retryOperation(ctx, func(ctx context.Context) error { @@ -90,7 +90,7 @@ func (s *dataSource) Start(ctx context.Context, tasksChan chan<- *engine.Tasks, } }() - zap.L().Info("Successfully started Farcaster data source") + zap.L().Info("successfully started farcaster data source") } func (s *dataSource) initialize() (err error) { @@ -109,13 +109,13 @@ func (s *dataSource) initialize() (err error) { func (s *dataSource) pollCasts(ctx context.Context, tasksChan chan<- *engine.Tasks) error { // Check if backfill of casts is complete. if s.state.CastsBackfill { - zap.L().Debug("Casts backfill is already complete") + zap.L().Debug("casts backfill is already complete") return nil } // If fid is 0 and backfill is not complete, fetch the maximum fid from the Farcaster Hub. if s.state.CastsFid == 0 && !s.state.CastsBackfill { - zap.L().Debug("Fetching maximum fid from Farcaster Hub") + zap.L().Debug("fetching maximum fid from farcaster hub") fidsResponse, err := s.farcasterClient.GetFids(ctx, true, lo.ToPtr(1)) @@ -125,12 +125,12 @@ func (s *dataSource) pollCasts(ctx context.Context, tasksChan chan<- *engine.Tas s.pendingState.CastsFid = fidsResponse.Fids[0] - zap.L().Debug("Successfully fetched maximum fid", zap.Uint64("fid", fidsResponse.Fids[0])) + zap.L().Debug("successfully fetched maximum fid", zap.Uint64("fid", fidsResponse.Fids[0])) } // Poll casts by fid until backfill is complete. for !s.state.CastsBackfill { - zap.L().Debug("Polling casts for fid", zap.Uint64("fid", s.pendingState.CastsFid)) + zap.L().Debug("polling casts for fid", zap.Uint64("fid", s.pendingState.CastsFid)) if err := s.pollCastsByFid(ctx, lo.ToPtr(int64(s.pendingState.CastsFid)), "", tasksChan); err != nil { return err @@ -142,7 +142,7 @@ func (s *dataSource) pollCasts(ctx context.Context, tasksChan chan<- *engine.Tas // If pending fid is 0, mark backfill as complete. if s.pendingState.CastsFid == 0 { - zap.L().Debug("Completed casts backfill") + zap.L().Debug("completed casts backfill") s.pendingState.CastsBackfill = true s.state = s.pendingState @@ -156,7 +156,7 @@ func (s *dataSource) pollCasts(ctx context.Context, tasksChan chan<- *engine.Tas func (s *dataSource) pollCastsByFid(ctx context.Context, fid *int64, pageToken string, tasksChan chan<- *engine.Tasks) error { for { // Fetch casts by fid. - zap.L().Debug("Fetching casts by fid", zap.Int64("fid", *fid), zap.String("pageToken", pageToken)) + zap.L().Debug("fetching casts by fid", zap.Int64("fid", *fid), zap.String("pageToken", pageToken)) castsByFidResponse, err := s.farcasterClient.GetCastsByFid(ctx, fid, true, nil, pageToken) if err != nil { @@ -167,7 +167,7 @@ func (s *dataSource) pollCastsByFid(ctx context.Context, fid *int64, pageToken s return message.Data.Timestamp >= s.startFarcasterTimestamp }) - zap.L().Debug("Filtered messages by timestamp", + zap.L().Debug("filtered messages by timestamp", zap.Int("total", len(castsByFidResponse.Messages)), zap.Int("filtered", len(messages))) @@ -179,7 +179,7 @@ func (s *dataSource) pollCastsByFid(ctx context.Context, fid *int64, pageToken s // If the fetched casts do not have a next page token // or the number of messages is less than the number of fetched messages if castsByFidResponse.NextPageToken == "" || len(messages) < len(castsByFidResponse.Messages) { - zap.L().Debug("Completed fetching casts for fid", zap.Int64("fid", *fid)) + zap.L().Debug("completed fetching casts for fid", zap.Int64("fid", *fid)) return nil } // Update the page token for the next iteration @@ -192,13 +192,13 @@ func (s *dataSource) pollCastsByFid(ctx context.Context, fid *int64, pageToken s func (s *dataSource) pollReactions(ctx context.Context, tasksChan chan<- *engine.Tasks) error { // Check if backfill of reactions is complete. if s.state.ReactionsBackfill { - zap.L().Debug("Reactions backfill is already complete") + zap.L().Debug("reactions backfill is already complete") return nil } // If fid is 0 and backfill is not complete, fetch the maximum fid from the Farcaster Hub. if s.state.ReactionsFid == 0 && !s.state.ReactionsBackfill { - zap.L().Info("Fetching maximum fid from Farcaster Hub") + zap.L().Info("fetching maximum fid from farcaster hub") fidsResponse, err := s.farcasterClient.GetFids(ctx, true, lo.ToPtr(1)) @@ -207,12 +207,12 @@ func (s *dataSource) pollReactions(ctx context.Context, tasksChan chan<- *engine } s.pendingState.ReactionsFid = fidsResponse.Fids[0] - zap.L().Debug("Successfully fetched maximum fid", zap.Uint64("fid", fidsResponse.Fids[0])) + zap.L().Debug("successfully fetched maximum fid", zap.Uint64("fid", fidsResponse.Fids[0])) } // Poll reactions by fid until backfill is complete. for !s.state.ReactionsBackfill { - zap.L().Debug("Polling reactions for fid", zap.Uint64("fid", s.pendingState.ReactionsFid)) + zap.L().Debug("polling reactions for fid", zap.Uint64("fid", s.pendingState.ReactionsFid)) if err := s.pollReactionsByFid(ctx, lo.ToPtr(int64(s.pendingState.ReactionsFid)), "", tasksChan); err != nil { return err @@ -224,7 +224,7 @@ func (s *dataSource) pollReactions(ctx context.Context, tasksChan chan<- *engine // If pending fid is 0, mark backfill as complete. if s.pendingState.ReactionsFid == 0 { - zap.L().Debug("Completed reactions backfill") + zap.L().Debug("completed reactions backfill") s.pendingState.ReactionsBackfill = true s.state = s.pendingState @@ -238,7 +238,7 @@ func (s *dataSource) pollReactions(ctx context.Context, tasksChan chan<- *engine func (s *dataSource) pollReactionsByFid(ctx context.Context, fid *int64, pageToken string, tasksChan chan<- *engine.Tasks) error { for { // Fetch reactions by fid. - zap.L().Debug("Fetching reactions by fid", zap.Int64("fid", *fid), zap.String("pageToken", pageToken)) + zap.L().Debug("fetching reactions by fid", zap.Int64("fid", *fid), zap.String("pageToken", pageToken)) reactionsByFidResponse, err := s.farcasterClient.GetReactionsByFid(ctx, fid, true, nil, pageToken, farcaster.ReactionTypeRecast.String()) if err != nil { @@ -249,7 +249,7 @@ func (s *dataSource) pollReactionsByFid(ctx context.Context, fid *int64, pageTok return message.Data.Timestamp >= s.startFarcasterTimestamp }) - zap.L().Debug("Filtered messages by timestamp", + zap.L().Debug("filtered messages by timestamp", zap.Int("total", len(reactionsByFidResponse.Messages)), zap.Int("filtered", len(messages))) @@ -260,7 +260,7 @@ func (s *dataSource) pollReactionsByFid(ctx context.Context, fid *int64, pageTok // If the fetched reactions do not have a next page token // or the number of messages is less than the number of fetched messages if reactionsByFidResponse.NextPageToken == "" || len(messages) < len(reactionsByFidResponse.Messages) { - zap.L().Debug("Completed fetching reactions for fid", zap.Int64("fid", *fid)) + zap.L().Debug("completed fetching reactions for fid", zap.Int64("fid", *fid)) return nil } // Update the page token for the next iteration @@ -273,11 +273,11 @@ func (s *dataSource) buildFarcasterMessageTasks(ctx context.Context, messages [] var tasks engine.Tasks if len(messages) == 0 { - zap.L().Debug("No messages to build tasks") + zap.L().Debug("no messages to build tasks") return &tasks } - zap.L().Debug("Building tasks from messages", + zap.L().Debug("building tasks from messages", zap.Int("messages.count", len(messages))) resultPool := pool.NewWithResults[*Task]().WithMaxGoroutines(lo.Ternary(len(messages) < 20*runtime.NumCPU(), len(messages), 20*runtime.NumCPU())) @@ -289,7 +289,7 @@ func (s *dataSource) buildFarcasterMessageTasks(ctx context.Context, messages [] switch message.Data.Type { case farcaster.MessageTypeCastAdd.String(): if err := s.fillCastParams(ctx, &message); err != nil { - zap.L().Error("Failed to fill cast parameters", + zap.L().Error("failed to fill cast parameters", zap.Uint64("fid", message.Data.Fid), zap.String("hash", message.Hash), zap.Error(err)) @@ -298,7 +298,7 @@ func (s *dataSource) buildFarcasterMessageTasks(ctx context.Context, messages [] } case farcaster.MessageTypeReactionAdd.String(): if err := s.fillReactionParams(ctx, &message); err != nil { - zap.L().Error("Failed to fill reaction parameters", + zap.L().Error("failed to fill reaction parameters", zap.Uint64("fid", message.Data.Fid), zap.String("hash", message.Hash), zap.Error(err)) @@ -320,7 +320,7 @@ func (s *dataSource) buildFarcasterMessageTasks(ctx context.Context, messages [] } } - zap.L().Debug("Successfully built tasks from messages", + zap.L().Debug("successfully built tasks from messages", zap.Int("tasks.count", len(tasks.Tasks))) return &tasks @@ -335,19 +335,19 @@ func (s *dataSource) pollEvents(ctx context.Context, tasksChan chan<- *engine.Ta if cursor == 0 { // If the cursor is 0, fetch the latest event ID from the Farcaster Hub. cursor = farcaster.ConvertTimestampMilliToEventID(time.Now().Add(-10 * time.Second).UnixMilli()) - zap.L().Debug("Starting event polling from current timestamp", + zap.L().Debug("starting event polling from current timestamp", zap.Uint64("event.id", cursor)) } for { // Fetch events from the Farcaster Hub using the cursor. - zap.L().Debug("Fetching events from Farcaster Hub", + zap.L().Debug("fetching events from farcaster hub", zap.Uint64("event.from.id", cursor)) eventsResponse, err := s.farcasterClient.GetEvents(ctx, lo.ToPtr(int64(cursor))) if err != nil || eventsResponse == nil { - zap.L().Error("Failed to fetch events from Farcaster Hub", + zap.L().Error("failed to fetch events from farcaster hub", zap.Uint64("event.from.id", cursor), zap.Error(err)) @@ -358,7 +358,7 @@ func (s *dataSource) pollEvents(ctx context.Context, tasksChan chan<- *engine.Ta // If the fetched events are empty, log an info message, wait for a default block time, and continue to the next iteration. if len(eventsResponse.Events) == 0 { - zap.L().Debug("No new events found, waiting for next poll", + zap.L().Debug("no new events found, waiting for next poll", zap.Uint64("event.from.id", cursor), zap.Duration("block.time", defaultBlockTime)) @@ -367,7 +367,7 @@ func (s *dataSource) pollEvents(ctx context.Context, tasksChan chan<- *engine.Ta continue } - zap.L().Debug("Processing fetched events", + zap.L().Debug("processing fetched events", zap.Int("events.count", len(eventsResponse.Events))) tasks := s.buildFarcasterEventTasks(ctx, eventsResponse.Events, tasksChan) @@ -379,7 +379,7 @@ func (s *dataSource) pollEvents(ctx context.Context, tasksChan chan<- *engine.Ta cursor = eventsResponse.NextPageEventID - zap.L().Debug("Successfully processed events batch", + zap.L().Debug("successfully processed events batch", zap.Uint64("next.event.id", cursor)) } } @@ -389,11 +389,11 @@ func (s *dataSource) buildFarcasterEventTasks(ctx context.Context, events []farc var tasks engine.Tasks if len(events) == 0 { - zap.L().Debug("No events to process") + zap.L().Debug("no events to process") return &tasks } - zap.L().Debug("Building tasks from events", zap.Int("events.count", len(events))) + zap.L().Debug("building tasks from events", zap.Int("events.count", len(events))) resultPool := pool.NewWithResults[*Task]().WithMaxGoroutines(lo.Ternary(len(events) < 20*runtime.NumCPU(), len(events), 20*runtime.NumCPU())) @@ -402,7 +402,7 @@ func (s *dataSource) buildFarcasterEventTasks(ctx context.Context, events []farc resultPool.Go(func() *Task { if event.Type != farcaster.HubEventTypeMergeMessage.String() { - zap.L().Debug("Skipping non-merge message event", zap.String("event.type", event.Type)) + zap.L().Debug("skipping non-merge message event", zap.String("event.type", event.Type)) return nil } @@ -410,7 +410,7 @@ func (s *dataSource) buildFarcasterEventTasks(ctx context.Context, events []farc switch message.Data.Type { case farcaster.MessageTypeCastAdd.String(): if err := s.fillCastParams(ctx, &message); err != nil { - zap.L().Error("Failed to fill cast parameters", + zap.L().Error("failed to fill cast parameters", zap.Uint64("fid", message.Data.Fid), zap.String("hash", message.Hash), zap.Error(err)) @@ -418,12 +418,12 @@ func (s *dataSource) buildFarcasterEventTasks(ctx context.Context, events []farc return nil } - zap.L().Debug("Successfully filled cast parameters", zap.String("hash", message.Hash)) + zap.L().Debug("successfully filled cast parameters", zap.String("hash", message.Hash)) case farcaster.MessageTypeReactionAdd.String(): if message.Data.ReactionBody.Type == farcaster.ReactionTypeRecast.String() { if err := s.fillReactionParams(ctx, &message); err != nil { - zap.L().Error("Failed to fill reaction parameters", + zap.L().Error("failed to fill reaction parameters", zap.Uint64("fid", message.Data.Fid), zap.String("hash", message.Hash), zap.Error(err)) @@ -431,9 +431,9 @@ func (s *dataSource) buildFarcasterEventTasks(ctx context.Context, events []farc return nil } - zap.L().Debug("Successfully filled recast parameters", zap.String("hash", message.Hash)) + zap.L().Debug("successfully filled recast parameters", zap.String("hash", message.Hash)) } else { - zap.L().Debug("Skipping non-recast reaction", zap.String("reaction.type", message.Data.ReactionBody.Type)) + zap.L().Debug("skipping non-recast reaction", zap.String("reaction.type", message.Data.ReactionBody.Type)) return nil } @@ -443,14 +443,14 @@ func (s *dataSource) buildFarcasterEventTasks(ctx context.Context, events []farc farcaster.MessageTypeUsernameProof.String(): fid := int64(message.Data.Fid) - zap.L().Debug("Processing verification/user data message", + zap.L().Debug("processing verification/user data message", zap.Int64("fid", fid), zap.String("message.type", message.Data.Type)) _, _ = s.updateProfileByFid(ctx, &fid) if message.Data.Type == farcaster.MessageTypeVerificationAddEthAddress.String() { - zap.L().Debug("Polling casts and reactions for new ETH address verification", + zap.L().Debug("polling casts and reactions for new ETH address verification", zap.Int64("fid", fid)) _ = s.pollCastsByFid(ctx, &fid, "", tasksChan) @@ -459,7 +459,7 @@ func (s *dataSource) buildFarcasterEventTasks(ctx context.Context, events []farc return nil default: - zap.L().Debug("Skipping unsupported message type", zap.String("type", message.Data.Type)) + zap.L().Debug("skipping unsupported message type", zap.String("type", message.Data.Type)) return nil } @@ -477,7 +477,7 @@ func (s *dataSource) buildFarcasterEventTasks(ctx context.Context, events []farc } } - zap.L().Debug("Successfully built tasks from events", + zap.L().Debug("successfully built tasks from events", zap.Int("total.events", len(events)), zap.Int("processed.tasks", len(tasks.Tasks))) @@ -489,19 +489,19 @@ func (s *dataSource) buildFarcasterEventTasks(ctx context.Context, events []farc func (s *dataSource) updateProfileByFid(ctx context.Context, fid *int64) (*model.Profile, error) { var username string - zap.L().Debug("Fetching user data by fid", zap.Int64("fid", *fid)) + zap.L().Debug("fetching user data by fid", zap.Int64("fid", *fid)) // owner username(handle) userData, err := s.farcasterClient.GetUserDataByFidAndType(ctx, fid, farcaster.UserDataTypeUsername.String()) if err != nil { - zap.L().Error("Failed to fetch user data by fid", zap.Error(err), zap.Int64("fid", *fid)) + zap.L().Error("failed to fetch user data by fid", zap.Error(err), zap.Int64("fid", *fid)) } else if userData.Data.UserDataBody != nil { username = userData.Data.UserDataBody.Value - zap.L().Debug("Found username for fid", zap.String("username", username), zap.Int64("fid", *fid)) + zap.L().Debug("found username for fid", zap.String("username", username), zap.Int64("fid", *fid)) } // custody address - zap.L().Debug("Fetching custody address", zap.Int64("fid", *fid)) + zap.L().Debug("fetching custody address", zap.Int64("fid", *fid)) custodyAddress, username, err := s.getCustodyAddress(ctx, fid, username) if err != nil { @@ -509,7 +509,7 @@ func (s *dataSource) updateProfileByFid(ctx context.Context, fid *int64) (*model } // eth addresses - zap.L().Debug("Fetching ETH addresses", zap.Int64("fid", *fid)) + zap.L().Debug("fetching eth addresses", zap.Int64("fid", *fid)) ethAddresses, err := s.getEthAddresses(ctx, fid) if err != nil { @@ -523,20 +523,20 @@ func (s *dataSource) updateProfileByFid(ctx context.Context, fid *int64) (*model EthAddresses: ethAddresses, } - zap.L().Debug("Saving profile to database", zap.Int64("fid", *fid)) + zap.L().Debug("saving profile to database", zap.Int64("fid", *fid)) if err = s.databaseClient.SaveDatasetFarcasterProfile(ctx, profile); err != nil { return nil, err } - zap.L().Debug("Successfully updated profile", zap.Int64("fid", *fid)) + zap.L().Debug("successfully updated profile", zap.Int64("fid", *fid)) return profile, nil } // getCustodyAddress get custody address by fid. func (s *dataSource) getCustodyAddress(ctx context.Context, fid *int64, username string) (string, string, error) { - zap.L().Debug("Fetching username proofs", zap.Int64("fid", *fid)) + zap.L().Debug("fetching username proofs", zap.Int64("fid", *fid)) userProofs, err := s.farcasterClient.GetUserNameProofsByFid(ctx, fid) if err != nil { @@ -553,7 +553,7 @@ func (s *dataSource) getCustodyAddress(ctx context.Context, fid *int64, username username = proof.Name } - zap.L().Debug("Found custody address from proofs", + zap.L().Debug("found custody address from proofs", zap.String("address", custodyAddress), zap.String("username", username)) @@ -562,7 +562,7 @@ func (s *dataSource) getCustodyAddress(ctx context.Context, fid *int64, username } if custodyAddress == "" { - zap.L().Debug("Fetching name proof by username", zap.String("username", username)) + zap.L().Debug("fetching name proof by username", zap.String("username", username)) nameProof, err := s.farcasterClient.GetUserNameProofByName(ctx, username) if err != nil || nameProof == nil { @@ -570,7 +570,7 @@ func (s *dataSource) getCustodyAddress(ctx context.Context, fid *int64, username } custodyAddress = nameProof.Owner - zap.L().Debug("Found custody address from name proof", zap.String("address", custodyAddress)) + zap.L().Debug("found custody address from name proof", zap.String("address", custodyAddress)) } return custodyAddress, username, nil @@ -578,7 +578,7 @@ func (s *dataSource) getCustodyAddress(ctx context.Context, fid *int64, username // getEthAddresses get eth addresses by fid. func (s *dataSource) getEthAddresses(ctx context.Context, fid *int64) ([]string, error) { - zap.L().Debug("Fetching verifications", zap.Int64("fid", *fid)) + zap.L().Debug("fetching verifications", zap.Int64("fid", *fid)) verifications, err := s.farcasterClient.GetVerificationsByFid(ctx, fid, "") if err != nil { @@ -591,7 +591,7 @@ func (s *dataSource) getEthAddresses(ctx context.Context, fid *int64) ([]string, if msg.Data.Type == farcaster.MessageTypeVerificationAddEthAddress.String() && msg.Data.VerificationAddEthAddressBody != nil && msg.Data.VerificationAddEthAddressBody.Protocol == farcaster.ProtocolEthereum.String() { address := common.HexToAddress(msg.Data.VerificationAddEthAddressBody.Address).String() ethAddresses = append(ethAddresses, address) - zap.L().Debug("Found ETH address", zap.String("address", address)) + zap.L().Debug("found eth address", zap.String("address", address)) } } @@ -607,7 +607,7 @@ func (s *dataSource) getProfileByFid(ctx context.Context, fid *int64) (*model.Pr err error ) - zap.L().Debug("Loading profile from database", zap.Int64("fid", *fid)) + zap.L().Debug("loading profile from database", zap.Int64("fid", *fid)) profile, err = s.databaseClient.LoadDatasetFarcasterProfile(ctx, *fid) if err != nil { @@ -615,7 +615,7 @@ func (s *dataSource) getProfileByFid(ctx context.Context, fid *int64) (*model.Pr } if profile != nil && profile.Username == "" && profile.CustodyAddress == "" && len(profile.EthAddresses) == 0 { - zap.L().Info("Profile incomplete, updating profile data", zap.Int64("fid", *fid)) + zap.L().Info("profile incomplete, updating profile data", zap.Int64("fid", *fid)) profile, err = s.updateProfileByFid(ctx, fid) if err != nil { @@ -628,7 +628,7 @@ func (s *dataSource) getProfileByFid(ctx context.Context, fid *int64) (*model.Pr // fillMentionsUsernames transfer mentions fid to username. func (s *dataSource) fillMentionsUsernames(ctx context.Context, message *farcaster.Message) error { - zap.L().Debug("Starting to fill mentions usernames", + zap.L().Debug("starting to fill mentions usernames", zap.Int("mentions_count", len(message.Data.CastAddBody.Mentions))) message.Data.CastAddBody.MentionsUsernames = make([]string, len(message.Data.CastAddBody.Mentions)) @@ -637,7 +637,7 @@ func (s *dataSource) fillMentionsUsernames(ctx context.Context, message *farcast profile, err := s.getProfileByFid(ctx, &fid) if err != nil { - zap.L().Error("Failed to fetch profile for mention", + zap.L().Error("failed to fetch profile for mention", zap.Int64("fid", fid), zap.Error(err)) @@ -645,7 +645,7 @@ func (s *dataSource) fillMentionsUsernames(ctx context.Context, message *farcast } message.Data.CastAddBody.MentionsUsernames[i] = profile.Username - zap.L().Debug("Successfully filled mention username", + zap.L().Debug("successfully filled mention username", zap.Int64("fid", fid), zap.String("username", profile.Username)) } @@ -656,12 +656,12 @@ func (s *dataSource) fillMentionsUsernames(ctx context.Context, message *farcast // fillProfile fill profile in each message. func (s *dataSource) fillProfile(ctx context.Context, message *farcaster.Message) error { fid := int64(message.Data.Fid) - zap.L().Debug("Fetching profile for message", zap.Int64("fid", fid)) + zap.L().Debug("fetching profile for message", zap.Int64("fid", fid)) profile, err := s.getProfileByFid(ctx, &fid) if err != nil { - zap.L().Error("Failed to fetch profile for message", + zap.L().Error("failed to fetch profile for message", zap.Int64("fid", fid), zap.Error(err)) @@ -670,7 +670,7 @@ func (s *dataSource) fillProfile(ctx context.Context, message *farcaster.Message message.Data.Profile = profile - zap.L().Debug("Successfully filled profile for message", zap.Int64("fid", fid)) + zap.L().Debug("successfully filled profile for message", zap.Int64("fid", fid)) return nil } @@ -679,7 +679,7 @@ func (s *dataSource) fillProfile(ctx context.Context, message *farcaster.Message func (s *dataSource) fillCastParams(ctx context.Context, message *farcaster.Message) error { if message.Data.CastAddBody.ParentCastID != nil { targetFid := int64(message.Data.CastAddBody.ParentCastID.Fid) - zap.L().Debug("Fetching parent cast", + zap.L().Debug("fetching parent cast", zap.Int64("target_fid", targetFid), zap.String("hash", message.Data.CastAddBody.ParentCastID.Hash)) @@ -715,7 +715,7 @@ func (s *dataSource) fillCastParams(ctx context.Context, message *farcaster.Mess func (s *dataSource) fillReactionParams(ctx context.Context, message *farcaster.Message) error { if message.Data.ReactionBody.Type == farcaster.ReactionTypeRecast.String() { targetFid := int64(message.Data.ReactionBody.TargetCastID.Fid) - zap.L().Debug("Fetching target cast for reaction", + zap.L().Debug("fetching target cast for reaction", zap.Int64("target_fid", targetFid), zap.String("hash", message.Data.ReactionBody.TargetCastID.Hash)) @@ -752,7 +752,7 @@ func retryOperation(ctx context.Context, operation func(ctx context.Context) err retry.Delay(1*time.Second), retry.DelayType(retry.BackOffDelay), retry.OnRetry(func(n uint, err error) { - zap.L().Warn("Retrying Farcaster data source operation", + zap.L().Warn("retrying farcaster data source operation", zap.Uint("attempt", n), zap.Error(err)) }), @@ -760,7 +760,7 @@ func retryOperation(ctx context.Context, operation func(ctx context.Context) err } func NewSource(config *config.Module, checkpoint *engine.Checkpoint, databaseClient database.Client) (engine.DataSource, error) { - zap.L().Debug("Creating new Farcaster data source") + zap.L().Debug("creating new farcaster data source") var ( state State @@ -769,7 +769,7 @@ func NewSource(config *config.Module, checkpoint *engine.Checkpoint, databaseCli // Initialize state from checkpoint. if checkpoint != nil { - zap.L().Debug("Initializing state from checkpoint") + zap.L().Debug("initializing state from checkpoint", zap.Any("checkpoint", checkpoint)) if err := json.Unmarshal(checkpoint.State, &state); err != nil { return nil, err @@ -787,16 +787,16 @@ func NewSource(config *config.Module, checkpoint *engine.Checkpoint, databaseCli return nil, fmt.Errorf("parse config: %w", err) } - zap.L().Info("Applied Farcaster options", zap.Any("option", instance.option)) + zap.L().Info("applied farcaster options", zap.Any("option", instance.option)) if instance.option.TimestampStart != nil { - zap.L().Debug("Setting start timestamp", + zap.L().Debug("setting start timestamp", zap.Int64("raw_timestamp", instance.option.TimestampStart.Int64())) instance.startFarcasterTimestamp = farcaster.CovertTimestampToFarcasterTime(instance.option.TimestampStart.Int64()) } - zap.L().Info("Successfully created Farcaster data source") + zap.L().Info("successfully created farcaster data source") return &instance, nil } diff --git a/internal/engine/protocol/near/data_source.go b/internal/engine/protocol/near/data_source.go index 7bf408370..3e2d4de43 100644 --- a/internal/engine/protocol/near/data_source.go +++ b/internal/engine/protocol/near/data_source.go @@ -44,7 +44,7 @@ func (s *dataSource) State() json.RawMessage { } func (s *dataSource) Start(ctx context.Context, tasksChan chan<- *engine.Tasks, errorChan chan<- error) { - zap.L().Info("Starting Near data source") + zap.L().Info("starting near data source") // Initialize dataSource. if err := s.initialize(ctx); err != nil { @@ -56,11 +56,11 @@ func (s *dataSource) Start(ctx context.Context, tasksChan chan<- *engine.Tasks, // Start a goroutine to poll blocks. go s.startPolling(ctx, tasksChan, errorChan) - zap.L().Info("Successfully started Near data source") + zap.L().Info("successfully started near data source") } func (s *dataSource) startPolling(ctx context.Context, tasksChan chan<- *engine.Tasks, errorChan chan<- error) { - zap.L().Debug("Starting block polling") + zap.L().Debug("starting block polling") retryableFunc := func() error { if err := s.pollBlocks(ctx, tasksChan); err != nil { @@ -76,7 +76,7 @@ func (s *dataSource) startPolling(ctx context.Context, tasksChan chan<- *engine. retry.DelayType(retry.BackOffDelay), retry.MaxDelay(5*time.Minute), retry.OnRetry(func(n uint, err error) { - zap.L().Error("Retrying Near data source start", zap.Uint("retry", n), zap.Error(err)) + zap.L().Error("retrying near data source start", zap.Uint("retry", n), zap.Error(err)) }), ) if err != nil { @@ -86,14 +86,14 @@ func (s *dataSource) startPolling(ctx context.Context, tasksChan chan<- *engine. // initialize initializes the dataSource. func (s *dataSource) initialize(ctx context.Context) (err error) { - zap.L().Debug("Initializing Near data source") + zap.L().Debug("initializing near data source") // Initialize near client. if s.nearClient, err = near.Dial(ctx, s.config.Endpoint.URL); err != nil { return fmt.Errorf("create near client: %w", err) } - zap.L().Debug("Successfully initialized Near data source") + zap.L().Debug("successfully initialized near data source") return nil } @@ -101,7 +101,7 @@ func (s *dataSource) initialize(ctx context.Context) (err error) { // initializeBlockHeights initializes block heights. func (s *dataSource) initializeBlockHeights() { if s.option.BlockStart != nil && s.option.BlockStart.Uint64() > s.state.BlockHeight { - zap.L().Debug("Updating initial block height", + zap.L().Debug("updating initial block height", zap.Uint64("oldHeight", s.state.BlockHeight), zap.Uint64("newHeight", s.option.BlockStart.Uint64())) @@ -114,12 +114,12 @@ func (s *dataSource) initializeBlockHeights() { func (s *dataSource) updateBlockHeight(ctx context.Context) { remoteBlockStart, err := parameter.GetNetworkBlockStart(ctx, s.redisClient, s.config.Network.String()) if err != nil { - zap.L().Error("Failed to get network block start from cache", zap.Error(err)) + zap.L().Error("failed to get network block start from cache", zap.Error(err)) return } if remoteBlockStart > s.state.BlockHeight { - zap.L().Debug("Updating block height from remote", + zap.L().Debug("updating block height from remote", zap.Uint64("oldHeight", s.state.BlockHeight), zap.Uint64("newHeight", remoteBlockStart)) @@ -129,7 +129,7 @@ func (s *dataSource) updateBlockHeight(ctx context.Context) { func (s *dataSource) getLatestBlockHeight(ctx context.Context) (int64, error) { if s.option.BlockTarget != nil { - zap.L().Debug("Using target block height", zap.Uint64("targetHeight", s.option.BlockTarget.Uint64())) + zap.L().Debug("using target block height", zap.Uint64("targetHeight", s.option.BlockTarget.Uint64())) return int64(s.option.BlockTarget.Uint64()), nil } @@ -138,14 +138,14 @@ func (s *dataSource) getLatestBlockHeight(ctx context.Context) (int64, error) { return 0, fmt.Errorf("get latest block height: %w", err) } - zap.L().Debug("Retrieved latest block height", zap.Int64("height", blockHeightLatestRemote)) + zap.L().Debug("retrieved latest block height", zap.Int64("height", blockHeightLatestRemote)) return blockHeightLatestRemote, nil } // pollBlocks polls blocks from near network. func (s *dataSource) pollBlocks(ctx context.Context, tasksChan chan<- *engine.Tasks) error { - zap.L().Debug("Starting block polling cycle") + zap.L().Debug("starting block polling cycle") s.initializeBlockHeights() for { @@ -158,11 +158,11 @@ func (s *dataSource) pollBlocks(ctx context.Context, tasksChan chan<- *engine.Ta if s.state.BlockHeight >= uint64(blockHeightLatestRemote) { if s.option.BlockTarget != nil && s.option.BlockTarget.Uint64() <= s.state.BlockHeight { - zap.L().Debug("Reached target block height", zap.Uint64("height", s.state.BlockHeight)) + zap.L().Debug("reached target block height", zap.Uint64("height", s.state.BlockHeight)) break } - zap.L().Debug("Waiting for new blocks", + zap.L().Debug("waiting for new blocks", zap.Uint64("currentHeight", s.state.BlockHeight), zap.Int64("latestHeight", blockHeightLatestRemote)) time.Sleep(defaultBlockTime) @@ -176,7 +176,7 @@ func (s *dataSource) pollBlocks(ctx context.Context, tasksChan chan<- *engine.Ta blockHeightStart + *s.option.ConcurrentBlockRequests - 1, }) - zap.L().Debug("Pulling block range", + zap.L().Debug("pulling block range", zap.Uint64("startHeight", blockHeightStart), zap.Uint64("endHeight", blockHeightEnd)) @@ -190,14 +190,14 @@ func (s *dataSource) pollBlocks(ctx context.Context, tasksChan chan<- *engine.Ta tasksChan <- tasks s.state.BlockHeight = blockHeightEnd - zap.L().Debug("Updated block height", zap.Uint64("newHeight", blockHeightEnd)) + zap.L().Debug("updated block height", zap.Uint64("newHeight", blockHeightEnd)) } return nil } func (s *dataSource) processBlocks(ctx context.Context, blocks []*near.Block) *engine.Tasks { - zap.L().Debug("Processing blocks", zap.Int("count", len(blocks))) + zap.L().Debug("processing blocks", zap.Int("count", len(blocks))) resultPool := pool.NewWithResults[[]engine.Task](). WithContext(ctx). @@ -214,7 +214,7 @@ func (s *dataSource) processBlocks(ctx context.Context, blocks []*near.Block) *e } s.state.BlockTimestamp = uint64(time.Duration(block.Header.Timestamp).Seconds()) - zap.L().Debug("Updated block timestamp", zap.Uint64("timestamp", s.state.BlockTimestamp)) + zap.L().Debug("updated block timestamp", zap.Uint64("timestamp", s.state.BlockTimestamp)) return chunkTasks, nil }) @@ -222,7 +222,7 @@ func (s *dataSource) processBlocks(ctx context.Context, blocks []*near.Block) *e allTasks, err := resultPool.Wait() if err != nil { - zap.L().Error("Failed to process blocks", zap.Error(err)) + zap.L().Error("failed to process blocks", zap.Error(err)) return &engine.Tasks{} } @@ -230,13 +230,13 @@ func (s *dataSource) processBlocks(ctx context.Context, blocks []*near.Block) *e Tasks: lo.Flatten(allTasks), } - zap.L().Debug("Successfully processed blocks", zap.Int("tasks", len(tasks.Tasks))) + zap.L().Debug("successfully processed blocks", zap.Int("tasks", len(tasks.Tasks))) return tasks } func (s *dataSource) processChunks(ctx context.Context, block *near.Block) ([]engine.Task, error) { - zap.L().Debug("Processing chunks", zap.Int("count", len(block.Chunks))) + zap.L().Debug("processing chunks", zap.Int("count", len(block.Chunks))) resultPool := pool.NewWithResults[[]engine.Task](). WithContext(ctx). @@ -254,7 +254,7 @@ func (s *dataSource) processChunks(ctx context.Context, block *near.Block) ([]en } localTasks := make([]engine.Task, 0, len(chunk.Transactions)) - zap.L().Info("Processing transactions", zap.Int("count", len(chunk.Transactions))) + zap.L().Debug("processing transactions", zap.Int("count", len(chunk.Transactions))) transactionPool := pool.NewWithResults[*near.Transaction](). WithContext(ctx). @@ -265,7 +265,7 @@ func (s *dataSource) processChunks(ctx context.Context, block *near.Block) ([]en transaction := transaction if s.filter.ReceiverIDs != nil && !lo.Contains(s.filter.ReceiverIDs, transaction.ReceiverID) { - zap.L().Debug("Skipping transaction - receiver ID not in filter", zap.String("receiver", transaction.ReceiverID)) + zap.L().Debug("skipping transaction - receiver ID not in filter", zap.String("receiver", transaction.ReceiverID)) continue } @@ -287,7 +287,7 @@ func (s *dataSource) processChunks(ctx context.Context, block *near.Block) ([]en }) } - zap.L().Debug("Created tasks for chunk", zap.Int("tasks", len(localTasks))) + zap.L().Debug("created tasks for chunk", zap.Int("tasks", len(localTasks))) return localTasks, nil } @@ -298,7 +298,7 @@ func (s *dataSource) processChunks(ctx context.Context, block *near.Block) ([]en retry.Delay(defaultRetryDelay), retry.DelayType(retry.BackOffDelay), retry.OnRetry(func(attempt uint, err error) { - zap.L().Error("Retrying chunk processing", zap.String("hash", chunkHash.ChunkHash), zap.Uint("attempt", attempt), zap.Error(err)) + zap.L().Error("retrying chunk processing", zap.String("hash", chunkHash.ChunkHash), zap.Uint("attempt", attempt), zap.Error(err)) }), ) }) @@ -310,14 +310,14 @@ func (s *dataSource) processChunks(ctx context.Context, block *near.Block) ([]en } tasks := lo.Flatten(allTasks) - zap.L().Debug("Successfully processed chunks", zap.Int("tasks", len(tasks))) + zap.L().Debug("successfully processed chunks", zap.Int("tasks", len(tasks))) return tasks, nil } // batchPullBlocksByRange pulls blocks by range, from local state block height to remote block height. func (s *dataSource) batchPullBlocksByRange(ctx context.Context, blockHeightStart, blockHeightEnd uint64) ([]*near.Block, error) { - zap.L().Debug("Pulling blocks by range", + zap.L().Debug("pulling blocks by range", zap.Uint64("startHeight", blockHeightStart), zap.Uint64("endHeight", blockHeightEnd)) @@ -331,7 +331,7 @@ func (s *dataSource) batchPullBlocksByRange(ctx context.Context, blockHeightStar // batchPullBlocks pulls blocks by block heights. func (s *dataSource) batchPullBlocks(ctx context.Context, blockHeights []*big.Int) ([]*near.Block, error) { - zap.L().Debug("Pulling blocks", zap.Int("count", len(blockHeights))) + zap.L().Debug("pulling blocks", zap.Int("count", len(blockHeights))) resultPool := pool.NewWithResults[*near.Block](). WithContext(ctx). @@ -352,7 +352,7 @@ func (s *dataSource) batchPullBlocks(ctx context.Context, blockHeights []*big.In retry.Delay(defaultRetryDelay), retry.DelayType(retry.BackOffDelay), retry.OnRetry(func(attempt uint, err error) { - zap.L().Error("Retrying block pull", zap.Stringer("height", blockHeight), zap.Uint("attempt", attempt), zap.Error(err)) + zap.L().Error("retrying block pull", zap.Stringer("height", blockHeight), zap.Uint("attempt", attempt), zap.Error(err)) }), ) }) @@ -363,14 +363,14 @@ func (s *dataSource) batchPullBlocks(ctx context.Context, blockHeights []*big.In return nil, err } - zap.L().Debug("Successfully pulled blocks", zap.Int("count", len(blocks))) + zap.L().Debug("successfully pulled blocks", zap.Int("count", len(blocks))) return blocks, nil } // NewSource creates a new near dataSource. func NewSource(config *config.Module, sourceFilter engine.DataSourceFilter, checkpoint *engine.Checkpoint, redisClient rueidis.Client) (engine.DataSource, error) { - zap.L().Info("Creating new Near data source", + zap.L().Info("creating new near data source", zap.String("network", config.Network.String()), zap.Bool("hasCheckpoint", checkpoint != nil)) @@ -385,7 +385,7 @@ func NewSource(config *config.Module, sourceFilter engine.DataSourceFilter, chec return nil, err } - zap.L().Debug("Initialized state from checkpoint") + zap.L().Debug("initialized state from checkpoint") } instance := dataSource{ @@ -402,14 +402,14 @@ func NewSource(config *config.Module, sourceFilter engine.DataSourceFilter, chec return nil, fmt.Errorf("invalid dataSource filter type %T", sourceFilter) } - zap.L().Debug("Initialized data source filter") + zap.L().Debug("initialized data source filter") } if instance.option, err = NewOption(config.Network, config.Parameters); err != nil { return nil, fmt.Errorf("parse config: %w", err) } - zap.L().Debug("Successfully created new Near data source", + zap.L().Debug("successfully created new Near data source", zap.String("network", config.Network.String()), zap.Bool("hasFilter", sourceFilter != nil)) diff --git a/internal/engine/protocol/near/task.go b/internal/engine/protocol/near/task.go index 46d161f29..0552b9902 100644 --- a/internal/engine/protocol/near/task.go +++ b/internal/engine/protocol/near/task.go @@ -6,6 +6,7 @@ import ( "time" "github.com/rss3-network/node/internal/engine" + "github.com/rss3-network/node/internal/utils" "github.com/rss3-network/node/provider/near" activityx "github.com/rss3-network/protocol-go/schema/activity" "github.com/rss3-network/protocol-go/schema/network" @@ -94,7 +95,7 @@ func (t Task) BuildActivity(options ...activityx.Option) (*activityx.Activity, e Type: typex.Unknown, Status: true, Fee: &activityx.Fee{ - Amount: decimal.NewFromBigInt(feeAmount, 0), + Amount: decimal.NewFromBigInt(utils.GetBigInt(feeAmount), 0), Decimal: defaultFeeDecimal, }, Actions: make([]*activityx.Action, 0), diff --git a/internal/engine/worker/decentralized/contract/1inch/worker.go b/internal/engine/worker/decentralized/contract/1inch/worker.go index 1cb57925f..323491a58 100644 --- a/internal/engine/worker/decentralized/contract/1inch/worker.go +++ b/internal/engine/worker/decentralized/contract/1inch/worker.go @@ -9,6 +9,7 @@ import ( "github.com/rss3-network/node/config" "github.com/rss3-network/node/internal/engine" source "github.com/rss3-network/node/internal/engine/protocol/ethereum" + "github.com/rss3-network/node/internal/utils" "github.com/rss3-network/node/provider/ethereum" "github.com/rss3-network/node/provider/ethereum/contract" oneinch "github.com/rss3-network/node/provider/ethereum/contract/1inch" @@ -97,8 +98,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, fmt.Errorf("invalid task type: %T", task) } - zap.L().Debug("transforming 1inch task", zap.String("task_id", oneinchTask.ID())) - // Build the activity. activity, err := task.BuildActivity(activityx.WithActivityPlatform(w.Platform())) if err != nil { @@ -114,18 +113,13 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac oneinch.AddressAggregationRouterV5: err = w.handleEthereumExchangeSwapTransaction(ctx, oneinchTask, activity) default: - return nil, fmt.Errorf("unknown transaction %s", task.ID()) + return nil, nil } if err != nil { - zap.L().Warn("failed to handle ethereum log", - zap.Error(err)) - return nil, err } - zap.L().Debug("successfully transformed 1inch task") - return activity, nil } @@ -138,9 +132,6 @@ func (w *worker) handleEthereumExchangeSwapTransaction(ctx context.Context, task err error ) - zap.L().Debug("handling ethereum exchange swap transaction", - zap.String("task_id", task.ID())) - switch *task.Transaction.To { case oneinch.AddressExchange2, @@ -161,9 +152,6 @@ func (w *worker) handleEthereumExchangeSwapTransaction(ctx context.Context, task activity.Actions = append(activity.Actions, actions...) - zap.L().Debug("successfully handled exchange swap transaction", - zap.String("task_id", task.ID())) - return nil } @@ -174,9 +162,6 @@ func (w *worker) handleEthereumImplicitAggregationRouterTransaction(ctx context. err error ) - zap.L().Debug("handling implicit aggregation router transaction", - zap.String("task_id", task.ID())) - switch *task.Transaction.To { case oneinch.AddressAggregationRouterV4: sender, receipt, err = w.parseEthereumAggregationRouterV4TransactionInput(ctx, *task) @@ -199,15 +184,9 @@ func (w *worker) handleEthereumImplicitAggregationRouterTransaction(ctx context. for _, log := range task.Receipt.Logs { if len(log.Topics) == 0 { - zap.L().Debug("skipping anonymous log") - continue } - zap.L().Debug("processing 1inch log", - zap.String("address", log.Address.String()), - zap.String("topic", log.Topics[0].String())) - switch log.Topics[0] { case erc20.EventHashTransfer: // Filter ERC-721 transfer event @@ -259,9 +238,6 @@ func (w *worker) handleEthereumImplicitAggregationRouterTransaction(ctx context. return nil, fmt.Errorf("build action: %w", err) } - zap.L().Debug("successfully handled implicit aggregation router transaction", - zap.String("task_id", task.ID())) - return []*activityx.Action{ action, }, nil @@ -805,15 +781,10 @@ func (w *worker) parseEthereumAggregationRouterV4TransactionClipperSwapToInput(_ // handleEthereumExplicitAggregationRouterTransaction handles the explicit aggregation router transaction. func (w *worker) handleEthereumExplicitAggregationRouterTransaction(ctx context.Context, task *source.Task) []*activityx.Action { - zap.L().Debug("handling ethereum explicit aggregation router transaction", - zap.String("task_id", task.ID())) - actions := make([]*activityx.Action, 0) for _, log := range task.Receipt.Logs { if len(log.Topics) == 0 { - zap.L().Debug("skipping anonymous log") - continue } @@ -822,26 +793,14 @@ func (w *worker) handleEthereumExplicitAggregationRouterTransaction(ctx context. err error ) - zap.L().Debug("processing 1inch log", - zap.String("address", log.Address.String()), - zap.String("topic", log.Topics[0].String())) - switch log.Topics[0] { case oneinch.EventHashExchangeSwapped: - zap.L().Debug("processing exchange swapped event") - action, err = w.handleEthereumExchangeSwappedLog(ctx, task, log) case oneinch.EventHashAggregationRouterV2Swapped: - zap.L().Debug("processing aggregation router v2 swapped event") - action, err = w.handleEthereumAggregationRouterV2SwappedLog(ctx, task, log) case oneinch.EventHashAggregationRouterV3Swapped: - zap.L().Debug("processing aggregation router v3 swapped event") - action, err = w.handleEthereumAggregationRouterV3SwappedLog(ctx, task, log) default: - zap.L().Debug("unsupported log") - continue } @@ -855,8 +814,6 @@ func (w *worker) handleEthereumExplicitAggregationRouterTransaction(ctx context. actions = append(actions, action) } - zap.L().Debug("successfully processed ethereum explicit aggregation router transaction") - return actions } @@ -904,14 +861,6 @@ func (w *worker) handleEthereumExchangeSwappedLog(ctx context.Context, task *sou // buildEthereumExchangeSwapAction builds the exchange swap action. func (w *worker) buildEthereumExchangeSwapAction(ctx context.Context, blockNumber *big.Int, chain uint64, from, to, tokenIn, tokenOut common.Address, amountIn, amountOut *big.Int) (*activityx.Action, error) { - zap.L().Debug("building ethereum exchange swap action", - zap.String("from", from.String()), - zap.String("to", to.String()), - zap.String("token_in", tokenIn.String()), - zap.String("token_out", tokenOut.String()), - zap.Any("amount_in", amountIn), - zap.Any("amount_out", amountOut)) - var ( tokenInAddress = lo.Ternary(tokenIn != oneinch.AddressEther, lo.ToPtr(tokenIn), nil) tokenOutAddress = lo.Ternary(tokenOut != oneinch.AddressEther, lo.ToPtr(tokenOut), nil) @@ -922,14 +871,14 @@ func (w *worker) buildEthereumExchangeSwapAction(ctx context.Context, blockNumbe return nil, fmt.Errorf("lookup token metadata %s: %w", tokenIn, err) } - tokenInMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(amountIn, 0).Abs()) + tokenInMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(amountIn), 0).Abs()) tokenOutMetadata, err := w.tokenClient.Lookup(ctx, chain, tokenOutAddress, nil, blockNumber) if err != nil { return nil, fmt.Errorf("lookup token metadata %s: %w", tokenOut, err) } - tokenOutMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(amountOut, 0).Abs()) + tokenOutMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(amountOut), 0).Abs()) action := activityx.Action{ Type: typex.ExchangeSwap, @@ -942,8 +891,6 @@ func (w *worker) buildEthereumExchangeSwapAction(ctx context.Context, blockNumbe }, } - zap.L().Debug("ethereum exchange swap action built successfully") - return &action, nil } diff --git a/internal/engine/worker/decentralized/contract/aave/worker.go b/internal/engine/worker/decentralized/contract/aave/worker.go index 11cfc91c4..5040ac505 100644 --- a/internal/engine/worker/decentralized/contract/aave/worker.go +++ b/internal/engine/worker/decentralized/contract/aave/worker.go @@ -9,6 +9,7 @@ import ( "github.com/rss3-network/node/config" "github.com/rss3-network/node/internal/engine" source "github.com/rss3-network/node/internal/engine/protocol/ethereum" + "github.com/rss3-network/node/internal/utils" "github.com/rss3-network/node/provider/ethereum" "github.com/rss3-network/node/provider/ethereum/contract" "github.com/rss3-network/node/provider/ethereum/contract/aave" @@ -25,7 +26,6 @@ import ( "github.com/rss3-network/protocol-go/schema/typex" "github.com/samber/lo" "github.com/shopspring/decimal" - "go.uber.org/zap" ) var _ engine.Worker = (*worker)(nil) @@ -128,8 +128,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, fmt.Errorf("invalid task type: %T", task) } - zap.L().Debug("transforming activity from task", zap.String("task_id", ethereumTask.ID())) - if ethereumTask.Transaction.To == nil { return nil, fmt.Errorf("invalid transaction to: %s", ethereumTask.Transaction.Hash) } @@ -143,8 +141,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac for _, log := range ethereumTask.Receipt.Logs { // Ignore anonymous logs. if len(log.Topics) == 0 { - zap.L().Debug("skipping anonymous log") - continue } @@ -153,31 +149,19 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac err error ) - zap.L().Debug("processing aave log", - zap.String("address", log.Address.String()), - zap.String("topic", log.Topics[0].String())) - switch { case w.matchLiquidityV1Pool(ethereumTask, log): - zap.L().Debug("handling v1 lending pool log") - actions, err = w.handleV1LendingPool(ctx, ethereumTask, log) case w.matchLiquidityV2LendingPool(ethereumTask, log): - zap.L().Debug("handling v2 lending pool log") - actions, err = w.handleV2LendingPool(ctx, ethereumTask, log) case w.matchLiquidityV3Pool(ethereumTask, log): - zap.L().Debug("handling v3 pool log") - actions, err = w.handleV3Pool(ctx, ethereumTask, log) default: - zap.L().Warn("unsupported log") - continue } if err != nil { - return nil, err + return nil, fmt.Errorf("handle pool log: %w", err) } activity.Type = typex.ExchangeLiquidity @@ -187,8 +171,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac } } - zap.L().Debug("successfully transformed aave task") - return activity, nil } @@ -260,10 +242,6 @@ func (w *worker) matchLiquidityV3Pool(task *source.Task, log *ethereum.Log) bool } func (w *worker) handleV1LendingPool(ctx context.Context, task *source.Task, log *ethereum.Log) ([]*activityx.Action, error) { - zap.L().Debug("handling aave v1 lending pool event", - zap.String("task_id", task.ID()), - zap.String("log_address", log.Address.String())) - var ( action *activityx.Action err error @@ -284,17 +262,10 @@ func (w *worker) handleV1LendingPool(ctx context.Context, task *source.Task, log return nil, fmt.Errorf("handle v1 pool: %w", err) } - zap.L().Debug("successfully handled aave v1 lending pool event", - zap.String("task_id", task.ID())) - return []*activityx.Action{action}, nil } func (w *worker) handleV2LendingPool(ctx context.Context, task *source.Task, log *ethereum.Log) ([]*activityx.Action, error) { - zap.L().Debug("handling aave v2 lending pool event", - zap.String("task_id", task.ID()), - zap.String("log_address", log.Address.String())) - var ( action *activityx.Action err error @@ -317,17 +288,10 @@ func (w *worker) handleV2LendingPool(ctx context.Context, task *source.Task, log return nil, fmt.Errorf("handle v2 pool: %w", err) } - zap.L().Debug("successfully handled aave v2 lending pool event", - zap.String("task_id", task.ID())) - return []*activityx.Action{action}, nil } func (w *worker) handleV3Pool(ctx context.Context, task *source.Task, log *ethereum.Log) ([]*activityx.Action, error) { - zap.L().Debug("handling aave v3 pool event", - zap.String("task_id", task.ID()), - zap.String("log_address", log.Address.String())) - var ( action *activityx.Action err error @@ -350,9 +314,6 @@ func (w *worker) handleV3Pool(ctx context.Context, task *source.Task, log *ether return nil, fmt.Errorf("handle v3 pool: %w", err) } - zap.L().Debug("successfully handled aave v3 pool event", - zap.String("task_id", task.ID())) - return []*activityx.Action{action}, nil } @@ -522,20 +483,12 @@ func (w *worker) transformV3PoolRepayLog(ctx context.Context, task *source.Task, } func (w *worker) buildEthereumExchangeLiquidityAction(ctx context.Context, task *source.Task, from, to common.Address, exchangeLiquidityAction metadata.ExchangeLiquidityAction, tokenAddress common.Address, tokenValue *big.Int) (*activityx.Action, error) { - zap.L().Debug("building ethereum exchange liquidity action", - zap.String("task_id", task.ID()), - zap.String("from", from.String()), - zap.String("to", to.String()), - zap.String("action", exchangeLiquidityAction.String()), - zap.Any("token", tokenAddress), - zap.Any("value", tokenValue)) - targetToken, err := w.tokenClient.Lookup(ctx, task.ChainID, &tokenAddress, nil, task.Header.Number) if err != nil { return nil, fmt.Errorf("lookup token metadata %s: %w", tokenAddress, err) } - targetToken.Value = lo.ToPtr(decimal.NewFromBigInt(tokenValue, 0)) + targetToken.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(tokenValue), 0)) action := activityx.Action{ Type: typex.ExchangeLiquidity, diff --git a/internal/engine/worker/decentralized/contract/aavegotchi/worker.go b/internal/engine/worker/decentralized/contract/aavegotchi/worker.go index d0611ebb7..de9322098 100644 --- a/internal/engine/worker/decentralized/contract/aavegotchi/worker.go +++ b/internal/engine/worker/decentralized/contract/aavegotchi/worker.go @@ -9,6 +9,7 @@ import ( "github.com/rss3-network/node/config" "github.com/rss3-network/node/internal/engine" source "github.com/rss3-network/node/internal/engine/protocol/ethereum" + "github.com/rss3-network/node/internal/utils" "github.com/rss3-network/node/provider/ethereum" "github.com/rss3-network/node/provider/ethereum/contract/aavegotchi" "github.com/rss3-network/node/provider/ethereum/contract/erc20" @@ -22,7 +23,6 @@ import ( "github.com/rss3-network/protocol-go/schema/typex" "github.com/samber/lo" "github.com/shopspring/decimal" - "go.uber.org/zap" ) var _ engine.Worker = (*worker)(nil) @@ -84,8 +84,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, fmt.Errorf("invalid task type: %T", task) } - zap.L().Debug("transforming aavegotchi task", zap.String("task_id", ethereumTask.ID())) - // Build the activity. activity, err := task.BuildActivity(activityx.WithActivityPlatform(w.Platform())) if err != nil { @@ -99,39 +97,21 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac ) if len(log.Topics) == 0 { - zap.L().Debug("skipping anonymous log") - continue } - zap.L().Debug("processing aavegotchi log", - zap.String("address", log.Address.String()), - zap.String("topic", log.Topics[0].String())) - switch { case w.matchERC721ListingAdd(ctx, *log): - zap.L().Debug("handling ERC721 listing add") - action, err = w.handleERC721ListingAdd(ctx, ethereumTask, *log, activity) case w.matchERC721ExecutedListing(ctx, *log): - zap.L().Debug("handling ERC721 executed listing") - action, err = w.handleERC721ExecutedListing(ctx, ethereumTask, *log, activity) case w.matchERC1155ListingAdd(ctx, *log): - zap.L().Debug("handling ERC1155 listing add") - action, err = w.handleERC1155ListingAdd(ctx, ethereumTask, *log, activity) case w.matchERC1155ExecutedListing(ctx, *log): - zap.L().Debug("handling ERC1155 executed listing") - action, err = w.handleERC1155ExecutedListing(ctx, ethereumTask, *log, activity) case w.matchERC20TransferLog(ctx, *log): - zap.L().Debug("handling ERC20 transfer") - action, err = w.handleERC20TransferLog(ctx, ethereumTask, *log, activity) default: - zap.L().Warn("unsupported log") - continue } @@ -146,8 +126,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return w.handleMetaverseTradeCost(ctx, activity) } - zap.L().Debug("successfully transformed aavegotchi task") - return activity, nil } @@ -266,7 +244,7 @@ func (w *worker) handleMetaverseTradeCost(_ context.Context, activity *activityx if cost.Value.IsZero() { cost = metadata.Token(action.Metadata.(metadata.MetaverseTransfer)) } else { - cost.Value = lo.ToPtr(cost.Value.Add(decimal.NewFromBigInt(action.Metadata.(metadata.MetaverseTransfer).Value.BigInt(), 0))) + cost.Value = lo.ToPtr(cost.Value.Add(decimal.NewFromBigInt(utils.GetBigInt(action.Metadata.(metadata.MetaverseTransfer).Value.BigInt()), 0))) } } } @@ -297,13 +275,6 @@ func (w *worker) buildTradeAction( from, to, tokenAddress common.Address, tokenID, value *big.Int, ) (*activityx.Action, error) { - zap.L().Debug("building metaverse trade action", - zap.String("from", from.String()), - zap.String("to", to.String()), - zap.String("token_address", tokenAddress.String()), - zap.Any("value", value), - zap.Any("action", metadataAction)) - tokenMetadata, err := w.tokenClient.Lookup(ctx, chainID, lo.ToPtr(tokenAddress), tokenID, blockNumber) if err != nil { return nil, fmt.Errorf("lookup token: %w", err) @@ -313,8 +284,6 @@ func (w *worker) buildTradeAction( return lo.ToPtr(decimal.NewFromBigInt(value, 0)) }) - zap.L().Debug("successfully built metaverse trade action") - return &activityx.Action{ Type: typex.MetaverseTrade, Platform: w.Platform(), @@ -336,14 +305,6 @@ func (w *worker) buildTransferAction( from, to, tokenAddress common.Address, tokenID, value *big.Int, ) (*activityx.Action, error) { - zap.L().Debug("building metaverse transfer action", - zap.String("from", from.String()), - zap.String("to", to.String()), - zap.String("token_address", tokenAddress.String()), - zap.Any("token_id", tokenID), - zap.Any("value", value), - zap.String("action_type", actionType.String())) - tokenMetadata, err := w.tokenClient.Lookup(ctx, chainID, lo.ToPtr(tokenAddress), tokenID, blockNumber) if err != nil { return nil, fmt.Errorf("lookup token: %w", err) @@ -353,8 +314,6 @@ func (w *worker) buildTransferAction( return lo.ToPtr(decimal.NewFromBigInt(value, 0)) }) - zap.L().Debug("successfully built metaverse transfer action") - return &activityx.Action{ Type: actionType, Platform: w.Platform(), diff --git a/internal/engine/worker/decentralized/contract/arbitrum/worker.go b/internal/engine/worker/decentralized/contract/arbitrum/worker.go index 7882e4716..f2d38b04e 100644 --- a/internal/engine/worker/decentralized/contract/arbitrum/worker.go +++ b/internal/engine/worker/decentralized/contract/arbitrum/worker.go @@ -9,6 +9,7 @@ import ( "github.com/rss3-network/node/config" "github.com/rss3-network/node/internal/engine" source "github.com/rss3-network/node/internal/engine/protocol/ethereum" + "github.com/rss3-network/node/internal/utils" "github.com/rss3-network/node/provider/ethereum" "github.com/rss3-network/node/provider/ethereum/contract" "github.com/rss3-network/node/provider/ethereum/contract/arbitrum" @@ -91,8 +92,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, fmt.Errorf("invalid task type: %T", task) } - zap.L().Debug("transforming arbitrum task", zap.String("task_id", ethereumTask.ID())) - activity, err := ethereumTask.BuildActivity(activityx.WithActivityPlatform(w.Platform())) if err != nil { return nil, fmt.Errorf("build activity: %w", err) @@ -106,43 +105,23 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac // Ignore anonymous logs. if len(log.Topics) == 0 { - zap.L().Debug("skipping anonymous log") - continue } - zap.L().Debug("processing arbitrum log", - zap.String("address", log.Address.String()), - zap.String("topic", log.Topics[0].String())) - switch { case w.matchBridgeMessageDeliveredLog(ethereumTask, log): - zap.L().Debug("handling bridge message delivered log") - actions, err = w.transformBridgeMessageDeliveredLog(ctx, ethereumTask, log) case w.matchL1CustomGatewayDepositInitiatedLog(ethereumTask, log): - zap.L().Debug("handling L1 custom gateway deposit initiated log") - actions, err = w.transformL1CustomGatewayDepositInitiatedLog(ctx, ethereumTask, log) case w.matchL2ReverseCustomGatewayWithdrawalInitiatedLog(ethereumTask, log): - zap.L().Debug("handling L2 reverse custom gateway withdrawal initiated log") - actions, err = w.transformL2ReverseCustomGatewayWithdrawalInitiatedLog(ctx, ethereumTask, log) case w.matchArbSysL2ToL1TxLog(ethereumTask, log): - zap.L().Debug("handling ArbSys L2 to L1 tx log") - actions, err = w.transformArbSysL2ToL1TxLog(ctx, ethereumTask, log) case w.matchL1CustomGatewayWithdrawalFinalizedLog(ethereumTask, log): - zap.L().Debug("handling L1 custom gateway withdrawal finalized log") - actions, err = w.transformL1CustomGatewayWithdrawalFinalizedLog(ctx, ethereumTask, log) case w.matchL2ReverseCustomGatewayDepositFinalizedLog(ethereumTask, log): - zap.L().Debug("handling L2 reverse custom gateway deposit finalized log") - actions, err = w.transformL2ReverseCustomGatewayDepositFinalizedLog(ctx, ethereumTask, log) default: - zap.L().Warn("unsupported log") - continue } @@ -158,8 +137,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac activity.Type = typex.TransactionBridge - zap.L().Debug("successfully transformed arbitrum task") - return activity, nil } @@ -304,15 +281,6 @@ func (w *worker) transformArbSysL2ToL1TxLog(ctx context.Context, task *source.Ta func (w *worker) buildTransactionBridgeAction(ctx context.Context, chainID uint64, sender, receiver common.Address, source, target network.Network, bridgeAction metadata.TransactionBridgeAction, tokenAddress *common.Address, tokenValue *big.Int, blockNumber *big.Int) (*activityx.Action, error) { - zap.L().Debug("building transaction bridge action", - zap.String("sender", sender.String()), - zap.String("receiver", receiver.String()), - zap.String("source_network", source.String()), - zap.String("target_network", target.String()), - zap.String("action", bridgeAction.String()), - zap.Any("token_address", tokenAddress), - zap.Any("token_value", tokenValue)) - // If the chain is 'Arbitrum', then set blockNumber to be nil by default to use Lookup() if source == network.Arbitrum { blockNumber = nil @@ -323,7 +291,7 @@ func (w *worker) buildTransactionBridgeAction(ctx context.Context, chainID uint6 return nil, fmt.Errorf("lookup token %s: %w", tokenAddress, err) } - tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(tokenValue, 0)) + tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(tokenValue), 0)) action := &activityx.Action{ Type: typex.TransactionBridge, @@ -338,8 +306,6 @@ func (w *worker) buildTransactionBridgeAction(ctx context.Context, chainID uint6 }, } - zap.L().Debug("successfully built transaction bridge action") - return action, nil } diff --git a/internal/engine/worker/decentralized/contract/base/worker.go b/internal/engine/worker/decentralized/contract/base/worker.go index 62b0415b6..21b29a057 100644 --- a/internal/engine/worker/decentralized/contract/base/worker.go +++ b/internal/engine/worker/decentralized/contract/base/worker.go @@ -9,6 +9,7 @@ import ( "github.com/rss3-network/node/config" "github.com/rss3-network/node/internal/engine" source "github.com/rss3-network/node/internal/engine/protocol/ethereum" + "github.com/rss3-network/node/internal/utils" "github.com/rss3-network/node/provider/ethereum" "github.com/rss3-network/node/provider/ethereum/contract" "github.com/rss3-network/node/provider/ethereum/contract/base" @@ -89,8 +90,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, fmt.Errorf("invalid task type: %T", task) } - zap.L().Debug("transforming base task", zap.String("task_id", ethereumTask.ID())) - // Build the activity. activity, err := task.BuildActivity(activityx.WithActivityPlatform(w.Platform())) if err != nil { @@ -100,8 +99,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac for _, log := range ethereumTask.Receipt.Logs { // Ignore anonymous logs. if len(log.Topics) == 0 { - zap.L().Debug("skipping anonymous log") - continue } @@ -110,34 +107,18 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac err error ) - zap.L().Debug("processing base log", - zap.String("address", log.Address.String()), - zap.String("topic", log.Topics[0].String())) - switch { case w.matchEthereumOptimismPortalTransactionDepositedLog(log): - zap.L().Debug("handling optimism portal transaction deposited log") - action, err = w.handleEthereumOptimismPortalTransactionDepositedLog(ctx, *ethereumTask, activity, log) case w.matchEthereumL1StandardBridgeETHDepositInitiatedLog(log): - zap.L().Debug("handling L1 standard bridge ETH deposit initiated log") - action, err = w.handleEthereumL1StandardBridgeETHDepositInitiatedLog(ctx, *ethereumTask, activity, log) case w.matchEthereumL1StandardBridgeERC20DepositInitiatedLog(log): - zap.L().Debug("handling L1 standard bridge ERC20 deposit initiated log") - action, err = w.handleEthereumL1StandardBridgeERC20DepositInitiatedLog(ctx, *ethereumTask, activity, log) case w.matchEthereumL1StandardBridgeETHWithdrawalFinalizedLog(log): - zap.L().Debug("handling L1 standard bridge ETH withdrawal finalized log") - action, err = w.handleEthereumL1StandardBridgeETHWithdrawalFinalizedLog(ctx, *ethereumTask, activity, log) case w.matchEthereumL1StandardBridgeERC20WithdrawalFinalizedLog(log): - zap.L().Debug("handling L1 standard bridge ERC20 withdrawal finalized log") - action, err = w.handleEthereumL1StandardBridgeERC20WithdrawalFinalizedLog(ctx, *ethereumTask, activity, log) default: - zap.L().Debug("skipping unsupported log") - continue } @@ -160,8 +141,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, nil } - zap.L().Debug("successfully transformed base task") - return activity, nil } @@ -264,21 +243,12 @@ func (w *worker) handleEthereumL1StandardBridgeERC20WithdrawalFinalizedLog(ctx c } func (w *worker) buildEthereumTransactionBridgeAction(ctx context.Context, blockNumber *big.Int, chainID uint64, sender, receiver common.Address, source, target network.Network, bridgeAction metadata.TransactionBridgeAction, tokenAddress *common.Address, tokenValue *big.Int) (*activityx.Action, error) { - zap.L().Debug("building ethereum transaction bridge action", - zap.String("sender", sender.String()), - zap.String("receiver", receiver.String()), - zap.String("source_network", source.String()), - zap.String("target_network", target.String()), - zap.String("action", bridgeAction.String()), - zap.Any("token_address", tokenAddress), - zap.Any("token_value", tokenValue)) - tokenMetadata, err := w.tokenClient.Lookup(ctx, chainID, tokenAddress, nil, blockNumber) if err != nil { return nil, fmt.Errorf("lookup token metadata: %w", err) } - tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(tokenValue, 0)) + tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(tokenValue), 0)) action := activityx.Action{ Type: typex.TransactionBridge, @@ -294,8 +264,6 @@ func (w *worker) buildEthereumTransactionBridgeAction(ctx context.Context, block }, } - zap.L().Debug("successfully built ethereum transaction bridge action") - return &action, nil } diff --git a/internal/engine/worker/decentralized/contract/benddao/worker.go b/internal/engine/worker/decentralized/contract/benddao/worker.go index 048438a0a..dd1a670f3 100644 --- a/internal/engine/worker/decentralized/contract/benddao/worker.go +++ b/internal/engine/worker/decentralized/contract/benddao/worker.go @@ -9,6 +9,7 @@ import ( "github.com/rss3-network/node/config" "github.com/rss3-network/node/internal/engine" source "github.com/rss3-network/node/internal/engine/protocol/ethereum" + "github.com/rss3-network/node/internal/utils" "github.com/rss3-network/node/provider/ethereum" "github.com/rss3-network/node/provider/ethereum/contract" "github.com/rss3-network/node/provider/ethereum/contract/benddao" @@ -22,7 +23,6 @@ import ( "github.com/rss3-network/protocol-go/schema/typex" "github.com/samber/lo" "github.com/shopspring/decimal" - "go.uber.org/zap" ) var _ engine.Worker = (*worker)(nil) @@ -92,8 +92,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, fmt.Errorf("invalid task type: %T", task) } - zap.L().Debug("transforming benddao task", zap.String("task_id", ethereumTask.ID())) - if ethereumTask.Transaction.To == nil { return nil, fmt.Errorf("invalid transaction to: %s", ethereumTask.Transaction.Hash) } @@ -107,8 +105,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac for _, log := range ethereumTask.Receipt.Logs { // Ignore anonymous logs. if len(log.Topics) == 0 { - zap.L().Debug("skipping anonymous log") - continue } @@ -117,62 +113,38 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac err error ) - zap.L().Debug("processing benddao log", - zap.String("address", log.Address.String()), - zap.String("topic", log.Topics[0].String())) - switch { // Bend exchange case w.matchBendExchangeTakerAsk(log): - zap.L().Debug("processing bend exchange taker ask event") - actions, err = w.transformBendExchangeTakerAsk(ctx, ethereumTask, log) activity.Type = typex.CollectibleTrade case w.matchBendExchangeTakerBid(log): - zap.L().Debug("processing bend exchange taker bid event") - actions, err = w.transformBendExchangeTakerBid(ctx, ethereumTask, log) activity.Type = typex.CollectibleTrade // Lend pool case w.matchLendPoolDeposit(log): - zap.L().Debug("processing lend pool deposit event") - actions, err = w.transformLendPoolDeposit(ctx, ethereumTask, log) activity.Type = typex.ExchangeLiquidity case w.matchLendPoolWithdraw(log): - zap.L().Debug("processing lend pool withdraw event") - actions, err = w.transformLendPoolWithdraw(ctx, ethereumTask, log) activity.Type = typex.ExchangeLiquidity case w.matchLendPoolBorrow(log): - zap.L().Debug("processing lend pool borrow event") - actions, err = w.transformLendPoolBorrow(ctx, ethereumTask, log) activity.Type = typex.ExchangeLoan case w.matchLendPoolRepay(log): - zap.L().Debug("processing lend pool repay event") - actions, err = w.transformLendPoolRepay(ctx, ethereumTask, log) activity.Type = typex.ExchangeLoan case w.matchLendPoolAuction(log): - zap.L().Debug("processing lend pool auction event") - actions, err = w.transformLendPoolAuction(ctx, ethereumTask, log) activity.Type = typex.CollectibleAuction case w.matchLendPoolRedeem(log): - zap.L().Debug("processing lend pool redeem event") - actions, err = w.transformLendPoolRedeem(ctx, ethereumTask, log) activity.Type = typex.ExchangeLoan case w.matchLendPoolLiquidate(log): - zap.L().Debug("processing lend pool liquidate event") - actions, err = w.transformLendPoolLiquidate(ctx, ethereumTask, log) activity.Type = typex.ExchangeLoan default: - zap.L().Debug("skipping unsupported log") - continue } @@ -183,8 +155,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac activity.Actions = append(activity.Actions, actions...) } - zap.L().Debug("successfully transformed benddao task") - return activity, nil } @@ -261,7 +231,7 @@ func (w *worker) transformLendPoolDeposit(ctx context.Context, task *source.Task action, err := w.buildEthereumLendPoolLiquidityAction(ctx, task, event.OnBehalfOf, log.Address, metadata.ActionExchangeLiquiditySupply, []metadata.Token{ { Address: lo.ToPtr(event.Reserve.String()), - Value: lo.ToPtr(decimal.NewFromBigInt(event.Amount, 0)), + Value: lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(event.Amount), 0)), }, }) if err != nil { @@ -280,7 +250,7 @@ func (w *worker) transformLendPoolWithdraw(ctx context.Context, task *source.Tas action, err := w.buildEthereumLendPoolLiquidityAction(ctx, task, log.Address, event.To, metadata.ActionExchangeLiquidityWithdraw, []metadata.Token{ { Address: lo.ToPtr(event.Reserve.String()), - Value: lo.ToPtr(decimal.NewFromBigInt(event.Amount, 0)), + Value: lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(event.Amount), 0)), }, }) if err != nil { @@ -376,11 +346,6 @@ func (w *worker) transformLendPoolLiquidate(ctx context.Context, task *source.Ta } func (w *worker) buildEthereumLendPoolLiquidityAction(ctx context.Context, task *source.Task, sender, receipt common.Address, action metadata.ExchangeLiquidityAction, tokens []metadata.Token) (*activityx.Action, error) { - zap.L().Debug("building ethereum lend pool liquidity action", - zap.String("sender", sender.String()), - zap.String("receipt", receipt.String()), - zap.String("action", action.String())) - tokenMetadataSlice := make([]metadata.Token, 0, len(tokens)) for _, t := range tokens { @@ -399,8 +364,6 @@ func (w *worker) buildEthereumLendPoolLiquidityAction(ctx context.Context, task tokenMetadataSlice = append(tokenMetadataSlice, *tokenMetadata) } - zap.L().Debug("ethereum lend pool liquidity action built successfully") - return &activityx.Action{ Type: typex.ExchangeLiquidity, Platform: w.Platform(), @@ -414,22 +377,12 @@ func (w *worker) buildEthereumLendPoolLiquidityAction(ctx context.Context, task } func (w *worker) buildEthereumAuctionAction(ctx context.Context, task *source.Task, from, to, nft common.Address, nftID, nftValue, offerValue *big.Int, offerToken *common.Address, action metadata.CollectibleAuctionAction) (*activityx.Action, error) { - zap.L().Debug("building ethereum auction action", - zap.String("from", from.String()), - zap.String("to", to.String()), - zap.String("nft", nft.String()), - zap.Any("nft_id", nftID), - zap.Any("nft_value", nftValue), - zap.Any("offer_token", offerToken), - zap.Any("offer_value", offerValue), - zap.String("action", action.String())) - tokenMetadata, err := w.tokenClient.Lookup(ctx, task.ChainID, &nft, nftID, task.Header.Number) if err != nil { return nil, fmt.Errorf("lookup token metadata %s %s: %w", nft, nftID, err) } - tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(nftValue, 0)) + tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(nftValue), 0)) var ( offerTokenMetadata *metadata.Token @@ -441,11 +394,9 @@ func (w *worker) buildEthereumAuctionAction(ctx context.Context, task *source.Ta return nil, fmt.Errorf("lookup token metadata %s: %w", offerToken, err) } - offerTokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(offerValue, 0)) + offerTokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(offerValue), 0)) } - zap.L().Debug("ethereum auction action built successfully") - return &activityx.Action{ Type: typex.CollectibleAuction, Platform: w.Platform(), @@ -460,29 +411,19 @@ func (w *worker) buildEthereumAuctionAction(ctx context.Context, task *source.Ta } func (w *worker) buildEthereumCollectibleTradeAction(ctx context.Context, task *source.Task, seller, buyer, nft common.Address, nftID, nftValue *big.Int, offerToken *common.Address, offerValue *big.Int) (*activityx.Action, error) { - zap.L().Debug("building ethereum collectible trade action", - zap.String("seller", seller.String()), - zap.String("buyer", buyer.String()), - zap.String("nft", nft.String()), - zap.Any("nft_id", nftID), - zap.Any("offer_token", offerToken), - zap.Any("offer_value", offerValue)) - offerTokenMetadata, err := w.tokenClient.Lookup(ctx, task.ChainID, offerToken, nil, task.Header.Number) if err != nil { return nil, fmt.Errorf("lookup token metadata %s: %w", offerToken, err) } - offerTokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(offerValue, 0)) + offerTokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(offerValue), 0)) tokenMetadata, err := w.tokenClient.Lookup(ctx, task.ChainID, &nft, nftID, task.Header.Number) if err != nil { return nil, fmt.Errorf("lookup token metadata %s %s: %w", nft, nftID, err) } - tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(nftValue, 0)) - - zap.L().Debug("ethereum collectible trade action built successfully") + tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(nftValue), 0)) return &activityx.Action{ Type: typex.CollectibleTrade, @@ -498,20 +439,12 @@ func (w *worker) buildEthereumCollectibleTradeAction(ctx context.Context, task * } func (w *worker) buildEthereumTransactionTransferAction(ctx context.Context, task *source.Task, from, to common.Address, token *common.Address, value *big.Int) (*activityx.Action, error) { - zap.L().Debug("building ethereum transaction transfer action", - zap.String("from", from.String()), - zap.String("to", to.String()), - zap.Any("token", token), - zap.Any("value", value)) - tokenMetadata, err := w.tokenClient.Lookup(ctx, task.ChainID, token, nil, task.Header.Number) if err != nil { return nil, fmt.Errorf("lookup token metadata %s: %w", token, err) } - tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(value, 0)) - - zap.L().Debug("ethereum transaction transfer action built successfully") + tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(value), 0)) return &activityx.Action{ Type: typex.TransactionTransfer, @@ -523,22 +456,12 @@ func (w *worker) buildEthereumTransactionTransferAction(ctx context.Context, tas } func (w *worker) buildEthereumExchangeLoanAction(ctx context.Context, task *source.Task, lender, borrower, nft common.Address, offerToken *common.Address, nftID, nftValue, offerValue *big.Int, action metadata.ExchangeLoanAction) (*activityx.Action, error) { - zap.L().Debug("building ethereum exchange loan action", - zap.String("lender", lender.String()), - zap.String("borrower", borrower.String()), - zap.String("nft", nft.String()), - zap.Any("offer_token", offerToken), - zap.Any("nft_id", nftID), - zap.Any("nft_value", nftValue), - zap.Any("offer_value", offerValue), - zap.String("action", action.String())) - tokenMetadata, err := w.tokenClient.Lookup(ctx, task.ChainID, &nft, nftID, task.Header.Number) if err != nil { return nil, fmt.Errorf("lookup token metadata %s %s: %w", nft, nftID, err) } - tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(nftValue, 0)) + tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(nftValue), 0)) var ( offerTokenMetadata *metadata.Token @@ -550,11 +473,9 @@ func (w *worker) buildEthereumExchangeLoanAction(ctx context.Context, task *sour return nil, fmt.Errorf("lookup token metadata %s: %w", "", err) } - offerTokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(offerValue, 0)) + offerTokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(offerValue), 0)) } - zap.L().Debug("ethereum exchange loan action built successfully") - return &activityx.Action{ Type: typex.ExchangeLoan, Platform: w.Platform(), @@ -569,21 +490,12 @@ func (w *worker) buildEthereumExchangeLoanAction(ctx context.Context, task *sour } func (w *worker) buildEthereumCollectibleTransferAction(ctx context.Context, task *source.Task, seller, buyer, nft common.Address, nftID, value *big.Int) (*activityx.Action, error) { - zap.L().Debug("building ethereum collectible transfer action", - zap.String("seller", seller.String()), - zap.String("buyer", buyer.String()), - zap.String("nft", nft.String()), - zap.Any("nft_id", nftID), - zap.Any("value", value)) - tokenMetadata, err := w.tokenClient.Lookup(ctx, task.ChainID, &nft, nftID, task.Header.Number) if err != nil { return nil, fmt.Errorf("lookup token metadata %s %s: %w", nft, nftID, err) } - tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(value, 0)) - - zap.L().Debug("ethereum collectible transfer action built successfully") + tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(value), 0)) return &activityx.Action{ Type: typex.CollectibleTransfer, diff --git a/internal/engine/worker/decentralized/contract/cow/worker.go b/internal/engine/worker/decentralized/contract/cow/worker.go index 07e41caa5..dae3e1a95 100644 --- a/internal/engine/worker/decentralized/contract/cow/worker.go +++ b/internal/engine/worker/decentralized/contract/cow/worker.go @@ -9,6 +9,7 @@ import ( "github.com/rss3-network/node/config" "github.com/rss3-network/node/internal/engine" source "github.com/rss3-network/node/internal/engine/protocol/ethereum" + "github.com/rss3-network/node/internal/utils" "github.com/rss3-network/node/provider/ethereum" "github.com/rss3-network/node/provider/ethereum/contract" "github.com/rss3-network/node/provider/ethereum/contract/cow" @@ -77,8 +78,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, fmt.Errorf("invalid task type %T", task) } - zap.L().Debug("transforming cow task", zap.String("task_id", ethereumTask.ID())) - activity, err := ethereumTask.BuildActivity(activityx.WithActivityPlatform(w.Platform())) if err != nil { return nil, fmt.Errorf("build activity: %w", err) @@ -86,26 +85,21 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac for _, log := range ethereumTask.Receipt.Logs { if len(log.Topics) == 0 { - zap.L().Debug("skipping anonymous log") - continue } switch { case w.matchSettlementTradeLog(ethereumTask, log): - zap.L().Debug("processing settlement trade log") - actions, err := w.transformSettlementTradeLog(ctx, ethereumTask, log) if err != nil { - zap.L().Warn("failed to handle settlement trade log", zap.Error(err)) + zap.L().Error("failed to handle settlement trade log", zap.Error(err)) continue } activity.Actions = append(activity.Actions, actions...) - default: - zap.L().Debug("skipping unsupported log") + continue } } @@ -115,13 +109,10 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac activity.Type = typex.ExchangeSwap - zap.L().Debug("successfully transformed cow task") - return activity, nil } func (w *worker) matchSettlementTradeLog(_ *source.Task, log *ethereum.Log) bool { - // zap.L().Info("cow.EventHashSettlementTrade is: ", zap.Any("trade", cow.EventHashSettlementTrade)) return contract.MatchEventHashes(log.Topics[0], cow.EventHashSettlementTrade) && contract.MatchAddresses(log.Address, cow.AddressSettlement) } @@ -145,14 +136,6 @@ func (w *worker) transformSettlementTradeLog(ctx context.Context, task *source.T } func (w *worker) buildExchangeSwapAction(ctx context.Context, task *source.Task, from, to, tokenIn, tokenOut common.Address, amountIn, amountOut *big.Int) (*activityx.Action, error) { - zap.L().Debug("building exchange swap action", - zap.String("from", from.String()), - zap.String("to", to.String()), - zap.String("token_in", tokenIn.String()), - zap.String("token_out", tokenOut.String()), - zap.Any("amount_in", amountIn), - zap.Any("amount_out", amountOut)) - tokenInAddress := lo.Ternary(tokenIn != cow.AddressETH, &tokenIn, nil) tokenOutAddress := lo.Ternary(tokenOut != cow.AddressETH, &tokenOut, nil) @@ -161,16 +144,14 @@ func (w *worker) buildExchangeSwapAction(ctx context.Context, task *source.Task, return nil, fmt.Errorf("lookup token in metadata: %w", err) } - tokenInMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(amountIn, 0)) + tokenInMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(amountIn), 0)) tokenOutMetadata, err := w.tokenClient.Lookup(ctx, task.ChainID, tokenOutAddress, nil, task.Header.Number) if err != nil { return nil, fmt.Errorf("lookup token out metadata: %w", err) } - tokenOutMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(amountOut, 0)) - - zap.L().Debug("exchange swap action built successfully") + tokenOutMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(amountOut), 0)) return &activityx.Action{ Type: typex.ExchangeSwap, diff --git a/internal/engine/worker/decentralized/contract/crossbell/worker.go b/internal/engine/worker/decentralized/contract/crossbell/worker.go index b1c189678..1536436f1 100644 --- a/internal/engine/worker/decentralized/contract/crossbell/worker.go +++ b/internal/engine/worker/decentralized/contract/crossbell/worker.go @@ -15,6 +15,7 @@ import ( "github.com/rss3-network/node/config" "github.com/rss3-network/node/internal/engine" source "github.com/rss3-network/node/internal/engine/protocol/ethereum" + "github.com/rss3-network/node/internal/utils" "github.com/rss3-network/node/provider/ethereum" "github.com/rss3-network/node/provider/ethereum/contract" "github.com/rss3-network/node/provider/ethereum/contract/crossbell" @@ -36,7 +37,6 @@ import ( "github.com/rss3-network/protocol-go/schema/typex" "github.com/samber/lo" "github.com/shopspring/decimal" - "go.uber.org/zap" ) // Worker is the worker for Crossbell. @@ -124,8 +124,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, fmt.Errorf("invalid task type: %T", task) } - zap.L().Debug("transforming crossbell task", zap.String("task_id", ethereumTask.ID())) - // Build default crossbell activity from task. activity, err := ethereumTask.BuildActivity(activityx.WithActivityPlatform(w.Platform())) if err != nil { @@ -136,8 +134,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac for _, log := range ethereumTask.Receipt.Logs { // Ignore anonymous logs. if len(log.Topics) == 0 { - zap.L().Debug("skipping anonymous log") - continue } @@ -146,71 +142,37 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac err error ) - zap.L().Debug("processing log", - zap.String("address", log.Address.String()), - zap.String("topic", log.Topics[0].String())) - // Match crossbell core contract events switch { case w.matchProfileCreated(ethereumTask, log): - zap.L().Debug("processing profile created event") - actions, err = w.transformProfileCreated(ctx, ethereumTask, log) case w.matchSetProfileURI(ethereumTask, log): - zap.L().Debug("processing set profile URI event") - actions, err = w.transformSetProfileURI(ctx, ethereumTask, log) case w.matchCharacterCreated(ethereumTask, log): - zap.L().Debug("processing character created event") - actions, err = w.transformCharacterCreated(ctx, ethereumTask, log) case w.matchCharacterSetHandle(ethereumTask, log): - zap.L().Debug("processing character set handle event") - actions, err = w.transformCharacterSetHandle(ctx, ethereumTask, log) case w.matchSetCharacterURI(ethereumTask, log): - zap.L().Debug("processing set character URI event") - actions, err = w.transformSetCharacterURI(ctx, ethereumTask, log) case w.matchPostCreated(ethereumTask, log): - zap.L().Debug("processing post created event") - actions, err = w.transformPostCreated(ctx, ethereumTask, log) case w.matchSetNoteURI(ethereumTask, log): - zap.L().Debug("processing set note URI event") - actions, err = w.transformSetNoteURI(ctx, ethereumTask, log) case w.matchDeleteNote(ethereumTask, log): - zap.L().Debug("processing delete note event") - actions, err = w.transformDeleteNote(ctx, ethereumTask, log) case w.matchMintNote(ethereumTask, log): - zap.L().Debug("processing mint note event") - actions, err = w.transformMintNote(ctx, ethereumTask, log) case w.matchSetOperator(ethereumTask, log): - zap.L().Debug("processing set operator event") - actions, err = w.transformSetOperator(ctx, ethereumTask, log) case w.matchAddOperator(ethereumTask, log): - zap.L().Debug("processing add operator event") - actions, err = w.transformAddOperator(ctx, ethereumTask, log) case w.matchRemoveOperator(ethereumTask, log): - zap.L().Debug("processing remove operator event") - actions, err = w.transformRemoveOperator(ctx, ethereumTask, log) case w.matchGrantOperatorPermissions(ethereumTask, log): - zap.L().Debug("processing grant operator permissions event") - actions, err = w.transformGrantOperatorPermissions(ctx, ethereumTask, log) case w.matchTipsCharacterForNote(ethereumTask, log): - zap.L().Debug("processing tips character for note event") - actions, err = w.transformTipsCharacterForNote(ctx, ethereumTask, log) default: - zap.L().Debug("skipping unsupported log") - continue } @@ -226,8 +188,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac activity.Actions = append(activity.Actions, actions...) } - zap.L().Debug("successfully transformed crossbell task") - return activity, nil } @@ -525,7 +485,7 @@ func (w *worker) transformTipsCharacterForNote(ctx context.Context, task *source return nil, fmt.Errorf("lookup token metadata %s: %w", event.Token, err) } - rewardTokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(event.Amount, 0)) + rewardTokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(event.Amount), 0)) post.Reward = rewardTokenMetadata @@ -692,7 +652,7 @@ func (w *worker) buildPostMetadata(ctx context.Context, blockNumber, characterID content, err := w.getIPFSContent(ctx, contentURI) if err != nil { - return nil, common.Hash{}, "", err + return nil, common.Hash{}, "", fmt.Errorf("get ipfs content: %w, uri: %s", err, contentURI) } var note NoteContent @@ -776,7 +736,7 @@ func (w *worker) buildProfileMetadata( if lo.IsNotEmpty(uri) { content, err := w.getIPFSContent(ctx, uri) if err != nil { - return nil, err + return nil, fmt.Errorf("get ipfs content: %w, uri: %s", err, uri) } mimeType := http.DetectContentType(content) @@ -935,7 +895,7 @@ func (w *worker) buildCharacterProfileMetadata( if !lo.IsEmpty(uri) { content, err := w.getIPFSContent(ctx, uri) if err != nil { - return nil, err + return nil, fmt.Errorf("get ipfs content: %w, uri: %s", err, uri) } var characterURI CharacterURIContent @@ -1040,25 +1000,16 @@ func (w *worker) buildProfileHandleSuffix(_ context.Context, handle string) stri // getIPFSContent gets IPFS content. func (w *worker) getIPFSContent(ctx context.Context, contentURI string) (json.RawMessage, error) { - zap.L().Debug("getting IPFS content", - zap.String("content_uri", contentURI)) - _, path, err := ipfs.ParseURL(contentURI) if err != nil { return nil, fmt.Errorf("parse ipfs url: %w", err) } - zap.L().Debug("fetching IPFS content", - zap.String("path", path)) - body, err := w.ipfsClient.Fetch(ctx, path, ipfs.FetchModeQuick) if err != nil { return nil, fmt.Errorf("quick fetch ipfs: %w", err) } - zap.L().Debug("successfully fetched IPFS content", - zap.String("path", path)) - return io.ReadAll(body) } diff --git a/internal/engine/worker/decentralized/contract/curve/worker.go b/internal/engine/worker/decentralized/contract/curve/worker.go index b66c5a3b3..1c79737ea 100644 --- a/internal/engine/worker/decentralized/contract/curve/worker.go +++ b/internal/engine/worker/decentralized/contract/curve/worker.go @@ -12,6 +12,7 @@ import ( "github.com/rss3-network/node/internal/engine" source "github.com/rss3-network/node/internal/engine/protocol/ethereum" "github.com/rss3-network/node/internal/engine/worker/decentralized/contract/curve/pool" + "github.com/rss3-network/node/internal/utils" "github.com/rss3-network/node/provider/ethereum" "github.com/rss3-network/node/provider/ethereum/contract" "github.com/rss3-network/node/provider/ethereum/contract/curve" @@ -99,8 +100,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac // If the task does not meet the filter conditions, it will be discarded. if !matched { - zap.L().Warn("unmatched curve task") - return nil, nil } @@ -109,8 +108,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, fmt.Errorf("invalid task type: %T", task) } - zap.L().Debug("transforming curve task", zap.String("task_id", ethereumTask.ID())) - // Build default curve feed from task. feed, err := ethereumTask.BuildActivity(activityx.WithActivityPlatform(w.Platform())) if err != nil { @@ -119,8 +116,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac switch { case w.matchStableSwapEventHashStableSwapAddLiquidityTransaction(ethereumTask): - zap.L().Debug("processing stable swap add liquidity transaction") - // Match stable swap add liquidity transaction. feed.Type = typex.ExchangeLiquidity @@ -134,8 +129,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return feed, nil case w.matchStableSwapEventHashStableSwapRemoveLiquidityTransaction(ethereumTask): - zap.L().Debug("processing stable swap remove liquidity transaction") - // Match stable swap remove liquidity transaction. feed.Type = typex.ExchangeLiquidity @@ -154,8 +147,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac for _, log := range ethereumTask.Receipt.Logs { // Ignore anonymous logs. if len(log.Topics) == 0 { - zap.L().Debug("skipping anonymous log") - continue } @@ -164,39 +155,25 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac err error ) - zap.L().Debug("processing log", - zap.String("address", log.Address.String()), - zap.String("topic", log.Topics[0].String())) - // Match curve core contract events switch { case w.matchEthereumRegistryExchangeExchangeMultipleLog(ethereumTask, log): - zap.L().Debug("processing registry exchange multiple log") - // Add registry exchange multiple feed.Type = typex.ExchangeSwap actions, err = w.transformRegistryExchangeExchangeMultipleLog(ctx, ethereumTask, log) case w.matchEthereumStableSwapTokenExchangeLog(ethereumTask, log): - zap.L().Debug("processing stable swap token exchange log") - // Add stable swap token exchange feed.Type = typex.ExchangeSwap actions, err = w.transformStableSwapTokenExchangeLog(ctx, ethereumTask, log) case w.matchEthereumLiquidityGaugeDepositLog(ethereumTask, log): - zap.L().Debug("processing liquidity gauge deposit log") - // Add liquidity gauge deposit feed.Type = typex.ExchangeStaking actions, err = w.transformLiquidityGaugeDepositLog(ctx, ethereumTask, log) case w.matchEthereumLiquidityGaugeWithdrawLog(ethereumTask, log): - zap.L().Debug("processing liquidity gauge withdraw log") - // Add liquidity gauge withdraw feed.Type = typex.ExchangeStaking actions, err = w.transformLiquidityGaugeWithdrawLog(ctx, ethereumTask, log) default: - zap.L().Debug("skipping unmatched log") - continue } @@ -207,8 +184,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac feed.Actions = append(feed.Actions, actions...) } - zap.L().Debug("successfully transformed curve task") - return feed, nil } @@ -586,21 +561,14 @@ func (w *worker) transformLiquidityGaugeWithdrawLog(ctx context.Context, task *s // buildExchangeLiquidityAction builds exchange liquidity action. func (w *worker) buildExchangeLiquidityAction(ctx context.Context, blockNumber *big.Int, chainID uint64, sender, receiver common.Address, tokenAddress *common.Address, tokenValue *big.Int, liquidityAction metadata.ExchangeLiquidityAction) (*activityx.Action, error) { - zap.L().Debug("building exchange liquidity action", - zap.String("sender", sender.String()), - zap.String("receiver", receiver.String()), - zap.Any("token", tokenAddress), - zap.Any("value", tokenValue), - zap.String("action", liquidityAction.String())) - tokenMetadata, err := w.tokenClient.Lookup(ctx, chainID, tokenAddress, nil, blockNumber) if err != nil { return nil, fmt.Errorf("lookup token: %w", err) } - tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(tokenValue, 0)) + tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(tokenValue), 0)) - action := activityx.Action{ + return &activityx.Action{ Type: typex.ExchangeLiquidity, Platform: w.Platform(), From: sender.String(), @@ -611,80 +579,48 @@ func (w *worker) buildExchangeLiquidityAction(ctx context.Context, blockNumber * *tokenMetadata, }, }, - } - - zap.L().Debug("successfully built exchange liquidity action") - - return &action, nil + }, nil } // buildTransferAction builds transfer action. func (w *worker) buildTransferAction(ctx context.Context, blockNumber *big.Int, chainID uint64, sender, receiver common.Address, tokenAddress *common.Address, tokenValue *big.Int) (*activityx.Action, error) { - zap.L().Debug("building transfer action", - zap.String("sender", sender.String()), - zap.String("receiver", receiver.String()), - zap.Any("token", tokenAddress), - zap.Any("value", tokenValue)) - tokenMetadata, err := w.tokenClient.Lookup(ctx, chainID, tokenAddress, nil, blockNumber) if err != nil { return nil, fmt.Errorf("lookup token: %w", err) } - tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(tokenValue, 0)) + tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(tokenValue), 0)) actionType := typex.TransactionTransfer if sender == ethereum.AddressGenesis { actionType = typex.TransactionMint - - zap.L().Debug("detected mint transaction", - zap.String("sender", sender.String())) } if receiver == ethereum.AddressGenesis { actionType = typex.TransactionBurn - - zap.L().Debug("detected burn transaction", - zap.String("receiver", receiver.String())) } - action := activityx.Action{ + return &activityx.Action{ Type: actionType, Platform: w.Platform(), From: sender.String(), To: receiver.String(), Metadata: metadata.TransactionTransfer(*tokenMetadata), - } - - zap.L().Debug("successfully built transfer action") - - return &action, nil + }, nil } // buildExchangeSwapAction builds exchange swap action. func (w *worker) buildExchangeSwapAction(ctx context.Context, blockNumber *big.Int, chainID uint64, from, to, tokenIn, tokenOut common.Address, amountIn, amountOut *big.Int) (*activityx.Action, error) { - zap.L().Debug("building exchange swap action", - zap.String("from", from.String()), - zap.String("to", to.String()), - zap.String("token_in", tokenIn.String()), - zap.String("token_out", tokenOut.String()), - zap.Any("amount_in", amountIn), - zap.Any("amount_out", amountOut)) - // handle the eth address tokenInAddr := &tokenIn if tokenIn == curve.AddressETH { tokenInAddr = nil - - zap.L().Debug("detected ETH as input token") } tokenOutAddr := &tokenOut if tokenOut == curve.AddressETH { tokenOutAddr = nil - - zap.L().Debug("detected ETH as output token") } tokenInMetadata, err := w.tokenClient.Lookup(ctx, chainID, tokenInAddr, nil, blockNumber) @@ -692,16 +628,16 @@ func (w *worker) buildExchangeSwapAction(ctx context.Context, blockNumber *big.I return nil, fmt.Errorf("lookup token metadata %s: %w", tokenIn, err) } - tokenInMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(amountIn, 0).Abs()) + tokenInMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(amountIn), 0).Abs()) tokenOutMetadata, err := w.tokenClient.Lookup(ctx, chainID, tokenOutAddr, nil, blockNumber) if err != nil { return nil, fmt.Errorf("lookup token metadata %s: %w", tokenOut, err) } - tokenOutMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(amountOut, 0).Abs()) + tokenOutMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(amountOut), 0).Abs()) - action := activityx.Action{ + return &activityx.Action{ Type: typex.ExchangeSwap, Platform: w.Platform(), From: from.String(), @@ -710,30 +646,19 @@ func (w *worker) buildExchangeSwapAction(ctx context.Context, blockNumber *big.I From: *tokenInMetadata, To: *tokenOutMetadata, }, - } - - zap.L().Debug("successfully built exchange swap action") - - return &action, nil + }, nil } // buildEthereumTransactionStakingAction builds ethereum transaction staking action. func (w *worker) buildEthereumTransactionStakingAction(ctx context.Context, task *source.Task, from, to common.Address, token common.Address, value *big.Int, stakingAction metadata.ExchangeStakingAction, period *metadata.ExchangeStakingPeriod) (*activityx.Action, error) { - zap.L().Debug("building ethereum transaction staking action", - zap.String("from", from.String()), - zap.String("to", to.String()), - zap.String("token", token.String()), - zap.Any("value", value), - zap.String("action", stakingAction.String())) - tokenMetadata, err := w.tokenClient.Lookup(ctx, task.ChainID, &token, nil, task.Header.Number) if err != nil { return nil, fmt.Errorf("lookup token: %w", err) } - tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(value, 0)) + tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(value), 0)) - action := activityx.Action{ + return &activityx.Action{ Type: typex.ExchangeStaking, Platform: w.Platform(), From: from.String(), @@ -743,11 +668,7 @@ func (w *worker) buildEthereumTransactionStakingAction(ctx context.Context, task Token: *tokenMetadata, Period: period, }, - } - - zap.L().Debug("successfully built ethereum transaction staking action") - - return &action, nil + }, nil } // NewWorker creates a new Curve worker. diff --git a/internal/engine/worker/decentralized/contract/ens/utils.go b/internal/engine/worker/decentralized/contract/ens/utils.go index 147a8e77f..880ca5788 100644 --- a/internal/engine/worker/decentralized/contract/ens/utils.go +++ b/internal/engine/worker/decentralized/contract/ens/utils.go @@ -16,7 +16,7 @@ func (w *worker) getEnsName(ctx context.Context, _ *big.Int, namehash common.Has // Load name from dataset namehashRecord, err := w.databaseClient.LoadDatasetENSNamehash(ctx, namehash) if err != nil { - zap.L().Error("Fail to find ens namehash from dataset", zap.String("namehash", namehash.Hex()), zap.Error(err)) + zap.L().Error("failed to find ens namehash from dataset", zap.String("namehash", namehash.Hex()), zap.Error(err)) return "", fmt.Errorf("fail to find ens namehash %v, all methods failed", namehash.String()) } diff --git a/internal/engine/worker/decentralized/contract/ens/worker.go b/internal/engine/worker/decentralized/contract/ens/worker.go index 08f2795b1..d38b39424 100644 --- a/internal/engine/worker/decentralized/contract/ens/worker.go +++ b/internal/engine/worker/decentralized/contract/ens/worker.go @@ -15,6 +15,7 @@ import ( "github.com/rss3-network/node/internal/database/model" "github.com/rss3-network/node/internal/engine" source "github.com/rss3-network/node/internal/engine/protocol/ethereum" + "github.com/rss3-network/node/internal/utils" "github.com/rss3-network/node/provider/ethereum" "github.com/rss3-network/node/provider/ethereum/contract/ens" "github.com/rss3-network/node/provider/ethereum/contract/erc1155" @@ -30,7 +31,6 @@ import ( "github.com/rss3-network/protocol-go/schema/typex" "github.com/samber/lo" "github.com/shopspring/decimal" - "go.uber.org/zap" ) // Worker is the worker for ENS. @@ -119,12 +119,10 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, fmt.Errorf("invalid task type: %T", task) } - zap.L().Debug("transforming ENS task", zap.String("task_id", ethereumTask.ID())) - // Build default ens _activities from task. - _activities, err := ethereumTask.BuildActivity(activityx.WithActivityPlatform(w.Platform())) + activities, err := ethereumTask.BuildActivity(activityx.WithActivityPlatform(w.Platform())) if err != nil { - return nil, fmt.Errorf("build _activities: %w", err) + return nil, fmt.Errorf("build activities: %w", err) } exist := lo.ContainsBy(ethereumTask.Receipt.Logs, func(log *ethereum.Log) bool { @@ -139,96 +137,62 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac ) if len(log.Topics) == 0 { - zap.L().Debug("skipping anonymous log") - continue } - zap.L().Debug("processing log", - zap.String("address", log.Address.String()), - zap.String("topic", log.Topics[0].String())) - if exist { - _activities.Type = typex.CollectibleTrade + activities.Type = typex.CollectibleTrade switch { case w.matchEnsNameRegisteredV1(ctx, *log): - zap.L().Debug("processing ENS name registration V1") - actions, err = w.transformEnsNameRegisteredV1(ctx, *log, ethereumTask) case w.matchEnsNameRegisteredV2(ctx, *log): - zap.L().Debug("processing ENS name registration V2") - actions, err = w.transformEnsNameRegisteredV2(ctx, *log, ethereumTask) default: continue } } else { - _activities.Type = typex.SocialProfile + activities.Type = typex.SocialProfile switch { case w.matchEnsNameRenewed(ctx, *log): - zap.L().Debug("processing ENS name renewal") - actions, err = w.transformEnsNameRenewed(ctx, *log, ethereumTask) case w.matchEnsTextChanged(ctx, *log): - zap.L().Debug("processing ENS text change") - actions, err = w.transformEnsTextChanged(ctx, *log, ethereumTask) case w.matchEnsTextChangedWithValue(ctx, *log): - zap.L().Debug("processing ENS text change with value") - actions, err = w.transformEnsTextChangedWithValue(ctx, *log, ethereumTask) case w.matchEnsNameWrapped(ctx, *log): - zap.L().Debug("processing ENS name wrap") - actions, err = w.transformEnsNameWrapped(ctx, *log, ethereumTask) case w.matchEnsNameUnwrapped(ctx, *log): - zap.L().Debug("processing ENS name unwrap") - actions, err = w.transformEnsNameUnwrapped(ctx, *log, ethereumTask) case w.matchEnsFusesSet(ctx, *log): - zap.L().Debug("processing ENS fuses set") - actions, err = w.transformEnsFusesSet(ctx, *log, ethereumTask) case w.matchEnsContenthashChanged(ctx, *log): - zap.L().Debug("processing ENS content hash change") - actions, err = w.transformEnsContenthashChanged(ctx, *log, ethereumTask) case w.matchEnsNameChanged(ctx, *log): - zap.L().Debug("processing ENS name change") - actions, err = w.transformEnsNameChanged(ctx, *log, ethereumTask) case w.matchEnsAddressChanged(ctx, *log): - zap.L().Debug("processing ENS address change") - actions, err = w.transformEnsAddressChanged(ctx, *log, ethereumTask) case w.matchEnsPubkeyChanged(ctx, *log): - zap.L().Debug("processing ENS pubkey change") - actions, err = w.transformEnsPubkeyChanged(ctx, *log, ethereumTask) default: - zap.L().Debug("skipping unmatched log") - continue } } if err != nil { - return nil, err + return nil, fmt.Errorf("transform ENS task: %w", err) } // Change _activities type to the first action type. for _, action := range actions { - _activities.Type = action.Type + activities.Type = action.Type } - _activities.Actions = append(_activities.Actions, actions...) + activities.Actions = append(activities.Actions, actions...) } - zap.L().Debug("successfully transformed ENS task") - - return _activities, nil + return activities, nil } // matchEnsNameRegisteredV1 matches events that ENS name register through V1 contract @@ -517,12 +481,6 @@ func (w *worker) transformEnsPubkeyChanged(ctx context.Context, log ethereum.Log } func (w *worker) buildEthereumENSRegisterAction(ctx context.Context, task *source.Task, labels [32]byte, from, to common.Address, cost *big.Int, name string) (*activityx.Action, error) { - zap.L().Debug("building ethereum ENS register action", - zap.String("from", from.String()), - zap.String("to", to.String()), - zap.String("name", name), - zap.Any("cost", cost)) - tokenMetadata, err := w.tokenClient.Lookup(ctx, task.ChainID, lo.ToPtr(ens.AddressBaseRegistrarImplementation), new(big.Int).SetBytes(labels[:]), task.Header.Number) if err != nil { return nil, fmt.Errorf("lookup token metadata %s %s: %w", ens.AddressBaseRegistrarImplementation.String(), new(big.Int).SetBytes(labels[:]), err) @@ -535,7 +493,7 @@ func (w *worker) buildEthereumENSRegisterAction(ctx context.Context, task *sourc return nil, fmt.Errorf("lookup token metadata %s: %w", "", err) } - costTokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(cost, 0)) + costTokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(cost), 0)) // Save namehash into database for further query requirements fullName := fmt.Sprintf("%s.%s", name, "eth") @@ -546,9 +504,6 @@ func (w *worker) buildEthereumENSRegisterAction(ctx context.Context, task *sourc return nil, fmt.Errorf("save dataset ens namehash: %w", err) } - zap.L().Debug("successfully built ethereum ENS register action", - zap.String("name", fullName)) - return &activityx.Action{ Type: typex.CollectibleTrade, Platform: w.Platform(), @@ -563,15 +518,6 @@ func (w *worker) buildEthereumENSRegisterAction(ctx context.Context, task *sourc } func (w *worker) buildEthereumENSProfileAction(_ context.Context, from, to common.Address, expires *big.Int, name, key, value string, action metadata.SocialProfileAction) *activityx.Action { - zap.L().Debug("building ethereum ENS profile action", - zap.String("from", from.String()), - zap.String("to", to.String()), - zap.Any("expires", expires), - zap.String("name", name), - zap.String("key", key), - zap.String("value", value), - zap.String("action", action.String())) - label := strings.Split(name, ".eth")[0] tokenID := common.BytesToHash(crypto.Keccak256([]byte(label))).Big() @@ -589,10 +535,6 @@ func (w *worker) buildEthereumENSProfileAction(_ context.Context, from, to commo socialProfile.Expiry = lo.ToPtr(time.Unix(expires.Int64(), 0)) } - zap.L().Debug("successfully built ethereum ENS profile action", - zap.String("profile_id", tokenID.String()), - zap.String("handle", name)) - return &activityx.Action{ Type: typex.SocialProfile, Platform: w.Platform(), diff --git a/internal/engine/worker/decentralized/contract/highlight/worker.go b/internal/engine/worker/decentralized/contract/highlight/worker.go index 79775c7eb..0bd86af0a 100644 --- a/internal/engine/worker/decentralized/contract/highlight/worker.go +++ b/internal/engine/worker/decentralized/contract/highlight/worker.go @@ -9,6 +9,7 @@ import ( "github.com/rss3-network/node/config" "github.com/rss3-network/node/internal/engine" source "github.com/rss3-network/node/internal/engine/protocol/ethereum" + "github.com/rss3-network/node/internal/utils" "github.com/rss3-network/node/provider/ethereum" "github.com/rss3-network/node/provider/ethereum/contract" "github.com/rss3-network/node/provider/ethereum/contract/erc721" @@ -23,7 +24,6 @@ import ( "github.com/rss3-network/protocol-go/schema/typex" "github.com/samber/lo" "github.com/shopspring/decimal" - "go.uber.org/zap" ) // Worker is the worker for Highlight. @@ -103,8 +103,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, fmt.Errorf("invalid task type: %T", task) } - zap.L().Debug("transforming highlight task", zap.String("task_id", ethereumTask.ID())) - // Build default highlight activity from task. activity, err := ethereumTask.BuildActivity(activityx.WithActivityPlatform(w.Platform())) if err != nil { @@ -115,8 +113,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac for _, log := range ethereumTask.Receipt.Logs { // Ignore anonymous logs. if len(log.Topics) == 0 { - zap.L().Debug("skipping anonymous log") - continue } @@ -125,30 +121,19 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac err error ) - zap.L().Debug("processing ethereum log", - zap.String("address", log.Address.String()), - zap.String("topic", log.Topics[0].String())) - // Match highlight core contract events switch { case w.matchNativeGasTokenPaymentMatched(ethereumTask, log): - zap.L().Debug("processing native gas token payment event") - actions, err = w.transformNativeGasTokenPayment(ctx, ethereumTask, log) case w.matchNumTokenMintMatched(ethereumTask, log): - zap.L().Debug("processing num token mint event") - activity.Type = typex.CollectibleMint actions, err = w.transformNumTokenMint(ctx, ethereumTask, log) default: - zap.L().Debug("skipping unmatched log", - zap.String("topic", log.Topics[0].String())) - continue } if err != nil { - return nil, err + return nil, fmt.Errorf("transform highlight task: %w", err) } // Change activity type to the first action type. @@ -159,8 +144,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac activity.Actions = append(activity.Actions, actions...) } - zap.L().Debug("successfully transformed highlight task") - return activity, nil } @@ -242,19 +225,12 @@ func (w *worker) transformNumTokenMint(ctx context.Context, task *source.Task, l // buildTransferAction builds transfer action. func (w *worker) buildTransferAction(ctx context.Context, task *source.Task, from common.Address, to common.Address, amount *big.Int) (*activityx.Action, error) { - zap.L().Debug("building transfer action", - zap.String("from", from.String()), - zap.String("to", to.String()), - zap.Any("amount", amount)) - tokenMetadata, err := w.tokenClient.Lookup(ctx, task.ChainID, nil, nil, task.Header.Number) if err != nil { return nil, fmt.Errorf("lookup token metadata: %w", err) } - tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(amount, 0)) - - zap.L().Debug("successfully built transfer action") + tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(amount), 0)) return &activityx.Action{ Type: typex.TransactionTransfer, @@ -267,21 +243,12 @@ func (w *worker) buildTransferAction(ctx context.Context, task *source.Task, fro // buildHighlightMintAction builds highlight mint action. func (w *worker) buildHighlightMintAction(ctx context.Context, task *source.Task, from, to common.Address, contract common.Address, id *big.Int, value *big.Int) (*activityx.Action, error) { - zap.L().Debug("building highlight mint action", - zap.String("from", from.String()), - zap.String("to", to.String()), - zap.String("contract", contract.String()), - zap.Any("token_id", id), - zap.Any("value", value)) - tokenMetadata, err := w.tokenClient.Lookup(ctx, task.ChainID, &contract, id, task.Header.Number) if err != nil { return nil, fmt.Errorf("lookup token metadata: %w", err) } - tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(value, 0)) - - zap.L().Debug("successfully built highlight mint action") + tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(value), 0)) return &activityx.Action{ Type: typex.CollectibleMint, diff --git a/internal/engine/worker/decentralized/contract/iqwiki/worker.go b/internal/engine/worker/decentralized/contract/iqwiki/worker.go index 06b4a0088..9f7db9afa 100644 --- a/internal/engine/worker/decentralized/contract/iqwiki/worker.go +++ b/internal/engine/worker/decentralized/contract/iqwiki/worker.go @@ -88,8 +88,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, fmt.Errorf("invalid task type: %T", task) } - zap.L().Debug("transforming IQWiki task", zap.String("task_id", ethereumTask.ID())) - if ethereumTask.Transaction.To == nil { return nil, fmt.Errorf("invalid transaction to: %s", ethereumTask.Transaction.Hash) } @@ -99,8 +97,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac } // Build default IQWiki activity from task. - zap.L().Debug("building default IQWiki activity") - activity, err := ethereumTask.BuildActivity(activityx.WithActivityPlatform(w.Platform())) if err != nil { return nil, fmt.Errorf("build activity: %w", err) @@ -110,8 +106,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac for _, log := range ethereumTask.Receipt.Logs { // Ignore anonymous logs. if len(log.Topics) == 0 { - zap.L().Debug("skipping anonymous log") - continue } @@ -134,28 +128,21 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac activity.Tag = tag.Social activity.TotalActions = uint(len(activity.Actions)) - zap.L().Debug("successfully transformed IQWiki task") - return activity, nil } // Parse action from Ethereum log. func (w *worker) parseAction(ctx context.Context, log *ethereum.Log, ethereumTask *source.Task) (*activityx.Action, error) { - zap.L().Debug("parsing IQWiki action", - zap.String("transaction_hash", ethereumTask.Transaction.Hash.String())) - wikiPosted, err := w.iqWikiFilterer.ParsePosted(log.Export()) if err != nil { return nil, fmt.Errorf("parse posted: %w", err) } ipfsID := wikiPosted.Ipfs - zap.L().Debug("fetching IPFS content", - zap.String("ipfs_id", ipfsID)) - content, err := w.getEthereumIPFSContent(ctx, ipfsID) + if err != nil { - return nil, fmt.Errorf("get ipfs content: %w", err) + return nil, fmt.Errorf("get ipfs content: %w,uri: %s", err, ipfsID) } var wiki struct { @@ -171,19 +158,11 @@ func (w *worker) parseAction(ctx context.Context, log *ethereum.Log, ethereumTas return nil, fmt.Errorf("invalid wiki, hash %s, %w", ethereumTask.Transaction.Hash, err) } - zap.L().Debug("fetching wiki details", - zap.String("wiki_id", wiki.ID), - zap.Int("block_number", int(ethereumTask.Header.Number.Int64()))) - wikiResponse, err := iqwiki.ActivityByWikiIdAndBlock(context.Background(), w.iqWikiClient, int(ethereumTask.Header.Number.Int64()), wiki.ID) if err != nil { return nil, fmt.Errorf("fetch wiki %s, hash %s, %w", wiki.ID, ethereumTask.Transaction.Hash.String(), err) } - zap.L().Debug("building IQWiki action", - zap.String("wiki_id", wikiResponse.ActivityByWikiIdAndBlock.WikiId), - zap.String("type", string(wikiResponse.ActivityByWikiIdAndBlock.Type))) - action := &activityx.Action{ Tag: tag.Social, Type: lo.If(iqwiki.StatusCreated == wikiResponse.ActivityByWikiIdAndBlock.Type, typex.SocialPost).Else(typex.SocialRevise), @@ -210,10 +189,6 @@ func (w *worker) parseAction(ctx context.Context, log *ethereum.Log, ethereumTas }, } - zap.L().Debug("successfully built IQWiki action", - zap.String("wiki_id", wikiResponse.ActivityByWikiIdAndBlock.WikiId), - zap.String("type", action.Type.Name())) - return action, nil } diff --git a/internal/engine/worker/decentralized/contract/kiwistand/worker.go b/internal/engine/worker/decentralized/contract/kiwistand/worker.go index a7734f702..f54139d0b 100644 --- a/internal/engine/worker/decentralized/contract/kiwistand/worker.go +++ b/internal/engine/worker/decentralized/contract/kiwistand/worker.go @@ -9,6 +9,7 @@ import ( "github.com/rss3-network/node/config" "github.com/rss3-network/node/internal/engine" source "github.com/rss3-network/node/internal/engine/protocol/ethereum" + "github.com/rss3-network/node/internal/utils" "github.com/rss3-network/node/provider/ethereum" "github.com/rss3-network/node/provider/ethereum/contract" "github.com/rss3-network/node/provider/ethereum/contract/kiwistand" @@ -22,7 +23,6 @@ import ( "github.com/rss3-network/protocol-go/schema/typex" "github.com/samber/lo" "github.com/shopspring/decimal" - "go.uber.org/zap" ) // Worker is the worker for KiwiStand. @@ -88,8 +88,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, fmt.Errorf("invalid task type: %T", task) } - zap.L().Debug("transforming KiwiStand task", zap.String("task_id", ethereumTask.ID())) - // Build default kiwistand activity from task. activity, err := ethereumTask.BuildActivity(activityx.WithActivityPlatform(w.Platform())) if err != nil { @@ -103,27 +101,15 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac err error ) - zap.L().Debug("processing log", - zap.String("address", log.Address.String()), - zap.String("topic", log.Topics[0].String())) - // Match kiwistand core contract events switch { case w.matchRewardsDeposit(ethereumTask, log): - zap.L().Debug("processing rewards deposit event") - actions, err = w.transformRewardsDeposit(ctx, ethereumTask, log) case w.matchTransfer(ethereumTask, log): - zap.L().Debug("processing transfer event") - actions, err = w.transformKiwiMint(ctx, ethereumTask, log) case w.matchSale(ethereumTask, log): - zap.L().Debug("processing sale event") - actions, err = w.transformSale(ctx, ethereumTask, log) case w.matchMintComment(ethereumTask, log): - zap.L().Debug("processing mint comment event") - actions, err = w.transformMintComment(ctx, ethereumTask, log) default: continue @@ -138,8 +124,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac activity.Actions = append(activity.Actions, actions...) } - zap.L().Debug("successfully transformed KiwiStand task") - return activity, nil } @@ -272,21 +256,12 @@ func (w *worker) transformMintComment(ctx context.Context, task *source.Task, lo // buildKiwiMintAction builds KiwiMint action. func (w *worker) buildKiwiMintAction(ctx context.Context, task *source.Task, from, to common.Address, contract common.Address, id *big.Int, value *big.Int) (*activityx.Action, error) { - zap.L().Debug("building kiwi mint action", - zap.String("from", from.String()), - zap.String("to", to.String()), - zap.String("contract", contract.String()), - zap.Any("token_id", id), - zap.Any("value", value)) - tokenMetadata, err := w.tokenClient.Lookup(ctx, task.ChainID, &contract, id, task.Header.Number) if err != nil { return nil, fmt.Errorf("lookup token metadata: %w", err) } - tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(value, 0)) - - zap.L().Debug("successfully built kiwi mint action") + tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(value), 0)) return &activityx.Action{ Type: typex.CollectibleMint, @@ -299,12 +274,7 @@ func (w *worker) buildKiwiMintAction(ctx context.Context, task *source.Task, fro // buildKiwiMintCommentAction builds KiwiMintComment action. func (w *worker) buildKiwiMintCommentAction(_ context.Context, from common.Address, to common.Address, comment string) *activityx.Action { - zap.L().Debug("building kiwi mint comment action", - zap.String("from", from.String()), - zap.String("to", to.String()), - zap.String("comment", comment)) - - action := &activityx.Action{ + return &activityx.Action{ From: from.String(), To: lo.If(to == ethereum.AddressGenesis, "").Else(to.String()), Platform: w.Platform(), @@ -314,27 +284,16 @@ func (w *worker) buildKiwiMintCommentAction(_ context.Context, from common.Addre Body: comment, }, } - - zap.L().Debug("successfully built kiwi mint comment action") - - return action } // buildKiwiFee builds fee func (w *worker) buildKiwiFeeAction(ctx context.Context, task *source.Task, from common.Address, to common.Address, amount *big.Int) (*activityx.Action, error) { - zap.L().Debug("building kiwi fee action", - zap.String("from", from.String()), - zap.String("to", to.String()), - zap.Any("amount", amount)) - tokenMetadata, err := w.tokenClient.Lookup(ctx, task.ChainID, nil, nil, task.Header.Number) if err != nil { return nil, fmt.Errorf("lookup token metadata: %w", err) } - tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(amount, 0)) - - zap.L().Debug("successfully built kiwi fee action") + tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(amount), 0)) return &activityx.Action{ Type: typex.TransactionTransfer, diff --git a/internal/engine/worker/decentralized/contract/lens/worker.go b/internal/engine/worker/decentralized/contract/lens/worker.go index b7751ae83..c1c1d60be 100644 --- a/internal/engine/worker/decentralized/contract/lens/worker.go +++ b/internal/engine/worker/decentralized/contract/lens/worker.go @@ -28,7 +28,6 @@ import ( "github.com/rss3-network/protocol-go/schema/typex" "github.com/samber/lo" "github.com/tidwall/gjson" - "go.uber.org/zap" ) // Worker is the worker for Lens. @@ -122,8 +121,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, fmt.Errorf("invalid task type: %T", task) } - zap.L().Debug("transforming lens task", zap.String("task_id", ethereumTask.ID())) - // Build default lens activity from task. activity, err := ethereumTask.BuildActivity(activityx.WithActivityPlatform(w.Platform())) if err != nil { @@ -134,8 +131,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac for _, log := range ethereumTask.Receipt.Logs { // Ignore anonymous logs. if len(log.Topics) == 0 { - zap.L().Debug("ignoring anonymous log") - continue } @@ -144,71 +139,37 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac err error ) - zap.L().Debug("processing log", - zap.String("address", log.Address.String()), - zap.String("topic", log.Topics[0].String())) - // Match lens core contract events switch { case w.matchEthereumV1PostCreated(ethereumTask, log): - zap.L().Debug("processing V1 post created event") - actions, err = w.transformEthereumV1PostCreated(ctx, ethereumTask, log) case w.matchEthereumV1CommentCreated(ethereumTask, log): - zap.L().Debug("processing V1 comment created event") - actions, err = w.transformEthereumV1CommentCreated(ctx, ethereumTask, log) case w.matchEthereumV1MirrorCreated(ethereumTask, log): - zap.L().Debug("processing V1 mirror created event") - actions, err = w.transformEthereumV1MirrorCreated(ctx, ethereumTask, log) case w.matchEthereumV1ProfileCreated(ethereumTask, log): - zap.L().Debug("processing V1 profile created event") - actions, err = w.transformEthereumV1ProfileCreated(ctx, ethereumTask, log) case w.matchEthereumV1ProfileSet(ethereumTask, log): - zap.L().Debug("processing V1 profile set event") - actions, err = w.transformEthereumV1ProfileSet(ctx, ethereumTask, log) case w.matchEthereumV1ProfileImageURISet(ethereumTask, log): - zap.L().Debug("processing V1 profile image URI set event") - actions, err = w.transformEthereumV1ProfileImageURISet(ctx, ethereumTask, log) case w.matchEthereumV1CollectNFTTransferred(ethereumTask, log): - zap.L().Debug("processing V1 collect NFT transferred event") - actions, err = w.transformEthereumV1CollectNFTTransferred(ctx, ethereumTask, log) case w.matchEthereumV2PostCreated(ethereumTask, log): - zap.L().Debug("processing V2 post created event") - actions, err = w.transformEthereumV2PostCreated(ctx, ethereumTask, log) case w.matchEthereumV2CommentCreated(ethereumTask, log): - zap.L().Debug("processing V2 comment created event") - actions, err = w.transformEthereumV2CommentCreated(ctx, ethereumTask, log) case w.matchEthereumV2MirrorCreated(ethereumTask, log): - zap.L().Debug("processing V2 mirror created event") - actions, err = w.transformEthereumV2MirrorCreated(ctx, ethereumTask, log) case w.matchEthereumV2QuoteCreated(ethereumTask, log): - zap.L().Debug("processing V2 quote created event") - actions, err = w.transformEthereumV2QuoteCreated(ctx, ethereumTask, log) case w.matchEthereumV2Collected(ethereumTask, log): - zap.L().Debug("processing V2 collected event") - actions, err = w.transformEthereumV2Collected(ctx, ethereumTask, log) case w.matchEthereumV2ProfileCreated(ethereumTask, log): - zap.L().Debug("processing V2 profile created event") - actions, err = w.transformEthereumV2ProfileCreated(ctx, ethereumTask, log) case w.matchEthereumV2ProfileSet(ethereumTask, log): - zap.L().Debug("processing V2 profile set event") - actions, err = w.transformEthereumV2ProfileSet(ctx, ethereumTask, log) default: - zap.L().Debug("unmatched event, skipping") - continue } @@ -224,8 +185,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac activity.Actions = append(activity.Actions, actions...) } - zap.L().Debug("successfully transformed lens task") - return activity, nil } @@ -779,14 +738,6 @@ func (w *worker) buildEthereumTransactionPostAction(_ context.Context, from comm } func (w *worker) buildEthereumV1TransactionPostMetadata(ctx context.Context, blockNumber *big.Int, profileID, pubID *big.Int, contentURI string, isTarget bool, timestamp uint64) (*metadata.SocialPost, string, error) { - zap.L().Debug("building ethereum V1 transaction post metadata", - zap.String("block_number", blockNumber.String()), - zap.Any("profile_id", profileID), - zap.Any("pub_id", pubID), - zap.String("content_uri", contentURI), - zap.Bool("is_target", isTarget), - zap.Any("timestamp", timestamp)) - handle, err := w.getLensHandle(ctx, blockNumber, profileID) if err != nil { return nil, "", err @@ -802,8 +753,6 @@ func (w *worker) buildEthereumV1TransactionPostMetadata(ctx context.Context, blo return nil, "", fmt.Errorf("unmarshal publication: %w", err) } - zap.L().Debug("successfully built ethereum V1 transaction post metadata") - return &metadata.SocialPost{ Handle: handle, Body: publication.Content, @@ -885,41 +834,29 @@ func (w *worker) getContentFromURI(ctx context.Context, contentURI string) (json } func (w *worker) getDataFromHTTP(ctx context.Context, contentURL string) (io.ReadCloser, error) { - zap.L().Debug("fetching data from URL", zap.String("url", contentURL)) - // get from ipfs if _, path, err := ipfs.ParseURL(contentURL); err == nil { - zap.L().Debug("fetching from IPFS", zap.String("path", path)) - resp, err := w.ipfsClient.Fetch(ctx, path, ipfs.FetchModeQuick) if err != nil { return nil, fmt.Errorf("quick fetch ipfs: %w", err) } - zap.L().Debug("successfully fetched from IPFS") - return resp, nil } // get from arweave if strings.HasPrefix(contentURL, "ar://") { - zap.L().Debug("detected ar:// prefix, removing") // remove ar:// prefix contentURL = contentURL[5:] } else if strings.HasPrefix(contentURL, "https://arweave.net/") { - zap.L().Debug("detected arweave.net URL, extracting transaction ID") // remove https://arweave.net/ contentURL = contentURL[19:] } if strings.HasPrefix(contentURL, "https://") { - zap.L().Debug("fetching from HTTPS URL", zap.String("url", contentURL)) - return w.httpClient.Fetch(ctx, contentURL) } - zap.L().Debug("fetching from Arweave", zap.String("transaction_id", contentURL)) - return w.arweaveClient.GetTransactionData(ctx, contentURL) } @@ -935,33 +872,17 @@ func (w *worker) getEthereumPublicationContentURI(_ context.Context, blockNumber // buildEthereumTransactionProfileAction builds profile action. func (w *worker) buildEthereumTransactionProfileAction(_ context.Context, from common.Address, to common.Address, profile metadata.SocialProfile) *activityx.Action { - zap.L().Debug("building ethereum transaction profile action", - zap.String("from", from.String()), - zap.String("to", to.String())) - - action := &activityx.Action{ + return &activityx.Action{ From: from.String(), To: lo.If(to == ethereum.AddressGenesis, "").Else(to.String()), Platform: w.Platform(), Type: typex.SocialProfile, Metadata: profile, } - - zap.L().Debug("successfully built ethereum transaction profile action") - - return action } // buildEthereumV2TransactionPostMetadata builds post metadata. func (w *worker) buildEthereumV2TransactionPostMetadata(ctx context.Context, blockNumber *big.Int, profileID, pubID *big.Int, contentURI string, isTarget bool, timestamp uint64) (*metadata.SocialPost, string, error) { - zap.L().Debug("building ethereum V2 transaction post metadata", - zap.String("block_number", blockNumber.String()), - zap.Any("profile_id", profileID), - zap.Any("pub_id", pubID), - zap.String("content_uri", contentURI), - zap.Bool("is_target", isTarget), - zap.Any("timestamp", timestamp)) - handle, err := w.getLensHandle(ctx, blockNumber, profileID) if err != nil { return nil, "", err @@ -1010,8 +931,6 @@ func (w *worker) buildEthereumV2TransactionPostMetadata(ctx context.Context, blo Timestamp: lo.If(isTarget, uint64(0)).Else(timestamp), } - zap.L().Debug("successfully built ethereum V2 transaction post metadata") - return post, publication.Lens.AppID, nil } diff --git a/internal/engine/worker/decentralized/contract/lido/worker.go b/internal/engine/worker/decentralized/contract/lido/worker.go index 6994a3e33..0d7b13411 100644 --- a/internal/engine/worker/decentralized/contract/lido/worker.go +++ b/internal/engine/worker/decentralized/contract/lido/worker.go @@ -9,6 +9,7 @@ import ( "github.com/rss3-network/node/config" "github.com/rss3-network/node/internal/engine" source "github.com/rss3-network/node/internal/engine/protocol/ethereum" + "github.com/rss3-network/node/internal/utils" "github.com/rss3-network/node/provider/ethereum" "github.com/rss3-network/node/provider/ethereum/contract" "github.com/rss3-network/node/provider/ethereum/contract/erc20" @@ -24,7 +25,6 @@ import ( "github.com/rss3-network/protocol-go/schema/typex" "github.com/samber/lo" "github.com/shopspring/decimal" - "go.uber.org/zap" ) // Worker is the worker for Lido. @@ -106,8 +106,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, fmt.Errorf("invalid task type: %T", task) } - zap.L().Debug("transforming lido task", zap.String("task_id", ethereumTask.ID())) - // Build default lido activity from task. activity, err := ethereumTask.BuildActivity(activityx.WithActivityPlatform(w.Platform())) if err != nil { @@ -118,7 +116,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac for _, log := range ethereumTask.Receipt.Logs { // Ignore anonymous logs. if len(log.Topics) == 0 { - zap.L().Debug("ignoring anonymous log") continue } @@ -127,50 +124,30 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac err error ) - zap.L().Debug("processing log", - zap.String("address", log.Address.String()), - zap.String("topic", log.Topics[0].String())) - // Match lido core contract events switch { case w.matchStakedETHSubmittedLog(ethereumTask, log): - zap.L().Debug("processing staked ETH submitted event") - activity.Type = typex.ExchangeLiquidity actions, err = w.transformStakedETHSubmittedLog(ctx, ethereumTask, log) case w.matchStakedETHWithdrawalNFTWithdrawalRequestedLog(ethereumTask, log): - zap.L().Debug("processing staked ETH withdrawal NFT request event") - activity.Type = typex.ExchangeLiquidity actions, err = w.transformStakedETHWithdrawalNFTWithdrawalRequestedLog(ctx, ethereumTask, log) case w.matchStakedETHWithdrawalNFTWithdrawalClaimedLog(ethereumTask, log): - zap.L().Debug("processing staked ETH withdrawal NFT claim event") - activity.Type = typex.CollectibleBurn actions, err = w.transformStakedETHWithdrawalNFTWithdrawalClaimedLog(ctx, ethereumTask, log) case w.matchStakedMATICSubmitEventLog(ethereumTask, log): - zap.L().Debug("processing staked MATIC submit event") - activity.Type = typex.ExchangeLiquidity actions, err = w.transformStakedMATICSubmitEventLog(ctx, ethereumTask, log) case w.matchStakedMATICRequestWithdrawEventLog(ethereumTask, log): - zap.L().Debug("processing staked MATIC withdrawal request event") - activity.Type = typex.CollectibleMint actions, err = w.transformStakedMATICRequestWithdrawEventLog(ctx, ethereumTask, log) case w.matchStakedMATICClaimTokensEventLog(ethereumTask, log): - zap.L().Debug("processing staked MATIC claim tokens event") - activity.Type = typex.CollectibleBurn actions, err = w.transformStakedMATICClaimTokensEventLog(ctx, ethereumTask, log) case w.matchStakedETHTransferSharesLog(ethereumTask, log): - zap.L().Debug("processing staked ETH transfer shares event") - activity.Type = typex.ExchangeSwap actions, err = w.transformStakedETHTransferSharesLog(ctx, ethereumTask, log) default: - zap.L().Debug("unmatched event, skipping") - continue } @@ -181,8 +158,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac activity.Actions = append(activity.Actions, actions...) } - zap.L().Debug("successfully transformed lido task") - return activity, nil } @@ -478,7 +453,7 @@ func (w *worker) buildEthereumExchangeLiquidityAction(ctx context.Context, block return nil, fmt.Errorf("lookup token: %w", err) } - tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(tokenValue, 0)) + tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(tokenValue), 0)) action := activityx.Action{ Type: typex.ExchangeLiquidity, @@ -497,110 +472,72 @@ func (w *worker) buildEthereumExchangeLiquidityAction(ctx context.Context, block } func (w *worker) buildEthereumTransactionTransferAction(ctx context.Context, blockNumber *big.Int, chainID uint64, sender, receiver common.Address, tokenAddress *common.Address, tokenValue *big.Int) (*activityx.Action, error) { - zap.L().Debug("building ethereum transaction transfer action", - zap.String("sender", sender.String()), - zap.String("receiver", receiver.String()), - zap.Any("token_address", tokenAddress), - zap.Any("token_value", tokenValue)) - tokenMetadata, err := w.tokenClient.Lookup(ctx, chainID, tokenAddress, nil, blockNumber) if err != nil { return nil, fmt.Errorf("lookup token: %w", err) } - tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(tokenValue, 0)) + tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(tokenValue), 0)) actionType := typex.TransactionTransfer if sender == ethereum.AddressGenesis { - zap.L().Debug("detected mint transaction") - actionType = typex.TransactionMint } if receiver == ethereum.AddressGenesis { - zap.L().Debug("detected burn transaction") - actionType = typex.TransactionBurn } - action := activityx.Action{ + return &activityx.Action{ Type: actionType, Platform: w.Platform(), From: sender.String(), To: receiver.String(), Metadata: metadata.TransactionTransfer(*tokenMetadata), - } - - zap.L().Debug("successfully built ethereum transaction transfer action") - - return &action, nil + }, nil } func (w *worker) buildEthereumCollectibleTransferAction(ctx context.Context, blockNumber *big.Int, chainID uint64, sender, receiver, tokenAddress common.Address, tokenID, tokenValue *big.Int) (*activityx.Action, error) { - zap.L().Debug("building ethereum collectible transfer action", - zap.String("sender", sender.String()), - zap.String("receiver", receiver.String()), - zap.String("token_address", tokenAddress.String()), - zap.Any("token_id", tokenID), - zap.Any("token_value", tokenValue)) - tokenMetadata, err := w.tokenClient.Lookup(ctx, chainID, &tokenAddress, tokenID, blockNumber) if err != nil { return nil, fmt.Errorf("lookup token: %w", err) } - tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(tokenValue, 0)) - + tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(tokenValue), 0)) actionType := typex.CollectibleTransfer if sender == ethereum.AddressGenesis { - zap.L().Debug("detected mint collectible") - actionType = typex.CollectibleMint } if receiver == ethereum.AddressGenesis { - zap.L().Debug("detected burn collectible") - actionType = typex.CollectibleBurn } - action := activityx.Action{ + return &activityx.Action{ Type: actionType, Platform: w.Platform(), From: sender.String(), To: receiver.String(), Metadata: metadata.CollectibleTransfer(*tokenMetadata), - } - - zap.L().Debug("successfully built ethereum collectible transfer action") - - return &action, nil + }, nil } func (w *worker) buildEthereumExchangeSwapAction(ctx context.Context, blockNumber *big.Int, chainID uint64, from, to, tokenIn, tokenOut common.Address, amountIn, amountOut *big.Int) (*activityx.Action, error) { - zap.L().Debug("building ethereum exchange swap action", - zap.String("from", from.String()), - zap.String("to", to.String()), - zap.String("token_in", tokenIn.String()), - zap.String("token_out", tokenOut.String()), - zap.Any("amount_in", amountIn), - zap.Any("amount_out", amountOut)) - tokenInMetadata, err := w.tokenClient.Lookup(ctx, chainID, &tokenIn, nil, blockNumber) if err != nil { return nil, fmt.Errorf("lookup token metadata %s: %w", tokenIn, err) } - tokenInMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(amountIn, 0).Abs()) + tokenInMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(amountIn), 0).Abs()) tokenOutMetadata, err := w.tokenClient.Lookup(ctx, chainID, &tokenOut, nil, blockNumber) if err != nil { return nil, fmt.Errorf("lookup token metadata %s: %w", tokenOut, err) } - tokenOutMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(amountOut, 0).Abs()) + tokenOutMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(amountOut), 0).Abs()) action := activityx.Action{ Type: typex.ExchangeSwap, @@ -613,8 +550,6 @@ func (w *worker) buildEthereumExchangeSwapAction(ctx context.Context, blockNumbe }, } - zap.L().Debug("successfully built ethereum exchange swap action") - return &action, nil } diff --git a/internal/engine/worker/decentralized/contract/linea/worker.go b/internal/engine/worker/decentralized/contract/linea/worker.go index aab043da4..d54286ff4 100644 --- a/internal/engine/worker/decentralized/contract/linea/worker.go +++ b/internal/engine/worker/decentralized/contract/linea/worker.go @@ -9,6 +9,7 @@ import ( "github.com/rss3-network/node/config" "github.com/rss3-network/node/internal/engine" source "github.com/rss3-network/node/internal/engine/protocol/ethereum" + "github.com/rss3-network/node/internal/utils" "github.com/rss3-network/node/provider/ethereum" "github.com/rss3-network/node/provider/ethereum/contract" "github.com/rss3-network/node/provider/ethereum/contract/linea" @@ -87,8 +88,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, fmt.Errorf("invalid task type: %T", task) } - zap.L().Debug("transforming linea task", zap.String("task_id", ethereumTask.ID())) - // Build the activity. activity, err := task.BuildActivity(activityx.WithActivityPlatform(w.Platform())) if err != nil { @@ -98,8 +97,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac for _, log := range ethereumTask.Receipt.Logs { // Ignore anonymous logs. if len(log.Topics) == 0 { - zap.L().Debug("ignoring anonymous log") - continue } @@ -108,43 +105,25 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac err error ) - zap.L().Debug("processing log", - zap.String("address", log.Address.String()), - zap.String("topic", log.Topics[0].String())) - switch { case w.matchEthereumZKEVMV2MessageSentLog(*ethereumTask, log): - zap.L().Debug("processing ZKEVMV2 message sent event") - actions, err = w.handleEthereumZKEVMV2MessageSentLog(ctx, *ethereumTask, *log, activity) case w.matchEthereumZKEVMV2MessageClaimedLog(*ethereumTask, log): - zap.L().Debug("processing ZKEVMV2 message claimed event") - actions, err = w.handleEthereumZKEVMV2MessageClaimedLog(ctx, *ethereumTask, *log, activity) case w.matchEthereumTokenBridgeBridgingInitiatedLog(*ethereumTask, log): - zap.L().Debug("processing token bridge bridging initiated event") - actions, err = w.handleEthereumTokenBridgeBridgingInitiatedLog(ctx, *ethereumTask, *log, activity) case w.matchEthereumTokenBridgeBridgingFinalizedLog(*ethereumTask, log): - zap.L().Debug("processing token bridge bridging finalized event") - actions, err = w.handleEthereumTokenBridgeBridgingFinalizedLog(ctx, *ethereumTask, *log, activity) case w.matchEthereumL1USDCBridgeDepositedLog(*ethereumTask, log): - zap.L().Debug("processing L1 USDC bridge deposited event") - actions, err = w.handleEthereumL1USDCBridgeDepositedLog(ctx, *ethereumTask, *log, activity) case w.matchEthereumL1USDCBridgeReceivedFromOtherLayerLog(*ethereumTask, log): - zap.L().Debug("processing L1 USDC bridge received from other layer event") - actions, err = w.handleEthereumL1USDCBridgeReceivedFromOtherLayerLog(ctx, *ethereumTask, *log, activity) default: - zap.L().Debug("unsupported log", zap.String("task", task.ID()), zap.Uint("topic_index", log.Index)) - continue } if err != nil { - zap.L().Warn("failed to handle ethereum log", + zap.L().Error("failed to handle ethereum log", zap.Error(err), zap.String("task", task.ID()), zap.String("log_address", log.Address.String())) @@ -164,8 +143,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, nil } - zap.L().Debug("successfully transformed linea task") - return activity, nil } @@ -367,20 +344,12 @@ func (w *worker) handleEthereumL1USDCBridgeReceivedFromOtherLayerLog(ctx context } func (w *worker) buildEthereumTransactionBridgeAction(ctx context.Context, chainID uint64, sender, receiver common.Address, source, target network.Network, bridgeAction metadata.TransactionBridgeAction, tokenAddress *common.Address, tokenValue *big.Int, blockNumber *big.Int) (*activityx.Action, error) { - zap.L().Debug("building ethereum transaction bridge action", - zap.String("sender", sender.String()), - zap.String("receiver", receiver.String()), - zap.String("source_network", source.String()), - zap.String("target_network", target.String()), - zap.Any("token_address", tokenAddress), - zap.Any("token_value", tokenValue)) - tokenMetadata, err := w.tokenClient.Lookup(ctx, chainID, tokenAddress, nil, blockNumber) if err != nil { return nil, fmt.Errorf("lookup token: %w", err) } - tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(tokenValue, 0)) + tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(tokenValue), 0)) action := activityx.Action{ Type: typex.TransactionBridge, @@ -396,8 +365,6 @@ func (w *worker) buildEthereumTransactionBridgeAction(ctx context.Context, chain }, } - zap.L().Debug("successfully built ethereum transaction bridge action") - return &action, nil } diff --git a/internal/engine/worker/decentralized/contract/linear/worker.go b/internal/engine/worker/decentralized/contract/linear/worker.go index cba173dbf..dc47b8e42 100644 --- a/internal/engine/worker/decentralized/contract/linear/worker.go +++ b/internal/engine/worker/decentralized/contract/linear/worker.go @@ -10,6 +10,7 @@ import ( "github.com/rss3-network/node/config" "github.com/rss3-network/node/internal/engine" source "github.com/rss3-network/node/internal/engine/protocol/near" + "github.com/rss3-network/node/internal/utils" workerx "github.com/rss3-network/node/schema/worker/decentralized" "github.com/rss3-network/protocol-go/schema" activityx "github.com/rss3-network/protocol-go/schema/activity" @@ -19,7 +20,6 @@ import ( "github.com/rss3-network/protocol-go/schema/typex" "github.com/samber/lo" "github.com/shopspring/decimal" - "go.uber.org/zap" ) var _ engine.Worker = (*worker)(nil) @@ -79,8 +79,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, fmt.Errorf("invalid task type: %T", task) } - zap.L().Debug("transforming linear task", zap.String("task_id", nearTask.ID())) - // Build the activity. activity, err := task.BuildActivity(activityx.WithActivityPlatform(w.Platform())) if err != nil { @@ -100,13 +98,8 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac }) if hasSwapAction { - zap.L().Debug("detected swap action, setting activity type to ExchangeSwap") - activity.Type = typex.ExchangeSwap } else { - zap.L().Debug("no swap action detected, using first action type", - zap.String("type", actions[0].Type.Name())) - activity.Type = actions[0].Type } @@ -115,8 +108,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, fmt.Errorf("no actions found in transaction") } - zap.L().Debug("successfully transformed linear task") - return activity, nil } @@ -171,11 +162,6 @@ func (w *worker) buildTransferAction(event *Event) (*activityx.Action, error) { data := event.Data[0] - zap.L().Debug("building transfer action", - zap.String("old_owner", data.OldOwnerID), - zap.String("new_owner", data.NewOwnerID), - zap.String("amount", data.Amount)) - amount, ok := new(big.Int).SetString(data.Amount, 10) if !ok { return nil, fmt.Errorf("invalid amount: %s", data.Amount) @@ -189,28 +175,22 @@ func (w *worker) buildTransferAction(event *Event) (*activityx.Action, error) { Name: "LNR", Symbol: "LNR", Decimals: 18, - Value: lo.ToPtr(decimal.NewFromBigInt(amount, 0)), + Value: lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(amount), 0)), Standard: getTokenStandard(event.Standard), Address: lo.ToPtr(event.TokenAddress), }, } - zap.L().Debug("successfully built transfer action") - return action, nil } func (w *worker) buildSwapAction(signerID string, event1, event2 *Event) (*activityx.Action, error) { - zap.L().Debug("building swap action", - zap.String("signer_id", signerID)) - var fromToken, toToken metadata.Token var toAddress string for _, event := range []*Event{event1, event2} { if len(event.Data) == 0 { - zap.L().Warn("empty event data, skipping") continue } @@ -222,7 +202,7 @@ func (w *worker) buildSwapAction(signerID string, event1, event2 *Event) (*activ } token := metadata.Token{ - Value: lo.ToPtr(decimal.NewFromBigInt(amount, 0)), + Value: lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(amount), 0)), Standard: getTokenStandard(event.Standard), Address: lo.ToPtr(event.TokenAddress), } @@ -230,16 +210,8 @@ func (w *worker) buildSwapAction(signerID string, event1, event2 *Event) (*activ if data.OldOwnerID == signerID { fromToken = token toAddress = data.NewOwnerID - - zap.L().Debug("found from token", - zap.String("old_owner", data.OldOwnerID), - zap.String("amount", data.Amount)) } else if data.NewOwnerID == signerID { toToken = token - - zap.L().Debug("found to token", - zap.String("new_owner", data.NewOwnerID), - zap.String("amount", data.Amount)) } } @@ -254,8 +226,6 @@ func (w *worker) buildSwapAction(signerID string, event1, event2 *Event) (*activ }, } - zap.L().Debug("successfully built swap action") - return action, nil } diff --git a/internal/engine/worker/decentralized/contract/looksrare/worker.go b/internal/engine/worker/decentralized/contract/looksrare/worker.go index 7e9d91de8..cac3784d6 100644 --- a/internal/engine/worker/decentralized/contract/looksrare/worker.go +++ b/internal/engine/worker/decentralized/contract/looksrare/worker.go @@ -9,6 +9,7 @@ import ( "github.com/rss3-network/node/config" "github.com/rss3-network/node/internal/engine" source "github.com/rss3-network/node/internal/engine/protocol/ethereum" + "github.com/rss3-network/node/internal/utils" "github.com/rss3-network/node/provider/ethereum" "github.com/rss3-network/node/provider/ethereum/contract" "github.com/rss3-network/node/provider/ethereum/contract/erc20" @@ -24,7 +25,6 @@ import ( "github.com/rss3-network/protocol-go/schema/typex" "github.com/samber/lo" "github.com/shopspring/decimal" - "go.uber.org/zap" ) // Worker is the worker for OpenSea. @@ -97,8 +97,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, fmt.Errorf("invalid task type: %T", task) } - zap.L().Debug("transforming looksrare task", zap.String("task_id", ethereumTask.ID())) - // Build default looksrare activity from task. activity, err := ethereumTask.BuildActivity(activityx.WithActivityPlatform(w.Platform())) if err != nil { @@ -109,8 +107,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac for _, log := range ethereumTask.Receipt.Logs { // Ignore anonymous logs. if len(log.Topics) == 0 { - zap.L().Debug("skipping anonymous log") - continue } @@ -119,44 +115,23 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac err error ) - zap.L().Debug("processing ethereum log", - zap.String("address", log.Address.String()), - zap.String("topic", log.Topics[0].String()), - ) - // Match looksrare core contract events switch { case w.matchExchangeAskMatched(ethereumTask, log): - zap.L().Debug("matched exchange ask event") - actions, err = w.transformExchangeAsk(ctx, ethereumTask, log) case w.matchExchangeBidMatched(ethereumTask, log): - zap.L().Debug("matched exchange bid event") - actions, err = w.transformExchangeBid(ctx, ethereumTask, log) case w.matchExchangeRoyaltyPaymentMatched(ethereumTask, log): - zap.L().Debug("matched exchange royalty payment event") - actions, err = w.transformExchangeRoyaltyPayment(ctx, ethereumTask, log) case w.matchRoyaltyTransferMatched(ethereumTask, log): - zap.L().Debug("matched royalty transfer event") - actions, err = w.transformRoyaltyTransfer(ctx, ethereumTask, log) case w.matchExchangeV2AskMatched(ethereumTask, log): - zap.L().Debug("matched exchange v2 ask event") - actions, err = w.transformExchangeV2Ask(ctx, ethereumTask, log) case w.matchExchangeV2BidMatched(ethereumTask, log): - zap.L().Debug("matched exchange v2 bid event") - actions, err = w.transformExchangeV2Bid(ctx, ethereumTask, log) case w.matchAggregatedBidMatched(ethereumTask, log): - zap.L().Debug("matched aggregated bid event") - actions, err = w.transformV2AggregatedBid(ctx, ethereumTask, log) default: - zap.L().Debug("no matching event found for log") - continue } @@ -168,8 +143,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac activity.Actions = append(activity.Actions, actions...) } - zap.L().Info("successfully transformed looksrare task") - return activity, nil } @@ -454,20 +427,12 @@ func (w *worker) transformV2AggregatedBid(ctx context.Context, task *source.Task // buildEthereumCollectibleTradeAction builds collectible trade action. func (w *worker) buildCollectibleTradeAction(ctx context.Context, task *source.Task, maker, taker, nft common.Address, action metadata.CollectibleTradeAction, nftID, nftValue, offerValue *big.Int, currency *common.Address) (*activityx.Action, error) { - zap.L().Debug("building collectible trade action", - zap.String("maker", maker.String()), - zap.String("taker", taker.String()), - zap.String("nft", nft.String()), - zap.String("action", action.String()), - zap.String("nft_id", nftID.String()), - zap.String("nft_value", nftValue.String())) - tokenMetadata, err := w.tokenClient.Lookup(ctx, task.ChainID, &nft, nftID, task.Header.Number) if err != nil { return nil, fmt.Errorf("lookup token metadata: %w", err) } - tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(nftValue, 0)) + tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(nftValue), 0)) tradeToken := metadata.CollectibleTrade{ Action: action, @@ -475,8 +440,6 @@ func (w *worker) buildCollectibleTradeAction(ctx context.Context, task *source.T } if currency.String() == "0x0000000000000000000000000000000000000000" { - zap.L().Debug("currency address is zero, setting to nil") - currency = nil } @@ -486,7 +449,7 @@ func (w *worker) buildCollectibleTradeAction(ctx context.Context, task *source.T return nil, fmt.Errorf("lookup token metadata: %w", err) } - offerTokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(offerValue, 0)) + offerTokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(offerValue), 0)) tradeToken.Cost = offerTokenMetadata } @@ -499,8 +462,6 @@ func (w *worker) buildCollectibleTradeAction(ctx context.Context, task *source.T to = taker.String() } - zap.L().Debug("successfully built collectible trade action") - return &activityx.Action{ Type: typex.CollectibleTrade, Platform: w.Platform(), @@ -512,11 +473,6 @@ func (w *worker) buildCollectibleTradeAction(ctx context.Context, task *source.T // buildRoyaltyPaymentAction builds royalty payment action. func (w *worker) buildRoyaltyPaymentAction(ctx context.Context, task *source.Task, currency common.Address, amount *big.Int, receipt common.Address) (*activityx.Action, error) { - zap.L().Debug("building royalty payment action", - zap.String("currency", currency.String()), - zap.String("amount", amount.String()), - zap.String("receipt", receipt.String())) - tokenMetadata, err := w.tokenClient.Lookup(ctx, task.ChainID, ¤cy, nil, task.Header.Number) if err != nil { return nil, fmt.Errorf("lookup token metadata: %w", err) @@ -526,15 +482,11 @@ func (w *worker) buildRoyaltyPaymentAction(ctx context.Context, task *source.Tas for _, log := range task.Receipt.Logs { if len(log.Topics) == 0 { - zap.L().Debug("skipping log with no topics") - continue } switch { case w.matchExchangeAskMatched(task, log): - zap.L().Debug("matched exchange ask event") - event, err := w.exchangeFilterer.ParseTakerAsk(log.Export()) if err != nil { return nil, fmt.Errorf("parse taker ask event: %w", err) @@ -542,8 +494,6 @@ func (w *worker) buildRoyaltyPaymentAction(ctx context.Context, task *source.Tas from = event.Maker case w.matchExchangeBidMatched(task, log): // Deposit and withdraw ETH - zap.L().Debug("matched exchange bid event") - event, err := w.exchangeFilterer.ParseTakerBid(log.Export()) if err != nil { return nil, fmt.Errorf("parse taker bid event: %w", err) @@ -551,15 +501,11 @@ func (w *worker) buildRoyaltyPaymentAction(ctx context.Context, task *source.Tas from = event.Maker default: - zap.L().Debug("no matching event found for log") - continue } } - tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(amount, 0)) - - zap.L().Debug("successfully built royalty payment action") + tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(amount), 0)) return &activityx.Action{ Type: typex.TransactionTransfer, @@ -572,10 +518,6 @@ func (w *worker) buildRoyaltyPaymentAction(ctx context.Context, task *source.Tas // buildRoyaltyTransferAction builds royalty transfer action. func (w *worker) buildRoyaltyTransferAction(ctx context.Context, task *source.Task, to common.Address, wad *big.Int) (*activityx.Action, error) { - zap.L().Debug("building royalty transfer action", - zap.String("to", to.String()), - zap.String("wad", wad.String())) - tokenMetadata, err := w.tokenClient.Lookup(ctx, task.ChainID, &weth.AddressMainnet, nil, task.Header.Number) if err != nil { return nil, fmt.Errorf("lookup token metadata: %w", err) @@ -585,15 +527,11 @@ func (w *worker) buildRoyaltyTransferAction(ctx context.Context, task *source.Ta for _, log := range task.Receipt.Logs { if len(log.Topics) == 0 { - zap.L().Debug("skipping log with no topics") - continue } switch { case w.matchExchangeAskMatched(task, log): - zap.L().Debug("matched exchange ask event") - event, err := w.exchangeFilterer.ParseTakerAsk(log.Export()) if err != nil { return nil, fmt.Errorf("parse taker ask event: %w", err) @@ -601,8 +539,6 @@ func (w *worker) buildRoyaltyTransferAction(ctx context.Context, task *source.Ta from = event.Maker case w.matchExchangeBidMatched(task, log): // Deposit and withdraw ETH - zap.L().Debug("matched exchange bid event") - event, err := w.exchangeFilterer.ParseTakerBid(log.Export()) if err != nil { return nil, fmt.Errorf("parse taker bid event: %w", err) @@ -610,15 +546,11 @@ func (w *worker) buildRoyaltyTransferAction(ctx context.Context, task *source.Ta from = event.Maker default: - zap.L().Debug("no matching event found for log") - continue } } - tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(wad, 0)) - - zap.L().Debug("successfully built royalty transfer action") + tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(wad), 0)) return &activityx.Action{ Type: typex.TransactionTransfer, @@ -631,14 +563,7 @@ func (w *worker) buildRoyaltyTransferAction(ctx context.Context, task *source.Ta // buildV2RoyaltyFeeAction builds royalty fee action. func (w *worker) buildV2RoyaltyFeeAction(ctx context.Context, task *source.Task, from common.Address, to common.Address, amount *big.Int, currency *common.Address) (*activityx.Action, error) { - zap.L().Debug("building v2 royalty fee action", - zap.String("from", from.String()), - zap.String("to", to.String()), - zap.String("amount", amount.String())) - if currency.String() == "0x0000000000000000000000000000000000000000" { - zap.L().Debug("currency address is zero, setting to nil") - currency = nil } @@ -647,9 +572,7 @@ func (w *worker) buildV2RoyaltyFeeAction(ctx context.Context, task *source.Task, return nil, fmt.Errorf("lookup token metadata: %w", err) } - tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(amount, 0)) - - zap.L().Debug("successfully built v2 royalty fee action") + tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(amount), 0)) return &activityx.Action{ Type: typex.TransactionTransfer, diff --git a/internal/engine/worker/decentralized/contract/matters/worker.go b/internal/engine/worker/decentralized/contract/matters/worker.go index acae3156a..4474d2645 100644 --- a/internal/engine/worker/decentralized/contract/matters/worker.go +++ b/internal/engine/worker/decentralized/contract/matters/worker.go @@ -13,6 +13,7 @@ import ( "github.com/rss3-network/node/config" "github.com/rss3-network/node/internal/engine" source "github.com/rss3-network/node/internal/engine/protocol/ethereum" + "github.com/rss3-network/node/internal/utils" "github.com/rss3-network/node/provider/ethereum" "github.com/rss3-network/node/provider/ethereum/contract" "github.com/rss3-network/node/provider/ethereum/contract/matters" @@ -91,8 +92,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, fmt.Errorf("invalid task type: %T", task) } - zap.L().Debug("transforming matters task", zap.String("task_id", ethereumTask.ID())) - // Build the activity. activity, err := task.BuildActivity(activityx.WithActivityPlatform(w.Platform())) if err != nil { @@ -102,8 +101,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac for _, log := range ethereumTask.Receipt.Logs { // Ignore anonymous logs. if len(log.Topics) == 0 { - zap.L().Debug("skipping anonymous log") - continue } @@ -112,23 +109,15 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac err error ) - zap.L().Debug("processing ethereum log", - zap.String("address", log.Address.String()), - zap.String("topic", log.Topics[0].String())) - switch { case w.matchEthereumCurationTransaction(log): - zap.L().Debug("matched ethereum curation transaction") - actions, err = w.handleEthereumCurationTransaction(ctx, *ethereumTask, *log, activity) default: - zap.L().Debug("no matching event found for log") - continue } if err != nil { - zap.L().Warn("handle ethereum log", zap.Error(err), zap.String("task", task.ID())) + zap.L().Error("handle ethereum log", zap.Error(err), zap.String("task", task.ID())) return nil, err } @@ -139,8 +128,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac activity.TotalActions = uint(len(activity.Actions)) activity.Tag = tag.Social - zap.L().Debug("successfully transformed matters task") - return activity, nil } @@ -168,8 +155,6 @@ func (w *worker) handleEthereumCurationTransaction(ctx context.Context, task sou } func (w *worker) fetchArticle(ctx context.Context, uri string) (*readability.Article, error) { - zap.L().Debug("fetching article", zap.String("uri", uri)) - _, path, err := ipfs.ParseURL(uri) var ( @@ -182,15 +167,11 @@ func (w *worker) fetchArticle(ctx context.Context, uri string) (*readability.Art return nil, fmt.Errorf("parse IPFS URL: %w", err) } - zap.L().Debug("fetching from IPFS", zap.String("path", path)) - readCloser, err = w.ipfsClient.Fetch(ctx, path, ipfs.FetchModeQuick) if err != nil { return nil, fmt.Errorf("quick fetch %s: %w", path, err) } default: - zap.L().Debug("fetching from HTTP", zap.String("uri", uri)) - readCloser, err = w.httpClient.Fetch(ctx, uri) if err != nil { return nil, fmt.Errorf("fetch metadata from HTTP %s: %w", uri, err) @@ -202,7 +183,6 @@ func (w *worker) fetchArticle(ctx context.Context, uri string) (*readability.Art return nil, fmt.Errorf("parse html: %w", err) } - zap.L().Debug("removing unused HTML tags") w.removeUnusedHTMLTags(node) article, err := w.readabilityParser.ParseDocument(node, nil) @@ -218,8 +198,6 @@ func (w *worker) fetchArticle(ctx context.Context, uri string) (*readability.Art article.Byline = w.filterName(article.Byline) - zap.L().Debug("successfully fetched and parsed article") - return &article, nil } @@ -248,15 +226,7 @@ func (w *worker) removeUnusedHTMLTags(node *html.Node) { } func (w *worker) buildEthereumCurationAction(ctx context.Context, task source.Task, trigger, recipient, token common.Address, amount *big.Int, uri string) (*activityx.Action, error) { - zap.L().Debug("building ethereum curation action", - zap.String("trigger", trigger.String()), - zap.String("recipient", recipient.String()), - zap.String("token", token.String()), - zap.Any("amount", amount), - zap.String("uri", uri)) - article, err := w.fetchArticle(ctx, uri) - if err != nil || article == nil { return nil, fmt.Errorf("fetch article: %w", err) } @@ -266,9 +236,7 @@ func (w *worker) buildEthereumCurationAction(ctx context.Context, task source.Ta return nil, fmt.Errorf("lookup token metadata %s: %w", "", err) } - rewardTokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(amount, 0)) - - zap.L().Debug("successfully built ethereum curation action") + rewardTokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(amount), 0)) return &activityx.Action{ Type: typex.SocialReward, diff --git a/internal/engine/worker/decentralized/contract/mirror/worker.go b/internal/engine/worker/decentralized/contract/mirror/worker.go index 30635315d..ae6564086 100644 --- a/internal/engine/worker/decentralized/contract/mirror/worker.go +++ b/internal/engine/worker/decentralized/contract/mirror/worker.go @@ -75,8 +75,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, fmt.Errorf("invalid task type: %T", task) } - zap.L().Debug("transforming mirror task", zap.String("task_id", arweaveTask.ID())) - // Build the activity. activity, err := task.BuildActivity(activityx.WithActivityPlatform(w.Platform())) if err != nil { @@ -97,8 +95,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac activity.Actions = append(activity.Actions, actions...) } - zap.L().Debug("successfully transformed mirror task") - return activity, nil } @@ -110,8 +106,6 @@ func (w *worker) transformMirrorAction(ctx context.Context, task *source.Task) ( emptyOriginDigest bool ) - zap.L().Debug("transforming mirror action", zap.String("transaction_id", task.Transaction.ID)) - for _, tag := range task.Transaction.Tags { tagName, err := arweave.Base64Decode(tag.Name) if err != nil { @@ -126,22 +120,18 @@ func (w *worker) transformMirrorAction(ctx context.Context, task *source.Task) ( switch string(tagName) { case "Content-Digest": contentDigest = string(tagValue) - zap.L().Debug("found content digest", zap.String("digest", contentDigest)) + case "Original-Content-Digest": originContentDigest = string(tagValue) - zap.L().Debug("found original content digest", zap.String("digest", originContentDigest)) if len(string(tagValue)) == 0 { emptyOriginDigest = true - - zap.L().Debug("original content digest is empty") } } } // Construct content URI from tx id contentURI := fmt.Sprintf("ar://%s", task.Transaction.ID) - zap.L().Debug("constructed content URI", zap.String("uri", contentURI)) // Get detailed post info from transaction data transactionData, err := arweave.Base64Decode(task.Transaction.Data) @@ -152,15 +142,12 @@ func (w *worker) transformMirrorAction(ctx context.Context, task *source.Task) ( mirrorData := gjson.ParseBytes(transactionData) author := mirrorData.Get("authorship.contributor").String() - zap.L().Debug("found post author", zap.String("author", author)) var media []metadata.Media // Get mirror nft as media address := mirrorData.Get("wnft.imageURI").String() if address != "" { - zap.L().Debug("fetching NFT image", zap.String("address", address)) - file, err := w.ipfsClient.Fetch(ctx, fmt.Sprintf("/ipfs/%s", address), ipfs.FetchModeQuick) if err != nil { return nil, fmt.Errorf("fetch ipfs: %w", err) @@ -182,23 +169,18 @@ func (w *worker) transformMirrorAction(ctx context.Context, task *source.Task) ( Address: fmt.Sprintf("ipfs://%s", address), MimeType: result.String(), }) - - zap.L().Debug("added NFT media", zap.String("mimetype", result.String())) } var publicationID string if contentDigest == "" { publicationID = mirrorData.Get("digest").String() - zap.L().Debug("using digest as publication ID", zap.String("publication_id", publicationID)) } else { publicationID = contentDigest - zap.L().Debug("using content digest as publication ID", zap.String("publication_id", publicationID)) } if originContentDigest != "" { publicationID = originContentDigest - zap.L().Debug("using original content digest as publication ID", zap.String("publication_id", publicationID)) } // Construct mirror Metadata @@ -210,7 +192,6 @@ func (w *worker) transformMirrorAction(ctx context.Context, task *source.Task) ( Media: media, Timestamp: mirrorData.Get("content.timestamp").Uint(), } - zap.L().Debug("constructed mirror metadata", zap.String("title", mirrorMetadata.Title)) // Build the post or revise action action, err := w.buildMirrorAction(ctx, task.Transaction.ID, author, mirror.AddressMirror, mirrorMetadata, emptyOriginDigest, originContentDigest) @@ -234,46 +215,28 @@ func (w *worker) transformMirrorAction(ctx context.Context, task *source.Task) ( action, } - zap.L().Debug("successfully transformed mirror action") - return actions, nil } // buildArweaveTransactionTransferAction Returns the native transfer transaction action. func (w *worker) buildMirrorAction(ctx context.Context, txID, from, to string, mirrorMetadata *metadata.SocialPost, emptyOriginDigest bool, originContentDigest string) (*activityx.Action, error) { - zap.L().Debug("building mirror action", - zap.String("transaction_id", txID), - zap.String("from", from), - zap.String("to", to), - zap.Any("metadata", mirrorMetadata), - zap.Bool("empty_origin_digest", emptyOriginDigest), - zap.String("origin_content_digest", originContentDigest)) - // Default action type is post. filterType := typex.SocialPost // if the origin digest is empty, the action type should be revise. if emptyOriginDigest { - zap.L().Debug("empty origin digest detected, setting action type to revise") - filterType = typex.SocialRevise } // If the origin digest is not empty, check if the origin digest is the first mirror post. if originContentDigest != "" { - zap.L().Debug("loading dataset mirror post", zap.String("origin_content_digest", originContentDigest)) - post, err := w.databaseClient.LoadDatasetMirrorPost(ctx, originContentDigest) if err != nil { return nil, fmt.Errorf("load dataset mirror post: %w", err) } if post != nil && txID != post.TransactionID { - zap.L().Debug("post exists with different transaction ID, setting action type to revise", - zap.String("post_transaction_id", post.TransactionID), - zap.String("current_transaction_id", txID)) - filterType = typex.SocialRevise } } @@ -288,8 +251,6 @@ func (w *worker) buildMirrorAction(ctx context.Context, txID, from, to string, m Metadata: mirrorMetadata, } - zap.L().Debug("successfully built mirror action") - return &action, nil } diff --git a/internal/engine/worker/decentralized/contract/momoka/worker.go b/internal/engine/worker/decentralized/contract/momoka/worker.go index f883b01a1..925ffd848 100644 --- a/internal/engine/worker/decentralized/contract/momoka/worker.go +++ b/internal/engine/worker/decentralized/contract/momoka/worker.go @@ -91,8 +91,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, fmt.Errorf("invalid task type: %T", task) } - zap.L().Debug("transforming momoka task", zap.String("task_id", arweaveTask.ID())) - // Build the activity. activity, err := task.BuildActivity(activityx.WithActivityPlatform(w.Platform())) if err != nil { @@ -113,15 +111,11 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac activity.Actions = append(activity.Actions, actions...) } - zap.L().Debug("successfully transformed momoka task") - return activity, nil } // transformPostOrReviseAction Returns the actions of mirror post or revise. func (w *worker) transformMomokaAction(ctx context.Context, task *source.Task) ([]*activityx.Action, error) { - zap.L().Debug("start transforming momoka action", zap.String("transaction_id", task.Transaction.ID)) - data, err := base64.RawURLEncoding.DecodeString(task.Transaction.Data) if err != nil { return nil, fmt.Errorf("decode transaction data: %w", err) @@ -130,25 +124,17 @@ func (w *worker) transformMomokaAction(ctx context.Context, task *source.Task) ( transactionData := gjson.ParseBytes(data) rawPublicationID := transactionData.Get("publicationId").String() - zap.L().Debug("got publication id", zap.String("publication_id", rawPublicationID)) timestamp := transactionData.Get("event.timestamp").Uint() - zap.L().Debug("got timestamp", zap.Uint64("timestamp", timestamp)) // Polygon block number blockNumber := transactionData.Get("chainProofs.thisPublication.blockNumber").Uint() - zap.L().Debug("got block number", zap.Uint64("block_number", blockNumber)) contentURI, rawProfileID, rawProfileIDPointed, socialType := w.parseTransactionDataByType(transactionData) - zap.L().Debug("parsed transaction data", - zap.String("content_uri", contentURI), - zap.String("profile_id", rawProfileID), - zap.String("profile_id_pointed", rawProfileIDPointed), - zap.String("social_type", socialType.String())) // Discard unsupported transaction type if rawProfileID == "" || rawPublicationID == "" { - zap.L().Warn("missing required fields", + zap.L().Error("missing required fields", zap.String("profile_id", rawProfileID), zap.String("publication_id", rawPublicationID)) @@ -159,18 +145,14 @@ func (w *worker) transformMomokaAction(ctx context.Context, task *source.Task) ( var profileIDInt *big.Int - if rawProfileID != "" { - profileIDInt, err = hexutil.DecodeBig(strings.Replace(rawProfileID, "0x0", "0x", 1)) - if err != nil { - return nil, fmt.Errorf("decode profile id: %w", err) - } - - profile, err = w.getLensHandle(ctx, new(big.Int).SetUint64(blockNumber), profileIDInt) - if err != nil { - return nil, fmt.Errorf("get lens handle: %w", err) - } + profileIDInt, err = hexutil.DecodeBig(strings.Replace(rawProfileID, "0x0", "0x", 1)) + if err != nil { + return nil, fmt.Errorf("decode profile id: %w", err) + } - zap.L().Debug("got lens handle", zap.String("profile", profile)) + profile, err = w.getLensHandle(ctx, new(big.Int).SetUint64(blockNumber), profileIDInt) + if err != nil { + return nil, fmt.Errorf("get lens handle: %w", err) } momokaMetadata, err := w.buildArweaveMomokaPostMetadata(ctx, rawProfileID, profile, rawPublicationID, contentURI, false, timestamp) @@ -189,12 +171,8 @@ func (w *worker) transformMomokaAction(ctx context.Context, task *source.Task) ( return nil, fmt.Errorf("get lens handle: %w", err) } - zap.L().Debug("got pointed lens handle", zap.String("profile_pointed", profilePointed)) - location := transactionData.Get("chainProofs.pointer.location").String() - zap.L().Debug("got chain proofs location", zap.String("location", location)) - body, err := w.getDataFromHTTP(ctx, location) if err != nil { return nil, fmt.Errorf("get publication from ipfs: %w", err) @@ -222,10 +200,7 @@ func (w *worker) transformMomokaAction(ctx context.Context, task *source.Task) ( targetContentURI = targetData.Get("event.contentURI").String() } - zap.L().Debug("got target content uri", zap.String("target_content_uri", targetContentURI)) - targetPublicationID := targetData.Get("publicationId").String() - zap.L().Debug("got target publication id", zap.String("target_publication_id", targetPublicationID)) momokaMetadata.Target, err = w.buildArweaveMomokaPostMetadata(ctx, rawProfileIDPointed, profilePointed, targetPublicationID, targetContentURI, true, timestamp) if err != nil { @@ -238,21 +213,15 @@ func (w *worker) transformMomokaAction(ctx context.Context, task *source.Task) ( return nil, fmt.Errorf("get lens owner of: %w", err) } - zap.L().Debug("got lens owner", zap.String("owner", from.String())) - activityFrom, err := arweave.PublicKeyToAddress(task.Transaction.Owner) if err != nil { return nil, fmt.Errorf("public key to address: %w", err) } - zap.L().Debug("got activity from address", zap.String("activity_from", activityFrom)) - actions := []*activityx.Action{ w.buildArweaveMomokaAction(ctx, from.String(), activityFrom, socialType, momokaMetadata), } - zap.L().Debug("successfully transformed momoka action") - return actions, nil } @@ -316,20 +285,11 @@ func (w *worker) buildArweaveMomokaAction(_ context.Context, from, to string, so } func (w *worker) buildArweaveMomokaPostMetadata(ctx context.Context, profileID, handle, pubID string, contentURI string, isTarget bool, timestamp uint64) (*metadata.SocialPost, error) { - zap.L().Debug("building arweave momoka post metadata", - zap.String("profile_id", profileID), - zap.String("handle", handle), - zap.String("pub_id", pubID), - zap.String("content_uri", contentURI), - zap.Bool("is_target", isTarget)) - var contentData []byte if contentURI != "" { var err error - zap.L().Debug("fetching content from HTTP", zap.String("content_uri", contentURI)) - body, err := w.getDataFromHTTP(ctx, contentURI) if err != nil { return nil, fmt.Errorf("get publication from ipfs: %w", err) @@ -340,8 +300,6 @@ func (w *worker) buildArweaveMomokaPostMetadata(ctx context.Context, profileID, if err != nil { return nil, fmt.Errorf("read all: %w", err) } - - zap.L().Debug("successfully fetched content data", zap.Int("bytes", len(contentData))) } momokaData := gjson.ParseBytes(contentData) @@ -353,8 +311,6 @@ func (w *worker) buildArweaveMomokaPostMetadata(ctx context.Context, profileID, var content string if momokaData.Get("lens").Exists() { - zap.L().Debug("parsing lens format content") - content = momokaData.Get("lens.content").String() momokaImages := lo.Map(momokaData.Get("lens.image").Array(), func(media gjson.Result, _ int) metadata.Media { @@ -388,13 +344,7 @@ func (w *worker) buildArweaveMomokaPostMetadata(ctx context.Context, profileID, momokaTags = lo.Map(momokaData.Get("lens.tags").Array(), func(tag gjson.Result, _ int) string { return tag.String() }) - - zap.L().Debug("parsed lens content", - zap.Int("media_count", len(momokaMedia)), - zap.Int("tags_count", len(momokaTags))) } else { - zap.L().Debug("parsing standard format content") - content = momokaData.Get("content").String() momokaMedia = lo.Map(momokaData.Get("media").Array(), func(media gjson.Result, _ int) metadata.Media { @@ -407,14 +357,8 @@ func (w *worker) buildArweaveMomokaPostMetadata(ctx context.Context, profileID, momokaTags = lo.Map(momokaData.Get("tags").Array(), func(tag gjson.Result, _ int) string { return tag.String() }) - - zap.L().Debug("parsed standard content", - zap.Int("media_count", len(momokaMedia)), - zap.Int("tags_count", len(momokaTags))) } - zap.L().Debug("building social post metadata") - return &metadata.SocialPost{ Handle: handle, Title: momokaData.Get("name").String(), diff --git a/internal/engine/worker/decentralized/contract/nearsocial/worker.go b/internal/engine/worker/decentralized/contract/nearsocial/worker.go index 33229be07..f9d435487 100644 --- a/internal/engine/worker/decentralized/contract/nearsocial/worker.go +++ b/internal/engine/worker/decentralized/contract/nearsocial/worker.go @@ -18,7 +18,6 @@ import ( "github.com/rss3-network/protocol-go/schema/network" "github.com/rss3-network/protocol-go/schema/tag" "github.com/rss3-network/protocol-go/schema/typex" - "go.uber.org/zap" ) var _ engine.Worker = (*worker)(nil) @@ -76,8 +75,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, fmt.Errorf("invalid task type: %T", task) } - zap.L().Debug("transforming near social task", zap.String("task_id", nearTask.ID())) - // Build the activity with the platform information. activity, err := task.BuildActivity(activityx.WithActivityPlatform(w.Platform())) if err != nil { @@ -97,8 +94,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, fmt.Errorf("no action found in transaction") } - zap.L().Debug("successfully transformed near social task") - return activity, nil } @@ -152,12 +147,6 @@ func (w *worker) processSetFunction(signerID string, functionCall *near.Function // buildSocialAction constructs an activityx.Action based on the provided social action data. // This function is crucial for creating the appropriate action type (post, comment, or share) and populating its metadata. func (w *worker) buildSocialAction(signerID, path string, postData PostData, args FunctionCallArgs, timestamp uint64) (*activityx.Action, error) { - zap.L().Debug("building social action", - zap.String("signer_id", signerID), - zap.String("path", path), - zap.Any("post_data", postData), - zap.Any("args", args)) - action := &activityx.Action{ Type: typex.SocialPost, Platform: w.Platform(), @@ -178,8 +167,6 @@ func (w *worker) buildSocialAction(signerID, path string, postData PostData, arg action = w.processUserContent(action, userContent, signerID, timestamp) } - zap.L().Debug("successfully built social action") - return action, nil } diff --git a/internal/engine/worker/decentralized/contract/nouns/worker.go b/internal/engine/worker/decentralized/contract/nouns/worker.go index 7691e56bc..d34666091 100644 --- a/internal/engine/worker/decentralized/contract/nouns/worker.go +++ b/internal/engine/worker/decentralized/contract/nouns/worker.go @@ -9,6 +9,7 @@ import ( "github.com/rss3-network/node/config" "github.com/rss3-network/node/internal/engine" source "github.com/rss3-network/node/internal/engine/protocol/ethereum" + "github.com/rss3-network/node/internal/utils" "github.com/rss3-network/node/provider/ethereum" "github.com/rss3-network/node/provider/ethereum/contract" "github.com/rss3-network/node/provider/ethereum/contract/nouns" @@ -22,7 +23,6 @@ import ( "github.com/rss3-network/protocol-go/schema/typex" "github.com/samber/lo" "github.com/shopspring/decimal" - "go.uber.org/zap" ) var _ engine.Worker = (*worker)(nil) @@ -85,8 +85,6 @@ func (w *worker) Filter() engine.DataSourceFilter { } func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Activity, error) { - zap.L().Debug("transforming nouns task", zap.String("task_id", task.ID())) - ethereumTask, ok := task.(*source.Task) if !ok { return nil, fmt.Errorf("invalid task type: %T", task) @@ -99,8 +97,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac for _, log := range ethereumTask.Receipt.Logs { if len(log.Topics) == 0 { - zap.L().Debug("ignoring anonymous log") - continue } @@ -109,43 +105,26 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac err error ) - zap.L().Debug("matching nouns event", - zap.String("address", log.Address.String()), - zap.String("topic", log.Topics[0].String())) - switch { case w.matchNounsAuctionBid(log): - zap.L().Debug("matched nouns auction bid event") - actions, err = w.handleNounsAuctionBid(ctx, ethereumTask, log) activity.Type = typex.CollectibleAuction case w.matchNounsAuctionSettled(log): - zap.L().Debug("matched nouns auction settled event") - actions, err = w.handleNounsAuctionSettled(ctx, ethereumTask, log) activity.Type = typex.CollectibleAuction case w.matchNounsAuctionCreated(log): - zap.L().Debug("matched nouns auction created event") - actions, err = w.handleNounsAuctionCreated(ctx, ethereumTask, log) activity.Type = typex.CollectibleAuction case w.matchNounCreated(log): - zap.L().Debug("matched noun created event") - actions, err = w.handleNounCreated(ctx, ethereumTask, log) activity.Type = typex.CollectibleMint case w.matchNounsProposal(log): - zap.L().Debug("matched nouns proposal event") - actions, err = w.handleNounsProposal(ctx, ethereumTask, log) activity.Type = typex.GovernanceProposal case w.matchNounsVote(log): - zap.L().Debug("matched nouns vote event") - actions, err = w.handleNounsVote(ctx, ethereumTask, log) activity.Type = typex.GovernanceVote default: - zap.L().Debug("no matching nouns event") continue } @@ -156,8 +135,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac activity.Actions = append(activity.Actions, actions...) } - zap.L().Debug("successfully transformed nouns task") - return activity, nil } @@ -229,20 +206,12 @@ func (w *worker) handleNounsAuctionCreated(ctx context.Context, task *source.Tas } func (w *worker) buildCollectibleAuctionAction(ctx context.Context, task *source.Task, sender, receiver common.Address, action metadata.CollectibleAuctionAction, nftID, nftValue, offerValue *big.Int) (*activityx.Action, error) { - zap.L().Debug("building collectible auction action", - zap.String("sender", sender.String()), - zap.String("receiver", receiver.String()), - zap.String("action", action.String()), - zap.String("nft_id", nftID.String()), - zap.Any("nft_value", nftValue), - zap.Any("offer_value", offerValue)) - tokenMetadata, err := w.tokenClient.Lookup(ctx, task.ChainID, &(nouns.AddressNouns), nftID, task.Header.Number) if err != nil { return nil, fmt.Errorf("lookup token metadata %s %s: %w", &(nouns.AddressNouns), nftID, err) } - tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(nftValue, 0)) + tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(nftValue), 0)) var offerTokenMetadata *metadata.Token @@ -252,11 +221,9 @@ func (w *worker) buildCollectibleAuctionAction(ctx context.Context, task *source return nil, fmt.Errorf("lookup offer token metadata: %w", err) } - offerTokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(offerValue, 0)) + offerTokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(offerValue), 0)) } - zap.L().Debug("successfully built collectible auction action") - return &activityx.Action{ Type: typex.CollectibleAuction, Platform: w.Platform(), @@ -285,21 +252,12 @@ func (w *worker) handleNounCreated(ctx context.Context, task *source.Task, log * } func (w *worker) buildCollectibleMintAction(ctx context.Context, task *source.Task, from, to, contract common.Address, id, value *big.Int) (*activityx.Action, error) { - zap.L().Debug("building collectible mint action", - zap.String("from", from.String()), - zap.String("to", to.String()), - zap.String("contract", contract.String()), - zap.Any("id", id), - zap.Any("value", value)) - tokenMetadata, err := w.tokenClient.Lookup(ctx, task.ChainID, &contract, id, task.Header.Number) if err != nil { return nil, fmt.Errorf("lookup token metadata %s %s: %w", contract, id, err) } - tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(value, 0)) - - zap.L().Debug("successfully built collectible mint action") + tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(value), 0)) return &activityx.Action{ Type: typex.CollectibleMint, @@ -322,14 +280,6 @@ func (w *worker) handleNounsProposal(_ context.Context, _ *source.Task, log *eth } func (w *worker) buildGovernanceProposalAction(from, to common.Address, id *big.Int, description string, start, end *big.Int) *activityx.Action { - zap.L().Debug("building governance proposal action", - zap.String("from", from.String()), - zap.String("to", to.String()), - zap.Any("id", id), - zap.String("description", description), - zap.Any("start", start), - zap.Any("end", end)) - return &activityx.Action{ Type: typex.GovernanceProposal, Platform: w.Platform(), @@ -343,8 +293,8 @@ func (w *worker) buildGovernanceProposalAction(from, to common.Address, id *big. metadata.ActionGovernanceVoteAgainst.String(), metadata.ActionGovernanceVoteAbstain.String(), }, - StartBlock: decimal.NewFromBigInt(start, 0).String(), - EndBlock: decimal.NewFromBigInt(end, 0).String(), + StartBlock: decimal.NewFromBigInt(utils.GetBigInt(start), 0).String(), + EndBlock: decimal.NewFromBigInt(utils.GetBigInt(end), 0).String(), }, } } @@ -384,14 +334,6 @@ func (w *worker) handleNounsVote(_ context.Context, _ *source.Task, log *ethereu } func (w *worker) buildGovernanceVoteAction(from, to common.Address, proposalID, votes *big.Int, reason string, action metadata.GovernanceVoteAction) *activityx.Action { - zap.L().Debug("building governance vote action", - zap.String("from", from.String()), - zap.String("to", to.String()), - zap.String("proposal_id", proposalID.String()), - zap.Any("votes", votes), - zap.String("reason", reason), - zap.String("action", action.String())) - return &activityx.Action{ Type: typex.GovernanceVote, Platform: w.Platform(), @@ -399,7 +341,7 @@ func (w *worker) buildGovernanceVoteAction(from, to common.Address, proposalID, To: to.String(), Metadata: metadata.GovernanceVote{ Action: action, - Count: uint64(decimal.NewFromBigInt(votes, 0).IntPart()), + Count: uint64(decimal.NewFromBigInt(utils.GetBigInt(votes), 0).IntPart()), Reason: reason, Proposal: metadata.GovernanceProposal{ ID: proposalID.String(), diff --git a/internal/engine/worker/decentralized/contract/opensea/worker.go b/internal/engine/worker/decentralized/contract/opensea/worker.go index 617a372b0..08ac5f1c0 100644 --- a/internal/engine/worker/decentralized/contract/opensea/worker.go +++ b/internal/engine/worker/decentralized/contract/opensea/worker.go @@ -10,6 +10,7 @@ import ( "github.com/rss3-network/node/config" "github.com/rss3-network/node/internal/engine" source "github.com/rss3-network/node/internal/engine/protocol/ethereum" + "github.com/rss3-network/node/internal/utils" "github.com/rss3-network/node/provider/ethereum" "github.com/rss3-network/node/provider/ethereum/contract" "github.com/rss3-network/node/provider/ethereum/contract/erc1155" @@ -26,7 +27,6 @@ import ( "github.com/rss3-network/protocol-go/schema/typex" "github.com/samber/lo" "github.com/shopspring/decimal" - "go.uber.org/zap" ) // Worker is the worker for OpenSea. @@ -92,8 +92,6 @@ func (w *worker) Filter() engine.DataSourceFilter { // Transform Ethereum task to activityx. func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Activity, error) { - zap.L().Debug("transforming opensea task", zap.String("task_id", task.ID())) - ethereumTask, ok := task.(*source.Task) if !ok { return nil, fmt.Errorf("invalid task type: %T", task) @@ -109,7 +107,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac for _, log := range ethereumTask.Receipt.Logs { // Ignore anonymous logs. if len(log.Topics) == 0 { - zap.L().Debug("ignoring anonymous log") continue } @@ -118,33 +115,20 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac err error ) - zap.L().Debug("matching opensea event", - zap.String("address", log.Address.String()), - zap.String("topic", log.Topics[0].String())) - // Match opensea core contract events switch { case w.matchWyvernExchangeV1Orders(ethereumTask, log): - zap.L().Debug("matched wyvern exchange v1 orders event") - actions, err = w.transformWyvernExchangeV1Orders(ctx, ethereumTask, log) case w.matchWyvernExchangeV2Orders(ethereumTask, log): - zap.L().Debug("matched wyvern exchange v2 orders event") - actions, err = w.transformWyvernExchangeV2Orders(ctx, ethereumTask, log) case w.matchSeaportV1OrderFulfilled(ethereumTask, log): - zap.L().Debug("matched seaport v1 order fulfilled event") - actions, err = w.transformSeaportV1OrderFulfilled(ctx, ethereumTask, log) default: - zap.L().Debug("no matching opensea event") - continue } if err != nil { if isInvalidTokenErr(err) { - zap.L().Debug("invalid token error", zap.Error(err)) return activityx.NewUnknownActivity(activity), nil } @@ -159,8 +143,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac activity.Actions = append(activity.Actions, actions...) } - zap.L().Debug("successfully transformed opensea task") - return activity, nil } @@ -327,15 +309,6 @@ func (w *worker) transformSeaportV1OrderFulfilled(ctx context.Context, task *sou } func (w *worker) buildEthereumCollectibleTradeAction(ctx context.Context, task *source.Task, seller, buyer, nft common.Address, nftID, nftValue *big.Int, offerToken *common.Address, offerValue *big.Int) (*activityx.Action, error) { - zap.L().Debug("building collectible trade action", - zap.String("seller", seller.String()), - zap.String("buyer", buyer.String()), - zap.String("nft", nft.String()), - zap.Any("nft_id", nftID), - zap.Any("nft_value", nftValue), - zap.Any("offer_token", offerToken), - zap.Any("offer_value", offerValue)) - if nftID == nil { return nil, fmt.Errorf("nft id is nil") } @@ -348,8 +321,8 @@ func (w *worker) buildEthereumCollectibleTradeAction(ctx context.Context, task * return nil, fmt.Errorf("lookup collectible token metadata: %w", err) } - collectibleTokenMetadata.ID = lo.ToPtr(decimal.NewFromBigInt(nftID, 0)) - collectibleTokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(nftValue, 0)) + collectibleTokenMetadata.ID = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(nftID), 0)) + collectibleTokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(nftValue), 0)) // Get offer token metadata. costTokenMetadata, err := w.tokenClient.Lookup(ctx, task.ChainID, offerToken, nil, task.Header.Number) @@ -357,11 +330,7 @@ func (w *worker) buildEthereumCollectibleTradeAction(ctx context.Context, task * return nil, fmt.Errorf("lookup collectible token metadata: %w", err) } - if offerValue == nil { - offerValue = big.NewInt(0) - } - - costTokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(offerValue, 0)) + costTokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(offerValue), 0)) action := activityx.Action{ Type: typex.CollectibleTrade, @@ -376,8 +345,6 @@ func (w *worker) buildEthereumCollectibleTradeAction(ctx context.Context, task * }, } - zap.L().Debug("successfully built collectible trade action") - return &action, nil } diff --git a/internal/engine/worker/decentralized/contract/optimism/worker.go b/internal/engine/worker/decentralized/contract/optimism/worker.go index f299622e4..8646f836d 100644 --- a/internal/engine/worker/decentralized/contract/optimism/worker.go +++ b/internal/engine/worker/decentralized/contract/optimism/worker.go @@ -9,6 +9,7 @@ import ( "github.com/rss3-network/node/config" "github.com/rss3-network/node/internal/engine" source "github.com/rss3-network/node/internal/engine/protocol/ethereum" + "github.com/rss3-network/node/internal/utils" "github.com/rss3-network/node/provider/ethereum" "github.com/rss3-network/node/provider/ethereum/contract/optimism" "github.com/rss3-network/node/provider/ethereum/token" @@ -84,8 +85,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, fmt.Errorf("invalid task type: %T", task) } - zap.L().Debug("transforming optimism task", zap.String("task_id", ethereumTask.ID())) - activity, err := ethereumTask.BuildActivity(activityx.WithActivityPlatform(w.Platform())) if err != nil { return nil, fmt.Errorf("build activity: %w", err) @@ -99,48 +98,28 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac // Ignore anonymous logs. if len(log.Topics) == 0 { - zap.L().Debug("ignoring anonymous log") - continue } - zap.L().Debug("matching optimism event", - zap.String("address", log.Address.String()), - zap.String("topic", log.Topics[0].String())) - switch { case w.matchL1StandardBridgeETHDepositInitiatedLog(ethereumTask, log): - zap.L().Debug("matched l1 standard bridge eth deposit initiated event") - actions, err = w.transformL1StandardBridgeETHDepositInitiatedLog(ctx, ethereumTask, log) case w.matchL1StandardBridgeERC20DepositInitiatedLog(ethereumTask, log): - zap.L().Debug("matched l1 standard bridge erc20 deposit initiated event") - actions, err = w.transformL1StandardBridgeERC20DepositInitiatedLog(ctx, ethereumTask, log) case w.matchL1StandardBridgeETHWithdrawalFinalizedLog(ethereumTask, log): - zap.L().Debug("matched l1 standard bridge eth withdrawal finalized event") - actions, err = w.transformL1StandardBridgeETHWithdrawalFinalizedLog(ctx, ethereumTask, log) case w.matchL1StandardBridgeERC20WithdrawalFinalizedLog(ethereumTask, log): - zap.L().Debug("matched l1 standard bridge erc20 withdrawal finalized event") - actions, err = w.transformL1StandardBridgeERC20WithdrawalFinalizedLog(ctx, ethereumTask, log) case w.matchL2StandardBridgeWithdrawalInitiatedLog(ethereumTask, log): - zap.L().Debug("matched l2 standard bridge withdrawal initiated event") - actions, err = w.transformL2StandardBridgeWithdrawalInitiatedLog(ctx, ethereumTask, log) case w.matchL2StandardBridgeDepositFinalizedLog(ethereumTask, log): - zap.L().Debug("matched l2 standard bridge deposit finalized event") - actions, err = w.transformL2StandardBridgeDepositFinalizedLog(ctx, ethereumTask, log) default: - zap.L().Warn("unsupported log", zap.String("task", task.ID()), zap.Uint("topic.index", log.Index)) - continue } if err != nil { - zap.L().Warn("handle ethereum log", zap.Error(err), zap.String("task", task.ID())) + zap.L().Error("handle ethereum log", zap.Error(err), zap.String("task", task.ID())) return nil, err } @@ -149,8 +128,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac activity.Actions = append(activity.Actions, actions...) } - zap.L().Debug("successfully transformed optimism task") - return activity, nil } @@ -287,15 +264,6 @@ func (w *worker) transformL2StandardBridgeDepositFinalizedLog(ctx context.Contex } func (w *worker) buildTransactionBridgeAction(ctx context.Context, chainID uint64, sender, receiver common.Address, source, target network.Network, bridgeAction metadata.TransactionBridgeAction, tokenAddress *common.Address, tokenValue *big.Int, blockNumber *big.Int) (*activityx.Action, error) { - zap.L().Debug("building transaction bridge action", - zap.String("sender", sender.String()), - zap.String("receiver", receiver.String()), - zap.String("source", source.String()), - zap.String("target", target.String()), - zap.String("bridge_action", bridgeAction.String()), - zap.Any("token", tokenAddress), - zap.Any("token_value", tokenValue)) - // Ignore L2 ETH token address. if tokenAddress != nil && (*tokenAddress == optimism.AddressL1ETH || *tokenAddress == optimism.AddressL2ETH) { tokenAddress = nil @@ -306,7 +274,7 @@ func (w *worker) buildTransactionBridgeAction(ctx context.Context, chainID uint6 return nil, fmt.Errorf("lookup token %s: %w", tokenAddress, err) } - tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(tokenValue, 0)) + tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(tokenValue), 0)) action := activityx.Action{ Type: typex.TransactionBridge, @@ -321,8 +289,6 @@ func (w *worker) buildTransactionBridgeAction(ctx context.Context, chainID uint6 }, } - zap.L().Debug("successfully built transaction bridge action") - return &action, nil } diff --git a/internal/engine/worker/decentralized/contract/paragraph/worker.go b/internal/engine/worker/decentralized/contract/paragraph/worker.go index 517b672d6..e5ffd61bc 100644 --- a/internal/engine/worker/decentralized/contract/paragraph/worker.go +++ b/internal/engine/worker/decentralized/contract/paragraph/worker.go @@ -21,7 +21,6 @@ import ( "github.com/rss3-network/protocol-go/schema/typex" "github.com/samber/lo" "github.com/tidwall/gjson" - "go.uber.org/zap" ) // make sure worker implements engine.Worker @@ -73,8 +72,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, fmt.Errorf("invalid task type: %T", task) } - zap.L().Debug("transforming paragraph task", zap.String("task_id", arweaveTask.ID())) - // Build the activity. activity, err := task.BuildActivity(activityx.WithActivityPlatform(w.Platform())) if err != nil { @@ -95,8 +92,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac activity.Actions = append(activity.Actions, actions...) } - zap.L().Debug("successfully transformed paragraph task") - return activity, nil } @@ -120,8 +115,6 @@ func (w *worker) transformParagraphAction(ctx context.Context, task *source.Task return nil, err } - zap.L().Debug("tag", zap.String("name", string(tagName)), zap.String("value", string(tagValue))) - switch string(tagName) { case "Contributor": contributor = string(tagValue) @@ -139,8 +132,6 @@ func (w *worker) transformParagraphAction(ctx context.Context, task *source.Task return nil, fmt.Errorf("invalid foramt of transaction data: %w", err) } - zap.L().Debug("transaction data", zap.String("data", string(transactionData))) - paragraphData := gjson.ParseBytes(transactionData) contentURI := fmt.Sprintf("https://arweave.net/%s", task.Transaction.ID) @@ -150,8 +141,6 @@ func (w *worker) transformParagraphAction(ctx context.Context, task *source.Task return nil, fmt.Errorf("build arweave paragraph post metadata failed: %w", err) } - zap.L().Debug("paragraph metadata", zap.Any("metadata", paragraphMetadata)) - var updated bool if paragraphData.Get("arweaveId").Exists() { @@ -174,12 +163,6 @@ func (w *worker) transformParagraphAction(ctx context.Context, task *source.Task // buildArweaveTransactionTransferAction Returns the native transfer transaction action. func (w *worker) buildParagraphAction(_ context.Context, from, to string, paragraphMetadata *metadata.SocialPost, updated bool) *activityx.Action { - zap.L().Debug("building paragraph action", - zap.String("from", from), - zap.String("to", to), - zap.Any("metadata", paragraphMetadata), - zap.Bool("updated", updated)) - // Default action type is post. filterType := typex.SocialPost @@ -199,17 +182,11 @@ func (w *worker) buildParagraphAction(_ context.Context, from, to string, paragr Metadata: paragraphMetadata, } - zap.L().Debug("successfully built paragraph action") - return &action } // buildParagraphMetadata Returns the metadata of the paragraph post. func (w *worker) buildParagraphMetadata(ctx context.Context, handle, contentURI string, contentData []byte) (*metadata.SocialPost, error) { - zap.L().Debug("building paragraph metadata", - zap.String("handle", handle), - zap.String("content_uri", contentURI)) - paragraphData := gjson.ParseBytes(contentData) var media []metadata.Media @@ -259,8 +236,6 @@ func (w *worker) buildParagraphMetadata(ctx context.Context, handle, contentURI profileID = paragraphData.Get("authors").Array()[0].String() } - zap.L().Debug("successfully built paragraph metadata") - return &metadata.SocialPost{ Handle: handle, Title: paragraphData.Get("title").String(), diff --git a/internal/engine/worker/decentralized/contract/paraswap/worker.go b/internal/engine/worker/decentralized/contract/paraswap/worker.go index 91b566839..c8d0d47cb 100644 --- a/internal/engine/worker/decentralized/contract/paraswap/worker.go +++ b/internal/engine/worker/decentralized/contract/paraswap/worker.go @@ -9,6 +9,7 @@ import ( "github.com/rss3-network/node/config" "github.com/rss3-network/node/internal/engine" source "github.com/rss3-network/node/internal/engine/protocol/ethereum" + "github.com/rss3-network/node/internal/utils" "github.com/rss3-network/node/provider/ethereum" "github.com/rss3-network/node/provider/ethereum/contract" "github.com/rss3-network/node/provider/ethereum/contract/paraswap" @@ -22,7 +23,6 @@ import ( "github.com/rss3-network/protocol-go/schema/typex" "github.com/samber/lo" "github.com/shopspring/decimal" - "go.uber.org/zap" ) var _ engine.Worker = (*worker)(nil) @@ -79,8 +79,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, fmt.Errorf("invalid task type %T", task) } - zap.L().Debug("transforming paraswap task", zap.String("task_id", ethereumTask.ID())) - activity, err := task.BuildActivity(activityx.WithActivityPlatform(w.Platform())) if err != nil { return nil, fmt.Errorf("build activity: %w", err) @@ -89,15 +87,12 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac activity.Type = typex.ExchangeSwap activity.Actions = w.transformSwapTransaction(ctx, ethereumTask) - zap.L().Debug("successfully transformed paraswap task") - return activity, nil } func (w *worker) transformSwapTransaction(ctx context.Context, ethereumTask *source.Task) (actions []*activityx.Action) { for _, log := range ethereumTask.Receipt.Logs { if len(log.Topics) == 0 { - zap.L().Debug("ignoring anonymous log") continue } @@ -106,40 +101,24 @@ func (w *worker) transformSwapTransaction(ctx context.Context, ethereumTask *sou err error ) - zap.L().Debug("matching paraswap event", - zap.String("address", log.Address.String()), - zap.String("event", log.Topics[0].String())) - switch { case w.matchV3SwappedLog(ethereumTask, log): - zap.L().Debug("matched v3 swapped event") - buffer, err = w.transformV3SwappedLog(ctx, ethereumTask, log) case w.matchV3BoughtLog(ethereumTask, log): - zap.L().Debug("matched v3 bought event") - buffer, err = w.transformV3BoughtLog(ctx, ethereumTask, log) case w.matchSwappedDirectLog(ethereumTask, log): - zap.L().Debug("matched swapped direct event") - buffer, err = w.transformSwappedDirectLog(ctx, ethereumTask, log) default: - zap.L().Debug("no matching paraswap event") - continue } if err != nil { - zap.L().Debug("error transforming paraswap event", zap.Error(err)) - continue } actions = append(actions, buffer...) } - zap.L().Debug("successfully transformed paraswap task") - return actions } @@ -201,14 +180,6 @@ func (w *worker) transformSwappedDirectLog(ctx context.Context, task *source.Tas } func (w *worker) buildExchangeSwapAction(ctx context.Context, task *source.Task, sender, receiver common.Address, tokenIn, tokenOut common.Address, amountIn, amountOut *big.Int) (*activityx.Action, error) { - zap.L().Debug("building exchange swap action", - zap.String("sender", sender.String()), - zap.String("receiver", receiver.String()), - zap.String("token_in", tokenIn.String()), - zap.String("token_out", tokenOut.String()), - zap.Any("amount_in", amountIn), - zap.Any("amount_out", amountOut)) - tokenInAddress := lo.Ternary(tokenIn != paraswap.AddressETH, &tokenIn, nil) tokenOutAddress := lo.Ternary(tokenOut != paraswap.AddressETH, &tokenOut, nil) @@ -217,14 +188,14 @@ func (w *worker) buildExchangeSwapAction(ctx context.Context, task *source.Task, return nil, fmt.Errorf("lookup token in metadata: %w", err) } - tokenInMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(amountIn, 0)) + tokenInMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(amountIn), 0)) tokenOutMetadata, err := w.tokenClient.Lookup(ctx, task.ChainID, tokenOutAddress, nil, task.Header.Number) if err != nil { return nil, fmt.Errorf("lookup token out metadata: %w", err) } - tokenOutMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(amountOut, 0)) + tokenOutMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(amountOut), 0)) action := activityx.Action{ Type: typex.ExchangeSwap, @@ -237,8 +208,6 @@ func (w *worker) buildExchangeSwapAction(ctx context.Context, task *source.Task, }, } - zap.L().Debug("successfully built exchange swap action") - return &action, nil } diff --git a/internal/engine/worker/decentralized/contract/polymarket/worker.go b/internal/engine/worker/decentralized/contract/polymarket/worker.go index 8ce26924f..9d4107f3e 100644 --- a/internal/engine/worker/decentralized/contract/polymarket/worker.go +++ b/internal/engine/worker/decentralized/contract/polymarket/worker.go @@ -9,6 +9,7 @@ import ( "github.com/rss3-network/node/config" "github.com/rss3-network/node/internal/engine" source "github.com/rss3-network/node/internal/engine/protocol/ethereum" + "github.com/rss3-network/node/internal/utils" "github.com/rss3-network/node/provider/ethereum" "github.com/rss3-network/node/provider/ethereum/contract" "github.com/rss3-network/node/provider/ethereum/contract/polymarket" @@ -22,7 +23,6 @@ import ( "github.com/rss3-network/protocol-go/schema/typex" "github.com/samber/lo" "github.com/shopspring/decimal" - "go.uber.org/zap" ) var _ engine.Worker = (*worker)(nil) @@ -77,8 +77,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, fmt.Errorf("invalid task type %T", task) } - zap.L().Debug("transforming polymarket task", zap.String("task_id", polygonTask.ID())) - activity, err := task.BuildActivity(activityx.WithActivityPlatform(w.Platform())) if err != nil { return nil, fmt.Errorf("build activity: %w", err) @@ -86,8 +84,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac for _, log := range polygonTask.Receipt.Logs { if len(log.Topics) == 0 { - zap.L().Debug("ignoring anonymous log") - continue } @@ -96,17 +92,11 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac err error ) - zap.L().Debug("matching polymarket event", - zap.String("address", log.Address.String()), - zap.String("topic", log.Topics[0].String())) - switch { case w.matchOrderFinalizedLog(polygonTask, log): actions, err = w.transformOrderFinalizedLog(ctx, polygonTask, log) default: - zap.L().Debug("no matching polymarket event") - continue } @@ -119,8 +109,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac activity.Type = typex.CollectibleTrade - zap.L().Debug("successfully transformed polymarket task") - return activity, nil } @@ -148,16 +136,8 @@ func (w *worker) transformOrderFinalizedLog(ctx context.Context, task *source.Ta } func (w *worker) buildMarketTradeAction(ctx context.Context, _ *source.Task, chainID uint64, maker, taker common.Address, makerAssetID, takerAssetID *big.Int, _ [32]byte, makerAmountFilled, takerAmountFilled *big.Int) (*activityx.Action, *activityx.Action, error) { - zap.L().Debug("building market trade action", - zap.String("maker", maker.String()), - zap.String("taker", taker.String()), - zap.Any("maker_asset_id", makerAssetID), - zap.Any("taker_asset_id", takerAssetID), - zap.Any("maker_amount_filled", makerAmountFilled), - zap.Any("taker_amount_filled", takerAmountFilled)) - - makerAmountFilledDecimal := decimal.NewFromBigInt(makerAmountFilled, 0) - takerAmountFilledDecimal := decimal.NewFromBigInt(takerAmountFilled, 0) + makerAmountFilledDecimal := decimal.NewFromBigInt(utils.GetBigInt(makerAmountFilled), 0) + takerAmountFilledDecimal := decimal.NewFromBigInt(utils.GetBigInt(takerAmountFilled), 0) var takerTokenAddress *common.Address if takerAssetID.Cmp(big.NewInt(0)) == 0 { @@ -216,8 +196,6 @@ func (w *worker) buildMarketTradeAction(ctx context.Context, _ *source.Task, cha }, } - zap.L().Debug("successfully built market trade action") - return buyAction, sellAction, nil } diff --git a/internal/engine/worker/decentralized/contract/rainbow/worker.go b/internal/engine/worker/decentralized/contract/rainbow/worker.go index bc0b5fbd3..702e97333 100644 --- a/internal/engine/worker/decentralized/contract/rainbow/worker.go +++ b/internal/engine/worker/decentralized/contract/rainbow/worker.go @@ -10,6 +10,7 @@ import ( "github.com/rss3-network/node/config" "github.com/rss3-network/node/internal/engine" source "github.com/rss3-network/node/internal/engine/protocol/ethereum" + "github.com/rss3-network/node/internal/utils" "github.com/rss3-network/node/provider/ethereum" "github.com/rss3-network/node/provider/ethereum/contract" "github.com/rss3-network/node/provider/ethereum/contract/erc20" @@ -89,35 +90,29 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, fmt.Errorf("invalid task type %T", task) } - zap.L().Debug("transforming rainbow task", zap.String("task_id", ethereumTask.ID())) - activity, err := ethereumTask.BuildActivity(activityx.WithActivityPlatform(w.Platform())) if err != nil { return nil, fmt.Errorf("build activity: %w", err) } - if w.matchSwapTransaction(ethereumTask) { - zap.L().Debug("matching rainbow swap transaction") + if !w.matchSwapTransaction(ethereumTask) { + return nil, nil + } - actions, err := w.transformSwapTransaction(ctx, ethereumTask) + actions, err := w.transformSwapTransaction(ctx, ethereumTask) - if err != nil { - return nil, fmt.Errorf("handle ethereum swap transaction: %w", err) - } - - activity.Actions = append(activity.Actions, actions...) - } else { - return nil, fmt.Errorf("unknown transaction %s", ethereumTask.ID()) + if err != nil { + return nil, fmt.Errorf("handle ethereum swap transaction: %w", err) } + activity.Actions = append(activity.Actions, actions...) + if len(activity.Actions) == 0 { return nil, fmt.Errorf("no actions") } activity.Type = typex.ExchangeSwap - zap.L().Debug("successfully transformed rainbow task") - return activity, nil } @@ -235,7 +230,7 @@ func (w *worker) transformTokenToEthSwap(ctx context.Context, task *source.Task) return nil, fmt.Errorf("copy input: %w", err) } - feePercentageBasisPoints := decimal.NewFromBigInt(input.FeePercentageBasisPoints, 0) + feePercentageBasisPoints := decimal.NewFromBigInt(utils.GetBigInt(input.FeePercentageBasisPoints), 0) return w.processSwapLogs(ctx, task, valueMap, actions, feePercentageBasisPoints) } @@ -292,7 +287,7 @@ func (w *worker) processSwapLogs(ctx context.Context, task *source.Task, valueMa event, err := w.erc20Filterer.ParseTransfer(log.Export()) if err != nil { - zap.L().Warn("parse event", zap.Error(err)) + zap.L().Error("parse event", zap.Error(err)) continue } @@ -306,7 +301,7 @@ func (w *worker) processSwapLogs(ctx context.Context, task *source.Task, valueMa case weth.EventHashWithdrawal: event, err := w.weth9Filterer.ParseWithdrawal(log.Export()) if err != nil { - zap.L().Warn("parse event", zap.Error(err)) + zap.L().Error("parse event", zap.Error(err)) continue } @@ -359,7 +354,7 @@ func (w *worker) findTokens(valueMap map[*common.Address]*big.Int) (*common.Addr // buildFeeAction builds a fee action for the swap. func (w *worker) buildFeeAction(ctx context.Context, task *source.Task, _ *common.Address, amountOut *big.Int, feePercentageBasisPoints decimal.Decimal) (*activityx.Action, error) { - ethDiff := decimal.NewFromBigInt(amountOut, 0) + ethDiff := decimal.NewFromBigInt(utils.GetBigInt(amountOut), 0) fees := ethDiff.Mul(feePercentageBasisPoints).DivRound(decimal.NewFromInt(1e18), -1) return w.buildTransactionTransferAction(ctx, task, task.Transaction.From, rainbow.AddressRouter, nil, fees.BigInt()) @@ -380,14 +375,6 @@ func (w *worker) simulationTransfer(valueMap map[*common.Address]*big.Int, trans // buildExchangeSwapAction builds an exchange swap action. func (w *worker) buildExchangeSwapAction(ctx context.Context, task *source.Task, from, to common.Address, tokenIn, tokenOut *common.Address, amountIn, amountOut *big.Int) (*activityx.Action, error) { - zap.L().Debug("building exchange swap action", - zap.String("from", from.String()), - zap.String("to", to.String()), - zap.Any("token_in", tokenIn), - zap.Any("token_out", tokenOut), - zap.Any("amount_in", amountIn), - zap.Any("amount_out", amountOut)) - tokenInAddress := lo.Ternary(tokenIn != nil && *tokenIn != ethereum.AddressGenesis, tokenIn, nil) tokenOutAddress := lo.Ternary(tokenOut != nil && *tokenOut != ethereum.AddressGenesis, tokenOut, nil) @@ -396,7 +383,7 @@ func (w *worker) buildExchangeSwapAction(ctx context.Context, task *source.Task, return nil, fmt.Errorf("lookup token in metadata: %w", err) } - tokenInMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(amountIn, 0).Abs()) + tokenInMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(amountIn), 0).Abs()) tokenOutMetadata, err := w.tokenClient.Lookup(ctx, task.ChainID, tokenOutAddress, nil, task.Header.Number) if err != nil { @@ -405,8 +392,6 @@ func (w *worker) buildExchangeSwapAction(ctx context.Context, task *source.Task, tokenOutMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(amountOut, 0).Abs()) - zap.L().Debug("successfully built exchange swap action") - return &activityx.Action{ Type: typex.ExchangeSwap, Platform: w.Platform(), @@ -421,20 +406,12 @@ func (w *worker) buildExchangeSwapAction(ctx context.Context, task *source.Task, // buildTransactionTransferAction builds a transaction transfer action. func (w *worker) buildTransactionTransferAction(ctx context.Context, task *source.Task, from, to common.Address, tokenAddress *common.Address, amount *big.Int) (*activityx.Action, error) { - zap.L().Debug("building transaction transfer action", - zap.String("from", from.String()), - zap.String("to", to.String()), - zap.Any("token_address", tokenAddress), - zap.Any("amount", amount)) - tokenMetadata, err := w.tokenClient.Lookup(ctx, task.ChainID, tokenAddress, nil, task.Header.Number) if err != nil { return nil, fmt.Errorf("lookup token metadata: %w", err) } - tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(amount, 0)) - - zap.L().Debug("successfully built transaction transfer action") + tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(amount), 0)) return &activityx.Action{ Type: typex.TransactionTransfer, diff --git a/internal/engine/worker/decentralized/contract/rss3/worker.go b/internal/engine/worker/decentralized/contract/rss3/worker.go index 252489f6e..8e06ddf07 100644 --- a/internal/engine/worker/decentralized/contract/rss3/worker.go +++ b/internal/engine/worker/decentralized/contract/rss3/worker.go @@ -10,6 +10,7 @@ import ( "github.com/rss3-network/node/config" "github.com/rss3-network/node/internal/engine" source "github.com/rss3-network/node/internal/engine/protocol/ethereum" + "github.com/rss3-network/node/internal/utils" "github.com/rss3-network/node/provider/ethereum" "github.com/rss3-network/node/provider/ethereum/contract" "github.com/rss3-network/node/provider/ethereum/contract/rss3" @@ -23,7 +24,6 @@ import ( "github.com/rss3-network/protocol-go/schema/typex" "github.com/samber/lo" "github.com/shopspring/decimal" - "go.uber.org/zap" ) var _ engine.Worker = (*worker)(nil) @@ -85,9 +85,7 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, fmt.Errorf("invalid task type: %T", task) } - zap.L().Debug("transforming rss3 task", zap.String("task_id", ethereumTask.ID())) - - _activities, err := ethereumTask.BuildActivity(activityx.WithActivityPlatform(w.Platform())) + activities, err := ethereumTask.BuildActivity(activityx.WithActivityPlatform(w.Platform())) if err != nil { return nil, fmt.Errorf("build _activities: %w", err) } @@ -96,8 +94,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac for _, log := range ethereumTask.Receipt.Logs { // Ignore anonymous logs. if len(log.Topics) == 0 { - zap.L().Debug("ignoring anonymous log") - continue } @@ -106,27 +102,15 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac err error ) - zap.L().Debug("matching rss3 event", - zap.String("address", log.Address.String()), - zap.String("topic", log.Topics[0].String())) - switch { // Ethereum Mainnet case w.matchStakingDeposited(ethereumTask, log): - zap.L().Debug("matching staking deposited event") - actions, err = w.transformStakingDeposited(ctx, ethereumTask, log) case w.matchStakingWithdrawn(ethereumTask, log): - zap.L().Debug("matching staking withdrawn event") - actions, err = w.transformStakingWithdrawn(ctx, ethereumTask, log) case w.matchStakingRewardsClaimed(ethereumTask, log): - zap.L().Debug("matching staking rewards claimed event") - actions, err = w.transformStakingRewardsClaimed(ctx, ethereumTask, log) default: - zap.L().Debug("no matching rss3 event") - continue } @@ -136,15 +120,13 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac // Overwrite the type for _activities. for _, action := range actions { - _activities.Type = action.Type + activities.Type = action.Type } - _activities.Actions = append(_activities.Actions, actions...) + activities.Actions = append(activities.Actions, actions...) } - zap.L().Debug("successfully transformed rss3 task") - - return _activities, nil + return activities, nil } // matchStakingDeposited matches the staking deposited event. @@ -226,20 +208,13 @@ func (w *worker) transformStakingRewardsClaimed(ctx context.Context, task *sourc // buildExchangeStakingAction builds the exchange staking action. func (w *worker) buildExchangeStakingAction(ctx context.Context, task *source.Task, from, to common.Address, tokenValue *big.Int, stakingAction metadata.ExchangeStakingAction, period *metadata.ExchangeStakingPeriod) (*activityx.Action, error) { - zap.L().Debug("building exchange staking action", - zap.String("from", from.String()), - zap.String("to", to.String()), - zap.Any("token_value", tokenValue), - zap.String("staking_action", stakingAction.String()), - zap.Any("period", period)) - // The Token always is $RSS3. tokenMetadata, err := w.tokenClient.Lookup(ctx, task.ChainID, &rss3.AddressToken, nil, task.Header.Number) if err != nil { return nil, fmt.Errorf("lookup token %s: %w", rss3.AddressToken, err) } - tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(tokenValue, 0)) + tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(tokenValue), 0)) action := activityx.Action{ Type: typex.ExchangeStaking, @@ -253,8 +228,6 @@ func (w *worker) buildExchangeStakingAction(ctx context.Context, task *source.Ta }, } - zap.L().Debug("successfully built exchange staking action") - return &action, nil } diff --git a/internal/engine/worker/decentralized/contract/savm/worker.go b/internal/engine/worker/decentralized/contract/savm/worker.go index 862dd2c65..f8529dff2 100644 --- a/internal/engine/worker/decentralized/contract/savm/worker.go +++ b/internal/engine/worker/decentralized/contract/savm/worker.go @@ -9,6 +9,7 @@ import ( "github.com/rss3-network/node/config" "github.com/rss3-network/node/internal/engine" source "github.com/rss3-network/node/internal/engine/protocol/ethereum" + "github.com/rss3-network/node/internal/utils" "github.com/rss3-network/node/provider/ethereum" "github.com/rss3-network/node/provider/ethereum/contract/erc20" "github.com/rss3-network/node/provider/ethereum/contract/savm" @@ -22,7 +23,6 @@ import ( "github.com/rss3-network/protocol-go/schema/typex" "github.com/samber/lo" "github.com/shopspring/decimal" - "go.uber.org/zap" ) var _ engine.Worker = (*worker)(nil) @@ -81,8 +81,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, fmt.Errorf("invalid task type: %T", task) } - zap.L().Debug("transforming savm task", zap.String("task_id", ethereumTask.ID())) - activity, err := ethereumTask.BuildActivity(activityx.WithActivityPlatform(w.Platform())) if err != nil { return nil, fmt.Errorf("build activity: %w", err) @@ -96,31 +94,17 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac // Ignore anonymous logs. if len(log.Topics) == 0 { - zap.L().Debug("ignoring anonymous log") - continue } - zap.L().Debug("matching savm event", - zap.String("address", log.Address.String()), - zap.String("topic", log.Topics[0].String())) - switch { case w.matchBTCBridgeWithdrawLog(ethereumTask, log): - zap.L().Debug("matching btc bridge withdraw event") - actions, err = w.transformBTCBridgeWithdrawLog(ctx, ethereumTask, log) case w.matchBTCBridgeDepositLog(ethereumTask, log): - zap.L().Debug("matching btc bridge deposit event") - actions, err = w.transformBTCBridgeDepositLog(ctx, ethereumTask, log) case w.matchSAVMTransferLog(ethereumTask, log): - zap.L().Debug("matching savm bridge event") - actions, err = w.transformSAVMBridgeLog(ctx, ethereumTask, log) default: - zap.L().Debug("no matching savm event") - continue } @@ -132,8 +116,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac activity.Actions = append(activity.Actions, actions...) } - zap.L().Debug("successfully transformed savm task") - return activity, nil } @@ -206,21 +188,12 @@ func (w *worker) transformSAVMBridgeLog(ctx context.Context, task *source.Task, } func (w *worker) buildTransactionBridgeAction(ctx context.Context, chainID uint64, sender, receiver common.Address, source, target network.Network, bridgeAction metadata.TransactionBridgeAction, tokenAddress *common.Address, tokenValue *big.Int, blockNumber *big.Int) (*activityx.Action, error) { - zap.L().Debug("building transaction bridge action", - zap.String("sender", sender.String()), - zap.String("receiver", receiver.String()), - zap.String("source", source.String()), - zap.String("target", target.String()), - zap.String("bridge_action", bridgeAction.String()), - zap.Any("token_address", tokenAddress), - zap.Any("token_value", tokenValue)) - tokenMetadata, err := w.tokenClient.Lookup(ctx, chainID, tokenAddress, nil, blockNumber) if err != nil { return nil, fmt.Errorf("lookup token %s: %w", tokenAddress, err) } - tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(tokenValue, 0)) + tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(tokenValue), 0)) action := activityx.Action{ Type: typex.TransactionBridge, @@ -235,8 +208,6 @@ func (w *worker) buildTransactionBridgeAction(ctx context.Context, chainID uint6 }, } - zap.L().Debug("successfully built transaction bridge action") - return &action, nil } diff --git a/internal/engine/worker/decentralized/contract/stargate/worker.go b/internal/engine/worker/decentralized/contract/stargate/worker.go index 0804d179d..c7beec219 100644 --- a/internal/engine/worker/decentralized/contract/stargate/worker.go +++ b/internal/engine/worker/decentralized/contract/stargate/worker.go @@ -10,6 +10,7 @@ import ( "github.com/rss3-network/node/config" "github.com/rss3-network/node/internal/engine" source "github.com/rss3-network/node/internal/engine/protocol/ethereum" + "github.com/rss3-network/node/internal/utils" "github.com/rss3-network/node/provider/ethereum" "github.com/rss3-network/node/provider/ethereum/contract" "github.com/rss3-network/node/provider/ethereum/contract/layerzero" @@ -84,8 +85,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac // If the task does not meet the filter conditions, it will be discarded. if !matched { - zap.L().Warn("unmatched task", zap.String("task.id", task.ID())) - return nil, nil } @@ -94,8 +93,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, fmt.Errorf("invalid task type: %T", task) } - zap.L().Debug("transforming stargate task", zap.String("task_id", ethereumTask.ID())) - activity, err := ethereumTask.BuildActivity(activityx.WithActivityPlatform(w.Platform())) if err != nil { return nil, fmt.Errorf("build activity: %w", err) @@ -109,27 +106,15 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac // Ignore anonymous logs. if len(log.Topics) == 0 { - zap.L().Debug("ignoring anonymous log") - continue } - zap.L().Debug("matching stargate event", - zap.String("address", log.Address.String()), - zap.String("topic", log.Topics[0].String())) - switch { case w.matchPoolSwapLog(ethereumTask, log): - zap.L().Debug("matching pool swap log") - actions, err = w.transformLPoolSwapLog(ctx, ethereumTask, log) case w.matchPoolSwapRemoteLog(ethereumTask, log): - zap.L().Debug("matching pool swap remote log") - actions, err = w.transformLPoolSwapRemoteLog(ctx, ethereumTask, log) default: - zap.L().Debug("no matching stargate event") - continue } @@ -141,8 +126,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac activity.Actions = append(activity.Actions, actions...) } - zap.L().Debug("successfully transformed stargate task") - return activity, nil } @@ -239,13 +222,13 @@ func (w *worker) transformLPoolSwapLog(ctx context.Context, task *source.Task, l return nil, fmt.Errorf("build transaction bridge action: %w", err) } - layerzeroFeeValue := decimal.NewFromBigInt(task.Transaction.Value, 0) + layerzeroFeeValue := decimal.NewFromBigInt(utils.GetBigInt(task.Transaction.Value), 0) if stargate.IsSGETH(tokenAddress) { layerzeroFeeValue = layerzeroFeeValue. - Sub(decimal.NewFromBigInt(event.AmountSD, 0)). - Sub(decimal.NewFromBigInt(event.EqFee, 0)). - Sub(decimal.NewFromBigInt(event.ProtocolFee, 0)). - Sub(decimal.NewFromBigInt(event.LpFee, 0)) + Sub(decimal.NewFromBigInt(utils.GetBigInt(event.AmountSD), 0)). + Sub(decimal.NewFromBigInt(utils.GetBigInt(event.EqFee), 0)). + Sub(decimal.NewFromBigInt(utils.GetBigInt(event.ProtocolFee), 0)). + Sub(decimal.NewFromBigInt(utils.GetBigInt(event.LpFee), 0)) } layerzeroUltraLightNodeAddress, exists := layerzero.UltraLightNodeAddress(task.Network) @@ -259,9 +242,9 @@ func (w *worker) transformLPoolSwapLog(ctx context.Context, task *source.Task, l } stargateFee := decimal.Zero. - Add(decimal.NewFromBigInt(event.EqFee, 0)). - Add(decimal.NewFromBigInt(event.ProtocolFee, 0)). - Add(decimal.NewFromBigInt(event.LpFee, 0)) + Add(decimal.NewFromBigInt(utils.GetBigInt(event.EqFee), 0)). + Add(decimal.NewFromBigInt(utils.GetBigInt(event.ProtocolFee), 0)). + Add(decimal.NewFromBigInt(utils.GetBigInt(event.LpFee), 0)) stargateFeeAction, err := w.buildTransactionTransferAction(ctx, task, task.Transaction.From, event.Raw.Address, lo.Ternary(stargate.IsSGETH(tokenAddress), nil, &tokenAddress), stargateFee.BigInt()) if err != nil { @@ -330,21 +313,12 @@ func (w *worker) transformLPoolSwapRemoteLog(ctx context.Context, task *source.T // buildTransactionBridgeAction builds the transaction bridge action. func (w *worker) buildTransactionBridgeAction(ctx context.Context, chainID uint64, sender, receiver common.Address, source, target network.Network, bridgeAction metadata.TransactionBridgeAction, tokenAddress *common.Address, tokenValue *big.Int, blockNumber *big.Int) (*activityx.Action, error) { - zap.L().Debug("building transaction bridge action", - zap.String("sender", sender.String()), - zap.String("receiver", receiver.String()), - zap.String("source", source.String()), - zap.String("target", target.String()), - zap.String("bridge_action", bridgeAction.String()), - zap.Any("token_address", tokenAddress), - zap.Any("token_value", tokenValue)) - tokenMetadata, err := w.tokenClient.Lookup(ctx, chainID, tokenAddress, nil, blockNumber) if err != nil { return nil, fmt.Errorf("lookup token %s: %w", tokenAddress, err) } - tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(tokenValue, 0)) + tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(tokenValue), 0)) action := activityx.Action{ Type: typex.TransactionBridge, @@ -359,25 +333,17 @@ func (w *worker) buildTransactionBridgeAction(ctx context.Context, chainID uint6 }, } - zap.L().Debug("successfully built transaction bridge action") - return &action, nil } // buildTransactionTransferAction builds the Ethereum transaction transfer action. func (w *worker) buildTransactionTransferAction(ctx context.Context, task *source.Task, sender, receipt common.Address, token *common.Address, value *big.Int) (*activityx.Action, error) { - zap.L().Debug("building transaction transfer action", - zap.String("sender", sender.String()), - zap.String("receipt", receipt.String()), - zap.Any("token_address", token), - zap.Any("token_value", value)) - tokenMetadata, err := w.tokenClient.Lookup(ctx, task.ChainID, token, nil, task.Header.Number) if err != nil { return nil, fmt.Errorf("lookup token metadata: %w", err) } - tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(value, 0)) + tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(value), 0)) action := activityx.Action{ Type: typex.TransactionTransfer, @@ -386,8 +352,6 @@ func (w *worker) buildTransactionTransferAction(ctx context.Context, task *sourc Metadata: metadata.TransactionTransfer(*tokenMetadata), } - zap.L().Debug("successfully built transaction transfer action") - return &action, nil } diff --git a/internal/engine/worker/decentralized/contract/uniswap/worker.go b/internal/engine/worker/decentralized/contract/uniswap/worker.go index 95446ea25..ab8fc7ab1 100644 --- a/internal/engine/worker/decentralized/contract/uniswap/worker.go +++ b/internal/engine/worker/decentralized/contract/uniswap/worker.go @@ -2,7 +2,6 @@ package uniswap import ( "context" - "errors" "fmt" "math/big" @@ -11,6 +10,7 @@ import ( "github.com/rss3-network/node/config" "github.com/rss3-network/node/internal/engine" source "github.com/rss3-network/node/internal/engine/protocol/ethereum" + "github.com/rss3-network/node/internal/utils" "github.com/rss3-network/node/provider/ethereum" "github.com/rss3-network/node/provider/ethereum/contract" "github.com/rss3-network/node/provider/ethereum/contract/erc721" @@ -115,8 +115,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, fmt.Errorf("invalid task type %T", task) } - zap.L().Debug("transforming uniswap task", zap.String("task_id", ethereumTask.ID())) - activity, err := task.BuildActivity(activityx.WithActivityPlatform(w.Platform())) if err != nil { return nil, fmt.Errorf("build activity: %w", err) @@ -124,17 +122,13 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac switch { case w.matchSwapTransaction(ethereumTask, ethereumTask.Transaction): - zap.L().Debug("matching swap transaction") - activity.Type = typex.ExchangeSwap activity.Actions = w.transformSwapTransaction(ctx, ethereumTask, ethereumTask.Transaction) case w.matchLiquidityTransaction(ethereumTask, ethereumTask.Transaction): - zap.L().Debug("matching liquidity transaction") - activity.Type = typex.ExchangeLiquidity activity.Actions = w.transformLiquidityTransaction(ctx, ethereumTask, ethereumTask.Transaction) default: - return nil, errors.New("unsupported transaction") + return nil, nil } return activity, nil @@ -145,8 +139,6 @@ func (w *worker) matchSwapTransaction(task *source.Task, transaction *ethereum.T return false } - zap.L().Debug("matching swap transaction", zap.String("to", transaction.To.String())) - switch *transaction.To { case // Uniswap V3 uniswap.AddressV3SwapRouter, @@ -156,15 +148,11 @@ func (w *worker) matchSwapTransaction(task *source.Task, transaction *ethereum.T uniswap.AddressV3SwapRouter02BinanceSmartChain, uniswap.AddressV3SwapRouter02Linea, uniswap.AddressUniversalRouter: - zap.L().Debug("matching uniswap v3 swap transaction") - return true case // Uniswap V2 uniswap.AddressV2SwapRouter01, uniswap.AddressV2SwapRouter02, uniswap.AddressV2SwapRouterSAVM: - zap.L().Debug("matching uniswap v2 swap transaction") - return lo.ContainsBy(task.Receipt.Logs, func(log *ethereum.Log) bool { if len(log.Topics) == 0 { return false @@ -173,8 +161,6 @@ func (w *worker) matchSwapTransaction(task *source.Task, transaction *ethereum.T return contract.MatchEventHashes(log.Topics[0], uniswap.EventHashV2PairSwap) }) default: // Uniswap V1 - zap.L().Debug("matching uniswap v1 swap transaction") - return lo.ContainsBy(task.Receipt.Logs, func(log *ethereum.Log) bool { if len(log.Topics) == 0 { return false @@ -194,24 +180,18 @@ func (w *worker) matchLiquidityTransaction(task *source.Task, transaction *ether return false } - zap.L().Debug("matching liquidity transaction", zap.String("to", transaction.To.String())) - switch *task.Transaction.To { case // Uniswap V3 uniswap.AddressNonfungiblePositionManager, uniswap.AddressV3Migrator, uniswap.AddressV3MigratorLinea, uniswap.AddressNonfungiblePositionManagerLinea: - zap.L().Debug("matching uniswap v3 liquidity transaction") - return true case // Uniswap V2 uniswap.AddressV2SwapRouter01, uniswap.AddressV2SwapRouter02, uniswap.AddressV2SwapRouterSAVM, uniswap.AddressV2Migrator: - zap.L().Debug("matching uniswap v2 liquidity transaction") - return lo.ContainsBy(task.Receipt.Logs, func(item *ethereum.Log) bool { if len(item.Topics) == 0 { return false @@ -224,8 +204,6 @@ func (w *worker) matchLiquidityTransaction(task *source.Task, transaction *ether ) }) default: // Uniswap V1 - zap.L().Debug("matching uniswap v1 liquidity transaction") - return lo.ContainsBy(task.Receipt.Logs, func(item *ethereum.Log) bool { if len(item.Topics) == 0 { return false @@ -264,44 +242,25 @@ func (w *worker) transformSwapTransaction(ctx context.Context, task *source.Task for _, log := range task.Receipt.Logs { if len(log.Topics) == 0 { - zap.L().Debug("ignoring anonymous log") - continue } var buffer []*activityx.Action - zap.L().Debug("transforming swap transaction", - zap.String("address", log.Address.String()), - zap.String("topic", log.Export().Topics[0].String())) - switch log.Export().Topics[0] { case uniswap.EventHashV1ExchangeTokenPurchase: - zap.L().Debug("transforming v1 token purchase log") - buffer, err = w.transformV1TokenPurchaseLog(ctx, task, log) case uniswap.EventHashV1ExchangeEthPurchase: - zap.L().Debug("transforming v1 eth purchase log") - buffer, err = w.transformV1EthPurchaseLog(ctx, task, log) case uniswap.EventHashV2PairSwap: - zap.L().Debug("transforming v2 pair swap log") - buffer, err = w.transformV2SwapLog(ctx, task, log) case uniswap.EventHashV3PoolSwap: - zap.L().Debug("transforming v3 pool swap log") - buffer, err = w.transformV3SwapLog(ctx, task, log) case weth.EventHashDeposit: - zap.L().Debug("transforming weth deposit log") - buffer, err = w.transformWETHDepositLog(ctx, task, log) case weth.EventHashWithdrawal: - zap.L().Debug("transforming weth withdrawal log") - buffer, err = w.transformWETHWithdrawalLog(ctx, task, log) default: - zap.L().Debug("no matching uniswap swap transaction event") continue } @@ -314,8 +273,6 @@ func (w *worker) transformSwapTransaction(ctx context.Context, task *source.Task actions = append(actions, buffer...) } - zap.L().Debug("successfully transformed swap transaction") - return actions } @@ -324,57 +281,33 @@ func (w *worker) transformLiquidityTransaction(ctx context.Context, task *source for _, log := range task.Receipt.Logs { if len(log.Topics) == 0 { - zap.L().Debug("ignoring anonymous log") - continue } var buffer []*activityx.Action - zap.L().Debug("transforming liquidity transaction", - zap.String("address", log.Address.String()), - zap.String("topic", log.Export().Topics[0].String())) - switch log.Export().Topics[0] { case uniswap.EventHashV1ExchangeAddLiquidity: - zap.L().Debug("transforming v1 exchange add liquidity log") - buffer, err = w.transformV1ExchangeAddLiquidityLog(ctx, task, log) case uniswap.EventHashV1ExchangeRemoveLiquidity: - zap.L().Debug("transforming v1 exchange remove liquidity log") - buffer, err = w.transformV1ExchangeRemoveLiquidityLog(ctx, task, log) case uniswap.EventHashV2PairMint: - zap.L().Debug("transforming v2 pair mint log") - buffer, err = w.transformV2PairMintLog(ctx, task, log) case uniswap.EventHashV2PairBurn: - zap.L().Debug("transforming v2 pair burn log") - buffer, err = w.transformV2PairBurnLog(ctx, task, log) case uniswap.EventHashNonfungiblePositionManagerIncreaseLiquidity: - zap.L().Debug("transforming nonfungible position manager increase liquidity log") - buffer, err = w.transformNonfungiblePositionManagerIncreaseLiquidityLog(ctx, task, log) case uniswap.EventHashNonfungiblePositionManagerDecreaseLiquidity: - zap.L().Debug("transforming nonfungible position manager decrease liquidity log") - buffer, err = w.transformNonfungiblePositionManagerDecreaseLiquidityLog(ctx, task, log) case uniswap.EventHashNonfungiblePositionManagerCollect: - zap.L().Debug("transforming nonfungible position manager collect log") - buffer, err = w.transformNonfungiblePositionManagerCollectLog(ctx, task, log) case erc721.EventHashTransfer: - zap.L().Debug("transforming nonfungible position manager transfer log") - if !w.matchNonfungiblePositionManagerTransferLog(task, log) { continue } buffer, err = w.transformNonfungiblePositionManagerTransferLog(ctx, task, log) default: - zap.L().Debug("no matching uniswap liquidity transaction event") - continue } @@ -387,8 +320,6 @@ func (w *worker) transformLiquidityTransaction(ctx context.Context, task *source actions = append(actions, buffer...) } - zap.L().Debug("successfully transformed liquidity transaction") - return actions } @@ -478,11 +409,11 @@ func (w *worker) transformV1ExchangeAddLiquidityLog(ctx context.Context, task *s tokens := []metadata.Token{ { // Native token - Value: lo.ToPtr(decimal.NewFromBigInt(event.EthAmount, 0)), + Value: lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(event.EthAmount), 0)), }, { // ERC-20 token Address: lo.ToPtr(tokenAddress.String()), - Value: lo.ToPtr(decimal.NewFromBigInt(event.TokenAmount, 0)), + Value: lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(event.TokenAmount), 0)), }, } @@ -521,12 +452,12 @@ func (w *worker) transformV1ExchangeRemoveLiquidityLog(ctx context.Context, task tokens := []metadata.Token{ { // Native token - Value: lo.ToPtr(decimal.NewFromBigInt(event.EthAmount, 0)), + Value: lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(event.EthAmount), 0)), }, { // ERC-20 token Address: lo.ToPtr(tokenAddr.String()), - Value: lo.ToPtr(decimal.NewFromBigInt(event.TokenAmount, 0)), + Value: lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(event.TokenAmount), 0)), }, } @@ -640,11 +571,11 @@ func (w *worker) transformV2PairMintLog(ctx context.Context, task *source.Task, tokens := []metadata.Token{ { Address: lo.ToPtr(tokenLeft.String()), - Value: lo.ToPtr(decimal.NewFromBigInt(event.Amount0, 0)), + Value: lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(event.Amount0), 0)), }, { Address: lo.ToPtr(tokenRight.String()), - Value: lo.ToPtr(decimal.NewFromBigInt(event.Amount1, 0)), + Value: lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(event.Amount1), 0)), }, } @@ -703,11 +634,11 @@ func (w *worker) transformV2PairBurnLog(ctx context.Context, task *source.Task, tokens := []metadata.Token{ { Address: lo.ToPtr(tokenLeft.String()), - Value: lo.ToPtr(decimal.NewFromBigInt(event.Amount0, 0)), + Value: lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(event.Amount0), 0)), }, { Address: lo.ToPtr(tokenRight.String()), - Value: lo.ToPtr(decimal.NewFromBigInt(event.Amount1, 0)), + Value: lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(event.Amount1), 0)), }, } @@ -830,11 +761,11 @@ func (w *worker) transformNonfungiblePositionManagerIncreaseLiquidityLog(ctx con tokens := []metadata.Token{ { Address: lo.ToPtr(positions.Token0.String()), - Value: lo.ToPtr(decimal.NewFromBigInt(event.Amount0, 0)), + Value: lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(event.Amount0), 0)), }, { Address: lo.ToPtr(positions.Token1.String()), - Value: lo.ToPtr(decimal.NewFromBigInt(event.Amount1, 0)), + Value: lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(event.Amount1), 0)), }, } @@ -874,11 +805,11 @@ func (w *worker) transformNonfungiblePositionManagerDecreaseLiquidityLog(ctx con tokens := []metadata.Token{ { Address: lo.ToPtr(positions.Token0.String()), - Value: lo.ToPtr(decimal.NewFromBigInt(event.Amount0, 0)), + Value: lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(event.Amount0), 0)), }, { Address: lo.ToPtr(positions.Token1.String()), - Value: lo.ToPtr(decimal.NewFromBigInt(event.Amount1, 0)), + Value: lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(event.Amount1), 0)), }, } @@ -918,11 +849,11 @@ func (w *worker) transformNonfungiblePositionManagerCollectLog(ctx context.Conte tokens := []metadata.Token{ { Address: lo.ToPtr(positions.Token0.String()), - Value: lo.ToPtr(decimal.NewFromBigInt(event.Amount0, 0)), + Value: lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(event.Amount0), 0)), }, { Address: lo.ToPtr(positions.Token1.String()), - Value: lo.ToPtr(decimal.NewFromBigInt(event.Amount1, 0)), + Value: lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(event.Amount1), 0)), }, } @@ -957,27 +888,19 @@ func (w *worker) transformNonfungiblePositionManagerTransferLog(ctx context.Cont } func (w *worker) buildExchangeSwapAction(ctx context.Context, task *source.Task, sender, receipt common.Address, tokenIn, tokenOut *common.Address, amountIn, amountOut *big.Int) (*activityx.Action, error) { - zap.L().Debug("building exchange swap action", - zap.String("sender", sender.String()), - zap.String("receipt", receipt.String()), - zap.Any("token_in", tokenIn), - zap.Any("token_out", tokenOut), - zap.Any("amount_in", amountIn), - zap.Any("amount_out", amountOut)) - tokenInMetadata, err := w.tokenClient.Lookup(ctx, task.ChainID, tokenIn, nil, task.Header.Number) if err != nil { return nil, fmt.Errorf("lookup token metadata %s: %w", tokenIn, err) } - tokenInMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(amountIn, 0).Abs()) + tokenInMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(amountIn), 0).Abs()) tokenOutMetadata, err := w.tokenClient.Lookup(ctx, task.ChainID, tokenOut, nil, task.Header.Number) if err != nil { return nil, fmt.Errorf("lookup token metadata %s: %w", tokenOut, err) } - tokenOutMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(amountOut, 0).Abs()) + tokenOutMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(amountOut), 0).Abs()) action := activityx.Action{ Type: typex.ExchangeSwap, @@ -990,8 +913,6 @@ func (w *worker) buildExchangeSwapAction(ctx context.Context, task *source.Task, }, } - zap.L().Debug("successfully built exchange swap action") - return &action, nil } @@ -1040,12 +961,6 @@ func (w *worker) transformWETHWithdrawalLog(ctx context.Context, task *source.Ta } func (w *worker) buildExchangeLiquidityAction(ctx context.Context, task *source.Task, sender, receipt common.Address, liquidityAction metadata.ExchangeLiquidityAction, tokens []metadata.Token) (*activityx.Action, error) { - zap.L().Debug("building exchange liquidity action", - zap.String("sender", sender.String()), - zap.String("receipt", receipt.String()), - zap.String("liquidity_action", liquidityAction.String()), - zap.Any("tokens", tokens)) - tokenMetadataSlice := make([]metadata.Token, 0, len(tokens)) for _, t := range tokens { @@ -1075,24 +990,16 @@ func (w *worker) buildExchangeLiquidityAction(ctx context.Context, task *source. }, } - zap.L().Debug("successfully built exchange liquidity action") - return &action, nil } func (w *worker) buildTransactionMintAction(ctx context.Context, task *source.Task, sender, receipt, tokenAddress common.Address, tokenID *big.Int) (*activityx.Action, error) { - zap.L().Debug("building transaction mint action", - zap.String("sender", sender.String()), - zap.String("receipt", receipt.String()), - zap.String("token_address", tokenAddress.String()), - zap.Any("token_id", tokenID)) - tokenMetadata, err := w.tokenClient.Lookup(ctx, task.ChainID, &tokenAddress, tokenID, task.Header.Number) if err != nil { return nil, fmt.Errorf("lookup token metadata %s %d: %w", tokenAddress, tokenID, err) } - tokenMetadata.ID = lo.ToPtr(decimal.NewFromBigInt(tokenID, 0)) + tokenMetadata.ID = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(tokenID), 0)) tokenMetadata.Value = lo.ToPtr(decimal.NewFromInt(1)) action := activityx.Action{ @@ -1103,8 +1010,6 @@ func (w *worker) buildTransactionMintAction(ctx context.Context, task *source.Ta Metadata: metadata.TransactionTransfer(*tokenMetadata), } - zap.L().Debug("successfully built transaction mint action") - return &action, nil } diff --git a/internal/engine/worker/decentralized/contract/vsl/worker.go b/internal/engine/worker/decentralized/contract/vsl/worker.go index df16574f6..dad5de0bd 100644 --- a/internal/engine/worker/decentralized/contract/vsl/worker.go +++ b/internal/engine/worker/decentralized/contract/vsl/worker.go @@ -9,6 +9,7 @@ import ( "github.com/rss3-network/node/config" "github.com/rss3-network/node/internal/engine" source "github.com/rss3-network/node/internal/engine/protocol/ethereum" + "github.com/rss3-network/node/internal/utils" "github.com/rss3-network/node/provider/ethereum" "github.com/rss3-network/node/provider/ethereum/contract/vsl" "github.com/rss3-network/node/provider/ethereum/token" @@ -21,7 +22,6 @@ import ( "github.com/rss3-network/protocol-go/schema/typex" "github.com/samber/lo" "github.com/shopspring/decimal" - "go.uber.org/zap" ) var _ engine.Worker = (*worker)(nil) @@ -79,8 +79,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, fmt.Errorf("invalid task type: %T", task) } - zap.L().Debug("transforming vsl task", zap.String("task", ethereumTask.ID())) - activity, err := ethereumTask.BuildActivity(activityx.WithActivityPlatform(w.Platform())) if err != nil { return nil, fmt.Errorf("build activity: %w", err) @@ -94,34 +92,19 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac // Ignore anonymous logs. if len(log.Topics) == 0 { - zap.L().Debug("ignoring anonymous log") - continue } - zap.L().Debug("transforming vsl log", - zap.String("address", log.Address.String()), - zap.String("topic", log.Topics[0].String())) - switch { case w.matchL1StandardBridgeETHDepositInitiatedLog(ethereumTask, log): - zap.L().Debug("transforming l1 standard bridge eth deposit initiated log") - actions, err = w.transformL1StandardBridgeETHDepositInitiatedLog(ctx, ethereumTask, log) case w.matchL1StandardBridgeERC20DepositInitiatedLog(ethereumTask, log): - zap.L().Debug("transforming l1 standard bridge erc20 deposit initiated log") - actions, err = w.transformL1StandardBridgeERC20DepositInitiatedLog(ctx, ethereumTask, log) case w.matchL1StandardBridgeETHWithdrawalFinalizedLog(ethereumTask, log): - zap.L().Debug("transforming l1 standard bridge eth withdrawal finalized log") - actions, err = w.transformL1StandardBridgeETHWithdrawalFinalizedLog(ctx, ethereumTask, log) case w.matchL1StandardBridgeERC20WithdrawalFinalizedLog(ethereumTask, log): - zap.L().Debug("transforming l1 standard bridge erc20 withdrawal finalized log") - actions, err = w.transformL1StandardBridgeERC20WithdrawalFinalizedLog(ctx, ethereumTask, log) default: - zap.L().Debug("no matching vsl log") continue } @@ -133,8 +116,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac activity.Actions = append(activity.Actions, actions...) } - zap.L().Debug("successfully transformed vsl task") - return activity, nil } @@ -227,21 +208,12 @@ func (w *worker) transformL1StandardBridgeERC20WithdrawalFinalizedLog(ctx contex } func (w *worker) buildTransactionBridgeAction(ctx context.Context, chainID uint64, sender, receiver common.Address, source, target network.Network, bridgeAction metadata.TransactionBridgeAction, tokenAddress *common.Address, tokenValue *big.Int, blockNumber *big.Int) (*activityx.Action, error) { - zap.L().Debug("building transaction bridge action", - zap.String("sender", sender.String()), - zap.String("receiver", receiver.String()), - zap.String("source", source.String()), - zap.String("target", target.String()), - zap.String("bridge_action", bridgeAction.String()), - zap.Any("token_address", tokenAddress), - zap.Any("token_value", tokenValue)) - tokenMetadata, err := w.tokenClient.Lookup(ctx, chainID, tokenAddress, nil, blockNumber) if err != nil { return nil, fmt.Errorf("lookup token %s: %w", tokenAddress, err) } - tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(tokenValue, 0)) + tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(tokenValue), 0)) action := activityx.Action{ Type: typex.TransactionBridge, @@ -256,8 +228,6 @@ func (w *worker) buildTransactionBridgeAction(ctx context.Context, chainID uint6 }, } - zap.L().Debug("successfully built transaction bridge action") - return &action, nil } diff --git a/internal/engine/worker/decentralized/contract/zerion/worker.go b/internal/engine/worker/decentralized/contract/zerion/worker.go index 136341111..85bbade9a 100644 --- a/internal/engine/worker/decentralized/contract/zerion/worker.go +++ b/internal/engine/worker/decentralized/contract/zerion/worker.go @@ -9,6 +9,7 @@ import ( "github.com/rss3-network/node/config" "github.com/rss3-network/node/internal/engine" source "github.com/rss3-network/node/internal/engine/protocol/ethereum" + "github.com/rss3-network/node/internal/utils" "github.com/rss3-network/node/provider/ethereum" "github.com/rss3-network/node/provider/ethereum/contract" "github.com/rss3-network/node/provider/ethereum/contract/erc20" @@ -97,8 +98,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, fmt.Errorf("invalid task type %T", task) } - zap.L().Debug("transforming zerion task", zap.String("task", ethereumTask.ID())) - activity, err := ethereumTask.BuildActivity(activityx.WithActivityPlatform(w.Platform())) if err != nil { @@ -108,19 +107,11 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac // Iterate through all logs in the transaction receipt for _, log := range ethereumTask.Receipt.Logs { if len(log.Topics) == 0 { - zap.L().Debug("ignoring anonymous log") - continue } - zap.L().Debug("transforming zerion log", - zap.String("address", log.Address.String()), - zap.String("topic", log.Topics[0].String())) - switch { case w.matchSwapLog(ethereumTask, log): - zap.L().Debug("transforming zerion swap log") - actions, err := w.transformSwapLog(ctx, ethereumTask, log) if err != nil { zap.L().Error("handle settlement trade log", zap.Error(err), zap.String("task", ethereumTask.ID())) @@ -129,9 +120,8 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac } activity.Actions = append(activity.Actions, actions...) - default: - zap.L().Debug("no matching zerion log") + continue } } @@ -141,8 +131,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac activity.Type = typex.ExchangeSwap - zap.L().Debug("successfully transformed zerion task") - return activity, nil } @@ -184,20 +172,12 @@ func (w *worker) transformSwapLog(ctx context.Context, task *source.Task, log *e // buildTransactionTransferAction creates a TransactionTransfer action for a given transfer. func (w *worker) buildTransactionTransferAction(ctx context.Context, task *source.Task, from, to common.Address, tokenAddress *common.Address, amount *big.Int) (*activityx.Action, error) { - zap.L().Debug("building transaction transfer action", - zap.String("from", from.String()), - zap.String("to", to.String()), - zap.Any("token_address", tokenAddress), - zap.Any("amount", amount)) - tokenMetadata, err := w.tokenClient.Lookup(ctx, task.ChainID, tokenAddress, nil, task.Header.Number) if err != nil { return nil, fmt.Errorf("lookup token metadata: %w", err) } - tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(amount, 0)) - - zap.L().Debug("successfully built transaction transfer action") + tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(amount), 0)) return &activityx.Action{ Type: typex.TransactionTransfer, @@ -210,14 +190,6 @@ func (w *worker) buildTransactionTransferAction(ctx context.Context, task *sourc // buildExchangeSwapAction creates an ExchangeSwap action for a given swap. func (w *worker) buildExchangeSwapAction(ctx context.Context, task *source.Task, from, to, tokenIn, tokenOut common.Address, amountIn, amountOut *big.Int) (*activityx.Action, error) { - zap.L().Debug("building exchange swap action", - zap.String("from", from.String()), - zap.String("to", to.String()), - zap.String("token_in", tokenIn.String()), - zap.String("token_out", tokenOut.String()), - zap.Any("amount_in", amountIn), - zap.Any("amount_out", amountOut)) - tokenInAddress := lo.Ternary(tokenIn != zerion.AddressNativeToken, &tokenIn, nil) tokenOutAddress := lo.Ternary(tokenOut != zerion.AddressNativeToken, &tokenOut, nil) @@ -226,16 +198,14 @@ func (w *worker) buildExchangeSwapAction(ctx context.Context, task *source.Task, return nil, fmt.Errorf("lookup token in metadata: %w", err) } - tokenInMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(amountIn, 0)) + tokenInMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(amountIn), 0)) tokenOutMetadata, err := w.tokenClient.Lookup(ctx, task.ChainID, tokenOutAddress, nil, task.Header.Number) if err != nil { return nil, fmt.Errorf("lookup token out metadata: %w", err) } - tokenOutMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(amountOut, 0)) - - zap.L().Debug("successfully built exchange swap action") + tokenOutMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(amountOut), 0)) return &activityx.Action{ Type: typex.ExchangeSwap, diff --git a/internal/engine/worker/decentralized/core/arweave/worker.go b/internal/engine/worker/decentralized/core/arweave/worker.go index 84bd51a10..165aa52b3 100644 --- a/internal/engine/worker/decentralized/core/arweave/worker.go +++ b/internal/engine/worker/decentralized/core/arweave/worker.go @@ -8,6 +8,7 @@ import ( "github.com/rss3-network/node/config" "github.com/rss3-network/node/internal/engine" source "github.com/rss3-network/node/internal/engine/protocol/arweave" + "github.com/rss3-network/node/internal/utils" "github.com/rss3-network/node/provider/arweave" workerx "github.com/rss3-network/node/schema/worker/decentralized" "github.com/rss3-network/protocol-go/schema" @@ -18,7 +19,6 @@ import ( "github.com/rss3-network/protocol-go/schema/typex" "github.com/samber/lo" "github.com/shopspring/decimal" - "go.uber.org/zap" ) var _ engine.Worker = (*worker)(nil) @@ -68,8 +68,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, fmt.Errorf("invalid task type: %T", task) } - zap.L().Debug("transforming arweave task", zap.String("task_id", arweaveTask.ID())) - // Build the activity. activity, err := task.BuildActivity() if err != nil { @@ -88,8 +86,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac activity.Actions = append(activity.Actions, action) } - zap.L().Debug("successfully transformed arweave task") - return activity, nil } @@ -124,23 +120,14 @@ func (w *worker) handleArweaveNativeTransferTransaction(ctx context.Context, tas // buildArweaveTransactionTransferAction returns the native transfer transaction action. func (w *worker) buildArweaveTransactionTransferAction(_ context.Context, from, to string, tokenValue *big.Int) (*activityx.Action, error) { - zap.L().Debug("building arweave transaction transfer action", - zap.String("from", from), - zap.String("to", to), - zap.Any("token_value", tokenValue)) - - action := activityx.Action{ + return &activityx.Action{ Type: typex.TransactionTransfer, From: from, To: to, Metadata: metadata.TransactionTransfer{ - Value: lo.ToPtr(decimal.NewFromBigInt(tokenValue, 0)), + Value: lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(tokenValue), 0)), }, - } - - zap.L().Debug("successfully built arweave transaction transfer action") - - return &action, nil + }, nil } // NewWorker returns a new Arweave worker. diff --git a/internal/engine/worker/decentralized/core/ethereum/worker.go b/internal/engine/worker/decentralized/core/ethereum/worker.go index 533047779..1f2ad6430 100644 --- a/internal/engine/worker/decentralized/core/ethereum/worker.go +++ b/internal/engine/worker/decentralized/core/ethereum/worker.go @@ -12,6 +12,7 @@ import ( "github.com/rss3-network/node/config" "github.com/rss3-network/node/internal/engine" source "github.com/rss3-network/node/internal/engine/protocol/ethereum" + "github.com/rss3-network/node/internal/utils" "github.com/rss3-network/node/provider/ethereum" "github.com/rss3-network/node/provider/ethereum/contract" "github.com/rss3-network/node/provider/ethereum/contract/erc1155" @@ -32,7 +33,6 @@ import ( "github.com/sourcegraph/conc/pool" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/trace" - "go.uber.org/zap" ) var _ engine.Worker = (*worker)(nil) @@ -117,8 +117,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, fmt.Errorf("invalid task type: %T", task) } - zap.L().Debug("transforming ethereum task", zap.String("task_id", ethereumTask.ID())) - activity, err := task.BuildActivity() if err != nil { return nil, fmt.Errorf("build activity: %w", err) @@ -132,8 +130,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac } if w.matchNativeTransferTransaction(ethereumTask) { - zap.L().Debug("handling native transfer transaction") - action, err := w.handleNativeTransferTransaction(ctx, ethereumTask) if err != nil { return nil, fmt.Errorf("handle native transfer transaction: %w", err) @@ -157,13 +153,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac continue } - zap.L().Debug("handling ethereum log", - zap.String("task_id", ethereumTask.ID()), - zap.Uint("log_index", log.Index), - zap.String("address", log.Address.String()), - zap.Any("topic", log.Topics[0]), - ) - contextPool.Go(func(ctx context.Context) error { var ( logActions []*activityx.Action @@ -173,49 +162,27 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac switch { // VSL Bridge case w.matchL2StandardBridgeWithdrawalInitiatedLog(ethereumTask, log): - zap.L().Debug("handling l2 standard bridge withdrawal initiated log", zap.String("task_id", ethereumTask.ID())) - logActions, err = w.transformL2StandardBridgeWithdrawalInitiatedLog(ctx, ethereumTask, log) case w.matchL2StandardBridgeDepositFinalizedLog(ethereumTask, log): - zap.L().Debug("handling l2 standard bridge deposit finalized log", zap.String("task_id", ethereumTask.ID())) - logActions, err = w.transformL2StandardBridgeDepositFinalizedLog(ctx, ethereumTask, log) // VSL Staking case w.matchStakingVSLDeposited(ethereumTask, log): - zap.L().Debug("handling staking vsl deposited log", zap.String("task_id", ethereumTask.ID())) - logActions, err = w.handleStakingVSLDeposited(ctx, ethereumTask, log) case w.matchStakingVSLStaked(ethereumTask, log): - zap.L().Debug("handling staking vsl staked log", zap.String("task_id", ethereumTask.ID())) - logActions, err = w.handleStakingVSLStaked(ctx, ethereumTask, log) case w.matchChipsTransfer(ethereumTask, log): - zap.L().Debug("handling chips mint log", zap.String("task_id", ethereumTask.ID())) - logActions, err = w.handleChipsMint(ctx, ethereumTask, log) case w.matchERC20TransferLog(ethereumTask, log): - zap.L().Debug("handling erc20 transfer log", zap.String("task_id", ethereumTask.ID())) - logActions, err = w.handleERC20TransferLog(ctx, ethereumTask, log) case w.matchERC20ApprovalLog(ethereumTask, log): - zap.L().Debug("handling erc20 approval log", zap.String("task_id", ethereumTask.ID())) - logActions, err = w.handleERC20ApproveLog(ctx, ethereumTask, log) case w.matchERC721TransferLog(ethereumTask, log): - zap.L().Debug("handling erc721 transfer log", zap.String("task_id", ethereumTask.ID())) - logActions, err = w.handleERC721TransferLog(ctx, ethereumTask, log) case w.matchERC721ApprovalLog(ethereumTask, log): - zap.L().Debug("handling erc721 approval log", zap.String("task_id", ethereumTask.ID())) - logActions, err = w.handleERC721ApproveLog(ctx, ethereumTask, log) case w.matchERC1155TransferLog(ethereumTask, log): - zap.L().Debug("handling erc1155 transfer log", zap.String("task_id", ethereumTask.ID())) - logActions, err = w.handleERC1155TransferLog(ctx, ethereumTask, log) case w.matchERC1155ApprovalLog(ethereumTask, log): - zap.L().Debug("handling erc1155 approval log", zap.String("task_id", ethereumTask.ID())) - logActions, err = w.handleERC1155ApproveLog(ctx, ethereumTask, log) } @@ -243,8 +210,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac activity.Type = action.Type } - zap.L().Debug("successfully transformed ethereum task") - return activity, nil } @@ -564,14 +529,6 @@ func (w *worker) transformL2StandardBridgeDepositFinalizedLog(ctx context.Contex } func (w *worker) buildTransactionTransferAction(ctx context.Context, task *source.Task, from, to common.Address, tokenAddress *common.Address, tokenValue *big.Int) (*activityx.Action, error) { - zap.L().Debug("building transaction transfer action", - zap.String("task_id", task.ID()), - zap.String("from", from.String()), - zap.String("to", to.String()), - zap.Any("token_address", tokenAddress), - zap.Any("token_value", tokenValue), - ) - chainID, err := network.EthereumChainIDString(task.GetNetwork().String()) if err != nil { return nil, fmt.Errorf("invalid chain id: %w", err) @@ -582,12 +539,7 @@ func (w *worker) buildTransactionTransferAction(ctx context.Context, task *sourc return nil, fmt.Errorf("lookup token %s: %w", tokenAddress, err) } - // If the token value is nil, set it to zero. - if tokenValue == nil { - tokenValue = big.NewInt(0) - } - - tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(tokenValue, 0)) + tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(tokenValue), 0)) var actionType typex.TransactionType @@ -607,20 +559,10 @@ func (w *worker) buildTransactionTransferAction(ctx context.Context, task *sourc Metadata: metadata.TransactionTransfer(*tokenMetadata), } - zap.L().Debug("successfully built transaction transfer action", zap.String("task_id", task.ID())) - return &action, nil } func (w *worker) buildTransactionApprovalAction(ctx context.Context, task *source.Task, from, to common.Address, tokenAddress *common.Address, tokenValue *big.Int) (*activityx.Action, error) { - zap.L().Debug("building transaction approval action", - zap.String("task_id", task.ID()), - zap.String("from", from.String()), - zap.String("to", to.String()), - zap.Any("token_address", tokenAddress), - zap.Any("token_value", tokenValue), - ) - chainID, err := network.EthereumChainIDString(task.GetNetwork().String()) if err != nil { return nil, fmt.Errorf("invalid chain id: %w", err) @@ -631,12 +573,7 @@ func (w *worker) buildTransactionApprovalAction(ctx context.Context, task *sourc return nil, fmt.Errorf("lookup token %s: %w", tokenAddress, err) } - // If the token value is nil, set it to zero. - if tokenValue == nil { - tokenValue = big.NewInt(0) - } - - tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(tokenValue, 0)) + tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(tokenValue), 0)) // Use the token value to determine the action type. metadataAction := metadata.ActionTransactionApprove @@ -654,21 +591,10 @@ func (w *worker) buildTransactionApprovalAction(ctx context.Context, task *sourc }, } - zap.L().Debug("successfully built transaction approval action", zap.String("task_id", task.ID())) - return &action, nil } func (w *worker) buildCollectibleTransferAction(ctx context.Context, task *source.Task, from, to common.Address, tokenAddress common.Address, tokenID *big.Int, tokenValue *big.Int) (*activityx.Action, error) { - zap.L().Debug("building collectible transfer action", - zap.String("task_id", task.ID()), - zap.String("from", from.String()), - zap.String("to", to.String()), - zap.String("token_address", tokenAddress.String()), - zap.Any("token_id", tokenID), - zap.Any("token_value", tokenValue), - ) - chainID, err := network.EthereumChainIDString(task.GetNetwork().String()) if err != nil { return nil, fmt.Errorf("invalid chain id: %w", err) @@ -679,12 +605,7 @@ func (w *worker) buildCollectibleTransferAction(ctx context.Context, task *sourc return nil, fmt.Errorf("lookup token %s: %w", tokenAddress, err) } - // If the token value is nil, set it to zero. - if tokenValue == nil { - tokenValue = big.NewInt(0) - } - - tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(tokenValue, 0)) + tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(tokenValue), 0)) var actionType typex.CollectibleType @@ -704,21 +625,10 @@ func (w *worker) buildCollectibleTransferAction(ctx context.Context, task *sourc Metadata: metadata.CollectibleTransfer(*tokenMetadata), } - zap.L().Debug("successfully built collectible transfer action", zap.String("task_id", task.ID())) - return &action, nil } func (w *worker) buildCollectibleApprovalAction(ctx context.Context, task *source.Task, from common.Address, to common.Address, tokenAddress common.Address, id *big.Int, approved *bool) (*activityx.Action, error) { - zap.L().Debug("building collectible approval action", - zap.String("task_id", task.ID()), - zap.String("from", from.String()), - zap.String("to", to.String()), - zap.String("token_address", tokenAddress.String()), - zap.Any("id", id), - zap.Any("approved", approved), - ) - chainID, err := network.EthereumChainIDString(task.GetNetwork().String()) if err != nil { return nil, fmt.Errorf("invalid chain id: %w", err) @@ -752,33 +662,18 @@ func (w *worker) buildCollectibleApprovalAction(ctx context.Context, task *sourc }, } - zap.L().Debug("successfully built collectible approval action", zap.String("task_id", task.ID())) - return &action, nil } // buildExchangeStakingVSLAction builds the exchange staking VSL action. func (w *worker) buildExchangeStakingVSLAction(ctx context.Context, task *source.Task, from, to common.Address, tokenValue *big.Int, stakingAction metadata.ExchangeStakingAction) (*activityx.Action, error) { - zap.L().Debug("building exchange staking vsl action", - zap.String("task_id", task.ID()), - zap.String("from", from.String()), - zap.String("to", to.String()), - zap.Any("token_value", tokenValue), - zap.String("staking_action", stakingAction.String()), - ) - // The Token always is $RSS3. tokenMetadata, err := w.tokenClient.Lookup(ctx, task.ChainID, nil, nil, task.Header.Number) if err != nil { return nil, fmt.Errorf("lookup token: %w", err) } - // If the token value is nil, set it to zero. - if tokenValue == nil { - tokenValue = big.NewInt(0) - } - - tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(tokenValue, 0)) + tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(tokenValue), 0)) action := activityx.Action{ Type: typex.ExchangeStaking, @@ -791,35 +686,17 @@ func (w *worker) buildExchangeStakingVSLAction(ctx context.Context, task *source }, } - zap.L().Debug("successfully built exchange staking vsl action", zap.String("task_id", task.ID())) - return &action, nil } // buildChipsMintAction builds the ChipsMint action. func (w *worker) buildChipsMintAction(ctx context.Context, task *source.Task, from, to common.Address, contract common.Address, id *big.Int, value *big.Int) (*activityx.Action, error) { - zap.L().Debug("building chips mint action", - zap.String("task_id", task.ID()), - zap.String("from", from.String()), - zap.String("to", to.String()), - zap.Any("contract", contract), - zap.Any("id", id), - zap.Any("value", value), - ) - tokenMetadata, err := w.tokenClient.Lookup(ctx, task.ChainID, &contract, id, task.Header.Number) if err != nil { return nil, fmt.Errorf("lookup token metadata: %w", err) } - // If the token value is nil, set it to zero. - if value == nil { - value = big.NewInt(0) - } - - tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(value, 0)) - - zap.L().Debug("successfully built chips mint action", zap.String("task_id", task.ID())) + tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(value), 0)) return &activityx.Action{ Type: typex.CollectibleMint, @@ -831,27 +708,12 @@ func (w *worker) buildChipsMintAction(ctx context.Context, task *source.Task, fr } func (w *worker) buildTransactionBridgeAction(ctx context.Context, chainID uint64, sender, receiver common.Address, source, target network.Network, bridgeAction metadata.TransactionBridgeAction, tokenAddress *common.Address, tokenValue *big.Int, blockNumber *big.Int) (*activityx.Action, error) { - zap.L().Debug("building transaction bridge action", - zap.String("sender", sender.String()), - zap.String("receiver", receiver.String()), - zap.String("source", source.String()), - zap.String("target", target.String()), - zap.String("bridge_action", bridgeAction.String()), - zap.Any("token_address", tokenAddress), - zap.Any("token_value", tokenValue), - ) - tokenMetadata, err := w.tokenClient.Lookup(ctx, chainID, tokenAddress, nil, blockNumber) if err != nil { return nil, fmt.Errorf("lookup token %s: %w", tokenAddress, err) } - // If the token value is nil, set it to zero. - if tokenValue == nil { - tokenValue = big.NewInt(0) - } - - tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(tokenValue, 0)) + tokenMetadata.Value = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(tokenValue), 0)) action := activityx.Action{ Type: typex.TransactionBridge, @@ -866,8 +728,6 @@ func (w *worker) buildTransactionBridgeAction(ctx context.Context, chainID uint6 }, } - zap.L().Debug("successfully built transaction bridge action") - return &action, nil } diff --git a/internal/engine/worker/decentralized/core/farcaster/worker.go b/internal/engine/worker/decentralized/core/farcaster/worker.go index dc6cc5071..dc88f2131 100644 --- a/internal/engine/worker/decentralized/core/farcaster/worker.go +++ b/internal/engine/worker/decentralized/core/farcaster/worker.go @@ -69,8 +69,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, fmt.Errorf("invalid task type: %T", task) } - zap.L().Debug("transforming farcaster task", zap.String("task_id", farcasterTask.ID())) - activity, err := task.BuildActivity(activityx.WithActivityPlatform(w.Platform())) if err != nil { return nil, fmt.Errorf("build activity: %w", err) @@ -79,33 +77,22 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac // Handle Farcaster message. switch farcasterTask.Message.Data.Type { case farcaster.MessageTypeCastAdd.String(): - zap.L().Debug("handling farcaster add cast message") - w.handleFarcasterAddCast(ctx, farcasterTask.Message, activity) case farcaster.MessageTypeReactionAdd.String(): - zap.L().Debug("handling farcaster recast reaction message") - w.handleFarcasterRecastReaction(ctx, farcasterTask.Message, activity) default: - zap.L().Warn("unsupported farcaster message type", zap.String("type", farcasterTask.Message.Data.Type)) + zap.L().Debug("unsupported farcaster message type", zap.String("type", farcasterTask.Message.Data.Type)) } if len(activity.Actions) == 0 { return nil, nil } - zap.L().Debug("successfully transformed farcaster task") - return activity, nil } // handleFarcasterAddCast handles farcaster add cast message. func (w *worker) handleFarcasterAddCast(ctx context.Context, message farcaster.Message, activity *activityx.Activity) { - zap.L().Debug("handling farcaster add cast message", - zap.Int64("fid", int64(message.Data.Fid)), - zap.String("hash", message.Hash), - zap.Any("body", message.Data.CastAddBody)) - fid := int64(message.Data.Fid) post := w.buildPost(ctx, int64(message.Data.Fid), message.Hash, message.Data.CastAddBody, farcaster.CovertFarcasterTimeToTimestamp(int64(message.Data.Timestamp))) @@ -115,30 +102,16 @@ func (w *worker) handleFarcasterAddCast(ctx context.Context, message farcaster.M // this represents a reply post. if message.Data.CastAddBody.ParentCastID != nil { - zap.L().Debug("handling farcaster reply post", - zap.Int64("parent_cast_id_fid", int64(message.Data.CastAddBody.ParentCastID.Fid)), - zap.String("parent_cast_id_hash", message.Data.CastAddBody.ParentCastID.Hash), - zap.Any("parent_cast", message.Data.CastAddBody.ParentCast)) - activity.Type = typex.SocialComment - targetFid := int64(message.Data.CastAddBody.ParentCastID.Fid) - targetMessage := message.Data.CastAddBody.ParentCast - post.Target = w.buildPost(ctx, targetFid, targetMessage.Hash, targetMessage.Data.CastAddBody, farcaster.CovertFarcasterTimeToTimestamp(int64(targetMessage.Data.Timestamp))) // this represents a reply to self. if fid == targetFid { - zap.L().Debug("handling farcaster reply to self post") - post.Target.Handle = post.Handle - activity.To = activity.From - w.buildPostActions(ctx, message.Data.Profile.EthAddresses, activity, post, activity.Type) - zap.L().Debug("successfully handled farcaster reply to self post") - return } @@ -159,52 +132,30 @@ func (w *worker) handleFarcasterAddCast(ctx context.Context, message farcaster.M } } - zap.L().Debug("successfully handled farcaster reply post") - return } activity.Type = typex.SocialPost activity.To = activity.From - w.buildPostActions(ctx, message.Data.Profile.EthAddresses, activity, post, activity.Type) - - zap.L().Debug("successfully handled farcaster add cast message") } // handleFarcasterRecastReaction handles farcaster recast reaction message. func (w *worker) handleFarcasterRecastReaction(ctx context.Context, message farcaster.Message, activity *activityx.Activity) { - zap.L().Debug("handling farcaster recast reaction message", - zap.Int64("fid", int64(message.Data.Fid)), - zap.String("hash", message.Hash), - zap.Any("reaction_body", message.Data.ReactionBody)) - fid := int64(message.Data.Fid) - post := w.buildPost(ctx, int64(message.Data.Fid), message.Hash, nil, farcaster.CovertFarcasterTimeToTimestamp(int64(message.Data.Timestamp))) - post.Handle = message.Data.Profile.Username activity.From = message.Data.Profile.CustodyAddress - activity.Type = typex.SocialShare - targetFid := int64(message.Data.ReactionBody.TargetCastID.Fid) - targetMessage := message.Data.ReactionBody.TargetCast - post.Target = w.buildPost(ctx, targetFid, targetMessage.Hash, targetMessage.Data.CastAddBody, farcaster.CovertFarcasterTimeToTimestamp(int64(targetMessage.Data.Timestamp))) if fid == targetFid { - zap.L().Debug("handling farcaster recast to self post") - post.Target.Handle = post.Handle - activity.To = activity.From - w.buildPostActions(ctx, message.Data.Profile.EthAddresses, activity, post, activity.Type) - zap.L().Debug("successfully handled farcaster recast to self post") - return } @@ -223,8 +174,6 @@ func (w *worker) handleFarcasterRecastReaction(ctx context.Context, message farc activity.Actions = append(activity.Actions, &action) } } - - zap.L().Debug("successfully handled farcaster recast reaction message") } // buildPostActions builds post actions from message. @@ -237,6 +186,7 @@ func (w *worker) buildPostActions(_ context.Context, ethAddresses []string, acti To: from, Metadata: *post, } + activity.Actions = append(activity.Actions, &action) } } diff --git a/internal/engine/worker/decentralized/core/near/worker.go b/internal/engine/worker/decentralized/core/near/worker.go index fa5fdadd0..10a733b0d 100644 --- a/internal/engine/worker/decentralized/core/near/worker.go +++ b/internal/engine/worker/decentralized/core/near/worker.go @@ -8,6 +8,7 @@ import ( "github.com/rss3-network/node/config" "github.com/rss3-network/node/internal/engine" source "github.com/rss3-network/node/internal/engine/protocol/near" + "github.com/rss3-network/node/internal/utils" "github.com/rss3-network/node/provider/near" workerx "github.com/rss3-network/node/schema/worker/decentralized" "github.com/rss3-network/protocol-go/schema" @@ -18,7 +19,6 @@ import ( "github.com/rss3-network/protocol-go/schema/typex" "github.com/samber/lo" "github.com/shopspring/decimal" - "go.uber.org/zap" ) var _ engine.Worker = (*worker)(nil) @@ -68,8 +68,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, fmt.Errorf("invalid task type: %T", task) } - zap.L().Debug("transforming near task", zap.String("task_id", nearTask.ID())) - // Build the activity. activity, err := task.BuildActivity() if err != nil { @@ -89,8 +87,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, fmt.Errorf("no actions found in transaction") } - zap.L().Debug("successfully transformed near task") - return activity, nil } @@ -130,12 +126,7 @@ func (w *worker) handleNearTransferAction(ctx context.Context, from, to string, // buildNearTransactionTransferAction returns the native transfer transaction action. func (w *worker) buildNearTransactionTransferAction(_ context.Context, from, to string, tokenValue *big.Int) (*activityx.Action, error) { - zap.L().Debug("building near transaction transfer action", - zap.String("from", from), - zap.String("to", to), - zap.Any("token_value", tokenValue)) - - action := &activityx.Action{ + return &activityx.Action{ Type: typex.TransactionTransfer, From: from, To: to, @@ -143,13 +134,9 @@ func (w *worker) buildNearTransactionTransferAction(_ context.Context, from, to Name: "NEAR", Symbol: "NEAR", Decimals: 24, - Value: lo.ToPtr(decimal.NewFromBigInt(tokenValue, 0)), + Value: lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(tokenValue), 0)), }, - } - - zap.L().Debug("successfully built near transaction transfer action") - - return action, nil + }, nil } // NewWorker returns a new Near worker. diff --git a/internal/engine/worker/federated/core/mastodon/worker.go b/internal/engine/worker/federated/core/mastodon/worker.go index 2651f0bda..f1a4873df 100644 --- a/internal/engine/worker/federated/core/mastodon/worker.go +++ b/internal/engine/worker/federated/core/mastodon/worker.go @@ -79,8 +79,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, fmt.Errorf("invalid task type: %T", task) } - zap.L().Debug("transforming mastodon task", zap.String("task_id", activityPubTask.ID())) - activity, err := task.BuildActivity(activityx.WithActivityPlatform(w.Platform())) if err != nil { @@ -90,15 +88,11 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac // Handle ActivityPub message. switch activityPubTask.Message.Type { case mastodon.MessageTypeCreate.String(): - zap.L().Debug("handling mastodon create message") - err = w.handleActivityPubCreate(ctx, activityPubTask.Message, activity) case mastodon.MessageTypeAnnounce.String(): - zap.L().Debug("handling mastodon announce message") - err = w.handleActivityPubAnnounce(ctx, activityPubTask.Message, activity) default: - zap.L().Warn("unsupported type", zap.String("type", activityPubTask.Message.Type)) + zap.L().Debug("unsupported type", zap.String("type", activityPubTask.Message.Type)) return nil, nil } @@ -107,8 +101,6 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac return nil, fmt.Errorf("handle %s message: %w", activityPubTask.Message.Type, err) } - zap.L().Debug("successfully transformed mastodon task") - return activity, nil } @@ -450,7 +442,7 @@ func (w *worker) buildPostMedia(post *metadata.SocialPost, attachments interface post.Media = append(post.Media, media) } default: - zap.L().Debug("Unexpected attachments type", zap.String("type", fmt.Sprintf("%T", attachments))) + zap.L().Debug("unexpected attachments type", zap.String("type", fmt.Sprintf("%T", attachments))) } } @@ -489,7 +481,7 @@ func (w *worker) buildPostTags(post *metadata.SocialPost, tags interface{}) { processTag(t.Type, t.Name) } default: - zap.L().Debug("Unexpected tags type", zap.String("type", fmt.Sprintf("%T", tags))) + zap.L().Debug("unexpected tags type", zap.String("type", fmt.Sprintf("%T", tags))) } } diff --git a/internal/node/component/decentralized/component.go b/internal/node/component/decentralized/component.go index ce3c8511a..5986809a7 100644 --- a/internal/node/component/decentralized/component.go +++ b/internal/node/component/decentralized/component.go @@ -73,7 +73,7 @@ func NewComponent(_ context.Context, apiServer *echo.Echo, config *config.File, // Initialize etherface client, an optional dependency etherfaceClient, err := etherface.NewEtherfaceClient() if err != nil { - zap.L().Warn("failed to initialize etherface client", zap.Any("error", err)) + zap.L().Error("failed to initialize etherface client", zap.Any("error", err)) } else { c.etherfaceClient = etherfaceClient } diff --git a/internal/node/component/decentralized/transformer_activity.go b/internal/node/component/decentralized/transformer_activity.go index 144ad46f3..62a64f18a 100644 --- a/internal/node/component/decentralized/transformer_activity.go +++ b/internal/node/component/decentralized/transformer_activity.go @@ -33,6 +33,7 @@ func (c *Component) TransformActivity(ctx context.Context, activity *activityx.A *activity.Actions[index], err = c.TransformSocialType(ctx, activity.Network, activity.Platform, *actionPtr) default: zap.L().Debug("unknown action tag, keeping original action", + zap.String("id", activity.ID), zap.String("tag", action.Tag.String())) activity.Actions[index] = actionPtr diff --git a/internal/node/component/federated/transformer_activity.go b/internal/node/component/federated/transformer_activity.go index c3ee4bf32..97e18e71b 100644 --- a/internal/node/component/federated/transformer_activity.go +++ b/internal/node/component/federated/transformer_activity.go @@ -29,7 +29,7 @@ func (c *Component) TransformActivity(ctx context.Context, activity *activityx.A } if err != nil { - zap.L().Error("Failed to transform federated activity action", + zap.L().Error("failed to transform federated activity action", zap.Error(err), zap.String("id", activity.ID)) } diff --git a/internal/node/component/info/handler_activity.go b/internal/node/component/info/handler_activity.go index 718dfb46c..891ca984b 100644 --- a/internal/node/component/info/handler_activity.go +++ b/internal/node/component/info/handler_activity.go @@ -25,14 +25,14 @@ func (c *Component) getActivityCountFromDB(ctx context.Context) (int64, *time.Ti updateTime *time.Time ) - zap.L().Debug("Loading checkpoints from database") + zap.L().Debug("loading checkpoints from database") checkpoints, err := c.databaseClient.LoadCheckpoints(ctx, "", networkx.Unknown, "") if err != nil { return count, nil, fmt.Errorf("failed to find activity count: %w", err) } - zap.L().Debug("Processing checkpoints to calculate total activity count") + zap.L().Debug("processing checkpoints to calculate total activity count") for _, checkpoint := range checkpoints { count += checkpoint.IndexCount @@ -48,24 +48,24 @@ func (c *Component) getActivityCountFromDB(ctx context.Context) (int64, *time.Ti // GetActivityCount returns the total number of activities indexed by this Node. func (c *Component) GetActivityCount(ctx echo.Context) error { if c.databaseClient == nil { - zap.L().Warn("Database client is not initialized, returning zero count") + zap.L().Debug("database client is not initialized, returning zero count") return ctx.JSON(http.StatusOK, StatisticResponse{ Count: 0, }) } - zap.L().Debug("Getting activity count from database") + zap.L().Debug("getting activity count from database") count, updateTime, err := c.getActivityCountFromDB(ctx.Request().Context()) if err != nil { - zap.L().Error("Failed to get activity count from database", + zap.L().Error("failed to get activity count from database", zap.Error(err)) return response.InternalError(ctx) } - zap.L().Debug("Successfully retrieved activity count", + zap.L().Debug("successfully retrieved activity count", zap.Int64("count", count), zap.Time("lastUpdate", *updateTime)) diff --git a/internal/node/component/info/handler_network.go b/internal/node/component/info/handler_network.go index 06a2b3090..7faf9c603 100644 --- a/internal/node/component/info/handler_network.go +++ b/internal/node/component/info/handler_network.go @@ -36,7 +36,7 @@ type NetworkConfigDetailForRSS struct { // GetNetworkConfig GetNetworksConfig returns the configuration for all supported networks. func (c *Component) GetNetworkConfig(ctx echo.Context) error { - zap.L().Debug("Getting network configuration") + zap.L().Debug("getting network configuration") go c.CollectMetric(ctx.Request().Context(), ctx.Request().RequestURI, "config") @@ -46,7 +46,7 @@ func (c *Component) GetNetworkConfig(ctx echo.Context) error { Federated: getNetworkConfigDetail(network.ActivityPubProtocol), } - zap.L().Debug("Successfully retrieved network configuration") + zap.L().Debug("successfully retrieved network configuration") return ctx.JSON(http.StatusOK, NetworkConfigResponse{ Data: config, @@ -74,14 +74,14 @@ func getNetworkConfigDetailForRSS(protocol network.Protocol) NetworkConfigDetail networkDetail.WorkerConfig = workerConfig - zap.L().Debug("Successfully retrieved RSS network configuration details", + zap.L().Debug("successfully retrieved RSS network configuration details", zap.String("networkID", n.String())) return networkDetail } func getNetworkConfigDetail(protocols ...network.Protocol) []NetworkConfigDetail { - zap.L().Debug("Getting network configuration details for protocols", + zap.L().Debug("getting network configuration details for protocols", zap.Any("protocols", protocols)) var details []NetworkConfigDetail @@ -89,7 +89,7 @@ func getNetworkConfigDetail(protocols ...network.Protocol) []NetworkConfigDetail for _, protocol := range protocols { for _, n := range protocol.Networks() { if shouldSkipNetwork(n) { - zap.L().Debug("Skipping network", + zap.L().Debug("skipping network", zap.String("network", n.String())) continue } @@ -106,7 +106,7 @@ func getNetworkConfigDetail(protocols ...network.Protocol) []NetworkConfigDetail } } - zap.L().Debug("Successfully retrieved network configuration details", + zap.L().Debug("successfully retrieved network configuration details", zap.Int("detailsCount", len(details))) return details @@ -117,7 +117,7 @@ func shouldSkipNetwork(n network.Network) bool { } func createNetworkDetail(protocol network.Protocol, n network.Network) NetworkConfigDetail { - zap.L().Debug("Creating network detail", + zap.L().Debug("creating network detail", zap.String("network", n.String())) networkDetail := NetworkConfigDetail{ @@ -134,7 +134,7 @@ func createNetworkDetail(protocol network.Protocol, n network.Network) NetworkCo } func getWorkerConfigs(protocol network.Protocol, n network.Network) []workerConfig { - zap.L().Debug("Getting worker configurations", + zap.L().Debug("getting worker configurations", zap.String("network", n.String())) var workerConfigs []workerConfig @@ -146,14 +146,14 @@ func getWorkerConfigs(protocol network.Protocol, n network.Network) []workerConf } } - zap.L().Debug("Successfully retrieved worker configurations", + zap.L().Debug("successfully retrieved worker configurations", zap.Int("configCount", len(workerConfigs))) return workerConfigs } func createWorkerConfig(n network.Network, worker worker.Worker, config workerConfig) workerConfig { - zap.L().Debug("Creating worker configuration", + zap.L().Debug("creating worker configuration", zap.String("network", n.String()), zap.String("worker", worker.Name())) diff --git a/internal/node/component/info/handler_node.go b/internal/node/component/info/handler_node.go index 2e6bb200d..2ff72038c 100644 --- a/internal/node/component/info/handler_node.go +++ b/internal/node/component/info/handler_node.go @@ -83,22 +83,22 @@ type Reward struct { // GetNodeOperator returns the node information. func (c *Component) GetNodeOperator(ctx echo.Context) error { go c.CollectMetric(ctx.Request().Context(), ctx.Request().RequestURI, "info") - zap.L().Debug("Getting node operator info") + zap.L().Debug("getting node operator info") // Get Operator address info evmAddress := common.Address{} if operator := c.config.Discovery.Operator; operator != nil { evmAddress = operator.EvmAddress - zap.L().Debug("Found operator address", + zap.L().Debug("found operator address", zap.String("address", evmAddress.String())) } else { - zap.L().Warn("No operator address configured") + zap.L().Warn("no operator address configured") } response := fmt.Sprintf("This is an RSS3 Node operated by %s.", evmAddress) - zap.L().Debug("Successfully retrieved node operator info") + zap.L().Debug("successfully retrieved node operator info") return ctx.JSON(http.StatusOK, response) } @@ -106,11 +106,11 @@ func (c *Component) GetNodeOperator(ctx echo.Context) error { // GetNodeInfo returns the node information. func (c *Component) GetNodeInfo(ctx echo.Context) error { go c.CollectMetric(ctx.Request().Context(), ctx.Request().RequestURI, "info") - zap.L().Debug("Getting node info") + zap.L().Debug("getting node info") // Get Version info version := c.buildVersion() - zap.L().Debug("Retrieved version info", + zap.L().Debug("retrieved version info", zap.String("tag", version.Tag), zap.String("commit", version.Commit)) @@ -119,49 +119,49 @@ func (c *Component) GetNodeInfo(ctx echo.Context) error { if operator := c.config.Discovery.Operator; operator != nil { evmAddress = operator.EvmAddress - zap.L().Debug("Found operator address", + zap.L().Debug("found operator address", zap.String("address", evmAddress.String())) } else { - zap.L().Warn("No operator address configured") + zap.L().Warn("no operator address configured") } // Get uptime info uptime, err := c.getNodeUptime() if err != nil { - zap.L().Error("Failed to get node uptime", + zap.L().Error("failed to get node uptime", zap.Error(err)) return err } - zap.L().Debug("Retrieved node uptime", + zap.L().Debug("retrieved node uptime", zap.Int64("uptime", uptime)) // Get worker coverage info workerCoverage := c.getNodeWorkerCoverage() - zap.L().Debug("Retrieved worker coverage", + zap.L().Debug("retrieved worker coverage", zap.Strings("coverage", workerCoverage)) // get reward info rewards, err := c.getNodeRewards(ctx.Request().Context(), evmAddress) if err != nil { - zap.L().Error("Failed to get node rewards", + zap.L().Error("failed to get node rewards", zap.Error(err)) return err } - zap.L().Debug("Retrieved node rewards", + zap.L().Debug("retrieved node rewards", zap.Int("reward_count", len(rewards))) // get last heartbeat and slashed tokens lastHeartbeat, slashedTokens, err := c.getNodeBasicInfo(ctx.Request().Context(), evmAddress) if err != nil { - zap.L().Error("Failed to get node basic info", + zap.L().Error("failed to get node basic info", zap.Error(err)) return err } - zap.L().Debug("Retrieved node basic info", + zap.L().Debug("retrieved node basic info", zap.Int64("last_heartbeat", lastHeartbeat), zap.String("slashed_tokens", slashedTokens.String())) @@ -170,25 +170,25 @@ func (c *Component) GetNodeInfo(ctx echo.Context) error { if len(c.config.Component.Decentralized) > 0 { decentralizedRequests := decentralized.GetRecentRequest() recentRequests = append(recentRequests, decentralizedRequests...) - zap.L().Debug("Retrieved decentralized requests", + zap.L().Debug("retrieved decentralized requests", zap.Int("count", len(decentralizedRequests))) } if len(c.config.Component.Federated) > 0 { federatedRequests := federated.GetRecentRequest() recentRequests = append(recentRequests, federatedRequests...) - zap.L().Debug("Retrieved federated requests", + zap.L().Debug("retrieved federated requests", zap.Int("count", len(federatedRequests))) } if c.config.Component.RSS != nil { rssRequests := rss.GetRecentRequest() recentRequests = append(recentRequests, rssRequests...) - zap.L().Debug("Retrieved RSS requests", + zap.L().Debug("retrieved RSS requests", zap.Int("count", len(rssRequests))) } - zap.L().Debug("Successfully retrieved all node info", + zap.L().Debug("successfully retrieved all node info", zap.String("operator", evmAddress.String()), zap.Int("total_recent_requests", len(recentRequests))) @@ -225,7 +225,7 @@ func (c *Component) getNodeWorkerCoverage() []string { for _, worker := range c.config.Component.Decentralized { coverage := fmt.Sprintf("%s_%s", worker.Network, worker.Worker.Name()) workerCoverage = append(workerCoverage, coverage) - zap.L().Debug("Added decentralized worker coverage", + zap.L().Debug("added decentralized worker coverage", zap.String("coverage", coverage)) } @@ -233,7 +233,7 @@ func (c *Component) getNodeWorkerCoverage() []string { if c.config.Component.RSS != nil { coverage := fmt.Sprintf("%s_%s", network.RSSHub, c.config.Component.RSS.Worker.Name()) workerCoverage = append(workerCoverage, coverage) - zap.L().Debug("Added RSS worker coverage", + zap.L().Debug("added RSS worker coverage", zap.String("coverage", coverage)) } @@ -241,12 +241,12 @@ func (c *Component) getNodeWorkerCoverage() []string { for _, worker := range c.config.Component.Federated { coverage := fmt.Sprintf("%s_%s", worker.Network, worker.Worker.Name()) workerCoverage = append(workerCoverage, coverage) - zap.L().Debug("Added federated worker coverage", + zap.L().Debug("added federated worker coverage", zap.String("coverage", coverage)) } uniqueCoverage := lo.Uniq(workerCoverage) - zap.L().Debug("Completed getting worker coverage", + zap.L().Debug("completed getting worker coverage", zap.Int("total_coverage", len(uniqueCoverage))) return uniqueCoverage @@ -254,14 +254,14 @@ func (c *Component) getNodeWorkerCoverage() []string { // getNodeUptime returns the node uptime. func (c *Component) getNodeUptime() (int64, error) { - zap.L().Debug("Getting node uptime") + zap.L().Debug("getting node uptime") var uptime int64 // get first start time from redis cache and calculate uptime firstStartTime, err := GetFirstStartTime() if err != nil { - zap.L().Error("Failed to get first start time from cache", + zap.L().Error("failed to get first start time from cache", zap.Error(err)) return 0, err } @@ -269,20 +269,20 @@ func (c *Component) getNodeUptime() (int64, error) { if firstStartTime == 0 { uptime = 0 - zap.L().Info("First time node startup detected") + zap.L().Info("first time node startup detected") err := UpdateFirstStartTime(time.Now().Unix()) if err != nil { - zap.L().Error("Failed to update first start time", + zap.L().Error("failed to update first start time", zap.Error(err)) return 0, err } - zap.L().Debug("Successfully updated first start time") + zap.L().Debug("successfully updated first start time") } else { uptime = time.Now().Unix() - firstStartTime - zap.L().Debug("Calculated uptime", + zap.L().Debug("calculated uptime", zap.Int64("uptime_seconds", uptime)) } @@ -291,7 +291,7 @@ func (c *Component) getNodeUptime() (int64, error) { // getNodeRewards returns the node rewards. func (c *Component) getNodeRewards(ctx context.Context, address common.Address) ([]Reward, error) { - zap.L().Debug("Getting node rewards", + zap.L().Debug("getting node rewards", zap.String("address", address.String())) var resp GIRewardsResponse @@ -319,7 +319,7 @@ func (c *Component) getNodeRewards(ctx context.Context, address common.Address) RequestCounts: rewardedNode.RequestCount, } - zap.L().Debug("Processed reward for epoch", + zap.L().Debug("processed reward for epoch", zap.Uint64("epoch", data.ID), zap.String("operation_rewards", rewardedNode.OperationRewards.String()), zap.String("staking_rewards", rewardedNode.StakingRewards.String())) @@ -329,7 +329,7 @@ func (c *Component) getNodeRewards(ctx context.Context, address common.Address) } } - zap.L().Debug("Successfully retrieved node rewards", + zap.L().Debug("successfully retrieved node rewards", zap.Int("total_rewards", len(rewards))) return rewards, nil @@ -337,21 +337,21 @@ func (c *Component) getNodeRewards(ctx context.Context, address common.Address) // getNodeInfo returns the node slashed token. func (c *Component) getNodeBasicInfo(ctx context.Context, address common.Address) (int64, decimal.Decimal, error) { - zap.L().Debug("Getting node basic info", + zap.L().Debug("getting node basic info", zap.String("address", address.String())) var resp GINodeInfoResponse err := c.sendRequest(ctx, fmt.Sprintf("/nta/nodes/%s", address), &resp) if err != nil { - zap.L().Error("Failed to get node basic info", + zap.L().Error("failed to get node basic info", zap.String("address", address.String()), zap.Error(err)) return 0, decimal.Decimal{}, err } - zap.L().Debug("Successfully retrieved node basic info", + zap.L().Debug("successfully retrieved node basic info", zap.Int64("last_heartbeat", resp.Data.LastHeartbeat), zap.String("slashed_tokens", resp.Data.SlashedTokens.String())) @@ -362,14 +362,14 @@ func (c *Component) getNodeBasicInfo(ctx context.Context, address common.Address func (c *Component) sendRequest(ctx context.Context, path string, result any) error { internalURL, err := url.Parse(c.config.Discovery.Server.GlobalIndexerEndpoint) if err != nil { - zap.L().Error("Failed to parse global indexer endpoint", + zap.L().Error("failed to parse global indexer endpoint", zap.Error(err)) return err } internalURL.Path = path - zap.L().Debug("Sending request to global indexer", + zap.L().Debug("sending request to global indexer", zap.String("url", internalURL.String())) body, err := c.httpClient.Fetch(ctx, internalURL.String()) @@ -382,7 +382,7 @@ func (c *Component) sendRequest(ctx context.Context, path string, result any) er return fmt.Errorf("decode response: %w", err) } - zap.L().Debug("Successfully completed request to global indexer") + zap.L().Debug("successfully completed request to global indexer") return nil } @@ -391,12 +391,12 @@ func (c *Component) sendRequest(ctx context.Context, path string, result any) er func GetFirstStartTime() (int64, error) { filePath := "first_start_time.txt" - zap.L().Debug("Getting first start time from file", + zap.L().Debug("getting first start time from file", zap.String("path", filePath)) // Check if file exists if _, err := os.Stat(filePath); os.IsNotExist(err) { - zap.L().Debug("First start time file does not exist") + zap.L().Debug("first start time file does not exist") return 0, nil } @@ -412,7 +412,7 @@ func GetFirstStartTime() (int64, error) { return 0, fmt.Errorf("parse int64: %w", err) } - zap.L().Debug("Successfully retrieved first start time", + zap.L().Debug("successfully retrieved first start time", zap.Int64("timestamp", firstStartTime)) return firstStartTime, nil @@ -422,7 +422,7 @@ func GetFirstStartTime() (int64, error) { func UpdateFirstStartTime(timestamp int64) error { filePath := "first_start_time.txt" - zap.L().Debug("Updating first start time", + zap.L().Debug("updating first start time", zap.String("path", filePath), zap.Int64("timestamp", timestamp)) @@ -435,7 +435,7 @@ func UpdateFirstStartTime(timestamp int64) error { return fmt.Errorf("write file: %w", err) } - zap.L().Debug("Successfully updated first start time") + zap.L().Debug("successfully updated first start time") return nil } diff --git a/internal/node/component/info/handler_worker.go b/internal/node/component/info/handler_worker.go index 583945287..cbc47012f 100644 --- a/internal/node/component/info/handler_worker.go +++ b/internal/node/component/info/handler_worker.go @@ -46,7 +46,7 @@ type WorkerInfo struct { func (c *Component) GetWorkersStatus(ctx echo.Context) error { go c.CollectTrace(ctx.Request().Context(), ctx.Request().RequestURI, "status") - zap.L().Debug("Getting status for all workers") + zap.L().Debug("getting status for all workers") workerCount := config.CalculateWorkerCount(c.config) workerInfoChan := make(chan *WorkerInfo, workerCount) @@ -56,7 +56,7 @@ func (c *Component) GetWorkersStatus(ctx echo.Context) error { response := c.buildWorkerResponse(workerInfoChan) - zap.L().Debug("Successfully retrieved worker statuses") + zap.L().Debug("successfully retrieved worker statuses") return ctx.JSON(http.StatusOK, response) } @@ -65,7 +65,7 @@ func (c *Component) GetWorkersStatus(ctx echo.Context) error { func (c *Component) fetchAllWorkerInfo(ctx echo.Context, workerInfoChan chan<- *WorkerInfo) { var wg sync.WaitGroup - zap.L().Debug("Starting concurrent worker info fetch") + zap.L().Debug("starting concurrent worker info fetch") fetchWorkerInfo := func(w *config.Module, fetchFunc func(context.Context, *config.Module) *WorkerInfo) { wg.Add(1) @@ -81,27 +81,27 @@ func (c *Component) fetchAllWorkerInfo(ctx echo.Context, workerInfoChan chan<- * if len(c.config.Component.Decentralized) > 0 { modules = append(modules, c.config.Component.Decentralized...) - zap.L().Debug("Added decentralized modules", + zap.L().Debug("added decentralized modules", zap.Int("count", len(c.config.Component.Decentralized))) } if len(c.config.Component.Federated) > 0 { modules = append(modules, c.config.Component.Federated...) - zap.L().Debug("Added federated modules", + zap.L().Debug("added federated modules", zap.Int("count", len(c.config.Component.Federated))) } if c.config.Component.RSS != nil { modules = append(modules, c.config.Component.RSS) - zap.L().Debug("Added RSS module") + zap.L().Debug("added RSS module") } for _, m := range modules { if m.Network.Protocol() == network.RSSProtocol { if rssWorker := rss.GetValueByWorkerStr(m.Worker.Name()); rssWorker != 0 { m.Worker = rssWorker - zap.L().Debug("Updated RSS worker", + zap.L().Debug("updated RSS worker", zap.String("worker", m.Worker.Name())) } } @@ -112,13 +112,13 @@ func (c *Component) fetchAllWorkerInfo(ctx echo.Context, workerInfoChan chan<- * go func() { wg.Wait() close(workerInfoChan) - zap.L().Debug("Completed fetching all worker info") + zap.L().Debug("completed fetching all worker info") }() } // buildWorkerResponse builds the worker response from the worker info channel func (c *Component) buildWorkerResponse(workerInfoChan <-chan *WorkerInfo) *WorkerResponse { - zap.L().Debug("Building worker response") + zap.L().Debug("building worker response") response := &WorkerResponse{ Data: ComponentInfo{}, @@ -138,23 +138,23 @@ func (c *Component) buildWorkerResponse(workerInfoChan <-chan *WorkerInfo) *Work if c.config.Component.RSS != nil { response.Data.RSS = workerInfo - zap.L().Debug("Added RSS worker info") + zap.L().Debug("added RSS worker info") } case network.EthereumProtocol, network.FarcasterProtocol, network.ArweaveProtocol, network.NearProtocol: response.Data.Decentralized = append(response.Data.Decentralized, workerInfo) - zap.L().Debug("Added decentralized worker info", + zap.L().Debug("added decentralized worker info", zap.String("network", workerInfo.Network.String())) case network.ActivityPubProtocol: response.Data.Federated = append(response.Data.Federated, workerInfo) - zap.L().Debug("Added federated worker info", + zap.L().Debug("added federated worker info", zap.String("network", workerInfo.Network.String())) default: - zap.L().Warn("Unknown protocol for worker", + zap.L().Warn("unknown protocol for worker", zap.String("worker_id", workerInfo.WorkerID)) } } - zap.L().Debug("Successfully built worker response") + zap.L().Debug("successfully built worker response") return response } @@ -170,7 +170,7 @@ func (c *Component) fetchWorkerInfo(ctx context.Context, module *config.Module) } } - zap.L().Debug("Fetching worker info", + zap.L().Debug("fetching worker info", zap.String("worker_id", module.ID), zap.String("network", module.Network.String())) @@ -180,10 +180,10 @@ func (c *Component) fetchWorkerInfo(ctx context.Context, module *config.Module) ) if module.Network.Protocol() == network.RSSProtocol { - // Check RSS worker health status + // check RSS worker health status status, _ = c.checkRSSWorkerHealth(ctx, module) } else { - // Fetch decentralized or federated worker status and progress from a specific worker by id. + // fetch decentralized or federated worker status and progress from a specific worker by id. status, workerProgress = c.getWorkerStatusAndProgressByID(ctx, module.ID) } @@ -235,12 +235,12 @@ func (c *Component) fetchWorkerInfo(ctx context.Context, module *config.Module) // checkRSSWorkerHealth checks the health of the RSS worker by `healthz` api. func (c *Component) checkRSSWorkerHealth(ctx context.Context, module *config.Module) (worker.Status, error) { - zap.L().Debug("Checking RSS worker health", + zap.L().Debug("checking RSS worker health", zap.String("endpoint", module.EndpointID)) baseURL, err := url.Parse(module.EndpointID) if err != nil { - zap.L().Error("Invalid RSS endpoint", + zap.L().Error("invalid RSS endpoint", zap.String("endpoint", module.EndpointID), zap.Error(err)) @@ -252,7 +252,7 @@ func (c *Component) checkRSSWorkerHealth(ctx context.Context, module *config.Mod // Parse RSS options from module parameters option, err := rssx.NewOption(module.Parameters) if err != nil { - zap.L().Error("Failed to parse config parameters", + zap.L().Error("failed to parse config parameters", zap.Error(err)) return worker.StatusUnhealthy, err @@ -263,13 +263,13 @@ func (c *Component) checkRSSWorkerHealth(ctx context.Context, module *config.Mod query.Set("key", option.Authentication.AccessKey) baseURL.RawQuery = query.Encode() - zap.L().Debug("Added authentication key to request", + zap.L().Debug("added authentication key to request", zap.String("key", option.Authentication.AccessKey)) } body, err := c.httpClient.Fetch(ctx, baseURL.String()) if err != nil { - zap.L().Error("Failed to fetch RSS healthz", + zap.L().Error("failed to fetch RSS healthz", zap.String("endpoint", baseURL.String()), zap.Error(err)) @@ -277,18 +277,18 @@ func (c *Component) checkRSSWorkerHealth(ctx context.Context, module *config.Mod } defer body.Close() - zap.L().Debug("Successfully checked RSS worker health") + zap.L().Debug("successfully checked RSS worker health") return worker.StatusReady, nil } // getWorkerStatusAndProgressByID gets both worker status and progress from Redis cache by worker ID. func (c *Component) getWorkerStatusAndProgressByID(ctx context.Context, workerID string) (worker.Status, monitor.WorkerProgress) { - zap.L().Debug("Getting worker status and progress", + zap.L().Debug("getting worker status and progress", zap.String("worker_id", workerID)) if c.redisClient == nil { - zap.L().Warn("Redis client is not initialized") + zap.L().Debug("redis client is not initialized") return worker.StatusUnknown, monitor.WorkerProgress{} } @@ -299,7 +299,7 @@ func (c *Component) getWorkerStatusAndProgressByID(ctx context.Context, workerID result := c.redisClient.Do(ctx, command) if err := result.Error(); err != nil { - zap.L().Error("Failed to execute Redis command", + zap.L().Error("failed to execute Redis command", zap.Error(err)) return worker.StatusUnknown, monitor.WorkerProgress{} } @@ -312,14 +312,14 @@ func (c *Component) getWorkerStatusAndProgressByID(ctx context.Context, workerID // Parse the status statusValue, err := c.parseRedisJSONValue(values[0].String()) if err != nil { - zap.L().Error("Failed to parse status value", + zap.L().Error("failed to parse status value", zap.Error(err)) return worker.StatusUnknown, monitor.WorkerProgress{} } status, err := worker.StatusString(statusValue) if err != nil { - zap.L().Error("Invalid worker status", + zap.L().Error("invalid worker status", zap.String("status", statusValue), zap.Error(err)) @@ -329,7 +329,7 @@ func (c *Component) getWorkerStatusAndProgressByID(ctx context.Context, workerID // Parse the progress progressValue, err := c.parseRedisJSONValue(values[1].String()) if err != nil { - zap.L().Error("Failed to parse progress value", + zap.L().Error("failed to parse progress value", zap.Error(err)) return status, monitor.WorkerProgress{} } @@ -339,13 +339,13 @@ func (c *Component) getWorkerStatusAndProgressByID(ctx context.Context, workerID if progressValue != "" { err = json.Unmarshal([]byte(progressValue), &workerProgress) if err != nil { - zap.L().Error("Failed to unmarshal worker progress", + zap.L().Error("failed to unmarshal worker progress", zap.Error(err)) return status, monitor.WorkerProgress{} } } - zap.L().Debug("Successfully retrieved worker status and progress", + zap.L().Debug("successfully retrieved worker status and progress", zap.String("status", status.String())) return status, workerProgress diff --git a/internal/node/component/rss/component.go b/internal/node/component/rss/component.go index d4b93b6d8..8e2706662 100644 --- a/internal/node/component/rss/component.go +++ b/internal/node/component/rss/component.go @@ -127,7 +127,7 @@ func (h *Component) CollectTrace(ctx context.Context, path, value string) { // setAccessKey set the access code according to the RSSHub authentication specification. func (h *Component) setAccessKey(config *config.Module) error { if config.Parameters == nil { - zap.L().Debug("No parameters provided for RSS component") + zap.L().Debug("no parameters provided for RSS component") return nil } @@ -137,12 +137,12 @@ func (h *Component) setAccessKey(config *config.Module) error { } if option.Authentication.AccessKey != "" { - zap.L().Debug("Setting RSS component access key", + zap.L().Debug("setting RSS component access key", zap.String("key", option.Authentication.AccessKey)) h.rsshub.accessKey = option.Authentication.AccessKey } else { - zap.L().Warn("No access key provided for RSS component") + zap.L().Debug("no access key provided for RSS component") } return nil diff --git a/internal/node/component/rss/data.go b/internal/node/component/rss/data.go index 0628f26f5..2c5c4a1e0 100644 --- a/internal/node/component/rss/data.go +++ b/internal/node/component/rss/data.go @@ -26,7 +26,7 @@ func (h *Component) getActivities(ctx context.Context, path string, url *url.URL return nil, fmt.Errorf("format request: %w", err) } - zap.L().Debug("Sending request to RSSHub", + zap.L().Debug("sending request to RSSHub", zap.String("url", request.String())) //nolint:bodyclose // False positive @@ -35,7 +35,7 @@ func (h *Component) getActivities(ctx context.Context, path string, url *url.URL return nil, fmt.Errorf("failed to get RSSHub response: %w", err) } - zap.L().Debug("Successfully received response from RSSHub", + zap.L().Debug("successfully received response from RSSHub", zap.Int("status_code", response.StatusCode)) return h.formatResponse(ctx, response) diff --git a/internal/node/component/rss/handler.go b/internal/node/component/rss/handler.go index 8d6f24929..9a22897ef 100644 --- a/internal/node/component/rss/handler.go +++ b/internal/node/component/rss/handler.go @@ -15,7 +15,7 @@ type Response struct { func (h *Component) Handler(ctx echo.Context) error { path := ctx.Param("*") - zap.L().Debug("Handling RSS request", + zap.L().Debug("handling RSS request", zap.String("path", path), zap.String("request_uri", ctx.Request().RequestURI)) @@ -27,14 +27,14 @@ func (h *Component) Handler(ctx echo.Context) error { data, err := h.getActivities(ctx.Request().Context(), path, ctx.Request().URL) if err != nil { - zap.L().Error("Failed to get activities from RSS feed", + zap.L().Error("failed to get activities from RSS feed", zap.String("path", path), zap.Error(err)) return response.InternalError(ctx) } - zap.L().Info("Successfully retrieved RSS activities", + zap.L().Info("successfully retrieved RSS activities", zap.String("path", path), zap.Int("activity_count", len(data))) diff --git a/internal/node/indexer/server.go b/internal/node/indexer/server.go index 89201d8dc..1264f710e 100644 --- a/internal/node/indexer/server.go +++ b/internal/node/indexer/server.go @@ -54,7 +54,7 @@ func (s *Server) Run(ctx context.Context) error { errorChan = make(chan error) ) - zap.L().Info("Starting node server", + zap.L().Info("starting node server", zap.String("version", constant.BuildVersion()), zap.String("worker", s.worker.Name())) @@ -63,7 +63,7 @@ func (s *Server) Run(ctx context.Context) error { for { select { case tasks := <-tasksChan: - zap.L().Debug("Received tasks from source", + zap.L().Debug("received tasks from source", zap.Int("task_count", tasks.Len())) retryableFunc := func() error { @@ -80,7 +80,7 @@ func (s *Server) Run(ctx context.Context) error { retry.DelayType(retry.BackOffDelay), // Use backoff delay type, increasing delay on each retry. retry.MaxDelay(5*time.Minute), retry.OnRetry(func(n uint, err error) { - zap.L().Error("Failed to handle tasks, retrying", + zap.L().Error("failed to handle tasks, retrying", zap.Uint("retry_count", n), zap.Error(err)) }), @@ -131,7 +131,7 @@ func (s *Server) handleTasks(ctx context.Context, tasks *engine.Tasks) error { // If no tasks are returned, only save the checkpoint to the database. if tasks.Len() == 0 { - zap.L().Info("No tasks to process, saving checkpoint", + zap.L().Info("no tasks to process, saving checkpoint", zap.Any("checkpoint", checkpoint)) if err := s.databaseClient.SaveCheckpoint(ctx, &checkpoint); err != nil { @@ -147,20 +147,19 @@ func (s *Server) handleTasks(ctx context.Context, tasks *engine.Tasks) error { task := task resultPool.Go(func() *activityx.Activity { - zap.L().Debug("Starting task transformation", - zap.String("task_id", task.ID())) - activity, err := s.worker.Transform(ctx, task) if err != nil { - zap.L().Error("Failed to transform task", + zap.L().Error("failed to transform task", zap.String("task_id", task.ID()), zap.Error(err)) return nil } - zap.L().Debug("Successfully transformed task", - zap.String("task_id", task.ID())) + if activity != nil && len(activity.Actions) > 0 { + zap.L().Info("successfully transformed task", + zap.String("task_id", task.ID())) + } return activity }) @@ -171,7 +170,7 @@ func (s *Server) handleTasks(ctx context.Context, tasks *engine.Tasks) error { return activity != nil && len(activity.Actions) > 0 }) - zap.L().Info("Task transformation completed", + zap.L().Info("task transformation completed", zap.Int("total_tasks", tasks.Len()), zap.Int("successful_activities", len(activities))) @@ -188,7 +187,7 @@ func (s *Server) handleTasks(ctx context.Context, tasks *engine.Tasks) error { return fmt.Errorf("save %d activities: %w", len(activities), err) } - zap.L().Info("Successfully saved activities and checkpoint", + zap.L().Info("successfully saved activities and checkpoint", zap.Int("activity_count", len(activities)), zap.Any("checkpoint", checkpoint)) @@ -206,7 +205,7 @@ func (s *Server) handleTasks(ctx context.Context, tasks *engine.Tasks) error { return fmt.Errorf("publish %d activities: %w", len(activities), err) } - zap.L().Debug("Successfully pushed activities to stream", + zap.L().Debug("successfully pushed activities to stream", zap.Int("activity_count", len(activities))) } @@ -233,7 +232,7 @@ func (s *Server) initializeMeter() (err error) { return fmt.Errorf("failed to observe meter LatestBlock: %w", err) } - zap.L().Info("Successfully initialized meters") + zap.L().Info("successfully initialized meters") return nil } @@ -244,7 +243,7 @@ func (s *Server) currentBlockMetricHandler(ctx context.Context, observer metric. // get current block height state latestCheckpoint, err := s.databaseClient.LoadCheckpoint(ctx, s.id, s.source.Network(), s.worker.Name()) if err != nil { - zap.L().Error("Failed to find latest checkpoint", + zap.L().Error("failed to find latest checkpoint", zap.Error(err)) return } @@ -253,7 +252,7 @@ func (s *Server) currentBlockMetricHandler(ctx context.Context, observer metric. // Get the current block height/block number from the checkpoint state. var state monitor.CheckpointState if err := json.Unmarshal(latestCheckpoint.State, &state); err != nil { - zap.L().Error("Failed to unmarshal checkpoint state", + zap.L().Error("failed to unmarshal checkpoint state", zap.Error(err)) return } @@ -273,7 +272,7 @@ func (s *Server) currentBlockMetricHandler(ctx context.Context, observer metric. attribute.String("worker", s.worker.Name()), )) - zap.L().Debug("Successfully observed current block metric", + zap.L().Debug("successfully observed current block metric", zap.Uint64("current_block", current)) } }() @@ -284,14 +283,14 @@ func (s *Server) currentBlockMetricHandler(ctx context.Context, observer metric. // latestBlockMetricHandler gets the latest block height/number from the network rpc. func (s *Server) latestBlockMetricHandler(ctx context.Context, observer metric.Int64Observer) error { go func() { - zap.L().Debug("Start getting latest block state") + zap.L().Debug("starting to get latest block state") var latest uint64 // get latest block height latestBlockHeight, latestBlockTimestamp, err := s.monitorClient.LatestState(ctx) if err != nil { - zap.L().Error("Failed to get latest block state", + zap.L().Error("failed to get latest block state", zap.Error(err)) return } @@ -306,7 +305,7 @@ func (s *Server) latestBlockMetricHandler(ctx context.Context, observer metric.I attribute.String("service", constant.Name), attribute.String("worker", s.worker.Name()))) - zap.L().Debug("Successfully observed latest block metric", + zap.L().Debug("successfully observed latest block metric", zap.Uint64("latest_block", latest), zap.String("worker", s.worker.Name())) }() @@ -315,7 +314,7 @@ func (s *Server) latestBlockMetricHandler(ctx context.Context, observer metric.I } func NewServer(ctx context.Context, config *config.Module, databaseClient database.Client, streamClient stream.Client, redisClient rueidis.Client) (server *Server, err error) { - zap.L().Debug("Creating new server instance", + zap.L().Debug("creating new server instance", zap.String("id", config.ID), zap.String("network", config.Network.String())) @@ -341,19 +340,20 @@ func NewServer(ctx context.Context, config *config.Module, databaseClient databa return nil, fmt.Errorf("new decentralized worker: %w", err) } - zap.L().Debug("Created decentralized worker", + zap.L().Debug("created decentralized worker", zap.String("protocol", string(config.Network.Protocol()))) case network.ActivityPubProtocol: if instance.worker, err = federatedWorker.New(instance.config, databaseClient, instance.redisClient); err != nil { return nil, fmt.Errorf("new federated worker: %w", err) } - zap.L().Debug("Created federated worker") + zap.L().Debug("created federated worker") default: return nil, fmt.Errorf("unknown worker protocol: %s", config.Network.Protocol()) } - zap.L().Info("worker initialized successfully", zap.String("ID", config.ID), + zap.L().Info("worker initialized successfully", + zap.String("ID", config.ID), zap.String("network", config.Network.String()), zap.String("worker", config.Worker.Name())) @@ -387,7 +387,7 @@ func NewServer(ctx context.Context, config *config.Module, databaseClient databa } } - zap.L().Debug("Successfully created monitor client", + zap.L().Debug("successfully created monitor client", zap.String("protocol", string(config.Network.Protocol()))) if err := instance.initializeMeter(); err != nil { @@ -406,7 +406,7 @@ func NewServer(ctx context.Context, config *config.Module, databaseClient databa return nil, fmt.Errorf("unmarshal checkpoint state: %w", err) } - zap.L().Debug("Successfully loaded checkpoint", + zap.L().Debug("successfully loaded checkpoint", zap.String("checkpoint.id", checkpoint.ID), zap.String("checkpoint.network", checkpoint.Network.String()), zap.String("checkpoint.worker", checkpoint.Worker), @@ -417,7 +417,7 @@ func NewServer(ctx context.Context, config *config.Module, databaseClient databa return nil, fmt.Errorf("new protocol: %w", err) } - zap.L().Info("Successfully created new indexer server") + zap.L().Info("successfully created new indexer server") return &instance, nil } diff --git a/internal/node/middlewarex/httpHandleMiddleware.go b/internal/node/middlewarex/httpHandleMiddleware.go index 942d76f83..c1365e64d 100644 --- a/internal/node/middlewarex/httpHandleMiddleware.go +++ b/internal/node/middlewarex/httpHandleMiddleware.go @@ -13,7 +13,7 @@ func DecodePathParamsMiddleware(next echo.HandlerFunc) echo.HandlerFunc { return func(c echo.Context) error { // Decode path parameters paramValues := c.ParamValues() - zap.L().Debug("Decoding path parameters", + zap.L().Debug("decoding path parameters", zap.Strings("param_values", paramValues)) for i, value := range paramValues { @@ -25,7 +25,7 @@ func DecodePathParamsMiddleware(next echo.HandlerFunc) echo.HandlerFunc { paramValues[i] = decodedValue } - zap.L().Debug("Successfully decoded path parameters", + zap.L().Debug("successfully decoded path parameters", zap.Strings("decoded_values", paramValues)) return next(c) @@ -36,7 +36,7 @@ func DecodePathParamsMiddleware(next echo.HandlerFunc) echo.HandlerFunc { func HeadToGetMiddleware(next echo.HandlerFunc) echo.HandlerFunc { return func(c echo.Context) error { if c.Request().Method == http.MethodHead { - zap.L().Debug("Converting HEAD request to GET", + zap.L().Debug("converting head request to get", zap.String("path", c.Request().URL.Path)) // Set the method to GET temporarily to reuse the handler @@ -44,19 +44,19 @@ func HeadToGetMiddleware(next echo.HandlerFunc) echo.HandlerFunc { defer func() { c.Request().Method = http.MethodHead - zap.L().Debug("Restored request method back to HEAD") + zap.L().Debug("restored request method back to head") }() // Restore method after // Call the next handler and then clear the response body if err := next(c); err != nil { if err.Error() == echo.ErrMethodNotAllowed.Error() { - zap.L().Debug("Method not allowed, returning empty response for HEAD request") + zap.L().Debug("method not allowed, returning empty response for head request") c.NoContent(http.StatusOK) //nolint:errcheck return nil } - zap.L().Error("Error handling HEAD request", + zap.L().Error("error handling head request", zap.Error(err)) return err diff --git a/internal/node/monitor/client.go b/internal/node/monitor/client.go index db1180a8e..15cf2ca85 100644 --- a/internal/node/monitor/client.go +++ b/internal/node/monitor/client.go @@ -225,7 +225,7 @@ func (c *activitypubClient) LatestState(ctx context.Context) (uint64, uint64, er for _, relayURL := range c.relayURLs { resp, err := c.httpClient.Fetch(ctx, relayURL) if err != nil { - zap.L().Warn("relay health check failed", + zap.L().Error("relay health check failed", zap.String("relay_url", relayURL), zap.Error(err)) diff --git a/internal/node/node.go b/internal/node/node.go index 71badf24f..79bd226a1 100644 --- a/internal/node/node.go +++ b/internal/node/node.go @@ -49,8 +49,6 @@ func (s *Core) Run(_ context.Context) error { // NewCoreService initializes the core services required by the Core func NewCoreService(ctx context.Context, config *config.File, databaseClient database.Client, redisClient rueidis.Client, networkParamsCaller *vsl.NetworkParamsCaller, settlementCaller *vsl.SettlementCaller) *Core { - zap.L().Debug("Initializing core service") - apiServer := echo.New() node := Core{ @@ -68,36 +66,26 @@ func NewCoreService(ctx context.Context, config *config.File, databaseClient dat Validator: validator.New(), } - zap.L().Debug("Configuring API server middleware") - apiServer.Use( middleware.CORSWithConfig(middleware.DefaultCORSConfig), middlewarex.DecodePathParamsMiddleware, middlewarex.HeadToGetMiddleware, ) - zap.L().Debug("Initializing info component") - infoComponent := info.NewComponent(ctx, apiServer, config, databaseClient, redisClient, networkParamsCaller) node.components = append(node.components, &infoComponent) if config.Component.RSS != nil { - zap.L().Debug("Initializing RSS component") - rssComponent := rss.NewComponent(ctx, apiServer, config) node.components = append(node.components, &rssComponent) } if len(config.Component.Decentralized) > 0 { - zap.L().Debug("Initializing decentralized component") - decentralizedComponent := decentralized.NewComponent(ctx, apiServer, config, databaseClient, redisClient) node.components = append(node.components, &decentralizedComponent) } if len(config.Component.Federated) > 0 { - zap.L().Debug("Initializing federated component") - federatedComponent := federated.NewComponent(ctx, apiServer, config, databaseClient, redisClient) node.components = append(node.components, &federatedComponent) } @@ -108,8 +96,6 @@ func NewCoreService(ctx context.Context, config *config.File, databaseClient dat endpoint = config.Discovery.Server.Endpoint } - zap.L().Debug("Generating OpenAPI documentation") - content, err := docs.Generate(endpoint) if err != nil { zap.L().Error("Failed to generate OpenAPI documentation", @@ -127,12 +113,12 @@ func NewCoreService(ctx context.Context, config *config.File, databaseClient dat // CheckParams checks the network parameters and settlement tasks func CheckParams(ctx context.Context, redisClient rueidis.Client, networkParamsCaller *vsl.NetworkParamsCaller, settlementCaller *vsl.SettlementCaller) error { - zap.L().Debug("Starting network parameters check service") + zap.L().Debug("starting network parameters check service") checkParamsCron := cron.New() _, err := checkParamsCron.AddFunc("@every 5m", func() { - zap.L().Debug("Running scheduled network parameters check") + zap.L().Debug("running scheduled network parameters check") localEpoch, err := parameter.GetCurrentEpoch(ctx, redisClient) if err != nil { diff --git a/internal/utils/utils.go b/internal/utils/utils.go new file mode 100644 index 000000000..5fb8cc619 --- /dev/null +++ b/internal/utils/utils.go @@ -0,0 +1,12 @@ +package utils + +import "math/big" + +// GetBigInt returns the value if not nil, otherwise returns big.NewInt(0) +func GetBigInt(value *big.Int) *big.Int { + if value == nil { + return big.NewInt(0) + } + + return value +} diff --git a/provider/activitypub/mastodon/client.go b/provider/activitypub/mastodon/client.go index e3c991853..e5c0723c9 100644 --- a/provider/activitypub/mastodon/client.go +++ b/provider/activitypub/mastodon/client.go @@ -196,7 +196,7 @@ func (c *client) startServerService(ctx context.Context, errChan chan<- error) { if err := c.startHTTPServer(ctx); err != nil { select { case errChan <- err: - zap.L().Error("HTTP server failed", zap.Error(err)) + zap.L().Error("http server failed", zap.Error(err)) case <-ctx.Done(): zap.L().Info("context cancelled, skipping error send", zap.Error(err)) @@ -232,7 +232,7 @@ func (c *client) startHTTPServer(ctx context.Context) error { startedCh := make(chan struct{}, 1) serverPortStr := ":" + strconv.Itoa(int(c.port)) - zap.L().Info("Starting mastodon relay server", zap.String("port", serverPortStr)) + zap.L().Info("starting mastodon relay server", zap.String("port", serverPortStr)) if err := c.server.Start(serverPortStr); err != nil && !errors.Is(err, http.ErrServerClosed) { zap.L().Error("server error", zap.Error(err)) @@ -248,7 +248,7 @@ func (c *client) startHTTPServer(ctx context.Context) error { return fmt.Errorf("server startup failed: %w", err) case <-startedCh: - zap.L().Info("HTTP server started successfully") + zap.L().Info("http server started successfully") return nil case <-ctx.Done(): @@ -392,7 +392,7 @@ func newSigner(instanceURL *url.URL) (httpsig.Signer, error) { headers = append(headers, headerHost, headerDigest) } - zap.L().Info("Creating signer", zap.String("instanceURL", instanceURL.String()), + zap.L().Info("creating signer", zap.String("instanceURL", instanceURL.String()), zap.Strings("headers", headers)) signer, _, err := httpsig.NewSigner( @@ -435,7 +435,7 @@ func generateKeyPair() (*rsa.PrivateKey, string, error) { // FollowRelayServices attempts to follow all configured relay services. func (c *client) FollowRelayServices(ctx context.Context) error { - zap.L().Debug("Beginning to follow relay services", zap.Strings("relayURLs", c.relayURLs)) + zap.L().Debug("beginning to follow relay services", zap.Strings("relayURLs", c.relayURLs)) var errs []error @@ -459,10 +459,13 @@ func (c *client) FollowRelayServices(ctx context.Context) error { continue } - zap.L().Warn("retry following relay", + zap.L().Warn("failed to follow relay, retrying", zap.String("instance", instance), - zap.Int("attempt", attempt), - zap.Error(err)) + zap.Int("currentAttempt", attempt), + zap.Int("maxAttempts", maxFollowRequestRetries), + zap.Duration("retryDelay", followRequestRetryDelay), + zap.Error(err), + ) time.Sleep(followRequestRetryDelay) } @@ -505,7 +508,7 @@ func (c *client) followRelay(ctx context.Context, instance string) error { return fmt.Errorf("failed to create and sign follow request: %w", err) } - zap.L().Info("Follow request created and signed successfully", + zap.L().Info("follow request created and signed successfully", zap.String("instanceURL", instanceURL.String()), zap.String("content", string(content)), ) @@ -515,6 +518,10 @@ func (c *client) followRelay(ctx context.Context, instance string) error { return fmt.Errorf("failed to send request for relay subscription: %w", err) } + zap.L().Info("successfully sent request to follow relay", + zap.String("instanceURL", instanceURL.String()), + ) + return nil } @@ -542,7 +549,7 @@ func (c *client) createAndSignFollowRequest(ctx context.Context, instanceURL *ur return nil, fmt.Errorf("signer cannot be nil") } - zap.L().Info("Creating follow request", zap.String("instanceURL", instanceURL.String()), + zap.L().Info("creating follow request", zap.String("instanceURL", instanceURL.String()), zap.ByteString("content", content)) reqURL := instanceURL.String() @@ -559,7 +566,7 @@ func (c *client) createAndSignFollowRequest(ctx context.Context, instanceURL *ur // Set Host header only if instance URL doesn't end in /inbox if !strings.HasSuffix(instanceURL.Path, inBoxPath) { req.Header.Set(headerHost, instanceURL.Host) - zap.L().Info("Set Host header", zap.String(headerHost, instanceURL.Host)) + zap.L().Info("set host header", zap.String(headerHost, instanceURL.Host)) } // Sign the request @@ -622,7 +629,7 @@ func (c *client) FetchAnnouncedObject(ctx context.Context, objectURL string) (*a activityURL += ActivitySuffix } - zap.L().Info("Fetching announced object with activity URL", + zap.L().Info("fetching announced object with activity URL", zap.String("activityURL", activityURL), ) @@ -690,7 +697,8 @@ func (c *client) GetMessageChan() (<-chan string, error) { // If the channel is full, the message is dropped and logged. func (c *client) SendMessage(msg string) { if msg == "" { - zap.L().Warn("empty message dropped") + zap.L().Debug("skipping empty message") + return } diff --git a/provider/ethereum/token/client.go b/provider/ethereum/token/client.go index 87843e0aa..1fa95717c 100644 --- a/provider/ethereum/token/client.go +++ b/provider/ethereum/token/client.go @@ -13,6 +13,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/redis/rueidis" + "github.com/rss3-network/node/internal/utils" "github.com/rss3-network/node/provider/ethereum" "github.com/rss3-network/node/provider/ethereum/contract" "github.com/rss3-network/node/provider/ethereum/contract/erc1155" @@ -348,7 +349,7 @@ func (c *client) lookupNFTByRedis(ctx context.Context, chainID uint64, address c func (c *client) lookupERC721(ctx context.Context, chainID uint64, address common.Address, id *big.Int, blockNumber *big.Int) (*metadata.Token, error) { tokenMetadata := metadata.Token{ Address: lo.ToPtr(address.String()), - ID: lo.ToPtr(decimal.NewFromBigInt(id, 0)), + ID: lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(id), 0)), Standard: metadata.StandardERC721, } @@ -420,7 +421,7 @@ func (c *client) lookupERC721(ctx context.Context, chainID uint64, address commo func (c *client) lookupERC1155(ctx context.Context, chainID uint64, address common.Address, id *big.Int, blockNumber *big.Int) (*metadata.Token, error) { tokenMetadata := metadata.Token{ Address: lo.ToPtr(address.String()), - ID: lo.ToPtr(decimal.NewFromBigInt(id, 0)), + ID: lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(id), 0)), Standard: metadata.StandardERC1155, } @@ -510,7 +511,7 @@ func (c *client) lookupENS(_ context.Context, _ uint64, address *common.Address, return &tokenMetadata, nil } - tokenMetadata.ID = lo.ToPtr(decimal.NewFromBigInt(id, 0)) + tokenMetadata.ID = lo.ToPtr(decimal.NewFromBigInt(utils.GetBigInt(id), 0)) return &tokenMetadata, nil } diff --git a/provider/farcaster/client.go b/provider/farcaster/client.go index 969a9cad8..7f92789f1 100644 --- a/provider/farcaster/client.go +++ b/provider/farcaster/client.go @@ -230,7 +230,7 @@ func (c *client) call(ctx context.Context, path string, query farcasterQuery, re // If the error is an HTTP error and the status code is 4xx, we will not retry. if errors.As(err, &httpErr) && httpErr.StatusCode >= http.StatusBadRequest && httpErr.StatusCode < http.StatusInternalServerError { - zap.L().Warn("failed to fetch farcaster request, will not retry", zap.Error(err), zap.Int("status.code", httpErr.StatusCode)) + zap.L().Error("failed to fetch farcaster request, will not retry", zap.Error(err), zap.Int("status.code", httpErr.StatusCode)) return retry.Unrecoverable(err) }