-
Notifications
You must be signed in to change notification settings - Fork 11
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
contrun
wants to merge
112
commits into
nervosnetwork:main
Choose a base branch
from
contrun:refactor-gossip-protocol
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
112 commits
Select commit
Hold shift + click to select a range
63a316b
Split message to gossip and fiber
contrun b08bb66
Add gossip message definition
contrun 703df22
Fix types.rs for newer gossip message
contrun 2af5ab5
Fix compilation error because message change
contrun 9ca595d
Register gossip protocol
contrun 2b5223f
Rename FiberBroadcastMessage to BroadcastMessage
contrun b0cfb5a
Use separate response type in fiber gossip protocol
contrun 654db4d
Use channel outpoint to query all gossip messages
contrun fa7b3c1
Add missing comments for QueryBroadcastMessagesResult
contrun c533ad1
Fix compilation becasue message protocol change
contrun 3c36de3
Use struct for gossip message if possible
contrun 3353246
Relocate gossip only data structure
contrun 164bba1
Remove message queue while syncing
contrun 7c96a2d
Add Cursor type
contrun 3ced134
Add network actor event GossipMessage
contrun 59490f3
Test Channel{Anouncement,Update} cursor serder
contrun fd0ba19
Add separate gossip protocol handler
contrun 6d84648
Receive service control in pre_start for gossip actor
contrun e8292e3
Implement some gossip message processing
contrun a832ef6
Remove some gossip message command in network actor
contrun c7f98c5
Add types BroadcastMessageQueryFlags BroadcastMessageWithTimestamp
contrun 3181b48
Add gossip message store
contrun 8b60e78
Implement gossip message store
contrun 5437693
Use GossipMessageStore in gossip actor
contrun b6345e6
Avoid overwriting channel updates of the same outpoint
contrun aa964be
Fix BroadcastMessageQueryFlags values
contrun a3878aa
Process BroadcastMessagesFilterResult
contrun cefccfd
Handle more gossip messages
contrun 183160f
Remove graph syncer
contrun 6d94ebc
Remove syncing status
contrun afb2033
Remove get current block number
contrun 95b7108
Mock sending gossip message
contrun 1fc73dd
Start the syncing process
contrun 75e0ae6
Refactor graph for the new gossip message store
contrun 9ba61fb
Fix tests compilation
contrun 9953b04
Add actor message to process a single broadcast message
contrun f963f88
Add chain_hash to QueryBroadcastMessages
contrun 82387ab
Add iterator function for GossipMessageStore
contrun 648de45
Add methods to save refined broadcast messages
contrun bd37e88
Implement get_{nodes,channels}_with_params
contrun 97148ab
Fix graph tests compilation
contrun 5160163
Fix batch not commited in store
contrun 977feb8
Fix graph store tests
contrun 864f8bf
Add tests for saving channel updates
contrun 5242732
Fix gossip message store get_broadcast_messages_iter
contrun e2a1b38
Fix gossip message store get_broadcast_messages
contrun c460d4e
Fix potential infinite loop because cursor not updated
contrun 73ae939
Fix graph tests because outdated message
contrun d109d19
Don't use identical gossip actor name
contrun e586f9e
Fix wrong channel update direction implementation
contrun c666fea
Fix timestamp issue in tests
contrun 711a585
Fix test_sync_node_announcement_version
contrun 948a514
Fix test_connect_to_peers_with_mutual_channel_on_restart
contrun 34dd7bd
Persist peer id to pubkey map
contrun 05b750c
Use smaller network maintenance interval for tests
contrun b4dd4c3
Remove outdated test helper functions
contrun 07c21b1
Fix channel update timestamp
contrun 6917331
Broadcast messsages to peers who sent filter
contrun e1eadce
Fix some comments because of refactoring
contrun 7c4c7ea
Avoid verifying broadcast message multiple times
contrun 08175d5
Use old peer state while sending gossip messages
contrun a3fe47a
Ignore existing while adding peers for filters
contrun 188f760
Save and send queries for missing messages
contrun 3e0db13
Remove sent messages cache in gossip
contrun 8bf8722
Add gossip syncing actor
contrun 4477356
Fix returning new broadcast message in test memory store
contrun b8da14c
Bookkeep syncing status only in syncer
contrun 3ecf5d5
Remove pending_broadcast_messages in gossip actor
contrun fbe2447
Reject broadcast messages from the far future
contrun 3a817bd
Only broadcast messages when we have related messages in store
contrun 7d9a15e
Broadcast many messages in one go
contrun cd5410e
Add SubscribableGossipMessageStore trait
contrun b9e230e
Remove save_broadcast_message from GossipMessageStore trait
contrun f1e6f01
Implement SubscribableGossipMessageStore
contrun a386fe5
Make SubscribableGossipMessageStore independent from GossipMessageStore
contrun 2324acb
Subscribe gossip message store updates for network graph
contrun 44c6e63
Update comments
contrun 70c0414
Fix not connecting to announced nodes
contrun 1041361
Simplify implementation of creating a channel
contrun d5ad36c
Add message saving notification
contrun 7078158
Fix condition in checking new get request
contrun be28389
Add a function to go back some time for cursor
contrun 9045f3f
Remove after cursor from peer state
contrun 2ff09ff
Use dedicated actor for active syncing
contrun d2cabb0
Fix test channel update version
contrun 250b25b
More properly guarantee block identical timestamp
contrun 9f5a434
Read private key from fiber config in tests
contrun 44173dc
Fix starting active syncing condition
contrun 0f2d1da
Encapsulate network graph in test network node
contrun 52fb671
Fix using the wrong channel update in certain test
contrun e036507
Fix missing gossip message updates for store
contrun de09c81
Make gossip store maintenance interval configurable
contrun c49878e
Simplify initial loading of store subscribers
contrun af9acf2
Add subscription id for better debugging info
contrun 47d6613
Fix returned gossip messages not ordered
contrun b837783
Correctly update last cursor in gossip store tick handler
contrun 58a9e44
Ignore my own node announcement while sampling addresses from graph
contrun 5d5659a
Fix channel update of different nodes
contrun f936f42
Fix a few syncing test cases
contrun d8cceeb
Merge remote-tracking branch 'nervosnetwork/main' into refactor-gossi…
contrun 14f2869
Merge remote-tracking branch 'nervosnetwork/main' into refactor-gossi…
contrun ff65a51
Avoid skipping some messages in graph tests
contrun d396ca4
Remove git merge temp files
contrun f8bb4c0
Fix get broadcast messages implementation
contrun 17bd3be
Fix broadcast messages not sent
contrun 620e31b
Update graph while building payment path
contrun 37d9291
Fix flaky test test_remove_tlc_with_expiry_error
contrun 0b9d9c1
Remove unused code
contrun 0154c6c
Remove duplicated expiry addition
contrun 37624f7
Remove lagged messages in gossip message store actor
contrun 8d057e9
Update comments for store updates subscription
contrun f79c059
Order messages by dependency relationship
contrun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,10 @@ use crate::{ | |
fiber::{ | ||
fee::calculate_tlc_forward_fee, | ||
network::{get_chain_hash, SendOnionPacketCommand}, | ||
serde_utils::PubNonceAsBytes, | ||
types::{ChannelUpdate, PeeledPaymentOnionPacket, TlcErr, TlcErrPacket, TlcErrorCode}, | ||
types::{ | ||
BroadcastMessage, ChannelUpdate, PeeledPaymentOnionPacket, TlcErr, TlcErrPacket, | ||
TlcErrorCode, | ||
}, | ||
}, | ||
invoice::{CkbInvoice, CkbInvoiceStatus, InvoiceStore}, | ||
now_timestamp_as_millis_u64, | ||
|
@@ -70,7 +72,7 @@ use super::{ | |
hash_algorithm::HashAlgorithm, | ||
key::blake2b_hash_with_salt, | ||
network::FiberMessageWithPeerId, | ||
serde_utils::EntityHex, | ||
serde_utils::{EntityHex, PubNonceAsBytes}, | ||
types::{ | ||
AcceptChannel, AddTlc, ChannelAnnouncement, ChannelReady, ClosingSigned, CommitmentSigned, | ||
EcdsaSignature, FiberChannelMessage, FiberMessage, Hash256, OpenChannel, | ||
|
@@ -90,6 +92,14 @@ pub const FUNDING_CELL_WITNESS_LEN: usize = 16 + 32 + 64; | |
// is funded or not. | ||
pub const INITIAL_COMMITMENT_NUMBER: u64 = 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_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; | ||
Comment on lines
+95
to
+101
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comments is not right. |
||
|
||
// The channel is disabled, and no more tlcs can be added to the channel. | ||
pub const CHANNEL_DISABLED_FLAG: u32 = 1; | ||
|
||
|
@@ -1630,10 +1640,9 @@ where | |
|
||
self.network | ||
.send_message(NetworkActorMessage::new_command( | ||
NetworkActorCommand::ProccessChannelUpdate( | ||
self.get_remote_peer_id(), | ||
update, | ||
), | ||
NetworkActorCommand::BroadcastMessages(vec![ | ||
BroadcastMessage::ChannelUpdate(update), | ||
]), | ||
)) | ||
.expect(ASSUME_NETWORK_ACTOR_ALIVE); | ||
|
||
|
@@ -3272,6 +3281,11 @@ impl ChannelActorState { | |
.get_unsigned_channel_update_message() | ||
.expect("public channel can generate channel update message"); | ||
f(&mut channel_update); | ||
debug!( | ||
"Generated channel update message for channel {:?}: {:?}", | ||
&self.get_id(), | ||
&channel_update | ||
); | ||
let node_signature = | ||
sign_network_message(network.clone(), channel_update.message_to_sign()) | ||
.await | ||
|
@@ -3312,10 +3326,9 @@ impl ChannelActorState { | |
|
||
network | ||
.send_message(NetworkActorMessage::new_command( | ||
NetworkActorCommand::ProccessChannelUpdate( | ||
self.get_remote_peer_id(), | ||
NetworkActorCommand::BroadcastMessages(vec![BroadcastMessage::ChannelUpdate( | ||
channel_update, | ||
), | ||
)]), | ||
)) | ||
.expect(ASSUME_NETWORK_ACTOR_ALIVE); | ||
} | ||
|
@@ -3360,7 +3373,7 @@ impl ChannelActorState { | |
) => Some(ChannelUpdate::new_unsigned( | ||
Default::default(), | ||
self.must_get_funding_transaction_outpoint(), | ||
std::time::UNIX_EPOCH.elapsed().expect("Duration since unix epoch").as_secs(), | ||
now_timestamp_as_millis_u64(), | ||
message_flags, | ||
0, | ||
expiry_delta, | ||
|
@@ -5241,30 +5254,15 @@ impl ChannelActorState { | |
self.on_channel_ready(network).await; | ||
|
||
debug!( | ||
"Broadcasting channel announcement message {:?}", | ||
&channel_announcement, | ||
"Broadcasting channel announcement {:?} and channel update {:?}", | ||
&channel_announcement, &channel_update | ||
); | ||
network | ||
.send_message(NetworkActorMessage::new_command( | ||
NetworkActorCommand::ProcessChannelAnnouncement( | ||
self.get_remote_peer_id(), | ||
self.get_funding_transaction_block_number(), | ||
self.get_funding_transaction_index(), | ||
channel_announcement, | ||
), | ||
)) | ||
.expect(ASSUME_NETWORK_ACTOR_ALIVE); | ||
debug!( | ||
"Broadcasting channel update message to peers: {:?}", | ||
&channel_update | ||
); | ||
|
||
network | ||
.send_message(NetworkActorMessage::new_command( | ||
NetworkActorCommand::ProccessChannelUpdate( | ||
self.get_remote_peer_id(), | ||
channel_update, | ||
), | ||
NetworkActorCommand::BroadcastMessages(vec![ | ||
BroadcastMessage::ChannelAnnouncement(channel_announcement), | ||
BroadcastMessage::ChannelUpdate(channel_update), | ||
]), | ||
)) | ||
.expect(ASSUME_NETWORK_ACTOR_ALIVE); | ||
} | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These
Eq
andHash
added in this file is not necessary.Suggest a clean up: