Skip to content

Commit 5cba47d

Browse files
authored
Merge pull request #9227 from yyforyongyu/yy-blockbeat-itest
Beat [5/4]: fix itests for `blockbeat`
2 parents 2c1399f + b4ab36c commit 5cba47d

30 files changed

+4401
-3761
lines changed

chainio/consumer.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (b *BeatConsumer) ProcessBlock(beat Blockbeat) error {
7979
// `beat.NotifyBlockProcessed` to send the error back here.
8080
select {
8181
case err := <-b.errChan:
82-
beat.logger().Debugf("[%s] processed beat: err=%v", b.name, err)
82+
beat.logger().Tracef("[%s] processed beat: err=%v", b.name, err)
8383

8484
return err
8585

@@ -99,11 +99,11 @@ func (b *BeatConsumer) ProcessBlock(beat Blockbeat) error {
9999
// processing the block.
100100
func (b *BeatConsumer) NotifyBlockProcessed(beat Blockbeat, err error) {
101101
// Update the current height.
102-
beat.logger().Debugf("[%s]: notifying beat processed", b.name)
102+
beat.logger().Tracef("[%s]: notifying beat processed", b.name)
103103

104104
select {
105105
case b.errChan <- err:
106-
beat.logger().Debugf("[%s]: notified beat processed, err=%v",
106+
beat.logger().Tracef("[%s]: notified beat processed, err=%v",
107107
b.name, err)
108108

109109
case <-b.quit:

chainio/dispatcher.go

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/btcsuite/btclog/v2"
1111
"github.com/lightningnetwork/lnd/chainntnfs"
12+
"github.com/lightningnetwork/lnd/lnutils"
1213
"golang.org/x/sync/errgroup"
1314
)
1415

@@ -136,6 +137,10 @@ func (b *BlockbeatDispatcher) dispatchBlocks(
136137
return
137138
}
138139

140+
// Log a separator so it's easier to identify when a
141+
// new block arrives for subsystems.
142+
clog.Debugf("%v", lnutils.NewSeparatorClosure())
143+
139144
clog.Infof("Received new block %v at height %d, "+
140145
"notifying consumers...", blockEpoch.Hash,
141146
blockEpoch.Height)

contractcourt/channel_arbitrator.go

+15-9
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ func (c *ChannelArbitrator) Start(state *chanArbStartState,
479479
}
480480
}
481481

482-
log.Debugf("Starting ChannelArbitrator(%v), htlc_set=%v, state=%v",
482+
log.Tracef("Starting ChannelArbitrator(%v), htlc_set=%v, state=%v",
483483
c.cfg.ChanPoint, lnutils.SpewLogClosure(c.activeHTLCs),
484484
state.currentState)
485485

@@ -2618,14 +2618,14 @@ func (c *ChannelArbitrator) replaceResolver(oldResolver,
26182618
func (c *ChannelArbitrator) resolveContract(currentContract ContractResolver) {
26192619
defer c.wg.Done()
26202620

2621-
log.Debugf("ChannelArbitrator(%v): attempting to resolve %T",
2621+
log.Tracef("ChannelArbitrator(%v): attempting to resolve %T",
26222622
c.cfg.ChanPoint, currentContract)
26232623

26242624
// Until the contract is fully resolved, we'll continue to iteratively
26252625
// resolve the contract one step at a time.
26262626
for !currentContract.IsResolved() {
2627-
log.Debugf("ChannelArbitrator(%v): contract %T not yet resolved",
2628-
c.cfg.ChanPoint, currentContract)
2627+
log.Tracef("ChannelArbitrator(%v): contract %T not yet "+
2628+
"resolved", c.cfg.ChanPoint, currentContract)
26292629

26302630
select {
26312631

@@ -2994,12 +2994,18 @@ func (c *ChannelArbitrator) handleBlockbeat(beat chainio.Blockbeat) error {
29942994

29952995
// If the state is StateContractClosed, StateWaitingFullResolution, or
29962996
// StateFullyResolved, there's no need to read the close event channel
2997-
// and launch the resolvers since the arbitrator can only get to this
2998-
// state after processing a previous close event and launched all its
2999-
// resolvers.
2997+
// since the arbitrator can only get to this state after processing a
2998+
// previous close event and launched all its resolvers.
30002999
if c.state.IsContractClosed() {
3001-
log.Infof("ChannelArbitrator(%v): skipping launching "+
3002-
"resolvers in state=%v", c.cfg.ChanPoint, c.state)
3000+
log.Infof("ChannelArbitrator(%v): skipping reading close "+
3001+
"events in state=%v", c.cfg.ChanPoint, c.state)
3002+
3003+
// Launch all active resolvers when a new blockbeat is
3004+
// received, even when the contract is closed, we still need
3005+
// this as the resolvers may transform into new ones. For
3006+
// already launched resolvers this will be NOOP as they track
3007+
// their own `launched` states.
3008+
c.launchResolvers()
30033009

30043010
return nil
30053011
}

contractcourt/htlc_outgoing_contest_resolver.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,8 @@ func (h *htlcOutgoingContestResolver) Resolve() (ContractResolver, error) {
165165
if newHeight >= expiry-1 {
166166
h.log.Infof("HTLC about to expire "+
167167
"(height=%v, expiry=%v), transforming "+
168-
"into timeout resolver", h,
169-
h.htlcResolution.ClaimOutpoint,
170-
newHeight, h.htlcResolution.Expiry)
168+
"into timeout resolver", newHeight,
169+
h.htlcResolution.Expiry)
171170

172171
return h.htlcTimeoutResolver, nil
173172
}

itest/list_on_test.go

+13-35
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ var allTestCases = []*lntest.TestCase{
1313
Name: "basic funding flow",
1414
TestFunc: testBasicChannelFunding,
1515
},
16-
{
17-
Name: "multi hop receiver chain claim",
18-
TestFunc: testMultiHopReceiverChainClaim,
19-
},
2016
{
2117
Name: "external channel funding",
2218
TestFunc: testExternalFundingChanPoint,
@@ -153,18 +149,6 @@ var allTestCases = []*lntest.TestCase{
153149
Name: "addpeer config",
154150
TestFunc: testAddPeerConfig,
155151
},
156-
{
157-
Name: "multi hop htlc local timeout",
158-
TestFunc: testMultiHopHtlcLocalTimeout,
159-
},
160-
{
161-
Name: "multi hop local force close on-chain htlc timeout",
162-
TestFunc: testMultiHopLocalForceCloseOnChainHtlcTimeout,
163-
},
164-
{
165-
Name: "multi hop remote force close on-chain htlc timeout",
166-
TestFunc: testMultiHopRemoteForceCloseOnChainHtlcTimeout,
167-
},
168152
{
169153
Name: "private channel update policy",
170154
TestFunc: testUpdateChannelPolicyForPrivateChannel,
@@ -226,11 +210,15 @@ var allTestCases = []*lntest.TestCase{
226210
TestFunc: testChannelUnsettledBalance,
227211
},
228212
{
229-
Name: "channel force closure",
230-
TestFunc: testChannelForceClosure,
213+
Name: "channel force closure anchor",
214+
TestFunc: testChannelForceClosureAnchor,
215+
},
216+
{
217+
Name: "channel force closure simple taproot",
218+
TestFunc: testChannelForceClosureSimpleTaproot,
231219
},
232220
{
233-
Name: "failing link",
221+
Name: "failing channel",
234222
TestFunc: testFailingChannel,
235223
},
236224
{
@@ -313,18 +301,6 @@ var allTestCases = []*lntest.TestCase{
313301
Name: "REST API",
314302
TestFunc: testRestAPI,
315303
},
316-
{
317-
Name: "multi hop htlc local chain claim",
318-
TestFunc: testMultiHopHtlcLocalChainClaim,
319-
},
320-
{
321-
Name: "multi hop htlc remote chain claim",
322-
TestFunc: testMultiHopHtlcRemoteChainClaim,
323-
},
324-
{
325-
Name: "multi hop htlc aggregation",
326-
TestFunc: testMultiHopHtlcAggregation,
327-
},
328304
{
329305
Name: "revoked uncooperative close retribution",
330306
TestFunc: testRevokedCloseRetribution,
@@ -574,10 +550,6 @@ var allTestCases = []*lntest.TestCase{
574550
Name: "lookup htlc resolution",
575551
TestFunc: testLookupHtlcResolution,
576552
},
577-
{
578-
Name: "watchtower",
579-
TestFunc: testWatchtower,
580-
},
581553
{
582554
Name: "channel fundmax",
583555
TestFunc: testChannelFundMax,
@@ -715,3 +687,9 @@ var allTestCases = []*lntest.TestCase{
715687
TestFunc: testQuiescence,
716688
},
717689
}
690+
691+
func init() {
692+
// Register subtests.
693+
allTestCases = append(allTestCases, multiHopForceCloseTestCases...)
694+
allTestCases = append(allTestCases, watchtowerTestCases...)
695+
}

itest/lnd_channel_backup_test.go

+14-18
Original file line numberDiff line numberDiff line change
@@ -637,8 +637,8 @@ func runChanRestoreScenarioCommitTypes(ht *lntest.HarnessTest,
637637
minerHeight := ht.CurrentHeight()
638638
thawHeight := minerHeight + thawHeightDelta
639639

640-
fundingShim, _ = deriveFundingShim(
641-
ht, dave, carol, crs.params.Amt, thawHeight, true, ct,
640+
fundingShim, _ = ht.DeriveFundingShim(
641+
dave, carol, crs.params.Amt, thawHeight, true, ct,
642642
)
643643
crs.params.FundingShim = fundingShim
644644
}
@@ -1320,12 +1320,20 @@ func testDataLossProtection(ht *lntest.HarnessTest) {
13201320
// information Dave needs to sweep his funds.
13211321
require.NoError(ht, restartDave(), "unable to restart Eve")
13221322

1323+
// Mine a block to trigger Dave's chain watcher to process Carol's sweep
1324+
// tx.
1325+
//
1326+
// TODO(yy): remove this block once the blockbeat starts remembering
1327+
// its last processed block and can handle looking for spends in the
1328+
// past blocks.
1329+
ht.MineEmptyBlocks(1)
1330+
1331+
// Make sure Dave still has the pending force close channel.
1332+
ht.AssertNumPendingForceClose(dave, 1)
1333+
13231334
// Dave should have a pending sweep.
13241335
ht.AssertNumPendingSweeps(dave, 1)
13251336

1326-
// Mine a block to trigger the sweep.
1327-
ht.MineBlocks(1)
1328-
13291337
// Dave should sweep his funds.
13301338
ht.AssertNumTxsInMempool(1)
13311339

@@ -1482,7 +1490,6 @@ func assertTimeLockSwept(ht *lntest.HarnessTest, carol, dave *node.HarnessNode,
14821490
expectedTxes := 1
14831491

14841492
// Mine a block to trigger the sweeps.
1485-
ht.MineBlocks(1)
14861493
ht.AssertNumTxsInMempool(expectedTxes)
14871494

14881495
// Carol should consider the channel pending force close (since she is
@@ -1512,7 +1519,7 @@ func assertTimeLockSwept(ht *lntest.HarnessTest, carol, dave *node.HarnessNode,
15121519
// The commit sweep resolver publishes the sweep tx at defaultCSV-1 and
15131520
// we already mined one block after the commitment was published, and
15141521
// one block to trigger Carol's sweeps, so take that into account.
1515-
ht.MineEmptyBlocks(1)
1522+
ht.MineBlocks(2)
15161523
ht.AssertNumPendingSweeps(dave, 2)
15171524

15181525
// Mine a block to trigger the sweeps.
@@ -1615,8 +1622,6 @@ func assertDLPExecuted(ht *lntest.HarnessTest,
16151622
// output and the other for her anchor.
16161623
ht.AssertNumPendingSweeps(carol, 2)
16171624

1618-
// Mine a block to trigger the sweep.
1619-
ht.MineEmptyBlocks(1)
16201625
ht.MineBlocksAndAssertNumTxes(1, 1)
16211626

16221627
// Now the channel should be fully closed also from Carol's POV.
@@ -1635,8 +1640,6 @@ func assertDLPExecuted(ht *lntest.HarnessTest,
16351640
// output and the other for his anchor.
16361641
ht.AssertNumPendingSweeps(dave, 2)
16371642

1638-
// Mine a block to trigger the sweep.
1639-
ht.MineEmptyBlocks(1)
16401643
ht.MineBlocksAndAssertNumTxes(1, 1)
16411644

16421645
// Now Dave should consider the channel fully closed.
@@ -1652,10 +1655,6 @@ func assertDLPExecuted(ht *lntest.HarnessTest,
16521655
ht.AssertNumPendingSweeps(dave, 1)
16531656
}
16541657

1655-
// Mine one block to trigger the sweeper to sweep.
1656-
ht.MineEmptyBlocks(1)
1657-
blocksMined++
1658-
16591658
// Expect one tx - the commitment sweep from Dave. For anchor
16601659
// channels, we expect the two anchor sweeping txns to be
16611660
// failed due they are uneconomical.
@@ -1673,9 +1672,6 @@ func assertDLPExecuted(ht *lntest.HarnessTest,
16731672
// commitmment was published, so take that into account.
16741673
ht.MineEmptyBlocks(int(defaultCSV - blocksMined))
16751674

1676-
// Mine one block to trigger the sweeper to sweep.
1677-
ht.MineEmptyBlocks(1)
1678-
16791675
// Carol should have two pending sweeps:
16801676
// 1. her commit output.
16811677
// 2. her anchor output, if this is anchor channel.

itest/lnd_channel_balance_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func testChannelUnsettledBalance(ht *lntest.HarnessTest) {
156156
TimeoutSeconds: 60,
157157
FeeLimitMsat: noFeeLimitMsat,
158158
}
159-
alice.RPC.SendPayment(req)
159+
ht.SendPaymentAssertInflight(alice, req)
160160
}()
161161
}
162162

0 commit comments

Comments
 (0)