-
Notifications
You must be signed in to change notification settings - Fork 94
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
Lightning Network Channels #1133
Conversation
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.
The first review iteration. I may have more remarks/questions in the future.
@artemii235 this is not ready for the next review yet. I need to use the correct size and fee here https://github.com/KomodoPlatform/atomicDEX-API/blob/7ff4b28217a2e12a1e9369ae883b7f2e145e9071/mm2src/coins/lightning.rs#L515 |
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.
Few minor questions and refactoring suggestions.
network: conf.network, | ||
best_block: BestBlock::new(BlockHash::from_hash(best_block_hash), best_block.height as u32), | ||
let mut restarting_node = true; | ||
let rpc_client = match &filter.clone().unwrap().platform_coin.as_ref().rpc_client { |
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.
Is unwrap safe here? Please add a comment if yes or return the error otherwise.
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.
What if rpc_client
is initialized before platform_coin
is moved?
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.
Is unwrap safe here? Please add a comment if yes or return the error otherwise.
filter which implements the Filter trait https://github.com/KomodoPlatform/atomicDEX-API/blob/7ff4b28217a2e12a1e9369ae883b7f2e145e9071/mm2src/coins/lightning/ln_rpc.rs#L138
is only needed for electrum clients that's why I chose to make it Some here https://github.com/KomodoPlatform/atomicDEX-API/blob/7ff4b28217a2e12a1e9369ae883b7f2e145e9071/mm2src/coins/lightning/ln_utils.rs#L247 for now until Native client is implemented then this code will be changed depending on which client is used.
What if rpc_client is initialized before platform_coin is moved?
I chose to use filter in places where the code will be used for electrum clients only in the future as a reminder. Maybe I should add a comment in the code as a reminder also.
activation_params: Self::ActivationParams, | ||
protocol_conf: Self::ProtocolInfo, | ||
) -> Result<(Self, Self::ActivationResult), MmError<Self::ActivationError>> { | ||
let network = network_from_string(protocol_conf.network)?; |
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.
This can be moved to the request deserialization stage by adding BitcoinNetwork
enum that implements Into<bitcoin::network::constants::Network>
.
protocol_conf: Self::ProtocolInfo, | ||
) -> Result<(Self, Self::ActivationResult), MmError<Self::ActivationError>> { | ||
let network = network_from_string(protocol_conf.network)?; | ||
let params = LightningActivationParams::from_activation_req(platform_coin.clone(), activation_params)?; |
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.
from_activation_req
performs additional validation of the platform config and activation params. I think it will be useful to have validate_platform_configuration
and validate_activation_params
methods in L2ActivationOps
instead.
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.
The set of comments from me 😅
mm2src/coins/lightning/ln_utils.rs
Outdated
if item.height > 0 && item.height <= current_height as i64 { | ||
let header = match client | ||
.blockchain_block_header( | ||
item.height.try_into().expect("Convertion to u64 should not fail"), |
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.
I'm afraid that electrum can return a negative height in some implementation.
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.
As I understand the negative height gets returned if the transaction is unconfirmed which is what's needed here. I also used blockchain.scripthash.get_history
because this is the only electrum method that returns the height. Please correct me If I am wrong.
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.
We never know what kind of trash some external service may return :D
@artemii235 @sergeyboyko0791 this is ready for the next review iteration |
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.
I have the last question for now 🙂
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.
One question in regards to the latest change.
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.
Great! @sergeyboyko0791 Could you please check that all your remarks are resolved too?
@artemii235 @sergeyboyko0791 this is not ready for merge yet if the review fixes are accepted as I found a mistake here after I reviewed my code one more time https://github.com/KomodoPlatform/atomicDEX-API/blob/6ab6a976cf1841a2b88ea66a6025993458dc65e2/mm2src/coins/lightning/ln_utils.rs#L655 |
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.
👍
process_tx_for_unconfirmation(txid, filter.clone(), channel_manager.clone()).await; | ||
} | ||
|
||
for txid in chain_monitor_relevant_txids { |
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.
Not blocking comment: I guess you can use channel_manager_relevant_txids.chain(chain_monitor_relevant_txids)
or something like this. Just for the next iteration :)
} | ||
|
||
#[cfg(not(target_arch = "wasm32"))] | ||
async fn process_txs_confirmations( |
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.
This function looks complicated. Could you please refactor it at the next iteration?
} | ||
|
||
#[cfg(not(target_arch = "wasm32"))] | ||
async fn get_best_header(best_header_listener: &ElectrumClient) -> EnableLightningResult<ElectrumBlockHeader> { |
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.
Can this be a part of the ElectrumClient
or a trait that is implemented by the client?
Err(e) => log::error!("{}", e.to_string()), | ||
} | ||
|
||
Timer::sleep(TRY_RECONNECTING_TO_NODE_INTERVAL as f64).await; |
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.
If MmArc
is stopping, the context may live until this sleep ends. In the worst case, it's 60 seconds.
Please take MmWeak
and drop MmArc
before the sleep starts.
mm2src/coins/lightning/ln_utils.rs
Outdated
if item.height > 0 && item.height <= current_height as i64 { | ||
let header = match client | ||
.blockchain_block_header( | ||
item.height.try_into().expect("Convertion to u64 should not fail"), |
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.
We never know what kind of trash some external service may return :D
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.
This is a ton of work 🤪
I leave some non-blocking comments, could you please take them into account?
Only one thing I thing should be fixed: please avoid keeping MmArc
during a Timer
future is used :) #1162
Part of #1045
Features: