Skip to content

Commit 9fbf274

Browse files
committed
itest: test that the fed envoy reattempts mint proof push syncs
This commit adds an integration test which helps to ensure that a minting node will retry pushing a minting proof to a federation server peer node, in the event that that peer node failed to receive the proof at the time of the initial sync attempt.
1 parent 75f93b2 commit 9fbf274

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed

itest/test_list_on_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ var testCases = []*testCase{
195195
name: "universe pagination simple",
196196
test: testUniversePaginationSimple,
197197
},
198+
{
199+
name: "mint proof repeat fed sync attempt",
200+
test: testMintProofRepeatFedSyncAttempt,
201+
},
198202
}
199203

200204
var optionalTestCases = []*testCase{

itest/universe_federation_test.go

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package itest
2+
3+
import (
4+
"context"
5+
"time"
6+
7+
"github.com/lightninglabs/taproot-assets/taprpc/mintrpc"
8+
unirpc "github.com/lightninglabs/taproot-assets/taprpc/universerpc"
9+
"github.com/stretchr/testify/require"
10+
)
11+
12+
// testMintProofRepeatFedSyncAttempt tests that the minting node will retry
13+
// pushing the minting proofs to the federation server peer node, if the peer
14+
// node is offline at the time of the initial sync attempt.
15+
func testMintProofRepeatFedSyncAttempt(t *harnessTest) {
16+
// Create a new minting node, without hooking it up to any existing
17+
// Universe server. We will also set the sync ticker to 4 second, so
18+
// that we can test that the proof push sync is retried and eventually
19+
// succeeds after the fed server peer node reappears online.
20+
syncTickerInterval := 4 * time.Second
21+
mintingNode := setupTapdHarness(
22+
t.t, t, t.lndHarness.Bob, nil,
23+
func(params *tapdHarnessParams) {
24+
params.fedSyncTickerInterval = &syncTickerInterval
25+
params.noDefaultUniverseSync = true
26+
},
27+
)
28+
defer func() {
29+
require.NoError(t.t, mintingNode.stop(!*noDelete))
30+
}()
31+
32+
// We'll use the main node as our federation universe server
33+
// counterparty.
34+
fedServerNode := t.tapd
35+
36+
// Keep a reference to the fed server node RPC host address, so that we
37+
// can assert that it has not changed after the restart. This is
38+
// important, because the minting node will be retrying the proof push
39+
// to this address.
40+
fedServerNodeRpcHost := fedServerNode.rpcHost()
41+
42+
// Register the fedServerNode as a federation universe server with the
43+
// minting node.
44+
ctxb := context.Background()
45+
ctxt, cancel := context.WithTimeout(ctxb, defaultWaitTimeout)
46+
defer cancel()
47+
48+
_, err := mintingNode.AddFederationServer(
49+
ctxt, &unirpc.AddFederationServerRequest{
50+
Servers: []*unirpc.UniverseFederationServer{
51+
{
52+
Host: fedServerNodeRpcHost,
53+
},
54+
},
55+
},
56+
)
57+
require.NoError(t.t, err)
58+
59+
// Assert that the fed server node has not seen any asset proofs.
60+
AssertUniverseStats(t.t, fedServerNode, 0, 0, 0)
61+
62+
// Stop the federation server peer node, so that it does not receive the
63+
// newly minted asset proofs immediately upon minting.
64+
t.Logf("Stopping fed server tapd node")
65+
require.NoError(t.t, fedServerNode.stop(false))
66+
67+
// Now that federation peer node is inactive, we'll mint some assets.
68+
t.Logf("Minting assets on minting node")
69+
rpcAssets := MintAssetsConfirmBatch(
70+
t.t, t.lndHarness.Miner.Client, mintingNode,
71+
[]*mintrpc.MintAssetRequest{
72+
simpleAssets[0], issuableAssets[0],
73+
},
74+
)
75+
require.Len(t.t, rpcAssets, 2)
76+
77+
t.lndHarness.MineBlocks(7)
78+
79+
// Wait for the minting node to attempt (and fail) to push the minting
80+
// proofs to the fed peer node. We wait some multiple of the sync ticker
81+
// interval to ensure that the minting node has had time to retry the
82+
// proof push sync.
83+
time.Sleep(syncTickerInterval * 2)
84+
85+
// Start the federation server peer node. The federation envoy component
86+
// of our minting node should currently be retrying the proof push sync
87+
// with the federation peer at each tick.
88+
t.Logf("Start (previously stopped) fed server tapd node")
89+
err = fedServerNode.start(false)
90+
require.NoError(t.t, err)
91+
92+
// Ensure that the federation server node RPC host address has not
93+
// changed after the restart. If it has, then the minting node will be
94+
// retrying the proof push to the wrong address.
95+
require.Equal(t.t, fedServerNodeRpcHost, fedServerNode.rpcHost())
96+
97+
t.Logf("Assert that fed peer node has seen the asset minting proofs")
98+
AssertUniverseStats(t.t, fedServerNode, 2, 2, 1)
99+
}

0 commit comments

Comments
 (0)