{"id":13411877,"url":"https://github.com/CovenantSQL/CovenantSQL","last_synced_at":"2025-03-14T17:31:20.312Z","repository":{"id":45638340,"uuid":"129072319","full_name":"CovenantSQL/CovenantSQL","owner":"CovenantSQL","description":"A decentralized, trusted, high performance, SQL database with blockchain features","archived":false,"fork":false,"pushed_at":"2023-02-25T09:40:53.000Z","size":55454,"stargazers_count":1496,"open_issues_count":36,"forks_count":147,"subscribers_count":73,"default_branch":"develop","last_synced_at":"2024-10-29T17:55:42.671Z","etag":null,"topics":["bft","blockchain","covenantsql","cql","crypto","database","dbaas","decentralized","p2p","qldb","sql","sql-database"],"latest_commit_sha":null,"homepage":"https://developers.covenantsql.io","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CovenantSQL.png","metadata":{"files":{"readme":"README-zh.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-04-11T09:52:58.000Z","updated_at":"2024-10-21T14:21:45.000Z","dependencies_parsed_at":"2024-06-13T08:46:43.625Z","dependency_job_id":"d8d98c85-917e-4e42-a9d5-71631928f63b","html_url":"https://github.com/CovenantSQL/CovenantSQL","commit_stats":null,"previous_names":["thunderdb/thunderdb"],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CovenantSQL%2FCovenantSQL","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CovenantSQL%2FCovenantSQL/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CovenantSQL%2FCovenantSQL/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CovenantSQL%2FCovenantSQL/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CovenantSQL","download_url":"https://codeload.github.com/CovenantSQL/CovenantSQL/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243618698,"owners_count":20320279,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bft","blockchain","covenantsql","cql","crypto","database","dbaas","decentralized","p2p","qldb","sql","sql-database"],"created_at":"2024-07-30T20:01:17.883Z","updated_at":"2025-03-14T17:31:15.298Z","avatar_url":"https://github.com/CovenantSQL.png","language":"Go","readme":"\u003cp align=\"center\"\u003e\n    \u003cimg src=\"logo/covenantsql_horizontal.png\"\n        width=\"760\"\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://goreportcard.com/report/github.com/CovenantSQL/CovenantSQL\"\u003e\n        \u003cimg src=\"https://goreportcard.com/badge/github.com/CovenantSQL/CovenantSQL?style=flat-square\"\n            alt=\"Go Report Card\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://codecov.io/gh/CovenantSQL/CovenantSQL\"\u003e\n        \u003cimg src=\"https://codecov.io/gh/CovenantSQL/CovenantSQL/branch/develop/graph/badge.svg\"\n            alt=\"Coverage\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://travis-ci.org/CovenantSQL/CovenantSQL\"\u003e\n        \u003cimg src=\"https://travis-ci.org/CovenantSQL/CovenantSQL.png?branch=develop\"\n            alt=\"Build Status\"/\u003e\u003c/a\u003e\n    \u003ca href=\"https://opensource.org/licenses/Apache-2.0\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/License-Apache%202.0-blue.svg\"\n            alt=\"License\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://godoc.org/github.com/CovenantSQL/CovenantSQL\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/godoc-reference-blue.svg\"\n            alt=\"GoDoc\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://formulae.brew.sh/formula/cql\"\u003e\n        \u003cimg src=\"https://img.shields.io/homebrew/v/cql.svg?color=blue\u0026label=brew%20install%20cql\"\n            alt=\"homebrew\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n[English Overview](https://github.com/CovenantSQL/CovenantSQL/blob/develop/README.md)\n\nCovenantSQL(CQL) 是一个运行在公网上的 SQL 数据库，并具有 GDPR 合规与去中心化等特点。\n\n- **ServerLess 支持**: 为小程序、浏览器插件提供免部署维护、自动同步、高可用的数据库服务\n- **SQL 接口**: 支持 SQL-92 标准\n- **去中心化**: 不依赖中心节点协调的高可用架构\n- **不可篡改**: CQL 中的 Query 历史是不可篡改且可追溯的\n- **隐私\u0026权限**: 列级别的权限限制，可以设定 SQL 白名单\n\n## CQL 是什么?\n\n- 对标 [Amazon QLDB](https://aws.amazon.com/qldb/) 的开源版\n- 免搭建、免维护、低成本的数据库服务（DBaaS）\n- 就像 [filecoin](https://filecoin.io/) + [IPFS](https://ipfs.io/) 是去中心化的文件系统, CQL 是去中心化的数据库\n\n\n## 快速开始\n#### MacOS 平台\n\n- 🍺 Homebrew 用户可以直接在命令行：\n\n    ```bash\n    brew install cql\n    ```\n\n- 非 Homebrew，可以执行：\n\n    ```bash\n    sudo bash -c 'curl -L \"https://mac.gridb.io/cql\" | tar xzv -C /usr/local/bin/ --strip-components=1'\n    ```\n\n#### Linux 平台\n\n- 在命令行中执行：\n\n    ```bash\n    sudo bash -c 'curl -L \"https://linux.gridb.io/cql\" | tar xzv -C /usr/local/bin/ --strip-components=1'\n    ```\n\n#### 继续请参见：[测试网快速开始](https://developers.covenantsql.io/docs/zh-CN/quickstart)\n\n## CQL 如何工作\n\n### 3 层架构\n\n\n![CovenantSQL 3 Layer design](https://cdn.jsdelivr.net/gh/CovenantSQL/docs@b7143254adb804dff0e3bc1f2f6ab11ad9cd44f5/website/static/img/2layers.svg)\n\n- 第一层: **全局共识层**(主链，架构图中的中间环):\n    - 整个网络中只有一个主链。\n    - 主要负责数据库矿工与用户的合同匹配，交易结算，反作弊，子链哈希锁定等全局共识事宜。\n- 第二层: **SQL 共识层**(子链，架构图中的两边环):\n    - 每个数据库都有自己独立的子链。\n    - 主要负责数据库各种事务的签名，交付和一致性。这里主要实现永久可追溯性的数据历史，并且在主链中执行哈希锁定。\n- 第三层: **数据储存层**(支持 SQL-92 的数据库引擎):\n    - 每个数据库都有自己独立的分布式引擎。\n    - 主要负责：数据库存储和加密；查询处理和签名；高效索引。\n\n\n### 共识算法\n\nCQL 支持两种共识算法：\n\n1. DPoS (委任权益证明) 应用在数据库的 `最终一致性` 和 Block Producer 所在的 `第一层 (全局共识层)` ，CQL 的矿工在客户端将所有SQL查询及其签名打包成块，从而形成整个区块链，我们把这个算法命名为 [`Xenomint`](https://github.com/CovenantSQL/CovenantSQL/tree/develop/xenomint)\n2. BFT-Raft (拜占庭容错算法)\u003csup\u003e[bft-raft](#bft-raft)\u003c/sup\u003e 应用于数据库的 `强一致性`。我们把这个实现命名为 [`Kayak`](https://github.com/CovenantSQL/CovenantSQL/tree/develop/kayak).  矿工 leader 会基于 `Kayak` 做 `两阶段提交` 来支持 `Transaction`.\u003csup\u003e[transaction](#transaction)\u003c/sup\u003e\n\n可以用命令行  `cql create '{\"UseEventualConsistency\": true, \"Node\": 3}'` 来创建 `最终一致性` CQL 数据库\n\n\n## 项目对比\n\n|                              | 以太坊            | Hyperledger Fabric     | AWS QLDB | CovenantSQL                                                  |\n| ---------------------------- | ----------------- | ---------------------- | ----------- | ------------------------------------------------------------ |\n| **开发语言**                  | Solidity, ewasm   | Chaincode (Go, NodeJS) | ?           | Python, Golang, Java, PHP, NodeJS, MatLab                    |\n| **开发模式**                  | Smart   Contract  | Chaincode              | SQL         | SQL                                                          |\n| **是否开源**                  | Y                 | Y                      | N           | Y                                                            |\n| **高可用节点**                | 3                 | 15                     | ?           | 3                                                            |\n| **列级别 ACL**                | N                 | Y                      | ?           | Y                                                            |\n| **数据格式**                  | File              | Key-value              | Document    | File\u003csup\u003e[fuse](#fuse)\u003c/sup\u003e, Key-value, Structured     |\n| **存储加密**                  | N                 | API                    | Y           | Y                                                            |\n| **数据脱敏**                  | N                 | N                      | N           | Y                                                            |\n| **多租户**                  | DIY               | DIY                    | N           | Y                                                            |\n| **吞吐量（1秒延迟）**          | 15~10 tx/s        | 3500 tx/s              | ?           | 11065 tx/s (Eventually Consistency)\u003cbr/\u003e1866 tx/s (Strong Consistency) |\n| **一致性延迟**                | 2~6 min           | \u003c 1 s                  | ?           | \u003c 10 ms                                                      |\n| **开放网络上的安全性**         | Y                 | N                      | Only in AWS | Y                                                            |\n| **共识机制**                  | PoW + PoS(Casper) | CFT                    | ?           | DPoS (Eventually Consistency)\u003cbr/\u003eBFT-Raft (Strong Consistency) |\n\n强一致性，2个miner，aws c5.2xlarge 8核心cpu下的性能测试图：\n![CovenantSQL bench](logo/bench.png)\n\n如图所见，前5个小时对数据库的并发压力逐渐增大，写入 TPS 也随之提升，当 TPS 不再增长时，维持并发压力持续测试100小时。\n\n#### 注释：\n- \u003ca name=\"bft-raft\"\u003eBFT-Raft\u003c/a\u003e: 在一个 CQL leader 离线的情况下，有两种可能的选择：等待 leader 上线，以保证数据的完整性，或者提拔 follwers 以保证服务可用性；目前是需要一定的人工介入来进行策略选择，这部分仍在迭代中，欢迎任何建议。\n\n- \u003ca name=\"transaction\"\u003e事务 (Transaction)\u003c/a\u003e: 说到 `ACID`，CQL 具有完整的 \"一致性，隔离性，持久化\" 和特定的 `Atomicity` 支持。即使在强一致性的模式下，CQL 事务只支持在 leader 节点上执行。如果你想要并发执行事务：\"读取 `v`, `v++`, 写回 `v` \", 仅有的办法是：\"从 leader 读取 `v` , `v++`, 从 leader 写回 `v`\"\n\n- \u003ca name=\"fuse\"\u003eFUSE\u003c/a\u003e: CQL 有一个从 CockroachDB 移植过来的 [FUSE 客户端](https://github.com/CovenantSQL/CovenantSQL/tree/develop/cmd/cql-fuse)，目前性能不是很理想，仍然存在一些小问题。但它可以通过如下的 fio 测试：\n\n  ```bash\n  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\n  ```\n\n\n## Demos\n\n- 去中心化论坛：[CovenantForum](https://demo.covenantsql.io/forum/)\n- 推特上链：[Twitter Bot @iBlockPin](https://twitter.com/iblockpin)\n- 微博上链：[Weibo Bot @BlockPin](https://weibo.com/BlockPin)\n- Markdown 同步上链：[Markdown Editor with CovenantSQL sync](https://github.com/CovenantSQL/stackedit)\n- 网页端管理：[Web Admin for CovenantSQL](https://github.com/CovenantSQL/adminer)\n- CovenantSQL 介绍视频：[How CovenantSQL works(video)](https://youtu.be/2Mz5POxxaQM?t=106)\n\n## 使用案例\n\n### 传统 App\n\n#### 数据隐私\n\n如果你是一个使用密码管理工具的开发者，比如 [1Password](https://1password.com/) or [LastPass](https://www.lastpass.com/). 你可以使用 CQL 作为数据库并有以下优点：\n\n1. 无服务器: 不需要部署服务器来存储用户密码，以进行同步，这是一个烫手山芋。\n2. 安全: CQL 可以保证所有的加密工作，去中心化的数据存储给予用户更多信心。\n3. 合规: CQL 天然符合 [GDPR](https://en.wikipedia.org/wiki/General_Data_Protection_Regulation) 标准。\n\n#### 物联网存储\n\nCQL 矿工全球化部署，IoT 节点可以写入最近的矿工。 \n\n1. 实惠: 不需要通过网关传输流量，你可以节省大量的带宽费用。同时，SQL 具有共享经济的特性，以此让存储更实惠。\n2. 更快: CQL 共识协议是基于互联网而设计，网络延迟不可避免。\n\n\n#### 开放数据服务\n\n例如，你是一个非常在意细节的比特币 OHLC 数据维护者，你可以直接放一个 SQL 接口给你的用户以满足各种查询需求。\n\n1. CQL 在平衡数据安全性的同时，可以限制特定的 SQL 查询语句以满足需求。\n2. CQL 将 SQL 操作，增删查改等记录在区块链上，方便用户检查账单比如 [这个](https://explorer.dbhub.org/dbs/7a51191ae06afa22595b3904dc558d41057a279393b22650a95a3fc610e1e2df/requests/f466f7bf89d4dd1ece7849ef3cbe5c619c2e6e793c65b31966dbe4c7db0bb072)\n3. 对于那些对高性能有要求的客户，可以在用户那里部署 `Slave` 节点，以满足低延迟查询的需求，同时实现几乎实时的数据更新。\n\n#### 安全存储\n\n由于 CQL 数据历史是不可篡改的，CQL 可以用来存储敏感的操作日志，以防止黑客攻击和删除访问日志。\n\n\n### 去中心化应用（ĐApp）\n\n在比特币或以太坊这种传统公链上存储数据非常昂贵（2018-05-15 以太坊上为 $4305 / MB），而且由于缺乏结构化数据的支持，代码实现非常复杂。但 CQL 可以给你一个结构化且低成本的 SQL 数据库，并为 ĐApp 提供了与真实世界交换数据的空间。\n\n\n## 相关论文\n团队成员发表过的论文\n\n- [迅雷水晶：一种新颖的基于众筹的内容分发平台](https://dl.acm.org/citation.cfm?id=2736085)\n- [基于众筹的视频服务系统性能分析](https://ieeexplore.ieee.org/abstract/document/7114727/)\n- [迅雷水晶性能分析：基于众筹的视频分发平台](https://ieeexplore.ieee.org/abstract/document/7762143/)\n\n\n这些启发了我们：\n\n- [比特币：P2P电子现金系统](https://bitcoin.org/bitcoin.pdf)\n- [S/Kademlia](https://github.com/thunderdb/research/wiki/Secure-Kademlia)\n    - [S/Kademlia: 一种针对密钥的实用方法](https://ieeexplore.ieee.org/document/4447808/)\n- [vSQL: 验证动态外包数据库上的任意SQL查询](https://ieeexplore.ieee.org/abstract/document/7958614/)\n\n\n## 相关库\n\n### 网络栈\n\n[DH-RPC](rpc/) := TLS - Cert + DHT\n\n| 层              | 应用 |\n|:-------------------|:--------------:|\n| 远程调用协议                |     `net/rpc`    |\n| 寻址             |      [**C**onsistent **S**ecure **DHT**](https://godoc.org/github.com/CovenantSQL/CovenantSQL/consistent)     |\n| 会话池           |  Session Pool  |\n| 多路复用          |      [smux](https://github.com/xtaci/smux)     |\n| 传输安全 |      [**E**nhanced **TLS**](https://github.com/CovenantSQL/research/wiki/ETLS(Enhanced-Transport-Layer-Security))      |\n| 网络            |       TCP or KCP for optional later      |\n\n\n#### 测试工具\n  - [全球网络拓扑模拟器(GNTE)](https://github.com/CovenantSQL/GNTE) 用于网络模拟\n  - [线性一致性测试](https://github.com/anishathalye/porcupine)\n\n\n#### 接口\n\nCovenantSQL仍在建设中，测试网已经发布，[尝试一下](https://developers.covenantsql.io/docs/quickstart).\n\n\n- [Golang](client/)\n- [Java](https://github.com/CovenantSQL/cql-java-driver)\n- [NodeJS](https://github.com/CovenantSQL/node-covenantsql)\n- [Python](https://github.com/CovenantSQL/cql-python-driver)\n- [Microsoft Excel (来自社区)](https://github.com/melancholiaforever/CQL_Excel)\n- Coding for more……\n\n关注我们或[![follow on Twitter](https://img.shields.io/twitter/url/https/twitter.com/fold_left.svg?style=social\u0026label=Follow%20%40CovenantLabs)](https://twitter.com/intent/follow?screen_name=CovenantLabs) 保持更新\n\n## 测试网\n\n- [快捷入口](https://developers.covenantsql.io)\n- [主链浏览器](http://scan.covenantsql.io)\n- [SQL 链浏览器](https://explorer.dbhub.org)\n- [Demo \u0026 论坛](https://demo.covenantsql.io/forum/)\n\n## 联系我们\n\n- [博客](https://medium.com/@covenant_labs)\n- [YouTube](https://www.youtube.com/channel/UCe9P_TMiexSHW2GGV5qBmZw)\n- [邮箱地址](mailto:webmaster@covenantsql.io)\n- [论坛](https://demo.covenantsql.io/forum/)\n- \u003ca href=\"https://twitter.com/intent/follow?screen_name=CovenantLabs\"\u003e\n          \u003cimg src=\"https://img.shields.io/twitter/url/https/twitter.com/fold_left.svg?style=social\u0026label=Follow%20%40CovenantLabs\"\n              alt=\"follow on Twitter\"\u003e\u003c/a\u003e\n- [![Join the chat at https://gitter.im/CovenantSQL/CovenantSQL](https://badges.gitter.im/CovenantSQL/CovenantSQL.svg)](https://gitter.im/CovenantSQL/CovenantSQL?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n- 添加微信: `CovenantSQL` 加入交流群\n    \u003cp align=\"left\"\u003e\n        \u003cimg src=\"logo/wechat.jpeg\" height=\"100\"\u003e\n    \u003c/p\u003e\n\n","funding_links":[],"categories":["Database","Go","数据库","blockchain","Projects","数据库  `go语言实现的数据库`","Uncategorized","Generators","Data Integration Frameworks"],"sub_categories":["Go中实现的数据库","Databases Implemented in Go","Advanced Console UIs","标准 CLI","Databases"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCovenantSQL%2FCovenantSQL","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FCovenantSQL%2FCovenantSQL","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCovenantSQL%2FCovenantSQL/lists"}