Skip to content

Commit

Permalink
add admin permission controller (#501)
Browse files Browse the repository at this point in the history
* feat: add doc store

* feat: merge sdk into db3

* fix: fix the contract test case

* fix: fix the test case

* fix: add protobuf generator

* fix: add protobuf generator

* feat: add record arweave tx to smart contract

* fix: fix the case

* feat: add new readme

* fix: remove the test large case

* feat: add arch png

* feat: update docker cd
  • Loading branch information
imotai committed Jun 25, 2023
1 parent 2b5a689 commit e4069c6
Show file tree
Hide file tree
Showing 73 changed files with 14,145 additions and 387 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,13 @@ jobs:
- name: Run rust test with coverage
run: |
cargo llvm-cov nextest --workspace --exclude merkdb --lcov --output-path lcov.info --no-fail-fast
- name: Run sdk test
run: |
ROOT_DIR=`pwd`
cd $ROOT_DIR/sdk && yarn && make
cd $ROOT_DIR/sdk && yarn test --coverage
- uses: codecov/codecov-action@v3
with:
token: ${{secrets.COV_TOKEN}}
directory: .
flags: rust

2 changes: 1 addition & 1 deletion .github/workflows/docker_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
sudo apt-get install protobuf-compiler
protoc --version
ROOT_DIR=`pwd`
cd ${ROOT_DIR}/metadata && yarn install && npx hardhat compile
cd ${ROOT_DIR}/metadata && yarn install && npx hardhat test
ls ${ROOT_DIR}/metadata/artifacts/contracts/DB3MetaStore.sol/
cd ${ROOT_DIR} && cargo build
cp ${ROOT_DIR}/target/debug/db3 ${ROOT_DIR}/docker/
Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/docker_release_cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Docker Release CD
on:
push:
tags:
- "[v]?[0-9]+.[0-9]+.[0-9]+"
jobs:

docker_image:
name: build_pr_image
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
profile: minimal
override: true
components: rustfmt
- uses: Swatinem/rust-cache@v2
- uses: taiki-e/install-action@cargo-llvm-cov
- uses: taiki-e/install-action@nextest
- name: Setup build env
run: |
sudo apt-get install protobuf-compiler
protoc --version
ROOT_DIR=`pwd`
cd ${ROOT_DIR}/metadata && yarn install && npx hardhat test
ls ${ROOT_DIR}/metadata/artifacts/contracts/DB3MetaStore.sol/
cd ${ROOT_DIR} && cargo build --release
cp ${ROOT_DIR}/target/release/db3 ${ROOT_DIR}/docker/
- name: docker login
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build Docker image
run: |
RELEASE_NAME=${GITHUB_REF/refs\/tags\//}
cd docker && docker build . -t ghcr.io/dbpunk-labs/db3:$RELEASE_NAME
docker push ghcr.io/dbpunk-labs/db3:$RELEASE_NAME
echo "the image is ghcr.io/dbpunk-labs/db3:$RELEASE_NAME"
24 changes: 24 additions & 0 deletions .github/workflows/sdk_cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: CD
on:
push:
tags:
- "[v]?[0-9]+.[0-9]+.[0-9]+"
jobs:
npm_publish:
name: Publish Package to npmjs
runs-on: ubuntu-latest
steps:
- name: checkout db3.js
uses: actions/checkout@v3
with:
submodules: recursive
- uses: actions/setup-node@v3.5.1
with:
node-version: "16.x"
- uses: CultureHQ/actions-yarn@v1.0.1
- run: |
cd sdk && yarn && make && yarn build
- uses: JS-DevTools/npm-publish@v1
with:
token: ${{ secrets.NPM_TOKEN }}
package: ./sdk/package.json
10 changes: 6 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ indexer
tools/mutation_db
tools/doc_db
tools/state_db
bridge/artifacts
bridge
tools/index_doc_db
tools/index_meta_db
/sdk/node_modules/
/sdk/.bin/
/sdk/.yarn/
/sdk/cache/
/sdk/typechain/
/sdk/src/proto/*.ts
11 changes: 11 additions & 0 deletions BUILD.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# How to build

## Prepare the environment

* cmake >= 3.27.0
* protobuf
* node >= 18
* yarn
* arlocal
* rust with nightly default

15 changes: 11 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Contribution guidelines

First off, thank you for considering contributing to db3.
First off, thank you for considering contributing to db3 network

If your contribution is not straightforward, please first discuss the change you
wish to make by creating a new issue before making the change.
Expand All @@ -22,16 +22,23 @@ git clone https://github.com/dbpunk-labs/db3.git
cd db3 & bash install_env.sh
```

2. compile the bridge contract
2. compile the metadata contract
```shell
cd bridge && yarn && npx hardhat test
cd metadata && yarn && npx hardhat test
```

3. build the db3 binary

```shell
cargo build
```
4. build typescript sdk

```shell
cd sdk && make && yarn && yarn build
```

### Start local testnet
### Start Local Test Environment

```
cd tools && bash start_localtestnet.sh
Expand Down
130 changes: 47 additions & 83 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<p align="center">
<img width="300px" src="./docs/images/db3_logo.svg" align="center"/>
<p align="center"> A ⭐️ is welcome!

<p align="center">

![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/dbpunk-labs/db3/ci.yml?branch=main&style=flat-square)
![coverage](https://img.shields.io/codecov/c/github/dbpunk-labs/db3?style=flat-square)
Expand All @@ -14,109 +11,76 @@
[![GitPOAP Badge](https://public-api.gitpoap.io/v1/repo/dbpunk-labs/db3/badge)](https://www.gitpoap.io/gh/dbpunk-labs/db3)
[![Discord](https://badgen.net/badge/icon/discord?icon=discord&label)](https://discord.gg/sz3bmZx2uh)

**English | [中文](./README_zh_cn.md)**

## DB3 Network

DB3 Network is a robust and secure **decentralized data network** designed to tackle the expected problems faced by dApps. These applications frequently require the ability to **CRUD** vast amounts of user-generated data, all while maintaining a decentralized architecture. By utilizing DB3 Network, you can effortlessly create data-intensive applications such as social networking apps, gamefi, and more.

<p align="center">
<img width="500px" src="./docs/images/db3_overview.png" align="center"/>

## **Guide Line of DB3**

---

- Before create your dApp, you need to create database or find the existing database you can use on **[DMS website](./docs/build/data_manager.md)**
- Try **[Quick Start](./docs/build/quick_start.md)** or based on **[ReactJS Demo](./docs/build/demos/js_demo.md)** to build your dApps with DB3 Network as your decentralized database
- Since running a dApp need connect with a node, you can ether find a existing node from **[Commuity nodes](./docs/build/node/community_node.md)** or
- Try **[Run Local Node](./docs/build/node/run_locally.md)** to host your own nodes
<!-- - Go deeper by reading **[Network](../network/overview.md)** and the **[Advanced](../advanced/overview.md)**specification -->

## **Build dApps**

---

### **[Refer to DB3.js =>](https://github.com/dbpunk-labs/db3.js)**

DB3 Network is a database the same as Firestore but in a decentralized way. DApps can directly interact with DB3 Network with db3 client. A properly designed `db3.js` package allow you do the "CRUD" job in the client never be easier

## **Run DB3 Node**
**English**

---
# DB3 Network

DB3 network is community owned and everyone is ecouraged to be part of the network. You can run a DB3 node to provide data storage, compute and bandwidth for dApps and earn make a good profit from that.
DB3 Network is a lightweight, permanent JSON document database for Web3. It is designed to store and retrieve data for decentralized applications built on blockchain technology. DB3 Network has two core features:

- **[Run Locally Node](./docs/build/node/run_locally.md)**
1. Using DB3 Network as a JSON document database.
2. Periodically rolling up the JSON document to the Arweave.

## DEMOS
# Have a try

- **[Create database](https://dms.db3.network)** and the related **[Github repository](https://github.com/dbpunk-labs/data-manager)**
- **[Message wall](https://message-wall-iota.vercel.app/)** A website where people can login with metamask and leave a message and the project **[Github repository](https://github.com/dbpunk-labs/message-wall)**
- **[Todo MVC](https://db3-network-crud-todomvc-demo.imotai.repl.co/)** and the related **[Github repository](https://github.com/dbpunk-labs/db3.js/tree/main/examples)**
## Build

## Why DB3 Network
```shell
git clone https://github.com/dbpunk-labs/db3.git
cd db3 && bash install_env.sh
cargo build
```
If you encounter any problems, you can check the environment by referring to [BUILD](./BUILD.md).

![why db3](./docs/images/why_db3.svg)
## Write And Query the Document

Currently, there are two types of Data architecture for dApp(decentralized application): centralized vs. decentralized.
```typescript
const account = createRandomAccount()
const client = createClient('http://127.0.0.1:26619',
'http://127.0.0.1:26639',
account)
const collection = await getCollection("0xF7..79", "book", client)
const [mutation, block, order, id] = await addDoc(collection, {
name:"The Three-Body Problem"
author:"Cixin-Liu",
rate:"4.8"
} as Book)
const resultSet = await queryDoc<Book>(collection, "/[author=Cixin-Liu]")
```
you can go to [sdk](https://dbpunk-labs.github.io/db3.js/) for more

**Centralized**: use [Firebase](https://firebase.google.com)<img height="20" width="20" src="https://cdn.jsdelivr.net/npm/simple-icons@v8/icons/firebase.svg" />
or [MongoDB](https://github.com/mongodb/mongo)<img height="20" width="20" src="https://cdn.jsdelivr.net/npm/simple-icons@v8/icons/mongodb.svg" />to store the data), both of which are developer-friendly. However, dApps would be regarded as less secure based on a central database.

**Decentralized**: use Ethereum<img height="20" width="20" src="https://cdn.jsdelivr.net/npm/simple-icons@v8/icons/ethereum.svg" /> or other blockchains to store the data and use [the Graph](https://thegraph.com/en/) to index data from it. The separation of the storage and the indexer would cost a lot of engineering efforts in future development.

With Db3 network, you can get both advantages of the above two choices.

# Features

**Schemaless**

You can store data on DB3 Network without any change.

**High Performance**

Currently, decentralization means terrible performance, but DB3 is trying to improve it significantly:

- [Merkdb](https://github.com/dbpunk-labs/db3/issues/100) is the storage engine of the DB3 Network, and it has high Performance and fast-proof generation.
- Geo distribution: the nodes in every storage shard are geo-distributed, and the clients can execute queries against the nearest storage node.
- [Query session](./docs/query.md), the first decentralized query protocol to resolve Performance and incentive perfectly.

**Data Ownership**

We proposed [the document level ownership](https://github.com/dbpunk-labs/db3/issues/271), and every document has its owner, while only the owner holds the private key can update/delete the record. DB3 network generates the proofs and provides signatures to prove the membership (db3 has the specific document) and ownership.
# How it works

**Programmable**
The DB3 Network has two roles:

Dapp developers can develop data processing contracts and deploy them to the DB3 Network, just like the data backend in web2.
1. The **Data Rollup Node** accepts write operations, compresses the data, rolls it up to Arweave, and stores the metadata in the smart contract.
2. The **Data Index Node** synchronizes data from the Data Rollup Node in real-time or recovers the index with metadata in the smart contract and files in Arweave. It serves the index as a queryable API.

**Ethereum Guarded Security**
To prevent tampering, every
JSON document must be signed by its owner. Only the owner can update or delete the JSON document.
<p align="center">
<img width="500px" src="./docs/images/db3_arch.png" align="center"/>

DB3 Network is a layer2 network on Ethereum and Ethereum guards all the assets.

# Project assistance
# What can we build with the db3 network?

- Add a GitHub Star⭐️ to the project.
- Tweet about how to use DB3 network.
- Write blogs about the project on [Dev.to](https://dev.to/), [Medium](https://medium.com/) or your personal blog.
1. A fully on-chain game.
2. A fully on-chain social network.

Together, we can make db3 network better!
All user data will be stored permanently on the DB3 network.

# FAQ

# How it works
Q: Is the DB3 Network a blockchain?

go to the [dips](https://github.com/dbpunk-labs/DIPs) for more
A: No, the DB3 Network is not a blockchain. It is simply a developer tool that can be hosted locally or used through our cloud service.

# Other Decentralized Database
Q: What are the differences between MongoDB and DB3 Network?

- [the graph](https://github.com/graphprotocol/graph-node), a decentralized on-chain indexer
- [Locutus](https://github.com/freenet/locutus), a decentralized key-value database
- [ceramic network](https://github.com/ceramicnetwork/ceramic), a decentralized data network that brings unlimited data composability to Web3 applications
- [kwil](https://github.com/kwilteam), the first permissionless SQL database for the decentralized internet
- [spaceandtime](https://www.spaceandtime.io/), a decentralized data Warehouse
- [OrbitDB](https://github.com/orbitdb/orbit-db) is a serverless, distributed, peer-to-peer database
A: MongoDB uses centralized data storage, whereas DB3 Network uses decentralized data storage. Additionally, DB3 Network ensures that data is permanently available.

Q: Will my data be lost if the Data Rollup Node or Data Index Node is not available?

A: No, you can set up your data index node and recover your data from the blockchain.
# License

Apache License, Version 2.0
Expand Down
Binary file added docs/images/db3_arch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 17 additions & 3 deletions docs/images/db3_arch.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 3 additions & 4 deletions format.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#! /bin/bash

WORKSPACE=`pwd`
cargo fmt
npx buf format -w src/proto/proto
#cd metadata && npx prettier --write 'contracts/**/*.sol'


cd ${WORKSPACE}/metadata && npx prettier --write 'contracts/**/*.sol'
cd ${WORKSPACE}/sdk && yarn prettier --write src tests ./jest.setup.ts ./jest.config.ts
3 changes: 2 additions & 1 deletion install_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ git submodule update
echo "install yarn "
corepack enable
corepack prepare yarn@stable --activate

echo "install ar local"
yarn global add arlocal
10 changes: 2 additions & 8 deletions metadata/contracts/DB3MetaStore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ contract DB3MetaStore is IDB3MetaStore {
"Network not registered"
);

// Check if sender is the same as admin
// Check if sender is the same as admin
require(
msg.sender == registration.admin,
"msg.sender must be the same as registration.admin "
Expand All @@ -86,7 +86,6 @@ contract DB3MetaStore is IDB3MetaStore {
bytes(registration.rollupNodeUrl).length > 0,
"Network not registered"
);

// Return registration info
return registration;
}
Expand Down Expand Up @@ -210,17 +209,12 @@ contract DB3MetaStore is IDB3MetaStore {
NetworkRegistration storage registration = networkRegistrations[
networkId
];
require(
bytes(registration.rollupNodeUrl).length > 0,
"Network not registered"
);

require(registration.admin != address(0), "Network not registered");
// Check if sender is the same as rollupNodeAddress
require(
msg.sender == registration.rollupNodeAddress,
"msg.sender must be the same as RollupNodeAddress"
);

// Update latest Arweave transaction in registration struct
registration.latestArweaveTx = latestArweaveTx;
return true;
Expand Down
Loading

0 comments on commit e4069c6

Please sign in to comment.