Files
zeekay b374abe5c4 feat: blockchain-native consensus with dual-certificate PQ finality
Replace Consul with private BFT blockchain (ConsensusKV) as default
state management backend for MPC cluster. MPC nodes are now validators
on their own chain with dual-certificate finality:

- Ed25519 (classical, 64B sig) + ML-DSA-65 (FIPS 204, 3,309B sig)
- Block finalized only when BOTH signature types reach t-of-n threshold
- Abstract KV interface with 3 backends: consensus (default), nats, consul
- Signer interface for KMS/HSM delegation (keys never leave enclave)
- Bootstrap via NATS JetStream KV bucket before consensus genesis
- State sync via snapshot for new node joins
- Same luxfi/crypto/mldsa used by Lux mainnet precompiles

All existing Consul code preserved for 100% parity testing.
2026-03-11 16:03:35 -07:00

70 lines
1.5 KiB
Go

package config
import (
"fmt"
"github.com/hashicorp/consul/api"
"github.com/hanzoai/mpc/pkg/infra"
)
type Peer struct {
ID string
Name string
}
// LoadPeersFromConsul loads peers from a Consul KV client (backward compatibility).
func LoadPeersFromConsul(kv *api.KV, prefix string) ([]Peer, error) {
// Retrieve node IDs with the "peers" prefix
pairs, _, err := kv.List(prefix, nil)
if err != nil {
return nil, err
}
fmt.Println("List of node IDs with the prefix: " + prefix)
peers := make([]Peer, 0, len(pairs))
for _, pair := range pairs {
peers = append(peers, Peer{
ID: string(pair.Value),
// remove prefix from key
Name: pair.Key[len(prefix):],
})
fmt.Printf("Key: %s, Value: %s\n", pair.Key, pair.Value)
}
return peers, nil
}
// LoadPeersFromKV loads peers from the abstract KV interface.
// Works with any backend: consensus, NATS, or Consul adapter.
func LoadPeersFromKV(kv infra.KV, prefix string) ([]Peer, error) {
pairs, err := kv.List(prefix)
if err != nil {
return nil, err
}
fmt.Println("List of node IDs with the prefix: " + prefix)
peers := make([]Peer, 0, len(pairs))
for _, pair := range pairs {
peers = append(peers, Peer{
ID: string(pair.Value),
Name: pair.Key[len(prefix):],
})
fmt.Printf("Key: %s, Value: %s\n", pair.Key, pair.Value)
}
return peers, nil
}
func GetNodeID(nodeName string, peers []Peer) string {
for _, peer := range peers {
if peer.Name == nodeName {
return peer.ID
}
}
return ""
}