Skip to content
Open
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
2 changes: 1 addition & 1 deletion asset/group_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ func TestNonSpendableLeafScript(t *testing.T) {

// Finally, we'll make the dummy spend transaction, and
// the output script that we'll attempt to spend.
spendTx := wire.NewMsgTx(1)
spendTx := wire.NewMsgTx(3)
spendTx.AddTxIn(&wire.TxIn{})

leafScript, err := txscript.PayToTaprootScript(
Expand Down
5 changes: 5 additions & 0 deletions asset/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,11 @@ func virtualGenesisTx(newAsset *Asset) (*wire.MsgTx, error) {

// With our single input and output mapped, we're ready to construct our
// virtual transaction.
//
// IMPORTANT: The virtual transaction version must remain at v2 for
// backwards compatibility. Changing the version would invalidate all
// existing asset witness signatures. Only the anchor (real Bitcoin)
// transactions use v3.
virtualTx := wire.NewMsgTx(2)
virtualTx.AddTxIn(txIn)
virtualTx.AddTxOut(txOut)
Expand Down
2 changes: 1 addition & 1 deletion itest/round_trip_send_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func testRoundTripSend(t *harnessTest) {
estimatedWeight := estimator.Weight()
requiredFee := feeRate.FeeForWeight(estimatedWeight)

tx := wire.NewMsgTx(2)
tx := wire.NewMsgTx(3)
tx.TxIn = []*wire.TxIn{{
PreviousOutPoint: *outpoint,
}}
Expand Down
2 changes: 1 addition & 1 deletion itest/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ func ManualMintSimpleAsset(t *harnessTest, lndNode *node.HarnessNode,
[]byte{txscript.OP_1, txscript.OP_DATA_32},
bytes.Repeat([]byte{0x00}, 32)...,
)
txTemplate := wire.NewMsgTx(2)
txTemplate := wire.NewMsgTx(3)
txTemplate.AddTxOut(&wire.TxOut{
Value: int64(btcutil.Amount(1000)),
PkScript: bytes.Clone(genesisDummyScript),
Expand Down
56 changes: 55 additions & 1 deletion proof/verifier_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package proof

import (
"bytes"
"encoding/hex"
"os"
"slices"
"strings"
"testing"

"github.com/btcsuite/btcd/btcec/v2"
Expand Down Expand Up @@ -155,7 +159,7 @@ func makeV0InclusionProof(t *testing.T, opts ...createProofOpt) ([]*Proof,

internalKey := test.RandPubKey(t)

anchorTx := wire.NewMsgTx(2)
anchorTx := wire.NewMsgTx(3)
anchorTx.TxOut = make([]*wire.TxOut, len(tapCommitments))

indexes := maps.Keys(tapCommitments)
Expand Down Expand Up @@ -1157,3 +1161,53 @@ func TestVerifyV1ExclusionProof(t *testing.T) {
})
}
}

// TestTransactionVersionInProofSystem verifies that the current codebase
// creates v3 transactions.
func TestTransactionVersionInProofSystem(t *testing.T) {
t.Parallel()

proofs, _ := makeV0InclusionProof(t)
require.Len(t, proofs, 1)
proof := proofs[0]

require.Equal(t, int32(3), proof.AnchorTx.Version,
"Post-commit b3562461: all new transactions should be v3")

Choose a reason for hiding this comment

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

medium

It's great that you've included a commit hash in this assertion message. However, it might be even more helpful to also include a reference to the BIP (BIP 431) that introduces v3 transactions. This would provide more context for future developers.

}

// TestBackwardsCompatibilityWithExistingProofs tests that existing proof files
// (which contain v2 transactions) can still be loaded and verified by the
// current v3-enabled codebase.
func TestBackwardsCompatibilityWithExistingProofs(t *testing.T) {
t.Parallel()

const fileName = "testdata/proof-file.hex"

// Load the existing proof file (created pre-v3).
proofHex, err := os.ReadFile(fileName)
require.NoError(t, err, "Failed to load %s", fileName)

proofBytes, err := hex.DecodeString(
strings.TrimSpace(string(proofHex)),
)
require.NoError(t, err)

// Decode the proof file.
var proofFile File
err = proofFile.Decode(bytes.NewReader(proofBytes))
require.NoError(t, err, "v3-enabled code must decode existing proofs")

// Get the last proof from the file.
lastProof, err := proofFile.LastProof()
require.NoError(t, err)

t.Logf("Proof file %s uses tx version: %d",
fileName, lastProof.AnchorTx.Version)

require.Equal(t, int32(2), lastProof.AnchorTx.Version)

_, err = lastProof.verifyExclusionProofs()
require.NoError(
t, err, "v3-enabled code must verify existing v2 proofs",
)
}
2 changes: 1 addition & 1 deletion tapchannel/commitment.go
Original file line number Diff line number Diff line change
Expand Up @@ -1492,7 +1492,7 @@ func CreateSecondLevelHtlcTx(chanState lnwallet.AuxChanState,
func FakeCommitTx(fundingOutpoint wire.OutPoint,
allocations []*tapsend.Allocation) (*wire.MsgTx, error) {

fakeCommitTx := wire.NewMsgTx(2)
fakeCommitTx := wire.NewMsgTx(3)
fakeCommitTx.TxIn = []*wire.TxIn{
{
PreviousOutPoint: fundingOutpoint,
Expand Down
2 changes: 1 addition & 1 deletion tapdb/addrs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func confirmTx(tx *lndclient.Transaction) {

func randWalletTx() *lndclient.Transaction {
tx := &lndclient.Transaction{
Tx: wire.NewMsgTx(2),
Tx: wire.NewMsgTx(3),
Timestamp: time.Now(),
BlockHeight: rand.Int31n(700_000),
BlockHash: test.RandHash().String(),
Expand Down
2 changes: 1 addition & 1 deletion tapdb/asset_minting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func addRandomManagedUTXO(t *testing.T, ctx context.Context,
_, err = rand.Read(blockHash[:])
require.NoError(t, err)

anchorTx := wire.NewMsgTx(2)
anchorTx := wire.NewMsgTx(3)
anchorTx.AddTxIn(&wire.TxIn{})
anchorTx.AddTxOut(&wire.TxOut{
PkScript: bytes.Repeat([]byte{0x01}, 34),
Expand Down
4 changes: 2 additions & 2 deletions tapdb/assets_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ func dbAssetsToChainAssets(dbAssets []ConfirmedAsset, witnesses assetWitnesses,
}
}

anchorTx := wire.NewMsgTx(2)
anchorTx := wire.NewMsgTx(3)
err = anchorTx.Deserialize(bytes.NewBuffer(sprout.AnchorTx))
if err != nil {
return nil, fmt.Errorf("unable to decode tx: %w", err)
Expand Down Expand Up @@ -3592,7 +3592,7 @@ func (a *AssetStore) queryParcelsWithFilters(ctx context.Context,
"%w", err)
}

anchorTx := wire.NewMsgTx(2)
anchorTx := wire.NewMsgTx(3)
err = anchorTx.Deserialize(bytes.NewReader(
dbAnchorTx.RawTx,
))
Expand Down
10 changes: 5 additions & 5 deletions tapdb/assets_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ func TestImportAssetProof(t *testing.T) {
// We now add a second proof for the same script key but a different
// outpoint and expect that to be stored and retrieved correctly.
oldOutpoint := testProof.AssetSnapshot.OutPoint
newChainTx := wire.NewMsgTx(2)
newChainTx := wire.NewMsgTx(3)
newChainTx.TxIn = []*wire.TxIn{{
PreviousOutPoint: test.RandOp(t),
}}
Expand Down Expand Up @@ -1577,7 +1577,7 @@ func TestAssetExportLog(t *testing.T) {
require.Len(t, utxos, 1)
require.Equal(t, assetGen.anchorPoints[0], utxos[0].OutPoint)

newAnchorTx := wire.NewMsgTx(2)
newAnchorTx := wire.NewMsgTx(3)
newAnchorTx.AddTxIn(&wire.TxIn{})
newAnchorTx.TxIn[0].SignatureScript = []byte{}
newAnchorTx.AddTxOut(&wire.TxOut{
Expand Down Expand Up @@ -2377,7 +2377,7 @@ func TestTransferOutputProofDeliveryStatus(t *testing.T) {
// of the first transfer output.
//
// First, we'll generate a new anchor transaction for use in the parcel.
newAnchorTx := wire.NewMsgTx(2)
newAnchorTx := wire.NewMsgTx(3)
newAnchorTx.AddTxIn(&wire.TxIn{})
newAnchorTx.TxIn[0].SignatureScript = []byte{}
newAnchorTx.AddTxOut(&wire.TxOut{
Expand Down Expand Up @@ -2670,7 +2670,7 @@ func TestQueryAssetBurns(t *testing.T) {
// of the first transfer output.
//
// First, we'll generate a new anchor transaction for use in the parcel.
newAnchorTx := wire.NewMsgTx(2)
newAnchorTx := wire.NewMsgTx(3)
newAnchorTx.AddTxIn(&wire.TxIn{})
newAnchorTx.TxIn[0].SignatureScript = []byte{}
newAnchorTx.AddTxOut(&wire.TxOut{
Expand Down Expand Up @@ -3257,7 +3257,7 @@ func createTestProofWithAnchor(t *testing.T, testAsset *asset.Asset,
_, err := rand.Read(blockHash[:])
require.NoError(t, err)

anchorTx := wire.NewMsgTx(2)
anchorTx := wire.NewMsgTx(3)
anchorTx.AddTxIn(&wire.TxIn{})

// Add enough outputs to cover the requested index
Expand Down
2 changes: 1 addition & 1 deletion tapdb/sqlutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (d *DbHandler) AddRandomAssetProof(t *testing.T) (*asset.Asset,
_, err = rand.Read(blockHash[:])
require.NoError(t, err)

anchorTx := wire.NewMsgTx(2)
anchorTx := wire.NewMsgTx(3)
anchorTx.AddTxIn(&wire.TxIn{})
anchorTx.AddTxOut(&wire.TxOut{
PkScript: bytes.Repeat([]byte{0x01}, 34),
Expand Down
8 changes: 4 additions & 4 deletions tapdb/supply_commit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (h *supplyCommitTestHarness) addTestMintingBatch() ([]byte, int64,
genesisPointID, err := upsertGenesisPoint(ctx, db, genesisPoint)
require.NoError(h.t, err)

mintingTx := wire.NewMsgTx(2)
mintingTx := wire.NewMsgTx(3)
mintingTx.AddTxIn(&wire.TxIn{
PreviousOutPoint: genesisPoint,
})
Expand Down Expand Up @@ -2238,7 +2238,7 @@ func TestSupplyCommitFetchLatestCommitment(t *testing.T) {
func randTx(t *testing.T, numOutputs int) *wire.MsgTx {
t.Helper()

tx := wire.NewMsgTx(2)
tx := wire.NewMsgTx(3)
tx.AddTxIn(&wire.TxIn{
PreviousOutPoint: test.RandOp(t),
})
Expand All @@ -2265,7 +2265,7 @@ func TestSupplyCommitMultipleSupplyCommitments(t *testing.T) {
// Helper to generate unique transaction data for each commitment
genTxData := func() (int64, []byte, []byte) {
genesisPoint := test.RandOp(h.t)
tx := wire.NewMsgTx(2)
tx := wire.NewMsgTx(3)
tx.AddTxIn(&wire.TxIn{
PreviousOutPoint: genesisPoint,
})
Expand Down Expand Up @@ -2323,7 +2323,7 @@ func TestSupplySyncerPushLog(t *testing.T) {
// TestSupplyCommitMultipleSupplyCommitments.
genTxData := func() (int64, []byte, []byte) {
genesisPoint := test.RandOp(h.t)
tx := wire.NewMsgTx(2)
tx := wire.NewMsgTx(3)
tx.AddTxIn(&wire.TxIn{
PreviousOutPoint: genesisPoint,
})
Expand Down
2 changes: 1 addition & 1 deletion tapdb/universe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,7 @@ func TestUpsertSupplyPreCommit(t *testing.T) {
// Create test data.
groupKey := test.RandPubKey(t)
internalKey, _ := test.RandKeyDesc(t)
mintingTx := wire.NewMsgTx(2)
mintingTx := wire.NewMsgTx(3)
mintingTx.AddTxOut(&wire.TxOut{Value: 1000})
blockHeight := uint32(100)

Expand Down
2 changes: 1 addition & 1 deletion tapgarden/custodian_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ func randAddrV2(h *custodianHarness, proofCourier url.URL,

func randWalletTx(addr *address.AddrWithKeyInfo) (int, *lndclient.Transaction) {
tx := &lndclient.Transaction{
Tx: wire.NewMsgTx(2),
Tx: wire.NewMsgTx(3),
Timestamp: time.Now(),
}
numInputs := rand.Intn(10) + 1
Expand Down
2 changes: 1 addition & 1 deletion tapgarden/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func NewMockWalletAnchor() *MockWalletAnchor {

// NewGenesisTx creates a funded genesis PSBT with the given fee rate.
func NewGenesisTx(t testing.TB, feeRate chainfee.SatPerKWeight) psbt.Packet {
txTemplate := wire.NewMsgTx(2)
txTemplate := wire.NewMsgTx(3)
txTemplate.AddTxOut(tapsend.CreateDummyOutput())
genesisPkt, err := psbt.NewFromUnsignedTx(txTemplate)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion tapgarden/planter.go
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ func unfundedAnchorPsbt(preCommitmentTxOut fn.Option[wire.TxOut]) (psbt.Packet,
var zero psbt.Packet

// Construct a template transaction for our minting anchor transaction.
txTemplate := wire.NewMsgTx(2)
txTemplate := wire.NewMsgTx(3)

// Add one output to anchor all assets which are being minted.
txTemplate.AddTxOut(tapsend.CreateDummyOutput())
Expand Down
2 changes: 1 addition & 1 deletion tapgarden/re-org_watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func newReOrgWatcherHarness(t *testing.T) *reOrgWatcherHarness {
}

func makeTx() *wire.MsgTx {
anchorTx := wire.NewMsgTx(2)
anchorTx := wire.NewMsgTx(3)
anchorTx.TxOut = []*wire.TxOut{{
PkScript: test.RandBytes(32),
Value: 100,
Expand Down
2 changes: 1 addition & 1 deletion tappsbt/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type encoderMapping struct {
// error if the encoding fails.
func (p *VPacket) EncodeAsPsbt() (*psbt.Packet, error) {
unsignedTx := &wire.MsgTx{
Version: 2,
Version: 3,
TxIn: make([]*wire.TxIn, len(p.Inputs)),
TxOut: make([]*wire.TxOut, len(p.Outputs)),
}
Expand Down
Loading
Loading