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
90d2f148
Unverified
Commit
90d2f148
authored
Jan 08, 2020
by
vipwzw
Committed by
GitHub
Jan 08, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #761 from icehawk-hyb/issues-768
add by hyb for cmpbestblock
parents
1e0f7be7
57808324
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
66 additions
and
3 deletions
+66
-3
go.mod
go.mod
+1
-1
go.sum
go.sum
+2
-2
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
+26
-0
ticket_test.go
plugin/consensus/ticket/ticket_test.go
+11
-0
No files found.
go.mod
View file @
90d2f148
...
...
@@ -3,7 +3,7 @@ module github.com/33cn/plugin
go 1.12
require (
github.com/33cn/chain33 v0.0.0-2020010
3093520-2bdc0cea1093
github.com/33cn/chain33 v0.0.0-2020010
8042336-2dda2dfb7e0e
github.com/BurntSushi/toml v0.3.1
github.com/NebulousLabs/Sia v1.3.7
github.com/beorn7/perks v1.0.1 // indirect
...
...
go.sum
View file @
90d2f148
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/33cn/chain33 v0.0.0-2020010
3093520-2bdc0cea1093 h1:ztzQN4V2DJL9b/rgx5lX3cip6A0er4560sKvt4vYBMM
=
github.com/33cn/chain33 v0.0.0-2020010
3093520-2bdc0cea1093
/go.mod h1:4I8n+Zyf3t0UKM5jjpqJY627Tub62oXkLsdzIv4r6rQ=
github.com/33cn/chain33 v0.0.0-2020010
8042336-2dda2dfb7e0e h1:FMnJCJUDEsjHURlHv3zqiiftvNCtTbsMSjXSykG7htc
=
github.com/33cn/chain33 v0.0.0-2020010
8042336-2dda2dfb7e0e
/go.mod h1:4I8n+Zyf3t0UKM5jjpqJY627Tub62oXkLsdzIv4r6rQ=
github.com/AndreasBriese/bbloom v0.0.0-20180913140656-343706a395b7 h1:PqzgE6kAMi81xWQA2QIVxjWkFHptGgC547vchpUbtFo=
github.com/AndreasBriese/bbloom v0.0.0-20180913140656-343706a395b7/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
...
...
plugin/consensus/dpos/dpos.go
View file @
90d2f148
...
...
@@ -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 @
90d2f148
...
...
@@ -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 @
90d2f148
...
...
@@ -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 @
90d2f148
...
...
@@ -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 @
90d2f148
...
...
@@ -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 @
90d2f148
...
...
@@ -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 @
90d2f148
...
...
@@ -795,3 +795,29 @@ 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
)
//数字越小难度越大
return
newBlockDiff
.
Cmp
(
cmpBlockDiff
)
<
0
}
plugin/consensus/ticket/ticket_test.go
View file @
90d2f148
...
...
@@ -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