-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #315 from MinterTeam/dev
v1.1.6
- Loading branch information
Showing
30 changed files
with
1,682 additions
and
410 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,58 @@ | ||
name: docker | ||
|
||
on: push | ||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
pull_request: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
docker: | ||
env: | ||
CONTAINER_NAME: minter_node | ||
CONTAINER_TIMEOUT_SEC: 10 | ||
API_RUN_PORT: 8841 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v1 | ||
with: | ||
fetch-depth: 1 | ||
|
||
- name: Build & Push to Docker Hub | ||
uses: opspresso/action-docker@master | ||
env: | ||
USERNAME: ${{ secrets.DOCKER_HUB_USER }} | ||
PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }} | ||
IMAGE_NAME: "minterteam/minter" | ||
LATEST: "true" | ||
TAG_NAME: "v1.0.5" | ||
- name: Set envs | ||
run: | | ||
echo ::set-env name=VERSION::$(awk -F\" '/Version =/ { print $2; exit }' < version/version.go) | ||
- name: Docker build | ||
run: docker build -t ${{ secrets.DOCKER_HUB_USER }}/minter:${{ env.VERSION }} . | ||
|
||
- name: Start docker container | ||
run: docker run -d --name $CONTAINER_NAME -p $API_RUN_PORT:8841 ${{ secrets.DOCKER_HUB_USER }}/minter:${{ env.VERSION }} | ||
|
||
- name: Check container is still running | ||
run: | | ||
echo ::set-env name=RUN_TEST_RESULT::$(sleep $CONTAINER_TIMEOUT_SEC && if [[ $(docker inspect -f "{{.State.Running}}" $CONTAINER_NAME 2> /dev/null) == true ]]; then echo OK; else echo FAIL; fi;) | ||
- name: Check api is available by HTTP (response code is 200) | ||
run: | | ||
echo ::set-env name=API_TEST_RESULT::$(if [[ $(curl -LIs localhost:$API_RUN_PORT -o /dev/null -w '%{http_code}') == 200 ]]; then echo OK; else echo FAIL; fi) | ||
- name: Print test results | ||
run: | | ||
echo $RUN_TEST_RESULT | ||
echo $API_TEST_RESULT | ||
- name: Tests fail | ||
run: docker logs $CONTAINER_NAME && exit 1 | ||
if: ${{ env.RUN_TEST_RESULT }} == 'FAIL' || ${{ env.API_TEST_RESULT }} == 'FAIL' | ||
|
||
- name: Docker push versioned image | ||
run: docker push ${{ secrets.DOCKER_HUB_USER }}/minter:${{ env.VERSION }} | ||
if: github.ref == 'refs/heads/master' | ||
|
||
- name: Docker push latest image | ||
run: docker push ${{ secrets.DOCKER_HUB_USER }}/minter:latest | ||
if: github.ref == 'refs/heads/master' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,16 @@ | ||
package service | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"encoding/hex" | ||
"fmt" | ||
pb "github.com/MinterTeam/node-grpc-gateway/api_pb" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
) | ||
|
||
func (s *Service) MissedBlocks(_ context.Context, req *pb.MissedBlocksRequest) (*pb.MissedBlocksResponse, error) { | ||
cState, err := s.getStateForHeight(req.Height) | ||
blocks, count, err := s.blockchain.MissedBlocks(req.PublicKey, uint64(req.Height)) | ||
if err != nil { | ||
return new(pb.MissedBlocksResponse), status.Error(codes.NotFound, err.Error()) | ||
return new(pb.MissedBlocksResponse), err | ||
} | ||
|
||
if req.Height != 0 { | ||
cState.Lock() | ||
cState.Validators.LoadValidators() | ||
cState.Unlock() | ||
} | ||
|
||
cState.RLock() | ||
defer cState.RUnlock() | ||
|
||
vals := cState.Validators.GetValidators() | ||
if vals == nil { | ||
return new(pb.MissedBlocksResponse), status.Error(codes.NotFound, "Validators not found") | ||
} | ||
|
||
for _, val := range vals { | ||
if len(req.PublicKey) < 3 { | ||
return new(pb.MissedBlocksResponse), status.Error(codes.InvalidArgument, "invalid public_key") | ||
} | ||
decodeString, err := hex.DecodeString(req.PublicKey[2:]) | ||
if err != nil { | ||
return new(pb.MissedBlocksResponse), status.Error(codes.InvalidArgument, err.Error()) | ||
} | ||
if bytes.Compare(val.PubKey[:], decodeString) == 0 { | ||
return &pb.MissedBlocksResponse{ | ||
MissedBlocks: val.AbsentTimes.String(), | ||
MissedBlocksCount: fmt.Sprintf("%d", val.CountAbsentTimes()), | ||
}, nil | ||
} | ||
} | ||
|
||
return new(pb.MissedBlocksResponse), status.Error(codes.NotFound, "Validator not found") | ||
|
||
return &pb.MissedBlocksResponse{MissedBlocks: blocks, MissedBlocksCount: fmt.Sprintf("%d", count)}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env bash | ||
|
||
cd "$(dirname "$0")" || exit | ||
|
||
protoc --go_out=plugins=grpc:. ./manager.proto |
Oops, something went wrong.