private void OnMutualCloseTransaction(LocalChannel channel, Transaction spendingTx) { var oldState = channel.State; channel.State = LocalChannelState.Closed; _channelLoggingService.LogStateUpdate(channel, oldState, "Mutual Close: Closing Transaction confirmed. "); _channelService.RemoveChannel(channel); }
public FundingCreatedMessage Handle(AcceptChannelMessage acceptMessage, PendingChannel pendingChannel) { var oldState = LocalChannelState.AcceptChannel; var openMessage = pendingChannel.OpenMessage; _channelLoggingService.LogPendingChannelInfo(openMessage.TemporaryChannelId.ToHex(), oldState, "Remote accepted channel open"); FundingTransaction fundingTx = _fundingService.CreateFundingTransaction(openMessage.FundingSatoshis, openMessage.FeeratePerKw, openMessage.FundingPubKey, acceptMessage.FundingPubKey); var channel = CreateChannel(pendingChannel.ChannelIndex, fundingTx, openMessage, acceptMessage); channel.IsFunder = true; _commitmentService.CreateInitialCommitmentTransactions(openMessage, acceptMessage, channel, pendingChannel.RevocationKey); channel.State = LocalChannelState.FundingCreated; var signatureOfRemoteCommitmentTx = channel.RemoteCommitmentTxParameters.LocalSignature; FundingCreatedMessage fundingCreatedMessage = new FundingCreatedMessage { TemporaryChannelId = openMessage.TemporaryChannelId, FundingTransactionId = fundingTx.Transaction.GetHash().ToBytes(), FundingOutputIndex = fundingTx.FundingOutputIndex, Signature = signatureOfRemoteCommitmentTx.ToRawSignature() }; pendingChannel.Channel = channel; _channelLoggingService.LogStateUpdate(channel, oldState, additionalData: fundingTx.Transaction.ToString()); return(fundingCreatedMessage); }
private void MutualClose(LocalChannel channel, IPeer peer) { var oldState = channel.State; if (channel.State != LocalChannelState.ClosingSigned) { channel.State = LocalChannelState.Shutdown; } channel.CloseReason = CloseReason.LocalMutualClose; SendShutdownMessage(channel, peer); _channelService.UpdateChannel(channel); _channelLoggingService.LogStateUpdate(channel, oldState, "Mutual Close"); _channelClosingProvider.OnNext(channel); }
public void Handle(IPeer peer, FundingSignedMessage message, PendingChannel pendingChannel) { var channel = pendingChannel.Channel; var oldState = channel.State; var signature = SignatureConverter.RawToTransactionSignature(message.Signature); if (!_commitmentService.IsValidRemoteCommitmentSignature(channel, signature)) { _channelLoggingService.LogError(channel, LocalChannelError.InvalidCommitmentSignature, $"Remote {peer.NodeAddress} sent us an invalid commitment signature"); string error = "Invalid commitment transaction signature."; channel.State = LocalChannelState.FundingFailed; peer.Messaging.Send(new ErrorMessage(message.ChannelId, error)); throw new ChannelException(error, channel); } channel.LocalCommitmentTxParameters.RemoteSignature = signature; channel.State = LocalChannelState.FundingSigned; _channelService.AddChannel(peer, channel); _fundingService.BroadcastFundingTransaction(channel); _blockchainMonitorService.WatchForTransactionId(channel.FundingTransactionId, (ushort)channel.MinimumDepth); _channelService.RemovePendingChannel(pendingChannel); _channelLoggingService.LogStateUpdate(channel, oldState); }