Skip to content

Conversation

@neekolas
Copy link
Contributor

@neekolas neekolas commented Apr 24, 2025

TL;DR

  • Replace custom inbox topic format with standardized topic implementation for identity updates.
  • Adds a test for sequential identity update inserts

What changed?

  • Replaced the custom BuildInboxTopic function with the standardized topic.NewTopic implementation
  • Removed the now-unused BuildInboxTopic function
  • Added a test case TestStoreSequential to verify sequential identity updates work correctly with the new topic format

How to test?

  1. Run the identity update tests to verify they pass with the new topic format:
    go test -v ./pkg/indexer/storer -run TestStoreIdentityUpdate
    go test -v ./pkg/indexer/storer -run TestStoreSequential
    
  2. Verify that identity updates are properly stored and can be retrieved using the new topic format

Why make this change?

This change standardizes how we handle topics for identity updates by using the common topic package instead of a custom string format. This improves consistency across the codebase and ensures that all components use the same topic format when working with identity updates.

Summary by CodeRabbit

  • Tests
    • Improved error checking in existing identity update storage tests.
    • Added a new test to verify correct handling of sequential identity update logs.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 24, 2025

Walkthrough

The changes update the construction of the topic parameter used in querying gateway envelopes within the validateIdentityUpdate method of the IdentityUpdateStorer by removing the BuildInboxTopic helper function and replacing it with a direct call to topic.NewTopic. Additionally, a new test function, TestStoreSequential, is introduced to verify sequential storage and validation of identity update logs, including the interaction with the mocked validation service and the state of stored envelopes.

Changes

File(s) Change Summary
pkg/indexer/storer/identityUpdate.go Removed BuildInboxTopic function; replaced topic construction in validateIdentityUpdate with direct call to topic.NewTopic.
pkg/indexer/storer/identityUpdate_test.go Added TestStoreSequential to test sequential identity update log storage and validation service interaction; refactored existing test for streamlined error checking.

Sequence Diagram(s)

sequenceDiagram
    participant Test as TestStoreSequential
    participant Storer as IdentityUpdateStorer
    participant Validation as MockedMLSValidationService
    participant DB as GatewayEnvelopeStore

    Test->>Storer: StoreLog(identityUpdateLog1)
    Storer->>Validation: GetAssociationStateFromEnvelopes([])
    Validation-->>Storer: StateDiff with new member
    Storer->>DB: Store envelope for log1

    Test->>DB: Query envelopes for inboxId
    DB-->>Test: Return 1 envelope

    Test->>Storer: StoreLog(identityUpdateLog2)
    Storer->>Validation: GetAssociationStateFromEnvelopes([envelope1])
    Validation-->>Storer: Empty StateDiff
    Storer->>DB: Store envelope for log2 (if valid)
Loading

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (1.64.8)

Error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2
Failed executing command with error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2

✨ Finishing Touches
  • 📝 Generate Docstrings

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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 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.

Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@macroscopeapp
Copy link

macroscopeapp bot commented Apr 24, 2025

Replace string-based inbox topic formatting with structured topic creation in identity update storer to fix topic identifier construction

  • Replaces the BuildInboxTopic string formatting approach with structured topic creation using topic.NewTopic in identityUpdate.go
  • Adds sequential identity update storage test in identityUpdate_test.go to verify state maintenance across multiple updates with incrementing sequence IDs

📍Where to Start

Start with the validateIdentityUpdate function in identityUpdate.go which contains the core changes to topic creation logic.


Macroscope summarized 3c4bf78.

@neekolas neekolas force-pushed the 04-24-fix_issue_with_identity_update_storer branch from 7030e20 to 3c4bf78 Compare April 24, 2025 18:22
Copy link
Contributor

@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.

Caution

Inline review comments failed to post. This is likely due to GitHub's limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.

Actionable comments posted: 1

🧹 Nitpick comments (2)
pkg/indexer/storer/identityUpdate_test.go (2)

124-125: Consider adding more specific assertions.

While checking the length of previous envelopes is good, consider adding more specific assertions to verify the exact content and sequence ID of the previous envelope.

 if numCalls > 1 {
   require.Len(t, prevEnvs, 1)
+  require.Equal(t, int64(sequenceID), prevEnvs[0].OriginatorSequenceID)
+  // Add additional checks for the envelope content if needed

172-173: Missing envelope content verification.

While you're checking the count of envelopes, consider adding verification of the envelope content after the first store operation, similar to what you do in TestStoreIdentityUpdate (lines 104-106).

 require.NoError(t, queryErr)
 require.Equal(t, len(envelopes), 1)
+
+// Verify the content of the stored envelope
+firstEnvelope := envelopes[0]
+deserializedEnvelope := envelopesProto.OriginatorEnvelope{}
+require.NoError(t, proto.Unmarshal(firstEnvelope.OriginatorEnvelope, &deserializedEnvelope))
+require.Greater(t, len(deserializedEnvelope.UnsignedOriginatorEnvelope), 0)
🛑 Comments failed to post (1)
pkg/indexer/storer/identityUpdate_test.go (1)

184-185: 🛠️ Refactor suggestion

Add verification after second update.

The test stores a second update but doesn't verify that there are now two envelopes or check the sequence ID of the second envelope. Consider adding this verification.

 	require.NoError(t, storer.StoreLog(
 		ctx,
 		logMessage,
 	))
+
+	// Verify that both envelopes are now stored
+	envelopes, queryErr = querier.SelectGatewayEnvelopes(
+		ctx,
+		queries.SelectGatewayEnvelopesParams{
+			OriginatorNodeIds: []int32{IDENTITY_UPDATE_ORIGINATOR_ID},
+			RowLimit:          10,
+		},
+	)
+	require.NoError(t, queryErr)
+	require.Equal(t, 2, len(envelopes))
+	
+	// Check that the sequence IDs are correct
+	var sequenceIDs []int64
+	for _, env := range envelopes {
+		sequenceIDs = append(sequenceIDs, env.OriginatorSequenceID)
+	}
+	require.Contains(t, sequenceIDs, int64(sequenceID))
+	require.Contains(t, sequenceIDs, int64(sequenceID+1))
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

	require.NoError(t, storer.StoreLog(
		ctx,
		logMessage,
	))

	// Verify that both envelopes are now stored
	envelopes, queryErr = querier.SelectGatewayEnvelopes(
		ctx,
		queries.SelectGatewayEnvelopesParams{
			OriginatorNodeIds: []int32{IDENTITY_UPDATE_ORIGINATOR_ID},
			RowLimit:          10,
		},
	)
	require.NoError(t, queryErr)
	require.Equal(t, 2, len(envelopes))

	// Check that the sequence IDs are correct
	var sequenceIDs []int64
	for _, env := range envelopes {
		sequenceIDs = append(sequenceIDs, env.OriginatorSequenceID)
	}
	require.Contains(t, sequenceIDs, int64(sequenceID))
	require.Contains(t, sequenceIDs, int64(sequenceID+1))
}

Copy link
Contributor

@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: 0

🧹 Nitpick comments (1)
pkg/indexer/storer/identityUpdate_test.go (1)

110-170: Good addition of sequential update test case.

This test effectively validates that sequential identity updates for the same inbox work correctly with the new topic implementation. It properly tests the validation service interaction by ensuring previous envelopes are correctly passed to subsequent validation calls.

Consider enhancing this test by verifying the database state after both store operations, similar to how TestStoreIdentityUpdate checks for stored envelopes and address logs. This would provide a more complete verification that both updates were properly persisted.

 	require.NoError(t, storer.StoreLog(
 		ctx,
 		logMessage,
 	))
+
+	// Verify database state after storing both updates
+	querier := queries.New(storer.db)
+
+	envelopes, queryErr := querier.SelectGatewayEnvelopes(
+		ctx,
+		queries.SelectGatewayEnvelopesParams{
+			OriginatorNodeIds: []int32{IDENTITY_UPDATE_ORIGINATOR_ID},
+			RowLimit:          10,
+		},
+	)
+	require.NoError(t, queryErr)
+	require.Equal(t, len(envelopes), 2) // Should have two envelopes now
+
+	getInboxIdResult, logsErr := querier.GetAddressLogs(ctx, []string{newAddress})
+	require.NoError(t, logsErr)
+	require.Equal(t, getInboxIdResult[0].InboxID, utils.HexEncode(inboxId[:]))
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7030e20 and 3c4bf78.

📒 Files selected for processing (2)
  • pkg/indexer/storer/identityUpdate.go (1 hunks)
  • pkg/indexer/storer/identityUpdate_test.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/indexer/storer/identityUpdate.go
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Test (Node)
  • GitHub Check: Upgrade Tests
🔇 Additional comments (1)
pkg/indexer/storer/identityUpdate_test.go (1)

83-86: Good refactoring of error handling.

The simplified error handling improves code readability by directly asserting no error from storer.StoreLog instead of using an intermediate error variable. This reduces unnecessary code while maintaining the same functionality.

@neekolas neekolas marked this pull request as ready for review April 24, 2025 18:39
@neekolas neekolas requested a review from a team as a code owner April 24, 2025 18:39
@mkysel mkysel merged commit ef993b8 into main Apr 24, 2025
9 checks passed
@mkysel mkysel deleted the 04-24-fix_issue_with_identity_update_storer branch April 24, 2025 18:41
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.

3 participants