Workspace IndexDev Notes › Linera microchains

#127PoC

Linera microchains

One chain per user — removing blockspace contention instead of pricing it.

Reference — docs/knowledge/linera-microchains.html.

Why

Almost every scaling design here takes contention as a given and competes for the block: PBS auctions it, gas prices it, a relayer sequences around it. Linera's premise is that contention is a choice — give each user their own chain and there is nothing to contend for. Worth reading precisely because it rejects the assumption the rest of the catalogue is built on.

How it works

Reading note: the microchain model where each user owns a chain they alone extend, validators run all of them, and cross-chain messages replace shared-state contention. The interesting question the note tracks is not throughput but composability — what happens to an application whose whole point is that many users touch the same state, like an order book.

Related code

"""Linera microchains PoC -- one chain per user, plus a cross-chain message delivery.
Illustrates the core mechanism: independent per-user chains remove contention for a
shared block; interaction between users happens via explicit cross-chain messages.
"""

from dataclasses import dataclass, field


@dataclass
class Microchain:
    owner: str
    blocks: list[str] = field(default_factory=list)
    inbox: list[str] = field(default_factory=list)

    def extend(self, operation: str) -> None:
        """Only the owner extends their own chain -- no contention with anyone else."""
        self.blocks.append(operation)

    def receive(self, message: str) -> None:
        self.inbox.append(message)
        self.blocks.append(f"applied cross-chain message: {message}")


class Validator:
    """Runs every microchain, and relays messages between them."""

    def __init__(self):
        self.chains: dict[str, Microchain] = {}

    def create_chain(self, owner: str) -> Microchain:
        chain = Microchain(owner=owner)
        self.chains[owner] = chain
        return chain

    def send_cross_chain(self, sender: str, recipient: str, message: str) -> None:
        self.chains[sender].extend(f"send to {recipient}: {message}")
        self.chains[recipient].receive(f"from {sender}: {message}")


if __name__ == "__main__":
    validator = Validator()
    alice = validator.create_chain("alice")
    bob = validator.create_chain("bob")
    carol = validator.create_chain("carol")

    # Each user extends their own chain independently -- no shared block to contend for.
    alice.extend("deposit 10 USDC")
    bob.extend("deposit 5 USDC")
    carol.extend("deposit 20 USDC")

    # One cross-chain message: alice pays bob. This is the only point where chains touch.
    validator.send_cross_chain("alice", "bob", "pay 3 USDC")

    for name, chain in validator.chains.items():
        print(f"\nchain[{name}] blocks:")
        for b in chain.blocks:
            print(f"  - {b}")

← All Dev Notes · Workspace Index · Top ↑

Linera 마이크로체인

사용자당 체인 하나 — 블록스페이스 경합에 값을 매기는 대신 없애버리기.

참조 — docs/knowledge/linera-microchains.html.

여기 있는 거의 모든 확장 설계는 경합을 주어진 것으로 두고 블록을 놓고 경쟁합니다 — PBS는 경매에 부치고, 가스는 값을 매기고, 릴레이어는 그 주위로 순서를 잡습니다. Linera의 전제는 경합이 선택이라는 것입니다: 사용자마다 자기 체인을 주면 다툴 대상이 없습니다. 카탈로그의 나머지가 딛고 선 가정을 정면으로 거부하기 때문에 읽을 가치가 있습니다.

동작 방식

정독 노트: 각 사용자가 자기만 확장하는 체인을 소유하고, 검증자들이 그 전부를 돌리며, 공유 상태 경합을 체인 간 메시지가 대체하는 마이크로체인 모델. 노트가 따라가는 흥미로운 질문은 처리량이 아니라 조합 가능성입니다 — 여러 사용자가 같은 상태를 건드리는 것이 존재 이유인 애플리케이션(오더북 같은)은 어떻게 되는가.

관련 코드

"""Linera microchains PoC -- one chain per user, plus a cross-chain message delivery.
Illustrates the core mechanism: independent per-user chains remove contention for a
shared block; interaction between users happens via explicit cross-chain messages.
"""

from dataclasses import dataclass, field


@dataclass
class Microchain:
    owner: str
    blocks: list[str] = field(default_factory=list)
    inbox: list[str] = field(default_factory=list)

    def extend(self, operation: str) -> None:
        """Only the owner extends their own chain -- no contention with anyone else."""
        self.blocks.append(operation)

    def receive(self, message: str) -> None:
        self.inbox.append(message)
        self.blocks.append(f"applied cross-chain message: {message}")


class Validator:
    """Runs every microchain, and relays messages between them."""

    def __init__(self):
        self.chains: dict[str, Microchain] = {}

    def create_chain(self, owner: str) -> Microchain:
        chain = Microchain(owner=owner)
        self.chains[owner] = chain
        return chain

    def send_cross_chain(self, sender: str, recipient: str, message: str) -> None:
        self.chains[sender].extend(f"send to {recipient}: {message}")
        self.chains[recipient].receive(f"from {sender}: {message}")


if __name__ == "__main__":
    validator = Validator()
    alice = validator.create_chain("alice")
    bob = validator.create_chain("bob")
    carol = validator.create_chain("carol")

    # Each user extends their own chain independently -- no shared block to contend for.
    alice.extend("deposit 10 USDC")
    bob.extend("deposit 5 USDC")
    carol.extend("deposit 20 USDC")

    # One cross-chain message: alice pays bob. This is the only point where chains touch.
    validator.send_cross_chain("alice", "bob", "pay 3 USDC")

    for name, chain in validator.chains.items():
        print(f"\nchain[{name}] blocks:")
        for b in chain.blocks:
            print(f"  - {b}")

← 전체 개발 노트 · 워크스페이스 인덱스 · 맨 위 ↑