Skip to content

Commit

Permalink
Merge pull request #1 from deep-foundation/testnet
Browse files Browse the repository at this point in the history
Testnet
  • Loading branch information
cyborgshead authored Jan 16, 2024
2 parents d2de6cc + 0f619aa commit 44ef8ea
Show file tree
Hide file tree
Showing 198 changed files with 2,736 additions and 2,156 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
cd ~/workdir
git clone -q --depth 1 https://${DOCS_GITHUB_TOKEN}@github.com/cybercongress/congress.git
- deploy:
name: Update docs from go-cyber repo
name: Update docs from deepchain repo
working_directory: ~/workdir/congress
command: |
# We need to remove current files in folder to avoid duplicating renamed files
Expand Down
35 changes: 35 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
run:
# timeout for analysis, e.g. 30s, 5m, default is 1m
timeout: 10m
tests: true

linters:
disable-all: true
enable:
- bodyclose
- depguard
- dogsled
- errcheck
- goconst
- gocritic
- gofumpt
- revive
- gosec
- gosimple
- govet
- ineffassign
- misspell
- nakedret
- exportloopref
- staticcheck
- stylecheck
- typecheck
- unconvert
- unused
- unparam
- misspell

linters-settings:
gosec:
excludes:
- G404
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ nfpm:
description: Distributed search engine
maintainer: Cyber Admin <[email protected]>
license: MIT
vendor: cyber.Congress
vendor: deepchain
formats:
- deb
- rpm
Expand Down
33 changes: 11 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
###########################################################################################
# Build cyber
# Build deepchain
###########################################################################################
FROM ubuntu:20.04

ENV GO_VERSION '1.17.8'
ENV GO_ARCH 'linux-amd64'
ENV GO_BIN_SHA '980e65a863377e69fd9b67df9d8395fd8e93858e7a24c9f55803421e453f4f99'
ENV DEBIAN_FRONTEND=noninteractive
ENV DAEMON_HOME /root/.cyber
ENV DAEMON_HOME /root/.deepchain
ENV DAEMON_RESTART_AFTER_UPGRADE=true
ENV DAEMON_ALLOW_DOWNLOAD_BINARIES=false
ENV DAEMON_LOG_BUFFER_SIZE=1048
ENV UNSAFE_SKIP_BACKUP=true
ENV DAEMON_NAME cyber
ENV DAEMON_NAME deepchain
ENV BUILD_DIR /build
ENV PATH /usr/local/go/bin:/root/.cargo/bin:/root/cargo/env:/root/.cyber/scripts:$PATH
ENV PATH /usr/local/go/bin:/root/.cargo/bin:/root/cargo/env:/root/.deepchain/scripts:$PATH
ENV CUDA_VER '11.4.4-1'
ENV PATH="/usr/local/go/bin:/usr/local/cuda/bin:$PATH"

Expand All @@ -32,7 +32,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends wget ca-certifi
COPY . /sources
WORKDIR /sources

# Install CUDA, build tools and compile cyber
# Install CUDA, build tools and compile deepchain
###########################################################################################
RUN apt-get -y install --no-install-recommends \
make gcc g++ \
Expand All @@ -48,26 +48,15 @@ RUN apt-get -y install --no-install-recommends \
&& add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/ /" \
&& apt-get update \
&& apt-get install cuda=${CUDA_VER} -y --no-install-recommends \
&& mkdir -p /cyber/cosmovisor/genesis/bin \
&& mkdir -p /cyber/cosmovisor/upgrades/cyberfrey/bin \
# Compile cyber for genesis version
&& mkdir -p /deepchain/cosmovisor/genesis/bin \
# Compile deepchain for genesis version
###########################################################################################
&& git checkout v0.2.0 \
&& cd /sources/x/rank/cuda \
&& make build \
&& cd /sources \
&& make build CUDA_ENABLED=true \
&& cp ./build/cyber /cyber/cosmovisor/genesis/bin/ \
&& cp ./build/cyber /usr/local/bin \
&& rm -rf ./build \
# Compile cyber for genesis version
###########################################################################################
&& git checkout v0.3.0 \
&& cd /sources/x/rank/cuda \
&& make build \
&& cd /sources \
&& make build CUDA_ENABLED=true \
&& cp ./build/cyber /cyber/cosmovisor/upgrades/cyberfrey/bin/ \
&& make build CUDA_ENABLED=false \
&& cp ./build/deepchain /deepchain/cosmovisor/genesis/bin/ \
&& cp ./build/deepchain /usr/local/bin \
&& rm -rf ./build \
# Cleanup
###########################################################################################
Expand Down Expand Up @@ -99,7 +88,7 @@ COPY entrypoint.sh /entrypoint.sh
RUN wget -O /genesis.json https://gateway.ipfs.cybernode.ai/ipfs/QmYubyVNfghD4xCrTFj26zBwrF9s5GJhi1TmxvrwmJCipr \
&& chmod +x start_script.sh \
&& chmod +x /entrypoint.sh \
&& cyber version
&& deepchain version


# Start
Expand Down
38 changes: 21 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ whitespace += $(whitespace)
comma := ,
build_tags_comma_sep := $(subst $(whitespace),$(comma),$(build_tags))

ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=cyber \
-X github.com/cosmos/cosmos-sdk/version.AppName=cyber \
ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=deepchain \
-X github.com/cosmos/cosmos-sdk/version.AppName=deepchain \
-X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \
-X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \
-X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep)" \
Expand All @@ -80,27 +80,32 @@ all: build format lint test
###############################################################################

build: go.sum
go build $(BUILD_FLAGS) -o $(BUILDDIR) ./cmd/cyber
go build $(BUILD_FLAGS) -o $(BUILDDIR) ./cmd/deepchain


build-linux: go.sum
LEDGER_ENABLED=false GOOS=linux GOARCH=amd64 $(MAKE) build
# mkdir -p ./build
# docker build --tag cybercongress/cyber ./
# docker create --name temp cybercongress/cyber:latest
# docker cp temp:/usr/bin/cyber ./build/
# docker build --tag cybercongress/deepchain ./
# docker create --name temp cybercongress/deepchain:latest
# docker cp temp:/usr/bin/deepchain ./build/
# docker rm temp

install: go.sum
go install $(BUILD_FLAGS) ./cmd/cyber
go install $(BUILD_FLAGS) ./cmd/deepchain

run:
$(BUILDDIR)/cyber --home $(BUILDDIR)/bostrom-dev start
$(BUILDDIR)/cyber --home $(BUILDDIR)/deepchain-dev start

###############################################################################
### Tools / Dependencies ###
###############################################################################

format-tools:
go install mvdan.cc/[email protected]
go install github.com/client9/misspell/cmd/[email protected]
go install golang.org/x/tools/cmd/goimports@latest

go-mod-cache: go.sum
@echo "--> Download go modules to local cache"
@go mod download
Expand All @@ -112,21 +117,20 @@ go.sum: go.mod
go mod tidy -compat=1.17
.PHONY: go.sum

lint:
$(BINDIR)/golangci-lint run
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "*.pb.go" | xargs gofmt -d -s
go mod verify
lint: format-tools
golangci-lint run --tests=false
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "*_test.go" | xargs gofumpt -d
.PHONY: lint

statik:
$(GO) get -u github.com/rakyll/statik
$(GO) generate ./api/...
.PHONY: statik

format:
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "*.pb.go" | xargs gofmt -w -s
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "*.pb.go" | xargs misspell -w
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "*.pb.go" | xargs goimports -w -local github.com/cybercongress/go-cyber
format: format-tools
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/docs/statik/statik.go" | xargs gofumpt -w
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/docs/statik/statik.go" | xargs misspell -w
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/docs/statik/statik.go" | xargs goimports -w -local github.com/deep-foundation/deep-chain
.PHONY: format

###############################################################################
Expand All @@ -150,7 +154,7 @@ localnet-stop:
### Protobuf ###
###############################################################################

HTTPS_GIT := https://github.com/cybercongress/go-cyber.git
HTTPS_GIT := https://github.com/deep-foundation/deep-chain.git
DOCKER := $(shell which docker)
DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# DEEPCHAIN
# DEEP CYBER HACKATHON January 2024


# Semantic non-deterministic Superintelligence consensus computer
# Cyber - SuperIntelligence for The Great Web

Expand Down
57 changes: 27 additions & 30 deletions app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@ package app

import (
"fmt"

"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
"github.com/cosmos/cosmos-sdk/x/auth/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"

ctypes "github.com/cybercongress/go-cyber/types"
ctypes "github.com/deep-foundation/deep-chain/types"

authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
ibcante "github.com/cosmos/ibc-go/v3/modules/core/ante"
"github.com/cosmos/ibc-go/v3/modules/core/keeper"
bandwidthkeeper "github.com/cybercongress/go-cyber/x/bandwidth/keeper"
bandwidthtypes "github.com/cybercongress/go-cyber/x/bandwidth/types"
graphtypes "github.com/cybercongress/go-cyber/x/graph/types"
wasmTypes "github.com/CosmWasm/wasmd/x/wasm/types"

bandwidthkeeper "github.com/deep-foundation/deep-chain/x/bandwidth/keeper"
bandwidthtypes "github.com/deep-foundation/deep-chain/x/bandwidth/types"
graphtypes "github.com/deep-foundation/deep-chain/x/graph/types"
)

// HandlerOptions are the options required for constructing a default SDK AnteHandler.
Expand All @@ -31,16 +31,16 @@ type HandlerBaseOptions struct {
FeegrantKeeper ante.FeegrantKeeper
BandwidthMeter *bandwidthkeeper.BandwidthMeter
SignModeHandler authsigning.SignModeHandler
SigGasConsumer func(meter sdk.GasMeter, sig signing.SignatureV2, params types.Params) error
SigGasConsumer func(meter sdk.GasMeter, sig signing.SignatureV2, params authtypes.Params) error
}

// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC
// channel keeper.
type HandlerOptions struct {
HandlerBaseOptions

IBCKeeper *keeper.Keeper
WasmConfig *wasmTypes.WasmConfig
IBCKeeper *keeper.Keeper
WasmConfig *wasmtypes.WasmConfig
TXCounterStoreKey sdk.StoreKey
}

Expand All @@ -64,7 +64,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "tx counter key is required for ante builder")
}

var sigGasConsumer = options.SigGasConsumer
sigGasConsumer := options.SigGasConsumer
if sigGasConsumer == nil {
sigGasConsumer = ante.DefaultSigVerificationGasConsumer
}
Expand Down Expand Up @@ -94,11 +94,10 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
}

type DeductFeeBandDecorator struct {
ak ante.AccountKeeper
bankKeeper bankkeeper.Keeper
bandMeter *bandwidthkeeper.BandwidthMeter
feegrantKeeper ante.FeegrantKeeper

ak ante.AccountKeeper
bankKeeper bankkeeper.Keeper
bandMeter *bandwidthkeeper.BandwidthMeter
feegrantKeeper ante.FeegrantKeeper
}

func NewDeductFeeBandRouterDecorator(
Expand All @@ -116,7 +115,6 @@ func NewDeductFeeBandRouterDecorator(
}

func (drd DeductFeeBandDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {

feeFlag := false
feeSplitFlag := false
bandwidthFlag := false
Expand Down Expand Up @@ -152,8 +150,8 @@ func (drd DeductFeeBandDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulat
return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx")
}

if addr := drd.ak.GetModuleAddress(types.FeeCollectorName); addr == nil {
panic(fmt.Sprintf("%s module account has not been set", types.FeeCollectorName))
if addr := drd.ak.GetModuleAddress(authtypes.FeeCollectorName); addr == nil {
panic(fmt.Sprintf("%s module account has not been set", authtypes.FeeCollectorName))
}

fee := feeTx.GetFee()
Expand All @@ -168,7 +166,6 @@ func (drd DeductFeeBandDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulat
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "fee grants are not enabled")
} else if !feeGranter.Equals(feePayer) {
err := drd.feegrantKeeper.UseGrantedFees(ctx, feeGranter, feePayer, fee, tx.GetMsgs())

if err != nil {
return ctx, sdkerrors.Wrapf(err, "%s not allowed to pay fees from %s", feeGranter, feePayer)
}
Expand Down Expand Up @@ -220,19 +217,19 @@ func (drd DeductFeeBandDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulat
currentBlockSpentBandwidth := drd.bandMeter.GetCurrentBlockSpentBandwidth(ctx)
maxBlockBandwidth := drd.bandMeter.GetMaxBlockBandwidth(ctx)

//nolint:gocritic
if !simulate {
if !accountBandwidth.HasEnoughRemained(txCost) {
return ctx, bandwidthtypes.ErrNotEnoughBandwidth
} else if (txCost + currentBlockSpentBandwidth) > maxBlockBandwidth {
} else if (txCost + currentBlockSpentBandwidth) > maxBlockBandwidth {
return ctx, bandwidthtypes.ErrExceededMaxBlockBandwidth
} else {
if !ctx.IsCheckTx() && !ctx.IsReCheckTx() {
err = drd.bandMeter.ConsumeAccountBandwidth(ctx, accountBandwidth, txCost); if err != nil {
return ctx, err
}
// TODO think to add to transient store
drd.bandMeter.AddToBlockBandwidth(txCost)
} else if !ctx.IsCheckTx() && !ctx.IsReCheckTx() {
err = drd.bandMeter.ConsumeAccountBandwidth(ctx, accountBandwidth, txCost)
if err != nil {
return ctx, err
}
// TODO think to add to transient store
drd.bandMeter.AddToBlockBandwidth(txCost)
}
}
return next(ctx, tx, simulate)
Expand All @@ -248,13 +245,13 @@ func DeductFees(bankKeeper bankkeeper.Keeper, ctx sdk.Context, acc authtypes.Acc
}

if program2pay == nil {
err := bankKeeper.SendCoinsFromAccountToModule(ctx, acc.GetAddress(), types.FeeCollectorName, fees)
err := bankKeeper.SendCoinsFromAccountToModule(ctx, acc.GetAddress(), authtypes.FeeCollectorName, fees)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, err.Error())
}
} else {
feeInCYB := sdk.NewDec(fees.AmountOf(ctypes.CYB).Int64())
toProgram := feeInCYB.Mul(sdk.NewDecWithPrec(80,2))
toProgram := feeInCYB.Mul(sdk.NewDecWithPrec(80, 2))
toValidators := feeInCYB.Sub(toProgram)

toValidatorsAmount := sdk.NewCoins(sdk.NewCoin(ctypes.CYB, toValidators.RoundInt()))
Expand All @@ -265,7 +262,7 @@ func DeductFees(bankKeeper bankkeeper.Keeper, ctx sdk.Context, acc authtypes.Acc
return sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, err.Error())
}

err = bankKeeper.SendCoinsFromAccountToModule(ctx, acc.GetAddress(), types.FeeCollectorName, toValidatorsAmount)
err = bankKeeper.SendCoinsFromAccountToModule(ctx, acc.GetAddress(), authtypes.FeeCollectorName, toValidatorsAmount)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, err.Error())
}
Expand Down
Loading

0 comments on commit 44ef8ea

Please sign in to comment.