From d1adf378df8679969c70933fb1a2e74b04ac46a6 Mon Sep 17 00:00:00 2001 From: Dylan Tinianov Date: Thu, 30 Jan 2025 12:18:09 -0500 Subject: [PATCH] Fix naming --- multinode/rpc_client_base.go | 8 ++++---- multinode/rpc_client_base_test.go | 22 +++++++++++----------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/multinode/rpc_client_base.go b/multinode/rpc_client_base.go index cd411af..b4a886c 100644 --- a/multinode/rpc_client_base.go +++ b/multinode/rpc_client_base.go @@ -64,7 +64,7 @@ func NewRPCClientBase[HEAD Head]( } } -func (m *RPCClientBase[HEAD]) LenSubs() int { +func (m *RPCClientBase[HEAD]) lenSubs() int { m.subsMu.RLock() defer m.subsMu.RUnlock() return len(m.subs) @@ -72,7 +72,7 @@ func (m *RPCClientBase[HEAD]) LenSubs() int { // RegisterSub adds the sub to the RPCClientBase list and returns a managed sub which is removed on unsubscribe func (m *RPCClientBase[HEAD]) RegisterSub(sub Subscription, lifeCycleCh chan struct{}) (*ManagedSubscription, error) { - // ensure that the `sub` belongs to current life cycle of the `rpcMultiNodeAdapter` and it should not be killed due to + // ensure that the `sub` belongs to current life cycle of the `RPCClientBase` and it should not be killed due to // previous `DisconnectAll` call. select { case <-lifeCycleCh: @@ -200,7 +200,7 @@ func (m *RPCClientBase[HEAD]) OnNewHead(ctx context.Context, requestCh <-chan st m.highestUserObservations.TotalDifficulty = MaxTotalDifficulty(m.highestUserObservations.TotalDifficulty, totalDifficulty) } select { - case <-requestCh: // no need to update latestChainInfo, as rpcMultiNodeAdapter already started new life cycle + case <-requestCh: // no need to update latestChainInfo, as RPCClientBase already started new life cycle return default: m.latestChainInfo.BlockNumber = blockNumber @@ -219,7 +219,7 @@ func (m *RPCClientBase[HEAD]) OnNewFinalizedHead(ctx context.Context, requestCh m.highestUserObservations.FinalizedBlockNumber = max(m.highestUserObservations.FinalizedBlockNumber, head.BlockNumber()) } select { - case <-requestCh: // no need to update latestChainInfo, as rpcMultiNodeAdapter already started new life cycle + case <-requestCh: // no need to update latestChainInfo, as RPCClientBase already started new life cycle return default: m.latestChainInfo.FinalizedBlockNumber = head.BlockNumber() diff --git a/multinode/rpc_client_base_test.go b/multinode/rpc_client_base_test.go index 1da6f7a..25afd4d 100644 --- a/multinode/rpc_client_base_test.go +++ b/multinode/rpc_client_base_test.go @@ -216,27 +216,27 @@ func TestAdapter_HeadSubscriptions(t *testing.T) { rpc := newTestRPC(t) _, sub1, err := rpc.SubscribeToHeads(tests.Context(t)) require.NoError(t, err) - require.Equal(t, 1, rpc.LenSubs()) + require.Equal(t, 1, rpc.lenSubs()) _, sub2, err := rpc.SubscribeToFinalizedHeads(tests.Context(t)) require.NoError(t, err) - require.Equal(t, 2, rpc.LenSubs()) + require.Equal(t, 2, rpc.lenSubs()) sub1.Unsubscribe() - require.Equal(t, 1, rpc.LenSubs()) + require.Equal(t, 1, rpc.lenSubs()) sub2.Unsubscribe() - require.Equal(t, 0, rpc.LenSubs()) + require.Equal(t, 0, rpc.lenSubs()) }) t.Run("Ensure no deadlock on UnsubscribeAll", func(t *testing.T) { rpc := newTestRPC(t) _, _, err := rpc.SubscribeToHeads(tests.Context(t)) require.NoError(t, err) - require.Equal(t, 1, rpc.LenSubs()) + require.Equal(t, 1, rpc.lenSubs()) _, _, err = rpc.SubscribeToFinalizedHeads(tests.Context(t)) require.NoError(t, err) - require.Equal(t, 2, rpc.LenSubs()) + require.Equal(t, 2, rpc.lenSubs()) rpc.UnsubscribeAllExcept() - require.Equal(t, 0, rpc.LenSubs()) + require.Equal(t, 0, rpc.lenSubs()) }) } @@ -262,7 +262,7 @@ func TestMultiNodeClient_RegisterSubs(t *testing.T) { sub, err := rpc.RegisterSub(mockSub, make(chan struct{})) require.NoError(t, err) require.NotNil(t, sub) - require.Equal(t, 1, rpc.LenSubs()) + require.Equal(t, 1, rpc.lenSubs()) rpc.UnsubscribeAllExcept() }) @@ -285,16 +285,16 @@ func TestMultiNodeClient_RegisterSubs(t *testing.T) { require.NoError(t, err) _, err = rpc.RegisterSub(mockSub2, chStopInFlight) require.NoError(t, err) - require.Equal(t, 2, rpc.LenSubs()) + require.Equal(t, 2, rpc.lenSubs()) // Ensure passed sub is not removed rpc.UnsubscribeAllExcept(sub1) - require.Equal(t, 1, rpc.LenSubs()) + require.Equal(t, 1, rpc.lenSubs()) require.True(t, mockSub2.unsubscribed) require.False(t, mockSub1.unsubscribed) rpc.UnsubscribeAllExcept() - require.Equal(t, 0, rpc.LenSubs()) + require.Equal(t, 0, rpc.lenSubs()) require.True(t, mockSub1.unsubscribed) }) }