Skip to content

feat: Add timestamp argument for deterministic CID generation - #43

Merged
somasekimoto merged 7 commits into
mainfrom
fix/timestamp-argument
Dec 24, 2025
Merged

somasekimoto merged 7 commits into
mainfrom
fix/timestamp-argument

Conversation

@somasekimoto

@somasekimoto somasekimoto commented Dec 14, 2025

Copy link
Copy Markdown
Contributor

Summary

  • Add timestamp parameter to DAG node creation methods for deterministic CID generation
  • Add node_timestamp field to Operation for replication support with consistent CIDs
  • Support importing operations (including Merge) from replicas
  • Remove internal timestamp generation from DAG and resolver (caller now provides timestamp)

Changes

src/graph/dag.rs

  • Add timestamp parameter to add_node, add_genesis_node, add_child_node, prepare_genesis_node, prepare_child_node methods
  • Remove internal current_timestamp() helper (timestamp is now provided by caller)
  • Add documentation comments for all public methods

src/convergence/resolver.rs

  • Add timestamp parameter to create_merge_node method
  • Remove internal current_timestamp() helper
  • Add documentation comments

src/crdt/operation.rs

  • Add node_timestamp: Option<Timestamp> field for import operations
  • When set, this timestamp is used for CID generation instead of current time

src/repo.rs

  • Use next_monotonic_timestamp() for local operations
  • Use op.node_timestamp for import operations (replication)
  • Add stage_merge method for importing Merge operations from replicas
  • Rename resolve_metadata_for_commit to resolve_metadata with lenient flag
    • lenient=true: returns default metadata when nodes not found (for imports)
    • lenient=false: returns error when nodes not found (for local operations)
  • Add CID verification for import Create operations (ensures imported CID matches computed CID)
  • Add documentation comments for commit_operation and resolve_metadata

Test plan

  • Verify all existing tests pass with timestamp arguments
  • Confirm CID generation is deterministic when same timestamp is provided
  • Add test_import_operation_preserves_cid - verifies Create operation import
  • Add test_import_operation_update_preserves_cid - verifies Update operation import

🤖 Generated with Claude Code

@somasekimoto
somasekimoto marked this pull request as ready for review December 14, 2025 07:25
@somasekimoto
somasekimoto requested a review from Yu-da-1 December 14, 2025 07:26
Comment thread src/repo.rs
"Merge operations must be committed via auto-merge".to_string(),
));
}
self.stage_merge(payload, &op, timestamp, &mut pending_nodes)?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

これかなり重要な問題でしたね.....!ありがとうございます!!
思ったのが現状だと一応誰でもmerge操作をすることができちゃうと思っていて、これってどう制御するのが良さそうですかね。monasで考えるとネットワーク内のnodeからのみ受け入れるなど?

そもそもその制御はライブラリ側で行うことではなかったりしますかね??

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@Yu-da-1
マージできるユーザー権限の管理みたいなところですかね?それはここではやらないで外でやればいいと思います!今回だとstate-node側の実装ですね。

@somasekimoto
somasekimoto merged commit e13b86c into main Dec 24, 2025
4 checks passed
@somasekimoto
somasekimoto deleted the fix/timestamp-argument branch December 24, 2025 09:52
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