MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL

github.com/CovenantSQL/CovenantSQL @v0.8.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.8.1 ↗ · + Follow
4,230 symbols 21,119 edges 606 files 1,847 documented · 44%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README
<img src="https://github.com/CovenantSQL/CovenantSQL/raw/v0.8.1/logo/covenantsql_horizontal.png"
    width="760">






<a href="https://goreportcard.com/report/github.com/CovenantSQL/CovenantSQL">
    <img src="https://goreportcard.com/badge/github.com/CovenantSQL/CovenantSQL?style=flat-square"
        alt="Go Report Card"></a>
<a href="https://codecov.io/gh/CovenantSQL/CovenantSQL">
    <img src="https://codecov.io/gh/CovenantSQL/CovenantSQL/branch/develop/graph/badge.svg"
        alt="Coverage"></a>
<a href="https://travis-ci.org/CovenantSQL/CovenantSQL">
    <img src="https://travis-ci.org/CovenantSQL/CovenantSQL.png?branch=develop"
        alt="Build Status"/></a>
<a href="https://opensource.org/licenses/Apache-2.0">
    <img src="https://img.shields.io/badge/License-Apache%202.0-blue.svg"
        alt="License"></a>
<a href="https://godoc.org/github.com/CovenantSQL/CovenantSQL">
    <img src="https://img.shields.io/badge/godoc-reference-blue.svg"
        alt="GoDoc"></a>
<a href="https://formulae.brew.sh/formula/cql">
    <img src="https://img.shields.io/homebrew/v/cql.svg?color=blue&label=brew%20install%20cql"
        alt="homebrew"></a>

English Overview

CovenantSQL(CQL) 是一个运行在公网上的 SQL 数据库,并具有 GDPR 合规与去中心化等特点。

  • ServerLess 支持: 为小程序、浏览器插件提供免部署维护、自动同步、高可用的数据库服务
  • SQL 接口: 支持 SQL-92 标准
  • 去中心化: 不依赖中心节点协调的高可用架构
  • 不可篡改: CQL 中的 Query 历史是不可篡改且可追溯的
  • 隐私&权限: 列级别的权限限制,可以设定 SQL 白名单

CQL 是什么?

  • 对标 Amazon QLDB 的开源版
  • 免搭建、免维护、低成本的数据库服务(DBaaS)
  • 就像 filecoin + IPFS 是去中心化的文件系统, CQL 是去中心化的数据库

快速开始

MacOS 平台

  • 🍺 Homebrew 用户可以直接在命令行:

    bash brew install cql

  • 非 Homebrew,可以执行:

    bash sudo bash -c 'curl -L "https://mac.gridb.io/cql" | tar xzv -C /usr/local/bin/ --strip-components=1'

Linux 平台

  • 在命令行中执行:

    bash sudo bash -c 'curl -L "https://linux.gridb.io/cql" | tar xzv -C /usr/local/bin/ --strip-components=1'

继续请参见:测试网快速开始

CQL 如何工作

3 层架构

CovenantSQL 3 Layer design

  • 第一层: 全局共识层(主链,架构图中的中间环):
    • 整个网络中只有一个主链。
    • 主要负责数据库矿工与用户的合同匹配,交易结算,反作弊,子链哈希锁定等全局共识事宜。
  • 第二层: SQL 共识层(子链,架构图中的两边环):
    • 每个数据库都有自己独立的子链。
    • 主要负责数据库各种事务的签名,交付和一致性。这里主要实现永久可追溯性的数据历史,并且在主链中执行哈希锁定。
  • 第三层: 数据储存层(支持 SQL-92 的数据库引擎):
    • 每个数据库都有自己独立的分布式引擎。
    • 主要负责:数据库存储和加密;查询处理和签名;高效索引。

共识算法

CQL 支持两种共识算法:

  1. DPoS (委任权益证明) 应用在数据库的 最终一致性 和 Block Producer 所在的 第一层 (全局共识层) ,CQL 的矿工在客户端将所有SQL查询及其签名打包成块,从而形成整个区块链,我们把这个算法命名为 Xenomint
  2. BFT-Raft (拜占庭容错算法)bft-raft 应用于数据库的 强一致性。我们把这个实现命名为 Kayak. 矿工 leader 会基于 Kayak两阶段提交 来支持 Transaction.transaction

可以用命令行 cql create '{"UseEventualConsistency": true, "Node": 3}' 来创建 最终一致性 CQL 数据库

项目对比

以太坊 Hyperledger Fabric AWS QLDB CovenantSQL
开发语言 Solidity, ewasm Chaincode (Go, NodeJS) ? Python, Golang, Java, PHP, NodeJS, MatLab
开发模式 Smart Contract Chaincode SQL SQL
是否开源 Y Y N Y
高可用节点 3 15 ? 3
列级别 ACL N Y ? Y
数据格式 File Key-value Document Filefuse, Key-value, Structured
存储加密 N API Y Y
数据脱敏 N N N Y
多租户 DIY DIY N Y
吞吐量(1秒延迟) 15~10 tx/s 3500 tx/s ? 11065 tx/s (Eventually Consistency)

1866 tx/s (Strong Consistency) | | 一致性延迟 | 2~6 min | < 1 s | ? | < 10 ms | | 开放网络上的安全性 | Y | N | Only in AWS | Y | | 共识机制 | PoW + PoS(Casper) | CFT | ? | DPoS (Eventually Consistency)

BFT-Raft (Strong Consistency) |

强一致性,2个miner,aws c5.2xlarge 8核心cpu下的性能测试图: CovenantSQL bench

如图所见,前5个小时对数据库的并发压力逐渐增大,写入 TPS 也随之提升,当 TPS 不再增长时,维持并发压力持续测试100小时。

注释:

  • BFT-Raft: 在一个 CQL leader 离线的情况下,有两种可能的选择:等待 leader 上线,以保证数据的完整性,或者提拔 follwers 以保证服务可用性;目前是需要一定的人工介入来进行策略选择,这部分仍在迭代中,欢迎任何建议。

  • 事务 (Transaction): 说到 ACID,CQL 具有完整的 "一致性,隔离性,持久化" 和特定的 Atomicity 支持。即使在强一致性的模式下,CQL 事务只支持在 leader 节点上执行。如果你想要并发执行事务:"读取 v, v++, 写回 v ", 仅有的办法是:"从 leader 读取 v , v++, 从 leader 写回 v"

  • FUSE: CQL 有一个从 CockroachDB 移植过来的 FUSE 客户端,目前性能不是很理想,仍然存在一些小问题。但它可以通过如下的 fio 测试:

bash fio --debug=io --loops=1 --size=8m --filename=../mnt/fiotest.tmp --stonewall --direct=1 --name=Seqread --bs=128k --rw=read --name=Seqwrite --bs=128k --rw=write --name=4krandread --bs=4k --rw=randread --name=4krandwrite --bs=4k --rw=randwrite

Demos

使用案例

传统 App

数据隐私

如果你是一个使用密码管理工具的开发者,比如 1Password or LastPass. 你可以使用 CQL 作为数据库并有以下优点:

  1. 无服务器: 不需要部署服务器来存储用户密码,以进行同步,这是一个烫手山芋。
  2. 安全: CQL 可以保证所有的加密工作,去中心化的数据存储给予用户更多信心。
  3. 合规: CQL 天然符合 GDPR 标准。

物联网存储

CQL 矿工全球化部署,IoT 节点可以写入最近的矿工。

  1. 实惠: 不需要通过网关传输流量,你可以节省大量的带宽费用。同时,SQL 具有共享经济的特性,以此让存储更实惠。
  2. 更快: CQL 共识协议是基于互联网而设计,网络延迟不可避免。

开放数据服务

例如,你是一个非常在意细节的比特币 OHLC 数据维护者,你可以直接放一个 SQL 接口给你的用户以满足各种查询需求。

  1. CQL 在平衡数据安全性的同时,可以限制特定的 SQL 查询语句以满足需求。
  2. CQL 将 SQL 操作,增删查改等记录在区块链上,方便用户检查账单比如 这个
  3. 对于那些对高性能有要求的客户,可以在用户那里部署 Slave 节点,以满足低延迟查询的需求,同时实现几乎实时的数据更新。

安全存储

由于 CQL 数据历史是不可篡改的,CQL 可以用来存储敏感的操作日志,以防止黑客攻击和删除访问日志。

去中心化应用(ĐApp)

在比特币或以太坊这种传统公链上存储数据非常昂贵(2018-05-15 以太坊上为 $4305 / MB),而且由于缺乏结构化数据的支持,代码实现非常复杂。但 CQL 可以给你一个结构化且低成本的 SQL 数据库,并为 ĐApp 提供了与真实世界交换数据的空间。

相关论文

团队成员发表过的论文

这些启发了我们:

相关库

网络栈

DH-RPC := TLS - Cert + DHT

应用
远程调用协议 net/rpc
寻址 Consistent Secure DHT
会话池 Session Pool
多路复用 smux
传输安全 Enhanced TLS
网络 TCP or KCP for optional later

测试工具

接口

CovenantSQL仍在建设中,测试网已经发布,尝试一下.

关注我们或follow on Twitter 保持更新

测试网

联系我们

  • 博客
  • YouTube
  • 邮箱地址
  • 论坛
  • follow on Twitter
  • Join the chat at https://gitter.im/CovenantSQL/CovenantSQL
  • 添加微信: CovenantSQL 加入交流群
    <img src="https://github.com/CovenantSQL/CovenantSQL/raw/v0.8.1/logo/wechat.jpeg" height="100">
    

Extension points exported contracts — how you extend this code

MarshalHasher (Interface)
go:generate hsp MarshalHasher is the interface implemented by an object that can be stably marshalling hashed. [98 implementers]
crypto/verifier/common.go
Caller (Interface)
Caller defines the rpc caller, supports mocks for the default rpc.PersistCaller. [6 implementers]
kayak/caller.go
Collector (Interface)
Collector is the interface a collector has to implement. [7 implementers]
metric/collector.go
NOClientPool (Interface)
NOClientPool defines the node-oriented client pool interface. [4 implementers]
rpc/utils.go
Validator (Interface)
Validator is designed for params checking. [4 implementers]
rpc/jsonrpc/middleware.go
Worker (Interface)
Worker represents a 2PC worker who implements Prepare, Commit, and Rollback. [3 implementers]
twopc/twopc.go
Resolver (Interface)
Resolver defines the node ID resolver interface for node-oriented connection. [3 implementers]
naconn/resolver.go
Persistence (Interface)
Persistence is the interface for consistent persistence. [2 implementers]
consistent/persistence.go

Core symbols most depended-on inside this repo

Error
called by 470
utils/log/entrylogwrapper.go
Fatal
called by 453
utils/log/entrylogwrapper.go
New
called by 334
rpc/wrapper.go
Errorf
called by 287
utils/log/entrylogwrapper.go
Msgsize
called by 209
blockproducer/interfaces/transaction.go
Fatalf
called by 209
utils/log/entrylogwrapper.go
MarshalHash
called by 199
types/util.go
Close
called by 178
rpc/client.go

Shape

Function 2,119
Method 1,575
Struct 426
TypeAlias 52
Interface 37
FuncType 13
Class 8

Languages

Go88%
C++6%
C5%
Java1%

Modules by API surface

crypto/secp256k1/libsecp256k1/src/tests.c95 symbols
blockproducer/metastate.go49 symbols
types/db_service_types_gen_test.go48 symbols
utils/log/logwrapper.go46 symbols
consistent/consistent_test.go43 symbols
xenomint/state.go42 symbols
blockproducer/chain.go37 symbols
types/db_service_types.go36 symbols
sqlchain/chain.go34 symbols
sqlchain/runtime.go33 symbols
proto/proto.go33 symbols
types/db_service_types_gen.go32 symbols

For agents

$ claude mcp add CovenantSQL \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact