Skip to content

Commit

Permalink
feat: add multi call routing strategy (#26)
Browse files Browse the repository at this point in the history
* feat: add multicall routing strategy
    * Updated proxyd config to accept a routing strategy parameter 
    * Added multicall routing strategies
    * Refactored backendGroup.Forward to handle multiple types of routing strategies
    * Background.ForwardToBackend now will return results via a channel
  • Loading branch information
jelias2 authored Jul 22, 2024
1 parent ec496f5 commit d4382bf
Show file tree
Hide file tree
Showing 11 changed files with 916 additions and 98 deletions.
391 changes: 298 additions & 93 deletions proxyd/backend.go

Large diffs are not rendered by default.

45 changes: 45 additions & 0 deletions proxyd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"os"
"strings"
"time"

"github.com/ethereum/go-ethereum/log"
)

type ServerConfig struct {
Expand Down Expand Up @@ -107,11 +109,54 @@ type BackendConfig struct {

type BackendsConfig map[string]*BackendConfig

type RoutingStrategy string

func (b *BackendGroupConfig) ValidateRoutingStrategy(bgName string) bool {

// If Consensus Aware is Set and Routing RoutingStrategy is populated fail
if b.ConsensusAware && b.RoutingStrategy != "" {
log.Warn("consensus_aware is now deprecated, please use routing_strategy = consensus_aware")
log.Crit("Exiting consensus_aware and routing strategy are mutually exclusive, they cannot both be defined")
}

// If Consensus Aware is Set set RoutingStrategy to consensus_aware
if b.ConsensusAware {
b.RoutingStrategy = ConsensusAwareRoutingStrategy
log.Info("consensus_aware is now deprecated, please use routing_strategy = consenus_aware in the future")
}

switch b.RoutingStrategy {
case ConsensusAwareRoutingStrategy:
return true
case MulticallRoutingStrategy:
return true
case FallbackRoutingStrategy:
return true
case "":
log.Info("Empty routing strategy provided for backend_group, using fallback strategy ", "name", bgName)
b.RoutingStrategy = FallbackRoutingStrategy
return true
default:
return false
}
}

const (
ConsensusAwareRoutingStrategy RoutingStrategy = "consensus_aware"
MulticallRoutingStrategy RoutingStrategy = "multicall"
FallbackRoutingStrategy RoutingStrategy = "fallback"
)

type BackendGroupConfig struct {
Backends []string `toml:"backends"`

WeightedRouting bool `toml:"weighted_routing"`

RoutingStrategy RoutingStrategy `toml:"routing_strategy"`

/*
Deprecated: Use routing_strategy config to create a consensus_aware proxyd instance
*/
ConsensusAware bool `toml:"consensus_aware"`
ConsensusAsyncHandler string `toml:"consensus_handler"`
ConsensusPollerInterval TOMLDuration `toml:"consensus_poller_interval"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func setupBlockHeightZero(t *testing.T) (map[string]*bhZeroNodeContext, *proxyd.
bg := svr.BackendGroups["node"]

require.NotNil(t, bg)
require.NotNil(t, bg.Consensus)
require.NotNil(t, bg.Consensus, "Expected Consenus Poller to be intialized")
require.Equal(t, 2, len(bg.Backends))

// convenient mapping to access the nodes
Expand Down
Loading

0 comments on commit d4382bf

Please sign in to comment.