mirror of
https://github.com/hanzoai/mpc.git
synced 2026-10-30 19:45:28 +00:00
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.
55 lines
1.3 KiB
Go
55 lines
1.3 KiB
Go
package infra
|
|
|
|
import (
|
|
"github.com/hashicorp/consul/api"
|
|
)
|
|
|
|
// ConsulKVAdapter wraps the existing ConsulKV interface to implement the
|
|
// abstract KV interface. This allows existing Consul-based deployments to
|
|
// continue working while new deployments use consensus-backed storage.
|
|
type ConsulKVAdapter struct {
|
|
consul ConsulKV
|
|
}
|
|
|
|
// NewConsulKVAdapter creates a KV implementation backed by Consul.
|
|
func NewConsulKVAdapter(consulKV ConsulKV) *ConsulKVAdapter {
|
|
return &ConsulKVAdapter{consul: consulKV}
|
|
}
|
|
|
|
func (c *ConsulKVAdapter) Put(key string, value []byte) error {
|
|
_, err := c.consul.Put(&api.KVPair{Key: key, Value: value}, nil)
|
|
return err
|
|
}
|
|
|
|
func (c *ConsulKVAdapter) Get(key string) ([]byte, error) {
|
|
pair, _, err := c.consul.Get(key, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if pair == nil {
|
|
return nil, nil
|
|
}
|
|
return pair.Value, nil
|
|
}
|
|
|
|
func (c *ConsulKVAdapter) Delete(key string) error {
|
|
_, err := c.consul.Delete(key, nil)
|
|
return err
|
|
}
|
|
|
|
func (c *ConsulKVAdapter) List(prefix string) ([]*KVPair, error) {
|
|
pairs, _, err := c.consul.List(prefix, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
result := make([]*KVPair, 0, len(pairs))
|
|
for _, p := range pairs {
|
|
result = append(result, &KVPair{
|
|
Key: p.Key,
|
|
Value: p.Value,
|
|
})
|
|
}
|
|
return result, nil
|
|
}
|