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

client/btc: Use coin specific tx hashes. #2342

Merged
merged 1 commit into from
May 5, 2023

Conversation

JoeGruffins
Copy link
Member

closes #2327

Copy link
Member

@chappjc chappjc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. There are so many gotchas with zcash and it's about to get trickier with #2338
I wonder if we should make zec not a clone wallet any more. This fix looks good though.

@chappjc
Copy link
Member

chappjc commented May 5, 2023

I see a few more wrong hashes if you wanna add these:

diff --git a/client/asset/btc/btc.go b/client/asset/btc/btc.go
index e36a38649..21988027e 100644
--- a/client/asset/btc/btc.go
+++ b/client/asset/btc/btc.go
@@ -3109,7 +3109,7 @@ func accelerateOrder(btc *baseWallet, swapCoins, accelerationCoins []dex.Bytes,
        delete(btc.fundingCoins, newOutPoint(changeTxHash, changeVout))
 
        if newChange == nil {
-               return nil, signedTx.TxHash().String(), nil
+               return nil, btc.hashTx(signedTx).String(), nil
        }
 
        // Add the new change to the cache if needed. We check if
@@ -3137,7 +3137,7 @@ func accelerateOrder(btc *baseWallet, swapCoins, accelerationCoins []dex.Bytes,
 
        // return nil error since tx is already broadcast, and core needs to update
        // the change coin
-       return newChange, signedTx.TxHash().String(), nil
+       return newChange, btc.hashTx(signedTx).String(), nil
 }
 
 // AccelerationEstimate takes the same parameters as AccelerateOrder, but
@@ -5314,7 +5314,7 @@ func (btc *baseWallet) MakeBondTx(ver uint16, amt, feeRate uint64, lockTime time
                return nil, nil, fmt.Errorf("failed to sign bond tx: %w", err)
        }
 
-       txid := signedTx.TxHash()
+       txid := btc.hashTx(signedTx)
 
        signedTxBytes, err := serializeMsgTx(signedTx)
        if err != nil {
@@ -5326,7 +5326,7 @@ func (btc *baseWallet) MakeBondTx(ver uint16, amt, feeRate uint64, lockTime time
        }
 
        // Prep the redeem / refund tx.
-       redeemMsgTx, err := btc.makeBondRefundTxV0(&txid, 0, amt, bondScript, bondKey, feeRate)
+       redeemMsgTx, err := btc.makeBondRefundTxV0(txid, 0, amt, bondScript, bondKey, feeRate)
        if err != nil {
                return nil, nil, fmt.Errorf("unable to create bond redemption tx: %w", err)
        }
@@ -5339,7 +5339,7 @@ func (btc *baseWallet) MakeBondTx(ver uint16, amt, feeRate uint64, lockTime time
                Version:    ver,
                AssetID:    btc.cloneParams.AssetID,
                Amount:     amt,
-               CoinID:     toCoinID(&txid, 0),
+               CoinID:     toCoinID(txid, 0),
                Data:       bondScript,
                SignedTx:   signedTxBytes,
                UnsignedTx: unsignedTxBytes,

@chappjc
Copy link
Member

chappjc commented May 5, 2023

Oh crud, also, cfg.TxSerializer needs to be used in MakeBondTx instead of serializeMsgTx.
ZEC has forced baseWallet to get a little out of hand.

@chappjc chappjc requested a review from buck54321 May 5, 2023 14:18
@chappjc
Copy link
Member

chappjc commented May 5, 2023

Oh crud, also, cfg.TxSerializer needs to be used in MakeBondTx instead of serializeMsgTx. ZEC has forced baseWallet to get a little out of hand.

should work but haven't tried it:

diff --git a/client/asset/btc/btc.go b/client/asset/btc/btc.go
index 5ac495bef..b4b689780 100644
--- a/client/asset/btc/btc.go
+++ b/client/asset/btc/btc.go
@@ -5316,11 +5316,11 @@ func (btc *baseWallet) MakeBondTx(ver uint16, amt, feeRate uint64, lockTime time
 
        txid := signedTx.TxHash()
 
-       signedTxBytes, err := serializeMsgTx(signedTx)
+       signedTxBytes, err := btc.serializeTx(signedTx)
        if err != nil {
                return nil, nil, err
        }
-       unsignedTxBytes, err := serializeMsgTx(baseTx)
+       unsignedTxBytes, err := btc.serializeTx(baseTx)
        if err != nil {
                return nil, nil, err
        }
@@ -5330,7 +5330,7 @@ func (btc *baseWallet) MakeBondTx(ver uint16, amt, feeRate uint64, lockTime time
        if err != nil {
                return nil, nil, fmt.Errorf("unable to create bond redemption tx: %w", err)
        }
-       redeemTx, err := serializeMsgTx(redeemMsgTx)
+       redeemTx, err := btc.serializeTx(redeemMsgTx)
        if err != nil {
                return nil, nil, fmt.Errorf("failed to serialize bond redemption tx: %w", err)
        }

@JoeGruffins
Copy link
Member Author

Applying chapp changes https://github.com/decred/dcrdex/compare/b7957ae597a98a656e6d20f231c3255167c73bcb..24a1b5a5988ba9b43ab907c905b9fb0b8a12cfef

@chappjc chappjc merged commit 0394ce3 into decred:master May 5, 2023
@chappjc chappjc added this to the 0.6.1 milestone May 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

client/zec: Sent transaction id does not exist.
2 participants