|
| 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 | + }, |
| 26 | + ) |
| 27 | + defer func() { |
| 28 | + require.NoError(t.t, mintingNode.stop(!*noDelete)) |
| 29 | + }() |
| 30 | + |
| 31 | + // We'll use the main node as our federation universe server |
| 32 | + // counterparty. |
| 33 | + fedServerNode := t.tapd |
| 34 | + |
| 35 | + // Keep a reference to the fed server node RPC host address, so that we |
| 36 | + // can assert that it has not changed after the restart. This is |
| 37 | + // important, because the minting node will be retrying the proof push |
| 38 | + // to this address. |
| 39 | + fedServerNodeRpcHost := fedServerNode.rpcHost() |
| 40 | + |
| 41 | + // Register the fedServerNode as a federation universe server with the |
| 42 | + // minting node. |
| 43 | + ctxb := context.Background() |
| 44 | + ctxt, cancel := context.WithTimeout(ctxb, defaultWaitTimeout) |
| 45 | + defer cancel() |
| 46 | + |
| 47 | + _, err := mintingNode.AddFederationServer( |
| 48 | + ctxt, &unirpc.AddFederationServerRequest{ |
| 49 | + Servers: []*unirpc.UniverseFederationServer{ |
| 50 | + { |
| 51 | + Host: fedServerNodeRpcHost, |
| 52 | + }, |
| 53 | + }, |
| 54 | + }, |
| 55 | + ) |
| 56 | + require.NoError(t.t, err) |
| 57 | + |
| 58 | + // Assert that the fed server node has not seen any asset proofs. |
| 59 | + AssertUniverseStats(t.t, fedServerNode, 0, 0, 0) |
| 60 | + |
| 61 | + // Stop the federation server peer node, so that it does not receive the |
| 62 | + // newly minted asset proofs immediately upon minting. |
| 63 | + t.Logf("Stopping fed server tapd node") |
| 64 | + require.NoError(t.t, fedServerNode.stop(*noDelete)) |
| 65 | + |
| 66 | + // Now that federation peer node is inactive, we'll mint some assets. |
| 67 | + t.Logf("Minting assets on minting node") |
| 68 | + rpcAssets := MintAssetsConfirmBatch( |
| 69 | + t.t, t.lndHarness.Miner.Client, mintingNode, |
| 70 | + []*mintrpc.MintAssetRequest{ |
| 71 | + simpleAssets[0], issuableAssets[0], |
| 72 | + }, |
| 73 | + ) |
| 74 | + require.Len(t.t, rpcAssets, 2) |
| 75 | + |
| 76 | + t.lndHarness.MineBlocks(7) |
| 77 | + |
| 78 | + // Wait for the minting node to attempt (and fail) to push the minting |
| 79 | + // proofs to the fed peer node. We wait some multiple of the sync ticker |
| 80 | + // interval to ensure that the minting node has had time to retry the |
| 81 | + // proof push sync. |
| 82 | + time.Sleep(syncTickerInterval * 2) |
| 83 | + |
| 84 | + // Start the federation server peer node. The federation envoy component |
| 85 | + // of our minting node should currently be retrying the proof push sync |
| 86 | + // with the federation peer at each tick. |
| 87 | + t.Logf("Start (previously stopped) fed server tapd node") |
| 88 | + err = fedServerNode.start(false) |
| 89 | + require.NoError(t.t, err) |
| 90 | + |
| 91 | + // Ensure that the federation server node RPC host address has not |
| 92 | + // changed after the restart. If it has, then the minting node will be |
| 93 | + // retrying the proof push to the wrong address. |
| 94 | + require.Equal(t.t, fedServerNodeRpcHost, fedServerNode.rpcHost()) |
| 95 | + |
| 96 | + t.Logf("Assert that fed peer node has seen the asset minting proofs") |
| 97 | + AssertUniverseStats(t.t, fedServerNode, 2, 2, 1) |
| 98 | +} |
0 commit comments