public void BroadcastFundingTransaction(LocalChannel channel) { var fundingTransaction = CreateFundingTransaction(channel.FundingSatoshis, channel.FeeRatePerKw, channel.LocalCommitmentTxParameters.FundingKey, channel.RemoteCommitmentTxParameters.FundingKey); _channelLoggingService.LogInfo(channel, "Funding Transaction", fundingTransaction.ToString()); _blockchainClientService.SendTransaction(fundingTransaction.Transaction); }
private void SignRemoteCommitmentTx(LocalChannel channel) { var builder = new CommitmentTransactionBuilder(channel, false, _networkParameters); Transaction rawTransaction = builder.Build(); Key fundingPrivateKey = new Key(channel.LocalCommitmentTxParameters.FundingKey.PrivateKeyData); channel.RemoteCommitmentTxParameters.LocalSignature = builder.SignCommitmentTransaction(fundingPrivateKey, rawTransaction); _channelLoggingService.LogInfo(channel, "Remote Commitment Transaction", rawTransaction.ToString()); }
public void Close(LocalChannel channel, bool unilateralCloseOnUnavailability) { _channelLoggingService.LogInfo(channel, $"Closing {channel.ChannelId}. State: {channel.State}. Force: {unilateralCloseOnUnavailability}"); var peer = _peerService.Peers.SingleOrDefault(p => p.NodeAddress.Address == channel.PersistentPeer.Address); if (peer == null && unilateralCloseOnUnavailability) { _logger.LogWarning($"Peer ({channel.PersistentPeer.Address}) is not available. Doing an unilateral close."); UnilateralClose(channel); return; } if (peer == null) { throw new PeerException("Peer is unavailable"); } MutualClose(channel, peer); }
private void OnPeerDisconnected(IPeer peer) { var channel = _channelService.Channels.Where(c => c.PersistentPeer.Address == peer.NodeAddress.Address).ToList(); channel.ForEach(c => { c.Active = false; _channelLoggingService.LogInfo(c, $"Peer {peer.NodeAddress} disconnected. Channel inactive."); }); }
public void HandleRemoteFundingLocked(IPeer peer, FundingLockedMessage message, LocalChannel channel) { if (channel.State == LocalChannelState.NormalOperation && channel.RemoteCommitmentTxParameters.TransactionNumber == 0) { _channelLoggingService.LogInfo(channel, $"Remote sent us a {nameof(FundingLockedMessage)} but we are already in Normal Operation state. " + "We will answer with a funding locked message."); SendFundingLocked(peer, channel); return; } if (channel.State != LocalChannelState.FundingSigned && channel.State != LocalChannelState.FundingLocked) { _channelLoggingService.LogWarning(channel, $"Remote sent us a {nameof(FundingLockedMessage)}, but the current state is {channel.State}"); return; } channel.State = channel.State == LocalChannelState.FundingLocked ? LocalChannelState.NormalOperation : LocalChannelState.FundingLocked; channel.RemoteCommitmentTxParameters.NextPerCommitmentPoint = message.NextPerCommitmentPoint; }