lnwallet: payment and revocation hashes are now 32 bytes
This unifies some inconstancies across the code-base with hashes being 32 vs 20 bytes. All hashes, whether payment or revocation are now uniformly 32 bytes everywhere. As a result, only OP_SHA256 will be used within commitment and HTLC scripts. The rationale for using sha256 instead of hash160 for the HTLC payment pre-image is that alternative chains are more likely to have sha256 implemented, rather than ripemd160. A forthcoming commit will update the current commitment, and HTLC scripts.
This commit is contained in:
parent
1a48db3039
commit
05fb9b5a6d
@ -58,7 +58,7 @@ const (
|
|||||||
// PaymentHash presents the hash160 of a random value. This hash is used to
|
// PaymentHash presents the hash160 of a random value. This hash is used to
|
||||||
// uniquely track incoming/outgoing payments within this channel, as well as
|
// uniquely track incoming/outgoing payments within this channel, as well as
|
||||||
// payments requested by the wallet/daemon.
|
// payments requested by the wallet/daemon.
|
||||||
type PaymentHash [20]byte
|
type PaymentHash [32]byte
|
||||||
|
|
||||||
// LightningChannel...
|
// LightningChannel...
|
||||||
// TODO(roasbeef): future peer struct should embed this struct
|
// TODO(roasbeef): future peer struct should embed this struct
|
||||||
@ -130,12 +130,12 @@ func NewLightningChannel(wallet *LightningWallet, events chainntnfs.ChainNotifie
|
|||||||
|
|
||||||
// PaymentDescriptor...
|
// PaymentDescriptor...
|
||||||
type PaymentDescriptor struct {
|
type PaymentDescriptor struct {
|
||||||
RHash [20]byte
|
RHash [32]byte
|
||||||
Timeout uint32
|
Timeout uint32
|
||||||
Value btcutil.Amount
|
Value btcutil.Amount
|
||||||
|
|
||||||
OurRevocation [20]byte // TODO(roasbeef): don't need these?
|
OurRevocation [32]byte // TODO(roasbeef): don't need these?
|
||||||
TheirRevocation [20]byte
|
TheirRevocation [32]byte
|
||||||
|
|
||||||
PayToUs bool
|
PayToUs bool
|
||||||
}
|
}
|
||||||
@ -151,7 +151,7 @@ type ChannelUpdate struct {
|
|||||||
ourPendingCommitTx *wire.MsgTx
|
ourPendingCommitTx *wire.MsgTx
|
||||||
theirPendingCommitTx *wire.MsgTx
|
theirPendingCommitTx *wire.MsgTx
|
||||||
|
|
||||||
pendingRevocation [20]byte
|
pendingRevocation [32]byte
|
||||||
sigTheirNewCommit []byte
|
sigTheirNewCommit []byte
|
||||||
|
|
||||||
// TODO(roasbeef): some enum to track current state in lifetime?
|
// TODO(roasbeef): some enum to track current state in lifetime?
|
||||||
@ -171,7 +171,7 @@ func (c *ChannelUpdate) RevocationHash() ([]byte, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return btcutil.Hash160(nextPreimage[:]), nil
|
return nextPreimage[:], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SignCounterPartyCommitment...
|
// SignCounterPartyCommitment...
|
||||||
@ -458,7 +458,7 @@ func (lc *LightningChannel) addHTLC(ourCommitTx, theirCommitTx *wire.MsgTx,
|
|||||||
// SettleHTLC...
|
// SettleHTLC...
|
||||||
// R-VALUE, NEW REVOKE HASH
|
// R-VALUE, NEW REVOKE HASH
|
||||||
// accept, sig
|
// accept, sig
|
||||||
func (lc *LightningChannel) SettleHTLC(rValue [20]byte, newRevocation [20]byte) (*ChannelUpdate, error) {
|
func (lc *LightningChannel) SettleHTLC(rValue [32]byte, newRevocation [32]byte) (*ChannelUpdate, error) {
|
||||||
// Grab the updateTotem, this acts as a barrier upholding the invariant
|
// Grab the updateTotem, this acts as a barrier upholding the invariant
|
||||||
// that only one channel update transaction should exist at any moment.
|
// that only one channel update transaction should exist at any moment.
|
||||||
// This aides in ensuring the channel updates are atomic, and consistent.
|
// This aides in ensuring the channel updates are atomic, and consistent.
|
||||||
|
@ -41,7 +41,7 @@ type ChannelContribution struct {
|
|||||||
|
|
||||||
// Hash to be used as the revocation for the initial version of this
|
// Hash to be used as the revocation for the initial version of this
|
||||||
// party's commitment transaction.
|
// party's commitment transaction.
|
||||||
RevocationHash [20]byte
|
RevocationHash [32]byte
|
||||||
|
|
||||||
// The delay (in blocks) to be used for the pay-to-self output in this
|
// The delay (in blocks) to be used for the pay-to-self output in this
|
||||||
// party's version of the commitment transaction.
|
// party's version of the commitment transaction.
|
||||||
|
@ -97,7 +97,7 @@ type bobNode struct {
|
|||||||
// For simplicity, used for both the commit tx and the multi-sig output.
|
// For simplicity, used for both the commit tx and the multi-sig output.
|
||||||
channelKey *btcec.PublicKey
|
channelKey *btcec.PublicKey
|
||||||
deliveryAddress btcutil.Address
|
deliveryAddress btcutil.Address
|
||||||
revocation [20]byte
|
revocation [32]byte
|
||||||
delay uint32
|
delay uint32
|
||||||
id [wire.HashSize]byte
|
id [wire.HashSize]byte
|
||||||
|
|
||||||
@ -228,7 +228,7 @@ func newBobNode(miner *rpctest.Harness, amt btcutil.Amount) (*bobNode, error) {
|
|||||||
|
|
||||||
// Bob's initial revocation hash is just his private key with the first
|
// Bob's initial revocation hash is just his private key with the first
|
||||||
// byte changed...
|
// byte changed...
|
||||||
var revocation [20]byte
|
var revocation [32]byte
|
||||||
copy(revocation[:], bobsPrivKey)
|
copy(revocation[:], bobsPrivKey)
|
||||||
revocation[0] = 0xff
|
revocation[0] = 0xff
|
||||||
|
|
||||||
@ -488,7 +488,7 @@ func testDualFundingReservationWorkflow(miner *rpctest.Harness, lnwallet *Lightn
|
|||||||
// Obtain bob's signature for the closure transaction.
|
// Obtain bob's signature for the closure transaction.
|
||||||
redeemScript := lnc.channelState.FundingRedeemScript
|
redeemScript := lnc.channelState.FundingRedeemScript
|
||||||
fundingOut := lnc.ChannelPoint()
|
fundingOut := lnc.ChannelPoint()
|
||||||
fundingTxIn := wire.NewTxIn(&fundingOut, nil, nil)
|
fundingTxIn := wire.NewTxIn(fundingOut, nil, nil)
|
||||||
bobCloseTx := createCooperativeCloseTx(fundingTxIn,
|
bobCloseTx := createCooperativeCloseTx(fundingTxIn,
|
||||||
lnc.channelState.TheirBalance, lnc.channelState.OurBalance,
|
lnc.channelState.TheirBalance, lnc.channelState.OurBalance,
|
||||||
lnc.channelState.TheirDeliveryScript, lnc.channelState.OurDeliveryScript,
|
lnc.channelState.TheirDeliveryScript, lnc.channelState.OurDeliveryScript,
|
||||||
|
Loading…
Reference in New Issue
Block a user