Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit 5a98918

Browse files
authored
Merge pull request #445 from BitCannaGlobal/v4
Update v4-devnet-1 with v4 changes
2 parents 07792dc + 2bae26e commit 5a98918

7 files changed

Lines changed: 218 additions & 41349 deletions

File tree

.github/workflows/build.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# This is a basic workflow that is manually triggered
2+
3+
name: compile bcna
4+
5+
# Controls when the action will run. Workflow runs when manually triggered using the UI
6+
# or API.
7+
on:
8+
workflow_dispatch:
9+
# This workflow makes x86_64 binaries for mac, windows, and linux.
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
strategy:
15+
matrix:
16+
arch: [amd64, arm64]
17+
targetos: [darwin, linux]
18+
include:
19+
- targetos: windows
20+
arch: amd64
21+
name: bcna ${{ matrix.arch }} for ${{ matrix.targetos }}
22+
steps:
23+
- uses: actions/checkout@v3
24+
- uses: actions/setup-go@v3
25+
with:
26+
go-version: "^1.23"
27+
env:
28+
GOOS: ${{ matrix.targetos }}
29+
GOARCH: ${{ matrix.arch }}
30+
31+
- name: run tests
32+
run: go test ./...
33+
34+
# we build and install in case we want to run it or capture an artifact as we do in the step below.
35+
- name: Compile bcnad
36+
run: |
37+
go build ./...
38+
go install ./...
39+
40+
# now uploads genesis.json and bin
41+
- uses: actions/upload-artifact@v3
42+
with:
43+
name: bcnad ${{ matrix.targetos }} ${{ matrix.arch }}
44+
path: build/bcnad

.github/workflows/release.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: "Release"
2+
3+
on:
4+
push:
5+
tags:
6+
- v*
7+
branches:
8+
- v4
9+
jobs:
10+
draft-release:
11+
runs-on: ubuntu-latest
12+
permissions: write-all
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v3
16+
17+
- name: Set up QEMU
18+
uses: docker/setup-qemu-action@v2
19+
20+
- name: Set up Docker Buildx
21+
uses: docker/setup-buildx-action@v2
22+
23+
- name: Copy Binary
24+
run: |
25+
make build-reproducible-all
26+
27+
- name: List files
28+
run: ls -R
29+
30+
- name: Draft Release
31+
uses: softprops/action-gh-release@v1
32+
with:
33+
draft: true
34+
files: |
35+
build/bcnad_linux_arm64
36+
build/bcnad_linux_amd64
37+
build/bcnad_sha256.txt

Dockerfile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
ARG IMG_TAG=latest
2+
ARG PLATFORM="linux/amd64"
3+
ARG GO_VERSION="1.23.1"
4+
ARG RUNNER_IMAGE="gcr.io/distroless/static"
5+
6+
FROM --platform=${PLATFORM} golang:${GO_VERSION}-alpine3.20 as builder
7+
WORKDIR /src/app/
8+
COPY go.mod go.sum* ./
9+
RUN go mod download
10+
COPY . .
11+
12+
# From https://github.com/CosmWasm/wasmd/blob/master/Dockerfile
13+
# For more details see https://github.com/CosmWasm/wasmvm#builds-of-libwasmvm
14+
ARG ARCH=x86_64
15+
# See https://github.com/CosmWasm/wasmvm/releases
16+
ADD https://github.com/CosmWasm/wasmvm/releases/download/v2.1.3/libwasmvm_muslc.aarch64.a /lib/libwasmvm_muslc.aarch64.a
17+
ADD https://github.com/CosmWasm/wasmvm/releases/download/v2.1.3/libwasmvm_muslc.x86_64.a /lib/libwasmvm_muslc.x86_64.a
18+
#ADD https://github.com/CosmWasm/wasmvm/releases/download/v2.1.3/libwasmvmstatic_darwin.a /lib/libwasmvm_muslc.darwin.a
19+
RUN sha256sum /lib/libwasmvm_muslc.aarch64.a | grep faea4e15390e046d2ca8441c21a88dba56f9a0363f92c5d94015df0ac6da1f2d
20+
RUN sha256sum /lib/libwasmvm_muslc.x86_64.a | grep 8dab08434a5fe57a6fbbcb8041794bc3c31846d31f8ff5fb353ee74e0fcd3093
21+
#RUN sha256sum /lib/libwasmvm_muslc.darwin.a | grep f7a997c6a769e5624dac910dc2f0bec4c386aeb54342dd04ef6d5eba0340a20d
22+
RUN cp /lib/libwasmvm_muslc.${ARCH}.a /lib/libwasmvm_muslc.a
23+
24+
ENV PACKAGES curl make git libc-dev bash gcc linux-headers eudev-dev python3
25+
RUN apk add --no-cache $PACKAGES
26+
RUN set -eux; apk add --no-cache ca-certificates build-base;
27+
28+
ARG VERSION=""
29+
RUN BUILD_TAGS=muslc LINK_STATICALLY=true LDFLAGS=-buildid=$VERSION make build
30+
31+
# Add to a distroless container
32+
ARG PLATFORM="linux/amd64"
33+
FROM --platform=${PLATFORM} gcr.io/distroless/cc:$IMG_TAG
34+
ARG IMG_TAG
35+
COPY --from=builder /src/app/build/bcnad /usr/local/bin/bcnad
36+
37+
EXPOSE 26656 26657 1317 9090
38+
39+
ENTRYPOINT ["bcnad"]

Makefile

Lines changed: 94 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,32 @@
11
#!/usr/bin/make -f
22

3-
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
4-
COMMIT := $(shell git log -1 --format='%H')
5-
BUILD_DIR ?= $(CURDIR)/build
6-
DIST_DIR ?= $(CURDIR)/dist
7-
LEDGER_ENABLED ?= true
8-
TM_VERSION := $(shell go list -m github.com/cometbft/cometbft | sed 's:.* ::')
9-
DOCKER := $(shell which docker)
10-
PROJECT_NAME := bitcanna
11-
HTTPS_GIT := https://github.com/BitCannaGlobal/bcna.git
12-
13-
###############################################################################
14-
## Version ##
15-
###############################################################################
3+
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
4+
COMMIT := $(shell git log -1 --format='%H')
5+
GO_VERSION := "1.23"
6+
BUILD_DIR ?= $(CURDIR)/build
167

8+
# don't override user values
179
ifeq (,$(VERSION))
18-
VERSION := $(shell git describe --tags | sed 's/^v//')
10+
VERSION := $(shell git describe --tags)
1911
# if VERSION is empty, then populate it with branch's name and raw commit hash
2012
ifeq (,$(VERSION))
2113
VERSION := $(BRANCH)-$(COMMIT)
2214
endif
2315
endif
2416

25-
GO_MAJOR_VERSION = $(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1)
26-
GO_MINOR_VERSION = $(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2)
27-
###############################################################################
28-
## Build ##
29-
###############################################################################
17+
PACKAGES_SIMTEST=$(shell go list ./... | grep '/simulation')
18+
LEDGER_ENABLED ?= true
19+
SDK_PACK := $(shell go list -m github.com/cosmos/cosmos-sdk | sed 's/ /\@/g')
20+
TM_VERSION := $(shell go list -m github.com/cometbft/cometbft | sed 's:.* ::') # grab everything after the space in "github.com/cometbft/cometbft v0.37.0"
21+
BUILDDIR ?= $(CURDIR)/build
22+
DOCKER := $(shell which docker)
23+
DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf:1.7.0
3024

31-
build_tags = netgo
25+
export GO111MODULE = on
3226

27+
# process build tags
28+
29+
build_tags = netgo
3330
ifeq ($(LEDGER_ENABLED),true)
3431
ifeq ($(OS),Windows_NT)
3532
GCCEXE = $(shell where gcc.exe 2> NUL)
@@ -53,94 +50,115 @@ ifeq ($(LEDGER_ENABLED),true)
5350
endif
5451
endif
5552

53+
ifeq (cleveldb,$(findstring cleveldb,$(bitcanna_BUILD_OPTIONS)))
54+
build_tags += gcc cleveldb
55+
endif
56+
build_tags += $(BUILD_TAGS)
57+
build_tags := $(strip $(build_tags))
58+
5659
whitespace :=
5760
whitespace += $(whitespace)
5861
comma := ,
5962
build_tags_comma_sep := $(subst $(whitespace),$(comma),$(build_tags))
6063

64+
# process linker flags
65+
6166
ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=bcna \
6267
-X github.com/cosmos/cosmos-sdk/version.AppName=bcnad \
6368
-X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \
6469
-X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \
6570
-X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep)" \
6671
-X github.com/cometbft/cometbft/version.TMCoreSemVer=$(TM_VERSION)
6772

73+
ifeq (cleveldb,$(findstring cleveldb,$(bitcanna_BUILD_OPTIONS)))
74+
ldflags += -X github.com/cosmos/cosmos-sdk/types.DBBackend=cleveldb
75+
endif
76+
ifeq (,$(findstring nostrip,$(bitcanna_BUILD_OPTIONS)))
77+
ldflags += -w -s
78+
endif
79+
ifeq ($(LINK_STATICALLY),true)
80+
ldflags += -linkmode=external -extldflags "-Wl,-z,muldefs -static"
81+
endif
6882
ldflags += $(LDFLAGS)
6983
ldflags := $(strip $(ldflags))
7084

7185
BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)'
72-
73-
check_version:
74-
ifeq ($(shell expr $(GO_MINOR_VERSION) \< 23), 1)
75-
@echo "ERROR: Go version 1.23 or newer is required for building BCNAD."
76-
exit 1
86+
# check for nostrip option
87+
ifeq (,$(findstring nostrip,$(bitcanna_BUILD_OPTIONS)))
88+
BUILD_FLAGS += -trimpath
7789
endif
7890

91+
#$(info $$BUILD_FLAGS is [$(BUILD_FLAGS)])
92+
93+
94+
all: check-go-version install
7995

80-
build: check_version go.sum
81-
@echo "--> Building..."
82-
go build -mod=readonly $(BUILD_FLAGS) -o $(BUILD_DIR)/ ./...
96+
install: check-go-version go.sum
97+
go install -mod=readonly $(BUILD_FLAGS) ./...
8398

84-
install: check_version go.sum
85-
@echo "--> Installing..."
86-
go install -mod=readonly $(BUILD_FLAGS) ./...
99+
build: check-go-version
100+
go build $(BUILD_FLAGS) -o $(BUILD_DIR)/ ./...
87101

88-
build-linux: check_version go.sum
89-
LEDGER_ENABLED=false GOOS=linux GOARCH=amd64 $(MAKE) build
102+
BUILD_TARGETS := build install
90103

91-
go-mod-cache: check_version go.sum
92-
@echo "--> Download go modules to local cache"
93-
@go mod download
104+
build-reproducible-all: build-reproducible-amd64 build-reproducible-arm64
94105

95-
go.sum: check_version go.mod
96-
@echo "--> Ensure dependencies have not been modified"
97-
@go mod verify
106+
build-reproducible-amd64:
107+
ARCH=x86_64 PLATFORM=linux/amd64 $(MAKE) build-reproducible-generic
98108

99-
go-mod-tidy:
100-
@contrib/scripts/go-mod-tidy-all.sh
109+
build-reproducible-arm64:
110+
ARCH=aarch64 PLATFORM=linux/arm64 $(MAKE) build-reproducible-generic
111+
112+
build-reproducible-generic: go.sum
113+
$(DOCKER) rm $(subst /,-,latest-build-$(PLATFORM)) || true
114+
DOCKER_BUILDKIT=1 $(DOCKER) build -t latest-build-$(PLATFORM) \
115+
--build-arg ARCH=$(ARCH) \
116+
--build-arg GO_VERSION=$(GO_VERSION) \
117+
--build-arg PLATFORM=$(PLATFORM) \
118+
--build-arg VERSION="$(VERSION)" \
119+
-f Dockerfile .
120+
mkdir -p build
121+
$(DOCKER) create -ti --name $(subst /,-,latest-build-$(PLATFORM)) latest-build-$(PLATFORM) bcnad
122+
$(DOCKER) cp -a $(subst /,-,latest-build-$(PLATFORM)):/usr/local/bin/bcnad $(BUILD_DIR)/bcnad_$(subst /,_,$(PLATFORM))
123+
sha256sum $(BUILD_DIR)/bcnad_$(subst /,_,$(PLATFORM)) >> $(BUILD_DIR)/bcnad_sha256.txt
124+
125+
# Add check to make sure we are using the proper Go version before proceeding with anything
126+
check-go-version:
127+
@if ! go version | grep -q "go$(GO_VERSION)"; then \
128+
echo "\033[0;31mERROR:\033[0m Go version $(GO_VERSION) is required for compiling BCNAD. It looks like you are using" "$(shell go version) \nThere are potential consensus-breaking changes that can occur when running binaries compiled with different versions of Go. Please download Go version $(GO_VERSION) and retry. Thank you!"; \
129+
exit 1; \
130+
fi
101131

102132
clean:
103133
@echo "--> Cleaning..."
104134
@rm -rf $(BUILD_DIR)/** $(DIST_DIR)/**
105135

106-
.PHONY: install build build-linux clean
107-
108136
###############################################################################
109-
## Protobuf ##
137+
### Protobuf ###
110138
###############################################################################
111139

112-
DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf
113-
114-
containerProtoVer=v0.2
115-
containerProtoImage=tendermintdev/sdk-proto-gen:$(containerProtoVer)
116-
containerProtoGen=$(PROJECT_NAME)-proto-gen-$(containerProtoVer)
117-
containerProtoFmt=$(PROJECT_NAME)-proto-fmt-$(containerProtoVer)
118-
containerProtoGenSwagger=$(PROJECT_NAME)-proto-gen-swagger-$(containerProtoVer)
119-
120-
proto-all: proto-format proto-lint proto-gen proto-swagger-gen
140+
containerProtoVer=0.13.0
141+
containerProtoImage=ghcr.io/cosmos/proto-builder:$(containerProtoVer)
121142

122143
proto-gen:
123144
@echo "Generating Protobuf files"
124-
@if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerProtoGen}$$"; then docker start -a $(containerProtoGen); else docker run --name $(containerProtoGen) -v $(CURDIR):/workspace --workdir /workspace $(containerProtoImage) \
125-
sh ./scripts/protocgen.sh; fi
126-
127-
proto-swagger-gen:
128-
@echo "Generating Swagger of Protobuf"
129-
@if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerProtoGenSwagger}$$"; then docker start -a $(containerProtoGenSwagger); else docker run --name $(containerProtoGenSwagger) -v $(CURDIR):/workspace --workdir /workspace $(containerProtoImage) \
130-
sh ./scripts/protoc-swagger-gen.sh; fi
131-
132-
proto-format:
133-
@echo "Formatting Protobuf files"
134-
@if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerProtoFmt}$$"; then docker start -a $(containerProtoFmt); else docker run --name $(containerProtoFmt) -v $(CURDIR):/workspace --workdir /workspace tendermintdev/docker-build-proto \
135-
find ./ -name "*.proto" -exec sh -c 'clang-format -style=file -i {}' \; ; fi
136-
137-
proto-lint:
138-
@echo "Linting Protobuf files"
139-
@$(DOCKER_BUF) lint --error-format=json
140-
141-
proto-check-breaking:
142-
@echo "Checking for breaking changes"
143-
@$(DOCKER_BUF) breaking --against $(HTTPS_GIT)#branch=main
144-
145-
146-
.PHONY: proto-all proto-gen proto-lint proto-check-breaking proto-format proto-swagger-gen
145+
@$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(containerProtoImage) \
146+
sh ./scripts/protocgen.sh;
147+
148+
docs:
149+
@echo
150+
@echo "=========== Generate Message ============"
151+
@echo
152+
./scripts/protoc-swagger-gen.sh
153+
154+
statik -src=docs/static -dest=docs -f -m
155+
@if [ -n "$(git status --porcelain)" ]; then \
156+
echo "\033[91mSwagger docs are out of sync!!!\033[0m";\
157+
exit 1;\
158+
else \
159+
echo "\033[92mSwagger docs are in sync\033[0m";\
160+
fi
161+
@echo
162+
@echo "=========== Generate Complete ============"
163+
@echo
164+
.PHONY: docs

0 commit comments

Comments
 (0)