Skip to content

feat(external-call): Add HTTP extension service client#442

Closed
trusch wants to merge 2 commits into
digital-asset:mainfrom
zenith-network:external-call/05-extension-service
Closed

feat(external-call): Add HTTP extension service client#442
trusch wants to merge 2 commits into
digital-asset:mainfrom
zenith-network:external-call/05-extension-service

Conversation

@trusch

@trusch trusch commented Feb 6, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR adds the HTTP client infrastructure for making external service calls. It provides an implementation with retry logic, authentication, TLS support, and connection pooling.

Requires #441

Changes

Configuration (ExtensionServiceConfig.scala)

final case class ExtensionServiceConfig(
    name: String,                           // Extension identifier
    host: String,                           // Service hostname
    port: Int,                              // Service port
    useTls: Boolean = false,                // Enable HTTPS
    tlsInsecure: Boolean = false,           // Skip cert validation
    jwt: Option[String] = None,             // JWT token (inline)
    jwtFile: Option[String] = None,         // JWT token (from file)
    connectTimeout: Duration = 500.millis,  // Connection timeout
    requestTimeout: Duration = 8.seconds,   // Request timeout
    maxTotalTimeout: Duration = 25.seconds, // Max total time including retries
    maxRetries: Int = 3,                    // Max retry attempts
    retryInitialDelay: Duration = 1.second, // Initial retry delay
    retryMaxDelay: Duration = 10.seconds,   // Max retry delay (exponential backoff)
    requestIdHeader: String = "X-Request-Id",
    declaredFunctions: Seq[DeclaredFunction] = Seq.empty
)

Service Interface (ExtensionService.scala)

trait ExtensionServiceClient {
  def call(
      functionId: String,
      config: Bytes,
      input: Bytes,
      mode: ExecutionMode  // Submission vs Validation
  )(implicit tc: TraceContext): Future[Either[ExtensionCallError, Bytes]]
}

sealed trait ExtensionCallError
case class SimpleError(message: String) extends ExtensionCallError
case class RetryableError(message: String, retryAfter: Option[Duration]) extends ExtensionCallError

HTTP Client (HttpExtensionServiceClient.scala)

Features:

  • Connection pooling: Shared HttpClient across calls
  • Retry logic: Exponential backoff with jitter
  • Rate limiting: Respects Retry-After header (429, 503)
  • Authentication: JWT Bearer token support
  • TLS: HTTPS with optional insecure mode
  • Tracing: Request ID header for distributed tracing
  • Mode header: Indicates submission vs validation mode
class HttpExtensionServiceClient(
    config: ExtensionServiceConfig,
    httpClient: HttpClient,
    loggerFactory: NamedLoggerFactory
) extends ExtensionServiceClient {

  override def call(...): Future[Either[ExtensionCallError, Bytes]] = {
    val request = buildRequest(functionId, config, input, mode)
    executeWithRetry(request, remainingRetries = config.maxRetries)
  }
}

Service Manager (ExtensionServiceManager.scala)

class ExtensionServiceManager(
    configs: Map[String, ExtensionServiceConfig],
    httpClient: HttpClient,
    loggerFactory: NamedLoggerFactory
) {
  private val clients: Map[String, ExtensionServiceClient] =
    configs.map { case (name, config) =>
      name -> new HttpExtensionServiceClient(config, httpClient, loggerFactory)
    }

  def getClient(extensionId: String): Option[ExtensionServiceClient] =
    clients.get(extensionId)
}

Validator (ExtensionValidator.scala)

Validates DAR packages against extension configuration:

  • Checks that all referenced extensions are configured
  • Validates function config hashes match
  • Reports warnings for missing extensions (non-fatal for observers)

Engine Bridge (ExtensionServiceExternalCallHandler.scala)

class ExtensionServiceExternalCallHandler(
    manager: ExtensionServiceManager
) extends ExternalCallHandler {

  override def handleExternalCall(
      extensionId: String,
      functionId: String,
      config: Bytes,
      input: Bytes,
      mode: ExecutionMode
  ): Future[Either[String, Bytes]] = {
    manager.getClient(extensionId) match {
      case Some(client) => client.call(functionId, config, input, mode)
      case None => Future.successful(Left(s"Unknown extension: $extensionId"))
    }
  }
}

Engine Config (CantonEngineConfig.scala)

  • Added extensions configuration section

Canton Configuration Example

canton.participants.participant1 {
  ledger-api.extensions {
    services {
      price-oracle {
        host = "oracle.example.com"
        port = 443
        useTls = true
        jwt = "eyJ..."
        requestTimeout = 5s
        maxRetries = 3
        declaredFunctions = [
          { functionId = "get-price", configHash = "abc123" }
        ]
      }
    }
  }
}

Testing

This will be covered by integration tests in the daml repo.

@github-actions

github-actions Bot commented Feb 6, 2026

Copy link
Copy Markdown

✅ All required contributors have signed the CLA for this PR. Thank you!
Posted by the CLA Assistant Lite bot.

@trusch trusch force-pushed the external-call/05-extension-service branch 2 times, most recently from 741cbad to cc8088d Compare February 6, 2026 09:25
@trusch trusch marked this pull request as draft February 6, 2026 09:27
@trusch trusch force-pushed the external-call/05-extension-service branch from cc8088d to edc6e9d Compare March 17, 2026 12:15
@trusch trusch force-pushed the external-call/05-extension-service branch from edc6e9d to 50e44bc Compare March 26, 2026 12:58
@trusch trusch force-pushed the external-call/05-extension-service branch from 50e44bc to d8190c0 Compare April 8, 2026 14:51
@angelol angelol force-pushed the external-call/05-extension-service branch 2 times, most recently from 9145be1 to 98e5c16 Compare May 8, 2026 11:18
- Extend ActionDescription with external call results
- Update participant_transaction.proto
- Update ViewParticipantData
- Update NodeHashBuilder for external call hashing
@angelol angelol force-pushed the external-call/05-extension-service branch 2 times, most recently from 6f57aba to 01ad572 Compare May 14, 2026 08:10
- Add ExtensionServiceConfig for configuration
- Implement HttpExtensionServiceClient with retry logic
- Add ExtensionServiceManager for service routing
- Add ExtensionValidator for DAR validation
- Add ExtensionServiceExternalCallHandler bridge
@angelol angelol force-pushed the external-call/05-extension-service branch from 01ad572 to 42652d2 Compare May 14, 2026 08:14
@trusch trusch closed this Jul 7, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant