Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Refactor gossip protocol #308

Draft
wants to merge 111 commits into
base: main
Choose a base branch
from

Conversation

contrun
Copy link
Collaborator

@contrun contrun commented Nov 15, 2024

No description provided.

@contrun contrun force-pushed the refactor-gossip-protocol branch from 7c6d63e to 59490f3 Compare November 19, 2024 02:18
@contrun contrun force-pushed the refactor-gossip-protocol branch from 5314d08 to e8292e3 Compare November 19, 2024 13:22
@contrun contrun force-pushed the refactor-gossip-protocol branch from f74d85c to c7f98c5 Compare November 20, 2024 02:33
@@ -148,7 +148,7 @@ serde_with::serde_conv!(
);

#[serde_as]
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq)]
#[derive(Serialize, Deserialize, Debug, Clone, Default, Eq, PartialEq, Hash)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

These Eq and Hash added in this file is not necessary.

Suggest a clean up:

diff --git a/src/ckb/config.rs b/src/ckb/config.rs
index 9ddded8..d0e318d 100644
--- a/src/ckb/config.rs
+++ b/src/ckb/config.rs
@@ -148,7 +148,7 @@ serde_with::serde_conv!(
 );
 
 #[serde_as]
-#[derive(Serialize, Deserialize, Debug, Clone, Default, Eq, PartialEq, Hash)]
+#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq)]
 pub struct UdtScript {
     pub code_hash: H256,
     #[serde_as(as = "ScriptHashTypeWrapper")]
@@ -158,7 +158,7 @@ pub struct UdtScript {
 }
 
 #[serde_as]
-#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, Hash)]
+#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
 pub struct UdtCellDep {
     #[serde_as(as = "DepTypeWrapper")]
     pub dep_type: DepType,
@@ -166,7 +166,7 @@ pub struct UdtCellDep {
     pub index: u32,
 }
 
-#[derive(Serialize, Deserialize, Clone, Debug, Default, Eq, PartialEq, Hash)]
+#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq)]
 pub struct UdtArgInfo {
     pub name: String,
     pub script: UdtScript,
@@ -174,7 +174,7 @@ pub struct UdtArgInfo {
     pub cell_deps: Vec<UdtCellDep>,
 }
 
-#[derive(Serialize, Deserialize, Clone, Debug, Default, Eq, PartialEq, Hash)]
+#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq)]
 pub struct UdtCfgInfos(pub Vec<UdtArgInfo>);
 
 impl FromStr for UdtCfgInfos {
diff --git a/src/fiber/types.rs b/src/fiber/types.rs
index 16b08ec..a651290 100644
--- a/src/fiber/types.rs
+++ b/src/fiber/types.rs
@@ -1498,7 +1498,7 @@ impl TryFrom<molecule_fiber::AnnouncementSignatures> for AnnouncementSignatures
     }
 }
 
-#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, Hash)]
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
 pub struct NodeAnnouncement {
     // Signature to this message, may be empty the message is not signed yet.
     pub signature: Option<EcdsaSignature>,
@@ -2274,7 +2274,7 @@ impl TryFrom<molecule_gossip::GossipMessage> for GossipMessage {
     }
 }
 
-#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, Hash)]
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
 pub enum BroadcastMessage {
     NodeAnnouncement(NodeAnnouncement),
     ChannelAnnouncement(ChannelAnnouncement),

Comment on lines +90 to +96
// Whether we are receiving a channel update from node1 or node2.
// If the flag is set, it means the channel update is from node2, otherwise it is from node1.
pub const MESSAGE_OF_NODE1_FLAG: u32 = 0;

// Whether we are receiving a channel update from node1 or node2.
// If the flag is set, it means the channel update is from node2, otherwise it is from node1.
pub const MESSAGE_OF_NODE2_FLAG: u32 = 1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

The comments is not right.

// A test helper to get a timestamp which will always increment by 1 when called.
// This guarantees that the timestamp is always increasing in tests.
// now_timestamp may return two identical timestamps in consecutive calls.
pub fn now_timestamp() -> u64 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure why we need this in testing, as you said now_timestamp() may return two identical timestamp when call at the same time?

/// Must be a valid utf-8 string of length maximal length 32 bytes.
/// If the length is less than 32 bytes, it will be padded with 0.
/// If the length is more than 32 bytes, it should be truncated.
#[derive(Eq, PartialEq, Copy, Clone, Default, Hash)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Eq and Hash is not necessary afer removing them from BroadcastMessage, as above.

@contrun contrun force-pushed the refactor-gossip-protocol branch from 1e78fa8 to d8cceeb Compare December 10, 2024 07:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🏗 In progress
Development

Successfully merging this pull request may close these issues.

2 participants