From 1034643f00e657b0cff35999c6988c6bb36a5972 Mon Sep 17 00:00:00 2001 From: Chung Wu Date: Wed, 15 Dec 2021 16:51:36 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20Add=20Makefile=20for=20reproduci?= =?UTF-8?q?ble=20build?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .build.sh | 44 ++++++++++++++++ .gitignore | 4 ++ CHANGELOG.md | 6 +++ Makefile | 109 +++++++++++++++++++++++++++++++++++++++ cmd/liked/cmd/migrate.go | 4 +- gen_proto.sh | 11 ++-- x/iscn/types/query.pb.go | 30 ++++++++--- x/iscn/types/tx.pb.go | 9 ++-- 8 files changed, 202 insertions(+), 15 deletions(-) create mode 100755 .build.sh create mode 100644 CHANGELOG.md create mode 100644 Makefile diff --git a/.build.sh b/.build.sh new file mode 100755 index 0000000000..1f7a148837 --- /dev/null +++ b/.build.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +set -ue + +# Expect the following envvars to be set: +# - APP +# - VERSION +# - COMMIT +# - TARGET_OS +# - LEDGER_ENABLED +# - DEBUG + +# Source builder's functions library +. /usr/local/share/tendermint/buildlib.sh + +# These variables are now available +# - BASEDIR +# - OUTDIR + +# Build for each os-architecture pair +for platform in ${TARGET_PLATFORMS} ; do + # This function sets GOOS, GOARCH, and OS_FILE_EXT environment variables + # according to the build target platform. OS_FILE_EXT is empty in all + # cases except when the target platform is 'windows'. + setup_build_env_for_platform "${platform}" + + make clean + echo Building for $(go env GOOS)/$(go env GOARCH) >&2 + GOROOT_FINAL="$(go env GOROOT)" \ + make build \ + LDFLAGS=-buildid=${VERSION} \ + VERSION=${VERSION} \ + COMMIT=${COMMIT} \ + LEDGER_ENABLED=${LEDGER_ENABLED} + mv ./build/${APP}${OS_FILE_EXT} ${OUTDIR}/${APP}-${VERSION}-$(go env GOOS)-$(go env GOARCH)${OS_FILE_EXT} + + # This function restore the build environment variables to their + # original state. + restore_build_env +done + +# Generate and display build report. +generate_build_report +cat ${OUTDIR}/build_report diff --git a/.gitignore b/.gitignore index 5adfd7a67e..a196eeff32 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,7 @@ .likecli docker-compose.yml .env +.ar + +artifacts +build diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000000..06d3a50ac2 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,6 @@ +# Changelog + +## fotan-1.2 + +- Changed ISCN ID generation rule to allow creating multiple ISCNs in one transaction. +- Setup upgrade handler for the upgrade. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000..1c21dc33df --- /dev/null +++ b/Makefile @@ -0,0 +1,109 @@ +#!/usr/bin/make -f + +NAME := likecoin-chain +APP := liked +VERSION := $(shell git describe --tags) +COMMIT=$(shell git rev-parse HEAD) +LEDGER_ENABLED ?= true +DOCKER := $(shell which docker) +BUILDDIR ?= $(CURDIR)/build + +export GO111MODULE = on + +# process build tags + +build_tags = netgo +ifeq ($(LEDGER_ENABLED),true) + ifeq ($(OS),Windows_NT) + GCCEXE = $(shell where gcc.exe 2> NUL) + ifeq ($(GCCEXE),) + $(error gcc.exe not installed for ledger support, please install or set LEDGER_ENABLED=false) + else + build_tags += ledger + endif + else + UNAME_S = $(shell uname -s) + ifeq ($(UNAME_S),OpenBSD) + $(warning OpenBSD detected, disabling ledger support (https://github.com/cosmos/cosmos-sdk/issues/1988)) + else + GCC = $(shell command -v gcc 2> /dev/null) + ifeq ($(GCC),) + $(error gcc not installed for ledger support, please install or set LEDGER_ENABLED=false) + else + build_tags += ledger + endif + endif + endif +endif + +ifeq (cleveldb,$(findstring cleveldb,$(LIKE_BUILD_OPTIONS))) + build_tags += gcc +endif +build_tags += $(BUILD_TAGS) +build_tags := $(strip $(build_tags)) + +whitespace := +whitespace += $(whitespace) +comma := , +build_tags_comma_sep := $(subst $(whitespace),$(comma),$(build_tags)) + +# process linker flags + +ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=$(NAME) \ + -X github.com/cosmos/cosmos-sdk/version.AppName=$(APP) \ + -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)" + +ifeq (cleveldb,$(findstring cleveldb,$(LIKE_BUILD_OPTIONS))) + ldflags += -X github.com/cosmos/cosmos-sdk/types.DBBackend=cleveldb +endif +ifeq (,$(findstring nostrip,$(LIKE_BUILD_OPTIONS))) + ldflags += -w -s +endif +ldflags += $(LDFLAGS) +ldflags := $(strip $(ldflags)) + +BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)' +# check for nostrip option +ifeq (,$(findstring nostrip,$(LIKE_BUILD_OPTIONS))) + BUILD_FLAGS += -trimpath +endif + +all: install test + +$(BUILDDIR)/: + mkdir -p $(BUILDDIR)/ + +go-mod-cache: go.sum + echo "--> Download go modules to local cache" + go mod download + +go.sum: go.mod + echo "--> Ensure dependencies have not been modified" + go mod verify + +build-reproducible: go.sum + $(DOCKER) rm latest-build || true + $(DOCKER) run --volume=$(CURDIR):/sources:ro \ + --env TARGET_PLATFORMS='linux/amd64 darwin/amd64 linux/arm64 windows/amd64' \ + --env APP=$(APP) \ + --env VERSION=$(VERSION) \ + --env COMMIT=$(COMMIT) \ + --env LEDGER_ENABLED=$(LEDGER_ENABLED) \ + --name latest-build likecoin/rbuilder:latest + $(DOCKER) cp -a latest-build:/home/builder/artifacts/ $(CURDIR)/ + +build: go.sum $(BUILDDIR)/ + go build -mod=readonly $(BUILD_FLAGS) -o $(BUILDDIR)/ ./... + +install: go.sum $(BUILDDIR)/ + go install -mod=readonly $(BUILD_FLAGS) ./... + +test: + go test -v ./x/... + +clean: + rm -rf $(BUILDDIR)/ artifacts/ + +.PHONY: go-mod-cache build-reproducible build install test clean diff --git a/cmd/liked/cmd/migrate.go b/cmd/liked/cmd/migrate.go index 998c70601c..d777de15b9 100644 --- a/cmd/liked/cmd/migrate.go +++ b/cmd/liked/cmd/migrate.go @@ -3,7 +3,7 @@ package cmd import ( "encoding/json" "fmt" - "os" + "io/ioutil" "strings" "time" @@ -167,7 +167,7 @@ $ %s migrate /path/to/genesis.json --%s=1000000 --%s=likecoin-chain-fotan --%s=2 } outputPath, _ := cmd.Flags().GetString(flagOutput) - err = os.WriteFile(outputPath, sortedBz, 0o644) + err = ioutil.WriteFile(outputPath, sortedBz, 0o644) if err != nil { return errors.Wrap(err, "failed to write JSON genesis doc") } diff --git a/gen_proto.sh b/gen_proto.sh index e554c762d2..119d81ac18 100755 --- a/gen_proto.sh +++ b/gen_proto.sh @@ -1,13 +1,18 @@ #!/bin/bash +COSMOS_SDK_VERSION="0.42.11" +SWAGGER_OUT="./swagger-gen" + +mkdir -p ${SWAGGER_OUT} + protoc \ - -I "$GOPATH/pkg/mod/github.com/cosmos/cosmos-sdk@v0.42.6/proto" \ - -I "$GOPATH/pkg/mod/github.com/cosmos/cosmos-sdk@v0.42.6/third_party/proto" \ + -I "$GOPATH/pkg/mod/github.com/cosmos/cosmos-sdk@v${COSMOS_SDK_VERSION}/proto" \ + -I "$GOPATH/pkg/mod/github.com/cosmos/cosmos-sdk@v${COSMOS_SDK_VERSION}/third_party/proto" \ --gocosmos_out=plugins=interfacetype+grpc,Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types:. \ --grpc-gateway_out=logtostderr=true:. \ --proto_path proto \ ./proto/iscn/* \ - --swagger_out ./swagger-gen \ + --swagger_out ${SWAGGER_OUT} \ --swagger_opt logtostderr=true --swagger_opt fqn_for_swagger_name=true --swagger_opt simple_operation_ids=true mv github.com/likecoin/likechain/x/iscn/types/* x/iscn/types/ diff --git a/x/iscn/types/query.pb.go b/x/iscn/types/query.pb.go index 3a3108adce..559636bbd7 100644 --- a/x/iscn/types/query.pb.go +++ b/x/iscn/types/query.pb.go @@ -75,9 +75,17 @@ func (m *QueryResponseRecord) GetIpld() string { } type QueryRecordsByIdRequest struct { - IscnId string `protobuf:"bytes,1,opt,name=iscn_id,json=iscnId,proto3" json:"iscn_id,omitempty"` + // The ISCN ID of the record(s) to be queried. + // Format: iscn://REGISTRY_NAME/CONTENT_ID[/VERSION] + // If version part omitted, version is default to 0. + // if non-zero version exists, then from_version and to_version are ignored. + IscnId string `protobuf:"bytes,1,opt,name=iscn_id,json=iscnId,proto3" json:"iscn_id,omitempty"` + // The initial version in the resulting records. + // If omitted or is 0, then it will be interpreted as the latest version. FromVersion uint64 `protobuf:"varint,2,opt,name=from_version,json=fromVersion,proto3" json:"from_version,omitempty"` - ToVersion uint64 `protobuf:"varint,3,opt,name=to_version,json=toVersion,proto3" json:"to_version,omitempty"` + // The final version in the resulting records. + // If omitted or is 0, then it will be interpreted as the latest version. + ToVersion uint64 `protobuf:"varint,3,opt,name=to_version,json=toVersion,proto3" json:"to_version,omitempty"` } func (m *QueryRecordsByIdRequest) Reset() { *m = QueryRecordsByIdRequest{} } @@ -195,7 +203,12 @@ func (m *QueryRecordsByIdResponse) GetRecords() []QueryResponseRecord { } type QueryRecordsByFingerprintRequest struct { - Fingerprint string `protobuf:"bytes,1,opt,name=fingerprint,proto3" json:"fingerprint,omitempty"` + // The fingerprint of the record(s) to be queried. + // All fingerprints in records should be URIs. + Fingerprint string `protobuf:"bytes,1,opt,name=fingerprint,proto3" json:"fingerprint,omitempty"` + // For pagination. + // For the first query, fill in 0 or just omit this field. + // For continuous queries, fill in the `next_sequence` field in the previous response. FromSequence uint64 `protobuf:"varint,2,opt,name=from_sequence,json=fromSequence,proto3" json:"from_sequence,omitempty"` } @@ -247,8 +260,9 @@ func (m *QueryRecordsByFingerprintRequest) GetFromSequence() uint64 { } type QueryRecordsByFingerprintResponse struct { - Records []QueryResponseRecord `protobuf:"bytes,1,rep,name=records,proto3" json:"records"` - NextSequence uint64 `protobuf:"varint,2,opt,name=next_sequence,json=nextSequence,proto3" json:"next_sequence,omitempty"` + Records []QueryResponseRecord `protobuf:"bytes,1,rep,name=records,proto3" json:"records"` + // For pagination. + NextSequence uint64 `protobuf:"varint,2,opt,name=next_sequence,json=nextSequence,proto3" json:"next_sequence,omitempty"` } func (m *QueryRecordsByFingerprintResponse) Reset() { *m = QueryRecordsByFingerprintResponse{} } @@ -299,7 +313,11 @@ func (m *QueryRecordsByFingerprintResponse) GetNextSequence() uint64 { } type QueryRecordsByOwnerRequest struct { - Owner string `protobuf:"bytes,1,opt,name=owner,proto3" json:"owner,omitempty"` + // Owner address of the record(s) to be queried. + Owner string `protobuf:"bytes,1,opt,name=owner,proto3" json:"owner,omitempty"` + // For pagination. + // For the first query, fill in 0 or just omit this field. + // For continuous queries, fill in the `next_sequence` field in the previous response. FromSequence uint64 `protobuf:"varint,2,opt,name=from_sequence,json=fromSequence,proto3" json:"from_sequence,omitempty"` } diff --git a/x/iscn/types/tx.pb.go b/x/iscn/types/tx.pb.go index 2bbe3ad838..3b98f12ed8 100644 --- a/x/iscn/types/tx.pb.go +++ b/x/iscn/types/tx.pb.go @@ -30,10 +30,11 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type IscnRecord struct { // Using camelCases to make the record JSON in tx more like general JSON documents - RecordNotes string `protobuf:"bytes,1,opt,name=recordNotes,proto3" json:"recordNotes,omitempty"` - ContentFingerprints []string `protobuf:"bytes,2,rep,name=contentFingerprints,proto3" json:"contentFingerprints,omitempty"` - Stakeholders []IscnInput `protobuf:"bytes,3,rep,name=stakeholders,proto3,customtype=IscnInput" json:"stakeholders,omitempty"` - ContentMetadata IscnInput `protobuf:"bytes,4,opt,name=contentMetadata,proto3,customtype=IscnInput" json:"contentMetadata"` + RecordNotes string `protobuf:"bytes,1,opt,name=recordNotes,proto3" json:"recordNotes,omitempty"` + ContentFingerprints []string `protobuf:"bytes,2,rep,name=contentFingerprints,proto3" json:"contentFingerprints,omitempty"` + // Here, `IscnInput` is JSON encoded bytes + Stakeholders []IscnInput `protobuf:"bytes,3,rep,name=stakeholders,proto3,customtype=IscnInput" json:"stakeholders,omitempty"` + ContentMetadata IscnInput `protobuf:"bytes,4,opt,name=contentMetadata,proto3,customtype=IscnInput" json:"contentMetadata"` } func (m *IscnRecord) Reset() { *m = IscnRecord{} }