lnwallet: separate channel state into new struct
* Will be integrated into ChannelReservation also * This is the struct that will be persisted to disk
This commit is contained in:
parent
39b100b865
commit
6af4aaf71b
@ -145,6 +145,41 @@ func createCommitTx(fundingOutput *wire.TxIn, ourKey, theirKey *btcec.PublicKey,
|
|||||||
|
|
||||||
type nodeId [32]byte
|
type nodeId [32]byte
|
||||||
|
|
||||||
|
// OpenChannelState...
|
||||||
|
// TODO(roasbeef): script gen methods on this?
|
||||||
|
type OpenChannelState struct {
|
||||||
|
// Hash? or Their current pubKey?
|
||||||
|
theirLNID [32]byte
|
||||||
|
|
||||||
|
fundingType FundingType
|
||||||
|
|
||||||
|
fundingAmount btcutil.Amount
|
||||||
|
|
||||||
|
ourCommitKey *btcec.PrivateKey
|
||||||
|
theirCommitKey *btcec.PublicKey
|
||||||
|
|
||||||
|
capacity btcutil.Amount
|
||||||
|
ourBalance btcutil.Amount
|
||||||
|
theirBalance btcutil.Amount
|
||||||
|
|
||||||
|
theirCommitTx *wire.MsgTx
|
||||||
|
ourCommitTx *wire.MsgTx
|
||||||
|
|
||||||
|
finalFundingTx *wire.MsgTx
|
||||||
|
|
||||||
|
ourMultiSigKey *btcec.PrivateKey
|
||||||
|
fundingRedeemScript []byte
|
||||||
|
|
||||||
|
ourShaChain *revocation.HyperShaChain
|
||||||
|
theirShaChain *revocation.HyperShaChain
|
||||||
|
|
||||||
|
// In blocks
|
||||||
|
htlcTimeout uint32
|
||||||
|
csvDelay uint32
|
||||||
|
}
|
||||||
|
|
||||||
|
// LightningChannel...
|
||||||
|
// TODO(roasbeef): future peer struct should embed this struct
|
||||||
type LightningChannel struct {
|
type LightningChannel struct {
|
||||||
wallet *LightningWallet
|
wallet *LightningWallet
|
||||||
channelEvents *chainntnfs.ChainNotifier
|
channelEvents *chainntnfs.ChainNotifier
|
||||||
@ -152,29 +187,12 @@ type LightningChannel struct {
|
|||||||
// TODO(roasbeef): Stores all previous R values + timeouts for each
|
// TODO(roasbeef): Stores all previous R values + timeouts for each
|
||||||
// commitment update, plus some other meta-data...Or just use OP_RETURN
|
// commitment update, plus some other meta-data...Or just use OP_RETURN
|
||||||
// to help out?
|
// to help out?
|
||||||
|
// currently going for: nSequence/nLockTime overloading
|
||||||
channelNamespace walletdb.Namespace
|
channelNamespace walletdb.Namespace
|
||||||
|
|
||||||
Id [32]byte
|
// stateMtx protects concurrent access to the state struct.
|
||||||
|
stateMtx sync.RWMutex
|
||||||
capacity btcutil.Amount
|
channelState OpenChannelState
|
||||||
ourTotalFunds btcutil.Amount
|
|
||||||
theirTotalFunds btcutil.Amount
|
|
||||||
|
|
||||||
// TODO(roasbeef): another shachain for R values for HTLC's?
|
|
||||||
// solve above?
|
|
||||||
ourShaChain *revocation.HyperShaChain
|
|
||||||
theirShaChain *revocation.HyperShaChain
|
|
||||||
|
|
||||||
ourFundingKey *btcec.PrivateKey
|
|
||||||
theirFundingKey *btcec.PublicKey
|
|
||||||
|
|
||||||
ourCommitKey *btcec.PublicKey
|
|
||||||
theirCommitKey *btcec.PublicKey
|
|
||||||
|
|
||||||
fundingTx *wire.MsgTx
|
|
||||||
commitmentTx *wire.MsgTx
|
|
||||||
|
|
||||||
sync.RWMutex
|
|
||||||
|
|
||||||
// TODO(roasbeef): create and embed 'Service' interface w/ below?
|
// TODO(roasbeef): create and embed 'Service' interface w/ below?
|
||||||
started int32
|
started int32
|
||||||
@ -185,31 +203,14 @@ type LightningChannel struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// newLightningChannel...
|
// newLightningChannel...
|
||||||
// TODO(roasbeef): bring back and embedd CompleteReservation struct? kinda large
|
|
||||||
// atm.....
|
|
||||||
func newLightningChannel(wallet *LightningWallet, events *chainntnfs.ChainNotifier,
|
func newLightningChannel(wallet *LightningWallet, events *chainntnfs.ChainNotifier,
|
||||||
dbNamespace walletdb.Namespace, theirNodeID nodeId, ourFunds,
|
dbNamespace walletdb.Namespace, state OpenChannelState) (*LightningChannel, error) {
|
||||||
theirFunds btcutil.Amount, ourChain, theirChain *revocation.HyperShaChain,
|
|
||||||
ourFundingKey *btcec.PrivateKey, theirFundingKey *btcec.PublicKey,
|
|
||||||
commitKey, theirCommitKey *btcec.PublicKey, fundingTx,
|
|
||||||
commitTx *wire.MsgTx) (*LightningChannel, error) {
|
|
||||||
|
|
||||||
return &LightningChannel{
|
return &LightningChannel{
|
||||||
wallet: wallet,
|
wallet: wallet,
|
||||||
channelEvents: events,
|
channelEvents: events,
|
||||||
channelNamespace: dbNamespace,
|
channelNamespace: dbNamespace,
|
||||||
Id: theirNodeID,
|
channelState: state,
|
||||||
capacity: ourFunds + theirFunds,
|
|
||||||
ourTotalFunds: ourFunds,
|
|
||||||
theirTotalFunds: theirFunds,
|
|
||||||
ourShaChain: ourChain,
|
|
||||||
theirShaChain: theirChain,
|
|
||||||
ourFundingKey: ourFundingKey,
|
|
||||||
theirFundingKey: theirFundingKey,
|
|
||||||
ourCommitKey: commitKey,
|
|
||||||
theirCommitKey: theirCommitKey,
|
|
||||||
fundingTx: fundingTx,
|
|
||||||
commitmentTx: commitTx,
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user