Skip to content

Commit 01782da

Browse files
authored
test: test P2P catchup (#1614)
<!-- Please read and fill out this form before submitting your PR. Please make sure you have reviewed our contributors guide before submitting your first PR. --> ## Overview Resolves #1213. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Tests** - Added `doTestCatchup` function to ensure the system can catch up with a specified number of blocks during integration tests. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 1456586 commit 01782da

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

node/full_node_integration_test.go

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,99 @@ func doTestMaxPending(maxPending uint64, t *testing.T) {
705705
require.NoError(waitForAtLeastNBlocks(seq, int(maxPending+1), Store))
706706
}
707707

708+
func TestCatchUp(t *testing.T) {
709+
cases := []struct {
710+
name string
711+
n int
712+
}{
713+
{
714+
name: "small catch-up",
715+
n: 200,
716+
},
717+
{
718+
name: "large catch-up",
719+
n: 1000,
720+
},
721+
}
722+
723+
for _, tc := range cases {
724+
t.Run(tc.name, func(t *testing.T) {
725+
doTestCatchup(t, tc.n)
726+
})
727+
}
728+
}
729+
730+
func doTestCatchup(t *testing.T, n int) {
731+
//t.Parallel()
732+
require := require.New(t)
733+
734+
const (
735+
timeout = 300 * time.Second
736+
clientNodes = 2
737+
blockTime = 10 * time.Millisecond
738+
daBlockTime = 20 * time.Millisecond
739+
)
740+
ctx, cancel := context.WithTimeout(context.Background(), timeout)
741+
defer cancel()
742+
nodes, _ := createNodes(
743+
ctx,
744+
context.Background(),
745+
clientNodes,
746+
config.BlockManagerConfig{
747+
DABlockTime: daBlockTime,
748+
BlockTime: blockTime,
749+
},
750+
types.TestChainID,
751+
false,
752+
t,
753+
)
754+
seq := nodes[0]
755+
full := nodes[1]
756+
mockDA := &mocks.DA{}
757+
758+
// make sure mock DA is not accepting any submissions to force P2P only sync
759+
mockDA.On("MaxBlobSize", mock.Anything).Return(uint64(123456789), nil)
760+
daError := errors.New("DA not available")
761+
mockDA.On("Submit", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, daError)
762+
mockDA.On("GetIDs", mock.Anything, mock.Anything, mock.Anything).Return(nil, daError)
763+
764+
dalc := da.NewDAClient(mockDA, 1234, 5678, goDA.Namespace(MockDANamespace), log.NewNopLogger())
765+
require.NotNil(dalc)
766+
767+
for _, node := range nodes {
768+
node.dalc = dalc
769+
node.blockManager.SetDALC(dalc)
770+
}
771+
772+
// start sequencer
773+
startNodeWithCleanup(t, seq)
774+
775+
// submit random transactions
776+
ch := make(chan *struct{})
777+
778+
// spam transactions until n blocks are produced
779+
txCtx := context.WithoutCancel(ctx)
780+
go func() {
781+
for {
782+
select {
783+
case <-ch:
784+
return
785+
default:
786+
for i := uint(1); i < 10; i++ {
787+
_, _ = seq.client.BroadcastTxAsync(txCtx, types.GetRandomBytes(10*i))
788+
}
789+
_, _ = seq.client.BroadcastTxCommit(txCtx, types.GetRandomBytes(1000))
790+
}
791+
}
792+
}()
793+
794+
require.NoError(waitForAtLeastNBlocks(seq, n, Store))
795+
ch <- nil
796+
797+
startNodeWithCleanup(t, full)
798+
require.NoError(waitForAtLeastNBlocks(full, n, Store))
799+
}
800+
708801
func testSingleAggregatorSingleFullNode(t *testing.T, source Source) {
709802
require := require.New(t)
710803

0 commit comments

Comments
 (0)