forked from deso-protocol/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9491786
Showing
104 changed files
with
79,969 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
workflow_dispatch: | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
|
||
env: | ||
BUILD_CACHE: /home/runner/.docker/buildkit | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
env: | ||
IMAGE_NAME: ghcr.io/${{ github.repository }} | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- uses: actions/cache@v2 | ||
with: | ||
path: ${{ env.BUILD_CACHE }} | ||
key: ${{ runner.os }}-buildkit-v3-${{ github.sha }} | ||
restore-keys: | | ||
${{ runner.os }}-buildkit-v3- | ||
- name: Install the latest buildkit release | ||
run: | | ||
BUILDKIT_URL="$(curl -sL https://api.github.com/repos/moby/buildkit/releases \ | ||
| jq -r 'map(select(.name|startswith("v")))|sort_by(.name)[-1].assets[]|select(.name|endswith(".linux-amd64.tar.gz")).browser_download_url')" | ||
curl -L "${BUILDKIT_URL}" | sudo tar -xz -C /usr/local | ||
- name: Start buildkit daemon | ||
run: | | ||
sudo --non-interactive --shell <<END_SUDO | ||
install -d -m 0750 -o root -g docker /run/buildkit | ||
buildkitd & | ||
while ! test -S /run/buildkit/buildkitd.sock; do sleep 0.1; done | ||
chgrp docker /run/buildkit/buildkitd.sock | ||
END_SUDO | ||
- uses: docker/login-action@v1 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Build docker image | ||
run: | | ||
buildctl build \ | ||
--frontend=dockerfile.v0 --local dockerfile=. --local context=. \ | ||
--export-cache type=local,dest=${{ env.BUILD_CACHE }},mode=max \ | ||
--import-cache type=local,src=${{ env.BUILD_CACHE }} \ | ||
--output type=docker,name=${{ env.IMAGE_NAME }} | docker load | ||
echo "Cache size: $(du -sh ${{ env.BUILD_CACHE }})" | ||
- name: Tag stable | ||
if: contains(github.event.head_commit.message, '[stable]') | ||
run: | | ||
docker tag ${{ env.IMAGE_NAME }} ${{ env.IMAGE_NAME }}:stable | ||
- name: Tag and push | ||
if: ${{ github.ref == 'refs/heads/main' }} | ||
run: | | ||
docker tag ${{ env.IMAGE_NAME }} ${{ env.IMAGE_NAME }}:${{ github.sha }} | ||
docker push --all-tags ${{ env.IMAGE_NAME }} | ||
test: | ||
runs-on: ubuntu-latest | ||
env: | ||
IMAGE_NAME: ghcr.io/${{ github.repository }}-test | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- uses: actions/cache@v2 | ||
with: | ||
path: ${{ env.BUILD_CACHE }} | ||
key: ${{ runner.os }}-buildkit-test-v2-${{ github.sha }} | ||
restore-keys: | | ||
${{ runner.os }}-buildkit-test-v2- | ||
- name: Install the latest buildkit release | ||
run: | | ||
BUILDKIT_URL="$(curl -sL https://api.github.com/repos/moby/buildkit/releases \ | ||
| jq -r 'map(select(.name|startswith("v")))|sort_by(.name)[-1].assets[]|select(.name|endswith(".linux-amd64.tar.gz")).browser_download_url')" | ||
curl -L "${BUILDKIT_URL}" | sudo tar -xz -C /usr/local | ||
- name: Start buildkit daemon | ||
run: | | ||
sudo --non-interactive --shell <<END_SUDO | ||
install -d -m 0750 -o root -g docker /run/buildkit | ||
buildkitd & | ||
while ! test -S /run/buildkit/buildkitd.sock; do sleep 0.1; done | ||
chgrp docker /run/buildkit/buildkitd.sock | ||
END_SUDO | ||
- name: Build docker image | ||
run: | | ||
buildctl build \ | ||
--frontend=dockerfile.v0 --local dockerfile=. --local context=. --opt filename=./test.Dockerfile \ | ||
--export-cache type=local,dest=${{ env.BUILD_CACHE }},mode=max \ | ||
--import-cache type=local,src=${{ env.BUILD_CACHE }} \ | ||
--output type=docker,name=${{ env.IMAGE_NAME }} | docker load | ||
echo "Cache size: $(du -sh ${{ env.BUILD_CACHE }})" | ||
- name: Run tests | ||
run: | | ||
docker run ${{ env.IMAGE_NAME }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
gopath | ||
bin | ||
quick_testing | ||
dump_txns | ||
compare_blocks.go | ||
backend | ||
|
||
.idea | ||
|
||
local_scripts/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# For now, tag everyone who wants to participate | ||
* @bitclout/reviewers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
FROM alpine:edge AS core | ||
|
||
RUN apk update | ||
RUN apk upgrade | ||
RUN apk add --update go=1.16.4-r0 gcc g++ vips vips-dev | ||
|
||
WORKDIR /bitclout/src/core | ||
|
||
COPY third_party third_party | ||
COPY go.mod . | ||
COPY go.sum . | ||
|
||
RUN go mod download | ||
|
||
COPY clouthash clouthash | ||
COPY cmd cmd | ||
COPY lib lib | ||
COPY test_data test_data | ||
COPY main.go . | ||
|
||
# build backend | ||
RUN GOOS=linux go build -mod=mod -a -installsuffix cgo -o bin/core main.go | ||
|
||
# create tiny image | ||
FROM alpine:edge | ||
|
||
RUN apk add --update vips-dev | ||
|
||
COPY --from=core /bitclout/src/core/bin/core /bitclout/bin/core |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
 | ||
|
||
# About BitClout | ||
BitClout is a blockchain built from the ground up to support a fully-featured | ||
social network. Its architecture is similar to Bitcoin, only it supports complex | ||
social network data like profiles, posts, follows, creator coin transactions, and | ||
more. | ||
|
||
[Read about the vision](https://docs.bitclout.com/the-vision) | ||
|
||
# About this Repo | ||
|
||
This repo contains all of the consensus code for the BitClout protocol. While it can | ||
technically be built and run as a stand-alone binary, it is mainly intended to be | ||
"composed" into other projects that want to build on top of BitClout. We provide | ||
multiple examples of how to do this in this README. | ||
|
||
# Building on BitClout Core | ||
|
||
We currently have two examples of how to compose BitClout core into your project. | ||
|
||
## Example 1: A BitClout Website (aka [bitclout.com](https://bitclout.com)) | ||
|
||
The code that powers [bitclout.com](https://bitclout.com) is fully open-source | ||
such that anyone in the world can run it, and it consists of three repositories: | ||
* **[github.com/bitclout/backend](https://github.com/bitclout/backend)** | ||
* **[github.com/bitclout/frontend](https://github.com/bitclout/frontend)** | ||
* **[github.com/bitclout/identity](https://github.com/bitclout/identity)** | ||
|
||
The repo that is most interesting for understanding the role of BitClout core is | ||
[backend](https://github.com/bitclout/backend) because it effectively includes core | ||
as a library and [uses its public API](https://FIXME) | ||
to run a node. Then, it builds on core's basic | ||
functionality to expose [a rich API](https://FIXME) of its own that can be used to | ||
construct transactions, submit transactions to the network, manage user data, and | ||
much more. | ||
|
||
The backend repo's API is then utilized by | ||
[frontend](https://github.com/bitclout/frontend) and | ||
[identity](https://github.com/bitclout/identity), which are Angular apps that are | ||
served as the frontend to [bitclout.com](https://bitclout.com). | ||
|
||
## Example 2: A Rosetta API for Exchange Listing | ||
|
||
[Rosetta](https://rosetta-api.org) is an API developed by Coinbase and used by | ||
exchanges all over the world to list coins. For most modern exchanges, implementing a | ||
Rosetta API makes it a breeze to integrate a coin because all of their infrastructure | ||
can plug into a standardized interface. | ||
|
||
Because exchanges have a different set of needs than what's required to run a | ||
BitClout web app, composing core allowed us | ||
to build a fully Dockerized Rosetta API that conforms perfectly to spec as its own | ||
self-contained service. This allows exchanges to integrate BitClout without having | ||
to run the unnecessary services associated with serving bitclout.com. | ||
|
||
For more information on the BitClout Rosetta API, see our bitclout-rosetta repo here: | ||
* **[github.com/bitclout/rosetta-api](https://github.com/bitclout/rosetta-api)** | ||
|
||
## Example 3: A MongoDB Data Dumper | ||
|
||
Another example of composing the core repo is the BitClout MongoDB Dumper. | ||
* **[github.com/bitclout/mongo-dumper](https://github.com/bitclout/mongo-dumper)** | ||
|
||
This tool does the following: | ||
* It includes core as a library | ||
* It uses its embedded core code to download all of the blockchain data | ||
* It takes all of the blockchain data and indexes it into MongoDB | ||
|
||
This gives users the ability to query all of the chain data using the MongoDB | ||
commandline tool, or to layer a product like Retool on top of it. | ||
|
||
# Running BitClout Core | ||
|
||
Because core is intended to be composed into other projects, we suggest that | ||
users who want to run it start by reading [the README in the backend repo](https://github.com/bitclout/backend) | ||
mentioned previously. This repo provides instructions on how set up a dev environment | ||
for a full frontend and backend stack that can serve a full clone | ||
of [bitclout.com](https://bitclout.com) with one's own custom feed. | ||
|
||
We also provide a [run repo](https://github.com/bitclout/run) that shows how to | ||
run this full stack in a fully Dockerized production environment. | ||
|
||
# Acknowledgements | ||
|
||
The architecture for BitClout was heavily-inspired by Bitcoin. We also owe a debt | ||
of gratitude to the developers of [btcd](https://github.com/btcsuite/btcd) for | ||
producing a truly amazing Go Bitcoin client that served as a reference when | ||
building BitClout. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package clouthash | ||
|
||
import ( | ||
"crypto/sha256" | ||
|
||
"github.com/bitclout/core/clouthash/sha3m" | ||
"golang.org/x/crypto/sha3" | ||
) | ||
|
||
var CloutHashV1MixConstant = [32]byte{140, 179, 163, 187, 73, 73, 228, 174, 70, 139, 110, 123, 77, 160, 46, 52, 165, 81, 68, 184, 179, 231, 190, 73, 152, 85, 103, 158, 216, 208, 207, 245} | ||
|
||
func CloutHashV1(input []byte) [32]byte { | ||
result := sha3m.Sum256(input[:]) | ||
|
||
for i, c := range CloutHashV1MixConstant { | ||
result[i] ^= c | ||
} | ||
|
||
return result | ||
} | ||
|
||
func CloutHashV0(input []byte) [32]byte { | ||
output := sha256.Sum256(input) | ||
|
||
for ii := 0; ii < 100; ii++ { | ||
if ii%7 == 0 { | ||
output = sha3.Sum256(output[:]) | ||
} | ||
output = sha256.Sum256(output[:]) | ||
} | ||
|
||
return output | ||
} |
Oops, something went wrong.