Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions tools/preconf-rpc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,20 @@ var (
Value: "",
}

optionSimulationURL = &cli.StringFlag{
optionSimulationURLs = &cli.StringSliceFlag{
Name: "simulation-url",
Usage: "URL for the transaction simulation service",
Usage: "URL(s) for the transaction simulation service. Multiple URLs can be specified for fallback support (first URL is primary, others are fallbacks)",
EnvVars: []string{"PRECONF_RPC_SIMULATION_URL"},
Required: true,
}

optionUseInlineSimulation = &cli.BoolFlag{
Name: "use-inline-simulation",
Usage: "Use inline simulation via debug_traceCall instead of external rethsim service. When false (default), uses external rethsim. When true, uses debug_traceCall (requires RPC with debug API support like Alchemy, Infura, or Erigon)",
EnvVars: []string{"PRECONF_RPC_USE_INLINE_SIMULATION"},
Value: false,
}

optionBackrunnerAPIURL = &cli.StringFlag{
Name: "backrunner-api-url",
Usage: "URL for the transaction backrun service",
Expand Down Expand Up @@ -357,7 +364,8 @@ func main() {
optionBidderThreshold,
optionBidderTopup,
optionAuthToken,
optionSimulationURL,
optionSimulationURLs,
optionUseInlineSimulation,
optionBackrunnerAPIURL,
optionBackrunnerRPCURL,
optionBackrunnerAPIKey,
Expand Down Expand Up @@ -458,7 +466,8 @@ func main() {
PricerAPIKey: c.String(optionBlocknativeAPIKey.Name),
Webhooks: c.StringSlice(optionWebhookURLs.Name),
Token: c.String(optionAuthToken.Name),
SimulatorURL: c.String(optionSimulationURL.Name),
SimulatorURLs: c.StringSlice(optionSimulationURLs.Name),
UseInlineSimulation: c.Bool(optionUseInlineSimulation.Name),
BackrunnerAPIURL: c.String(optionBackrunnerAPIURL.Name),
BackrunnerRPC: c.String(optionBackrunnerRPCURL.Name),
BackrunnerAPIKey: c.String(optionBackrunnerAPIKey.Name),
Expand Down
30 changes: 27 additions & 3 deletions tools/preconf-rpc/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ type Config struct {
PricerAPIKey string
Webhooks []string
Token string
SimulatorURL string
SimulatorURLs []string
UseInlineSimulation bool
BackrunnerRPC string
BackrunnerAPIURL string
BackrunnerAPIKey string
Expand Down Expand Up @@ -270,8 +271,31 @@ func New(config *Config) (*Service, error) {
healthChecker.Register(health.CloseChannelHealthCheck("BlockTracker", blockTrackerDone))
s.closers = append(s.closers, channelCloser(blockTrackerDone))

simulator := sim.NewSimulator(config.SimulatorURL)
metricsRegistry.MustRegister(simulator.Metrics()...)
// Create simulator based on feature flag
// When UseInlineSimulation is true, uses debug_traceCall via standard RPC (Alchemy, Infura, Erigon)
// When false (default), uses external rethsim API for backward compatibility
// Multiple URLs can be provided for fallback support
if len(config.SimulatorURLs) == 0 {
return nil, fmt.Errorf("at least one simulation URL is required")
}
var simulator sender.Simulator
var simulatorMetrics []prometheus.Collector
if config.UseInlineSimulation {
inlineSim, err := sim.NewInlineSimulator(config.SimulatorURLs, config.Logger)
if err != nil {
return nil, fmt.Errorf("failed to create inline simulator: %w", err)
}
simulator = inlineSim
simulatorMetrics = inlineSim.Metrics()
s.closers = append(s.closers, inlineSim) // close RPC clients on shutdown
config.Logger.Info("using inline simulator (debug_traceCall)", "endpointCount", len(config.SimulatorURLs))
} else {
externalSim := sim.NewSimulator(config.SimulatorURLs, config.Logger)
simulator = externalSim
simulatorMetrics = externalSim.Metrics()
config.Logger.Info("using external simulator (rethsim)", "endpointCount", len(config.SimulatorURLs))
}
metricsRegistry.MustRegister(simulatorMetrics...)

var pointsTracker PointsTracker
if config.PointsAPIURL == "" {
Expand Down
Loading