Skip to content

Commit

Permalink
ONT-1110 fix add consensus node bug (#563)
Browse files Browse the repository at this point in the history
* fix add consensus node bug
* change fee split
* add peer cost
* add 1000 limit for authorize peer
* change fee split from node to address
* add withdraw fee func
* update fee split
* add if fork
* add candidate fee split num
* update ifAuthorize and fix fee split
* fix bugs
* change ifAuthorize to changeMaxAuthorize
* add and reduce initPos and add promise pos
* add block num constrain for new funcs
* fix integer underflow
* add authorizeInfo comment
* fix newPos bugs and split authorize address first when fee split
* fix reduceInitPos bug
* change peer cost T + 2 active
* fix setPeerCost != 100 bug and status type from int to uint8 add some comment
* fix unregister bugs
* change set promise pos to approve candidate func
* fix fee split
* change authorize info var name
* fix unAuthorize bugs
* change apply preConfig position
* fix consensus get config
* add new version view +1 and add some comment
* add field annotation
* fix GetStorageItem common.ErrNotFound bug
* add some constrain in ChangeMaxAuthorization
* fix split fee address bugs
* change governance version view and height
  • Loading branch information
siovanus authored and laizy committed Sep 26, 2018
1 parent 587f369 commit f5219c7
Show file tree
Hide file tree
Showing 7 changed files with 2,430 additions and 777 deletions.
147 changes: 144 additions & 3 deletions cmd/abi/native_abi_script/governance.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
"returnType":"Bool"
},
{
"name":"voteForPeer",
"name":"authorizeForPeer",
"parameters":
[
{
Expand Down Expand Up @@ -178,7 +178,7 @@
"returnType":"Bool"
},
{
"name":"voteForPeerTransferFrom",
"name":"authorizeForPeerTransferFrom",
"parameters":
[
{
Expand Down Expand Up @@ -211,7 +211,7 @@
"returnType":"Bool"
},
{
"name":"unVoteForPeer",
"name":"unAuthorizeForPeer",
"parameters":
[
{
Expand Down Expand Up @@ -411,6 +411,147 @@
}
],
"returnType":"Bool"
},
{
"name":"changeMaxAuthorizations",
"parameters":
[
{
"name":"PeerPubkey",
"type":"String"
},
{
"name":"Address",
"type":"Address"
},
{
"name":"MaxAuthorize",
"type":"Int"
}
],
"returnType":"Bool"
},
{
"name":"setPeerCost",
"parameters":
[
{
"name":"PeerPubkey",
"type":"String"
},
{
"name":"Address",
"type":"Address"
},
{
"name":"PeerCost",
"type":"Int"
}
],
"returnType":"Bool"
},
{
"name":"withdrawFee",
"parameters":
[
{
"name":"Address",
"type":"Address"
}
],
"returnType":"Bool"
},
{
"name":"addInitPos",
"parameters":
[
{
"name":"PeerPubkey",
"type":"String"
},
{
"name":"Address",
"type":"Address"
},
{
"name":"Pos",
"type":"Int"
}
],
"returnType":"Bool"
},
{
"name":"reduceInitPos",
"parameters":
[
{
"name":"PeerPubkey",
"type":"String"
},
{
"name":"Address",
"type":"Address"
},
{
"name":"Pos",
"type":"Int"
}
],
"returnType":"Bool"
},
{
"name":"updateGlobalParam2",
"parameters":
[
{
"name":"MinAuthorizePos",
"type":"Int"
},
{
"name":"CandidateFeeSplitNum",
"type":"Int"
},
{
"name":"Field1",
"type":"ByteArray"
},
{
"name":"Field2",
"type":"ByteArray"
},
{
"name":"Field3",
"type":"ByteArray"
},
{
"name":"Field4",
"type":"ByteArray"
},
{
"name":"Field5",
"type":"ByteArray"
},
{
"name":"Field6",
"type":"ByteArray"
}
],
"returnType":"Bool"
},
{
"name":"setPromisePos",
"parameters":
[
{
"name":"PeerPubkey",
"type":"String"
},
{
"name":"Pos",
"type":"Int"
}
],
"returnType":"Bool"
}
],
"events":
Expand Down
68 changes: 53 additions & 15 deletions consensus/vbft/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/ontio/ontology/core/ledger"
"github.com/ontio/ontology/core/signature"
"github.com/ontio/ontology/core/states"
scommon "github.com/ontio/ontology/core/store/common"
gov "github.com/ontio/ontology/smartcontract/service/native/governance"
nutils "github.com/ontio/ontology/smartcontract/service/native/utils"
)
Expand Down Expand Up @@ -126,28 +127,65 @@ func verifyVrf(pk keypair.PublicKey, blkNum uint32, prevVrf, newVrf, proof []byt
return nil
}
func GetVbftConfigInfo() (*config.VBFTConfig, error) {
//get governance view
goveranceview, err := GetGovernanceView()
if err != nil {
return nil, err
}

//get preConfig
storageKey := &states.StorageKey{
ContractAddress: nutils.GovernanceContractAddress,
Key: append([]byte(gov.VBFT_CONFIG)),
Key: append([]byte(gov.PRE_CONFIG)),
}
preCfg := new(gov.PreConfig)
data, err := ledger.DefLedger.GetStorageItem(storageKey.ContractAddress, storageKey.Key)
if err != nil {
if err != nil && err != scommon.ErrNotFound {
return nil, err
}
cfg := new(gov.Configuration)
err = cfg.Deserialize(bytes.NewBuffer(data))
if err != nil {
return nil, err
if data != nil {
err = preCfg.Deserialize(bytes.NewBuffer(data))
if err != nil {
return nil, err
}
}
chainconfig := &config.VBFTConfig{
N: uint32(cfg.N),
C: uint32(cfg.C),
K: uint32(cfg.K),
L: uint32(cfg.L),
BlockMsgDelay: uint32(cfg.BlockMsgDelay),
HashMsgDelay: uint32(cfg.HashMsgDelay),
PeerHandshakeTimeout: uint32(cfg.PeerHandshakeTimeout),
MaxBlockChangeView: uint32(cfg.MaxBlockChangeView),

chainconfig := new(config.VBFTConfig)
if preCfg.SetView == goveranceview.View {
chainconfig = &config.VBFTConfig{
N: uint32(preCfg.Configuration.N),
C: uint32(preCfg.Configuration.C),
K: uint32(preCfg.Configuration.K),
L: uint32(preCfg.Configuration.L),
BlockMsgDelay: uint32(preCfg.Configuration.BlockMsgDelay),
HashMsgDelay: uint32(preCfg.Configuration.HashMsgDelay),
PeerHandshakeTimeout: uint32(preCfg.Configuration.PeerHandshakeTimeout),
MaxBlockChangeView: uint32(preCfg.Configuration.MaxBlockChangeView),
}
} else {
storageKey := &states.StorageKey{
ContractAddress: nutils.GovernanceContractAddress,
Key: append([]byte(gov.VBFT_CONFIG)),
}
data, err := ledger.DefLedger.GetStorageItem(storageKey.ContractAddress, storageKey.Key)
if err != nil {
return nil, err
}
cfg := new(gov.Configuration)
err = cfg.Deserialize(bytes.NewBuffer(data))
if err != nil {
return nil, err
}
chainconfig = &config.VBFTConfig{
N: uint32(cfg.N),
C: uint32(cfg.C),
K: uint32(cfg.K),
L: uint32(cfg.L),
BlockMsgDelay: uint32(cfg.BlockMsgDelay),
HashMsgDelay: uint32(cfg.HashMsgDelay),
PeerHandshakeTimeout: uint32(cfg.PeerHandshakeTimeout),
MaxBlockChangeView: uint32(cfg.MaxBlockChangeView),
}
}
return chainconfig, nil
}
Expand Down
Loading

0 comments on commit f5219c7

Please sign in to comment.