Skip to content

New Release#465

Merged
ziscky merged 2 commits into
mainfrom
dev
Jul 29, 2025
Merged

New Release#465
ziscky merged 2 commits into
mainfrom
dev

Conversation

@ziscky
Copy link
Copy Markdown
Contributor

@ziscky ziscky commented Jul 29, 2025

🔗 zboto Link

Summary by CodeRabbit

  • New Features

    • Added comprehensive support for parsing and displaying deal-related events, including deal messages, proposals, activations, and space usage information.
    • Introduced new data structures and event generation for deal lifecycle events, enhancing visibility into deal activities.
    • Added new utility functions for extracting and converting values from generic data structures.
  • Bug Fixes

    • Improved handling of specific transaction types when retrieving block CIDs.
  • Refactor

    • Centralized and standardized utility functions for data extraction and parsing.
    • Updated internal logic to use common utility functions, reducing code duplication.
  • Tests

    • Added and updated unit tests for new utility functions and deal event parsing.
    • Removed obsolete tests for deprecated utility functions.
  • Chores

    • Updated external node URL in test configuration.

ziscky added 2 commits July 24, 2025 17:43
* feat: deals parsing template

* feat: add parsing of storage deals proposals

* feat: add dealIds to miner sector data

* feat: conditional version

* feat: impl. ParseDealsEvent on parserV1

* refactor: move common methods to diff. pkg

* test: update utils tests

* fix: lint

* refactor: move common methods to diff. pkg

* feat: parse deal space/weight info and activations

* fix: refactor struct names

* fix: use correct return type

* fix: remove unused metrics

* fix: parsing bugs

* fix: parsing bugs

* fix: activation parsing bugs

* fix: lint

* fix: test case

* feat: add comments on version switches

* test: use hel1 light node

* test: use zur1 full node
* fix: skip special case check for block cids

* fix: lint
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jul 29, 2025

Walkthrough

This change introduces comprehensive support for parsing and generating deal-related events from blockchain transactions. It adds new utility packages and event generators for deals, implements parsing logic for deal proposals and activations, and defines new types for structured deal event data. Existing miner utilities are refactored to use the new common utilities, and related tests are updated or removed accordingly. The parser's interface and implementation are extended to expose deal event parsing, and a new constant for batch deal activation is added.

Changes

Cohort / File(s) Change Summary
Deal Event Parsing Infrastructure
tools/deals/deals.go, tools/deals/activations.go, tools/deals/proposal.go, tools/deals/messages.go, tools/deals/metrics.go
Introduces a new deals event generator package: implements event parsing for deal messages, proposals, activations, and space info; defines an event generator interface and implementation; adds metrics client for deals parsing; handles multiple network versions and transaction types.
Deal Event Data Types
types/deals.go
Adds new data structures for deal events: DealsEvents, DealsMessages, DealsProposals, DealsActivations, and DealsSpaceInfo with relevant fields for each deal lifecycle stage.
Common Parsing Utilities
tools/common/utils.go, tools/common/utils_test.go
Adds a new common utility package for extracting and converting typed values from generic maps, including big integers, integers, slices, CIDs, and decoding JSON-encoded bitfields; provides comprehensive unit tests for these utilities.
Parser Interface and Implementation
factory.go, parser/v1/parser.go, parser/v2/parser.go
Extends the parser interface and both v1/v2 implementations to support deal event parsing; adds a new method ParseDealsEvents and integrates the deals event generator into parser constructors.
Parser Constants
parser/constants.go
Adds a new constant MethodBatchActivateDeals to the set of recognized market method names.
Miner Utilities Refactor
tools/miner/info.go, tools/miner/sector.go, tools/miner/utils.go, tools/miner/utils_test.go
Refactors miner parsing logic to use new common utility functions; removes all local generic helper functions and their tests; adds support for extracting deal IDs in sector pre-commit events.
Miner Bitfield Test Removal
tools/miner/sector_test.go
Deletes the test for bitfield decoding, now replaced by common utility tests.
Parser Test Update
parser_test.go
Updates the node URL constant for mainnet RPC endpoint in tests.
Block CID Extraction Logic
actors/v2/tools.go
Modifies block CID extraction logic: narrows early return to only the block reward method, allowing other transaction types to attempt block CID retrieval from the tipset.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Parser
    participant DealsEventGenerator
    participant Helper/Logger/Metrics

    Client->>Parser: ParseDealsEvents(ctx, txs, tipsetCid, tipsetKey)
    Parser->>DealsEventGenerator: GenerateDealsEvents(ctx, txs, tipsetCid, tipsetKey)
    DealsEventGenerator->>Helper/Logger/Metrics: (Resolve actor info, log, update metrics)
    DealsEventGenerator-->>Parser: DealsEvents (messages, proposals, activations, space info)
    Parser-->>Client: DealsEvents
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dev

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@ziscky ziscky requested a review from emmanuelm41 July 29, 2025 16:09
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 9

🧹 Nitpick comments (3)
tools/common/utils_test.go (2)

16-34: Add error condition test cases.

The test covers basic functionality but lacks coverage for error conditions. Consider adding test cases for:

  • Invalid string format that can't be converted to big.Int
  • Missing key when canBeNil is false
  • Nil params when canBeNil is false
		{name: "test 3", params: map[string]interface{}{key: ""}, canBeNil: true, want: nil},
+		{name: "invalid format", params: map[string]interface{}{key: "invalid"}, canBeNil: false, expectError: true},
+		{name: "missing key", params: map[string]interface{}{}, canBeNil: false, expectError: true},

36-54: Add error condition test cases.

Similar to TestGetBigInt, this test lacks coverage for error conditions. Consider adding test cases for:

  • Wrong type input (e.g., string instead of float64)
  • Missing key when canBeNil is false
types/deals.go (1)

15-23: Consider adding documentation for the Value field.

The Value field's purpose is unclear from its name alone. Consider adding a comment to clarify what type of value this represents (e.g., transaction value, deal value, etc.).

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Knowledge Base: Disabled due to Reviews > Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between 07d8f14 and 527011b.

📒 Files selected for processing (19)
  • actors/v2/tools.go (2 hunks)
  • factory.go (2 hunks)
  • parser/constants.go (1 hunks)
  • parser/v1/parser.go (5 hunks)
  • parser/v2/parser.go (5 hunks)
  • parser_test.go (1 hunks)
  • tools/common/utils.go (1 hunks)
  • tools/common/utils_test.go (1 hunks)
  • tools/deals/activations.go (1 hunks)
  • tools/deals/deals.go (1 hunks)
  • tools/deals/messages.go (1 hunks)
  • tools/deals/metrics.go (1 hunks)
  • tools/deals/proposal.go (1 hunks)
  • tools/miner/info.go (12 hunks)
  • tools/miner/sector.go (14 hunks)
  • tools/miner/sector_test.go (0 hunks)
  • tools/miner/utils.go (0 hunks)
  • tools/miner/utils_test.go (0 hunks)
  • types/deals.go (1 hunks)
💤 Files with no reviewable changes (3)
  • tools/miner/sector_test.go
  • tools/miner/utils_test.go
  • tools/miner/utils.go
🧰 Additional context used
🧬 Code Graph Analysis (9)
factory.go (2)
types/transaction.go (1)
  • Transaction (14-46)
types/deals.go (1)
  • DealsEvents (8-13)
tools/common/utils_test.go (1)
tools/common/utils.go (4)
  • GetBigInt (13-26)
  • GetInteger (28-35)
  • GetIntegerSlice (37-49)
  • JsonEncodedBitfieldToIDs (120-147)
tools/deals/messages.go (5)
types/transaction.go (1)
  • Transaction (14-46)
types/deals.go (1)
  • DealsMessages (15-23)
tools/version_mapping.go (2)
  • VersionFromHeight (317-373)
  • V20 (96-96)
parser/constants.go (2)
  • MethodActivateDeals (154-154)
  • MethodBatchActivateDeals (155-155)
tools/tools.go (1)
  • BuildId (30-41)
actors/v2/tools.go (1)
parser/constants.go (1)
  • MethodAwardBlockReward (75-75)
tools/deals/deals.go (5)
types/transaction.go (1)
  • Transaction (14-46)
types/deals.go (5)
  • DealsEvents (8-13)
  • DealsMessages (15-23)
  • DealsProposals (25-54)
  • DealsActivations (56-64)
  • DealsSpaceInfo (66-81)
parser/helper/helpers.go (1)
  • Helper (140-147)
metrics/client.go (1)
  • MetricsClient (12-15)
parser/constants.go (8)
  • MethodUpdateClaimedPower (80-80)
  • TotalFeeOp (10-10)
  • MethodPublishStorageDeals (149-149)
  • MethodPublishStorageDealsExported (150-150)
  • MethodVerifyDealsForActivation (153-153)
  • MethodActivateDeals (154-154)
  • MethodSettleDealPaymentsExported (170-170)
  • MethodSectorContentChanged (171-171)
parser/v2/parser.go (6)
tools/deals/deals.go (2)
  • EventGenerator (22-24)
  • NewEventGenerator (35-42)
logger/logger.go (1)
  • GetSafeLogger (7-17)
parser/v1/parser.go (1)
  • Parser (42-56)
factory.go (1)
  • Parser (48-60)
types/transaction.go (1)
  • Transaction (14-46)
types/deals.go (1)
  • DealsEvents (8-13)
tools/miner/sector.go (4)
tools/common/utils.go (5)
  • GetItem (66-84)
  • GetInteger (28-35)
  • GetIntegerSlice (37-49)
  • GetSlice (86-113)
  • JsonEncodedBitfieldToIDs (120-147)
tools/deals/proposal.go (2)
  • KeyParams (30-30)
  • KeyDealIDs (17-17)
tools/deals/activations.go (1)
  • KeySectors (16-16)
types/miner.go (1)
  • MinerSectorEvent (19-28)
parser/v1/parser.go (5)
tools/deals/deals.go (2)
  • EventGenerator (22-24)
  • NewEventGenerator (35-42)
logger/logger.go (1)
  • GetSafeLogger (7-17)
factory.go (1)
  • Parser (48-60)
parser/v2/parser.go (1)
  • Parser (44-58)
types/deals.go (1)
  • DealsEvents (8-13)
tools/deals/metrics.go (1)
metrics/client.go (2)
  • MetricsClient (12-15)
  • Metric (17-22)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Analyze (go)
  • GitHub Check: tests
  • GitHub Check: build
  • GitHub Check: checks
  • GitHub Check: Analyze (go)
  • GitHub Check: tests
🔇 Additional comments (24)
parser_test.go (1)

58-58: Good infrastructure improvement.

Updating from a "light" node to a "stable" node endpoint is a sensible change for tests, as stable nodes provide better reliability and consistency for test execution.

parser/constants.go (1)

155-155: Well-structured constant addition.

The new MethodBatchActivateDeals constant follows the established naming convention and is logically placed after the related MethodActivateDeals constant. This addition supports batch processing of deal activations for enhanced performance in newer network versions.

tools/miner/info.go (1)

9-9: Excellent refactoring to centralize utility functions.

The migration from local getItem and getSlice helper functions to the centralized common.GetItem and common.GetSlice functions is a positive change that:

  • Reduces code duplication across the codebase
  • Improves maintainability by centralizing common functionality
  • Maintains consistent error handling patterns
  • Follows good software engineering practices

The changes are systematically applied across all parsing functions while preserving the existing logic and error handling.

Also applies to: 62-69, 100-103, 135-150, 190-196, 236-242, 277-277, 304-323, 314-338

actors/v2/tools.go (1)

111-138: Review: Verify the intentional drop of “empty‐block” special cases

It looks like v2/tools.go now only treats MethodAwardBlockReward as a special case; all the other transaction types that used to immediately return an empty blockCid will now fall through and hit the default lookup in tipset.BlockMessages. Please confirm:

  • That ExtendedTipSet.BlockMessages is indeed populated (or intentionally left empty) for the previously‐skipped tx types.
  • That no downstream code or tests rely on those types returning "" unconditionally.

If this change is by design (i.e. you want default lookup to handle them, or simply return "" if they never appear in any block), then no further action is needed. Otherwise, restore the excluded tx types or add any missing special cases back.

factory.go (1)

56-56: LGTM! Well-implemented interface extension.

The new ParseDealsEvents method follows the established pattern of other event parsing methods. The interface definition is clean and the implementation correctly delegates to parserV2, maintaining consistency with other event parsing functionality.

Also applies to: 247-249

tools/miner/sector.go (1)

11-11: Excellent refactoring with valuable feature addition.

This refactoring successfully centralizes utility functions from local implementations to the tools/common package, improving code maintainability. The addition of KeyDealIDs support in pre-commit events is a valuable enhancement that allows tracking of deal associations with sectors.

The consistent replacement of functions like getIntegercommon.GetInteger and jsonEncodedBitfieldToSectorNumberscommon.JsonEncodedBitfieldToIDs follows good practices for code deduplication.

Also applies to: 21-21, 129-132, 142-142

parser/v2/parser.go (1)

31-31: Perfect integration following established patterns.

The deals event parsing integration is implemented consistently with existing event generators. The field placement, constructor initialization, and method implementation all follow the established patterns used by multisigEventGenerator and minerEventGenerator.

The delegation to dealsEventGenerator.GenerateDealsEvents maintains the separation of concerns and keeps the parser focused on orchestration rather than implementation details.

Also applies to: 53-53, 75-75, 94-94, 299-301

tools/deals/metrics.go (1)

45-52: Avoid modifying metric definitions in place

The method modifies the input metrics by appending to their Labels slice directly. This could cause issues if the same metric definitions are reused elsewhere, leading to duplicate labels being appended.

 func (c *dealsMetricsClient) registerModuleMetrics(metrics ...metrics.Metric) {
 	commonLabels := []string{parserModule}
 	for i := range metrics {
-		metrics[i].Labels = append(metrics[i].Labels, commonLabels...)
+		// Create a copy of the metric to avoid modifying the original
+		metricCopy := metrics[i]
+		metricCopy.Labels = append(metricCopy.Labels, commonLabels...)
+		metrics[i] = metricCopy
 	}
 
 	c.RegisterCustomMetrics(metrics...)
 }

Likely an incorrect or invalid review comment.

types/deals.go (4)

8-13: LGTM!

The DealsEvents struct is well-structured as a container for different types of deal events, using pointer slices appropriately for memory efficiency.


25-54: LGTM!

The DealsProposals struct is well-designed with appropriate types and excellent documentation for complex fields. The use of *big.Int for collateral values is the correct choice for handling large blockchain values.


56-64: LGTM!

The DealsActivations struct is well-structured with appropriate types for representing deal activation events.


66-81: LGTM!

The DealsSpaceInfo struct is excellently documented with clear explanations of the space and weight fields. The use of *big.Int for space values and the SpaceAsWeight flag with its detailed comment make the struct's purpose and usage clear.

tools/deals/activations.go (7)

15-23: LGTM!

Well-organized constants for map keys used throughout the parsing logic.


25-65: LGTM!

The createDealActivations function correctly handles different transaction types and appropriately manages optional return values for different network versions.


168-243: LGTM!

The parseActivateDeals function elegantly handles version-specific parsing with a well-structured nested function approach. The version branching and error handling are comprehensive.


245-262: LGTM!

Clean helper function with appropriate use of named returns and proper error handling.


264-275: LGTM!

Simple and focused helper function with proper error handling.


277-300: LGTM!

Well-implemented function that correctly handles optional fields and properly accumulates big.Int values for verified deal space calculation.


302-311: LGTM!

Clean helper function that clearly identifies deal activation transaction types.

parser/v1/parser.go (5)

30-30: LGTM!

The import alias follows the established pattern used for other tool packages.


49-49: LGTM!

The field addition follows the established pattern and is positioned appropriately within the struct.


73-73: LGTM!

The deals event generator initialization follows the established pattern with appropriate parameters.


89-89: LGTM!

The deals event generator initialization in the v2 constructor is consistent with the pattern and uses the correct network parameter.


230-232: LGTM!

The method implementation correctly delegates to the deals event generator and matches the interface signature. The parameter naming follows established conventions.

Comment thread tools/common/utils_test.go
Comment thread tools/common/utils_test.go
Comment thread tools/common/utils_test.go
Comment thread tools/common/utils.go
Comment on lines +144 to +161
for i := 0; i < len(sectorDeals); i++ {
dealIDs, nonVerifiedDealWeight, verifiedDealWeight, err := eg.getCommonVerifyDealForActivationFields(sectorDeals[i], sectorWeights[i])
if err != nil {
return nil, err
}

dealSpaceInfo = append(dealSpaceInfo, &types.DealsSpaceInfo{
ID: tools.BuildId(tx.TxCid, tx.TxFrom, tx.TxTo, fmt.Sprint(tx.Height), tx.TxType, fmt.Sprint(dealIDs[i])),
Height: tx.Height,
TxCid: tx.TxCid,
DealIDs: dealIDs,
NonVerifiedDealSpace: nonVerifiedDealWeight,
VerifiedDealSpace: verifiedDealWeight,
SpaceAsWeight: true,
ActionType: tx.TxType,
TxTimestamp: tx.TxTimestamp,
})
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix array indexing error in DealSpaceInfo ID generation.

The loop iterates through all sectorDeals, but line 151 uses dealIDs[i] which will cause an index out of bounds error. Should use the entire dealIDs array or iterate through dealIDs separately.

Apply this diff to fix the issue:

-				ID:                   tools.BuildId(tx.TxCid, tx.TxFrom, tx.TxTo, fmt.Sprint(tx.Height), tx.TxType, fmt.Sprint(dealIDs[i])),
+				ID:                   tools.BuildId(tx.TxCid, tx.TxFrom, tx.TxTo, fmt.Sprint(tx.Height), tx.TxType, fmt.Sprint(dealIDs)),
🤖 Prompt for AI Agents
In tools/deals/activations.go around lines 144 to 161, the code incorrectly uses
dealIDs[i] inside the loop over sectorDeals, causing an index out of bounds
error. To fix this, do not index dealIDs with i; instead, use the entire dealIDs
slice as is when building the ID or iterate separately over dealIDs if
individual IDs are needed. Adjust the code so that the ID generation correctly
handles all dealIDs without indexing errors.

Comment thread tools/deals/deals.go
Comment thread tools/deals/messages.go
Comment thread tools/deals/metrics.go
Comment thread tools/deals/proposal.go
@ziscky ziscky merged commit 0a7256b into main Jul 29, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants