Skip to content

Commit

Permalink
itest: test that the fed envoy reattempts mint proof push syncs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ffranr committed Nov 29, 2023
1 parent 2722552 commit cbf8d04
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
4 changes: 4 additions & 0 deletions itest/test_list_on_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ var testCases = []*testCase{
name: "universe pagination simple",
test: testUniversePaginationSimple,
},
{
name: "mint proof repeat fed sync attempt",
test: testMintProofRepeatFedSyncAttempt,
},
}

var optionalTestCases = []*testCase{
Expand Down
98 changes: 98 additions & 0 deletions itest/universe_federation_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package itest

import (
"context"
"time"

"github.com/lightninglabs/taproot-assets/taprpc/mintrpc"
unirpc "github.com/lightninglabs/taproot-assets/taprpc/universerpc"
"github.com/stretchr/testify/require"
)

// testMintProofRepeatFedSyncAttempt tests that the minting node will retry
// pushing the minting proofs to the federation server peer node, if the peer
// node is offline at the time of the initial sync attempt.
func testMintProofRepeatFedSyncAttempt(t *harnessTest) {
// Create a new minting node, without hooking it up to any existing
// Universe server. We will also set the sync ticker to 4 second, so
// that we can test that the proof push sync is retried and eventually
// succeeds after the fed server peer node reappears online.
syncTickerInterval := 4 * time.Second
mintingNode := setupTapdHarness(
t.t, t, t.lndHarness.Bob, nil,
func(params *tapdHarnessParams) {
params.fedSyncTickerInterval = &syncTickerInterval
},
)
defer func() {
require.NoError(t.t, mintingNode.stop(!*noDelete))
}()

// We'll use the main node as our federation universe server
// counterparty.
fedServerNode := t.tapd

// Keep a reference to the fed server node RPC host address, so that we
// can assert that it has not changed after the restart. This is
// important, because the minting node will be retrying the proof push
// to this address.
fedServerNodeRpcHost := fedServerNode.rpcHost()

// Register the fedServerNode as a federation universe server with the
// minting node.
ctxb := context.Background()
ctxt, cancel := context.WithTimeout(ctxb, defaultWaitTimeout)
defer cancel()

_, err := mintingNode.AddFederationServer(
ctxt, &unirpc.AddFederationServerRequest{
Servers: []*unirpc.UniverseFederationServer{
{
Host: fedServerNodeRpcHost,
},
},
},
)
require.NoError(t.t, err)

// Assert that the fed server node has not seen any asset proofs.
AssertUniverseStats(t.t, fedServerNode, 0, 0, 0)

// Stop the federation server peer node, so that it does not receive the
// newly minted asset proofs immediately upon minting.
t.Logf("Stopping fed server tapd node")
require.NoError(t.t, fedServerNode.stop(*noDelete))

// Now that federation peer node is inactive, we'll mint some assets.
t.Logf("Minting assets on minting node")
rpcAssets := MintAssetsConfirmBatch(
t.t, t.lndHarness.Miner.Client, mintingNode,
[]*mintrpc.MintAssetRequest{
simpleAssets[0], issuableAssets[0],
},
)
require.Len(t.t, rpcAssets, 2)

t.lndHarness.MineBlocks(7)

// Wait for the minting node to attempt (and fail) to push the minting
// proofs to the fed peer node. We wait some multiple of the sync ticker
// interval to ensure that the minting node has had time to retry the
// proof push sync.
time.Sleep(syncTickerInterval * 2)

// Start the federation server peer node. The federation envoy component
// of our minting node should currently be retrying the proof push sync
// with the federation peer at each tick.
t.Logf("Start (previously stopped) fed server tapd node")
err = fedServerNode.start(false)
require.NoError(t.t, err)

// Ensure that the federation server node RPC host address has not
// changed after the restart. If it has, then the minting node will be
// retrying the proof push to the wrong address.
require.Equal(t.t, fedServerNodeRpcHost, fedServerNode.rpcHost())

t.Logf("Assert that fed peer node has seen the asset minting proofs")
AssertUniverseStats(t.t, fedServerNode, 2, 2, 1)
}

0 comments on commit cbf8d04

Please sign in to comment.