Skip to content

Commit

Permalink
Merge pull request #42 from dappledger/develop
Browse files Browse the repository at this point in the history
dev->master
  • Loading branch information
wickyyang authored Oct 15, 2019
2 parents 77b42f0 + a32f5a1 commit 662830a
Show file tree
Hide file tree
Showing 42 changed files with 1,192 additions and 1,014 deletions.
30 changes: 28 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
deaIDE
# See http://help.github.com/ignore-files/ for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile ~/.gitignore_global

*#
*~
.project
.settings

# used by the Makefile
/build/_workspace/
/build/bin/
*.zip
/gemmill/modules/go-log/testdir

# travis
profile.tmp
profile.cov

# IdeaIDE
.idea

# VS Code
.vscode

*.log
build
.DS_Store
.DS_Store

5 changes: 4 additions & 1 deletion .travis.yml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
nguage: go
language: go
go_import_path: https://github.com/dappledger/AnnChain
sudo: false
jobs:
Expand All @@ -17,3 +17,6 @@ jobs:
- make
script:
- make test
- go test ./gemmill/... -coverprofile=coverage.txt -covermode=atomic
after_success:
- bash <(curl -s https://codecov.io/bash)
71 changes: 71 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,77 @@ cd AnnChain
make
```

## Supported Consensus

AnnChain supports bft and raft consensus as valid consensus options,and bft is the default.if you want to use raft, you can operate like this:

##### First, set consensus to raft in config.toml file:

``` shell
consensus = "raft"
```

##### Then, add raft peers config file raft-cluster.json into the runtime dir(take four nodes for example):

``` shell
{
"advertise": "ann7939-validator8fc99df2-2.default.svc.cluster.local:23000",
"local": {
"bind": "0.0.0.0:23000",
"pub_key": [
1,
"35EC28D113DB8D057140F903BAB049770CABAD4C2838509602552511C3F2D2E3"
],
"rpc": "ann7939-validator8fc99df2-2.default.svc.cluster.local:47000"
},
"peers": [
{
"bind": "ann7939-validator480649ca-0.default.svc.cluster.local:23000",
"pub_key": [
1,
"7B788FD0A5A1504C438B2D6B5602717C07F5E82D25175B4065B75C46017B770D"
],
"rpc": "ann7939-validator480649ca-0.default.svc.cluster.local:47000"
},
{
"bind": "ann7939-validatorb14a47dc-1.default.svc.cluster.local:23000",
"pub_key": [
1,
"1FE0A5560BB9376348CB8F218BDA2011280606571DB20B841FA9F7560143796D"
],
"rpc": "ann7939-validatorb14a47dc-1.default.svc.cluster.local:47000"
},
{
"bind": "ann7939-validator8fc99df2-2.default.svc.cluster.local:23000",
"pub_key": [
1,
"35EC28D113DB8D057140F903BAB049770CABAD4C2838509602552511C3F2D2E3"
],
"rpc": "ann7939-validator8fc99df2-2.default.svc.cluster.local:47000"
},
{
"bind": "ann7939-validatore78bd527-3.default.svc.cluster.local:23000",
"pub_key": [
1,
"3C521E9D3D942654FA1E6C52E7B3A4EDE059E047FB4DF4F00F04C092149002EA"
],
"rpc": "10.103.237.176:47000"
}
]
}
```

* advertise: advertise address is used for others peers to connect.

* local.bind: local bind address for raft protocl.

* local.pub_key: node's pubkey, same as pbft pubkey.

* local.rpc: node's rpc bind address.

* peers: others node's bind address and pub_key info, including it selft.


## Quick Start

#### Single node
Expand Down
4 changes: 0 additions & 4 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,11 @@ run()
genesis )
build $prev"/cmd/genesis" "genesis"
;;
api )
build $prev"/cmd/api" "genesis-api"
;;
gtool )
build $prev"/cmd/client" "gtool"
;;
* )
build $prev"/cmd/genesis" "genesis"
build $prev"/cmd/api" "genesis-api"
build $prev"/cmd/client" "gtool"
;;
esac
Expand Down
9 changes: 8 additions & 1 deletion chain/core/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,14 @@ func (n *Node) StartRPC() ([]net.Listener, error) {
mux := http.NewServeMux()
// wm := rpcserver.NewWebsocketManager(rpcRoutes, n.evsw)
// mux.HandleFunc("/websocket", wm.WebsocketHandler)
rpcserver.RegisterRPCFuncs(mux, n.rpcRoutes())
routes := n.rpcRoutes()
for _, v := range n.Angine.APIs() {
for n, h := range v {
routes[n] = h
}
}
rpcserver.RegisterRPCFuncs(mux, routes)

listener, err := rpcserver.StartHTTPServer(listenAddr, mux)
if err != nil {
return nil, err
Expand Down
5 changes: 3 additions & 2 deletions cmd/client/commands/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ import (
"fmt"

"gopkg.in/urfave/cli.v1"

"github.com/dappledger/AnnChain/chain/types"
)

var (
VERSION string
VersionCommands = cli.Command{
Name: "version",
Action: ShowVersion,
Expand All @@ -36,5 +37,5 @@ var (
)

func ShowVersion(ctx *cli.Context) {
fmt.Println("version:", VERSION)
fmt.Println("version:", types.GetVersion())
}
3 changes: 2 additions & 1 deletion cmd/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

"gopkg.in/urfave/cli.v1"

"github.com/dappledger/AnnChain/chain/types"
"github.com/dappledger/AnnChain/cmd/client/commands"
"github.com/dappledger/AnnChain/cmd/client/commons"
)
Expand All @@ -27,7 +28,7 @@ func main() {

app := cli.NewApp()
app.Name = "anntool"
app.Version = "0.6"
app.Version = types.GetVersion()

app.Commands = []cli.Command{
commands.SignCommand,
Expand Down
68 changes: 38 additions & 30 deletions eth/common/hexutil/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package hexutil
import (
"bytes"
"encoding/hex"
"encoding/json"
"errors"
"math/big"
"testing"
)
Expand Down Expand Up @@ -55,15 +57,17 @@ func referenceBytes(s string) []byte {
return b
}

var errJSONEOF = errors.New("unexpected end of JSON input")

var unmarshalBytesTests = []unmarshalTest{
// invalid encoding
{input: "", wantErr: errNonString},
{input: "null", wantErr: errNonString},
{input: "10", wantErr: errNonString},
{input: `"0"`, wantErr: ErrMissingPrefix},
{input: `"0x0"`, wantErr: ErrOddLength},
{input: `"0xxx"`, wantErr: ErrSyntax},
{input: `"0x01zz01"`, wantErr: ErrSyntax},
{input: "", wantErr: errJSONEOF},
{input: "null", wantErr: errNonString(bytesT)},
{input: "10", wantErr: errNonString(bytesT)},
{input: `"0"`, wantErr: wrapTypeError(ErrMissingPrefix, bytesT)},
{input: `"0x0"`, wantErr: wrapTypeError(ErrOddLength, bytesT)},
{input: `"0xxx"`, wantErr: wrapTypeError(ErrSyntax, bytesT)},
{input: `"0x01zz01"`, wantErr: wrapTypeError(ErrSyntax, bytesT)},

// valid encoding
{input: `""`, want: referenceBytes("")},
Expand All @@ -80,7 +84,7 @@ var unmarshalBytesTests = []unmarshalTest{
func TestUnmarshalBytes(t *testing.T) {
for _, test := range unmarshalBytesTests {
var v Bytes
err := v.UnmarshalJSON([]byte(test.input))
err := json.Unmarshal([]byte(test.input), &v)
if !checkError(t, test.input, err, test.wantErr) {
continue
}
Expand All @@ -104,7 +108,7 @@ func BenchmarkUnmarshalBytes(b *testing.B) {
func TestMarshalBytes(t *testing.T) {
for _, test := range encodeBytesTests {
in := test.input.([]byte)
out, err := Bytes(in).MarshalJSON()
out, err := json.Marshal(Bytes(in))
if err != nil {
t.Errorf("%x: %v", in, err)
continue
Expand All @@ -122,14 +126,18 @@ func TestMarshalBytes(t *testing.T) {

var unmarshalBigTests = []unmarshalTest{
// invalid encoding
{input: "", wantErr: errNonString},
{input: "null", wantErr: errNonString},
{input: "10", wantErr: errNonString},
{input: `"0"`, wantErr: ErrMissingPrefix},
{input: `"0x"`, wantErr: ErrEmptyNumber},
{input: `"0x01"`, wantErr: ErrLeadingZero},
{input: `"0xx"`, wantErr: ErrSyntax},
{input: `"0x1zz01"`, wantErr: ErrSyntax},
{input: "", wantErr: errJSONEOF},
{input: "null", wantErr: errNonString(bigT)},
{input: "10", wantErr: errNonString(bigT)},
{input: `"0"`, wantErr: wrapTypeError(ErrMissingPrefix, bigT)},
{input: `"0x"`, wantErr: wrapTypeError(ErrEmptyNumber, bigT)},
{input: `"0x01"`, wantErr: wrapTypeError(ErrLeadingZero, bigT)},
{input: `"0xx"`, wantErr: wrapTypeError(ErrSyntax, bigT)},
{input: `"0x1zz01"`, wantErr: wrapTypeError(ErrSyntax, bigT)},
{
input: `"0x10000000000000000000000000000000000000000000000000000000000000000"`,
wantErr: wrapTypeError(ErrBig256Range, bigT),
},

// valid encoding
{input: `""`, want: big.NewInt(0)},
Expand All @@ -153,7 +161,7 @@ var unmarshalBigTests = []unmarshalTest{
func TestUnmarshalBig(t *testing.T) {
for _, test := range unmarshalBigTests {
var v Big
err := v.UnmarshalJSON([]byte(test.input))
err := json.Unmarshal([]byte(test.input), &v)
if !checkError(t, test.input, err, test.wantErr) {
continue
}
Expand All @@ -177,7 +185,7 @@ func BenchmarkUnmarshalBig(b *testing.B) {
func TestMarshalBig(t *testing.T) {
for _, test := range encodeBigTests {
in := test.input.(*big.Int)
out, err := (*Big)(in).MarshalJSON()
out, err := json.Marshal((*Big)(in))
if err != nil {
t.Errorf("%d: %v", in, err)
continue
Expand All @@ -195,15 +203,15 @@ func TestMarshalBig(t *testing.T) {

var unmarshalUint64Tests = []unmarshalTest{
// invalid encoding
{input: "", wantErr: errNonString},
{input: "null", wantErr: errNonString},
{input: "10", wantErr: errNonString},
{input: `"0"`, wantErr: ErrMissingPrefix},
{input: `"0x"`, wantErr: ErrEmptyNumber},
{input: `"0x01"`, wantErr: ErrLeadingZero},
{input: `"0xfffffffffffffffff"`, wantErr: ErrUint64Range},
{input: `"0xx"`, wantErr: ErrSyntax},
{input: `"0x1zz01"`, wantErr: ErrSyntax},
{input: "", wantErr: errJSONEOF},
{input: "null", wantErr: errNonString(uint64T)},
{input: "10", wantErr: errNonString(uint64T)},
{input: `"0"`, wantErr: wrapTypeError(ErrMissingPrefix, uint64T)},
{input: `"0x"`, wantErr: wrapTypeError(ErrEmptyNumber, uint64T)},
{input: `"0x01"`, wantErr: wrapTypeError(ErrLeadingZero, uint64T)},
{input: `"0xfffffffffffffffff"`, wantErr: wrapTypeError(ErrUint64Range, uint64T)},
{input: `"0xx"`, wantErr: wrapTypeError(ErrSyntax, uint64T)},
{input: `"0x1zz01"`, wantErr: wrapTypeError(ErrSyntax, uint64T)},

// valid encoding
{input: `""`, want: uint64(0)},
Expand All @@ -219,7 +227,7 @@ var unmarshalUint64Tests = []unmarshalTest{
func TestUnmarshalUint64(t *testing.T) {
for _, test := range unmarshalUint64Tests {
var v Uint64
err := v.UnmarshalJSON([]byte(test.input))
err := json.Unmarshal([]byte(test.input), &v)
if !checkError(t, test.input, err, test.wantErr) {
continue
}
Expand All @@ -241,7 +249,7 @@ func BenchmarkUnmarshalUint64(b *testing.B) {
func TestMarshalUint64(t *testing.T) {
for _, test := range encodeUint64Tests {
in := test.input.(uint64)
out, err := Uint64(in).MarshalJSON()
out, err := json.Marshal(Uint64(in))
if err != nil {
t.Errorf("%d: %v", in, err)
continue
Expand Down
2 changes: 1 addition & 1 deletion eth/core/vm/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func NewEVMInterpreter(evm *EVM, cfg Config) *EVMInterpreter {
}

// Edit by zhongan
cfg.JumpTable = byzantiumInstructionSet
cfg.JumpTable = constantinopleInstructionSet
}

return &EVMInterpreter{
Expand Down
3 changes: 2 additions & 1 deletion eth/core/vm/runtime/runtime_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ import (
"fmt"

"github.com/dappledger/AnnChain/eth/common"
"github.com/dappledger/AnnChain/eth/core/vm"
"github.com/dappledger/AnnChain/eth/core/vm/runtime"
)

func ExampleExecute() {
ret, _, err := runtime.Execute(common.Hex2Bytes("6060604052600a8060106000396000f360606040526008565b00"), nil, nil)
ret, _, err := runtime.Execute(common.Hex2Bytes("6060604052600a8060106000396000f360606040526008565b00"), nil, &runtime.Config{EVMConfig: vm.Config{EVMGasLimit: 100000000}})
if err != nil {
fmt.Println(err)
}
Expand Down
4 changes: 2 additions & 2 deletions eth/core/vm/runtime/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestExecute(t *testing.T) {
byte(vm.PUSH1), 32,
byte(vm.PUSH1), 0,
byte(vm.RETURN),
}, nil, nil)
}, nil, &Config{EVMConfig: vm.Config{EVMGasLimit: 100000000}})
if err != nil {
t.Fatal("didn't expect error", err)
}
Expand All @@ -106,7 +106,7 @@ func TestCall(t *testing.T) {
byte(vm.RETURN),
})

ret, _, err := Call(address, nil, &Config{State: state})
ret, _, err := Call(address, nil, &Config{State: state, EVMConfig: vm.Config{EVMGasLimit: 100000000}})
if err != nil {
t.Fatal("didn't expect error", err)
}
Expand Down
Loading

0 comments on commit 662830a

Please sign in to comment.