Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
plugin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
link33
plugin
Commits
f35ed63b
Commit
f35ed63b
authored
Jan 07, 2020
by
heyubin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add by hyb for cmpbestblock
parent
cf531070
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
66 additions
and
0 deletions
+66
-0
dpos.go
plugin/consensus/dpos/dpos.go
+5
-0
para.go
plugin/consensus/para/para.go
+5
-0
block.go
plugin/consensus/pbft/block.go
+5
-0
block.go
plugin/consensus/raft/block.go
+5
-0
tendermint.go
plugin/consensus/tendermint/tendermint.go
+5
-0
chain33.cfg.toml
plugin/consensus/ticket/testdata/chain33.cfg.toml
+1
-0
ticket.go
plugin/consensus/ticket/ticket.go
+29
-0
ticket_test.go
plugin/consensus/ticket/ticket_test.go
+11
-0
No files found.
plugin/consensus/dpos/dpos.go
View file @
f35ed63b
...
...
@@ -784,3 +784,8 @@ func (client *Client) SetTestFlag() {
func
(
client
*
Client
)
GetNode
()
*
Node
{
return
client
.
node
}
//比较newBlock是不是最优区块
func
(
client
*
Client
)
CmpBestBlock
(
newBlock
*
types
.
Block
,
cmpBlock
*
types
.
Block
)
bool
{
return
false
}
plugin/consensus/para/para.go
View file @
f35ed63b
...
...
@@ -473,3 +473,8 @@ func (client *client) Query_WalletStatus(walletStatus *types.WalletStatus) (type
client
.
commitMsgClient
.
onWalletStatus
(
walletStatus
)
return
&
types
.
Reply
{
IsOk
:
true
,
Msg
:
[]
byte
(
"OK"
)},
nil
}
//比较newBlock是不是最优区块
func
(
client
*
client
)
CmpBestBlock
(
newBlock
*
types
.
Block
,
cmpBlock
*
types
.
Block
)
bool
{
return
false
}
plugin/consensus/pbft/block.go
View file @
f35ed63b
...
...
@@ -146,3 +146,8 @@ func (client *Client) readReply() {
client
.
SetCurrentBlock
(
data
.
Result
.
Value
)
}
//比较newBlock是不是最优区块
func
(
client
*
Client
)
CmpBestBlock
(
newBlock
*
types
.
Block
,
cmpBlock
*
types
.
Block
)
bool
{
return
false
}
plugin/consensus/raft/block.go
View file @
f35ed63b
...
...
@@ -270,3 +270,8 @@ func (client *Client) pollingTask() {
}
}
}
//比较newBlock是不是最优区块
func
(
client
*
Client
)
CmpBestBlock
(
newBlock
*
types
.
Block
,
cmpBlock
*
types
.
Block
)
bool
{
return
false
}
plugin/consensus/tendermint/tendermint.go
View file @
f35ed63b
...
...
@@ -635,3 +635,8 @@ func (client *Client) Query_NodeInfo(req *types.ReqNil) (types.Message, error) {
}
return
&
tmtypes
.
ValidatorSet
{
Validators
:
validators
,
Proposer
:
&
tmtypes
.
Validator
{}},
nil
}
//比较newBlock是不是最优区块
func
(
client
*
Client
)
CmpBestBlock
(
newBlock
*
types
.
Block
,
cmpBlock
*
types
.
Block
)
bool
{
return
false
}
plugin/consensus/ticket/testdata/chain33.cfg.toml
View file @
f35ed63b
...
...
@@ -72,6 +72,7 @@ minerstart=true
genesisBlockTime
=
1514533394
genesis
=
"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
minerExecs
=[
"ticket"
,
"autonomy"
]
enableBestBlockCmp
=
true
[mver.consensus]
fundKeyAddr
=
"1BQXS6TxaYYG5mADaWij4AxhZZUTpw95a5"
...
...
plugin/consensus/ticket/ticket.go
View file @
f35ed63b
...
...
@@ -795,3 +795,32 @@ func getTxHashes(txs []*types.Transaction) (hashes [][]byte) {
}
return
hashes
}
//比较newBlock是不是最优区块,目前ticket主要是比较挖矿交易的难度系数
func
(
client
*
Client
)
CmpBestBlock
(
newBlock
*
types
.
Block
,
cmpBlock
*
types
.
Block
)
bool
{
cfg
:=
client
.
GetAPI
()
.
GetConfig
()
//newblock挖矿交易的难度系数
newBlockTicket
,
err
:=
client
.
getMinerTx
(
newBlock
)
if
err
!=
nil
{
tlog
.
Error
(
"CmpBestBlock:getMinerTx"
,
"newBlockHash"
,
common
.
ToHex
(
newBlock
.
Hash
(
cfg
)))
return
false
}
newBlockMiner
:=
newBlockTicket
.
GetMiner
()
newBlockDiff
:=
client
.
getCurrentTarget
(
newBlock
.
BlockTime
,
newBlockMiner
.
TicketId
,
newBlockMiner
.
Modify
,
newBlockMiner
.
PrivHash
)
//cmpBlock挖矿交易的难度系数
cmpBlockTicket
,
err
:=
client
.
getMinerTx
(
cmpBlock
)
if
err
!=
nil
{
tlog
.
Error
(
"CmpBestBlock:getMinerTx"
,
"cmpBlockHash"
,
common
.
ToHex
(
cmpBlock
.
Hash
(
cfg
)))
return
false
}
cmpBlockMiner
:=
cmpBlockTicket
.
GetMiner
()
cmpBlockDiff
:=
client
.
getCurrentTarget
(
cmpBlock
.
BlockTime
,
cmpBlockMiner
.
TicketId
,
cmpBlockMiner
.
Modify
,
cmpBlockMiner
.
PrivHash
)
//数字越小难度越大
if
newBlockDiff
.
Cmp
(
cmpBlockDiff
)
<
0
{
return
true
}
return
false
}
plugin/consensus/ticket/ticket_test.go
View file @
f35ed63b
...
...
@@ -22,6 +22,7 @@ import (
"github.com/stretchr/testify/assert"
apimocks
"github.com/33cn/chain33/client/mocks"
"github.com/33cn/chain33/common/merkle"
_
"github.com/33cn/chain33/system"
drivers
"github.com/33cn/chain33/system/consensus"
_
"github.com/33cn/plugin/plugin/dapp/init"
...
...
@@ -103,6 +104,16 @@ func testTicket(t *testing.T) {
accounts
,
err
=
acc
.
GetBalance
(
mock33
.
GetAPI
(),
&
types
.
ReqBalance
{
Execer
:
"ticket"
,
Addresses
:
[]
string
{
addr
}})
assert
.
Nil
(
t
,
err
)
fmt
.
Println
(
accounts
[
0
])
//测试最优节点的选择,难度相同
lastBlock
:=
mock33
.
GetLastBlock
()
temblock
:=
types
.
Clone
(
lastBlock
)
newblock
:=
temblock
.
(
*
types
.
Block
)
newblock
.
GetTxs
()[
0
]
.
Nonce
=
newblock
.
GetTxs
()[
0
]
.
Nonce
+
1
newblock
.
TxHash
=
merkle
.
CalcMerkleRoot
(
cfg
,
newblock
.
GetHeight
(),
newblock
.
GetTxs
())
isbestBlock
:=
util
.
CmpBestBlock
(
mock33
.
GetClient
(),
newblock
,
lastBlock
.
Hash
(
cfg
))
assert
.
Equal
(
t
,
isbestBlock
,
false
)
}
func
createBindMiner
(
cfg
*
types
.
Chain33Config
,
t
*
testing
.
T
,
m
,
r
string
,
priv
crypto
.
PrivKey
)
*
types
.
Transaction
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment