Skip to content

Commit

Permalink
Merge branch 'release/1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
graup committed Jun 4, 2019
2 parents cb68557 + efe71ea commit a9a0eee
Show file tree
Hide file tree
Showing 237 changed files with 15,763 additions and 6,421 deletions.
4 changes: 3 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
*.go text eol=lf
* text=auto
contract/sqlite3-binding.* linguist-vendored
contract/sqlite3*.* linguist-vendored=true
libtool/src/gmp-*/* linguist-vendored=true

4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ os:
- osx

go:
- 1.10.x
- 1.12.x

before_install:
- go get -t github.com/Masterminds/glide
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then go get -t github.com/codeclimate/test-reporter; fi
- cmake .

install:
- make all polaris colaris
Expand Down
46 changes: 19 additions & 27 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,55 +17,47 @@ endif()

add_custom_target(build ALL DEPENDS aergocli aergosvr aergoluac brick)

add_custom_target(aergocli GOBIN=${BIN_DIR} go install ${GCFLAGS} -ldflags \"-X github.com/aergoio/aergo/cmd/aergocli/cmd.githash=`git describe --tags`\" ./cmd/aergocli/...
add_custom_target(aergocli GO111MODULE=on GOBIN=${BIN_DIR} go install ${GCFLAGS} -ldflags \"-X github.com/aergoio/aergo/cmd/aergocli/cmd.githash=`git describe --tags`\" ./cmd/aergocli/...
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
DEPENDS vendor libtool)
DEPENDS libtool)

add_custom_target(aergosvr GOBIN=${BIN_DIR} go install ${GCFLAGS} -ldflags \"-X main.githash=`git describe --tags` -X main.gitRevision=`git rev-parse --short HEAD` -X main.gitBranch=`git rev-parse --symbolic-full-name --abbrev-ref HEAD`\" ./cmd/aergosvr/...
add_custom_target(aergosvr GO111MODULE=on GOBIN=${BIN_DIR} go install ${GCFLAGS} -ldflags \"-X main.githash=`git describe --tags` -X main.gitRevision=`git rev-parse --short HEAD` -X main.gitBranch=`git rev-parse --symbolic-full-name --abbrev-ref HEAD`\" ./cmd/aergosvr/...
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
DEPENDS vendor libtool)
DEPENDS libtool)

add_custom_target(polaris GOBIN=${BIN_DIR} go install ${GCFLAGS} ./cmd/polaris/...
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
DEPENDS vendor libtool)
add_custom_target(polaris GO111MODULE=on GOBIN=${BIN_DIR} go install ${GCFLAGS} -ldflags \"-X github.com/aergoio/aergo/cmd/polaris/cmd.githash=`git rev-parse HEAD`\" ./cmd/polaris/...
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})

add_custom_target(colaris GOBIN=${BIN_DIR} go install ${GCFLAGS} -ldflags \"-X github.com/aergoio/aergo/cmd/colaris/cmd.githash=`git rev-parse HEAD`\" ./cmd/colaris/...
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
DEPENDS vendor libtool)
add_custom_target(colaris GO111MODULE=on GOBIN=${BIN_DIR} go install ${GCFLAGS} -ldflags \"-X github.com/aergoio/aergo/cmd/colaris/cmd.githash=`git rev-parse HEAD`\" ./cmd/colaris/...
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})

add_custom_target(aergoluac GOBIN=${BIN_DIR} go install ${GCFLAGS} ./cmd/aergoluac/...
add_custom_target(aergoluac GO111MODULE=on GOBIN=${BIN_DIR} go install ${GCFLAGS} -ldflags \"-X main.githash=`git describe --tags`\" ./cmd/aergoluac/...
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
DEPENDS vendor libtool)
DEPENDS libtool)

add_custom_target(brick GOBIN=${BIN_DIR} go install ${GCFLAGS} ${GFLAG} -ldflags \"-X 'github.com/aergoio/aergo/cmd/brick/context.GitHash=`git describe --tags`'
-X 'github.com/aergoio/aergo/vendor/github.com/aergoio/aergo-lib/log.defaultConfStr=`cat ./cmd/brick/arglog.toml`'\" ./cmd/brick/...
add_custom_target(brick GO111MODULE=on GOBIN=${BIN_DIR} go install ${GCFLAGS} ${GFLAG} -ldflags \"-X 'github.com/aergoio/aergo/cmd/brick/context.GitHash=`git describe --tags`'
-X 'github.com/aergoio/aergo-lib/log.defaultConfStr=`cat ./cmd/brick/arglog.toml`'\" ./cmd/brick/...
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
DEPENDS vendor libtool)
DEPENDS libtool)

set(VENDOR ${CMAKE_CURRENT_LIST_DIR}/vendor)
add_custom_command(OUTPUT ${VENDOR}
COMMAND glide install
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
DEPENDS glide.yaml glide.lock)
add_custom_target(vendor DEPENDS ${VENDOR})
add_custom_target(deps DEPENDS libtool)

add_custom_target(deps DEPENDS vendor libtool)

add_custom_target(check go test -timeout 60s ./...
add_custom_target(check GO111MODULE=on go test -timeout 60s ./...
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
DEPENDS build)
add_custom_target(cover-check go test -coverprofile c.out ./...
add_custom_target(cover-check GO111MODULE=on go test -coverprofile c.out ./...
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
DEPENDS build)

add_custom_target(distclean go clean ..
add_custom_target(distclean GO111MODULE=on go clean ..
COMMAND rm -rf ${BIN_DIR}/aergo* ${BIN_DIR}/brick
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 go build ../types/...)
COMMAND GO111MODULE=on go build ../types/...)

add_custom_target(protoclean rm -f ../types/*.pb.go)


add_subdirectory(libtool)
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
FROM golang:alpine as builder
RUN apk update && apk add git glide cmake build-base m4
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 && cmake .
RUN git checkout --detach ${GIT_TAG} && git submodule init && git submodule update
RUN make aergosvr

FROM alpine:3.8
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/
Expand Down
10 changes: 4 additions & 6 deletions Dockerfile.polaris
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
FROM golang:alpine as builder
RUN apk update && apk add git glide cmake build-base m4
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 && cmake .
RUN git checkout --detach ${GIT_TAG} && git submodule init && git submodule update
RUN make polaris colaris

FROM alpine:3.8
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 $HOME/go/src/github.com/aergoio/aergo/libtool/lib/* /usr/local/lib/
ENV LD_LIBRARY_PATH="/usr/local/lib:${LD_LIBRARY_PATH}"

WORKDIR /tools/
CMD ["polaris"]
8 changes: 4 additions & 4 deletions Dockerfile.tools
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
FROM golang:alpine as builder
RUN apk update && apk add git glide cmake build-base m4
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 && cmake .
RUN git checkout --detach ${GIT_TAG} && git submodule init && git submodule update
RUN make aergocli aergoluac brick

FROM alpine:3.8
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/
Expand Down
32 changes: 22 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,35 @@ ifeq ($(OS),Windows_NT)
endif
endif

.PHONY: all release debug clean
BUILD_RULES := \
deps \
aergocli aergosvr aergoluac polaris colaris brick \
libtool libtool-clean \
libluajit liblmdb libgmp \
libluajit-clean liblmdb-clean libgmp-clean \
check cover-check \
distclean \
protoc protoclean

.PHONY: all release debug clean $(BUILD_RULES)

all: $(BUILD_FILE)
@$(MAKE) --no-print-directory -C $(BUILD_DIR)

$(BUILD_FILE):
$(BUILD_DIR):
@mkdir -p $(BUILD_DIR)
cd $(BUILD_DIR) && $(CMAKE_CMD) -G "Unix Makefiles" -D CMAKE_BUILD_TYPE="Release" $(MAKE_FLAG) ..

release:
@mkdir -p $(BUILD_DIR)
$(BUILD_FILE): $(BUILD_DIR)
@if ! [ -f $(BUILD_FILE) ]; then \
cd $(BUILD_DIR) && $(CMAKE_CMD) -G "Unix Makefiles" -D CMAKE_BUILD_TYPE="Release" $(MAKE_FLAG) ..; \
fi

release: $(BUILD_DIR)
cd $(BUILD_DIR) && $(CMAKE_CMD) -G "Unix Makefiles" -D CMAKE_BUILD_TYPE="Release" $(MAKE_FLAG) ..
@$(MAKE) --no-print-directory -C $(BUILD_DIR)

debug:
@mkdir -p $(BUILD_DIR)
cd $(BUILD_DIR) && $(CMAKE_CMD) -G "Unix Makefiles" -D CMAKE_BUILD_TYPE="Debug" $(MAKE_FLAG) ..
debug: $(BUILD_DIR)
@cd $(BUILD_DIR) && $(CMAKE_CMD) -G "Unix Makefiles" -D CMAKE_BUILD_TYPE="Debug" $(MAKE_FLAG) ..
@$(MAKE) --no-print-directory -C $(BUILD_DIR)

clean:
Expand All @@ -41,5 +53,5 @@ clean:
realclean: clean
@rm -rf $(BUILD_DIR)

%:
@$(MAKE) --no-print-directory -C $(BUILD_DIR) $(MAKECMDGOALS)
$(BUILD_RULES): $(BUILD_FILE)
@$(MAKE) --no-print-directory -C $(BUILD_DIR) $@
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ MVP based, Forward compatibility, Iteration

### Prerequisites

* Go1.10 or higher - https://golang.org/dl
* Glide - https://github.com/Masterminds/glide
* Go1.11.4+ - https://golang.org/dl
* Proto Buffers - https://github.com/google/protobuf
* CMake 3.0.0 or higher - https://cmake.org

Expand Down
7 changes: 7 additions & 0 deletions account/key/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,19 @@ func (ks *Store) SaveAddress(addr Address) error {
if len(addr) != types.AddressLength {
return errors.New("invalid address length")
}

ks.RWMutex.Lock()
defer ks.RWMutex.Unlock()

addrs := append(ks.storage.Get(addresses), addr...)
ks.storage.Set(addresses, addrs)
return nil
}

func (ks *Store) GetAddresses() ([]Address, error) {
ks.RWMutex.RLock()
defer ks.RWMutex.RUnlock()

b := ks.storage.Get(addresses)
var ret []Address
for i := 0; i < len(b); i += types.AddressLength {
Expand Down
24 changes: 18 additions & 6 deletions account/key/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"crypto/cipher"
"errors"
"path"
"sync"
"time"

"github.com/aergoio/aergo-lib/db"
Expand All @@ -23,19 +24,22 @@ type keyPair struct {

// Store stucture of keystore
type Store struct {
timeout time.Duration
unlocked map[string]*keyPair
storage db.DB
sync.RWMutex
timeout time.Duration
unlocked map[string]*keyPair
unlockedLock *sync.Mutex
storage db.DB
}

// NewStore make new instance of keystore
func NewStore(storePath string, unlockTimeout uint) *Store {
const dbName = "account"
dbPath := path.Join(storePath, dbName)
return &Store{
timeout: time.Duration(unlockTimeout) * time.Second,
unlocked: map[string]*keyPair{},
storage: db.NewDB(db.LevelImpl, dbPath),
timeout: time.Duration(unlockTimeout) * time.Second,
unlocked: map[string]*keyPair{},
unlockedLock: &sync.Mutex{},
storage: db.NewDB(db.LevelImpl, dbPath),
}
}
func (ks *Store) CloseStore() {
Expand Down Expand Up @@ -103,6 +107,10 @@ func (ks *Store) Unlock(addr Address, pass string) (Address, error) {
}
pk, _ := btcec.PrivKeyFromBytes(btcec.S256(), key)
addrKey := types.EncodeAddress(addr)

ks.unlockedLock.Lock()
defer ks.unlockedLock.Unlock()

unlockedKeyPair, exist := ks.unlocked[addrKey]

if ks.timeout == 0 {
Expand Down Expand Up @@ -130,6 +138,10 @@ func (ks *Store) Lock(addr Address, pass string) (Address, error) {
return nil, err
}
b58addr := types.EncodeAddress(addr)

ks.unlockedLock.Lock()
defer ks.unlockedLock.Unlock()

if _, exist := ks.unlocked[b58addr]; exist {
ks.unlocked[b58addr] = nil
delete(ks.unlocked, b58addr)
Expand Down
30 changes: 29 additions & 1 deletion account/key/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package key
import (
"fmt"
"io/ioutil"
"sync"
"testing"

"github.com/aergoio/aergo/types"
"github.com/stretchr/testify/assert"
)

var (
Expand Down Expand Up @@ -53,7 +55,7 @@ func TestCreateKeyLongPass(t *testing.T) {
}
}

func TestExportKey(t *testing.T) {
func TestExportImportKey(t *testing.T) {
initTest()
defer deinitTest()
const testSize = 10
Expand All @@ -73,6 +75,9 @@ func TestExportKey(t *testing.T) {
if len(exported) != 48 {
t.Errorf("invalid exported address : length = %d", len(exported))
}
imported, err := ks.ImportKey(exported, pass, pass)
assert.NoError(t, err, "import")
assert.Equal(t, imported, addr, "import result")
}
}

Expand Down Expand Up @@ -127,3 +132,26 @@ func TestSign(t *testing.T) {
}
}
}

func TestConcurrentUnlockAndLock(t *testing.T) {
initTest()
defer deinitTest()

pass := "password"
addr, err := ks.CreateKey(pass)
if err != nil {
t.Errorf("could not create key : %s", err.Error())
}

const testSize = 50
var wg sync.WaitGroup
for i := 0; i < testSize; i++ {
wg.Add(1)
go func(wg *sync.WaitGroup, id int) {
defer wg.Done()
ks.Unlock(addr, pass)
ks.Lock(addr, pass)
}(&wg, i)
}
wg.Wait()
}
2 changes: 1 addition & 1 deletion aergo-protobuf
Loading

0 comments on commit a9a0eee

Please sign in to comment.