Skip to content

Commit

Permalink
Pulled private methods out of IClientManager
Browse files Browse the repository at this point in the history
  • Loading branch information
jclapis committed May 7, 2024
1 parent 64306af commit 1fb5c25
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
4 changes: 2 additions & 2 deletions node/services/bn-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ func (m *BeaconClientManager) GetClientTypeName() string {
return "Beacon Node"
}

func (m *BeaconClientManager) setPrimaryReady(ready bool) {
func (m *BeaconClientManager) SetPrimaryReady(ready bool) {
m.primaryReady = ready
}

func (m *BeaconClientManager) setFallbackReady(ready bool) {
func (m *BeaconClientManager) SetFallbackReady(ready bool) {
m.fallbackReady = ready
}

Expand Down
4 changes: 2 additions & 2 deletions node/services/ec-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ func (m *ExecutionClientManager) GetClientTypeName() string {
return "Execution Client"
}

func (m *ExecutionClientManager) setPrimaryReady(ready bool) {
func (m *ExecutionClientManager) SetPrimaryReady(ready bool) {
m.primaryReady = ready
}

func (m *ExecutionClientManager) setFallbackReady(ready bool) {
func (m *ExecutionClientManager) SetFallbackReady(ready bool) {
m.fallbackReady = ready
}

Expand Down
10 changes: 5 additions & 5 deletions node/services/function-runners.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type function2[ClientType any, ReturnType1 any, ReturnType2 any] func(ClientType

// Attempts to run a function progressively through each client until one succeeds or they all fail.
// Expects functions with 1 output and an error; for functions with other signatures, see the other runFunctionX functions.
func runFunction1[ClientType any, ReturnType any](m IClientManager[ClientType], ctx context.Context, function function1[ClientType, ReturnType]) (ReturnType, error) {
func runFunction1[ClientType any, ReturnType any](m iClientManagerImpl[ClientType], ctx context.Context, function function1[ClientType, ReturnType]) (ReturnType, error) {
logger, _ := log.FromContext(ctx)
var blank ReturnType
typeName := m.GetClientTypeName()
Expand All @@ -30,7 +30,7 @@ func runFunction1[ClientType any, ReturnType any](m IClientManager[ClientType],
if err != nil {
if isDisconnected(err) {
// If it's disconnected, log it and try the fallback
m.setPrimaryReady(false)
m.SetPrimaryReady(false)
if m.IsFallbackEnabled() {
logger.Warn("Primary "+typeName+" client disconnected, using fallback...", log.Err(err))
return runFunction1[ClientType, ReturnType](m, ctx, function)
Expand All @@ -53,7 +53,7 @@ func runFunction1[ClientType any, ReturnType any](m IClientManager[ClientType],
if isDisconnected(err) {
// If it's disconnected, log it and try the fallback
logger.Warn("Fallback "+typeName+" disconnected", log.Err(err))
m.setFallbackReady(false)
m.SetFallbackReady(false)
return blank, fmt.Errorf("all " + typeName + "s failed")
}

Expand All @@ -68,15 +68,15 @@ func runFunction1[ClientType any, ReturnType any](m IClientManager[ClientType],
}

// Run a function with 0 outputs and an error
func runFunction0[ClientType any](m IClientManager[ClientType], ctx context.Context, function function0[ClientType]) error {
func runFunction0[ClientType any](m iClientManagerImpl[ClientType], ctx context.Context, function function0[ClientType]) error {
_, err := runFunction1(m, ctx, func(client ClientType) (any, error) {
return nil, function(client)
})
return err
}

// Run a function with 2 outputs and an error
func runFunction2[ClientType any, ReturnType1 any, ReturnType2 any](m IClientManager[ClientType], ctx context.Context, function function2[ClientType, ReturnType1, ReturnType2]) (ReturnType1, ReturnType2, error) {
func runFunction2[ClientType any, ReturnType1 any, ReturnType2 any](m iClientManagerImpl[ClientType], ctx context.Context, function function2[ClientType, ReturnType1, ReturnType2]) (ReturnType1, ReturnType2, error) {
type out struct {
arg1 ReturnType1
arg2 ReturnType2
Expand Down
8 changes: 6 additions & 2 deletions node/services/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ type IClientManager[ClientType any] interface {
IsFallbackReady() bool
IsFallbackEnabled() bool
GetClientTypeName() string
}

type iClientManagerImpl[ClientType any] interface {
IClientManager[ClientType]

// Internal functions
setPrimaryReady(bool)
setFallbackReady(bool)
SetPrimaryReady(bool)
SetFallbackReady(bool)
}

0 comments on commit 1fb5c25

Please sign in to comment.