Object.ShardedConsensus (object v0.1.2)

Advanced Byzantine fault-tolerant consensus with sharding for AAOS.

Implements state-of-the-art consensus protocols including:

  • Practical Byzantine Fault Tolerance (pBFT) with optimizations
  • Sharded consensus for scalability to millions of nodes
  • Fast Byzantine Paxos with pipeline optimization
  • HotStuff consensus with linear communication complexity
  • Cross-shard transaction coordination via atomic commit
  • Verifiable secret sharing for threshold cryptography
  • Asynchronous consensus with eventual delivery guarantees
  • Adaptive protocol switching based on network conditions
  • Zero-knowledge consensus for privacy-preserving agreement

Summary

Functions

Returns a specification to start this module under a supervisor.

Creates zero-knowledge proofs for privacy-preserving consensus.

Performs Byzantine fault detection and node reputation scoring.

Executes a cross-shard transaction with atomic guarantees.

Generates threshold signatures for enhanced security.

Initializes a new shard with specified nodes.

Proposes a new consensus value to the specified shard.

Starts the sharded consensus service.

Switches the consensus protocol based on network conditions.

Types

consensus_message()

@type consensus_message() :: %{
  type:
    :pre_prepare | :prepare | :commit | :view_change | :new_view | :checkpoint,
  view: view_number(),
  sequence: sequence_number(),
  digest: binary(),
  payload: term(),
  sender: node_id(),
  timestamp: non_neg_integer(),
  signature: binary()
}

cross_shard_transaction()

@type cross_shard_transaction() :: %{
  transaction_id: binary(),
  coordinator_shard: shard_id(),
  participant_shards: [shard_id()],
  payload: term(),
  phase: :prepare | :commit | :abort,
  votes: %{required(shard_id()) => :yes | :no | :abort},
  timeout: non_neg_integer()
}

node_id()

@type node_id() :: binary()

sequence_number()

@type sequence_number() :: non_neg_integer()

shard_id()

@type shard_id() :: non_neg_integer()

shard_state()

@type shard_state() :: %{
  shard_id: shard_id(),
  nodes: [node_id()],
  primary: node_id(),
  view: view_number(),
  sequence: sequence_number(),
  phase: non_neg_integer(),
  prepared_messages: %{required(sequence_number()) => consensus_message()},
  committed_messages: %{required(sequence_number()) => consensus_message()},
  checkpoints: %{required(sequence_number()) => binary()},
  view_change_votes: %{required(view_number()) => [node_id()]},
  message_log: [consensus_message()],
  performance_metrics: map()
}

state()

@type state() :: %{
  node_id: node_id(),
  shards: %{required(shard_id()) => shard_state()},
  shard_mapping: %{required(term()) => shard_id()},
  cross_shard_transactions: %{required(binary()) => cross_shard_transaction()},
  consensus_protocols: %{
    current: :pbft | :hotstuff | :fast_paxos | :async_consensus,
    performance_history: [map()],
    switching_thresholds: map()
  },
  cryptographic_state: %{
    threshold_keys: %{required(shard_id()) => map()},
    verifiable_shares: %{required(shard_id()) => map()},
    zero_knowledge_proofs: %{required(shard_id()) => [map()]}
  },
  network_monitor: %{
    latency_matrix: [[float()]],
    bandwidth_matrix: [[float()]],
    failure_detector: map(),
    partition_detector: map()
  },
  system_metrics: %{
    throughput: float(),
    latency: float(),
    byzantine_detection_rate: float(),
    cross_shard_success_rate: float()
  }
}

threshold_signature()

@type threshold_signature() :: %{
  signature_shares: %{required(node_id()) => binary()},
  threshold: non_neg_integer(),
  combined_signature: binary() | nil,
  message_hash: binary()
}

view_number()

@type view_number() :: non_neg_integer()

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

create_zk_consensus_proof(shard_id, secret_input)

@spec create_zk_consensus_proof(shard_id(), term()) :: {:ok, map()} | {:error, term()}

Creates zero-knowledge proofs for privacy-preserving consensus.

detect_byzantine_behavior(shard_id)

@spec detect_byzantine_behavior(shard_id()) :: {:ok, [node_id()]} | {:error, term()}

Performs Byzantine fault detection and node reputation scoring.

execute_cross_shard_transaction(shard_ids, transaction_data)

@spec execute_cross_shard_transaction([shard_id()], term()) ::
  {:ok, term()} | {:error, term()}

Executes a cross-shard transaction with atomic guarantees.

generate_threshold_signature(shard_id, message)

@spec generate_threshold_signature(shard_id(), binary()) ::
  {:ok, threshold_signature()} | {:error, term()}

Generates threshold signatures for enhanced security.

initialize_shard(shard_id, nodes)

@spec initialize_shard(shard_id(), [node_id()]) :: :ok | {:error, term()}

Initializes a new shard with specified nodes.

propose_consensus(shard_id, value)

@spec propose_consensus(shard_id(), term()) :: {:ok, term()} | {:error, term()}

Proposes a new consensus value to the specified shard.

start_link(opts \\ [])

Starts the sharded consensus service.

switch_consensus_protocol(protocol)

@spec switch_consensus_protocol(atom()) :: :ok | {:error, term()}

Switches the consensus protocol based on network conditions.