Skip to content

Commit

Permalink
Merge branch 'release/1.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sung-Jae Woo committed Aug 7, 2019
2 parents 3189c3b + 7a3cfce commit e83b884
Show file tree
Hide file tree
Showing 387 changed files with 20,762 additions and 5,836 deletions.
26 changes: 26 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# build result
/bin
/build
debug
debug.test
Gopkg.lock
*.o
*.a
libtool/bin
libtool/include
libtool/lib
libtool/share
libtool/src/luajit/src/*.[ao]
libtool/src/lmdb/libraries/liblmdb/*.[ao]

# vim swp file
*.swp
*.tmp

# IDE specific
*.vscode
*.idea
*.iml

# developer workspace specific
/conf
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ Gopkg.lock
# developer workspace specific
/conf

# consensus test directory
/consensus/**/tmp/
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ add_custom_target(distclean GO111MODULE=on go clean ..
DEPENDS libtool-clean)

add_custom_target(protoc
COMMAND protoc -I/usr/local/include -I${PROTO_DIR} --go_out=plugins=grpc:$ENV{GOPATH}/src ${PROTO_DIR}/*.proto
COMMAND protoc -I/usr/local/include -I${PROTO_DIR} --go_out=plugins=grpc:${CMAKE_CURRENT_LIST_DIR}/types ${PROTO_DIR}/*.proto
COMMAND GO111MODULE=on go build ../types/...)

add_custom_target(protoclean rm -f ../types/*.pb.go)
Expand Down
7 changes: 7 additions & 0 deletions Docker/Dockerfile.builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM golang:1.12.5-alpine3.9
ARG GIT_TAG=master
RUN apk update && apk add git cmake build-base m4
RUN git clone --branch ${GIT_TAG} --recursive https://github.com/aergoio/aergo.git \
&& cd aergo \
&& make aergosvr polaris colaris aergocli aergoluac brick

8 changes: 8 additions & 0 deletions Docker/Dockerfile.node
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM alpine:3.9
RUN apk add libgcc
COPY bin/aergosvr /usr/local/bin/
COPY lib/* /usr/local/lib/
COPY conf/* /aergo/
ENV LD_LIBRARY_PATH="/usr/local/lib:${LD_LIBRARY_PATH}"
CMD ["aergosvr", "--home", "/aergo"]
EXPOSE 7845 7846 6060
4 changes: 4 additions & 0 deletions Docker/Dockerfile.polaris
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM alpine:3.9
RUN apk add libgcc
COPY bin/?olaris /usr/local/bin/
CMD ["polaris"]
8 changes: 8 additions & 0 deletions Docker/Dockerfile.tools
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM alpine:3.9
RUN apk add libgcc
WORKDIR /tools/
COPY bin/aergocli bin/aergoluac bin/brick /usr/local/bin/
COPY bin/brick-arglog.toml arglog.toml
COPY lib/* /usr/local/lib/
ENV LD_LIBRARY_PATH="/usr/local/lib:${LD_LIBRARY_PATH}"
CMD ["aergocli"]
24 changes: 19 additions & 5 deletions scripts/docker-build.sh → Docker/build.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#!/usr/bin/env bash

# This script can be used to build the Docker images manually (outside of CI)

set -e

GIT_TAG=$1
MAIN_TAG=$2
SECOND_TAG=$3
THIRD_TAG=$4

if [[ -z "$MAIN_TAG" || -z "$GIT_TAG" ]]
then
echo "Usage:"
Expand All @@ -30,22 +34,32 @@ fi
echo "Building Docker images for ${tags[*]} using git tag $GIT_TAG"
sleep 1

BUILDER_TAG="aergo/builder"
echo "Building ${BUILDER_TAG}"

docker build --no-cache --build-arg GIT_TAG=$GIT_TAG --file Dockerfile.builder -t ${BUILDER_TAG} .
docker create --name extract ${BUILDER_TAG}
docker cp extract:/go/aergo/bin/ .
docker cp extract:/go/aergo/cmd/brick/arglog.toml bin/brick-arglog.toml
docker cp extract:/go/aergo/libtool/lib/ .
docker rm -f extract

declare -a names=("node" "tools" "polaris")
for name in "${names[@]}"
do

tagsExpanded=()
for tag in "${tags[@]}"; do
tagsExpanded+=("-t aergo/$name:$tag")
done
echo "[aergo/$name:${tags[*]}]"
DOCKERFILE="../Dockerfile.$name"
[[ $name == "node" ]] && DOCKERFILE="../Dockerfile"
echo docker build -q --build-arg GIT_TAG=$GIT_TAG ${tagsExpanded[@]} ../ --file $DOCKERFILE
imageid=`docker build -q --build-arg GIT_TAG=$GIT_TAG ${tagsExpanded[@]} ../ --file $DOCKERFILE`
DOCKERFILE="Dockerfile.$name"
echo docker build -q ${tagsExpanded[@]} --file $DOCKERFILE .
imageid=`docker build -q ${tagsExpanded[@]} --file $DOCKERFILE .`
docker images --format "Done: \t{{.Repository}}:{{.Tag}} \t{{.ID}} ({{.Size}})" | grep "${imageid:7:12}"
done

rm -rf bin lib

echo -e "\nREPOSITORY TAG IMAGE ID CREATED SIZE"
for name in "${names[@]}"
do
Expand Down
File renamed without changes.
File renamed without changes.
15 changes: 5 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
FROM golang:1.12.5-alpine3.9 as builder
RUN apk update && apk add git cmake build-base m4
ENV GOPATH $HOME/go
ARG GIT_TAG
RUN go get -d github.com/aergoio/aergo
WORKDIR ${GOPATH}/src/github.com/aergoio/aergo
RUN git checkout --detach ${GIT_TAG} && git submodule init && git submodule update
RUN make aergosvr
COPY . aergo
RUN cd aergo && make aergosvr

FROM alpine:3.9
RUN apk add libgcc
COPY --from=builder $HOME/go/src/github.com/aergoio/aergo/bin/aergosvr /usr/local/bin/
COPY --from=builder $HOME/go/src/github.com/aergoio/aergo/libtool/lib/* /usr/local/lib/
ADD node/testmode.toml /aergo/testmode.toml
ADD node/arglog.toml /aergo/arglog.toml
COPY --from=builder /go/aergo/bin/aergosvr /usr/local/bin/
COPY --from=builder /go/aergo/libtool/lib/* /usr/local/lib/
COPY --from=builder /go/aergo/Docker/conf/* /aergo/
ENV LD_LIBRARY_PATH="/usr/local/lib:${LD_LIBRARY_PATH}"
WORKDIR /aergo/
CMD ["aergosvr", "--home", "/aergo"]
Expand Down
12 changes: 3 additions & 9 deletions Dockerfile.polaris
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
FROM golang:1.12.5-alpine3.9 as builder
RUN apk update && apk add git cmake build-base m4
ENV GOPATH $HOME/go
ARG GIT_TAG
RUN go get -d github.com/aergoio/aergo
WORKDIR ${GOPATH}/src/github.com/aergoio/aergo
RUN git checkout --detach ${GIT_TAG} && git submodule init && git submodule update
RUN make polaris colaris
COPY . aergo
RUN cd aergo && make polaris colaris

FROM alpine:3.9
RUN apk add libgcc
COPY --from=builder $HOME/go/src/github.com/aergoio/aergo/bin/polaris /usr/local/bin/
COPY --from=builder $HOME/go/src/github.com/aergoio/aergo/bin/colaris /usr/local/bin/

COPY --from=builder go/aergo/bin/?olaris /usr/local/bin/
WORKDIR /tools/
CMD ["polaris"]
17 changes: 5 additions & 12 deletions Dockerfile.tools
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
FROM golang:1.12.5-alpine3.9 as builder
RUN apk update && apk add git cmake build-base m4
ENV GOPATH $HOME/go
ARG GIT_TAG
RUN go get -d github.com/aergoio/aergo
WORKDIR ${GOPATH}/src/github.com/aergoio/aergo
RUN git checkout --detach ${GIT_TAG} && git submodule init && git submodule update
RUN make aergocli aergoluac brick
COPY . aergo
RUN cd aergo && make aergocli aergoluac brick

FROM alpine:3.9
RUN apk add libgcc
COPY --from=builder $HOME/go/src/github.com/aergoio/aergo/bin/aergocli /usr/local/bin/
COPY --from=builder $HOME/go/src/github.com/aergoio/aergo/bin/aergoluac /usr/local/bin/
COPY --from=builder $HOME/go/src/github.com/aergoio/aergo/bin/brick /usr/local/bin/
COPY --from=builder $HOME/go/src/github.com/aergoio/aergo/cmd/brick/arglog.toml /tools/arglog.toml
COPY --from=builder $HOME/go/src/github.com/aergoio/aergo/libtool/lib/* /usr/local/lib/

COPY --from=builder /go/aergo/bin/* /usr/local/bin/
COPY --from=builder /go/aergo/cmd/brick/arglog.toml /tools/arglog.toml
COPY --from=builder /go/aergo/libtool/lib/* /usr/local/lib/
ENV LD_LIBRARY_PATH="/usr/local/lib:${LD_LIBRARY_PATH}"
WORKDIR /tools/
CMD ["aergocli"]
6 changes: 5 additions & 1 deletion account/accountservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ func (as *AccountService) BeforeStop() {
}

func (as *AccountService) Statistics() *map[string]interface{} {
return nil
return &map[string]interface{}{
"totalaccounts": len(as.accounts),
"personal": as.cfg.Personal,
"config": as.cfg.Account,
}
}
func (as *AccountService) resolveName(namedAddress []byte) ([]byte, error) {
scs, err := as.sdb.GetStateDB().OpenContractStateAccount(types.ToAccountID([]byte(types.AergoName)))
Expand Down
33 changes: 21 additions & 12 deletions chain/chaindb.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,21 @@ var (
ErrorLoadBestBlock = errors.New("failed to load latest block from DB")
ErrCantDropGenesis = errors.New("can't drop genesis block")
ErrTooBigResetHeight = errors.New("reset height is too big")
ErrWalNoHardState = errors.New("not exist hard state")
ErrInvalidHardState = errors.New("invalid hard state")
ErrInvalidRaftSnapshot = errors.New("invalid raft snapshot")
ErrInvalidCCProgress = errors.New("invalid conf change progress")

latestKey = []byte(chainDBName + ".latest")
receiptsPrefix = []byte("r")

raftIdentityKey = []byte("r_identity")
raftStateKey = []byte("r_state")
raftSnapKey = []byte("r_snap")
raftEntryLastIdxKey = []byte("r_last")
raftEntryPrefix = []byte("r_entry.")
raftIdentityKey = []byte("r_identity")
raftStateKey = []byte("r_state")
raftSnapKey = []byte("r_snap")
raftEntryLastIdxKey = []byte("r_last")
raftEntryPrefix = []byte("r_entry.")
raftEntryInvertPrefix = []byte("r_inv.")
raftConfChangeProgressPrefix = []byte("r_ccstatus.")
)

// ErrNoBlock reports there is no such a block with id (hash or block number).
Expand Down Expand Up @@ -91,6 +95,7 @@ func (cdb *ChainDB) NewTx() db.Transaction {

func (cdb *ChainDB) Init(dbType string, dataDir string) error {
if cdb.store == nil {
logger.Info().Str("datadir", dataDir).Msg("chain database initialized")
dbPath := common.PathMkdirAll(dataDir, chainDBName)
cdb.store = db.NewDB(db.ImplType(dbType), dbPath)
}
Expand Down Expand Up @@ -305,7 +310,7 @@ func (cdb *ChainDB) addGenesisBlock(genesis *types.Genesis) error {
block.BlockID()
}

cdb.connectToChain(&tx, block, false)
cdb.connectToChain(tx, block, false)
tx.Set([]byte(genesisKey), genesis.Bytes())
if totalBalance := genesis.TotalBalance(); totalBalance != nil {
tx.Set([]byte(genesisBalanceKey), totalBalance.Bytes())
Expand Down Expand Up @@ -362,7 +367,7 @@ func (cdb *ChainDB) setLatest(newBestBlock *types.Block) (oldLatest types.BlockN
return
}

func (cdb *ChainDB) connectToChain(dbtx *db.Transaction, block *types.Block, skipAdd bool) (oldLatest types.BlockNo) {
func (cdb *ChainDB) connectToChain(dbtx db.Transaction, block *types.Block, skipAdd bool) (oldLatest types.BlockNo) {
blockNo := block.GetHeader().GetBlockNo()
blockIdx := types.BlockNoToBytes(blockNo)

Expand All @@ -373,12 +378,12 @@ func (cdb *ChainDB) connectToChain(dbtx *db.Transaction, block *types.Block, ski
}

// Update best block hash
(*dbtx).Set(latestKey, blockIdx)
(*dbtx).Set(blockIdx, block.BlockHash())
dbtx.Set(latestKey, blockIdx)
dbtx.Set(blockIdx, block.BlockHash())

// Save the last consensus status.
if cdb.cc != nil {
if err := cdb.cc.Save(*dbtx); err != nil {
if err := cdb.cc.Save(dbtx); err != nil {
logger.Error().Err(err).Msg("failed to save DPoS status")
}
}
Expand Down Expand Up @@ -488,7 +493,7 @@ func (cdb *ChainDB) deleteTx(dbtx *db.Transaction, tx *types.Tx) {
}

// store block info to DB
func (cdb *ChainDB) addBlock(dbtx *db.Transaction, block *types.Block) error {
func (cdb *ChainDB) addBlock(dbtx db.Transaction, block *types.Block) error {
blockNo := block.GetHeader().GetBlockNo()

// TODO: Is it possible?
Expand All @@ -507,7 +512,7 @@ func (cdb *ChainDB) addBlock(dbtx *db.Transaction, block *types.Block) error {
}

//add block
(*dbtx).Set(block.BlockHash(), blockBytes)
dbtx.Set(block.BlockHash(), blockBytes)

return nil
}
Expand Down Expand Up @@ -587,6 +592,10 @@ func (cdb *ChainDB) GetBlock(blockHash []byte) (*types.Block, error) {
return cdb.getBlock(blockHash)
}

func (cdb *ChainDB) GetHashByNo(blockNo types.BlockNo) ([]byte, error) {
return cdb.getHashByNo(blockNo)
}

func (cdb *ChainDB) getBlock(blockHash []byte) (*types.Block, error) {
if blockHash == nil {
return nil, fmt.Errorf("block hash invalid(nil)")
Expand Down
Loading

0 comments on commit e83b884

Please sign in to comment.