funding: update fundingManager to register for conf's using pkScripts

This commit is contained in:
Olaoluwa Osuntokun 2018-05-30 22:16:34 -07:00
parent 3268019326
commit 8aef43360f
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21
2 changed files with 36 additions and 6 deletions

@ -1752,6 +1752,20 @@ func (f *fundingManager) waitForFundingWithTimeout(completeChan *channeldb.OpenC
} }
} }
// makeFundingScript re-creates the funding script for the funding transaction
// of the target channel.
func makeFundingScript(channel *channeldb.OpenChannel) ([]byte, error) {
localKey := channel.LocalChanCfg.MultiSigKey.PubKey.SerializeCompressed()
remoteKey := channel.RemoteChanCfg.MultiSigKey.PubKey.SerializeCompressed()
multiSigScript, err := lnwallet.GenMultiSigScript(localKey, remoteKey)
if err != nil {
return nil, err
}
return lnwallet.WitnessScriptHash(multiSigScript)
}
// waitForFundingConfirmation handles the final stages of the channel funding // waitForFundingConfirmation handles the final stages of the channel funding
// process once the funding transaction has been broadcast. The primary // process once the funding transaction has been broadcast. The primary
// function of waitForFundingConfirmation is to wait for blockchain // function of waitForFundingConfirmation is to wait for blockchain
@ -1767,9 +1781,16 @@ func (f *fundingManager) waitForFundingConfirmation(completeChan *channeldb.Open
// Register with the ChainNotifier for a notification once the funding // Register with the ChainNotifier for a notification once the funding
// transaction reaches `numConfs` confirmations. // transaction reaches `numConfs` confirmations.
txid := completeChan.FundingOutpoint.Hash txid := completeChan.FundingOutpoint.Hash
fundingScript, err := makeFundingScript(completeChan)
if err != nil {
fndgLog.Errorf("unable to create funding script for "+
"ChannelPoint(%v): %v", completeChan.FundingOutpoint, err)
return
}
numConfs := uint32(completeChan.NumConfsRequired) numConfs := uint32(completeChan.NumConfsRequired)
confNtfn, err := f.cfg.Notifier.RegisterConfirmationsNtfn(&txid, confNtfn, err := f.cfg.Notifier.RegisterConfirmationsNtfn(
numConfs, completeChan.FundingBroadcastHeight) &txid, fundingScript, numConfs, completeChan.FundingBroadcastHeight,
)
if err != nil { if err != nil {
fndgLog.Errorf("Unable to register for confirmation of "+ fndgLog.Errorf("Unable to register for confirmation of "+
"ChannelPoint(%v)", completeChan.FundingOutpoint) "ChannelPoint(%v)", completeChan.FundingOutpoint)
@ -2073,8 +2094,16 @@ func (f *fundingManager) annAfterSixConfs(completeChan *channeldb.OpenChannel,
shortChanID.ToUint64(), completeChan.FundingOutpoint, shortChanID.ToUint64(), completeChan.FundingOutpoint,
numConfs) numConfs)
confNtfn, err := f.cfg.Notifier.RegisterConfirmationsNtfn(&txid, fundingScript, err := makeFundingScript(completeChan)
numConfs, completeChan.FundingBroadcastHeight) if err != nil {
return fmt.Errorf("unable to create funding script for "+
"ChannelPoint(%v): %v",
completeChan.FundingOutpoint, err)
}
confNtfn, err := f.cfg.Notifier.RegisterConfirmationsNtfn(
&txid, fundingScript, numConfs, completeChan.FundingBroadcastHeight,
)
if err != nil { if err != nil {
return fmt.Errorf("Unable to register for "+ return fmt.Errorf("Unable to register for "+
"confirmation of ChannelPoint(%v): %v", "confirmation of ChannelPoint(%v): %v",

@ -98,8 +98,9 @@ type mockNotifier struct {
epochChan chan *chainntnfs.BlockEpoch epochChan chan *chainntnfs.BlockEpoch
} }
func (m *mockNotifier) RegisterConfirmationsNtfn(txid *chainhash.Hash, numConfs, func (m *mockNotifier) RegisterConfirmationsNtfn(txid *chainhash.Hash,
heightHint uint32) (*chainntnfs.ConfirmationEvent, error) { _ []byte, numConfs, heightHint uint32) (*chainntnfs.ConfirmationEvent, error) {
if numConfs == 6 { if numConfs == 6 {
return &chainntnfs.ConfirmationEvent{ return &chainntnfs.ConfirmationEvent{
Confirmed: m.sixConfChannel, Confirmed: m.sixConfChannel,