multi: fix a variety of typos throughout the repo
This commit is contained in:
1 parent
49df1b0737
commit
40c7bac3aa
38 files changed
+311
-311
No files matched your search
@@ -72,7 +72,7 @@ func (b *BtcWallet) GetBlock(blockHash *chainhash.Hash) (*wire.MsgBlock, error)
|
||||
return block, nil
|
||||
}
|
||||
|
||||
// GetBlockHash returns the hash of the block in the best block chain at the
|
||||
// GetBlockHash returns the hash of the block in the best blockchain at the
|
||||
// given height.
|
||||
//
|
||||
// This method is a part of the lnwallet.BlockChainIO interface.
|
||||
|
||||
+35
-35
@@ -33,7 +33,7 @@ var (
|
||||
)
|
||||
|
||||
const (
|
||||
// MaxPendingPayments is the max number of pending HTLC's permitted on
|
||||
// MaxPendingPayments is the max number of pending HTLCs permitted on
|
||||
// a channel.
|
||||
// TODO(roasbeef): make not random value + enforce
|
||||
// * should be tuned to account for max tx "cost"
|
||||
@@ -66,7 +66,7 @@ const (
|
||||
channelClosing
|
||||
|
||||
// channelClosed represents a channel which has been fully closed. Note
|
||||
// that before a channel can be closed, ALL pending HTLC's must be
|
||||
// that before a channel can be closed, ALL pending HTLCs must be
|
||||
// settled/removed.
|
||||
channelClosed
|
||||
|
||||
@@ -75,7 +75,7 @@ const (
|
||||
channelDispute
|
||||
|
||||
// channelPendingPayment indicates that there a currently outstanding
|
||||
// HTLC's within the channel.
|
||||
// HTLCs within the channel.
|
||||
channelPendingPayment
|
||||
)
|
||||
|
||||
@@ -95,7 +95,7 @@ const (
|
||||
|
||||
// PaymentDescriptor represents a commitment state update which either adds,
|
||||
// settles, or removes an HTLC. PaymentDescriptors encapsulate all necessary
|
||||
// meta-data w.r.t to an HTLC, and additional data pairing a settle message to
|
||||
// metadata w.r.t to an HTLC, and additional data pairing a settle message to
|
||||
// the original added HTLC.
|
||||
// TODO(roasbeef): LogEntry interface??
|
||||
// * need to separate attrs for cancel/add/settle
|
||||
@@ -197,7 +197,7 @@ type commitment struct {
|
||||
ourBalance btcutil.Amount
|
||||
theirBalance btcutil.Amount
|
||||
|
||||
// htlcs is the set of HTLC's which remain unsettled within this
|
||||
// htlcs is the set of HTLCs which remain unsettled within this
|
||||
// commitment.
|
||||
outgoingHTLCs []*PaymentDescriptor
|
||||
incomingHTLCs []*PaymentDescriptor
|
||||
@@ -377,7 +377,7 @@ type LightningChannel struct {
|
||||
|
||||
// revocationWindow is a window of revocations sent to use by the
|
||||
// remote party, allowing us to create new commitment transactions
|
||||
// until depleted. The revocations don't contain a valid pre-image,
|
||||
// until depleted. The revocations don't contain a valid preimage,
|
||||
// only an additional key/hash allowing us to create a new commitment
|
||||
// transaction for the remote node that they are able to revoke. If
|
||||
// this slice is empty, then we cannot make any new updates to their
|
||||
@@ -430,7 +430,7 @@ type LightningChannel struct {
|
||||
// ContractBreach is a channel that is used to communicate the data
|
||||
// necessary to fully resolve the channel in the case that a contract
|
||||
// breach is detected. A contract breach occurs it is detected that the
|
||||
// counter party has broadcast a prior *revoked* state.
|
||||
// counterparty has broadcast a prior *revoked* state.
|
||||
ContractBreach chan *BreachRetribution
|
||||
|
||||
// LocalFundingKey is the public key under control by the wallet that
|
||||
@@ -540,7 +540,7 @@ func NewLightningChannel(signer Signer, bio BlockChainIO,
|
||||
}
|
||||
|
||||
// BreachRetribution contains all the data necessary to bring a channel
|
||||
// counter-party to justice claiming ALL lingering funds within the channel in
|
||||
// counterparty to justice claiming ALL lingering funds within the channel in
|
||||
// the scenario that they broadcast a revoked commitment transaction. A
|
||||
// BreachRetribution is created by the closeObserver if it detects an
|
||||
// uncooperative close of the channel which uses a revoked commitment
|
||||
@@ -555,7 +555,7 @@ type BreachRetribution struct {
|
||||
// RevokedStateNum is the revoked state number which was broadcast.
|
||||
RevokedStateNum uint64
|
||||
|
||||
// PendingHTLCs is a slice of the HTLC's which were pending at this
|
||||
// PendingHTLCs is a slice of the HTLCs which were pending at this
|
||||
// point within the channel's history transcript.
|
||||
PendingHTLCs []*channeldb.HTLC
|
||||
|
||||
@@ -680,7 +680,7 @@ func newBreachRetribution(chanState *channeldb.OpenChannel, stateNum uint64,
|
||||
// the following three scenarios: a cooperative close, a unilateral close, and
|
||||
// a uncooperative contract breaching close. In the case of the last scenario a
|
||||
// BreachRetribution struct is created and sent over the ContractBreach channel
|
||||
// notifying subscribers that the counter-party has violated the condition of
|
||||
// notifying subscribers that the counterparty has violated the condition of
|
||||
// the channel by broadcasting a revoked prior state.
|
||||
//
|
||||
// NOTE: This MUST be run as a goroutine.
|
||||
@@ -772,7 +772,7 @@ func (lc *LightningChannel) closeObserver(channelCloseNtfn *chainntnfs.SpendEven
|
||||
}
|
||||
}
|
||||
|
||||
// restoreStateLogs runs through the current locked-in HTLC's from the point of
|
||||
// restoreStateLogs runs through the current locked-in HTLCs from the point of
|
||||
// view of the channel and insert corresponding log entries (both local and
|
||||
// remote) for each HTLC read from disk. This method is required sync the
|
||||
// in-memory state of the state machine with that read from persistent storage.
|
||||
@@ -820,7 +820,7 @@ func (lc *LightningChannel) restoreStateLogs() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// htlcView represents the "active" HTLC's at a particular point within the
|
||||
// htlcView represents the "active" HTLCs at a particular point within the
|
||||
// history of the HTLC update log.
|
||||
type htlcView struct {
|
||||
ourUpdates []*PaymentDescriptor
|
||||
@@ -890,7 +890,7 @@ func (lc *LightningChannel) fetchCommitmentView(remoteChain bool,
|
||||
|
||||
nextHeight := commitChain.tip().height + 1
|
||||
|
||||
// Run through all the HTLC's that will be covered by this transaction
|
||||
// Run through all the HTLCs that will be covered by this transaction
|
||||
// in order to update their commitment addition height, and to adjust
|
||||
// the balances on the commitment transaction accordingly.
|
||||
// TODO(roasbeef): error if log empty?
|
||||
@@ -919,7 +919,7 @@ func (lc *LightningChannel) fetchCommitmentView(remoteChain bool,
|
||||
}
|
||||
|
||||
// Generate a new commitment transaction with all the latest
|
||||
// unsettled/un-timed out HTLC's.
|
||||
// unsettled/un-timed out HTLCs.
|
||||
ourCommitTx := !remoteChain
|
||||
commitTx, err := CreateCommitTx(lc.fundingTxIn, selfKey, remoteKey,
|
||||
revocationKey, delay, delayBalance, p2wkhBalance)
|
||||
@@ -978,7 +978,7 @@ func (lc *LightningChannel) fetchCommitmentView(remoteChain bool,
|
||||
// evaluateHTLCView processes all update entries in both HTLC update logs,
|
||||
// producing a final view which is the result of properly applying all adds,
|
||||
// settles, and timeouts found in both logs. The resulting view returned
|
||||
// reflects the current state of htlc's within the remote or local commitment
|
||||
// reflects the current state of HTLCs within the remote or local commitment
|
||||
// chain.
|
||||
func (lc *LightningChannel) evaluateHTLCView(view *htlcView, ourBalance,
|
||||
theirBalance *btcutil.Amount, nextHeight uint64, remoteChain bool) *htlcView {
|
||||
@@ -1025,8 +1025,8 @@ func (lc *LightningChannel) evaluateHTLCView(view *htlcView, ourBalance,
|
||||
}
|
||||
|
||||
// Next we take a second pass through all the log entries, skipping any
|
||||
// settled HTLC's, and debiting the chain state balance due to any
|
||||
// newly added HTLC's.
|
||||
// settled HTLCs, and debiting the chain state balance due to any
|
||||
// newly added HTLCs.
|
||||
for _, entry := range view.ourUpdates {
|
||||
isAdd := entry.EntryType == Add
|
||||
if _, ok := skipUs[entry.Index]; !isAdd || ok {
|
||||
@@ -1108,7 +1108,7 @@ func processRemoveEntry(htlc *PaymentDescriptor, ourBalance,
|
||||
|
||||
switch {
|
||||
// If an incoming HTLC is being settled, then this means that we've
|
||||
// received the preimage either from another sub-system, or the
|
||||
// received the preimage either from another subsystem, or the
|
||||
// upstream peer in the route. Therefore, we increase our balance by
|
||||
// the HTLC amount.
|
||||
case isIncoming && htlc.EntryType == Settle:
|
||||
@@ -1123,7 +1123,7 @@ func processRemoveEntry(htlc *PaymentDescriptor, ourBalance,
|
||||
// the value of the HTLC.
|
||||
case !isIncoming && htlc.EntryType == Settle:
|
||||
*theirBalance += htlc.Amount
|
||||
// Otherwise, one of our outgoing HTLC's has been cancelled, so the
|
||||
// Otherwise, one of our outgoing HTLCs has been cancelled, so the
|
||||
// value of the HTLC should be returned to our settled balance.
|
||||
case !isIncoming && htlc.EntryType == Cancel:
|
||||
*ourBalance += htlc.Amount
|
||||
@@ -1164,7 +1164,7 @@ func (lc *LightningChannel) SignNextCommitment() ([]byte, uint32, error) {
|
||||
|
||||
// Create a new commitment view which will calculate the evaluated
|
||||
// state of the remote node's new commitment including our latest added
|
||||
// HTLC's. The view includes the latest balances for both sides on the
|
||||
// HTLCs. The view includes the latest balances for both sides on the
|
||||
// remote node's chain, and also update the addition height of any new
|
||||
// HTLC log entries.
|
||||
newCommitView, err := lc.fetchCommitmentView(true, lc.ourLogCounter,
|
||||
@@ -1218,7 +1218,7 @@ func (lc *LightningChannel) validateCommitmentSanity(theirLogCounter,
|
||||
htlcCount++
|
||||
}
|
||||
|
||||
// Run through all the HTLC's that will be covered by this transaction
|
||||
// Run through all the HTLCs that will be covered by this transaction
|
||||
// in order to calculate theirs count.
|
||||
htlcView := lc.fetchHTLCView(theirLogCounter, ourLogCounter)
|
||||
|
||||
@@ -1305,7 +1305,7 @@ func (lc *LightningChannel) ReceiveNewCommitment(rawSig []byte,
|
||||
sigHash, err := txscript.CalcWitnessSigHash(multiSigScript, hashCache,
|
||||
txscript.SigHashAll, localCommitTx, 0, int64(lc.channelState.Capacity))
|
||||
if err != nil {
|
||||
// TODO(roasbeef): fetchview has already mutated the htlc's...
|
||||
// TODO(roasbeef): fetchview has already mutated the HTLCs...
|
||||
// * need to either roll-back, or make pure
|
||||
return err
|
||||
}
|
||||
@@ -1409,12 +1409,12 @@ func (lc *LightningChannel) RevokeCurrentCommitment() (*lnwire.CommitRevocation,
|
||||
// windows are extended, or in response to a state update that we initiate. If
|
||||
// successful, then the remote commitment chain is advanced by a single
|
||||
// commitment, and a log compaction is attempted. In addition, a slice of
|
||||
// HTLC's which can be forwarded upstream are returned.
|
||||
// HTLCs which can be forwarded upstream are returned.
|
||||
func (lc *LightningChannel) ReceiveRevocation(revMsg *lnwire.CommitRevocation) ([]*PaymentDescriptor, error) {
|
||||
lc.Lock()
|
||||
defer lc.Unlock()
|
||||
|
||||
// The revocation has a nil (zero) pre-image, then this should simply be
|
||||
// The revocation has a nil (zero) preimage, then this should simply be
|
||||
// added to the end of the revocation window for the remote node.
|
||||
if bytes.Equal(zeroHash[:], revMsg.Revocation[:]) {
|
||||
lc.revocationWindow = append(lc.revocationWindow, revMsg)
|
||||
@@ -1425,7 +1425,7 @@ func (lc *LightningChannel) ReceiveRevocation(revMsg *lnwire.CommitRevocation) (
|
||||
currentRevocationKey := lc.channelState.TheirCurrentRevocation
|
||||
pendingRevocation := chainhash.Hash(revMsg.Revocation)
|
||||
|
||||
// Ensure the new pre-image fits in properly within the elkrem receiver
|
||||
// Ensure the new preimage fits in properly within the elkrem receiver
|
||||
// tree. If this fails, then all other checks are skipped.
|
||||
// TODO(rosbeef): abstract into func
|
||||
remoteElkrem := lc.channelState.RemoteElkrem
|
||||
@@ -1434,15 +1434,15 @@ func (lc *LightningChannel) ReceiveRevocation(revMsg *lnwire.CommitRevocation) (
|
||||
}
|
||||
|
||||
// Verify that the revocation public key we can derive using this
|
||||
// pre-image and our private key is identical to the revocation key we
|
||||
// preimage and our private key is identical to the revocation key we
|
||||
// were given for their current (prior) commitment transaction.
|
||||
revocationPub := DeriveRevocationPubkey(ourCommitKey, pendingRevocation[:])
|
||||
if !revocationPub.IsEqual(currentRevocationKey) {
|
||||
return nil, fmt.Errorf("revocation key mismatch")
|
||||
}
|
||||
|
||||
// Additionally, we need to ensure we were given the proper pre-image
|
||||
// to the revocation hash used within any current HTLC's.
|
||||
// Additionally, we need to ensure we were given the proper preimage
|
||||
// to the revocation hash used within any current HTLCs.
|
||||
if !bytes.Equal(lc.channelState.TheirCurrentRevocationHash[:], zeroHash[:]) {
|
||||
revokeHash := fastsha256.Sum256(pendingRevocation[:])
|
||||
// TODO(roasbeef): rename to drop the "Their"
|
||||
@@ -1497,7 +1497,7 @@ func (lc *LightningChannel) ReceiveRevocation(revMsg *lnwire.CommitRevocation) (
|
||||
continue
|
||||
}
|
||||
|
||||
// TODO(roasbeef): re-visit after adding persistence to HTLC's
|
||||
// TODO(roasbeef): re-visit after adding persistence to HTLCs
|
||||
// * either record add height, or set to N - 1
|
||||
uncomitted := (htlc.addCommitHeightRemote == 0 ||
|
||||
htlc.addCommitHeightLocal == 0)
|
||||
@@ -1524,9 +1524,9 @@ func (lc *LightningChannel) ReceiveRevocation(revMsg *lnwire.CommitRevocation) (
|
||||
return htlcsToForward, nil
|
||||
}
|
||||
|
||||
// compactLogs performs garbage collection within the log removing HTLC's which
|
||||
// compactLogs performs garbage collection within the log removing HTLCs which
|
||||
// have been removed from the point-of-view of the tail of both chains. The
|
||||
// entries which timeout/settle HTLC's are also removed.
|
||||
// entries which timeout/settle HTLCs are also removed.
|
||||
func (lc *LightningChannel) compactLogs(ourLog, theirLog *list.List,
|
||||
localChainTail, remoteChainTail uint64) {
|
||||
|
||||
@@ -1654,7 +1654,7 @@ func (lc *LightningChannel) ReceiveHTLC(htlc *lnwire.HTLCAddRequest) (uint32, er
|
||||
|
||||
// SettleHTLC attempts to settle an existing outstanding received HTLC. The
|
||||
// remote log index of the HTLC settled is returned in order to facilitate
|
||||
// creating the corresponding wire message. In the case the supplied pre-image
|
||||
// creating the corresponding wire message. In the case the supplied preimage
|
||||
// is invalid, an error is returned.
|
||||
func (lc *LightningChannel) SettleHTLC(preimage [32]byte) (uint32, error) {
|
||||
lc.Lock()
|
||||
@@ -1794,7 +1794,7 @@ func (lc *LightningChannel) ReceiveCancelHTLC(logIndex uint32) error {
|
||||
|
||||
// ChannelPoint returns the outpoint of the original funding transaction which
|
||||
// created this active channel. This outpoint is used throughout various
|
||||
// sub-systems to uniquely identify an open channel.
|
||||
// subsystems to uniquely identify an open channel.
|
||||
func (lc *LightningChannel) ChannelPoint() *wire.OutPoint {
|
||||
return lc.channelState.ChanID
|
||||
}
|
||||
@@ -2119,7 +2119,7 @@ func (lc *LightningChannel) CompleteCooperativeClose(remoteSig []byte) (*wire.Ms
|
||||
}
|
||||
|
||||
// DeleteState deletes all state concerning the channel from the underlying
|
||||
// database, only leaving a small summary describing meta-data of the
|
||||
// database, only leaving a small summary describing metadata of the
|
||||
// channel's lifetime.
|
||||
func (lc *LightningChannel) DeleteState() error {
|
||||
return lc.channelState.CloseChannel()
|
||||
@@ -2138,7 +2138,7 @@ func (lc *LightningChannel) StateSnapshot() *channeldb.ChannelSnapshot {
|
||||
// funding output. The commitment transaction contains two outputs: one paying
|
||||
// to the "owner" of the commitment transaction which can be spent after a
|
||||
// relative block delay or revocation event, and the other paying the the
|
||||
// counter-party within the channel, which can be spent immediately.
|
||||
// counterparty within the channel, which can be spent immediately.
|
||||
func CreateCommitTx(fundingOutput *wire.TxIn, selfKey, theirKey *btcec.PublicKey,
|
||||
revokeKey *btcec.PublicKey, csvTimeout uint32, amountToSelf,
|
||||
amountToThem btcutil.Amount) (*wire.MsgTx, error) {
|
||||
|
||||
+10
-10
@@ -398,7 +398,7 @@ func TestSimpleAddSettleWorkflow(t *testing.T) {
|
||||
t.Fatalf("alice unable to process bob's new commitment: %v", err)
|
||||
}
|
||||
// Alice then processes this revocation, sending her own recovation for
|
||||
// her prior commitment transaction. Alice shouldn't have any HTLC's to
|
||||
// her prior commitment transaction. Alice shouldn't have any HTLCs to
|
||||
// forward since she's sending an outgoing HTLC.
|
||||
if htlcs, err := aliceChannel.ReceiveRevocation(bobRevocation); err != nil {
|
||||
t.Fatalf("alice unable to rocess bob's revocation: %v", err)
|
||||
@@ -497,7 +497,7 @@ func TestSimpleAddSettleWorkflow(t *testing.T) {
|
||||
if htlcs, err := bobChannel.ReceiveRevocation(aliceRevocation2); err != nil {
|
||||
t.Fatalf("bob unable to process alice's revocation: %v", err)
|
||||
} else if len(htlcs) != 0 {
|
||||
t.Fatalf("bob shouldn't forward any HTLC's after outgoing settle, "+
|
||||
t.Fatalf("bob shouldn't forward any HTLCs after outgoing settle, "+
|
||||
"instead can forward: %v", spew.Sdump(htlcs))
|
||||
}
|
||||
if htlcs, err := aliceChannel.ReceiveRevocation(bobRevocation2); err != nil {
|
||||
@@ -566,7 +566,7 @@ func TestSimpleAddSettleWorkflow(t *testing.T) {
|
||||
}
|
||||
|
||||
// The logs of both sides should now be cleared since the entry adding
|
||||
// the HTLC should have been removed once both sides recieve the
|
||||
// the HTLC should have been removed once both sides receive the
|
||||
// revocation.
|
||||
if aliceChannel.ourUpdateLog.Len() != 0 {
|
||||
t.Fatalf("alice's local not updated, should be empty, has %v entries "+
|
||||
@@ -977,7 +977,7 @@ func TestStateUpdatePersistence(t *testing.T) {
|
||||
|
||||
const numHtlcs = 4
|
||||
|
||||
// Alice adds 3 HTLC's to the update log, while Bob adds a single HTLC.
|
||||
// Alice adds 3 HTLCs to the update log, while Bob adds a single HTLC.
|
||||
var alicePreimage [32]byte
|
||||
copy(alicePreimage[:], bytes.Repeat([]byte{0xaa}, 32))
|
||||
var bobPreimage [32]byte
|
||||
@@ -1002,9 +1002,9 @@ func TestStateUpdatePersistence(t *testing.T) {
|
||||
bobChannel.AddHTLC(bobh)
|
||||
aliceChannel.ReceiveHTLC(bobh)
|
||||
|
||||
// Next, Alice initiates a state transition to lock in the above HTLC's.
|
||||
// Next, Alice initiates a state transition to lock in the above HTLCs.
|
||||
if err := forceStateTransition(aliceChannel, bobChannel); err != nil {
|
||||
t.Fatalf("unable to lock in HTLC's: %v", err)
|
||||
t.Fatalf("unable to lock in HTLCs: %v", err)
|
||||
}
|
||||
|
||||
// The balances of both channels should be updated accordingly.
|
||||
@@ -1021,7 +1021,7 @@ func TestStateUpdatePersistence(t *testing.T) {
|
||||
bobBalance)
|
||||
}
|
||||
|
||||
// The latest commitment from both sides should have all the HTLC's.
|
||||
// The latest commitment from both sides should have all the HTLCs.
|
||||
numAliceOutgoing := aliceChannel.localCommitChain.tail().outgoingHTLCs
|
||||
numAliceIncoming := aliceChannel.localCommitChain.tail().incomingHTLCs
|
||||
if len(numAliceOutgoing) != 3 {
|
||||
@@ -1065,7 +1065,7 @@ func TestStateUpdatePersistence(t *testing.T) {
|
||||
}
|
||||
|
||||
// The state update logs of the new channels and the old channels
|
||||
// should now be identical other than the height the HTLC's were added.
|
||||
// should now be identical other than the height the HTLCs were added.
|
||||
if aliceChannel.ourLogCounter != aliceChannelNew.ourLogCounter {
|
||||
t.Fatalf("alice log counter: expected %v, got %v",
|
||||
aliceChannel.ourLogCounter, aliceChannelNew.ourLogCounter)
|
||||
@@ -1101,7 +1101,7 @@ func TestStateUpdatePersistence(t *testing.T) {
|
||||
bobChannel.theirUpdateLog.Len(), bobChannelNew.theirUpdateLog.Len())
|
||||
}
|
||||
|
||||
// Now settle all the HTLC's, then force a state update. The state
|
||||
// Now settle all the HTLCs, then force a state update. The state
|
||||
// update should suceed as both sides have identical.
|
||||
for i := 0; i < 3; i++ {
|
||||
settleIndex, err := bobChannelNew.SettleHTLC(alicePreimage)
|
||||
@@ -1216,7 +1216,7 @@ func TestCancelHTLC(t *testing.T) {
|
||||
t.Fatalf("unable to create new commitment: %v", err)
|
||||
}
|
||||
|
||||
// Now HTLC's should be present on the commitment transaction for
|
||||
// Now HTLCs should be present on the commitment transaction for
|
||||
// either side.
|
||||
if len(aliceChannel.localCommitChain.tip().outgoingHTLCs) != 0 ||
|
||||
len(aliceChannel.remoteCommitChain.tip().outgoingHTLCs) != 0 {
|
||||
|
||||
@@ -214,7 +214,7 @@ type BlockChainIO interface {
|
||||
// transaction ID.
|
||||
GetTransaction(txid *chainhash.Hash) (*wire.MsgTx, error)
|
||||
|
||||
// GetBlockHash returns the hash of the block in the best block chain
|
||||
// GetBlockHash returns the hash of the block in the best blockchain
|
||||
// at the given height.
|
||||
GetBlockHash(blockHeight int64) (*chainhash.Hash, error)
|
||||
|
||||
|
||||
+17
-17
@@ -118,7 +118,7 @@ func SpendMultiSig(witnessScript, pubA, sigA, pubB, sigB []byte) [][]byte {
|
||||
witness[2] = sigB
|
||||
}
|
||||
|
||||
// Finally, add the pre-image as the last witness element.
|
||||
// Finally, add the preimage as the last witness element.
|
||||
witness[3] = witnessScript
|
||||
|
||||
return witness
|
||||
@@ -191,9 +191,9 @@ func senderHTLCScript(absoluteTimeout, relativeTimeout uint32, senderKey,
|
||||
|
||||
// Alternatively, the receiver can place a 0 as the second item of the
|
||||
// witness stack if they wish to claim the HTLC with the proper
|
||||
// pre-image as normal. In order to prevent an over-sized pre-image
|
||||
// preimage as normal. In order to prevent an over-sized preimage
|
||||
// attack (which can create undesirable redemption asymmetries), we
|
||||
// strongly require that all HTLC pre-images are exactly 32 bytes.
|
||||
// strongly require that all HTLC preimages are exactly 32 bytes.
|
||||
builder.AddOp(txscript.OP_ELSE)
|
||||
builder.AddOp(txscript.OP_SIZE)
|
||||
builder.AddInt64(32)
|
||||
@@ -218,7 +218,7 @@ func senderHTLCScript(absoluteTimeout, relativeTimeout uint32, senderKey,
|
||||
// In this case, the sender will need to wait for an absolute HTLC
|
||||
// timeout, then afterwards a relative timeout before we claim re-claim
|
||||
// the unsettled funds. This delay gives the other party a chance to
|
||||
// present the pre-image to the revocation hash in the event that the
|
||||
// present the preimage to the revocation hash in the event that the
|
||||
// sender (at this time) broadcasts this commitment transaction after
|
||||
// it has been revoked.
|
||||
builder.AddInt64(int64(absoluteTimeout))
|
||||
@@ -237,7 +237,7 @@ func senderHTLCScript(absoluteTimeout, relativeTimeout uint32, senderKey,
|
||||
// senderHtlcSpendRevoke constructs a valid witness allowing the receiver of an
|
||||
// HTLC to claim the output with knowledge of the revocation preimage in the
|
||||
// scenario that the sender of the HTLC broadcasts a previously revoked
|
||||
// commitment transaction. A valid spend requires knowledge of the pre-image to
|
||||
// commitment transaction. A valid spend requires knowledge of the preimage to
|
||||
// the commitment transaction's revocation hash, and a valid signature under
|
||||
// the receiver's public key.
|
||||
func senderHtlcSpendRevoke(commitScript []byte, outputAmt btcutil.Amount,
|
||||
@@ -268,7 +268,7 @@ func senderHtlcSpendRevoke(commitScript []byte, outputAmt btcutil.Amount,
|
||||
// senderHtlcSpendRedeem constructs a valid witness allowing the receiver of an
|
||||
// HTLC to redeem the pending output in the scenario that the sender broadcasts
|
||||
// their version of the commitment transaction. A valid spend requires
|
||||
// knowledge of the payment pre-image, and a valid signature under the
|
||||
// knowledge of the payment preimage, and a valid signature under the
|
||||
// receivers public key.
|
||||
func senderHtlcSpendRedeem(commitScript []byte, outputAmt btcutil.Amount,
|
||||
reciverKey *btcec.PrivateKey, sweepTx *wire.MsgTx,
|
||||
@@ -364,7 +364,7 @@ func senderHtlcSpendTimeout(commitScript []byte, outputAmt btcutil.Amount,
|
||||
// <sender key> OP_CHECKSIG
|
||||
// OP_ENDIF
|
||||
// TODO(roasbeef): go back to revocation keys in the HTLC outputs?
|
||||
// * also could combine pre-image with their key?
|
||||
// * also could combine preimage with their key?
|
||||
func receiverHTLCScript(absoluteTimeout, relativeTimeout uint32, senderKey,
|
||||
receiverKey *btcec.PublicKey, revokeHash, paymentHash []byte) ([]byte, error) {
|
||||
|
||||
@@ -380,7 +380,7 @@ func receiverHTLCScript(absoluteTimeout, relativeTimeout uint32, senderKey,
|
||||
// opportunity to re-claim the pending HTLC in the event that the
|
||||
// receiver (at this time) broadcasts this old commitment transaction
|
||||
// after it has been revoked. Additionally, we require that the
|
||||
// pre-image is exactly 32-bytes in order to avoid undesirable
|
||||
// preimage is exactly 32-bytes in order to avoid undesirable
|
||||
// redemption asymmetries in the multi-hop scenario.
|
||||
builder.AddOp(txscript.OP_SIZE)
|
||||
builder.AddInt64(32)
|
||||
@@ -549,7 +549,7 @@ func lockTimeToSequence(isSeconds bool, locktime uint32) uint32 {
|
||||
|
||||
// commitScriptToSelf constructs the public key script for the output on the
|
||||
// commitment transaction paying to the "owner" of said commitment transaction.
|
||||
// If the other party learns of the pre-image to the revocation hash, then they
|
||||
// If the other party learns of the preimage to the revocation hash, then they
|
||||
// can claim all the settled funds in the channel, plus the unsettled funds.
|
||||
//
|
||||
// Possible Input Scripts:
|
||||
@@ -641,7 +641,7 @@ func CommitSpendTimeout(signer Signer, signDesc *SignDescriptor,
|
||||
}
|
||||
|
||||
// CommitSpendRevoke constructs a valid witness allowing a node to sweep the
|
||||
// settled output of a malicious counter-party who broadcasts a revoked
|
||||
// settled output of a malicious counterparty who broadcasts a revoked
|
||||
// commitment transaction.
|
||||
func CommitSpendRevoke(signer Signer, signDesc *SignDescriptor,
|
||||
sweepTx *wire.MsgTx) (wire.TxWitness, error) {
|
||||
@@ -662,7 +662,7 @@ func CommitSpendRevoke(signer Signer, signDesc *SignDescriptor,
|
||||
}
|
||||
|
||||
// CommitSpendNoDelay constructs a valid witness allowing a node to spend their
|
||||
// settled no-delay output on the counter-party's commitment transaction.
|
||||
// settled no-delay output on the counterparty's commitment transaction.
|
||||
func CommitSpendNoDelay(signer Signer, signDesc *SignDescriptor,
|
||||
sweepTx *wire.MsgTx) (wire.TxWitness, error) {
|
||||
|
||||
@@ -677,10 +677,10 @@ func CommitSpendNoDelay(signer Signer, signDesc *SignDescriptor,
|
||||
}
|
||||
|
||||
// DeriveRevocationPubkey derives the revocation public key given the
|
||||
// counter-party's commitment key, and revocation pre-image derived via a
|
||||
// counterparty's commitment key, and revocation preimage derived via a
|
||||
// pseudo-random-function. In the event that we (for some reason) broadcast a
|
||||
// revoked commitment transaction, then if the other party knows the revocation
|
||||
// pre-image, then they'll be able to derive the corresponding private key to
|
||||
// preimage, then they'll be able to derive the corresponding private key to
|
||||
// this private key by exploiting the homomorphism in the elliptic curve group:
|
||||
// * https://en.wikipedia.org/wiki/Group_homomorphism#Homomorphisms_of_abelian_groups
|
||||
//
|
||||
@@ -690,7 +690,7 @@ func CommitSpendNoDelay(signer Signer, signDesc *SignDescriptor,
|
||||
// := G*k + G*h
|
||||
// := G * (k+h)
|
||||
//
|
||||
// Therefore, once we divulge the revocation pre-image, the remote peer is able to
|
||||
// Therefore, once we divulge the revocation preimage, the remote peer is able to
|
||||
// compute the proper private key for the revokeKey by computing:
|
||||
// revokePriv := commitPriv + revokePreimge mod N
|
||||
//
|
||||
@@ -710,7 +710,7 @@ func DeriveRevocationPubkey(commitPubKey *btcec.PublicKey,
|
||||
}
|
||||
|
||||
// DeriveRevocationPrivKey derives the revocation private key given a node's
|
||||
// commitment private key, and the pre-image to a previously seen revocation
|
||||
// commitment private key, and the preimage to a previously seen revocation
|
||||
// hash. Using this derived private key, a node is able to claim the output
|
||||
// within the commitment transaction of a node in the case that they broadcast
|
||||
// a previously revoked commitment transaction.
|
||||
@@ -722,12 +722,12 @@ func DeriveRevocationPubkey(commitPubKey *btcec.PublicKey,
|
||||
func DeriveRevocationPrivKey(commitPrivKey *btcec.PrivateKey,
|
||||
revokePreimage []byte) *btcec.PrivateKey {
|
||||
|
||||
// Convert the revocation pre-image into a scalar value so we can
|
||||
// Convert the revocation preimage into a scalar value so we can
|
||||
// manipulate it within the curve's defined finite field.
|
||||
revokeScalar := new(big.Int).SetBytes(revokePreimage)
|
||||
|
||||
// To derive the revocation private key, we simply add the revocation
|
||||
// pre-image to the commitment private key.
|
||||
// preimage to the commitment private key.
|
||||
//
|
||||
// This works since:
|
||||
// P = G*a + G*b
|
||||
|
||||
@@ -215,10 +215,10 @@ func makeWitnessTestCase(t *testing.T, f func() (wire.TxWitness, error)) func()
|
||||
//
|
||||
// The following cases are exercised by this test:
|
||||
// sender script:
|
||||
// * reciever spends
|
||||
// * receiver spends
|
||||
// * revoke w/ sig
|
||||
// * HTLC with invalid pre-image size
|
||||
// * HTLC with valid pre-image size + sig
|
||||
// * HTLC with invalid preimage size
|
||||
// * HTLC with valid preimage size + sig
|
||||
// * sender spends
|
||||
// * invalid lock-time for CLTV
|
||||
// * invalid sequence for CSV
|
||||
@@ -235,14 +235,14 @@ func TestHTLCSenderSpendValidation(t *testing.T) {
|
||||
}
|
||||
fakeFundingTxIn := wire.NewTxIn(fundingOut, nil, nil)
|
||||
|
||||
// Generate a payment and revocation pre-image to be used below.
|
||||
// Generate a payment and revocation preimage to be used below.
|
||||
revokePreimage := testHdSeed[:]
|
||||
revokeHash := fastsha256.Sum256(revokePreimage)
|
||||
paymentPreimage := revokeHash
|
||||
paymentPreimage[0] ^= 1
|
||||
paymentHash := fastsha256.Sum256(paymentPreimage[:])
|
||||
|
||||
// We'll also need some tests keys for alice and bob, and meta-data of
|
||||
// We'll also need some tests keys for alice and bob, and metadata of
|
||||
// the HTLC output.
|
||||
aliceKeyPriv, aliceKeyPub := btcec.PrivKeyFromBytes(btcec.S256(),
|
||||
testWalletPrivKey)
|
||||
@@ -302,18 +302,18 @@ func TestHTLCSenderSpendValidation(t *testing.T) {
|
||||
true,
|
||||
},
|
||||
{
|
||||
// HTLC with invalid pre-image size
|
||||
// HTLC with invalid preimage size
|
||||
makeWitnessTestCase(t, func() (wire.TxWitness, error) {
|
||||
return senderHtlcSpendRedeem(htlcScript, paymentAmt,
|
||||
bobKeyPriv, sweepTx,
|
||||
// Invalid pre-image length
|
||||
// Invalid preimage length
|
||||
bytes.Repeat([]byte{1}, 45))
|
||||
}),
|
||||
false,
|
||||
},
|
||||
{
|
||||
// HTLC with valid pre-image size + sig
|
||||
// TODO(roabeef): invalid pre-image
|
||||
// HTLC with valid preimage size + sig
|
||||
// TODO(roabeef): invalid preimage
|
||||
makeWitnessTestCase(t, func() (wire.TxWitness, error) {
|
||||
return senderHtlcSpendRedeem(htlcScript, paymentAmt,
|
||||
bobKeyPriv, sweepTx,
|
||||
@@ -385,11 +385,11 @@ func TestHTLCSenderSpendValidation(t *testing.T) {
|
||||
}
|
||||
|
||||
// TestHTLCReceiverSpendValidation tests all possible valid+invalid redemption
|
||||
// paths in the script used within the reciever's commitment transaction for an
|
||||
// paths in the script used within the receiver's commitment transaction for an
|
||||
// incoming HTLC.
|
||||
//
|
||||
// The following cases are exercised by this test:
|
||||
// * reciever spends
|
||||
// * receiver spends
|
||||
// * HTLC redemption w/ invalid preimage size
|
||||
// * HTLC redemption w/ invalid sequence
|
||||
// * HTLC redemption w/ valid preimage size
|
||||
@@ -407,14 +407,14 @@ func TestHTLCReceiverSpendValidation(t *testing.T) {
|
||||
}
|
||||
fakeFundingTxIn := wire.NewTxIn(fundingOut, nil, nil)
|
||||
|
||||
// Generate a payment and revocation pre-image to be used below.
|
||||
// Generate a payment and revocation preimage to be used below.
|
||||
revokePreimage := testHdSeed[:]
|
||||
revokeHash := fastsha256.Sum256(revokePreimage)
|
||||
paymentPreimage := revokeHash
|
||||
paymentPreimage[0] ^= 1
|
||||
paymentHash := fastsha256.Sum256(paymentPreimage[:])
|
||||
|
||||
// We'll also need some tests keys for alice and bob, and meta-data of
|
||||
// We'll also need some tests keys for alice and bob, and metadata of
|
||||
// the HTLC output.
|
||||
aliceKeyPriv, aliceKeyPub := btcec.PrivKeyFromBytes(btcec.S256(),
|
||||
testWalletPrivKey)
|
||||
@@ -438,15 +438,15 @@ func TestHTLCReceiverSpendValidation(t *testing.T) {
|
||||
// This will be Bob's commitment transaction. In this scenario Alice
|
||||
// is sending an HTLC to a node she has a a path to (could be Bob,
|
||||
// could be multiple hops down, it doesn't really matter).
|
||||
recieverCommitTx := wire.NewMsgTx(2)
|
||||
recieverCommitTx.AddTxIn(fakeFundingTxIn)
|
||||
recieverCommitTx.AddTxOut(&wire.TxOut{
|
||||
receiverCommitTx := wire.NewMsgTx(2)
|
||||
receiverCommitTx.AddTxIn(fakeFundingTxIn)
|
||||
receiverCommitTx.AddTxOut(&wire.TxOut{
|
||||
Value: int64(paymentAmt),
|
||||
PkScript: htlcWitnessScript,
|
||||
})
|
||||
|
||||
prevOut := &wire.OutPoint{
|
||||
Hash: recieverCommitTx.TxHash(),
|
||||
Hash: receiverCommitTx.TxHash(),
|
||||
Index: 0,
|
||||
}
|
||||
|
||||
|
||||
+7
-7
@@ -241,10 +241,10 @@ type channelOpenMsg struct {
|
||||
// as a regular Bitcoin wallet which uses HD keys. The wallet is highly concurrent
|
||||
// internally. All communication, and requests towards the wallet are
|
||||
// dispatched as messages over channels, ensuring thread safety across all
|
||||
// operations. Interaction has been designed independant of any peer-to-peer
|
||||
// operations. Interaction has been designed independent of any peer-to-peer
|
||||
// communication protocol, allowing the wallet to be self-contained and embeddable
|
||||
// within future projects interacting with the Lightning Network.
|
||||
// NOTE: At the moment the wallet requires a btcd full node, as it's dependant
|
||||
// NOTE: At the moment the wallet requires a btcd full node, as it's dependent
|
||||
// on btcd's websockets notifications as even triggers during the lifetime of
|
||||
// a channel. However, once the chainntnfs package is complete, the wallet
|
||||
// will be compatible with multiple RPC/notification services such as Electrum,
|
||||
@@ -261,7 +261,7 @@ type LightningWallet struct {
|
||||
coinSelectMtx sync.RWMutex
|
||||
|
||||
// A wrapper around a namespace within boltdb reserved for ln-based
|
||||
// wallet meta-data. See the 'channeldb' package for further
|
||||
// wallet metadata. See the 'channeldb' package for further
|
||||
// information.
|
||||
ChannelDB *channeldb.DB
|
||||
|
||||
@@ -480,7 +480,7 @@ out:
|
||||
// same inputs in the funding transaction. If reservation initialization is
|
||||
// successful, a ChannelReservation containing our completed contribution is
|
||||
// returned. Our contribution contains all the items necessary to allow the
|
||||
// counter party to build the funding transaction, and both versions of the
|
||||
// counterparty to build the funding transaction, and both versions of the
|
||||
// commitment transaction. Otherwise, an error occurred a nil pointer along with
|
||||
// an error are returned.
|
||||
//
|
||||
@@ -608,7 +608,7 @@ func (l *LightningWallet) handleFundingReserveRequest(req *initFundingReserveMsg
|
||||
|
||||
// Funding reservation request successfully handled. The funding inputs
|
||||
// will be marked as unavailable until the reservation is either
|
||||
// completed, or canceled.
|
||||
// completed, or cancelled.
|
||||
req.resp <- reservation
|
||||
req.err <- nil
|
||||
}
|
||||
@@ -754,7 +754,7 @@ func (l *LightningWallet) handleContributionMsg(req *addContributionMsg) {
|
||||
pendingReservation.partialState.FundingOutpoint = fundingOutpoint
|
||||
|
||||
// Initialize an empty sha-chain for them, tracking the current pending
|
||||
// revocation hash (we don't yet know the pre-image so we can't add it
|
||||
// revocation hash (we don't yet know the preimage so we can't add it
|
||||
// to the chain).
|
||||
e := &elkrem.ElkremReceiver{}
|
||||
pendingReservation.partialState.RemoteElkrem = e
|
||||
@@ -921,7 +921,7 @@ func (l *LightningWallet) handleSingleContribution(req *addSingleContributionMsg
|
||||
ourRevokeKey := DeriveRevocationPubkey(theirCommitKey, firstPreimage[:])
|
||||
|
||||
// Initialize an empty sha-chain for them, tracking the current pending
|
||||
// revocation hash (we don't yet know the pre-image so we can't add it
|
||||
// revocation hash (we don't yet know the preimage so we can't add it
|
||||
// to the chain).
|
||||
remoteElkrem := &elkrem.ElkremReceiver{}
|
||||
pendingReservation.partialState.RemoteElkrem = remoteElkrem
|
||||
|
||||
Reference in new issue
Block a user