Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opt isProposer and isEndorser #1285

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 3 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,32 +63,13 @@ all-cross: ontology-cross tools-cross abi
format:
$(GOFMT) -w main.go

docker/payload: docker/build/bin/ontology docker/Dockerfile
@echo "Building ontology payload"
@mkdir -p $@
@cp docker/Dockerfile $@
@cp docker/build/bin/ontology $@
@touch $@

docker/build/bin/%: Makefile
@echo "Building ontology in docker"
@mkdir -p docker/build/bin docker/build/pkg
@$(DRUN) --rm \
-v $(abspath docker/build/bin):/go/bin \
-v $(abspath docker/build/pkg):/go/pkg \
-v $(GOPATH)/src:/go/src \
-w /go/src/github.com/ontio/ontology \
golang:1.9.5-stretch \
$(GC) $(BUILD_NODE_PAR) -o docker/build/bin/ontology main.go
@touch $@

docker: Makefile docker/payload docker/Dockerfile
docker: Makefile
@echo "Building ontology docker"
@$(DBUILD) -t $(DOCKER_NS)/ontology docker/payload
@docker tag $(DOCKER_NS)/ontology $(DOCKER_NS)/ontology:$(DOCKER_TAG)
@$(DBUILD) --no-cache -t $(DOCKER_NS)/ontology:$(DOCKER_TAG) - < docker/Dockerfile
@touch $@

clean:
rm -rf *.8 *.o *.out *.6 *exe coverage
rm -rf ontology ontology-* tools docker/payload docker/build
rm -rf ontology ontology-* tools

54 changes: 24 additions & 30 deletions cmd/abi/native_abi_script/governance.json
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,29 @@
],
"returnType":"Bool"
},
{
"name":"setFeePercentage",
"parameters":
[
{
"name":"PeerPubkey",
"type":"String"
},
{
"name":"Address",
"type":"Address"
},
{
"name":"PeerCost",
"type":"Int"
},
{
"name":"StakeCost",
"type":"Int"
}
],
"returnType":"Bool"
},
{
"name":"withdrawFee",
"parameters":
Expand Down Expand Up @@ -556,38 +579,9 @@
}
],
"returnType":"Bool"
},
{
"name":"getPeerPool",
"parameters":
[
],
"returnType":"ByteArray"
},
{
"name":"getPeerInfo",
"parameters":
[
{
"name":"PeerPublicKey",
"type":"String"
}
],
"returnType":"ByteArray"
},
{
"name":"getPeerPoolByAddress",
"parameters":
[
{
"name":"Address",
"type":"Address"
}
],
"returnType":"ByteArray"
}
],
"events":
[
]
}
}
12 changes: 3 additions & 9 deletions cmd/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ var schemeMap = map[string]schemeInfo{
// wait for user to choose options
func chooseKeyType(reader *bufio.Reader) string {
common.PrintNotice("key type")
for true {
for {
tmp, _ := reader.ReadString('\n')
tmp = strings.TrimSpace(tmp)
_, ok := keyTypeMap[tmp]
Expand All @@ -123,7 +123,7 @@ func chooseKeyType(reader *bufio.Reader) string {
}
func chooseScheme(reader *bufio.Reader) string {
common.PrintNotice("signature-scheme")
for true {
for {
tmp, _ := reader.ReadString('\n')
tmp = strings.TrimSpace(tmp)

Expand All @@ -139,7 +139,7 @@ func chooseScheme(reader *bufio.Reader) string {
}
func chooseCurve(reader *bufio.Reader) string {
common.PrintNotice("curve")
for true {
for {
tmp, _ := reader.ReadString('\n')
tmp = strings.TrimSpace(tmp)
_, ok := curveMap[tmp]
Expand Down Expand Up @@ -217,15 +217,12 @@ func checkCurve(ctx *cli.Context, reader *bufio.Reader, t *string) string {
} else {
c = chooseCurve(reader)
}
break
case "sm2":
fmt.Println("Use curve sm2p256v1 with key length of 256 bits.")
c = "SM2P256V1"
break
case "ed25519":
fmt.Println("Use curve 25519 with key length of 256 bits.")
c = "ED25519"
break
default:
return ""
}
Expand All @@ -247,15 +244,12 @@ func checkScheme(ctx *cli.Context, reader *bufio.Reader, t *string) string {
} else {
sch = chooseScheme(reader)
}
break
case "sm2":
fmt.Println("Use SM3withSM2 as the signature scheme.")
sch = "SM3withSM2"
break
case "ed25519":
fmt.Println("Use SHA512withEdDSA as the signature scheme.")
sch = "SHA512withEdDSA"
break
default:
return ""
}
Expand Down
3 changes: 0 additions & 3 deletions cmd/common/notice.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ Select a signature algorithm from the following:
3 Ed25519

[default is 1]: `)
break

case "curve":
fmt.Printf(`
Expand All @@ -46,7 +45,6 @@ Select a curve from the following:
4 | P-521 | 521

This determines the length of the private key [default is 2]: `)
break

case "signature-scheme":
fmt.Printf(`
Expand All @@ -63,7 +61,6 @@ Select a signature scheme from the following:
9 RIPEMD160withECDSA

This can be changed later [default is 2]: `)
break

default:
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/contract_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func deployContract(ctx *cli.Context) error {
gasPrice = 0
}

cversion := fmt.Sprintf("%s", version)
cversion := version

if ctx.IsSet(utils.GetFlagName(utils.ContractPrepareDeployFlag)) {
preResult, err := utils.PrepareDeployContract(vmtype, code, name, cversion, author, email, desc)
Expand Down
6 changes: 6 additions & 0 deletions cmd/sig_tx_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ func genMultiSigAddress(ctx *cli.Context) error {
continue
}
data, err := hex.DecodeString(pk)
if err != nil {
return err
}
pubKey, err := keypair.DeserializePublicKey(data)
if err != nil {
return fmt.Errorf("invalid pub key:%s", pk)
Expand Down Expand Up @@ -141,6 +144,9 @@ func multiSigToTx(ctx *cli.Context) error {
continue
}
data, err := hex.DecodeString(pk)
if err != nil {
return err
}
pubKey, err := keypair.DeserializePublicKey(data)
if err != nil {
return fmt.Errorf("invalid pub key:%s", pk)
Expand Down
15 changes: 7 additions & 8 deletions cmd/tx_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,10 @@ func transferTx(ctx *cli.Context) error {
switch strings.ToLower(asset) {
case "ont":
amount = utils.ParseOnt(amountStr)
amountStr = utils.FormatOnt(amount)
// amountStr = utils.FormatOnt(amount)
case "ong":
amount = utils.ParseOng(amountStr)
amountStr = utils.FormatOng(amount)
// amountStr = utils.FormatOng(amount)
default:
return fmt.Errorf("unsupport asset:%s", asset)
}
Expand Down Expand Up @@ -277,10 +277,10 @@ func approveTx(ctx *cli.Context) error {
switch strings.ToLower(asset) {
case "ont":
amount = utils.ParseOnt(amountStr)
amountStr = utils.FormatOnt(amount)
// amountStr = utils.FormatOnt(amount)
case "ong":
amount = utils.ParseOng(amountStr)
amountStr = utils.FormatOng(amount)
// amountStr = utils.FormatOng(amount)
default:
return fmt.Errorf("unsupport asset:%s", asset)
}
Expand Down Expand Up @@ -363,10 +363,9 @@ func transferFromTx(ctx *cli.Context) error {
switch strings.ToLower(asset) {
case "ont":
amount = utils.ParseOnt(amountStr)
amountStr = utils.FormatOnt(amount)
case "ong":
amount = utils.ParseOng(amountStr)
amountStr = utils.FormatOng(amount)
// amountStr = utils.FormatOng(amount)
default:
return fmt.Errorf("unsupport asset:%s", asset)
}
Expand Down Expand Up @@ -425,13 +424,13 @@ func withdrawONGTx(ctx *cli.Context) error {
if amount <= 0 {
return fmt.Errorf("haven't unbound ong")
}
amountStr = utils.FormatOng(amount)
// amountStr = utils.FormatOng(amount)
} else {
amount = utils.ParseOng(amountStr)
if amount <= 0 {
return fmt.Errorf("haven't unbound ong")
}
amountStr = utils.FormatOng(amount)
// amountStr = utils.FormatOng(amount)
}

var payer common.Address
Expand Down
15 changes: 7 additions & 8 deletions cmd/utils/ont.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import (
"github.com/ontio/ontology/core/types"
cutils "github.com/ontio/ontology/core/utils"
httpcom "github.com/ontio/ontology/http/base/common"
rpccommon "github.com/ontio/ontology/http/base/common"
"github.com/ontio/ontology/smartcontract/service/native/ont"
"github.com/ontio/ontology/smartcontract/service/native/utils"
)
Expand Down Expand Up @@ -454,12 +453,12 @@ func SendRawTransactionData(txData string) (string, error) {
return hexHash, nil
}

func PrepareSendRawTransaction(txData string) (*rpccommon.PreExecuteResult, error) {
func PrepareSendRawTransaction(txData string) (*httpcom.PreExecuteResult, error) {
data, ontErr := sendRpcRequest("sendrawtransaction", []interface{}{txData, 1})
if ontErr != nil {
return nil, ontErr.Error
}
preResult := &rpccommon.PreExecuteResult{}
preResult := &httpcom.PreExecuteResult{}
err := json.Unmarshal(data, &preResult)
if err != nil {
return nil, fmt.Errorf("json.Unmarshal PreExecResult:%s error:%s", data, err)
Expand All @@ -468,7 +467,7 @@ func PrepareSendRawTransaction(txData string) (*rpccommon.PreExecuteResult, erro
}

//GetSmartContractEvent return smart contract event execute by invoke transaction by hex string code
func GetSmartContractEvent(txHash string) (*rpccommon.ExecuteNotify, error) {
func GetSmartContractEvent(txHash string) (*httpcom.ExecuteNotify, error) {
data, ontErr := sendRpcRequest("getsmartcodeevent", []interface{}{txHash})
if ontErr != nil {
switch ontErr.ErrorCode {
Expand All @@ -477,7 +476,7 @@ func GetSmartContractEvent(txHash string) (*rpccommon.ExecuteNotify, error) {
}
return nil, ontErr.Error
}
notifies := &rpccommon.ExecuteNotify{}
notifies := &httpcom.ExecuteNotify{}
err := json.Unmarshal(data, &notifies)
if err != nil {
return nil, fmt.Errorf("json.Unmarshal SmartContactEvent:%s error:%s", data, err)
Expand Down Expand Up @@ -714,7 +713,7 @@ func InvokeSmartContract(signer *account.Account, tx *types.MutableTransaction)
func PrepareInvokeNeoVMContract(
contractAddress common.Address,
params []interface{},
) (*rpccommon.PreExecuteResult, error) {
) (*httpcom.PreExecuteResult, error) {
mutable, err := httpcom.NewNeovmInvokeTransaction(0, 0, contractAddress, params)
if err != nil {
return nil, err
Expand All @@ -729,7 +728,7 @@ func PrepareInvokeNeoVMContract(
return PrepareSendRawTransaction(txData)
}

func PrepareInvokeCodeNeoVMContract(code []byte) (*rpccommon.PreExecuteResult, error) {
func PrepareInvokeCodeNeoVMContract(code []byte) (*httpcom.PreExecuteResult, error) {
mutable, err := httpcom.NewSmartContractTransaction(0, 0, code)
if err != nil {
return nil, err
Expand All @@ -743,7 +742,7 @@ func PrepareInvokeCodeNeoVMContract(code []byte) (*rpccommon.PreExecuteResult, e
}

//prepare invoke wasm
func PrepareInvokeWasmVMContract(contractAddress common.Address, params []interface{}) (*rpccommon.PreExecuteResult, error) {
func PrepareInvokeWasmVMContract(contractAddress common.Address, params []interface{}) (*httpcom.PreExecuteResult, error) {
mutable, err := cutils.NewWasmVMInvokeTransaction(0, 0, contractAddress, params)
if err != nil {
return nil, err
Expand Down
3 changes: 3 additions & 0 deletions common/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,9 @@ func (this *OntologyConfig) GetBookkeepers() ([]keypair.PublicKey, error) {
pubKeys := make([]keypair.PublicKey, 0, len(bookKeepers))
for _, key := range bookKeepers {
pubKey, err := hex.DecodeString(key)
if err != nil {
return nil, err
}
k, err := keypair.DeserializePublicKey(pubKey)
if err != nil {
return nil, fmt.Errorf("Incorrectly book keepers key:%s", key)
Expand Down
2 changes: 1 addition & 1 deletion common/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,4 @@ const BLOCKHEIGHT_CC_POLARIS = 13130000

//new node cost height
const BLOCKHEIGHT_NEW_PEER_COST_MAINNET = 9400000
const BLOCKHEIGHT_NEW_PEER_COST_POLARIS = 13360000
const BLOCKHEIGHT_NEW_PEER_COST_POLARIS = 13400000
4 changes: 4 additions & 0 deletions consensus/dbft/block_signatures.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ func (self *BlockSignatures) Deserialization(source *common.ZeroCopySource) erro
sig := SignaturesData{}

sig.Signature, _, irregular, eof = source.NextVarBytes()
if eof {
return io.ErrUnexpectedEOF
}

if irregular {
return common.ErrIrregularData
}
Expand Down
4 changes: 4 additions & 0 deletions consensus/dbft/consensus_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ func (cd *ConsensusMessageData) Deserialization(source *common.ZeroCopySource) e
var eof bool
var temp byte
temp, eof = source.NextByte()
if eof {
return io.ErrUnexpectedEOF
}

cd.Type = ConsensusMessageType(temp)
cd.ViewNumber, eof = source.NextByte()
if eof {
Expand Down
Loading