Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tapchannel: fix linter, formatting and typos #963

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 47 additions & 40 deletions tapchannel/aux_sweeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ type sweepAddrReq struct {
resp chan lfn.Result[sweep.SweepOutput]
}

// broadcastReq is used by the sweeper to notify us of a transaction broascast.
// broadcastReq is used by the sweeper to notify us of a transaction broadcast.
type broadcastReq struct {
// req holds the sweep request that includes the set of inputs to be
// swept.
req *sweep.BumpRequest

// tx is the transaction to be broadcasted.
// tx is the transaction to be broadcast.
tx *wire.MsgTx

// fee is the fee that was used for the transaction.
Expand Down Expand Up @@ -226,9 +226,11 @@ func (a *AuxSweeper) createSweepVpackets(sweepInputs []*cmsg.AssetOutput,

// With the allocations created above, we'll now extract a slice of
// each of the input proofs for each asset.
inputProofs := fn.Map(sweepInputs, func(o *cmsg.AssetOutput) *proof.Proof {
return &o.Proof.Val
})
inputProofs := fn.Map(
sweepInputs, func(o *cmsg.AssetOutput) *proof.Proof {
return &o.Proof.Val
},
)

// With the proofs constructed, we can now distribute the coins to
// create the vPackets that we'll pass on to the next stage.
Expand Down Expand Up @@ -268,16 +270,18 @@ func (a *AuxSweeper) createSweepVpackets(sweepInputs []*cmsg.AssetOutput,
}

// Next before we sign, we'll make sure to update the witness
// of the prev asset's root asset. Otherwise we'll be signing
// of the prev asset's root asset. Otherwise, we'll be signing
// the wrong input leaf.
vIn := vPackets[idx].Inputs[0]
if vIn.Asset().HasSplitCommitmentWitness() {
rootAsset := vIn.Asset().PrevWitnesses[0].SplitCommitment.RootAsset //nolint:lll
//nolint:lll
rootAsset := vIn.Asset().PrevWitnesses[0].SplitCommitment.RootAsset
rootAsset.PrevWitnesses[0].TxWitness = fundingWitness
}

for outIdx := range vPackets[idx].Outputs {
vPackets[idx].Outputs[outIdx].ProofDeliveryAddress = courierAddr //nolint:lll
//nolint:lll
vPackets[idx].Outputs[outIdx].ProofDeliveryAddress = courierAddr
}
}

Expand Down Expand Up @@ -426,7 +430,7 @@ func commitNoDelaySweepDesc(keyRing *lnwallet.CommitmentKeyRing,
})
}

// comimtDelaySweepDesc creates a sweep desc for a commitment output that
// commitDelaySweepDesc creates a sweep desc for a commitment output that
// resides on our local commitment transaction. This output is a delay output,
// so we need to mind the CSV delay when sweeping it.
func commitDelaySweepDesc(keyRing *lnwallet.CommitmentKeyRing,
Expand Down Expand Up @@ -573,11 +577,11 @@ func assetOutputToVPacket(fundingInputProofs map[asset.ID]*proof.Proof,
return nil
}

// anchorOutputAllocs is a helper function that creates a set of allocations
// for the anchor outputs. We'll use this later to create the proper exclusion
// proofs.
func anchorOutputAllocs(keyRing *lnwallet.CommitmentKeyRing,
) lfn.Result[[]*Allocation] {
// anchorOutputAllocations is a helper function that creates a set of
// allocations for the anchor outputs. We'll use this later to create the proper
// exclusion proofs.
func anchorOutputAllocations(
keyRing *lnwallet.CommitmentKeyRing) lfn.Result[[]*Allocation] {

anchorAlloc := func(k *btcec.PublicKey) lfn.Result[*Allocation] {
anchorTree, err := input.NewAnchorScriptTree(k)
Expand Down Expand Up @@ -631,8 +635,8 @@ func anchorOutputAllocs(keyRing *lnwallet.CommitmentKeyRing,

// remoteCommitScriptKey creates the script key for the remote commitment
// output.
func remoteCommitScriptKey(remoteKey *btcec.PublicKey,
) lfn.Result[asset.ScriptKey] {
func remoteCommitScriptKey(
remoteKey *btcec.PublicKey) lfn.Result[asset.ScriptKey] {

remoteScriptTree, err := input.NewRemoteCommitScriptTree(
remoteKey, input.NoneTapLeaf(),
Expand Down Expand Up @@ -679,8 +683,8 @@ func localCommitScriptKey(localKey, revokeKey *btcec.PublicKey,
}

// deriveCommitKeys derives the script keys for the local and remote party.
func deriveCommitKeys(req lnwallet.ResolutionReq,
) (*asset.ScriptKey, *asset.ScriptKey, error) {
func deriveCommitKeys(req lnwallet.ResolutionReq) (*asset.ScriptKey,
*asset.ScriptKey, error) {

localScriptTree, err := localCommitScriptKey(
req.KeyRing.ToLocalKey, req.KeyRing.RevocationKey,
Expand All @@ -705,7 +709,7 @@ func deriveCommitKeys(req lnwallet.ResolutionReq,
// importCommitScriptKeys imports the script keys for the commitment outputs
// into the local addr book.
func (a *AuxSweeper) importCommitScriptKeys(req lnwallet.ResolutionReq) error {
// Generate the local and remote script key so we can properly import
// Generate the local and remote script key, so we can properly import
// into the addr book, like we did above.
localCommitScriptKey, remoteCommitScriptKey, err := deriveCommitKeys(
req,
Expand Down Expand Up @@ -815,12 +819,14 @@ func (a *AuxSweeper) importOutputProofs(scid lnwire.ShortChannelID,
if err != nil {
return fmt.Errorf("unable to get block: %w", err)
}
err = proofToImport.UpdateTransitionProof(&proof.BaseProofParams{ //nolint:lll
Block: block,
BlockHeight: scid.BlockHeight,
Tx: block.Transactions[scid.TxIndex],
TxIndex: int(scid.TxIndex),
})
err = proofToImport.UpdateTransitionProof(
&proof.BaseProofParams{
Block: block,
BlockHeight: scid.BlockHeight,
Tx: block.Transactions[scid.TxIndex],
TxIndex: int(scid.TxIndex),
},
)
if err != nil {
return fmt.Errorf("error updating transition "+
"proof: %w", err)
Expand Down Expand Up @@ -851,9 +857,10 @@ func (a *AuxSweeper) importOutputProofs(scid lnwire.ShortChannelID,
ctxb, a.cfg.HeaderVerifier, proof.DefaultMerkleVerifier,
a.cfg.GroupVerifier, a.cfg.ChainBridge, false,
&proof.AnnotatedProof{
//nolint:lll
Locator: proof.Locator{
AssetID: fn.Ptr(fundingUTXO.ID()),
ScriptKey: *fundingUTXO.ScriptKey.PubKey, //nolint:lll
ScriptKey: *fundingUTXO.ScriptKey.PubKey,
OutPoint: fn.Ptr(
proofToImport.OutPoint(),
),
Expand Down Expand Up @@ -952,7 +959,8 @@ func (a *AuxSweeper) importCommitTx(req lnwallet.ResolutionReq,
return err
}
}
for _, outgoingHTLCs := range commitState.OutgoingHtlcAssets.Val.HtlcOutputs { //nolint:lll
//nolint:lll
for _, outgoingHTLCs := range commitState.OutgoingHtlcAssets.Val.HtlcOutputs {
for _, outgoingHTLC := range outgoingHTLCs.Outputs {
err := assetOutputToVPacket(
fundingInputProofs, vPktsByAssetID, outgoingHTLC,
Expand All @@ -964,7 +972,8 @@ func (a *AuxSweeper) importCommitTx(req lnwallet.ResolutionReq,
}
}
}
for _, incomingHTLCs := range commitState.IncomingHtlcAssets.Val.HtlcOutputs { //nolint:lll
//nolint:lll
for _, incomingHTLCs := range commitState.IncomingHtlcAssets.Val.HtlcOutputs {
for _, incomingHTLC := range incomingHTLCs.Outputs {
err := assetOutputToVPacket(
fundingInputProofs, vPktsByAssetID, incomingHTLC,
Expand Down Expand Up @@ -1018,16 +1027,14 @@ func (a *AuxSweeper) importCommitTx(req lnwallet.ResolutionReq,
"commitments: %w", err)
}

// With the output commitments known, we ca regenerate the proof suffix
// With the output commitments known, we can regenerate the proof suffix
// for each vPkt.
anchorAllocs, err := anchorOutputAllocs(req.KeyRing).Unpack()
anchorAllocations, err := anchorOutputAllocations(req.KeyRing).Unpack()
if err != nil {
return fmt.Errorf("unable to create anchor "+
"allocations: %w", err)
}
exclusionCreator := NonAssetExclusionProofs(
anchorAllocs,
)
exclusionCreator := NonAssetExclusionProofs(anchorAllocations)
for idx := range vPkts {
vPkt := vPkts[idx]
for outIdx := range vPkt.Outputs {
Expand Down Expand Up @@ -1058,8 +1065,8 @@ func (a *AuxSweeper) importCommitTx(req lnwallet.ResolutionReq,
// resolveContract takes in a resolution request and resolves it by creating a
// serialized resolution blob that contains the virtual packets needed to sweep
// the funds from the contract.
func (a *AuxSweeper) resolveContract(req lnwallet.ResolutionReq,
) lfn.Result[tlv.Blob] {
func (a *AuxSweeper) resolveContract(
req lnwallet.ResolutionReq) lfn.Result[tlv.Blob] {

// If there's no commit blob, then there's nothing to resolve.
if req.CommitBlob.IsNone() {
Expand All @@ -1069,9 +1076,9 @@ func (a *AuxSweeper) resolveContract(req lnwallet.ResolutionReq,
log.Infof("Generating resolution_blob for contract_type=%v, "+
"chan_point=%v", req.Type, req.ChanPoint)

// As we have a commit blob, we'll decode the commit blob so we can
// As we have a commit blob, we'll decode the commit blob, so we can
// have access to all the active outputs. We'll also decode the funding
// blob so we can make vInt from it.
// blob, so we can make vInt from it.
commitState, err := tapchannelmsg.DecodeCommitment(
req.CommitBlob.UnwrapOr(nil),
)
Expand Down Expand Up @@ -1119,7 +1126,7 @@ func (a *AuxSweeper) resolveContract(req lnwallet.ResolutionReq,
// A non-delay output. This means the remote party force closed on
// chain.
case input.TaprootRemoteCommitSpend:
// In this case, we'll be resolving the set of of remote
// In this case, we'll be resolving the set of remote
// assets, on the remote party's commitment, which are actually
// our assets.
assetOutputs = commitState.RemoteAssets.Val.Outputs
Expand Down Expand Up @@ -1467,8 +1474,8 @@ func (a *AuxSweeper) contractResolver() {

// ResolveContract attempts to obtain a resolution blob for the specified
// contract.
func (a *AuxSweeper) ResolveContract(req lnwallet.ResolutionReq,
) lfn.Result[tlv.Blob] {
func (a *AuxSweeper) ResolveContract(
req lnwallet.ResolutionReq) lfn.Result[tlv.Blob] {

auxReq := &resolutionReq{
req: req,
Expand Down
1 change: 1 addition & 0 deletions tapchannel/commitment.go
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,7 @@ func addCommitmentOutputs(chanType channeldb.ChannelType, localChanCfg,
).PubKey,
TweakedScriptKey: &asset.TweakedScriptKey{
RawKey: keychain.KeyDescriptor{
//nolint:lll
PubKey: toRemoteTree.InternalKey,
},
Tweak: toRemoteTree.TapscriptRoot,
Expand Down
Loading