Skip to content

RFC-8 support #2132

@josepot

Description

@josepot

Now that RFC-8 has been finally implemented in PolkadotSDK 🎉, I think this is a great opportunity to improve the ergonomics and clarity of the public API by revisiting the Client interface.

Specifically, I’d like to propose a redesign of the Client interface to make it more ergonomic and less error-prone. One key motivation is to remove the problematic potentialRelayChains property, which has historically caused confusion and race conditions.

Proposed Interface

type JsonChainOptions = {
  disableJsonRpc?: boolean;
  jsonRpcMaxPendingRequests?: number;
  jsonRpcMaxSubscriptions?: number;
};

type AddRelayChainOptions = {
  chainSpec: string;
  databaseContent?: string;
} & JsonChainOptions;

type AddParaChainFromParaIdOptions = {
  paraId: number;
} & JsonChainOptions;

type AddParaChainFromChainSpecOptions = {
  chainSpec: string;
} & JsonChainOptions;

type AddParaChainOptions =
  | AddParaChainFromParaIdOptions
  | AddParaChainFromChainSpecOptions;

// Reuses the existing `Chain` interface
type RelayChain = Chain & {
  addParaChain: (options: AddParaChainOptions) => Promise<Chain>;
};

interface Client {
  addRelayChain(options: AddRelayChainOptions): Promise<RelayChain>;
  terminate(): Promise<void>;
}

Benefits

  • Simplifies API ergonomics: Easier to understand and more intuitive to use.
  • Removes race conditions: Eliminates potentialRelayChains, addressing an important source of bugs and complexity.
  • Improves developer experience: Clearer structure for adding relay and parachains.

Example Usage

const smoldot = start();
const polkadot = await smoldot.addRelayChain({ chainSpec });
const assetHub = await polkadot.addParaChain({ paraId: 1000 });

WDYT?

Also, we (the PAPI team) would like to help with this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions