Skip to content

Commit

Permalink
Merge pull request #625 from cybercongress/cyberfrey
Browse files Browse the repository at this point in the history
  • Loading branch information
cyborgshead authored May 31, 2022
2 parents 2168846 + 6bb68e2 commit 71e7614
Show file tree
Hide file tree
Showing 29 changed files with 928 additions and 396 deletions.
164 changes: 73 additions & 91 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,127 +1,109 @@
###########################################################################################
# Build cyber
###########################################################################################
FROM ubuntu:20.04 as build_stage_cuda
FROM ubuntu:20.04

ENV GO_VERSION '1.17.2'
ENV GO_VERSION '1.17.8'
ENV GO_ARCH 'linux-amd64'
ENV GO_BIN_SHA 'f242a9db6a0ad1846de7b6d94d507915d14062660616a61ef7c808a76e4f1676'
ENV GO_BIN_SHA '980e65a863377e69fd9b67df9d8395fd8e93858e7a24c9f55803421e453f4f99'
ENV DEBIAN_FRONTEND=noninteractive
ENV DAEMON_HOME /root/.cyber
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 BUILD_DIR /build
ENV COSMWASM_VER "1.0.0-beta"
ENV PATH /usr/local/go/bin:/root/.cargo/bin:/root/cargo/env:/root/.cyber/scripts:$PATH
ENV CUDA_VER '11.4.4-1'
ENV PATH="/usr/local/go/bin:/usr/local/cuda/bin:$PATH"


# Install required dev tools to compile cyberd
# Install go and required deps
###########################################################################################
RUN apt-get update && apt-get install -y --no-install-recommends wget git ca-certificates
RUN apt-get update && apt-get install -y --no-install-recommends wget ca-certificates \
&& wget -O go.tgz https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz \
&& echo "${GO_BIN_SHA} *go.tgz" | sha256sum -c - \
&& tar -C /usr/local -xzf go.tgz \
&& rm go.tgz \
&& go version

# Install golang
###########################################################################################
RUN wget -O go.tgz https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz && \
echo "${GO_BIN_SHA} *go.tgz" | sha256sum -c - && \
tar -C /usr/local -xzf go.tgz &&\
rm go.tgz

ENV PATH="/usr/local/go/bin:$PATH"
COPY . /sources
WORKDIR /sources

# Install CUDA, build tools and compile cyber
###########################################################################################
RUN apt-get -y install --no-install-recommends \
make gcc g++ \
wget \
curl \
gnupg \
git \
nvidia-cuda-toolkit \
&& go version
software-properties-common \
# nvidia-cuda-toolkit \
# Install cuda selected version instead nvidia-cuda-toolkit
&& wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin \
&& mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600 \
&& apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/3bf863cc.pub \
&& 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
###########################################################################################
&& 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/ \
&& rm -rf ./build \
# Cleanup
###########################################################################################
&& apt-get purge -y git \
make \
cuda \
gcc g++ \
curl \
gnupg \
python3.8 \
&& go clean --cache -i \
&& apt-get remove --purge '^nvidia-.*' -y \
&& apt-get autoremove -y \
&& apt-get clean

# Create appropriate folders layout
###########################################################################################
RUN mkdir -p /cyber/cosmovisor/genesis/bin
# Compile cosmovisor
# Install cosmovisor
###########################################################################################
RUN git clone --depth 1 https://github.com/cosmos/cosmos-sdk.git $BUILD_DIR/ \
&& cd $BUILD_DIR/cosmovisor/ \
&& make cosmovisor \
RUN wget -O cosmovisor.tgz https://github.com/cosmos/cosmos-sdk/releases/download/cosmovisor%2Fv1.1.0/cosmovisor-v1.1.0-linux-amd64.tar.gz \
&& tar -xzf cosmovisor.tgz \
&& cp cosmovisor /usr/bin/cosmovisor \
&& chmod +x /usr/bin/cosmovisor \
&& rm -fR $BUILD_DIR/* && rm -fR $BUILD_DIR/.*[a-z]
&& rm cosmovisor.tgz && rm -fR $BUILD_DIR/* && rm -fR $BUILD_DIR/.*[a-z]

###########################################################################################
# Build wasmvm
# Copy startup scripts and genesis
###########################################################################################
WORKDIR /
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y \
&& wget --quiet https://github.com/CosmWasm/wasmvm/archive/v${COSMWASM_VER}.tar.gz -P /tmp \
&& tar xzf /tmp/v${COSMWASM_VER}.tar.gz -C $BUILD_DIR \
&& cd $BUILD_DIR/wasmvm-${COSMWASM_VER}/ && make build \
&& cp $BUILD_DIR/wasmvm-${COSMWASM_VER}/api/libwasmvm.so /usr/lib/ \
&& cp $BUILD_DIR/wasmvm-${COSMWASM_VER}/api/libwasmvm.dylib /usr/lib/

# Compile cuda kernel
###########################################################################################
COPY . /sources
WORKDIR /sources/x/rank/cuda
RUN make build
RUN cp ./build/libcbdrank.so /usr/lib/ && cp cbdrank.h /usr/lib/

# Compile cyberd for genesis version
###########################################################################################

WORKDIR /sources
RUN make build CUDA_ENABLED=true \
&& chmod +x ./build/cyber \
&& cp ./build/cyber /cyber/cosmovisor/genesis/bin/ \
&& cp ./build/cyber /cyber/ \
&& rm -rf ./build \
&& git reset --hard

###########################################################################################
# Create runtime cyber image
###########################################################################################
FROM ubuntu:20.04

ENV DAEMON_HOME /root/.cyber
ENV DAEMON_RESTART_AFTER_UPGRADE=true
ENV GAIA_HOME ${DAEMON_HOME}
ENV DAEMON_NAME cyber

# Install useful dev tools
###########################################################################################
RUN apt-get update && apt-get install -y --no-install-recommends wget curl ca-certificates

# Download genesis file and links file from IPFS
###########################################################################################
RUN wget -O /genesis.json https://gateway.ipfs.cybernode.ai/ipfs/QmYubyVNfghD4xCrTFj26zBwrF9s5GJhi1TmxvrwmJCipr

WORKDIR /

# Copy compiled kernel and binaries for current bin version
###########################################################################################
COPY --from=build_stage_cuda /cyber /cyber

COPY --from=build_stage_cuda /cyber/cyber /usr/bin

COPY --from=build_stage_cuda /usr/bin/cosmovisor /usr/bin/cosmovisor

COPY --from=build_stage_cuda /usr/lib/cbdrank.h /usr/lib/cbdrank.h
COPY --from=build_stage_cuda /usr/lib/libcbdrank.so /usr/lib/libcbdrank.so

COPY --from=build_stage_cuda /usr/lib/libwasmvm.so /usr/lib/libwasmvm.so
COPY --from=build_stage_cuda /usr/lib/libwasmvm.dylib /usr/lib/libwasmvm.dylib

# Copy startup scripts
###########################################################################################

COPY start_script.sh start_script.sh
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x start_script.sh
RUN chmod +x /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


# Start
###############################################################################
EXPOSE 26656 26657 1317 9090
EXPOSE 26656 26657 1317 9090 26660
ENTRYPOINT ["/entrypoint.sh"]
CMD ["./start_script.sh"]
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ go-mod-cache: go.sum

go.sum: go.mod
@echo "--> Ensure dependencies have not been modified"
@#go mod verify # TODO uncomment on release
@go mod tidy
@go mod verify # TODO uncomment on release
go mod tidy -compat=1.17
.PHONY: go.sum

lint:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</div>

<div align="center">
<h3>Join us, Hero - <a href="https://github.com/cybercongress/go-cyber/blob/bostrom-dev/docs/run_validator.md">Setup validator guide</a></h3>
<h3>Join us, Hero - <a href="https://github.com/cybercongress/go-cyber/blob/main/docs/run_validator.md">Setup validator guide</a></h3>
</div>

<div align="center">
Expand Down Expand Up @@ -51,7 +51,7 @@ _____________

## Blockchain

[![chain](https://img.shields.io/badge/Chain-bostrom-success.svg?style=flat-square)](https://github.com/cybercongress/cyberd/blob/master/docs/run_validator.md)
[![chain](https://img.shields.io/badge/Chain-bostrom-success.svg?style=flat-square)](https://github.com/cybercongress/go-cyber/blob/main/docs/run_validator.md)
[![block](https://img.shields.io/badge/dynamic/json?color=blue&label=Block%20Height&query=%24.result.sync_info.latest_block_height&url=https://rpc.bostrom.cybernode.ai/status&style=flat-square)]()
[![cyberlinks](https://img.shields.io/badge/dynamic/json?color=blue&label=Cyberlinks&query=%24.result.cyberlinks&url=https://lcd.bostrom.cybernode.ai/graph/graph_stats&style=flat-square)]()
[![particles](https://img.shields.io/badge/dynamic/json?color=blue&label=Particles&query=%24.result.particles&url=https://lcd.bostrom.cybernode.ai/graph/graph_stats&style=flat-square)]()
Expand Down
25 changes: 17 additions & 8 deletions app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ import (
ctypes "github.com/cybercongress/go-cyber/types"

authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
channelkeeper "github.com/cosmos/ibc-go/modules/core/04-channel/keeper"
ibcante "github.com/cosmos/ibc-go/modules/core/ante"
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"
)

// HandlerOptions are the options required for constructing a default SDK AnteHandler.
Expand All @@ -38,8 +39,9 @@ type HandlerBaseOptions struct {
type HandlerOptions struct {
HandlerBaseOptions

IBCChannelkeeper channelkeeper.Keeper
txCounterStoreKey sdk.StoreKey
IBCKeeper *keeper.Keeper
WasmConfig *wasmTypes.WasmConfig
TXCounterStoreKey sdk.StoreKey
}

func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
Expand All @@ -55,6 +57,12 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
if options.SignModeHandler == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder")
}
if options.WasmConfig == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "wasm config is required for ante builder")
}
if options.TXCounterStoreKey == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "tx counter key is required for ante builder")
}

var sigGasConsumer = options.SigGasConsumer
if sigGasConsumer == nil {
Expand All @@ -63,22 +71,23 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {

anteDecorators := []sdk.AnteDecorator{
ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
wasmkeeper.NewCountTXDecorator(options.txCounterStoreKey),
wasmkeeper.NewLimitSimulationGasDecorator(options.WasmConfig.SimulationGasLimit), // after setup context to enforce limits early
wasmkeeper.NewCountTXDecorator(options.TXCounterStoreKey),
ante.NewRejectExtensionOptionsDecorator(),
//ante.NewMempoolFeeDecorator(),
// overwrite ante.NewMempoolFeeDecorator(),
NewMempoolFeeDecorator(),
ante.NewValidateBasicDecorator(),
ante.NewTxTimeoutHeightDecorator(),
ante.NewValidateMemoDecorator(options.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
//ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper),
// overwrite ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper),
NewDeductFeeBandRouterDecorator(options.AccountKeeper, options.BankKeeper, options.BandwidthMeter, options.FeegrantKeeper),
ante.NewSetPubKeyDecorator(options.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators
ante.NewValidateSigCountDecorator(options.AccountKeeper),
ante.NewSigGasConsumeDecorator(options.AccountKeeper, sigGasConsumer),
ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
ante.NewIncrementSequenceDecorator(options.AccountKeeper),
ibcante.NewAnteDecorator(options.IBCChannelkeeper),
ibcante.NewAnteDecorator(options.IBCKeeper),
}

return sdk.ChainAnteDecorators(anteDecorators...), nil
Expand Down
Loading

0 comments on commit 71e7614

Please sign in to comment.