Skip to content

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

Draft
trusch wants to merge 8 commits intodigital-asset:mainfrom
zenith-network:external-call/05-extension-service
Draft

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

Conversation

@trusch
Copy link
Copy Markdown

@trusch trusch commented Feb 6, 2026

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
Copy link
Copy Markdown

github-actions bot commented Feb 6, 2026

🎉 Thank you for your contribution! It appears you have not yet signed the Agreement DA Contributor License Agreement (CLA), which is required for your changes to be incorporated into an Open Source Software (OSS) project. Please kindly read the and reply on a new comment with the following text to agree:


I have hereby read the Digital Asset CLA and agree to its terms


You can retrigger this bot by commenting recheck in this Pull Request. 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 added 8 commits April 8, 2026 16:33
…eedback

- Proto: config_hash/input_hex/output_hex (string) -> config/input/output (bytes)
- Proto: Remove call_index field (repeated is already ordered)
- Scala: ExternalCallResult fields now use data.Bytes instead of String
- Test generators: Updated to generate binary data instead of hex strings
…r review

- Add EXTERNAL_CALL to LF test parser (ExprParser.scala)
- Add EXTERNAL_CALL to parser spec (ParsersSpec.scala)
- Add externalCall entry to Builtin_2.dev_.lf
- Add ResultNeedExternalCall to Engine results
- Implement SBExternalCall builtin in Speedy
- Add NeedExternalCall question type
- Update PartialTransaction to store external call results
- Update CostModel for external calls
…alls

- Encode/decode ExternalCallResult in TransactionCoder
- Update serialization version handling
- Extend ActionDescription with external call results
- Update participant_transaction.proto
- Update ViewParticipantData
- Update NodeHashBuilder for external call hashing
- Add ExtensionServiceConfig for configuration
- Implement HttpExtensionServiceClient with retry logic
- Add ExtensionServiceManager for service routing
- Add ExtensionValidator for DAR validation
- Add ExtensionServiceExternalCallHandler bridge
@trusch trusch force-pushed the external-call/05-extension-service branch from 50e44bc to d8190c0 Compare April 8, 2026 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant