Skip to content

Commit

Permalink
Merge pull request #1036 from lightninglabs/rename-chain-porter-states
Browse files Browse the repository at this point in the history
Improve Clarity in ChainPorter State Names
  • Loading branch information
guggero authored Jul 19, 2024
2 parents 7035ded + 0647401 commit 4a11fd1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 26 deletions.
2 changes: 1 addition & 1 deletion itest/psbt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2968,7 +2968,7 @@ func testPsbtRelativeLockTimeSendProofFail(t *harnessTest) {

AssertSendEvents(
t.t, aliceScriptKeyBytes, sendEvents,
tapfreighter.SendStateLogCommit,
tapfreighter.SendStateStorePreBroadcast,
tapfreighter.SendStateWaitTxConf,
)

Expand Down
24 changes: 12 additions & 12 deletions tapfreighter/chain_porter.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ func (p *ChainPorter) storeProofs(sendPkg *sendPackage) error {
log.Debugf("Not updating proofs as there are no active " +
"transfers")

sendPkg.SendState = SendStateReceiverProofTransfer
sendPkg.SendState = SendStateTransferProofs
return nil
}

Expand Down Expand Up @@ -532,7 +532,7 @@ func (p *ChainPorter) storeProofs(sendPkg *sendPackage) error {
}
}

sendPkg.SendState = SendStateReceiverProofTransfer
sendPkg.SendState = SendStateTransferProofs
return nil
}

Expand Down Expand Up @@ -1031,16 +1031,16 @@ func (p *ChainPorter) stateStep(currentPkg sendPackage) (*sendPackage, error) {
"package: %w", err)
}

currentPkg.SendState = SendStateLogCommit
currentPkg.SendState = SendStateStorePreBroadcast

return &currentPkg, nil

// At this state, we have a final PSBT transaction which is fully
// signed. We'll write this to disk (the point of no return), then
// broadcast this to the network.
case SendStateLogCommit:
// Before we can broadcast, we want to find out the current
// height to pass as a height hint.
// In this state, the parcel state is stored before the fully signed
// transaction is broadcast to the mempool.
case SendStateStorePreBroadcast:
// We won't broadcast in this state, but in preparation for
// broadcasting, we will find out the current height to use as
// a height hint.
ctx, cancel := p.WithCtxQuit()
defer cancel()
currentHeight, err := p.cfg.ChainBridge.CurrentHeight(ctx)
Expand Down Expand Up @@ -1164,8 +1164,8 @@ func (p *ChainPorter) stateStep(currentPkg sendPackage) (*sendPackage, error) {

// At this point, the transfer transaction is confirmed on-chain, and
// we've stored the sender and receiver proofs in the proof archive.
// We'll now attempt to transfer the receiver proof to the receiver.
case SendStateReceiverProofTransfer:
// We'll now attempt to transfer one or more proofs to the receiver(s).
case SendStateTransferProofs:
// We'll set the package state to complete early here so the
// main loop breaks out. We'll continue to attempt proof
// deliver in the background.
Expand All @@ -1181,7 +1181,7 @@ func (p *ChainPorter) stateStep(currentPkg sendPackage) (*sendPackage, error) {
"proof: %v", err)

p.publishSubscriberEvent(newAssetSendErrorEvent(
err, SendStateReceiverProofTransfer,
err, SendStateTransferProofs,
currentPkg,
))
}
Expand Down
24 changes: 11 additions & 13 deletions tapfreighter/parcel.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@ const (
// then finalize to place the necessary signatures in the transaction.
SendStateAnchorSign

// SendStateLogCommit is the final in memory state. In this state,
// we'll extract the signed transaction from the PSBT and log the
// transfer information to disk. At this point, after a restart, the
// transfer can be resumed.
SendStateLogCommit
// SendStateStorePreBroadcast is the state in which the finalized fully
// signed transaction is written to persistent storage before broadcast.
SendStateStorePreBroadcast

// SendStateBroadcast broadcasts the transfer transaction to the
// network, and imports the taproot output back into the wallet to
Expand All @@ -57,9 +55,9 @@ const (
// and receiver proofs to the proof archive.
SendStateStoreProofs

// SendStateReceiverProofTransfer is the state in which we will commence
// the receiver proof transfer process.
SendStateReceiverProofTransfer
// SendStateTransferProofs is the state where we attempt to transfer
// on-chain transaction proof(s) to the receiving party or parties.
SendStateTransferProofs

// SendStateComplete is the state which is reached once entire asset
// transfer process is complete.
Expand All @@ -78,8 +76,8 @@ func (s SendState) String() string {
case SendStateAnchorSign:
return "SendStateAnchorSign"

case SendStateLogCommit:
return "SendStateLogCommit"
case SendStateStorePreBroadcast:
return "SendStateStorePreBroadcast"

case SendStateBroadcast:
return "SendStateBroadcast"
Expand All @@ -90,8 +88,8 @@ func (s SendState) String() string {
case SendStateStoreProofs:
return "SendStateStoreProofs"

case SendStateReceiverProofTransfer:
return "SendStateReceiverProofTransfer"
case SendStateTransferProofs:
return "SendStateTransferProofs"

case SendStateComplete:
return "SendStateComplete"
Expand Down Expand Up @@ -381,7 +379,7 @@ func (p *PreAnchoredParcel) pkg() *sendPackage {
// commitment.
return &sendPackage{
Parcel: p,
SendState: SendStateLogCommit,
SendState: SendStateStorePreBroadcast,
VirtualPackets: p.virtualPackets,
PassiveAssets: p.passiveAssets,
AnchorTx: p.anchorTx,
Expand Down

0 comments on commit 4a11fd1

Please sign in to comment.