itest+lntest: stop using pointer to chainhash.Hash

This commit fixes the methods used in `lntest` so they stop using
pointers to chainhash.
This commit is contained in:
yyforyongyu committed 2024-10-17 07:14:51 +08:00
1 parent af6b88a9f6
commit ed3cb26188
16 files changed
+99 -93

No files matched your search

+11 -10
View File
@@ -342,6 +342,7 @@ func (h *HarnessTest) SetupStandbyNodes() {
// above a good number of confirmations.
const totalTxes = 200
h.MineBlocksAndAssertNumTxes(numBlocksSendOutput, totalTxes)
h.MineBlocks(numBlocksSendOutput)
// Now we want to wait for the nodes to catch up.
h.WaitForBlockchainSync(h.Alice)
@@ -913,12 +914,12 @@ func (h *HarnessTest) validateNodeState(hn *node.HarnessNode) error {
// GetChanPointFundingTxid takes a channel point and converts it into a chain
// hash.
func (h *HarnessTest) GetChanPointFundingTxid(
cp *lnrpc.ChannelPoint) *chainhash.Hash {
cp *lnrpc.ChannelPoint) chainhash.Hash {
txid, err := lnrpc.GetChanPointFundingTxid(cp)
require.NoError(h, err, "unable to get txid")
return txid
return *txid
}
// OutPointFromChannelPoint creates an outpoint from a given channel point.
@@ -927,7 +928,7 @@ func (h *HarnessTest) OutPointFromChannelPoint(
txid := h.GetChanPointFundingTxid(cp)
return wire.OutPoint{
Hash: *txid,
Hash: txid,
Index: cp.OutputIndex,
}
}
@@ -1263,7 +1264,7 @@ func (h *HarnessTest) OpenChannelAssertErr(srcNode, destNode *node.HarnessNode,
// mempool.
func (h *HarnessTest) CloseChannelAssertPending(hn *node.HarnessNode,
cp *lnrpc.ChannelPoint,
force bool) (rpc.CloseChanClient, *chainhash.Hash) {
force bool) (rpc.CloseChanClient, chainhash.Hash) {
// Calls the rpc to close the channel.
closeReq := &lnrpc.CloseChannelRequest{
@@ -1306,9 +1307,9 @@ func (h *HarnessTest) CloseChannelAssertPending(hn *node.HarnessNode,
pendingClose.ClosePending.Txid)
// Assert the closing tx is in the mempool.
h.miner.AssertTxInMempool(closeTxid)
h.miner.AssertTxInMempool(*closeTxid)
return stream, closeTxid
return stream, *closeTxid
}
// CloseChannel attempts to coop close a non-anchored channel identified by the
@@ -1321,7 +1322,7 @@ func (h *HarnessTest) CloseChannelAssertPending(hn *node.HarnessNode,
// 5. the node reports zero waiting close channels.
// 6. the node receives a topology update regarding the channel close.
func (h *HarnessTest) CloseChannel(hn *node.HarnessNode,
cp *lnrpc.ChannelPoint) *chainhash.Hash {
cp *lnrpc.ChannelPoint) chainhash.Hash {
stream, _ := h.CloseChannelAssertPending(hn, cp, false)
@@ -1340,7 +1341,7 @@ func (h *HarnessTest) CloseChannel(hn *node.HarnessNode,
// 7. mine DefaultCSV-1 blocks.
// 8. the node reports zero pending force close channels.
func (h *HarnessTest) ForceCloseChannel(hn *node.HarnessNode,
cp *lnrpc.ChannelPoint) *chainhash.Hash {
cp *lnrpc.ChannelPoint) chainhash.Hash {
stream, _ := h.CloseChannelAssertPending(hn, cp, true)
@@ -1902,7 +1903,7 @@ func (h *HarnessTest) CalculateTxFee(tx *wire.MsgTx) btcutil.Amount {
var balance btcutil.Amount
for _, in := range tx.TxIn {
parentHash := in.PreviousOutPoint.Hash
rawTx := h.miner.GetRawTransaction(&parentHash)
rawTx := h.miner.GetRawTransaction(parentHash)
parent := rawTx.MsgTx()
value := parent.TxOut[in.PreviousOutPoint.Index].Value
@@ -2151,7 +2152,7 @@ func (h *HarnessTest) ReceiveChannelEvent(
// GetOutputIndex returns the output index of the given address in the given
// transaction.
func (h *HarnessTest) GetOutputIndex(txid *chainhash.Hash, addr string) int {
func (h *HarnessTest) GetOutputIndex(txid chainhash.Hash, addr string) int {
// We'll then extract the raw transaction from the mempool in order to
// determine the index of the p2tr output.
tx := h.miner.GetRawTransaction(txid)
+4 -4
View File
@@ -534,7 +534,7 @@ func (h *HarnessTest) AssertTopologyChannelClosed(hn *node.HarnessNode,
// by consuming a message from the passed close channel stream. Returns the
// closing txid if found.
func (h HarnessTest) WaitForChannelCloseEvent(
stream rpc.CloseChanClient) *chainhash.Hash {
stream rpc.CloseChanClient) chainhash.Hash {
// Consume one event.
event, err := h.ReceiveCloseChannelUpdate(stream)
@@ -548,7 +548,7 @@ func (h HarnessTest) WaitForChannelCloseEvent(
require.NoErrorf(h, err, "wrong format found in closing txid: %v",
resp.ChanClose.ClosingTxid)
return txid
return *txid
}
// AssertNumWaitingClose checks that a PendingChannels response from the node
@@ -634,7 +634,7 @@ func (h *HarnessTest) AssertNumPendingForceClose(hn *node.HarnessNode,
// - assert the node has seen the channel close update.
func (h *HarnessTest) AssertStreamChannelCoopClosed(hn *node.HarnessNode,
cp *lnrpc.ChannelPoint, anchors bool,
stream rpc.CloseChanClient) *chainhash.Hash {
stream rpc.CloseChanClient) chainhash.Hash {
// Assert the channel is waiting close.
resp := h.AssertChannelWaitingClose(hn, cp)
@@ -682,7 +682,7 @@ func (h *HarnessTest) AssertStreamChannelCoopClosed(hn *node.HarnessNode,
// confirmed.
func (h *HarnessTest) AssertStreamChannelForceClosed(hn *node.HarnessNode,
cp *lnrpc.ChannelPoint, anchorSweep bool,
stream rpc.CloseChanClient) *chainhash.Hash {
stream rpc.CloseChanClient) chainhash.Hash {
// Assert the channel is waiting close.
resp := h.AssertChannelWaitingClose(hn, cp)
+6 -6
View File
@@ -113,7 +113,7 @@ func (h *HarnessTest) MineBlocksAndAssertNumTxes(num uint32,
// Make sure the mempool has been updated.
for _, txid := range txids {
h.miner.AssertTxNotInMempool(*txid)
h.miner.AssertTxNotInMempool(txid)
}
// Finally, make sure all the active nodes are synced.
@@ -202,7 +202,7 @@ func (h *HarnessTest) mineTillForceCloseResolved(hn *node.HarnessNode) {
}
// AssertTxInMempool asserts a given transaction can be found in the mempool.
func (h *HarnessTest) AssertTxInMempool(txid *chainhash.Hash) *wire.MsgTx {
func (h *HarnessTest) AssertTxInMempool(txid chainhash.Hash) *wire.MsgTx {
return h.miner.AssertTxInMempool(txid)
}
@@ -219,7 +219,7 @@ func (h *HarnessTest) AssertTxNotInMempool(txid chainhash.Hash) *wire.MsgTx {
// AssertNumTxsInMempool polls until finding the desired number of transactions
// in the provided miner's mempool. It will assert if this number is not met
// after the given timeout.
func (h *HarnessTest) AssertNumTxsInMempool(n int) []*chainhash.Hash {
func (h *HarnessTest) AssertNumTxsInMempool(n int) []chainhash.Hash {
return h.miner.AssertNumTxsInMempool(n)
}
@@ -230,7 +230,7 @@ func (h *HarnessTest) AssertOutpointInMempool(op wire.OutPoint) *wire.MsgTx {
// AssertTxInBlock asserts that a given txid can be found in the passed block.
func (h *HarnessTest) AssertTxInBlock(block *wire.MsgBlock,
txid *chainhash.Hash) {
txid chainhash.Hash) {
h.miner.AssertTxInBlock(block, txid)
}
@@ -263,13 +263,13 @@ func (h *HarnessTest) DisconnectFromMiner(tempMiner *miner.HarnessMiner) {
// GetRawMempool makes a RPC call to the miner's GetRawMempool and
// asserts.
func (h *HarnessTest) GetRawMempool() []*chainhash.Hash {
func (h *HarnessTest) GetRawMempool() []chainhash.Hash {
return h.miner.GetRawMempool()
}
// GetRawTransaction makes a RPC call to the miner's GetRawTransaction and
// asserts.
func (h *HarnessTest) GetRawTransaction(txid *chainhash.Hash) *btcutil.Tx {
func (h *HarnessTest) GetRawTransaction(txid chainhash.Hash) *btcutil.Tx {
return h.miner.GetRawTransaction(txid)
}
+19 -14
View File
@@ -156,11 +156,16 @@ func (h *HarnessMiner) GetBestBlock() (*chainhash.Hash, int32) {
// GetRawMempool makes a RPC call to the miner's GetRawMempool and
// asserts.
func (h *HarnessMiner) GetRawMempool() []*chainhash.Hash {
func (h *HarnessMiner) GetRawMempool() []chainhash.Hash {
mempool, err := h.Client.GetRawMempool()
require.NoError(h, err, "unable to get mempool")
return mempool
txns := make([]chainhash.Hash, 0, len(mempool))
for _, txid := range mempool {
txns = append(txns, *txid)
}
return txns
}
// GenerateBlocks mine 'num' of blocks and returns them.
@@ -198,9 +203,9 @@ func (h *HarnessMiner) MineBlocks(num uint32) []*wire.MsgBlock {
// AssertNumTxsInMempool polls until finding the desired number of transactions
// in the provided miner's mempool. It will assert if this number is not met
// after the given timeout.
func (h *HarnessMiner) AssertNumTxsInMempool(n int) []*chainhash.Hash {
func (h *HarnessMiner) AssertNumTxsInMempool(n int) []chainhash.Hash {
var (
mem []*chainhash.Hash
mem []chainhash.Hash
err error
)
@@ -222,7 +227,7 @@ func (h *HarnessMiner) AssertNumTxsInMempool(n int) []*chainhash.Hash {
// AssertTxInBlock asserts that a given txid can be found in the passed block.
func (h *HarnessMiner) AssertTxInBlock(block *wire.MsgBlock,
txid *chainhash.Hash) {
txid chainhash.Hash) {
blockTxes := make([]chainhash.Hash, 0)
@@ -264,8 +269,8 @@ func (h *HarnessMiner) MineBlocksAndAssertNumTxes(num uint32,
// GetRawTransaction makes a RPC call to the miner's GetRawTransaction and
// asserts.
func (h *HarnessMiner) GetRawTransaction(txid *chainhash.Hash) *btcutil.Tx {
tx, err := h.Client.GetRawTransaction(txid)
func (h *HarnessMiner) GetRawTransaction(txid chainhash.Hash) *btcutil.Tx {
tx, err := h.Client.GetRawTransaction(&txid)
require.NoErrorf(h, err, "failed to get raw tx: %v", txid)
return tx
}
@@ -273,15 +278,15 @@ func (h *HarnessMiner) GetRawTransaction(txid *chainhash.Hash) *btcutil.Tx {
// GetRawTransactionVerbose makes a RPC call to the miner's
// GetRawTransactionVerbose and asserts.
func (h *HarnessMiner) GetRawTransactionVerbose(
txid *chainhash.Hash) *btcjson.TxRawResult {
txid chainhash.Hash) *btcjson.TxRawResult {
tx, err := h.Client.GetRawTransactionVerbose(txid)
tx, err := h.Client.GetRawTransactionVerbose(&txid)
require.NoErrorf(h, err, "failed to get raw tx verbose: %v", txid)
return tx
}
// AssertTxInMempool asserts a given transaction can be found in the mempool.
func (h *HarnessMiner) AssertTxInMempool(txid *chainhash.Hash) *wire.MsgTx {
func (h *HarnessMiner) AssertTxInMempool(txid chainhash.Hash) *wire.MsgTx {
err := wait.NoError(func() error {
// We require the RPC call to be succeeded and won't wait for
// it as it's an unexpected behavior.
@@ -291,8 +296,8 @@ func (h *HarnessMiner) AssertTxInMempool(txid *chainhash.Hash) *wire.MsgTx {
return fmt.Errorf("empty mempool")
}
isEqual := func(memTx *chainhash.Hash) bool {
return *memTx == *txid
isEqual := func(memTx chainhash.Hash) bool {
return memTx == txid
}
result := fn.Find(isEqual, mempool)
@@ -325,7 +330,7 @@ func (h *HarnessMiner) AssertTxNotInMempool(txid chainhash.Hash) *wire.MsgTx {
for _, memTx := range mempool {
// Check the values are equal.
if txid.IsEqual(memTx) {
if txid == memTx {
return fmt.Errorf("expect txid %v to be NOT "+
"found in mempool", txid)
}
@@ -418,7 +423,7 @@ func (h *HarnessMiner) AssertOutpointInMempool(op wire.OutPoint) *wire.MsgTx {
// found. For instance, the aggregation logic used in
// sweeping HTLC outputs will update the mempool by
// replacing the HTLC spending txes with a single one.
tx, err := h.Client.GetRawTransaction(txid)
tx, err := h.Client.GetRawTransaction(&txid)
if err != nil {
return err
}