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
f94e04d5
Commit
f94e04d5
authored
Jun 06, 2019
by
张振华
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into dpos
parents
c48b4c11
01f6506d
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
53 changed files
with
737 additions
and
500 deletions
+737
-500
dapp-test-common.sh
build/dapp-test-common.sh
+6
-0
docker-compose.sh
build/docker-compose.sh
+1
-0
chain33.toml
chain33.toml
+2
-1
paracommitmsg.go
plugin/consensus/para/paracommitmsg.go
+5
-2
test-rpc.sh
plugin/dapp/blackwhite/cmd/build/test-rpc.sh
+14
-52
test-rpc.sh
plugin/dapp/js/cmd/build/test-rpc.sh
+6
-114
chain33.para.test.toml
plugin/dapp/paracross/cmd/build/chain33.para.test.toml
+1
-0
chain33.para.toml
plugin/dapp/paracross/cmd/build/chain33.para.toml
+1
-0
testcase.sh
plugin/dapp/paracross/cmd/build/testcase.sh
+0
-0
paracross.go
plugin/dapp/paracross/commands/paracross.go
+41
-8
action.go
plugin/dapp/paracross/executor/action.go
+18
-0
exec_del_local.go
plugin/dapp/paracross/executor/exec_del_local.go
+14
-0
exec_local.go
plugin/dapp/paracross/executor/exec_local.go
+15
-0
query.go
plugin/dapp/paracross/executor/query.go
+3
-7
superaccount.go
plugin/dapp/paracross/executor/superaccount.go
+0
-0
superaccount_test.go
plugin/dapp/paracross/executor/superaccount_test.go
+23
-21
paracross.proto
plugin/dapp/paracross/proto/paracross.proto
+12
-6
rpc.go
plugin/dapp/paracross/rpc/rpc.go
+50
-15
cfg.go
plugin/dapp/paracross/testnode/cfg.go
+1
-0
errors.go
plugin/dapp/paracross/types/errors.go
+2
-2
paracross.go
plugin/dapp/paracross/types/paracross.go
+15
-10
paracross.pb.go
plugin/dapp/paracross/types/paracross.pb.go
+0
-0
type.go
plugin/dapp/paracross/types/type.go
+1
-0
test-rpc.sh
plugin/dapp/unfreeze/cmd/build/test-rpc.sh
+11
-116
.travis.yml
vendor/github.com/33cn/chain33/.travis.yml
+1
-1
jerkins-ci-autotest.sh
...n/chain33/build/autotest/jerkinsci/jerkins-ci-autotest.sh
+0
-8
local-autotest.sh
...b.com/33cn/chain33/build/autotest/local/local-autotest.sh
+2
-4
system-test-rpc.sh
vendor/github.com/33cn/chain33/build/system-test-rpc.sh
+21
-12
bityuan.toml
vendor/github.com/33cn/chain33/cmd/chain33/bityuan.toml
+2
-0
chain33.test.toml
vendor/github.com/33cn/chain33/cmd/chain33/chain33.test.toml
+4
-0
chain33.toml
vendor/github.com/33cn/chain33/cmd/chain33/chain33.toml
+6
-0
addrbook.go
vendor/github.com/33cn/chain33/p2p/addrbook.go
+7
-13
const.go
vendor/github.com/33cn/chain33/p2p/const.go
+0
-6
downloadblocks.go
vendor/github.com/33cn/chain33/p2p/downloadblocks.go
+2
-0
node.go
vendor/github.com/33cn/chain33/p2p/node.go
+4
-3
p2p.go
vendor/github.com/33cn/chain33/p2p/p2p.go
+89
-81
p2p_test.go
vendor/github.com/33cn/chain33/p2p/p2p_test.go
+26
-11
p2pcli.go
vendor/github.com/33cn/chain33/p2p/p2pcli.go
+2
-2
p2pserver.go
vendor/github.com/33cn/chain33/p2p/p2pserver.go
+1
-1
base.go
vendor/github.com/33cn/chain33/system/mempool/base.go
+29
-0
cache.go
vendor/github.com/33cn/chain33/system/mempool/cache.go
+26
-1
check.go
vendor/github.com/33cn/chain33/system/mempool/check.go
+22
-1
eventprocess.go
...or/github.com/33cn/chain33/system/mempool/eventprocess.go
+2
-2
mempool_test.go
...or/github.com/33cn/chain33/system/mempool/mempool_test.go
+0
-0
simplequeue.go
vendor/github.com/33cn/chain33/system/mempool/simplequeue.go
+4
-0
chain33.test.toml
...om/33cn/chain33/system/mempool/testdata/chain33.test.toml
+203
-0
cfg.go
vendor/github.com/33cn/chain33/types/cfg.go
+3
-0
config.go
vendor/github.com/33cn/chain33/types/config.go
+6
-0
const.go
vendor/github.com/33cn/chain33/types/const.go
+5
-0
guodun.toml
vendor/github.com/33cn/chain33/types/testdata/guodun.toml
+1
-0
guodun2.toml
vendor/github.com/33cn/chain33/types/testdata/guodun2.toml
+1
-0
tx.go
vendor/github.com/33cn/chain33/types/tx.go
+22
-0
chain33.go
vendor/github.com/33cn/chain33/util/cli/chain33.go
+4
-0
No files found.
build/dapp-test-common.sh
View file @
f94e04d5
...
@@ -150,3 +150,9 @@ chain33_QueryExecBalance() {
...
@@ -150,3 +150,9 @@ chain33_QueryExecBalance() {
ok
=
$(
jq
'(.error|not) and (.result[0] | [has("balance", "frozen"), true] | unique | length == 1)'
<<<
"
$resp
"
)
ok
=
$(
jq
'(.error|not) and (.result[0] | [has("balance", "frozen"), true] | unique | length == 1)'
<<<
"
$resp
"
)
[
"
$ok
"
==
true
]
[
"
$ok
"
==
true
]
}
}
chain33_GetAccounts
()
{
local
MAIN_HTTP
=
$1
resp
=
$(
curl
-ksd
'{"jsonrpc":"2.0","id":2,"method":"Chain33.GetAccounts","params":[{}]}'
-H
'content-type:text/plain;'
"
${
MAIN_HTTP
}
"
)
echo
"
$resp
"
}
build/docker-compose.sh
View file @
f94e04d5
...
@@ -98,6 +98,7 @@ function base_init() {
...
@@ -98,6 +98,7 @@ function base_init() {
sed
-i
$sedfix
's/^minerdisable=.*/minerdisable=false/g'
chain33.toml
sed
-i
$sedfix
's/^minerdisable=.*/minerdisable=false/g'
chain33.toml
sed
-i
$sedfix
's/^nodeGroupFrozenCoins=.*/nodeGroupFrozenCoins=20/g'
chain33.toml
sed
-i
$sedfix
's/^nodeGroupFrozenCoins=.*/nodeGroupFrozenCoins=20/g'
chain33.toml
sed
-i
$sedfix
's/^paraConsensusStopBlocks=.*/paraConsensusStopBlocks=100/g'
chain33.toml
# ticket
# ticket
sed
-i
$sedfix
's/^ticketPrice =.*/ticketPrice = 10000/g'
chain33.toml
sed
-i
$sedfix
's/^ticketPrice =.*/ticketPrice = 10000/g'
chain33.toml
...
...
chain33.toml
View file @
f94e04d5
...
@@ -216,6 +216,7 @@ superManager=[
...
@@ -216,6 +216,7 @@ superManager=[
]
]
[exec.sub.paracross]
[exec.sub.paracross]
nodeGroupFrozenCoins
=
0
nodeGroupFrozenCoins
=
0
paraConsensusStopBlocks
=
100
#平行链共识停止后主链等待的高度
paraConsensusStopBlocks
=
30000
plugin/consensus/para/paracommitmsg.go
View file @
f94e04d5
...
@@ -40,6 +40,7 @@ func (client *commitMsgClient) handler() {
...
@@ -40,6 +40,7 @@ func (client *commitMsgClient) handler() {
var
isRollback
bool
var
isRollback
bool
var
notification
[]
int64
//记录每次系统重启后 min and current height
var
notification
[]
int64
//记录每次系统重启后 min and current height
var
finishHeight
int64
var
finishHeight
int64
var
consensHeight
int64
var
sendingHeight
int64
//当前发送的最大高度
var
sendingHeight
int64
//当前发送的最大高度
var
sendingMsgs
[]
*
pt
.
ParacrossNodeStatus
var
sendingMsgs
[]
*
pt
.
ParacrossNodeStatus
var
readTick
<-
chan
time
.
Time
var
readTick
<-
chan
time
.
Time
...
@@ -155,7 +156,7 @@ out:
...
@@ -155,7 +156,7 @@ out:
//获取正在共识的高度,同步有两层意思,一个是主链跟其他节点完成了同步,另一个是当前平行链节点的高度追赶上了共识高度
//获取正在共识的高度,同步有两层意思,一个是主链跟其他节点完成了同步,另一个是当前平行链节点的高度追赶上了共识高度
//一般来说高度增长从小到大: notifiy[0] -- selfConsensusHeight(mainHeight) -- finishHeight -- sendingHeight -- notify[1]
//一般来说高度增长从小到大: notifiy[0] -- selfConsensusHeight(mainHeight) -- finishHeight -- sendingHeight -- notify[1]
case
rsp
:=
<-
consensusCh
:
case
rsp
:=
<-
consensusCh
:
consensHeight
:
=
rsp
.
Height
consensHeight
=
rsp
.
Height
plog
.
Info
(
"para consensus rcv"
,
"notify"
,
notification
,
"sending"
,
len
(
sendingMsgs
),
plog
.
Info
(
"para consensus rcv"
,
"notify"
,
notification
,
"sending"
,
len
(
sendingMsgs
),
"consensHeigt"
,
rsp
.
Height
,
"finished"
,
finishHeight
,
"sync"
,
isSync
,
"miner"
,
readTick
!=
nil
,
"consensBlockHash"
,
common
.
ToHex
(
rsp
.
BlockHash
))
"consensHeigt"
,
rsp
.
Height
,
"finished"
,
finishHeight
,
"sync"
,
isSync
,
"miner"
,
readTick
!=
nil
,
"consensBlockHash"
,
common
.
ToHex
(
rsp
.
BlockHash
))
...
@@ -193,7 +194,6 @@ out:
...
@@ -193,7 +194,6 @@ out:
finishHeight
=
consensHeight
finishHeight
=
consensHeight
sendingMsgs
=
nil
sendingMsgs
=
nil
client
.
currentTx
=
nil
client
.
currentTx
=
nil
isSync
=
true
}
}
case
miner
:=
<-
client
.
minerSwitch
:
case
miner
:=
<-
client
.
minerSwitch
:
...
@@ -212,6 +212,9 @@ out:
...
@@ -212,6 +212,9 @@ out:
ticker
=
time
.
NewTicker
(
time
.
Second
*
time
.
Duration
(
minerInterval
))
ticker
=
time
.
NewTicker
(
time
.
Second
*
time
.
Duration
(
minerInterval
))
readTick
=
ticker
.
C
readTick
=
ticker
.
C
plog
.
Info
(
"para consensus start mining"
)
plog
.
Info
(
"para consensus start mining"
)
//钱包开启后,从共识高度重新开始发送,在需要重发共识时候,不需要重启设备
finishHeight
=
consensHeight
}
}
case
<-
client
.
quit
:
case
<-
client
.
quit
:
...
...
plugin/dapp/blackwhite/cmd/build/test-rpc.sh
View file @
f94e04d5
...
@@ -2,21 +2,11 @@
...
@@ -2,21 +2,11 @@
# shellcheck disable=SC2128
# shellcheck disable=SC2128
set
+e
set
+e
set
-o
pipefail
set
-o
pipefail
set
-x
MAIN_HTTP
=
""
MAIN_HTTP
=
""
CASE_ERR
=
""
# $2=0 means true, other false
# shellcheck source=/dev/null
echo_rst
()
{
source
../dapp-test-common.sh
if
[
"
$2
"
-eq
0
]
;
then
echo
"
$1
ok"
else
echo
"
$1
err"
CASE_ERR
=
"err"
fi
}
gID
=
""
gID
=
""
gResp
=
""
gResp
=
""
...
@@ -49,38 +39,6 @@ chain33_NewAccount() {
...
@@ -49,38 +39,6 @@ chain33_NewAccount() {
echo
"
$glAddr
"
echo
"
$glAddr
"
}
}
function
block_wait
()
{
if
[
"$#"
-lt
1
]
;
then
echo
"wrong block_wait params"
exit
1
fi
cur_height
=
$(
curl
-ksd
'{"jsonrpc":"2.0","id":2,"method":"Chain33.GetLastHeader","params":[{}]}'
-H
'content-type:text/plain;'
${
MAIN_HTTP
}
| jq
-r
".result.height"
)
expect
=
$((
cur_height
+
${
1
}))
local
count
=
0
while
true
;
do
new_height
=
$(
curl
-ksd
'{"jsonrpc":"2.0","id":2,"method":"Chain33.GetLastHeader","params":[{}]}'
-H
'content-type:text/plain;'
${
MAIN_HTTP
}
| jq
-r
".result.height"
)
if
[
"
${
new_height
}
"
-ge
"
${
expect
}
"
]
;
then
break
fi
count
=
$((
count
+
1
))
sleep
1
done
echo
"wait new block
$count
s, cur height=
$expect
,old=
$cur_height
"
}
chain33_SendToAddress
()
{
from
=
$1
to
=
$2
amount
=
$3
http
=
$4
note
=
"test"
resp
=
$(
curl
-ksd
'{"jsonrpc":"2.0","id":2,"method":"Chain33.SendToAddress","params":[{"from":"'
"
$from
"
'","to":"'
"
$to
"
'","amount":'
"
$amount
"
',"note":"'
"
$note
"
'"}]}'
-H
'content-type:text/plain;'
"
${
http
}
"
)
ok
=
$(
jq
'(.error|not)'
<<<
"
$resp
"
)
[
"
$ok
"
==
true
]
rst
=
$?
echo_rst
"
$FUNCNAME
"
"
$rst
"
}
chain33_SendTransaction
()
{
chain33_SendTransaction
()
{
rawTx
=
$1
rawTx
=
$1
addr
=
$2
addr
=
$2
...
@@ -98,8 +56,9 @@ chain33_SendTransaction() {
...
@@ -98,8 +56,9 @@ chain33_SendTransaction() {
rst
=
$?
rst
=
$?
echo_rst
"
$FUNCNAME
"
"
$rst
"
echo_rst
"
$FUNCNAME
"
"
$rst
"
#返回交易
#返回交易
gResp
=
$(
echo
"
${
resp
}
"
| jq
-r
".result
"
)
gResp
=
$(
jq
-r
".result"
<<<
"
$resp
"
)
echo
"tx hash is
$gResp
"
echo
"tx hash is
$gResp
"
chain33_QueryTx
"
$gResp
"
"
${
MAIN_HTTP
}
"
}
}
blackwhite_BlackwhiteCreateTx
()
{
blackwhite_BlackwhiteCreateTx
()
{
...
@@ -211,6 +170,8 @@ function run_testcases() {
...
@@ -211,6 +170,8 @@ function run_testcases() {
#给每个账户分别转帐
#给每个账户分别转帐
origAddr
=
"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
origAddr
=
"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
chain33_GetAccounts
"
${
MAIN_HTTP
}
"
#主链中相应账户需要转帐
#主链中相应账户需要转帐
M_HTTP
=
${
MAIN_HTTP
//8901/8801
}
M_HTTP
=
${
MAIN_HTTP
//8901/8801
}
chain33_SendToAddress
"
${
origAddr
}
"
"
${
gameAddr1
}
"
1000000000
"
${
M_HTTP
}
"
chain33_SendToAddress
"
${
origAddr
}
"
"
${
gameAddr1
}
"
1000000000
"
${
M_HTTP
}
"
...
@@ -222,29 +183,23 @@ function run_testcases() {
...
@@ -222,29 +183,23 @@ function run_testcases() {
chain33_SendToAddress
"
${
origAddr
}
"
"
${
gameAddr2
}
"
1000000000
"
${
MAIN_HTTP
}
"
chain33_SendToAddress
"
${
origAddr
}
"
"
${
gameAddr2
}
"
1000000000
"
${
MAIN_HTTP
}
"
chain33_SendToAddress
"
${
origAddr
}
"
"
${
gameAddr3
}
"
1000000000
"
${
MAIN_HTTP
}
"
chain33_SendToAddress
"
${
origAddr
}
"
"
${
gameAddr3
}
"
1000000000
"
${
MAIN_HTTP
}
"
block_wait 1
#给游戏合约中转帐
#给游戏合约中转帐
chain33_SendToAddress
"
${
gameAddr1
}
"
"
${
bwExecAddr
}
"
500000000
"
${
MAIN_HTTP
}
"
chain33_SendToAddress
"
${
gameAddr1
}
"
"
${
bwExecAddr
}
"
500000000
"
${
MAIN_HTTP
}
"
chain33_SendToAddress
"
${
gameAddr2
}
"
"
${
bwExecAddr
}
"
500000000
"
${
MAIN_HTTP
}
"
chain33_SendToAddress
"
${
gameAddr2
}
"
"
${
bwExecAddr
}
"
500000000
"
${
MAIN_HTTP
}
"
chain33_SendToAddress
"
${
gameAddr3
}
"
"
${
bwExecAddr
}
"
500000000
"
${
MAIN_HTTP
}
"
chain33_SendToAddress
"
${
gameAddr3
}
"
"
${
bwExecAddr
}
"
500000000
"
${
MAIN_HTTP
}
"
block_wait 1
blackwhite_BlackwhiteCreateTx
"
${
gameAddr1
}
"
blackwhite_BlackwhiteCreateTx
"
${
gameAddr1
}
"
block_wait 1
blackwhite_BlackwhitePlayTx
"
${
gameAddr1
}
"
"
${
white0
}
"
"
${
white1
}
"
"
${
black2
}
"
blackwhite_BlackwhitePlayTx
"
${
gameAddr1
}
"
"
${
white0
}
"
"
${
white1
}
"
"
${
black2
}
"
blackwhite_BlackwhitePlayTx
"
${
gameAddr2
}
"
"
${
white0
}
"
"
${
black1
}
"
"
${
black2
}
"
blackwhite_BlackwhitePlayTx
"
${
gameAddr2
}
"
"
${
white0
}
"
"
${
black1
}
"
"
${
black2
}
"
blackwhite_BlackwhitePlayTx
"
${
gameAddr3
}
"
"
${
white0
}
"
"
${
black1
}
"
"
${
black2
}
"
blackwhite_BlackwhitePlayTx
"
${
gameAddr3
}
"
"
${
white0
}
"
"
${
black1
}
"
"
${
black2
}
"
block_wait 1
blackwhite_BlackwhiteShowTx
"
${
gameAddr1
}
"
"
${
sect1
}
"
blackwhite_BlackwhiteShowTx
"
${
gameAddr1
}
"
"
${
sect1
}
"
blackwhite_BlackwhiteShowTx
"
${
gameAddr2
}
"
"
${
sect1
}
"
blackwhite_BlackwhiteShowTx
"
${
gameAddr2
}
"
"
${
sect1
}
"
blackwhite_BlackwhiteShowTx
"
${
gameAddr3
}
"
"
${
sect1
}
"
blackwhite_BlackwhiteShowTx
"
${
gameAddr3
}
"
"
${
sect1
}
"
blackwhite_BlackwhiteTimeoutDoneTx
"
$gID
"
blackwhite_BlackwhiteTimeoutDoneTx
"
$gID
"
#查询部分
#查询部分
block_wait 3
blackwhite_GetBlackwhiteRoundInfo
"
$gID
"
blackwhite_GetBlackwhiteRoundInfo
"
$gID
"
blackwhite_GetBlackwhiteByStatusAndAddr
"
$gID
"
"
${
gameAddr1
}
"
blackwhite_GetBlackwhiteByStatusAndAddr
"
$gID
"
"
${
gameAddr1
}
"
blackwhite_GetBlackwhiteloopResult
"
$gID
"
blackwhite_GetBlackwhiteloopResult
"
$gID
"
...
@@ -256,6 +211,7 @@ function main() {
...
@@ -256,6 +211,7 @@ function main() {
echo
"main_ip=
$MAIN_HTTP
"
echo
"main_ip=
$MAIN_HTTP
"
init
init
run_testcases
run_testcases
if
[
-n
"
$CASE_ERR
"
]
;
then
if
[
-n
"
$CASE_ERR
"
]
;
then
...
@@ -264,4 +220,10 @@ function main() {
...
@@ -264,4 +220,10 @@ function main() {
fi
fi
}
}
main
"
$1
"
function
debug_function
()
{
set
-x
eval
"
$@
"
set
+x
}
debug_function main
"
$1
"
plugin/dapp/js/cmd/build/test-rpc.sh
View file @
f94e04d5
#!/usr/bin/env bash
#!/usr/bin/env bash
# shellcheck disable=SC2128
# shellcheck disable=SC2128
MAIN_HTTP
=
""
# shellcheck source=/dev/null
CASE_ERR
=
""
source
../dapp-test-common.sh
#color
RED
=
'\033[1;31m'
GRE
=
'\033[1;32m'
NOC
=
'\033[0m'
# base functions
# $2=0 means true, other false
function
echo_rst
()
{
if
[
"
$2
"
-eq
0
]
;
then
echo
-e
"
${
GRE
}
$1
ok
${
NOC
}
"
else
echo
-e
"
${
RED
}
$1
fail
${
NOC
}
"
CASE_ERR
=
"err"
fi
}
function
Chain33_SendToAddress
()
{
local
from
=
"
$1
"
local
to
=
"
$2
"
local
amount
=
$3
local
req
=
'{"method":"Chain33.SendToAddress", "params":[{"from":"'
"
$from
"
'","to":"'
"
$to
"
'", "amount":'
"
$amount
"
', "note":"test\n"}]}'
# echo "#request: $req"
resp
=
$(
curl
-ksd
"
$req
"
"
${
MAIN_HTTP
}
"
)
# echo "#response: $resp"
ok
=
$(
jq
'(.error|not) and (.result.hash|length==66)'
<<<
"
$resp
"
)
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
hash
=
$(
jq
'(.result.hash)'
<<<
"
$resp
"
)
echo
"hash=
$hash
"
# query_tx "$hash"
}
function
sign_raw_tx
()
{
txHex
=
"
$1
"
priKey
=
"
$2
"
req
=
'{"method":"Chain33.SignRawTx","params":[{"privkey":"'
"
$priKey
"
'","txHex":"'
"
$txHex
"
'","expire":"120s"}]}'
# echo "#request SignRawTx: $req"
resp
=
$(
curl
-ksd
"
$req
"
${
MAIN_HTTP
})
signedTx
=
$(
jq
-r
".result"
<<<
"
$resp
"
)
# echo "signedTx=$signedTx"
if
[
"
$signedTx
"
!=
null
]
;
then
send_tx
"
$signedTx
"
else
echo
"signedTx null error"
fi
}
function
send_tx
()
{
signedTx
=
$1
req
=
'{"method":"Chain33.SendTransaction","params":[{"token":"BTY","data":"'
"
$signedTx
"
'"}]}'
# echo "#request sendTx: $req"
# curl -ksd "$req" ${MAIN_HTTP}
resp
=
$(
curl
-ksd
"
$req
"
${
MAIN_HTTP
})
err
=
$(
jq
'(.error)'
<<<
"
$resp
"
)
txhash
=
$(
jq
-r
".result"
<<<
"
$resp
"
)
if
[
"
$err
"
==
null
]
;
then
# echo "tx hash: $txhash"
query_tx
"
$txhash
"
else
echo
"send tx error:
$err
"
fi
}
MAIN_HTTP
=
""
function
block_wait
()
{
req
=
'{"method":"Chain33.GetLastHeader","params":[{}]}'
cur_height
=
$(
curl
-ksd
"
$req
"
${
MAIN_HTTP
}
| jq
".result.height"
)
expect
=
$((
cur_height
+
${
1
}))
local
count
=
0
while
true
;
do
new_height
=
$(
curl
-ksd
"
$req
"
${
MAIN_HTTP
}
| jq
".result.height"
)
if
[
"
${
new_height
}
"
-ge
"
${
expect
}
"
]
;
then
break
fi
count
=
$((
count
+
1
))
sleep
1
done
echo
"wait new block
$count
s, cur height=
$expect
,old=
$cur_height
"
}
function
query_tx
()
{
block_wait 1
txhash
=
"
$1
"
# echo "req=$req"
local times
=
10
while
true
;
do
req
=
'{"method":"Chain33.QueryTransaction","params":[{"hash":"'
"
$txhash
"
'"}]}'
ret
=
$(
curl
-ksd
"
$req
"
${
MAIN_HTTP
})
tx
=
$(
jq
-r
".result.tx.hash"
<<<
"
$ret
"
)
echo
"====query tx=
${
1
}
, return=
$ret
"
if
[
"
${
tx
}
"
!=
"
${
1
}
"
]
;
then
block_wait 1
times
=
$((
times
-
1
))
if
[
$times
-le
0
]
;
then
echo
"====query tx=
$1
failed"
echo
"req=
$req
"
curl
-ksd
"
$req
"
${
MAIN_HTTP
}
exit
1
fi
else
exec_ok
=
$(
jq
'(.result.receipt.tyName == "ExecOk")'
<<<
"
$ret
"
)
[
"
$exec_ok
"
==
true
]
echo_rst
"query tx=
$1
"
$?
break
fi
done
}
function
init
()
{
function
init
()
{
ispara
=
$(
echo
'"'
"
${
MAIN_HTTP
}
"
'"'
| jq
'.|contains("8901")'
)
ispara
=
$(
echo
'"'
"
${
MAIN_HTTP
}
"
'"'
| jq
'.|contains("8901")'
)
...
@@ -149,7 +41,7 @@ function configJSCreator() {
...
@@ -149,7 +41,7 @@ function configJSCreator() {
[
"
$ok
"
==
true
]
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
echo_rst
"
$FUNCNAME
"
"
$?
"
rawtx
=
$(
jq
-r
".result"
<<<
"
$resp
"
)
rawtx
=
$(
jq
-r
".result"
<<<
"
$resp
"
)
sign_raw_tx
"
$rawtx
"
"
${
super_manager
}
"
chain33_SignRawTx
"
$rawtx
"
"
${
super_manager
}
"
"
${
MAIN_HTTP
}
"
}
}
function
createJSContract
()
{
function
createJSContract
()
{
...
@@ -161,7 +53,7 @@ function createJSContract() {
...
@@ -161,7 +53,7 @@ function createJSContract() {
[
"
$ok
"
==
true
]
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
echo_rst
"
$FUNCNAME
"
"
$?
"
rawtx
=
$(
jq
-r
".result"
<<<
"
$resp
"
)
rawtx
=
$(
jq
-r
".result"
<<<
"
$resp
"
)
sign_raw_tx
"
$rawtx
"
"
${
beneficiary_key
}
"
chain33_SignRawTx
"
$rawtx
"
"
${
beneficiary_key
}
"
"
${
MAIN_HTTP
}
"
}
}
function
callJS
()
{
function
callJS
()
{
...
@@ -174,7 +66,7 @@ function callJS() {
...
@@ -174,7 +66,7 @@ function callJS() {
[
"
$ok
"
==
true
]
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
echo_rst
"
$FUNCNAME
"
"
$?
"
rawtx
=
$(
jq
-r
".result"
<<<
"
$resp
"
)
rawtx
=
$(
jq
-r
".result"
<<<
"
$resp
"
)
sign_raw_tx
"
$rawtx
"
"
${
beneficiary_key
}
"
chain33_SignRawTx
"
$rawtx
"
"
${
beneficiary_key
}
"
"
${
MAIN_HTTP
}
"
}
}
function
queryJS
()
{
function
queryJS
()
{
...
...
plugin/dapp/paracross/cmd/build/chain33.para.test.toml
View file @
f94e04d5
Title
=
"user.p.para."
Title
=
"user.p.para."
CoinSymbol
=
"paracoin"
[log]
[log]
# 日志级别,支持debug(dbug)/info/warn/error(eror)/crit
# 日志级别,支持debug(dbug)/info/warn/error(eror)/crit
...
...
plugin/dapp/paracross/cmd/build/chain33.para.toml
View file @
f94e04d5
Title
=
"user.p.guodun."
Title
=
"user.p.guodun."
# TestNet=true
# TestNet=true
CoinSymbol
=
"paracoin"
[log]
[log]
# 日志级别,支持debug(dbug)/info/warn/error(eror)/crit
# 日志级别,支持debug(dbug)/info/warn/error(eror)/crit
...
...
plugin/dapp/paracross/cmd/build/testcase.sh
View file @
f94e04d5
This diff is collapsed.
Click to expand it.
plugin/dapp/paracross/commands/paracross.go
View file @
f94e04d5
...
@@ -38,6 +38,7 @@ func ParcCmd() *cobra.Command {
...
@@ -38,6 +38,7 @@ func ParcCmd() *cobra.Command {
GetParaListCmd
(),
GetParaListCmd
(),
GetNodeGroupCmd
(),
GetNodeGroupCmd
(),
GetNodeInfoCmd
(),
GetNodeInfoCmd
(),
GetNodeIDInfoCmd
(),
GetNodeListCmd
(),
GetNodeListCmd
(),
NodeGroupStatusCmd
(),
NodeGroupStatusCmd
(),
NodeGroupListCmd
(),
NodeGroupListCmd
(),
...
@@ -251,12 +252,12 @@ func CreateRawNodeManageCmd() *cobra.Command {
...
@@ -251,12 +252,12 @@ func CreateRawNodeManageCmd() *cobra.Command {
}
}
func
addNodeManageFlags
(
cmd
*
cobra
.
Command
)
{
func
addNodeManageFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
Uint32P
(
"operation"
,
"o"
,
0
,
"operation:1:join,2:vote,3:quit"
)
cmd
.
Flags
()
.
Uint32P
(
"operation"
,
"o"
,
0
,
"operation:1:join,2:vote,3:quit
,4:cancel
"
)
cmd
.
MarkFlagRequired
(
"operation"
)
cmd
.
MarkFlagRequired
(
"operation"
)
cmd
.
Flags
()
.
StringP
(
"addr"
,
"a"
,
""
,
"operating target addr"
)
cmd
.
Flags
()
.
StringP
(
"addr"
,
"a"
,
""
,
"operating target addr
[optional]
"
)
cmd
.
Flags
()
.
StringP
(
"id"
,
"i"
,
""
,
"operating target id"
)
cmd
.
Flags
()
.
StringP
(
"id"
,
"i"
,
""
,
"operating target id
[optional]
"
)
cmd
.
Flags
()
.
Uint32P
(
"value"
,
"v"
,
1
,
"vote value: 1:yes,2:no"
)
cmd
.
Flags
()
.
Uint32P
(
"value"
,
"v"
,
1
,
"vote value: 1:yes,2:no"
)
cmd
.
Flags
()
.
Float64P
(
"coins_frozen"
,
"c"
,
0
,
"frozen coins amount, should not less nodegroup's"
)
cmd
.
Flags
()
.
Float64P
(
"coins_frozen"
,
"c"
,
0
,
"frozen coins amount, should not less nodegroup's"
)
...
@@ -455,8 +456,8 @@ func paraList(cmd *cobra.Command, args []string) {
...
@@ -455,8 +456,8 @@ func paraList(cmd *cobra.Command, args []string) {
// GetNodeInfoCmd get node current status
// GetNodeInfoCmd get node current status
func
GetNodeInfoCmd
()
*
cobra
.
Command
{
func
GetNodeInfoCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"node_status"
,
Use
:
"node_
addr_
status"
,
Short
:
"Get node current
vote status
"
,
Short
:
"Get node current
status:10:joined,11:quited from nodegroup
"
,
Run
:
nodeInfo
,
Run
:
nodeInfo
,
}
}
addNodeBodyCmdFlags
(
cmd
)
addNodeBodyCmdFlags
(
cmd
)
...
@@ -468,7 +469,7 @@ func addNodeBodyCmdFlags(cmd *cobra.Command) {
...
@@ -468,7 +469,7 @@ func addNodeBodyCmdFlags(cmd *cobra.Command) {
cmd
.
MarkFlagRequired
(
"title"
)
cmd
.
MarkFlagRequired
(
"title"
)
cmd
.
Flags
()
.
StringP
(
"addr"
,
"a"
,
""
,
"addr apply for super user"
)
cmd
.
Flags
()
.
StringP
(
"addr"
,
"a"
,
""
,
"addr apply for super user"
)
cmd
.
Flags
()
.
StringP
(
"id"
,
"i"
,
""
,
"id apply for super use
r"
)
cmd
.
MarkFlagRequired
(
"add
r"
)
}
}
...
@@ -476,15 +477,47 @@ func nodeInfo(cmd *cobra.Command, args []string) {
...
@@ -476,15 +477,47 @@ func nodeInfo(cmd *cobra.Command, args []string) {
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
title
,
_
:=
cmd
.
Flags
()
.
GetString
(
"title"
)
title
,
_
:=
cmd
.
Flags
()
.
GetString
(
"title"
)
addr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"addr"
)
addr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"addr"
)
id
,
_
:=
cmd
.
Flags
()
.
GetString
(
"id"
)
params
:=
pt
.
ReqParacrossNodeInfo
{
params
:=
pt
.
ReqParacrossNodeInfo
{
Title
:
title
,
Title
:
title
,
Addr
:
addr
,
Addr
:
addr
,
}
var
res
pt
.
ParaNodeAddrIdStatus
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"paracross.GetNodeAddrStatus"
,
params
,
&
res
)
ctx
.
Run
()
}
// GetNodeIDInfoCmd get node current status
func
GetNodeIDInfoCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"node_id_status"
,
Short
:
"Get node id current vote status:0:all,1:joining,2:quiting,3:closed,4:canceled"
,
Run
:
nodeIDInfo
,
}
addNodeIDBodyCmdFlags
(
cmd
)
return
cmd
}
func
addNodeIDBodyCmdFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"title"
,
"t"
,
""
,
"parallel chain's title"
)
cmd
.
MarkFlagRequired
(
"title"
)
cmd
.
Flags
()
.
StringP
(
"id"
,
"i"
,
""
,
"id apply for super user"
)
cmd
.
MarkFlagRequired
(
"id"
)
}
func
nodeIDInfo
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
title
,
_
:=
cmd
.
Flags
()
.
GetString
(
"title"
)
id
,
_
:=
cmd
.
Flags
()
.
GetString
(
"id"
)
params
:=
pt
.
ReqParacrossNodeInfo
{
Title
:
title
,
Id
:
id
,
Id
:
id
,
}
}
var
res
pt
.
ParaNodeIdStatus
var
res
pt
.
ParaNodeIdStatus
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"paracross.GetNodeStatus"
,
params
,
&
res
)
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"paracross.GetNode
ID
Status"
,
params
,
&
res
)
ctx
.
Run
()
ctx
.
Run
()
}
}
...
...
plugin/dapp/paracross/executor/action.go
View file @
f94e04d5
...
@@ -260,6 +260,19 @@ func (a *action) getNodesGroup(title string) (map[string]struct{}, error) {
...
@@ -260,6 +260,19 @@ func (a *action) getNodesGroup(title string) (map[string]struct{}, error) {
return
nodes
,
nil
return
nodes
,
nil
}
}
//根据nodes过滤掉可能退出了的addrs
func
updateCommitAddrs
(
stat
*
pt
.
ParacrossHeightStatus
,
nodes
map
[
string
]
struct
{})
{
details
:=
&
pt
.
ParacrossStatusDetails
{}
for
i
,
addr
:=
range
stat
.
Details
.
Addrs
{
if
_
,
ok
:=
nodes
[
addr
];
ok
{
details
.
Addrs
=
append
(
details
.
Addrs
,
addr
)
details
.
BlockHash
=
append
(
details
.
BlockHash
,
stat
.
Details
.
BlockHash
[
i
])
}
}
stat
.
Details
=
details
}
func
(
a
*
action
)
Commit
(
commit
*
pt
.
ParacrossCommitAction
)
(
*
types
.
Receipt
,
error
)
{
func
(
a
*
action
)
Commit
(
commit
*
pt
.
ParacrossCommitAction
)
(
*
types
.
Receipt
,
error
)
{
err
:=
checkCommitInfo
(
commit
)
err
:=
checkCommitInfo
(
commit
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -364,6 +377,11 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error
...
@@ -364,6 +377,11 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error
}
}
receipt
=
makeCommitReceipt
(
a
.
fromaddr
,
commit
,
&
copyStat
,
stat
)
receipt
=
makeCommitReceipt
(
a
.
fromaddr
,
commit
,
&
copyStat
,
stat
)
}
}
if
types
.
IsDappFork
(
commit
.
Status
.
MainBlockHeight
,
pt
.
ParaX
,
pt
.
ForkCommitTx
)
{
updateCommitAddrs
(
stat
,
nodes
)
}
clog
.
Info
(
"paracross.Commit commit"
,
"stat.title"
,
stat
.
Title
,
"stat.height"
,
stat
.
Height
,
"notes"
,
len
(
nodes
))
clog
.
Info
(
"paracross.Commit commit"
,
"stat.title"
,
stat
.
Title
,
"stat.height"
,
stat
.
Height
,
"notes"
,
len
(
nodes
))
for
i
,
v
:=
range
stat
.
Details
.
Addrs
{
for
i
,
v
:=
range
stat
.
Details
.
Addrs
{
clog
.
Info
(
"paracross.Commit commit detail"
,
"addr"
,
v
,
"hash"
,
hex
.
EncodeToString
(
stat
.
Details
.
BlockHash
[
i
]))
clog
.
Info
(
"paracross.Commit commit detail"
,
"addr"
,
v
,
"hash"
,
hex
.
EncodeToString
(
stat
.
Details
.
BlockHash
[
i
]))
...
...
plugin/dapp/paracross/executor/exec_del_local.go
View file @
f94e04d5
...
@@ -100,6 +100,20 @@ func (e *Paracross) ExecDelLocal_NodeGroupConfig(payload *pt.ParaNodeGroupConfig
...
@@ -100,6 +100,20 @@ func (e *Paracross) ExecDelLocal_NodeGroupConfig(payload *pt.ParaNodeGroupConfig
set
.
KV
=
append
(
set
.
KV
,
&
types
.
KeyValue
{
set
.
KV
=
append
(
set
.
KV
,
&
types
.
KeyValue
{
Key
:
calcLocalNodeGroupStatusTitle
(
g
.
Current
.
Status
,
g
.
Current
.
Title
,
g
.
Current
.
Id
),
Value
:
nil
})
Key
:
calcLocalNodeGroupStatusTitle
(
g
.
Current
.
Status
,
g
.
Current
.
Title
,
g
.
Current
.
Id
),
Value
:
nil
})
}
}
if
log
.
Ty
==
pt
.
TyLogParaNodeConfig
{
var
g
pt
.
ReceiptParaNodeConfig
err
:=
types
.
Decode
(
log
.
Log
,
&
g
)
if
err
!=
nil
{
return
nil
,
err
}
if
g
.
Prev
!=
nil
{
set
.
KV
=
append
(
set
.
KV
,
&
types
.
KeyValue
{
Key
:
calcLocalNodeTitleStatus
(
g
.
Current
.
Title
,
g
.
Prev
.
Status
,
g
.
Prev
.
Id
),
Value
:
types
.
Encode
(
g
.
Prev
)})
}
set
.
KV
=
append
(
set
.
KV
,
&
types
.
KeyValue
{
Key
:
calcLocalNodeTitleStatus
(
g
.
Current
.
Title
,
g
.
Current
.
Status
,
g
.
Current
.
Id
),
Value
:
nil
})
}
}
}
return
&
set
,
nil
return
&
set
,
nil
}
}
...
...
plugin/dapp/paracross/executor/exec_local.go
View file @
f94e04d5
...
@@ -104,6 +104,21 @@ func (e *Paracross) ExecLocal_NodeGroupConfig(payload *pt.ParaNodeGroupConfig, t
...
@@ -104,6 +104,21 @@ func (e *Paracross) ExecLocal_NodeGroupConfig(payload *pt.ParaNodeGroupConfig, t
set
.
KV
=
append
(
set
.
KV
,
&
types
.
KeyValue
{
set
.
KV
=
append
(
set
.
KV
,
&
types
.
KeyValue
{
Key
:
calcLocalNodeGroupStatusTitle
(
g
.
Current
.
Status
,
g
.
Current
.
Title
,
g
.
Current
.
Id
),
Value
:
types
.
Encode
(
g
.
Current
)})
Key
:
calcLocalNodeGroupStatusTitle
(
g
.
Current
.
Status
,
g
.
Current
.
Title
,
g
.
Current
.
Id
),
Value
:
types
.
Encode
(
g
.
Current
)})
}
}
if
log
.
Ty
==
pt
.
TyLogParaNodeConfig
{
var
g
pt
.
ReceiptParaNodeConfig
err
:=
types
.
Decode
(
log
.
Log
,
&
g
)
if
err
!=
nil
{
return
nil
,
err
}
if
g
.
Prev
!=
nil
{
set
.
KV
=
append
(
set
.
KV
,
&
types
.
KeyValue
{
Key
:
calcLocalNodeTitleStatus
(
g
.
Current
.
Title
,
g
.
Prev
.
Status
,
g
.
Current
.
Id
),
Value
:
nil
})
}
set
.
KV
=
append
(
set
.
KV
,
&
types
.
KeyValue
{
Key
:
calcLocalNodeTitleStatus
(
g
.
Current
.
Title
,
g
.
Current
.
Status
,
g
.
Current
.
Id
),
Value
:
types
.
Encode
(
g
.
Current
)})
}
}
}
return
&
set
,
nil
return
&
set
,
nil
}
}
...
...
plugin/dapp/paracross/executor/query.go
View file @
f94e04d5
...
@@ -85,19 +85,15 @@ func (p *Paracross) Query_GetNodeAddrInfo(in *pt.ReqParacrossNodeInfo) (types.Me
...
@@ -85,19 +85,15 @@ func (p *Paracross) Query_GetNodeAddrInfo(in *pt.ReqParacrossNodeInfo) (types.Me
if
in
==
nil
||
in
.
Title
==
""
||
in
.
Addr
==
""
{
if
in
==
nil
||
in
.
Title
==
""
||
in
.
Addr
==
""
{
return
nil
,
types
.
ErrInvalidParam
return
nil
,
types
.
ErrInvalidParam
}
}
addrStat
,
err
:=
getNodeAddr
(
p
.
GetStateDB
(),
in
.
Title
,
in
.
Addr
)
stat
,
err
:=
getNodeAddr
(
p
.
GetStateDB
(),
in
.
Title
,
in
.
Addr
)
if
err
!=
nil
{
return
nil
,
err
}
stat
,
err
:=
getNodeID
(
p
.
GetStateDB
(),
addrStat
.
ProposalId
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
return
stat
,
nil
return
stat
,
nil
}
}
//Query_GetNodeI
d
Info get specific node addr info
//Query_GetNodeI
D
Info get specific node addr info
func
(
p
*
Paracross
)
Query_GetNodeI
d
Info
(
in
*
pt
.
ReqParacrossNodeInfo
)
(
types
.
Message
,
error
)
{
func
(
p
*
Paracross
)
Query_GetNodeI
D
Info
(
in
*
pt
.
ReqParacrossNodeInfo
)
(
types
.
Message
,
error
)
{
if
in
==
nil
||
in
.
Title
==
""
||
in
.
Id
==
""
{
if
in
==
nil
||
in
.
Title
==
""
||
in
.
Id
==
""
{
return
nil
,
types
.
ErrInvalidParam
return
nil
,
types
.
ErrInvalidParam
}
}
...
...
plugin/dapp/paracross/executor/superaccount.go
View file @
f94e04d5
This diff is collapsed.
Click to expand it.
plugin/dapp/paracross/executor/superaccount_test.go
View file @
f94e04d5
...
@@ -109,34 +109,17 @@ func checkGroupApplyReceipt(suite *NodeManageTestSuite, receipt *types.Receipt)
...
@@ -109,34 +109,17 @@ func checkGroupApplyReceipt(suite *NodeManageTestSuite, receipt *types.Receipt)
assert
.
Len
(
suite
.
T
(),
receipt
.
KV
,
1
)
assert
.
Len
(
suite
.
T
(),
receipt
.
KV
,
1
)
assert
.
Len
(
suite
.
T
(),
receipt
.
Logs
,
1
)
assert
.
Len
(
suite
.
T
(),
receipt
.
Logs
,
1
)
var
stat
pt
.
ParaNodeIdStatus
err
:=
types
.
Decode
(
receipt
.
KV
[
0
]
.
Value
,
&
stat
)
assert
.
Nil
(
suite
.
T
(),
err
,
"decode ParaNodeAddrStatus failed"
)
//suite.T().Log("titleHeight", titleHeight)
assert
.
Equal
(
suite
.
T
(),
int32
(
pt
.
TyLogParaNodeGroupConfig
),
receipt
.
Logs
[
0
]
.
Ty
)
assert
.
Equal
(
suite
.
T
(),
int32
(
pt
.
TyLogParaNodeGroupConfig
),
receipt
.
Logs
[
0
]
.
Ty
)
assert
.
Equal
(
suite
.
T
(),
int32
(
pt
.
ParacrossNodeGroupApply
),
stat
.
Status
)
}
}
func
checkGroupApproveReceipt
(
suite
*
NodeManageTestSuite
,
receipt
*
types
.
Receipt
)
{
func
checkGroupApproveReceipt
(
suite
*
NodeManageTestSuite
,
receipt
*
types
.
Receipt
)
{
assert
.
Equal
(
suite
.
T
(),
receipt
.
Ty
,
int32
(
types
.
ExecOk
))
assert
.
Equal
(
suite
.
T
(),
receipt
.
Ty
,
int32
(
types
.
ExecOk
))
assert
.
Len
(
suite
.
T
(),
receipt
.
KV
,
11
)
assert
.
Len
(
suite
.
T
(),
receipt
.
Logs
,
7
)
len
:=
len
(
receipt
.
KV
)
var
stat
pt
.
ParaNodeIdStatus
err
:=
types
.
Decode
(
receipt
.
KV
[
len
-
1
]
.
Value
,
&
stat
)
assert
.
Nil
(
suite
.
T
(),
err
,
"decode ParaNodeAddrStatus failed"
)
//suite.T().Log("ty len-1", receipt.Logs[lenLogs-1].Ty,"len",lenLogs)
assert
.
Equal
(
suite
.
T
(),
int32
(
pt
.
TyLogParaNodeGroupStatusUpdate
),
receipt
.
Logs
[
7
-
1
]
.
Ty
)
assert
.
Equal
(
suite
.
T
(),
int32
(
pt
.
ParacrossNodeGroupApprove
),
stat
.
Status
)
}
}
func
checkJoinReceipt
(
suite
*
NodeManageTestSuite
,
receipt
*
types
.
Receipt
)
{
func
checkJoinReceipt
(
suite
*
NodeManageTestSuite
,
receipt
*
types
.
Receipt
)
{
assert
.
Equal
(
suite
.
T
(),
receipt
.
Ty
,
int32
(
types
.
ExecOk
))
assert
.
Equal
(
suite
.
T
(),
receipt
.
Ty
,
int32
(
types
.
ExecOk
))
assert
.
Len
(
suite
.
T
(),
receipt
.
KV
,
2
)
assert
.
Len
(
suite
.
T
(),
receipt
.
KV
,
1
)
assert
.
Len
(
suite
.
T
(),
receipt
.
Logs
,
1
)
assert
.
Len
(
suite
.
T
(),
receipt
.
Logs
,
1
)
var
stat
pt
.
ParaNodeIdStatus
var
stat
pt
.
ParaNodeIdStatus
...
@@ -151,7 +134,7 @@ func checkJoinReceipt(suite *NodeManageTestSuite, receipt *types.Receipt) {
...
@@ -151,7 +134,7 @@ func checkJoinReceipt(suite *NodeManageTestSuite, receipt *types.Receipt) {
func
checkQuitReceipt
(
suite
*
NodeManageTestSuite
,
receipt
*
types
.
Receipt
)
{
func
checkQuitReceipt
(
suite
*
NodeManageTestSuite
,
receipt
*
types
.
Receipt
)
{
assert
.
Equal
(
suite
.
T
(),
receipt
.
Ty
,
int32
(
types
.
ExecOk
))
assert
.
Equal
(
suite
.
T
(),
receipt
.
Ty
,
int32
(
types
.
ExecOk
))
assert
.
Len
(
suite
.
T
(),
receipt
.
KV
,
2
)
assert
.
Len
(
suite
.
T
(),
receipt
.
KV
,
1
)
assert
.
Len
(
suite
.
T
(),
receipt
.
Logs
,
1
)
assert
.
Len
(
suite
.
T
(),
receipt
.
Logs
,
1
)
var
stat
pt
.
ParaNodeIdStatus
var
stat
pt
.
ParaNodeIdStatus
...
@@ -298,14 +281,18 @@ func (suite *NodeManageTestSuite) testNodeConfig() {
...
@@ -298,14 +281,18 @@ func (suite *NodeManageTestSuite) testNodeConfig() {
//Quit test
//Quit test
config
=
&
pt
.
ParaNodeAddrConfig
{
config
=
&
pt
.
ParaNodeAddrConfig
{
Op
:
pt
.
ParaNodeQuit
,
Op
:
pt
.
ParaNodeQuit
,
Id
:
g
.
Current
.
Id
,
Addr
:
Account14K
,
}
}
tx
,
err
=
pt
.
CreateRawNodeConfigTx
(
config
)
tx
,
err
=
pt
.
CreateRawNodeConfigTx
(
config
)
suite
.
Nil
(
err
)
suite
.
Nil
(
err
)
receipt
=
nodeCommit
(
suite
,
PrivKeyD
,
tx
)
receipt
=
nodeCommit
(
suite
,
PrivKeyD
,
tx
)
checkQuitReceipt
(
suite
,
receipt
)
checkQuitReceipt
(
suite
,
receipt
)
suite
.
Equal
(
int32
(
pt
.
TyLogParaNodeConfig
),
receipt
.
Logs
[
0
]
.
Ty
)
err
=
types
.
Decode
(
receipt
.
Logs
[
0
]
.
Log
,
&
g
)
suite
.
Nil
(
err
)
//vote test
//vote test
voteTest
(
suite
,
g
.
Current
.
Id
,
false
)
voteTest
(
suite
,
g
.
Current
.
Id
,
false
)
}
}
...
@@ -352,3 +339,18 @@ func TestGetAddrGroup(t *testing.T) {
...
@@ -352,3 +339,18 @@ func TestGetAddrGroup(t *testing.T) {
assert
.
Equal
(
t
,
0
,
len
(
ret
))
assert
.
Equal
(
t
,
0
,
len
(
ret
))
}
}
func
TestUpdateVotes
(
t
*
testing
.
T
)
{
stat
:=
&
pt
.
ParaNodeIdStatus
{}
votes
:=
&
pt
.
ParaNodeVoteDetail
{
Addrs
:
[]
string
{
"AA"
,
"BB"
,
"CC"
},
Votes
:
[]
string
{
"yes"
,
"no"
,
"no"
}}
stat
.
Votes
=
votes
nodes
:=
make
(
map
[
string
]
struct
{})
nodes
[
"BB"
]
=
struct
{}{}
nodes
[
"CC"
]
=
struct
{}{}
updateVotes
(
stat
,
nodes
)
assert
.
Equal
(
t
,
[]
string
{
"BB"
,
"CC"
},
stat
.
Votes
.
Addrs
)
assert
.
Equal
(
t
,
[]
string
{
"no"
,
"no"
},
stat
.
Votes
.
Votes
)
}
plugin/dapp/paracross/proto/paracross.proto
View file @
f94e04d5
...
@@ -63,7 +63,11 @@ message ParaNodeVoteDetail {
...
@@ -63,7 +63,11 @@ message ParaNodeVoteDetail {
}
}
message
ParaNodeAddrIdStatus
{
message
ParaNodeAddrIdStatus
{
string
proposalId
=
1
;
string
addr
=
1
;
string
proposalId
=
2
;
string
quitId
=
3
;
int32
status
=
4
;
string
title
=
5
;
}
}
message
ParaNodeIdStatus
{
message
ParaNodeIdStatus
{
...
@@ -85,6 +89,11 @@ message ReceiptParaNodeConfig {
...
@@ -85,6 +89,11 @@ message ReceiptParaNodeConfig {
ParaNodeIdStatus
current
=
4
;
ParaNodeIdStatus
current
=
4
;
}
}
message
ReceiptParaNodeAddrStatUpdate
{
string
fromAddr
=
1
;
ParaNodeAddrIdStatus
prev
=
2
;
ParaNodeAddrIdStatus
current
=
3
;
}
message
ReceiptParaNodeVoteDone
{
message
ReceiptParaNodeVoteDone
{
string
id
=
1
;
string
id
=
1
;
...
@@ -104,7 +113,6 @@ message ParaNodeGroupConfig {
...
@@ -104,7 +113,6 @@ message ParaNodeGroupConfig {
string
id
=
3
;
string
id
=
3
;
string
addrs
=
4
;
string
addrs
=
4
;
int64
coinsFrozen
=
5
;
int64
coinsFrozen
=
5
;
uint32
emptyBlockInterval
=
6
;
}
}
...
@@ -114,10 +122,8 @@ message ParaNodeGroupStatus {
...
@@ -114,10 +122,8 @@ message ParaNodeGroupStatus {
string
title
=
3
;
string
title
=
3
;
string
targetAddrs
=
4
;
string
targetAddrs
=
4
;
int64
coinsFrozen
=
5
;
int64
coinsFrozen
=
5
;
uint32
emptyBlockInterval
=
6
;
string
fromAddr
=
6
;
int64
mainHeight
=
7
;
int64
height
=
7
;
string
fromAddr
=
8
;
int64
height
=
9
;
}
}
message
ReceiptParaNodeGroupConfig
{
message
ReceiptParaNodeGroupConfig
{
...
...
plugin/dapp/paracross/rpc/rpc.go
View file @
f94e04d5
...
@@ -49,6 +49,9 @@ func (c *Jrpc) GetHeight(req *types.ReqString, result *interface{}) error {
...
@@ -49,6 +49,9 @@ func (c *Jrpc) GetHeight(req *types.ReqString, result *interface{}) error {
}
}
data
,
err
:=
c
.
cli
.
GetTitle
(
context
.
Background
(),
req
)
data
,
err
:=
c
.
cli
.
GetTitle
(
context
.
Background
(),
req
)
if
err
!=
nil
{
return
err
}
*
result
=
*
data
*
result
=
*
data
return
err
return
err
...
@@ -68,6 +71,9 @@ func (c *channelClient) ListTitles(ctx context.Context, req *types.ReqNil) (*pt.
...
@@ -68,6 +71,9 @@ func (c *channelClient) ListTitles(ctx context.Context, req *types.ReqNil) (*pt.
// ListTitles get paracross consensus titles list
// ListTitles get paracross consensus titles list
func
(
c
*
Jrpc
)
ListTitles
(
req
*
types
.
ReqNil
,
result
*
interface
{})
error
{
func
(
c
*
Jrpc
)
ListTitles
(
req
*
types
.
ReqNil
,
result
*
interface
{})
error
{
data
,
err
:=
c
.
cli
.
ListTitles
(
context
.
Background
(),
req
)
data
,
err
:=
c
.
cli
.
ListTitles
(
context
.
Background
(),
req
)
if
err
!=
nil
{
return
err
}
*
result
=
data
*
result
=
data
return
err
return
err
}
}
...
@@ -89,6 +95,9 @@ func (c *Jrpc) GetTitleHeight(req *pt.ReqParacrossTitleHeight, result *interface
...
@@ -89,6 +95,9 @@ func (c *Jrpc) GetTitleHeight(req *pt.ReqParacrossTitleHeight, result *interface
return
types
.
ErrInvalidParam
return
types
.
ErrInvalidParam
}
}
data
,
err
:=
c
.
cli
.
GetTitleHeight
(
context
.
Background
(),
req
)
data
,
err
:=
c
.
cli
.
GetTitleHeight
(
context
.
Background
(),
req
)
if
err
!=
nil
{
return
err
}
*
result
=
data
*
result
=
data
return
err
return
err
}
}
...
@@ -121,6 +130,9 @@ func (c *Jrpc) GetAssetTxResult(req *types.ReqHash, result *interface{}) error {
...
@@ -121,6 +130,9 @@ func (c *Jrpc) GetAssetTxResult(req *types.ReqHash, result *interface{}) error {
return
types
.
ErrInvalidParam
return
types
.
ErrInvalidParam
}
}
data
,
err
:=
c
.
cli
.
GetAssetTxResult
(
context
.
Background
(),
req
)
data
,
err
:=
c
.
cli
.
GetAssetTxResult
(
context
.
Background
(),
req
)
if
err
!=
nil
{
return
err
}
*
result
=
data
*
result
=
data
return
err
return
err
}
}
...
@@ -175,27 +187,30 @@ func (c *Jrpc) GetBlock2MainInfo(req *types.ReqBlocks, result *interface{}) erro
...
@@ -175,27 +187,30 @@ func (c *Jrpc) GetBlock2MainInfo(req *types.ReqBlocks, result *interface{}) erro
}
}
ret
,
err
:=
c
.
cli
.
GetBlock2MainInfo
(
context
.
Background
(),
req
)
ret
,
err
:=
c
.
cli
.
GetBlock2MainInfo
(
context
.
Background
(),
req
)
if
err
!=
nil
{
return
err
}
*
result
=
*
ret
*
result
=
*
ret
return
err
return
nil
}
}
// GetNodeStatus get super node status
// GetNode
Addr
Status get super node status
func
(
c
*
channelClient
)
GetNode
Status
(
ctx
context
.
Context
,
req
*
pt
.
ReqParacrossNodeInfo
)
(
*
pt
.
ParaNode
IdStatus
,
error
)
{
func
(
c
*
channelClient
)
GetNode
AddrStatus
(
ctx
context
.
Context
,
req
*
pt
.
ReqParacrossNodeInfo
)
(
*
pt
.
ParaNodeAddr
IdStatus
,
error
)
{
r
:=
*
req
r
:=
*
req
data
,
err
:=
c
.
Query
(
pt
.
GetExecName
(),
"GetNodeAddrInfo"
,
&
r
)
data
,
err
:=
c
.
Query
(
pt
.
GetExecName
(),
"GetNodeAddrInfo"
,
&
r
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
if
resp
,
ok
:=
data
.
(
*
pt
.
ParaNodeIdStatus
);
ok
{
if
resp
,
ok
:=
data
.
(
*
pt
.
ParaNode
Addr
IdStatus
);
ok
{
return
resp
,
nil
return
resp
,
nil
}
}
return
nil
,
types
.
ErrDecode
return
nil
,
types
.
ErrDecode
}
}
// GetNodeStatus get super node status
// GetNode
ID
Status get super node status
func
(
c
*
channelClient
)
GetNodeIDStatus
(
ctx
context
.
Context
,
req
*
pt
.
ReqParacrossNodeInfo
)
(
*
pt
.
ParaNodeIdStatus
,
error
)
{
func
(
c
*
channelClient
)
GetNodeIDStatus
(
ctx
context
.
Context
,
req
*
pt
.
ReqParacrossNodeInfo
)
(
*
pt
.
ParaNodeIdStatus
,
error
)
{
r
:=
*
req
r
:=
*
req
data
,
err
:=
c
.
Query
(
pt
.
GetExecName
(),
"GetNodeI
d
Info"
,
&
r
)
data
,
err
:=
c
.
Query
(
pt
.
GetExecName
(),
"GetNodeI
D
Info"
,
&
r
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -205,22 +220,30 @@ func (c *channelClient) GetNodeIDStatus(ctx context.Context, req *pt.ReqParacros
...
@@ -205,22 +220,30 @@ func (c *channelClient) GetNodeIDStatus(ctx context.Context, req *pt.ReqParacros
return
nil
,
types
.
ErrDecode
return
nil
,
types
.
ErrDecode
}
}
// GetNodeStatus get super node status
// GetNode
Addr
Status get super node status
func
(
c
*
Jrpc
)
GetNodeStatus
(
req
*
pt
.
ReqParacrossNodeInfo
,
result
*
interface
{})
error
{
func
(
c
*
Jrpc
)
GetNode
Addr
Status
(
req
*
pt
.
ReqParacrossNodeInfo
,
result
*
interface
{})
error
{
if
req
==
nil
||
(
req
.
Addr
==
""
&&
req
.
Id
==
""
)
{
if
req
==
nil
||
req
.
Addr
==
""
{
return
types
.
ErrInvalidParam
return
types
.
ErrInvalidParam
}
}
var
data
*
pt
.
ParaNodeIdStatus
data
,
err
:=
c
.
cli
.
GetNodeAddrStatus
(
context
.
Background
(),
req
)
var
err
error
if
err
!=
nil
{
if
req
.
Addr
!=
""
{
return
err
data
,
err
=
c
.
cli
.
GetNodeStatus
(
context
.
Background
(),
req
)
}
}
*
result
=
data
return
err
}
if
req
.
Id
!=
""
{
// GetNodeIDStatus get super node status
data
,
err
=
c
.
cli
.
GetNodeIDStatus
(
context
.
Background
(),
req
)
func
(
c
*
Jrpc
)
GetNodeIDStatus
(
req
*
pt
.
ReqParacrossNodeInfo
,
result
*
interface
{})
error
{
if
req
==
nil
||
req
.
Id
==
""
{
return
types
.
ErrInvalidParam
}
}
data
,
err
:=
c
.
cli
.
GetNodeIDStatus
(
context
.
Background
(),
req
)
if
err
!=
nil
{
return
err
}
*
result
=
data
*
result
=
data
return
err
return
err
}
}
...
@@ -241,6 +264,9 @@ func (c *channelClient) ListNodeStatus(ctx context.Context, req *pt.ReqParacross
...
@@ -241,6 +264,9 @@ func (c *channelClient) ListNodeStatus(ctx context.Context, req *pt.ReqParacross
//ListNodeStatus list super node by status
//ListNodeStatus list super node by status
func
(
c
*
Jrpc
)
ListNodeStatus
(
req
*
pt
.
ReqParacrossNodeInfo
,
result
*
interface
{})
error
{
func
(
c
*
Jrpc
)
ListNodeStatus
(
req
*
pt
.
ReqParacrossNodeInfo
,
result
*
interface
{})
error
{
data
,
err
:=
c
.
cli
.
ListNodeStatus
(
context
.
Background
(),
req
)
data
,
err
:=
c
.
cli
.
ListNodeStatus
(
context
.
Background
(),
req
)
if
err
!=
nil
{
return
err
}
*
result
=
data
*
result
=
data
return
err
return
err
}
}
...
@@ -261,6 +287,9 @@ func (c *channelClient) GetNodeGroupAddrs(ctx context.Context, req *pt.ReqParacr
...
@@ -261,6 +287,9 @@ func (c *channelClient) GetNodeGroupAddrs(ctx context.Context, req *pt.ReqParacr
// GetNodeGroupAddrs get super node group addrs
// GetNodeGroupAddrs get super node group addrs
func
(
c
*
Jrpc
)
GetNodeGroupAddrs
(
req
*
pt
.
ReqParacrossNodeInfo
,
result
*
interface
{})
error
{
func
(
c
*
Jrpc
)
GetNodeGroupAddrs
(
req
*
pt
.
ReqParacrossNodeInfo
,
result
*
interface
{})
error
{
data
,
err
:=
c
.
cli
.
GetNodeGroupAddrs
(
context
.
Background
(),
req
)
data
,
err
:=
c
.
cli
.
GetNodeGroupAddrs
(
context
.
Background
(),
req
)
if
err
!=
nil
{
return
err
}
*
result
=
data
*
result
=
data
return
err
return
err
}
}
...
@@ -281,6 +310,9 @@ func (c *channelClient) GetNodeGroupStatus(ctx context.Context, req *pt.ReqParac
...
@@ -281,6 +310,9 @@ func (c *channelClient) GetNodeGroupStatus(ctx context.Context, req *pt.ReqParac
// GetNodeGroupStatus get super node group status
// GetNodeGroupStatus get super node group status
func
(
c
*
Jrpc
)
GetNodeGroupStatus
(
req
*
pt
.
ReqParacrossNodeInfo
,
result
*
interface
{})
error
{
func
(
c
*
Jrpc
)
GetNodeGroupStatus
(
req
*
pt
.
ReqParacrossNodeInfo
,
result
*
interface
{})
error
{
data
,
err
:=
c
.
cli
.
GetNodeGroupStatus
(
context
.
Background
(),
req
)
data
,
err
:=
c
.
cli
.
GetNodeGroupStatus
(
context
.
Background
(),
req
)
if
err
!=
nil
{
return
err
}
*
result
=
data
*
result
=
data
return
err
return
err
}
}
...
@@ -301,6 +333,9 @@ func (c *channelClient) ListNodeGroupStatus(ctx context.Context, req *pt.ReqPara
...
@@ -301,6 +333,9 @@ func (c *channelClient) ListNodeGroupStatus(ctx context.Context, req *pt.ReqPara
//ListNodeGroupStatus list super node group by status
//ListNodeGroupStatus list super node group by status
func
(
c
*
Jrpc
)
ListNodeGroupStatus
(
req
*
pt
.
ReqParacrossNodeInfo
,
result
*
interface
{})
error
{
func
(
c
*
Jrpc
)
ListNodeGroupStatus
(
req
*
pt
.
ReqParacrossNodeInfo
,
result
*
interface
{})
error
{
data
,
err
:=
c
.
cli
.
ListNodeGroupStatus
(
context
.
Background
(),
req
)
data
,
err
:=
c
.
cli
.
ListNodeGroupStatus
(
context
.
Background
(),
req
)
if
err
!=
nil
{
return
err
}
*
result
=
data
*
result
=
data
return
err
return
err
}
}
plugin/dapp/paracross/testnode/cfg.go
View file @
f94e04d5
...
@@ -3,6 +3,7 @@ package testnode
...
@@ -3,6 +3,7 @@ package testnode
//DefaultConfig default config for testnode
//DefaultConfig default config for testnode
var
DefaultConfig
=
`
var
DefaultConfig
=
`
Title="user.p.guodun."
Title="user.p.guodun."
CoinSymbol="bty"
# TestNet=true
# TestNet=true
[log]
[log]
...
...
plugin/dapp/paracross/types/errors.go
View file @
f94e04d5
...
@@ -45,8 +45,8 @@ var (
...
@@ -45,8 +45,8 @@ var (
ErrParaNodeVoteSelf
=
errors
.
New
(
"ErrParaNodeVoteSelf"
)
ErrParaNodeVoteSelf
=
errors
.
New
(
"ErrParaNodeVoteSelf"
)
//ErrParaNodeGroupFrozenCoinsNotEnough node group coins in tx less than conf's minimum coins
//ErrParaNodeGroupFrozenCoinsNotEnough node group coins in tx less than conf's minimum coins
ErrParaNodeGroupFrozenCoinsNotEnough
=
errors
.
New
(
"ErrParaNodeGroupFrozenCoinsNotEnough"
)
ErrParaNodeGroupFrozenCoinsNotEnough
=
errors
.
New
(
"ErrParaNodeGroupFrozenCoinsNotEnough"
)
//ErrParaNode
GroupStatusWrong node group
process wrong status
//ErrParaNode
OpStatusWrong node
process wrong status
ErrParaNode
GroupStatusWrong
=
errors
.
New
(
"ErrParaNodeGrou
pStatusWrong"
)
ErrParaNode
OpStatusWrong
=
errors
.
New
(
"ErrParaNodeO
pStatusWrong"
)
//ErrParaConsensStopBlocksNotReach consensus stop blocks not reach
//ErrParaConsensStopBlocksNotReach consensus stop blocks not reach
ErrParaConsensStopBlocksNotReach
=
errors
.
New
(
"ErrParaConsensStopBlocksNotReach"
)
ErrParaConsensStopBlocksNotReach
=
errors
.
New
(
"ErrParaConsensStopBlocksNotReach"
)
)
)
plugin/dapp/paracross/types/paracross.go
View file @
f94e04d5
...
@@ -41,6 +41,7 @@ const (
...
@@ -41,6 +41,7 @@ const (
TyLogParaNodeVoteDone
=
658
TyLogParaNodeVoteDone
=
658
TyLogParaNodeGroupAddrsUpdate
=
659
TyLogParaNodeGroupAddrsUpdate
=
659
TyLogParaNodeGroupConfig
=
660
TyLogParaNodeGroupConfig
=
660
TyLogParaNodeStatusUpdate
=
661
TyLogParaNodeGroupStatusUpdate
=
664
TyLogParaNodeGroupStatusUpdate
=
664
)
)
...
@@ -92,6 +93,7 @@ const (
...
@@ -92,6 +93,7 @@ const (
ParaNodeJoin
=
iota
+
1
ParaNodeJoin
=
iota
+
1
ParaNodeVote
ParaNodeVote
ParaNodeQuit
ParaNodeQuit
ParaNodeCancel
)
)
// node vote op
// node vote op
...
@@ -106,16 +108,24 @@ const (
...
@@ -106,16 +108,24 @@ const (
var
ParaNodeVoteStr
=
[]
string
{
"invalid"
,
"yes"
,
"no"
}
var
ParaNodeVoteStr
=
[]
string
{
"invalid"
,
"yes"
,
"no"
}
const
(
const
(
// ParacrossNodeJoining apply for adding group
ParacrossNodeJoining
=
iota
+
1
// ParacrossNodeJoined pass to add by votes
// ParacrossNodeJoined pass to add by votes
ParacrossNodeJoined
ParacrossNodeJoined
=
iota
+
10
// ParacrossNodeQuiting apply for quiting
ParacrossNodeQuiting
// ParacrossNodeQuited pass to quite by votes
// ParacrossNodeQuited pass to quite by votes
ParacrossNodeQuited
ParacrossNodeQuited
)
)
//voting status
const
(
// ParacrossNodeIDJoining apply for join group
ParacrossNodeJoining
=
iota
+
1
// ParacrossNodeIDQuiting apply for quiting group
ParacrossNodeQuiting
// ParacrossNodeIDClosed id voting closed
ParacrossNodeClosed
// ParacrossNodeCanceled to cancel apply of joining or quiting
ParacrossNodeCanceled
)
const
(
const
(
//ParacrossNodeGroupApply apply for para chain node group initially
//ParacrossNodeGroupApply apply for para chain node group initially
ParacrossNodeGroupApply
=
iota
+
1
ParacrossNodeGroupApply
=
iota
+
1
...
@@ -204,12 +214,7 @@ func CreateRawNodeConfigTx(config *ParaNodeAddrConfig) (*types.Transaction, erro
...
@@ -204,12 +214,7 @@ func CreateRawNodeConfigTx(config *ParaNodeAddrConfig) (*types.Transaction, erro
//CreateRawNodeGroupApplyTx create raw tx for node group
//CreateRawNodeGroupApplyTx create raw tx for node group
func
CreateRawNodeGroupApplyTx
(
apply
*
ParaNodeGroupConfig
)
(
*
types
.
Transaction
,
error
)
{
func
CreateRawNodeGroupApplyTx
(
apply
*
ParaNodeGroupConfig
)
(
*
types
.
Transaction
,
error
)
{
apply
.
Title
=
types
.
GetTitle
()
apply
.
Title
=
types
.
GetTitle
()
apply
.
EmptyBlockInterval
=
4
apply
.
Id
=
strings
.
Trim
(
apply
.
Id
,
" "
)
apply
.
Id
=
strings
.
Trim
(
apply
.
Id
,
" "
)
interval
:=
types
.
Conf
(
"config.consensus.sub.para"
)
.
GInt
(
"emptyBlockInterval"
)
if
interval
>
0
{
apply
.
EmptyBlockInterval
=
uint32
(
interval
)
}
action
:=
&
ParacrossAction
{
action
:=
&
ParacrossAction
{
Ty
:
ParacrossActionNodeGroupApply
,
Ty
:
ParacrossActionNodeGroupApply
,
...
...
plugin/dapp/paracross/types/paracross.pb.go
View file @
f94e04d5
This diff is collapsed.
Click to expand it.
plugin/dapp/paracross/types/type.go
View file @
f94e04d5
...
@@ -62,6 +62,7 @@ func (p *ParacrossType) GetLogMap() map[int64]*types.LogInfo {
...
@@ -62,6 +62,7 @@ func (p *ParacrossType) GetLogMap() map[int64]*types.LogInfo {
TyLogParaAssetDeposit
:
{
Ty
:
reflect
.
TypeOf
(
types
.
ReceiptAccountTransfer
{}),
Name
:
"LogParaAssetDeposit"
},
TyLogParaAssetDeposit
:
{
Ty
:
reflect
.
TypeOf
(
types
.
ReceiptAccountTransfer
{}),
Name
:
"LogParaAssetDeposit"
},
TyLogParacrossMiner
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptParacrossMiner
{}),
Name
:
"LogParacrossMiner"
},
TyLogParacrossMiner
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptParacrossMiner
{}),
Name
:
"LogParacrossMiner"
},
TyLogParaNodeConfig
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptParaNodeConfig
{}),
Name
:
"LogParaNodeConfig"
},
TyLogParaNodeConfig
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptParaNodeConfig
{}),
Name
:
"LogParaNodeConfig"
},
TyLogParaNodeStatusUpdate
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptParaNodeAddrStatUpdate
{}),
Name
:
"LogParaNodeAddrStatUpdate"
},
TyLogParaNodeGroupAddrsUpdate
:
{
Ty
:
reflect
.
TypeOf
(
types
.
ReceiptConfig
{}),
Name
:
"LogParaNodeGroupAddrsUpdate"
},
TyLogParaNodeGroupAddrsUpdate
:
{
Ty
:
reflect
.
TypeOf
(
types
.
ReceiptConfig
{}),
Name
:
"LogParaNodeGroupAddrsUpdate"
},
TyLogParaNodeVoteDone
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptParaNodeVoteDone
{}),
Name
:
"LogParaNodeVoteDone"
},
TyLogParaNodeVoteDone
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptParaNodeVoteDone
{}),
Name
:
"LogParaNodeVoteDone"
},
TyLogParaNodeGroupConfig
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptParaNodeGroupConfig
{}),
Name
:
"LogParaNodeGroupConfig"
},
TyLogParaNodeGroupConfig
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptParaNodeGroupConfig
{}),
Name
:
"LogParaNodeGroupConfig"
},
...
...
plugin/dapp/unfreeze/cmd/build/test-rpc.sh
View file @
f94e04d5
#!/usr/bin/env bash
#!/usr/bin/env bash
# shellcheck disable=SC2128
# shellcheck disable=SC2128
MAIN_HTTP
=
""
# shellcheck source=/dev/null
CASE_ERR
=
""
source
../dapp-test-common.sh
#color
RED
=
'\033[1;31m'
GRE
=
'\033[1;32m'
NOC
=
'\033[0m'
# base functions
# $2=0 means true, other false
function
echo_rst
()
{
if
[
"
$2
"
-eq
0
]
;
then
echo
-e
"
${
GRE
}
$1
ok
${
NOC
}
"
else
echo
-e
"
${
RED
}
$1
fail
${
NOC
}
"
CASE_ERR
=
"err"
fi
}
function
Chain33_SendToAddress
()
{
local
from
=
"
$1
"
local
to
=
"
$2
"
local
amount
=
$3
local
req
=
'{"method":"Chain33.SendToAddress", "params":[{"from":"'
"
$from
"
'","to":"'
"
$to
"
'", "amount":'
"
$amount
"
', "note":"test\n"}]}'
# echo "#request: $req"
resp
=
$(
curl
-ksd
"
$req
"
"
${
MAIN_HTTP
}
"
)
# echo "#response: $resp"
ok
=
$(
jq
'(.error|not) and (.result.hash|length==66)'
<<<
"
$resp
"
)
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
hash
=
$(
jq
'(.result.hash)'
<<<
"
$resp
"
)
echo
"hash=
$hash
"
# query_tx "$hash"
}
function
sign_raw_tx
()
{
txHex
=
"
$1
"
priKey
=
"
$2
"
req
=
'{"method":"Chain33.SignRawTx","params":[{"privkey":"'
"
$priKey
"
'","txHex":"'
"
$txHex
"
'","expire":"120s"}]}'
# echo "#request SignRawTx: $req"
signedTx
=
$(
curl
-ksd
"
$req
"
${
MAIN_HTTP
}
| jq
-r
".result"
)
# echo "signedTx=$signedTx"
if
[
"
$signedTx
"
!=
null
]
;
then
send_tx
"
$signedTx
"
else
echo
"signedTx null error"
fi
}
function
send_tx
()
{
signedTx
=
$1
req
=
'{"method":"Chain33.SendTransaction","params":[{"token":"BTY","data":"'
"
$signedTx
"
'"}]}'
# echo "#request sendTx: $req"
# curl -ksd "$req" ${MAIN_HTTP}
resp
=
$(
curl
-ksd
"
$req
"
${
MAIN_HTTP
})
err
=
$(
jq
'(.error)'
<<<
"
$resp
"
)
txhash
=
$(
jq
-r
".result"
<<<
"
$resp
"
)
if
[
"
$err
"
==
null
]
;
then
# echo "tx hash: $txhash"
query_tx
"
$txhash
"
else
echo
"send tx error:
$err
"
fi
}
function
block_wait
()
{
req
=
'{"method":"Chain33.GetLastHeader","params":[{}]}'
cur_height
=
$(
curl
-ksd
"
$req
"
${
MAIN_HTTP
}
| jq
".result.height"
)
expect
=
$((
cur_height
+
${
1
}))
local
count
=
0
while
true
;
do
new_height
=
$(
curl
-ksd
"
$req
"
${
MAIN_HTTP
}
| jq
".result.height"
)
if
[
"
${
new_height
}
"
-ge
"
${
expect
}
"
]
;
then
break
fi
count
=
$((
count
+
1
))
sleep
1
done
echo
"wait new block
$count
s, cur height=
$expect
,old=
$cur_height
"
}
function
query_tx
()
{
MAIN_HTTP
=
""
block_wait 1
txhash
=
""
txhash
=
"
$1
"
# echo "req=$req"
local times
=
10
while
true
;
do
req
=
'{"method":"Chain33.QueryTransaction","params":[{"hash":"'
"
$txhash
"
'"}]}'
ret
=
$(
curl
-ksd
"
$req
"
${
MAIN_HTTP
})
tx
=
$(
jq
-r
".result.tx.hash"
<<<
"
$ret
"
)
echo
"====query tx=
${
1
}
, return=
$ret
"
if
[
"
${
tx
}
"
!=
"
${
1
}
"
]
;
then
block_wait 1
times
=
$((
times
-
1
))
if
[
$times
-le
0
]
;
then
echo
"====query tx=
$1
failed"
echo
"req=
$req
"
curl
-ksd
"
$req
"
${
MAIN_HTTP
}
exit
1
fi
else
exec_err
=
$(
jq
'(.result.receipt.logs[0].tyName == "LogErr")'
<<<
"
$ret
"
)
[
"
$exec_err
"
!=
true
]
echo
"====query tx=
$1
success"
break
fi
done
}
function
query_unfreezeID
()
{
function
query_unfreezeID
()
{
block_wait 1
chain33_BlockWait 1
"
$MAIN_HTTP
"
# echo "req=$req"
# echo "req=$req"
local times
=
10
local times
=
10
...
@@ -161,8 +55,8 @@ function init() {
...
@@ -161,8 +55,8 @@ function init() {
owner_key=CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944
owner_key=CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944
#unfreeze_exec_addr=15YsqAuXeEXVHgm6RVx4oJaAAnhtwqnu3H
#unfreeze_exec_addr=15YsqAuXeEXVHgm6RVx4oJaAAnhtwqnu3H
Chain33_SendToAddress "
$owner
" "
$exec_addr
" 500000000
Chain33_SendToAddress "
$owner
" "
$exec_addr
" 500000000
"
${
MAIN_HTTP
}
"
Chain33_SendToAddress "
$beneficiary
" "
$exec_addr
" 500000000
Chain33_SendToAddress "
$beneficiary
" "
$exec_addr
" 500000000
"
${
MAIN_HTTP
}
"
block_wait 1
block_wait 1
}
}
...
@@ -175,7 +69,7 @@ function CreateRawUnfreezeCreate() {
...
@@ -175,7 +69,7 @@ function CreateRawUnfreezeCreate() {
[ "
$ok
" == true ]
[ "
$ok
" == true ]
echo_rst "
$FUNCNAME
" "
$?
"
echo_rst "
$FUNCNAME
" "
$?
"
rawtx=
$(
jq
-r
".result"
<<<
"
$resp
"
)
rawtx=
$(
jq
-r
".result"
<<<
"
$resp
"
)
sign_raw_tx "
$rawtx
" "
$owner_key
"
chain33_SignRawTx "
$rawtx
" "
$owner_key
" "
${
MAIN_HTTP
}
"
query_unfreezeID
query_unfreezeID
}
}
...
@@ -189,8 +83,9 @@ function CreateRawUnfreezeWithdraw() {
...
@@ -189,8 +83,9 @@ function CreateRawUnfreezeWithdraw() {
[ "
$ok
" == true ]
[ "
$ok
" == true ]
echo_rst "
$FUNCNAME
" "
$?
"
echo_rst "
$FUNCNAME
" "
$?
"
rawtx=
$(
jq
-r
".result"
<<<
"
$resp
"
)
rawtx=
$(
jq
-r
".result"
<<<
"
$resp
"
)
sign_raw_tx "
$rawtx
" "
${
beneficiary_key
}
"
chain33_SignRawTx "
$rawtx
" "
${
beneficiary_key
}
" "
${
MAIN_HTTP
}
"
}
}
function CreateRawUnfreezeTerminate() {
function CreateRawUnfreezeTerminate() {
req='{"
method
":"
unfreeze
.CreateRawUnfreezeTerminate
","
params
":[{"
unfreezeID
":"
'${uid}'
"}]}'
req='{"
method
":"
unfreeze
.CreateRawUnfreezeTerminate
","
params
":[{"
unfreezeID
":"
'${uid}'
"}]}'
# echo "
#request
:
$req
"
# echo "
#request
:
$req
"
...
@@ -200,7 +95,7 @@ function CreateRawUnfreezeTerminate() {
...
@@ -200,7 +95,7 @@ function CreateRawUnfreezeTerminate() {
[ "
$ok
" == true ]
[ "
$ok
" == true ]
echo_rst "
$FUNCNAME
" "
$?
"
echo_rst "
$FUNCNAME
" "
$?
"
rawtx=
$(
jq
-r
".result"
<<<
"
$resp
"
)
rawtx=
$(
jq
-r
".result"
<<<
"
$resp
"
)
sign_raw_tx "
$rawtx
" "
$owner_key
"
chain33_SignRawTx "
$rawtx
" "
$owner_key
" "
${
MAIN_HTTP
}
"
block_wait 2
block_wait 2
}
}
...
...
vendor/github.com/33cn/chain33/.travis.yml
View file @
f94e04d5
...
@@ -58,6 +58,6 @@ matrix:
...
@@ -58,6 +58,6 @@ matrix:
-
sudo mv docker-compose /usr/local/bin
-
sudo mv docker-compose /usr/local/bin
script
:
script
:
-
make build_ci
-
make build_ci
-
make autotest
_ci
-
make autotest
dapp=all
-
make docker-compose && make docker-compose-down
-
make docker-compose && make docker-compose-down
vendor/github.com/33cn/chain33/build/autotest/jerkinsci/jerkins-ci-autotest.sh
View file @
f94e04d5
...
@@ -49,14 +49,6 @@ function config_chain33() {
...
@@ -49,14 +49,6 @@ function config_chain33() {
else
else
sed
-i
$sedfix
'/^Title/a TestNet=true'
${
chain33Config
}
sed
-i
$sedfix
'/^Title/a TestNet=true'
${
chain33Config
}
fi
fi
#update fee
sed
-i
$sedfix
's/Fee=.*/Fee=100000/'
${
chain33Config
}
#update block time
#update wallet store driver
sed
-i
$sedfix
'/^\[wallet\]/,/^\[wallet./ s/^driver.*/driver="leveldb"/'
${
chain33Config
}
}
}
function
config_autotest
()
{
function
config_autotest
()
{
...
...
vendor/github.com/33cn/chain33/build/autotest/local/local-autotest.sh
View file @
f94e04d5
...
@@ -40,12 +40,10 @@ function config_chain33() {
...
@@ -40,12 +40,10 @@ function config_chain33() {
fi
fi
#update fee
#update fee
sed
-i
$sedfix
's/Fee=.*/Fee=100000/'
${
chain33Config
}
# sed -i $sedfix 's/Fee=.*/Fee=100000/' ${chain33Config}
#update block time
#update wallet store driver
#update wallet store driver
sed
-i
$sedfix
'/^\[wallet\]/,/^\[wallet./ s/^driver.*/driver="leveldb"/'
${
chain33Config
}
#
sed -i $sedfix '/^\[wallet\]/,/^\[wallet./ s/^driver.*/driver="leveldb"/' ${chain33Config}
}
}
autotestConfig
=
"autotest.toml"
autotestConfig
=
"autotest.toml"
...
...
vendor/github.com/33cn/chain33/build/system-test-rpc.sh
View file @
f94e04d5
...
@@ -138,13 +138,17 @@ chain33_GetHeaders() {
...
@@ -138,13 +138,17 @@ chain33_GetHeaders() {
chain33_GetLastMemPool
()
{
chain33_GetLastMemPool
()
{
req
=
'"method":"Chain33.GetLastMemPool", "params":[{}]'
if
[
"
$IS_PARA
"
==
true
]
;
then
echo
"#request:
$req
"
echo_rst
"
$FUNCNAME
"
2
resp
=
$(
curl
-ksd
"{
$req
}"
"
$1
"
)
else
# echo "#response: $resp"
req
=
'"method":"Chain33.GetLastMemPool", "params":[{}]'
ok
=
$(
jq
'(.error|not) and (.result.txs|length >= 0)'
<<<
"
$resp
"
)
echo
"#request:
$req
"
[
"
$ok
"
==
true
]
resp
=
$(
curl
-ksd
"{
$req
}"
"
$1
"
)
echo_rst
"
$FUNCNAME
"
"
$?
"
#echo "#response: $resp"
ok
=
$(
jq
'(.error|not) and (.result.txs|length >= 0)'
<<<
"
$resp
"
)
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
fi
}
}
chain33_GetProperFee
()
{
chain33_GetProperFee
()
{
...
@@ -394,11 +398,16 @@ chain33_GetTxByHashes() {
...
@@ -394,11 +398,16 @@ chain33_GetTxByHashes() {
}
}
chain33_GetMempool
()
{
chain33_GetMempool
()
{
resp
=
$(
curl
-ksd
'{"jsonrpc":"2.0","id":2,"method":"Chain33.GetMempool","params":[{}]}'
-H
'content-type:text/plain;'
${
MAIN_HTTP
})
ok
=
$(
jq
'(.error|not) and (.result.txs|length >= 0)'
<<<
"
$resp
"
)
if
[
"
$IS_PARA
"
==
true
]
;
then
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
2
rst
=
$?
else
echo_rst
"
$FUNCNAME
"
"
$rst
"
resp
=
$(
curl
-ksd
'{"jsonrpc":"2.0","id":2,"method":"Chain33.GetMempool","params":[{}]}'
-H
'content-type:text/plain;'
${
MAIN_HTTP
})
ok
=
$(
jq
'(.error|not) and (.result.txs|length >= 0)'
<<<
"
$resp
"
)
[
"
$ok
"
==
true
]
rst
=
$?
echo_rst
"
$FUNCNAME
"
"
$rst
"
fi
}
}
chain33_GetAccountsV2
()
{
chain33_GetAccountsV2
()
{
...
...
vendor/github.com/33cn/chain33/cmd/chain33/bityuan.toml
View file @
f94e04d5
...
@@ -54,6 +54,8 @@ dbPath="datadir/addrbook"
...
@@ -54,6 +54,8 @@ dbPath="datadir/addrbook"
dbCache
=
4
dbCache
=
4
# GRPC请求日志文件
# GRPC请求日志文件
grpcLogFile
=
"grpc33.log"
grpcLogFile
=
"grpc33.log"
#waitPid 等待seed导入
waitPid
=
false
[rpc]
[rpc]
# jrpc绑定地址
# jrpc绑定地址
...
...
vendor/github.com/33cn/chain33/cmd/chain33/chain33.test.toml
View file @
f94e04d5
...
@@ -53,6 +53,8 @@ grpcLogFile="grpc33.log"
...
@@ -53,6 +53,8 @@ grpcLogFile="grpc33.log"
version
=
216
version
=
216
verMix
=
216
verMix
=
216
verMax
=
217
verMax
=
217
#waitPid 等待seed导入
waitPid
=
false
[rpc]
[rpc]
jrpcBindAddr
=
"localhost:8801"
jrpcBindAddr
=
"localhost:8801"
...
@@ -69,6 +71,7 @@ name="timeline"
...
@@ -69,6 +71,7 @@ name="timeline"
poolCacheSize
=
10240
poolCacheSize
=
10240
minTxFee
=
100000
minTxFee
=
100000
maxTxNumPerAccount
=
100
maxTxNumPerAccount
=
100
isLevelFee
=
false
[mempool.sub.timeline]
[mempool.sub.timeline]
poolCacheSize
=
10240
poolCacheSize
=
10240
...
@@ -163,6 +166,7 @@ minerwhitelist=["*"]
...
@@ -163,6 +166,7 @@ minerwhitelist=["*"]
[exec]
[exec]
isFree
=
false
isFree
=
false
minExecFee
=
100000
minExecFee
=
100000
maxExecFee
=
1000000000
enableStat
=
false
enableStat
=
false
enableMVCC
=
false
enableMVCC
=
false
...
...
vendor/github.com/33cn/chain33/cmd/chain33/chain33.toml
View file @
f94e04d5
Title
=
"chain33"
Title
=
"chain33"
TestNet
=
true
TestNet
=
true
FixTime
=
false
FixTime
=
false
# 配置主币的名称: 比特元链bty, 部分未配置的平行链需要配置为 bty, 新的平行链配置 para或其他, 不配置panic
CoinSymbol
=
"bty"
CoinSymbol
=
"bty"
[log]
[log]
...
@@ -77,6 +78,8 @@ dbPath="datadir/addrbook"
...
@@ -77,6 +78,8 @@ dbPath="datadir/addrbook"
dbCache
=
4
dbCache
=
4
# GRPC请求日志文件
# GRPC请求日志文件
grpcLogFile
=
"grpc33.log"
grpcLogFile
=
"grpc33.log"
#waitPid 等待seed导入
waitPid
=
false
[rpc]
[rpc]
# jrpc绑定地址
# jrpc绑定地址
...
@@ -105,7 +108,10 @@ poolCacheSize=10240
...
@@ -105,7 +108,10 @@ poolCacheSize=10240
minTxFee
=
100000
minTxFee
=
100000
# 每个账户在mempool中得最大交易数量,默认100
# 每个账户在mempool中得最大交易数量,默认100
maxTxNumPerAccount
=
100
maxTxNumPerAccount
=
100
# 最大得交易手续费用,这个没有默认值,必填,一般是100000
maxTxFee
=
1000000000
maxTxFee
=
1000000000
# 是否开启阶梯手续费
isLevelFee
=
false
[mempool.sub.timeline]
[mempool.sub.timeline]
# mempool缓存容量大小,默认10240
# mempool缓存容量大小,默认10240
...
...
vendor/github.com/33cn/chain33/p2p/addrbook.go
View file @
f94e04d5
...
@@ -243,15 +243,7 @@ func (a *AddrBook) genPubkey(privkey string) string {
...
@@ -243,15 +243,7 @@ func (a *AddrBook) genPubkey(privkey string) string {
func
(
a
*
AddrBook
)
loadDb
()
bool
{
func
(
a
*
AddrBook
)
loadDb
()
bool
{
a
.
bookDb
=
db
.
NewDB
(
"addrbook"
,
a
.
cfg
.
Driver
,
a
.
cfg
.
DbPath
,
a
.
cfg
.
DbCache
)
a
.
bookDb
=
db
.
NewDB
(
"addrbook"
,
a
.
cfg
.
Driver
,
a
.
cfg
.
DbPath
,
a
.
cfg
.
DbCache
)
privkey
,
err
:=
a
.
bookDb
.
Get
([]
byte
(
privKeyTag
))
privkey
,
err
:=
a
.
bookDb
.
Get
([]
byte
(
privKeyTag
))
if
len
(
privkey
)
==
0
||
err
!=
nil
{
if
len
(
privkey
)
!=
0
&&
err
==
nil
{
a
.
initKey
()
privkey
,
_
:=
a
.
GetPrivPubKey
()
err
:=
a
.
bookDb
.
Set
([]
byte
(
privKeyTag
),
[]
byte
(
privkey
))
if
err
!=
nil
{
panic
(
err
)
}
}
else
{
a
.
setKey
(
string
(
privkey
),
a
.
genPubkey
(
string
(
privkey
)))
a
.
setKey
(
string
(
privkey
),
a
.
genPubkey
(
string
(
privkey
)))
}
}
...
@@ -393,10 +385,12 @@ func (a *AddrBook) setKey(privkey, pubkey string) {
...
@@ -393,10 +385,12 @@ func (a *AddrBook) setKey(privkey, pubkey string) {
//ResetPeerkey reset priv,pub key
//ResetPeerkey reset priv,pub key
func
(
a
*
AddrBook
)
ResetPeerkey
(
privkey
,
pubkey
string
)
{
func
(
a
*
AddrBook
)
ResetPeerkey
(
privkey
,
pubkey
string
)
{
a
.
keymtx
.
Lock
()
defer
a
.
keymtx
.
Unlock
()
if
privkey
==
""
||
pubkey
==
""
{
a
.
privkey
=
privkey
a
.
initKey
()
a
.
pubkey
=
pubkey
privkey
,
pubkey
=
a
.
GetPrivPubKey
()
}
a
.
setKey
(
privkey
,
pubkey
)
err
:=
a
.
bookDb
.
Set
([]
byte
(
privKeyTag
),
[]
byte
(
privkey
))
err
:=
a
.
bookDb
.
Set
([]
byte
(
privKeyTag
),
[]
byte
(
privkey
))
if
err
!=
nil
{
if
err
!=
nil
{
panic
(
err
)
panic
(
err
)
...
...
vendor/github.com/33cn/chain33/p2p/const.go
View file @
f94e04d5
...
@@ -34,12 +34,6 @@ const (
...
@@ -34,12 +34,6 @@ const (
maxSamIPNum
=
20
maxSamIPNum
=
20
)
)
var
(
// LocalAddr local address
LocalAddr
string
//defaultPort = 13802
)
const
(
const
(
defalutNatPort
=
23802
defalutNatPort
=
23802
maxOutBoundNum
=
25
maxOutBoundNum
=
25
...
...
vendor/github.com/33cn/chain33/p2p/downloadblocks.go
View file @
f94e04d5
...
@@ -147,6 +147,7 @@ func (d *DownloadJob) GetFreePeer(blockHeight int64) *Peer {
...
@@ -147,6 +147,7 @@ func (d *DownloadJob) GetFreePeer(blockHeight int64) *Peer {
var
jobNum
int32
=
10
var
jobNum
int32
=
10
var
bestPeer
*
Peer
var
bestPeer
*
Peer
for
_
,
peer
:=
range
d
.
downloadPeers
{
for
_
,
peer
:=
range
d
.
downloadPeers
{
pbpeer
,
ok
:=
infos
[
peer
.
Addr
()]
pbpeer
,
ok
:=
infos
[
peer
.
Addr
()]
if
ok
{
if
ok
{
if
len
(
peer
.
GetPeerName
())
==
0
{
if
len
(
peer
.
GetPeerName
())
==
0
{
...
@@ -194,6 +195,7 @@ func (d *DownloadJob) DownloadBlock(invs []*pb.Inventory,
...
@@ -194,6 +195,7 @@ func (d *DownloadJob) DownloadBlock(invs []*pb.Inventory,
REGET
:
REGET
:
freePeer
:=
d
.
GetFreePeer
(
inv
.
GetHeight
())
//获取当前任务数最少的节点,相当于 下载速度最快的节点
freePeer
:=
d
.
GetFreePeer
(
inv
.
GetHeight
())
//获取当前任务数最少的节点,相当于 下载速度最快的节点
if
freePeer
==
nil
{
if
freePeer
==
nil
{
log
.
Debug
(
"no free peer"
)
time
.
Sleep
(
time
.
Millisecond
*
100
)
time
.
Sleep
(
time
.
Millisecond
*
100
)
goto
REGET
goto
REGET
}
}
...
...
vendor/github.com/33cn/chain33/p2p/node.go
View file @
f94e04d5
...
@@ -123,7 +123,8 @@ func (n *Node) flushNodePort(localport, export uint16) {
...
@@ -123,7 +123,8 @@ func (n *Node) flushNodePort(localport, export uint16) {
n
.
nodeInfo
.
SetExternalAddr
(
exaddr
)
n
.
nodeInfo
.
SetExternalAddr
(
exaddr
)
n
.
nodeInfo
.
addrBook
.
AddOurAddress
(
exaddr
)
n
.
nodeInfo
.
addrBook
.
AddOurAddress
(
exaddr
)
}
}
if
listenAddr
,
err
:=
NewNetAddressString
(
fmt
.
Sprintf
(
"%v:%v"
,
LocalAddr
,
localport
));
err
==
nil
{
if
listenAddr
,
err
:=
NewNetAddressString
(
fmt
.
Sprintf
(
"%v:%v"
,
n
.
nodeInfo
.
GetListenAddr
()
.
IP
.
String
(),
localport
));
err
==
nil
{
n
.
nodeInfo
.
SetListenAddr
(
listenAddr
)
n
.
nodeInfo
.
SetListenAddr
(
listenAddr
)
n
.
nodeInfo
.
addrBook
.
AddOurAddress
(
listenAddr
)
n
.
nodeInfo
.
addrBook
.
AddOurAddress
(
listenAddr
)
}
}
...
@@ -354,9 +355,9 @@ func (n *Node) detectNodeAddr() {
...
@@ -354,9 +355,9 @@ func (n *Node) detectNodeAddr() {
for
{
for
{
cfg
:=
n
.
nodeInfo
.
cfg
cfg
:=
n
.
nodeInfo
.
cfg
laddr
:=
P2pComm
.
GetLocalAddr
()
laddr
:=
P2pComm
.
GetLocalAddr
()
LocalAddr
=
laddr
//
LocalAddr = laddr
log
.
Info
(
"DetectNodeAddr"
,
"addr:"
,
laddr
)
log
.
Info
(
"DetectNodeAddr"
,
"addr:"
,
laddr
)
if
l
en
(
LocalAddr
)
==
0
{
if
l
addr
==
""
{
log
.
Error
(
"DetectNodeAddr"
,
"NetWork Disable p2p Disable"
,
"Retry until Network enable"
)
log
.
Error
(
"DetectNodeAddr"
,
"NetWork Disable p2p Disable"
,
"Retry until Network enable"
)
time
.
Sleep
(
time
.
Second
*
5
)
time
.
Sleep
(
time
.
Second
*
5
)
continue
continue
...
...
vendor/github.com/33cn/chain33/p2p/p2p.go
View file @
f94e04d5
...
@@ -34,9 +34,10 @@ type P2p struct {
...
@@ -34,9 +34,10 @@ type P2p struct {
txFactory
chan
struct
{}
txFactory
chan
struct
{}
otherFactory
chan
struct
{}
otherFactory
chan
struct
{}
waitRestart
chan
struct
{}
waitRestart
chan
struct
{}
closed
int32
restart
int32
closed
int32
cfg
*
types
.
P2P
restart
int32
cfg
*
types
.
P2P
}
}
// New produce a p2p object
// New produce a p2p object
...
@@ -96,15 +97,15 @@ func (network *P2p) isRestart() bool {
...
@@ -96,15 +97,15 @@ func (network *P2p) isRestart() bool {
// Close network client
// Close network client
func
(
network
*
P2p
)
Close
()
{
func
(
network
*
P2p
)
Close
()
{
log
.
Info
(
"p2p network start shutdown"
)
atomic
.
StoreInt32
(
&
network
.
closed
,
1
)
atomic
.
StoreInt32
(
&
network
.
closed
,
1
)
log
.
Debug
(
"close"
,
"network"
,
"ShowTaskCapcity done"
)
network
.
node
.
Close
()
network
.
node
.
Close
()
log
.
Debug
(
"close"
,
"node"
,
"done"
)
if
network
.
client
!=
nil
{
if
network
.
client
!=
nil
{
if
!
network
.
isRestart
()
{
if
!
network
.
isRestart
()
{
network
.
client
.
Close
()
network
.
client
.
Close
()
}
}
}
}
network
.
node
.
pubsub
.
Shutdown
()
network
.
node
.
pubsub
.
Shutdown
()
...
@@ -126,25 +127,74 @@ func (network *P2p) SetQueueClient(cli queue.Client) {
...
@@ -126,25 +127,74 @@ func (network *P2p) SetQueueClient(cli queue.Client) {
go
func
(
p2p
*
P2p
)
{
go
func
(
p2p
*
P2p
)
{
p2p
.
node
.
Start
()
if
p2p
.
isRestart
()
{
if
p2p
.
isRestart
()
{
//reset
p2p
.
node
.
Start
()
atomic
.
StoreInt32
(
&
p2p
.
closed
,
0
)
atomic
.
StoreInt32
(
&
p2p
.
closed
,
0
)
atomic
.
StoreInt32
(
&
p2p
.
restart
,
0
)
atomic
.
StoreInt32
(
&
p2p
.
restart
,
0
)
network
.
waitRestart
<-
struct
{}{}
network
.
waitRestart
<-
struct
{}{}
return
}
p2p
.
subP2pMsg
()
key
,
pub
:=
p2p
.
node
.
nodeInfo
.
addrBook
.
GetPrivPubKey
()
log
.
Debug
(
"key pub:"
,
pub
,
""
)
if
key
==
""
{
if
p2p
.
cfg
.
WaitPid
{
//key为空,则为初始钱包,阻塞模式,一直等到钱包导入助记词,解锁
if
p2p
.
genAirDropKeyFromWallet
()
!=
nil
{
return
}
}
else
{
//创建随机Pid,会同时出现node award ,airdropaddr
p2p
.
node
.
nodeInfo
.
addrBook
.
ResetPeerkey
(
key
,
pub
)
go
p2p
.
genAirDropKeyFromWallet
()
}
}
else
{
}
else
{
p2p
.
subP2pMsg
()
//key 有两种可能,老版本的随机key,也有可能是seed的key, 非阻塞模式
go
p2p
.
loadP2PPrivKeyToWallet
()
go
p2p
.
genAirDropKeyFromWallet
()
go
p2p
.
genAirDropKeyFromWallet
()
}
}
p2p
.
node
.
Start
()
log
.
Debug
(
"SetQueueClient gorountine ret"
)
log
.
Debug
(
"SetQueueClient gorountine ret"
)
}(
network
)
}(
network
)
}
}
func
(
network
*
P2p
)
loadP2PPrivKeyToWallet
()
error
{
var
parm
types
.
ReqWalletImportPrivkey
parm
.
Privkey
,
_
=
network
.
node
.
nodeInfo
.
addrBook
.
GetPrivPubKey
()
parm
.
Label
=
"node award"
ReTry
:
msg
:=
network
.
client
.
NewMessage
(
"wallet"
,
types
.
EventWalletImportPrivkey
,
&
parm
)
err
:=
network
.
client
.
SendTimeout
(
msg
,
true
,
time
.
Minute
)
if
err
!=
nil
{
log
.
Error
(
"ImportPrivkey"
,
"Error"
,
err
.
Error
())
return
err
}
resp
,
err
:=
network
.
client
.
WaitTimeout
(
msg
,
time
.
Minute
)
if
err
!=
nil
{
if
err
==
types
.
ErrPrivkeyExist
{
return
nil
}
if
err
==
types
.
ErrLabelHasUsed
{
//切换随机lable
parm
.
Label
=
fmt
.
Sprintf
(
"node award %v"
,
P2pComm
.
RandStr
(
3
))
time
.
Sleep
(
time
.
Second
)
goto
ReTry
}
log
.
Error
(
"loadP2PPrivKeyToWallet"
,
"err"
,
err
.
Error
())
return
err
}
log
.
Debug
(
"loadP2PPrivKeyToWallet"
,
"resp"
,
resp
.
GetData
())
return
nil
}
func
(
network
*
P2p
)
showTaskCapcity
()
{
func
(
network
*
P2p
)
showTaskCapcity
()
{
ticker
:=
time
.
NewTicker
(
time
.
Second
*
5
)
ticker
:=
time
.
NewTicker
(
time
.
Second
*
5
)
log
.
Info
(
"ShowTaskCapcity"
,
"Capcity"
,
atomic
.
LoadInt32
(
&
network
.
txCapcity
))
log
.
Info
(
"ShowTaskCapcity"
,
"Capcity"
,
atomic
.
LoadInt32
(
&
network
.
txCapcity
))
...
@@ -160,10 +210,11 @@ func (network *P2p) showTaskCapcity() {
...
@@ -160,10 +210,11 @@ func (network *P2p) showTaskCapcity() {
}
}
func
(
network
*
P2p
)
genAirDropKeyFromWallet
()
error
{
func
(
network
*
P2p
)
genAirDropKeyFromWallet
()
error
{
_
,
savePub
:=
network
.
node
.
nodeInfo
.
addrBook
.
GetPrivPubKey
()
for
{
for
{
if
network
.
isClose
()
{
if
network
.
isClose
()
{
return
nil
log
.
Error
(
"genAirDropKeyFromWallet"
,
"p2p closed"
,
""
)
return
fmt
.
Errorf
(
"p2p closed"
)
}
}
msg
:=
network
.
client
.
NewMessage
(
"wallet"
,
types
.
EventGetWalletStatus
,
nil
)
msg
:=
network
.
client
.
NewMessage
(
"wallet"
,
types
.
EventGetWalletStatus
,
nil
)
err
:=
network
.
client
.
SendTimeout
(
msg
,
true
,
time
.
Minute
)
err
:=
network
.
client
.
SendTimeout
(
msg
,
true
,
time
.
Minute
)
...
@@ -179,12 +230,20 @@ func (network *P2p) genAirDropKeyFromWallet() error {
...
@@ -179,12 +230,20 @@ func (network *P2p) genAirDropKeyFromWallet() error {
continue
continue
}
}
if
resp
.
GetData
()
.
(
*
types
.
WalletStatus
)
.
GetIsWalletLock
()
{
//上锁
if
resp
.
GetData
()
.
(
*
types
.
WalletStatus
)
.
GetIsWalletLock
()
{
//上锁
if
savePub
==
""
{
log
.
Warn
(
"P2P Stuck ! Wallet must be unlock and save with mnemonics"
)
}
time
.
Sleep
(
time
.
Second
)
time
.
Sleep
(
time
.
Second
)
continue
continue
}
}
if
!
resp
.
GetData
()
.
(
*
types
.
WalletStatus
)
.
GetIsHasSeed
()
{
//无种子
if
!
resp
.
GetData
()
.
(
*
types
.
WalletStatus
)
.
GetIsHasSeed
()
{
//无种子
time
.
Sleep
(
time
.
Second
)
if
savePub
==
""
{
log
.
Warn
(
"P2P Stuck ! Wallet must be imported with mnemonics"
)
}
time
.
Sleep
(
time
.
Second
*
5
)
continue
continue
}
}
...
@@ -208,7 +267,6 @@ func (network *P2p) genAirDropKeyFromWallet() error {
...
@@ -208,7 +267,6 @@ func (network *P2p) genAirDropKeyFromWallet() error {
}
else
{
}
else
{
hexPrivkey
=
reply
.
GetData
()
hexPrivkey
=
reply
.
GetData
()
}
}
log
.
Info
(
"genAirDropKeyFromWallet"
,
"hexprivkey"
,
hexPrivkey
)
if
hexPrivkey
[
:
2
]
==
"0x"
{
if
hexPrivkey
[
:
2
]
==
"0x"
{
hexPrivkey
=
hexPrivkey
[
2
:
]
hexPrivkey
=
hexPrivkey
[
2
:
]
}
}
...
@@ -221,19 +279,30 @@ func (network *P2p) genAirDropKeyFromWallet() error {
...
@@ -221,19 +279,30 @@ func (network *P2p) genAirDropKeyFromWallet() error {
log
.
Info
(
"genAirDropKeyFromWallet"
,
"pubkey"
,
hexPubkey
)
log
.
Info
(
"genAirDropKeyFromWallet"
,
"pubkey"
,
hexPubkey
)
_
,
pub
:=
network
.
node
.
nodeInfo
.
addrBook
.
GetPrivPubKey
()
if
savePub
==
hexPubkey
{
if
pub
==
hexPubkey
{
return
nil
}
if
savePub
!=
""
{
//priv,pub是随机公私钥对,兼容老版本,先对其进行导入钱包处理
err
=
network
.
loadP2PPrivKeyToWallet
()
if
err
!=
nil
{
log
.
Error
(
"genAirDropKeyFromWallet"
,
"loadP2PPrivKeyToWallet error"
,
err
)
panic
(
err
)
}
network
.
node
.
nodeInfo
.
addrBook
.
ResetPeerkey
(
hexPrivkey
,
hexPubkey
)
//重启p2p模块
log
.
Info
(
"genAirDropKeyFromWallet"
,
"p2p will Restart...."
)
network
.
ReStart
()
return
nil
return
nil
}
}
//覆盖addrbook 中的公私钥对
//覆盖addrbook 中的公私钥对
network
.
node
.
nodeInfo
.
addrBook
.
ResetPeerkey
(
hexPrivkey
,
hexPubkey
)
network
.
node
.
nodeInfo
.
addrBook
.
ResetPeerkey
(
hexPrivkey
,
hexPubkey
)
//重启p2p模块
log
.
Info
(
"genAirDropKeyFromWallet"
,
"p2p will Restart...."
)
network
.
ReStart
()
return
nil
return
nil
}
}
//
ReStart p2p
//ReStart p2p
func
(
network
*
P2p
)
ReStart
()
{
func
(
network
*
P2p
)
ReStart
()
{
atomic
.
StoreInt32
(
&
network
.
restart
,
1
)
atomic
.
StoreInt32
(
&
network
.
restart
,
1
)
network
.
Close
()
network
.
Close
()
...
@@ -246,67 +315,6 @@ func (network *P2p) ReStart() {
...
@@ -246,67 +315,6 @@ func (network *P2p) ReStart() {
network
.
SetQueueClient
(
network
.
client
)
network
.
SetQueueClient
(
network
.
client
)
}
}
func
(
network
*
P2p
)
loadP2PPrivKeyToWallet
()
error
{
for
{
if
network
.
isClose
()
{
return
nil
}
msg
:=
network
.
client
.
NewMessage
(
"wallet"
,
types
.
EventGetWalletStatus
,
nil
)
err
:=
network
.
client
.
SendTimeout
(
msg
,
true
,
time
.
Minute
)
if
err
!=
nil
{
log
.
Error
(
"GetWalletStatus"
,
"Error"
,
err
.
Error
())
time
.
Sleep
(
time
.
Second
)
continue
}
resp
,
err
:=
network
.
client
.
WaitTimeout
(
msg
,
time
.
Minute
)
if
err
!=
nil
{
time
.
Sleep
(
time
.
Second
)
continue
}
if
resp
.
GetData
()
.
(
*
types
.
WalletStatus
)
.
GetIsWalletLock
()
{
//上锁
time
.
Sleep
(
time
.
Second
)
continue
}
if
!
resp
.
GetData
()
.
(
*
types
.
WalletStatus
)
.
GetIsHasSeed
()
{
//无种子
time
.
Sleep
(
time
.
Second
)
continue
}
break
}
var
parm
types
.
ReqWalletImportPrivkey
parm
.
Privkey
,
_
=
network
.
node
.
nodeInfo
.
addrBook
.
GetPrivPubKey
()
parm
.
Label
=
"node award"
ReTry
:
msg
:=
network
.
client
.
NewMessage
(
"wallet"
,
types
.
EventWalletImportPrivkey
,
&
parm
)
err
:=
network
.
client
.
SendTimeout
(
msg
,
true
,
time
.
Minute
)
if
err
!=
nil
{
log
.
Error
(
"ImportPrivkey"
,
"Error"
,
err
.
Error
())
return
err
}
resp
,
err
:=
network
.
client
.
WaitTimeout
(
msg
,
time
.
Minute
)
if
err
!=
nil
{
if
err
==
types
.
ErrPrivkeyExist
{
return
nil
}
if
err
==
types
.
ErrLabelHasUsed
{
//切换随机lable
parm
.
Label
=
fmt
.
Sprintf
(
"node award %v"
,
P2pComm
.
RandStr
(
3
))
time
.
Sleep
(
time
.
Second
)
goto
ReTry
}
log
.
Error
(
"loadP2PPrivKeyToWallet"
,
"err"
,
err
.
Error
())
return
err
}
log
.
Debug
(
"loadP2PPrivKeyToWallet"
,
"resp"
,
resp
.
GetData
())
return
nil
}
func
(
network
*
P2p
)
subP2pMsg
()
{
func
(
network
*
P2p
)
subP2pMsg
()
{
if
network
.
client
==
nil
{
if
network
.
client
==
nil
{
...
...
vendor/github.com/33cn/chain33/p2p/p2p_test.go
View file @
f94e04d5
...
@@ -2,6 +2,7 @@ package p2p
...
@@ -2,6 +2,7 @@ package p2p
import
(
import
(
"encoding/hex"
"encoding/hex"
//"fmt"
"net"
"net"
"os"
"os"
"sort"
"sort"
...
@@ -31,8 +32,6 @@ func init() {
...
@@ -31,8 +32,6 @@ func init() {
q
=
queue
.
New
(
"channel"
)
q
=
queue
.
New
(
"channel"
)
go
q
.
Start
()
go
q
.
Start
()
p2pModule
=
initP2p
(
33802
,
dataDir
)
p2pModule
.
Wait
()
go
func
()
{
go
func
()
{
cfg
,
sub
:=
types
.
InitCfg
(
"../cmd/chain33/chain33.test.toml"
)
cfg
,
sub
:=
types
.
InitCfg
(
"../cmd/chain33/chain33.test.toml"
)
...
@@ -115,6 +114,9 @@ func init() {
...
@@ -115,6 +114,9 @@ func init() {
}
}
}
}
}()
}()
time
.
Sleep
(
time
.
Second
)
p2pModule
=
initP2p
(
53802
,
dataDir
)
p2pModule
.
Wait
()
}
}
...
@@ -128,9 +130,14 @@ func initP2p(port int32, dbpath string) *P2p {
...
@@ -128,9 +130,14 @@ func initP2p(port int32, dbpath string) *P2p {
cfg
.
Version
=
119
cfg
.
Version
=
119
cfg
.
ServerStart
=
true
cfg
.
ServerStart
=
true
cfg
.
Driver
=
"leveldb"
cfg
.
Driver
=
"leveldb"
p2pcli
:=
New
(
cfg
)
p2pcli
:=
New
(
cfg
)
p2pcli
.
SetQueueClient
(
q
.
Client
())
p2pcli
.
node
.
nodeInfo
.
addrBook
.
initKey
()
privkey
,
_
:=
p2pcli
.
node
.
nodeInfo
.
addrBook
.
GetPrivPubKey
()
p2pcli
.
node
.
nodeInfo
.
addrBook
.
bookDb
.
Set
([]
byte
(
privKeyTag
),
[]
byte
(
privkey
))
p2pcli
.
node
.
nodeInfo
.
SetServiceTy
(
7
)
p2pcli
.
node
.
nodeInfo
.
SetServiceTy
(
7
)
p2pcli
.
SetQueueClient
(
q
.
Client
())
return
p2pcli
return
p2pcli
}
}
...
@@ -162,17 +169,19 @@ func TestNetInfo(t *testing.T) {
...
@@ -162,17 +169,19 @@ func TestNetInfo(t *testing.T) {
p2pModule
.
node
.
nodeInfo
.
SetNatDone
()
p2pModule
.
node
.
nodeInfo
.
SetNatDone
()
p2pModule
.
node
.
nodeInfo
.
Get
()
p2pModule
.
node
.
nodeInfo
.
Get
()
p2pModule
.
node
.
nodeInfo
.
Set
(
p2pModule
.
node
.
nodeInfo
)
p2pModule
.
node
.
nodeInfo
.
Set
(
p2pModule
.
node
.
nodeInfo
)
assert
.
NotNil
(
t
,
p2pModule
.
node
.
nodeInfo
.
GetListenAddr
())
assert
.
NotNil
(
t
,
p2pModule
.
node
.
nodeInfo
.
GetExternalAddr
())
}
}
//测试Peer
//测试Peer
func
TestPeer
(
t
*
testing
.
T
)
{
func
TestPeer
(
t
*
testing
.
T
)
{
conn
,
err
:=
grpc
.
Dial
(
"localhost:
3
3802"
,
grpc
.
WithInsecure
(),
conn
,
err
:=
grpc
.
Dial
(
"localhost:
5
3802"
,
grpc
.
WithInsecure
(),
grpc
.
WithDefaultCallOptions
(
grpc
.
UseCompressor
(
"gzip"
)))
grpc
.
WithDefaultCallOptions
(
grpc
.
UseCompressor
(
"gzip"
)))
assert
.
Nil
(
t
,
err
)
assert
.
Nil
(
t
,
err
)
defer
conn
.
Close
()
defer
conn
.
Close
()
remote
,
err
:=
NewNetAddressString
(
"127.0.0.1:
3
3802"
)
remote
,
err
:=
NewNetAddressString
(
"127.0.0.1:
5
3802"
)
assert
.
Nil
(
t
,
err
)
assert
.
Nil
(
t
,
err
)
localP2P
:=
initP2p
(
43802
,
"testdata2"
)
localP2P
:=
initP2p
(
43802
,
"testdata2"
)
...
@@ -219,7 +228,7 @@ func TestPeer(t *testing.T) {
...
@@ -219,7 +228,7 @@ func TestPeer(t *testing.T) {
_
,
err
=
p2pcli
.
SendVersion
(
peer
,
localP2P
.
node
.
nodeInfo
)
_
,
err
=
p2pcli
.
SendVersion
(
peer
,
localP2P
.
node
.
nodeInfo
)
assert
.
Nil
(
t
,
err
)
assert
.
Nil
(
t
,
err
)
t
.
Log
(
p2pcli
.
CheckPeerNatOk
(
"localhost:
3
3802"
))
t
.
Log
(
p2pcli
.
CheckPeerNatOk
(
"localhost:
5
3802"
))
t
.
Log
(
"checkself:"
,
p2pcli
.
CheckSelf
(
"loadhost:43803"
,
localP2P
.
node
.
nodeInfo
))
t
.
Log
(
"checkself:"
,
p2pcli
.
CheckSelf
(
"loadhost:43803"
,
localP2P
.
node
.
nodeInfo
))
_
,
err
=
p2pcli
.
GetAddr
(
peer
)
_
,
err
=
p2pcli
.
GetAddr
(
peer
)
assert
.
Nil
(
t
,
err
)
assert
.
Nil
(
t
,
err
)
...
@@ -230,7 +239,7 @@ func TestPeer(t *testing.T) {
...
@@ -230,7 +239,7 @@ func TestPeer(t *testing.T) {
height
,
err
:=
p2pcli
.
GetBlockHeight
(
localP2P
.
node
.
nodeInfo
)
height
,
err
:=
p2pcli
.
GetBlockHeight
(
localP2P
.
node
.
nodeInfo
)
assert
.
Nil
(
t
,
err
)
assert
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
int
(
height
),
2019
)
assert
.
Equal
(
t
,
int
(
height
),
2019
)
assert
.
Equal
(
t
,
false
,
p2pcli
.
CheckSelf
(
"localhost:
3
3802"
,
localP2P
.
node
.
nodeInfo
))
assert
.
Equal
(
t
,
false
,
p2pcli
.
CheckSelf
(
"localhost:
5
3802"
,
localP2P
.
node
.
nodeInfo
))
//测试下载
//测试下载
job
:=
NewDownloadJob
(
NewP2PCli
(
localP2P
)
.
(
*
Cli
),
[]
*
Peer
{
peer
})
job
:=
NewDownloadJob
(
NewP2PCli
(
localP2P
)
.
(
*
Cli
),
[]
*
Peer
{
peer
})
...
@@ -271,7 +280,7 @@ func TestGrpcConns(t *testing.T) {
...
@@ -271,7 +280,7 @@ func TestGrpcConns(t *testing.T) {
var
conns
[]
*
grpc
.
ClientConn
var
conns
[]
*
grpc
.
ClientConn
for
i
:=
0
;
i
<
maxSamIPNum
;
i
++
{
for
i
:=
0
;
i
<
maxSamIPNum
;
i
++
{
conn
,
err
:=
grpc
.
Dial
(
"localhost:
3
3802"
,
grpc
.
WithInsecure
(),
conn
,
err
:=
grpc
.
Dial
(
"localhost:
5
3802"
,
grpc
.
WithInsecure
(),
grpc
.
WithDefaultCallOptions
(
grpc
.
UseCompressor
(
"gzip"
)))
grpc
.
WithDefaultCallOptions
(
grpc
.
UseCompressor
(
"gzip"
)))
assert
.
Nil
(
t
,
err
)
assert
.
Nil
(
t
,
err
)
...
@@ -282,7 +291,7 @@ func TestGrpcConns(t *testing.T) {
...
@@ -282,7 +291,7 @@ func TestGrpcConns(t *testing.T) {
conns
=
append
(
conns
,
conn
)
conns
=
append
(
conns
,
conn
)
}
}
conn
,
err
:=
grpc
.
Dial
(
"localhost:
3
3802"
,
grpc
.
WithInsecure
(),
conn
,
err
:=
grpc
.
Dial
(
"localhost:
5
3802"
,
grpc
.
WithInsecure
(),
grpc
.
WithDefaultCallOptions
(
grpc
.
UseCompressor
(
"gzip"
)))
grpc
.
WithDefaultCallOptions
(
grpc
.
UseCompressor
(
"gzip"
)))
assert
.
Nil
(
t
,
err
)
assert
.
Nil
(
t
,
err
)
cli
:=
types
.
NewP2PgserviceClient
(
conn
)
cli
:=
types
.
NewP2PgserviceClient
(
conn
)
...
@@ -300,7 +309,7 @@ func TestGrpcConns(t *testing.T) {
...
@@ -300,7 +309,7 @@ func TestGrpcConns(t *testing.T) {
//测试grpc 流多连接
//测试grpc 流多连接
func
TestGrpcStreamConns
(
t
*
testing
.
T
)
{
func
TestGrpcStreamConns
(
t
*
testing
.
T
)
{
conn
,
err
:=
grpc
.
Dial
(
"localhost:
3
3802"
,
grpc
.
WithInsecure
(),
conn
,
err
:=
grpc
.
Dial
(
"localhost:
5
3802"
,
grpc
.
WithInsecure
(),
grpc
.
WithDefaultCallOptions
(
grpc
.
UseCompressor
(
"gzip"
)))
grpc
.
WithDefaultCallOptions
(
grpc
.
UseCompressor
(
"gzip"
)))
assert
.
Nil
(
t
,
err
)
assert
.
Nil
(
t
,
err
)
cli
:=
types
.
NewP2PgserviceClient
(
conn
)
cli
:=
types
.
NewP2PgserviceClient
(
conn
)
...
@@ -329,7 +338,7 @@ func TestGrpcStreamConns(t *testing.T) {
...
@@ -329,7 +338,7 @@ func TestGrpcStreamConns(t *testing.T) {
func
TestP2pComm
(
t
*
testing
.
T
)
{
func
TestP2pComm
(
t
*
testing
.
T
)
{
addrs
:=
P2pComm
.
AddrRouteble
([]
string
{
"localhost:
3
3802"
})
addrs
:=
P2pComm
.
AddrRouteble
([]
string
{
"localhost:
5
3802"
})
t
.
Log
(
addrs
)
t
.
Log
(
addrs
)
i32
:=
P2pComm
.
BytesToInt32
([]
byte
{
0xff
})
i32
:=
P2pComm
.
BytesToInt32
([]
byte
{
0xff
})
...
@@ -398,7 +407,13 @@ func TestAddrBook(t *testing.T) {
...
@@ -398,7 +407,13 @@ func TestAddrBook(t *testing.T) {
assert
.
Equal
(
t
,
addrBook
.
genPubkey
(
hex
.
EncodeToString
(
prv
)),
pubstr
)
assert
.
Equal
(
t
,
addrBook
.
genPubkey
(
hex
.
EncodeToString
(
prv
)),
pubstr
)
addrBook
.
Save
()
addrBook
.
Save
()
addrBook
.
GetAddrs
()
addrBook
.
GetAddrs
()
addrBook
.
ResetPeerkey
(
""
,
""
)
privkey
,
_
:=
addrBook
.
GetPrivPubKey
()
assert
.
NotEmpty
(
t
,
privkey
)
addrBook
.
ResetPeerkey
(
hex
.
EncodeToString
(
prv
),
pubstr
)
addrBook
.
ResetPeerkey
(
hex
.
EncodeToString
(
prv
),
pubstr
)
resetkey
,
_
:=
addrBook
.
GetPrivPubKey
()
assert
.
NotEqual
(
t
,
resetkey
,
privkey
)
}
}
func
TestBytesToInt32
(
t
*
testing
.
T
)
{
func
TestBytesToInt32
(
t
*
testing
.
T
)
{
...
...
vendor/github.com/33cn/chain33/p2p/p2pcli.go
View file @
f94e04d5
...
@@ -630,8 +630,8 @@ func (m *Cli) getLocalPeerInfo() (*pb.P2PPeerInfo, error) {
...
@@ -630,8 +630,8 @@ func (m *Cli) getLocalPeerInfo() (*pb.P2PPeerInfo, error) {
localpeerinfo
.
Name
=
pub
localpeerinfo
.
Name
=
pub
localpeerinfo
.
MempoolSize
=
int32
(
meminfo
.
GetSize
())
localpeerinfo
.
MempoolSize
=
int32
(
meminfo
.
GetSize
())
if
m
.
network
.
node
.
nodeInfo
.
GetExternalAddr
()
.
IP
==
nil
{
if
m
.
network
.
node
.
nodeInfo
.
GetExternalAddr
()
.
IP
==
nil
{
localpeerinfo
.
Addr
=
LocalAddr
localpeerinfo
.
Addr
=
m
.
network
.
node
.
nodeInfo
.
GetListenAddr
()
.
IP
.
String
()
localpeerinfo
.
Port
=
int32
(
m
.
network
.
node
.
listen
Port
)
localpeerinfo
.
Port
=
int32
(
m
.
network
.
node
.
nodeInfo
.
GetListenAddr
()
.
Port
)
}
else
{
}
else
{
localpeerinfo
.
Addr
=
m
.
network
.
node
.
nodeInfo
.
GetExternalAddr
()
.
IP
.
String
()
localpeerinfo
.
Addr
=
m
.
network
.
node
.
nodeInfo
.
GetExternalAddr
()
.
IP
.
String
()
localpeerinfo
.
Port
=
int32
(
m
.
network
.
node
.
nodeInfo
.
GetExternalAddr
()
.
Port
)
localpeerinfo
.
Port
=
int32
(
m
.
network
.
node
.
nodeInfo
.
GetExternalAddr
()
.
Port
)
...
...
vendor/github.com/33cn/chain33/p2p/p2pserver.go
View file @
f94e04d5
...
@@ -574,7 +574,7 @@ func (s *P2pserver) ServerStreamRead(stream pb.P2Pgservice_ServerStreamReadServe
...
@@ -574,7 +574,7 @@ func (s *P2pserver) ServerStreamRead(stream pb.P2Pgservice_ServerStreamReadServe
if
s
.
node
.
Size
()
>
0
{
if
s
.
node
.
Size
()
>
0
{
if
remoteIP
!=
LocalAddr
&&
remoteIP
!=
s
.
node
.
nodeInfo
.
GetExternalAddr
()
.
IP
.
String
()
{
if
remoteIP
!=
s
.
node
.
nodeInfo
.
GetListenAddr
()
.
IP
.
String
()
&&
remoteIP
!=
s
.
node
.
nodeInfo
.
GetExternalAddr
()
.
IP
.
String
()
{
s
.
node
.
nodeInfo
.
SetServiceTy
(
Service
)
s
.
node
.
nodeInfo
.
SetServiceTy
(
Service
)
}
}
}
}
...
...
vendor/github.com/33cn/chain33/system/mempool/base.go
View file @
f94e04d5
...
@@ -281,6 +281,35 @@ func (mem *Mempool) RemoveTxsOfBlock(block *types.Block) bool {
...
@@ -281,6 +281,35 @@ func (mem *Mempool) RemoveTxsOfBlock(block *types.Block) bool {
return
true
return
true
}
}
// GetProperFeeRate 获取合适的手续费率
func
(
mem
*
Mempool
)
GetProperFeeRate
()
int64
{
baseFeeRate
:=
mem
.
cache
.
GetProperFee
()
if
mem
.
cfg
.
IsLevelFee
{
return
mem
.
getLevelFeeRate
(
baseFeeRate
)
}
return
baseFeeRate
}
// getLevelFeeRate 获取合适的阶梯手续费率
func
(
mem
*
Mempool
)
getLevelFeeRate
(
baseFeeRate
int64
)
int64
{
var
feeRate
int64
sumByte
:=
mem
.
cache
.
TotalByte
()
maxTxNumber
:=
types
.
GetP
(
mem
.
Height
())
.
MaxTxNumber
switch
{
case
(
sumByte
>
int64
(
types
.
MaxBlockSize
/
100
)
&&
sumByte
<
int64
(
types
.
MaxBlockSize
/
20
))
||
(
int64
(
mem
.
Size
())
>=
maxTxNumber
/
10
&&
int64
(
mem
.
Size
())
<
maxTxNumber
/
2
)
:
feeRate
=
10
*
baseFeeRate
case
sumByte
>=
int64
(
types
.
MaxBlockSize
/
20
)
||
int64
(
mem
.
Size
())
>=
maxTxNumber
/
2
:
feeRate
=
100
*
baseFeeRate
default
:
return
baseFeeRate
}
if
feeRate
>
10000000
{
feeRate
=
10000000
}
return
feeRate
}
// Mempool.DelBlock将回退的区块内的交易重新加入mempool中
// Mempool.DelBlock将回退的区块内的交易重新加入mempool中
func
(
mem
*
Mempool
)
delBlock
(
block
*
types
.
Block
)
{
func
(
mem
*
Mempool
)
delBlock
(
block
*
types
.
Block
)
{
if
len
(
block
.
Txs
)
<=
0
{
if
len
(
block
.
Txs
)
<=
0
{
...
...
vendor/github.com/33cn/chain33/system/mempool/cache.go
View file @
f94e04d5
...
@@ -6,6 +6,7 @@ package mempool
...
@@ -6,6 +6,7 @@ package mempool
import
(
import
(
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/types"
"github.com/golang/protobuf/proto"
)
)
//QueueCache 排队交易处理
//QueueCache 排队交易处理
...
@@ -30,7 +31,9 @@ type Item struct {
...
@@ -30,7 +31,9 @@ type Item struct {
type
txCache
struct
{
type
txCache
struct
{
*
AccountTxIndex
*
AccountTxIndex
*
LastTxCache
*
LastTxCache
qcache
QueueCache
qcache
QueueCache
totalFee
int64
totalByte
int64
}
}
//NewTxCache init accountIndex and last cache
//NewTxCache init accountIndex and last cache
...
@@ -59,6 +62,8 @@ func (cache *txCache) Remove(hash string) {
...
@@ -59,6 +62,8 @@ func (cache *txCache) Remove(hash string) {
}
}
cache
.
AccountTxIndex
.
Remove
(
tx
)
cache
.
AccountTxIndex
.
Remove
(
tx
)
cache
.
LastTxCache
.
Remove
(
tx
)
cache
.
LastTxCache
.
Remove
(
tx
)
cache
.
totalFee
-=
tx
.
Fee
cache
.
totalByte
-=
int64
(
proto
.
Size
(
tx
))
}
}
//Exist 是否存在
//Exist 是否存在
...
@@ -69,6 +74,14 @@ func (cache *txCache) Exist(hash string) bool {
...
@@ -69,6 +74,14 @@ func (cache *txCache) Exist(hash string) bool {
return
cache
.
qcache
.
Exist
(
hash
)
return
cache
.
qcache
.
Exist
(
hash
)
}
}
//GetProperFee 获取合适手续费
func
(
cache
*
txCache
)
GetProperFee
()
int64
{
if
cache
.
qcache
==
nil
{
return
0
}
return
cache
.
qcache
.
GetProperFee
()
}
//Size cache tx num
//Size cache tx num
func
(
cache
*
txCache
)
Size
()
int
{
func
(
cache
*
txCache
)
Size
()
int
{
if
cache
.
qcache
==
nil
{
if
cache
.
qcache
==
nil
{
...
@@ -77,6 +90,16 @@ func (cache *txCache) Size() int {
...
@@ -77,6 +90,16 @@ func (cache *txCache) Size() int {
return
cache
.
qcache
.
Size
()
return
cache
.
qcache
.
Size
()
}
}
//TotalFee 手续费总和
func
(
cache
*
txCache
)
TotalFee
()
int64
{
return
cache
.
totalFee
}
//TotalByte 交易字节数总和
func
(
cache
*
txCache
)
TotalByte
()
int64
{
return
cache
.
totalByte
}
//Walk iter all txs
//Walk iter all txs
func
(
cache
*
txCache
)
Walk
(
count
int
,
cb
func
(
tx
*
Item
)
bool
)
{
func
(
cache
*
txCache
)
Walk
(
count
int
,
cb
func
(
tx
*
Item
)
bool
)
{
if
cache
.
qcache
==
nil
{
if
cache
.
qcache
==
nil
{
...
@@ -107,6 +130,8 @@ func (cache *txCache) Push(tx *types.Transaction) error {
...
@@ -107,6 +130,8 @@ func (cache *txCache) Push(tx *types.Transaction) error {
return
err
return
err
}
}
cache
.
LastTxCache
.
Push
(
tx
)
cache
.
LastTxCache
.
Push
(
tx
)
cache
.
totalFee
+=
tx
.
Fee
cache
.
totalByte
+=
int64
(
proto
.
Size
(
tx
))
return
nil
return
nil
}
}
...
...
vendor/github.com/33cn/chain33/system/mempool/check.go
View file @
f94e04d5
...
@@ -92,6 +92,13 @@ func (mem *Mempool) checkTxs(msg *queue.Message) *queue.Message {
...
@@ -92,6 +92,13 @@ func (mem *Mempool) checkTxs(msg *queue.Message) *queue.Message {
msg
.
Data
=
err
msg
.
Data
=
err
return
msg
return
msg
}
}
if
mem
.
cfg
.
IsLevelFee
{
err
=
mem
.
checkLevelFee
(
tx
)
if
err
!=
nil
{
msg
.
Data
=
err
return
msg
}
}
//检查txgroup 中的每个交易
//检查txgroup 中的每个交易
txs
,
err
:=
tx
.
GetTxGroup
()
txs
,
err
:=
tx
.
GetTxGroup
()
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -114,7 +121,21 @@ func (mem *Mempool) checkTxs(msg *queue.Message) *queue.Message {
...
@@ -114,7 +121,21 @@ func (mem *Mempool) checkTxs(msg *queue.Message) *queue.Message {
return
msg
return
msg
}
}
//checkTxList 检查账户余额是否足够,并加入到Mempool,成功则传入goodChan,若加入Mempool失败则传入badChan
// checkLevelFee 检查阶梯手续费
func
(
mem
*
Mempool
)
checkLevelFee
(
tx
*
types
.
TransactionCache
)
error
{
//获取mempool里所有交易手续费总和
feeRate
:=
mem
.
GetProperFeeRate
()
totalfee
,
err
:=
tx
.
GetTotalFee
(
feeRate
)
if
err
!=
nil
{
return
err
}
if
tx
.
Fee
<
totalfee
{
return
types
.
ErrTxFeeTooLow
}
return
nil
}
//checkTxRemote 检查账户余额是否足够,并加入到Mempool,成功则传入goodChan,若加入Mempool失败则传入badChan
func
(
mem
*
Mempool
)
checkTxRemote
(
msg
*
queue
.
Message
)
*
queue
.
Message
{
func
(
mem
*
Mempool
)
checkTxRemote
(
msg
*
queue
.
Message
)
*
queue
.
Message
{
tx
:=
msg
.
GetData
()
.
(
types
.
TxGroup
)
tx
:=
msg
.
GetData
()
.
(
types
.
TxGroup
)
lastheader
:=
mem
.
GetHeader
()
lastheader
:=
mem
.
GetHeader
()
...
...
vendor/github.com/33cn/chain33/system/mempool/eventprocess.go
View file @
f94e04d5
...
@@ -189,9 +189,9 @@ func (mem *Mempool) eventGetAddrTxs(msg *queue.Message) {
...
@@ -189,9 +189,9 @@ func (mem *Mempool) eventGetAddrTxs(msg *queue.Message) {
msg
.
Reply
(
mem
.
client
.
NewMessage
(
""
,
types
.
EventReplyAddrTxs
,
txlist
))
msg
.
Reply
(
mem
.
client
.
NewMessage
(
""
,
types
.
EventReplyAddrTxs
,
txlist
))
}
}
// eventGetProperFee 获取排队策略中合适的手续费
// eventGetProperFee 获取排队策略中合适的手续费
率
func
(
mem
*
Mempool
)
eventGetProperFee
(
msg
*
queue
.
Message
)
{
func
(
mem
*
Mempool
)
eventGetProperFee
(
msg
*
queue
.
Message
)
{
properFee
:=
mem
.
cache
.
qcache
.
GetProperFe
e
()
properFee
:=
mem
.
GetProperFeeRat
e
()
msg
.
Reply
(
mem
.
client
.
NewMessage
(
"rpc"
,
types
.
EventReplyProperFee
,
msg
.
Reply
(
mem
.
client
.
NewMessage
(
"rpc"
,
types
.
EventReplyProperFee
,
&
types
.
ReplyProperFee
{
ProperFee
:
properFee
}))
&
types
.
ReplyProperFee
{
ProperFee
:
properFee
}))
}
}
...
...
vendor/github.com/33cn/chain33/system/mempool/mempool_test.go
View file @
f94e04d5
This diff is collapsed.
Click to expand it.
vendor/github.com/33cn/chain33/system/mempool/simplequeue.go
View file @
f94e04d5
...
@@ -58,6 +58,10 @@ func (cache *SimpleQueue) Push(tx *Item) error {
...
@@ -58,6 +58,10 @@ func (cache *SimpleQueue) Push(tx *Item) error {
// Remove 删除数据
// Remove 删除数据
func
(
cache
*
SimpleQueue
)
Remove
(
hash
string
)
error
{
func
(
cache
*
SimpleQueue
)
Remove
(
hash
string
)
error
{
_
,
err
:=
cache
.
GetItem
(
hash
)
if
err
!=
nil
{
return
err
}
cache
.
txList
.
Remove
(
hash
)
cache
.
txList
.
Remove
(
hash
)
return
nil
return
nil
}
}
...
...
vendor/github.com/33cn/chain33/system/mempool/testdata/chain33.test.toml
0 → 100644
View file @
f94e04d5
Title
=
"chain33"
TestNet
=
true
CoinSymbol
=
"bty"
[log]
# 日志级别,支持debug(dbug)/info/warn/error(eror)/crit
loglevel
=
"debug"
logConsoleLevel
=
"info"
# 日志文件名,可带目录,所有生成的日志文件都放到此目录下
logFile
=
"logs/chain33.log"
# 单个日志文件的最大值(单位:兆)
maxFileSize
=
20
# 最多保存的历史日志文件个数
maxBackups
=
20
# 最多保存的历史日志消息(单位:天)
maxAge
=
28
# 日志文件名是否使用本地事件(否则使用UTC时间)
localTime
=
true
# 历史日志文件是否压缩(压缩格式为gz)
compress
=
false
# 是否打印调用源文件和行号
callerFile
=
true
# 是否打印调用方法
callerFunction
=
true
[blockchain]
defCacheSize
=
128
maxFetchBlockNum
=
128
timeoutSeconds
=
5
batchBlockNum
=
128
driver
=
"memdb"
dbPath
=
"datadir"
dbCache
=
64
isStrongConsistency
=
true
singleMode
=
true
batchsync
=
false
isRecordBlockSequence
=
true
isParaChain
=
false
enableTxQuickIndex
=
false
[p2p]
port
=
13802
seeds
=
["47.104.125.151:13802","47.104.125.97:13802","47.104.125.177:13802"]
enable
=
true
isSeed
=
true
serverStart
=
true
msgCacheSize
=
10240
driver
=
"memdb"
dbPath
=
"datadir/addrbook"
dbCache
=
4
grpcLogFile
=
"grpc33.log"
version
=
216
verMix
=
216
verMax
=
217
[rpc]
jrpcBindAddr
=
"localhost:8801"
grpcBindAddr
=
"localhost:8802"
whitelist
=
["127.0.0.1"]
jrpcFuncWhitelist
=
["*"]
grpcFuncWhitelist
=
["*"]
enableTLS
=
false
certFile
=
"cert.pem"
keyFile
=
"key.pem"
[mempool]
name
=
"timeline"
poolCacheSize
=
10240
minTxFee
=
100000
maxTxNumPerAccount
=
100
isLevelFee
=
false
[mempool.sub.timeline]
poolCacheSize
=
10240
[mempool.sub.score]
poolCacheSize
=
10240
timeParam
=
1
#时间占价格比例
priceConstant
=
1544
#手续费相对于时间的一个合适的常量,取当前unxi时间戳前四位数,排序时手续费高1e-5~=快1s
pricePower
=
1
#常量比例
[mempool.sub.price]
poolCacheSize
=
10240
[consensus]
name
=
"solo"
minerstart
=
true
genesisBlockTime
=
1514533394
genesis
=
"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
[mver.consensus]
fundKeyAddr
=
"1BQXS6TxaYYG5mADaWij4AxhZZUTpw95a5"
coinReward
=
18
coinDevFund
=
12
ticketPrice
=
10000
powLimitBits
=
"0x1f00ffff"
retargetAdjustmentFactor
=
4
futureBlockTime
=
16
ticketFrozenTime
=
5
#5s only for test
ticketWithdrawTime
=
10
#10s only for test
ticketMinerWaitTime
=
2
#2s only for test
maxTxNumber
=
4
#160
targetTimespan
=
2304
targetTimePerBlock
=
16
[mver.consensus.ForkChainParamV1]
maxTxNumber
=
10000
targetTimespan
=
288
#only for test
targetTimePerBlock
=
2
[mver.consensus.ForkChainParamV2]
powLimitBits
=
"0x1f2fffff"
[consensus.sub.solo]
genesis
=
"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
genesisBlockTime
=
1514533394
hotkeyAddr
=
"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
waitTxMs
=
10
[consensus.sub.ticket]
genesisBlockTime
=
1514533394
[[consensus.sub.ticket.genesis]]
minerAddr
=
"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
returnAddr
=
"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
count
=
10000
[[consensus.sub.ticket.genesis]]
minerAddr
=
"1PUiGcbsccfxW3zuvHXZBJfznziph5miAo"
returnAddr
=
"1EbDHAXpoiewjPLX9uqoz38HsKqMXayZrF"
count
=
10000
[[consensus.sub.ticket.genesis]]
minerAddr
=
"1EDnnePAZN48aC2hiTDzhkczfF39g1pZZX"
returnAddr
=
"1KcCVZLSQYRUwE5EXTsAoQs9LuJW6xwfQa"
count
=
10000
[store]
name
=
"mavl"
driver
=
"memdb"
dbPath
=
"datadir/mavltree"
dbCache
=
128
[store.sub.mavl]
enableMavlPrefix
=
false
enableMVCC
=
false
enableMavlPrune
=
false
pruneHeight
=
10000
# 是否使能mavl数据载入内存
enableMemTree
=
false
# 是否使能mavl叶子节点数据载入内存
enableMemVal
=
false
[wallet]
minFee
=
1000000
driver
=
"memdb"
dbPath
=
"datadir/wallet"
dbCache
=
16
signType
=
"secp256k1"
[wallet.sub.ticket]
minerwhitelist
=
["*"]
[exec]
isFree
=
false
minExecFee
=
100000
maxExecFee
=
1000000000
enableStat
=
false
enableMVCC
=
false
[exec.sub.token]
saveTokenTxList
=
true
tokenApprs
=
[
"1Bsg9j6gW83sShoee1fZAt9TkUjcrCgA9S"
,
"1Q8hGLfoGe63efeWa8fJ4Pnukhkngt6poK"
,
"1LY8GFia5EiyoTodMLfkB5PHNNpXRqxhyB"
,
"1GCzJDS6HbgTQ2emade7mEJGGWFfA15pS9"
,
"1JYB8sxi4He5pZWHCd3Zi2nypQ4JMB6AxN"
,
"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
,
]
[exec.sub.relay]
genesis
=
"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
[exec.sub.cert]
# 是否启用证书验证和签名
enable
=
false
# 加密文件路径
cryptoPath
=
"authdir/crypto"
# 带证书签名类型,支持"auth_ecdsa", "auth_sm2"
signType
=
"auth_ecdsa"
[exec.sub.manage]
superManager
=[
"1Bsg9j6gW83sShoee1fZAt9TkUjcrCgA9S"
,
"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
,
"1Q8hGLfoGe63efeWa8fJ4Pnukhkngt6poK"
]
[health]
listenAddr
=
"localhost:8805"
checkInterval
=
1
unSyncMaxTimes
=
2
vendor/github.com/33cn/chain33/types/cfg.go
View file @
f94e04d5
...
@@ -68,6 +68,7 @@ type Mempool struct {
...
@@ -68,6 +68,7 @@ type Mempool struct {
// 每个账户在mempool中得最大交易数量,默认100
// 每个账户在mempool中得最大交易数量,默认100
MaxTxNumPerAccount
int64
`protobuf:"varint,5,opt,name=maxTxNumPerAccount" json:"maxTxNumPerAccount,omitempty"`
MaxTxNumPerAccount
int64
`protobuf:"varint,5,opt,name=maxTxNumPerAccount" json:"maxTxNumPerAccount,omitempty"`
MaxTxLast
int64
`protobuf:"varint,6,opt,name=maxTxLast" json:"maxTxLast,omitempty"`
MaxTxLast
int64
`protobuf:"varint,6,opt,name=maxTxLast" json:"maxTxLast,omitempty"`
IsLevelFee
bool
`protobuf:"varint,7,opt,name=isLevelFee" json:"isLevelFee,omitempty"`
}
}
// Consensus 配置
// Consensus 配置
...
@@ -176,6 +177,8 @@ type P2P struct {
...
@@ -176,6 +177,8 @@ type P2P struct {
InnerBounds
int32
`protobuf:"varint,15,opt,name=innerBounds" json:"innerBounds,omitempty"`
InnerBounds
int32
`protobuf:"varint,15,opt,name=innerBounds" json:"innerBounds,omitempty"`
// 是否使用Github获取种子节点
// 是否使用Github获取种子节点
UseGithub
bool
`protobuf:"varint,16,opt,name=useGithub" json:"useGithub,omitempty"`
UseGithub
bool
`protobuf:"varint,16,opt,name=useGithub" json:"useGithub,omitempty"`
//是否等待Pid
WaitPid
bool
`protobuf:"varint,17,opt,name=waitPid" json:"waitPid,omitempty"`
}
}
// RPC 配置
// RPC 配置
...
...
vendor/github.com/33cn/chain33/types/config.go
View file @
f94e04d5
...
@@ -286,6 +286,12 @@ func Init(t string, cfg *Config) {
...
@@ -286,6 +286,12 @@ func Init(t string, cfg *Config) {
panic
(
"config CoinSymbol must without '-'"
)
panic
(
"config CoinSymbol must without '-'"
)
}
}
coinSymbol
=
cfg
.
CoinSymbol
coinSymbol
=
cfg
.
CoinSymbol
}
else
{
if
isPara
()
{
panic
(
"must config CoinSymbol in para chain"
)
}
else
{
coinSymbol
=
DefaultCoinsSymbol
}
}
}
}
}
//local 只用于单元测试
//local 只用于单元测试
...
...
vendor/github.com/33cn/chain33/types/const.go
View file @
f94e04d5
...
@@ -33,6 +33,11 @@ const (
...
@@ -33,6 +33,11 @@ const (
NoneX
=
"none"
NoneX
=
"none"
)
)
//DefaultCoinsSymbol 默认的主币名称
const
(
DefaultCoinsSymbol
=
"bty"
)
//UserKeyX 用户自定义执行器前缀byte类型
//UserKeyX 用户自定义执行器前缀byte类型
var
(
var
(
UserKey
=
[]
byte
(
UserKeyX
)
UserKey
=
[]
byte
(
UserKeyX
)
...
...
vendor/github.com/33cn/chain33/types/testdata/guodun.toml
View file @
f94e04d5
...
@@ -2,6 +2,7 @@ Title="user.p.guodun."
...
@@ -2,6 +2,7 @@ Title="user.p.guodun."
TestNet
=
false
TestNet
=
false
FixTime
=
false
FixTime
=
false
EnableParaFork
=
true
EnableParaFork
=
true
CoinSymbol
=
"gd"
[log]
[log]
# 日志级别,支持debug(dbug)/info/warn/error(eror)/crit
# 日志级别,支持debug(dbug)/info/warn/error(eror)/crit
...
...
vendor/github.com/33cn/chain33/types/testdata/guodun2.toml
View file @
f94e04d5
...
@@ -2,6 +2,7 @@ Title="user.p.guodun2."
...
@@ -2,6 +2,7 @@ Title="user.p.guodun2."
TestNet
=
false
TestNet
=
false
FixTime
=
false
FixTime
=
false
EnableParaFork
=
false
EnableParaFork
=
false
CoinSymbol
=
"gd2"
[log]
[log]
# 日志级别,支持debug(dbug)/info/warn/error(eror)/crit
# 日志级别,支持debug(dbug)/info/warn/error(eror)/crit
...
...
vendor/github.com/33cn/chain33/types/tx.go
View file @
f94e04d5
...
@@ -348,6 +348,28 @@ func (tx *TransactionCache) Check(height, minfee, maxFee int64) error {
...
@@ -348,6 +348,28 @@ func (tx *TransactionCache) Check(height, minfee, maxFee int64) error {
return
tx
.
checkok
return
tx
.
checkok
}
}
//GetTotalFee 获取交易真实费用
func
(
tx
*
TransactionCache
)
GetTotalFee
(
minFee
int64
)
(
int64
,
error
)
{
txgroup
,
err
:=
tx
.
GetTxGroup
()
if
err
!=
nil
{
tx
.
checkok
=
err
return
0
,
err
}
var
totalfee
int64
if
txgroup
==
nil
{
return
tx
.
GetRealFee
(
minFee
)
}
txs
:=
txgroup
.
Txs
for
i
:=
0
;
i
<
len
(
txs
);
i
++
{
fee
,
err
:=
txs
[
i
]
.
GetRealFee
(
minFee
)
if
err
!=
nil
{
return
0
,
err
}
totalfee
+=
fee
}
return
totalfee
,
nil
}
//GetTxGroup 获取交易组
//GetTxGroup 获取交易组
func
(
tx
*
TransactionCache
)
GetTxGroup
()
(
*
Transactions
,
error
)
{
func
(
tx
*
TransactionCache
)
GetTxGroup
()
(
*
Transactions
,
error
)
{
var
err
error
var
err
error
...
...
vendor/github.com/33cn/chain33/util/cli/chain33.go
View file @
f94e04d5
...
@@ -49,6 +49,7 @@ var (
...
@@ -49,6 +49,7 @@ var (
datadir
=
flag
.
String
(
"datadir"
,
""
,
"data dir of chain33, include logs and datas"
)
datadir
=
flag
.
String
(
"datadir"
,
""
,
"data dir of chain33, include logs and datas"
)
versionCmd
=
flag
.
Bool
(
"v"
,
false
,
"version"
)
versionCmd
=
flag
.
Bool
(
"v"
,
false
,
"version"
)
fixtime
=
flag
.
Bool
(
"fixtime"
,
false
,
"fix time"
)
fixtime
=
flag
.
Bool
(
"fixtime"
,
false
,
"fix time"
)
waitPid
=
flag
.
Bool
(
"waitpid"
,
false
,
"p2p stuck until seed save info wallet & wallet unlock"
)
)
)
//RunChain33 : run Chain33
//RunChain33 : run Chain33
...
@@ -91,6 +92,9 @@ func RunChain33(name string) {
...
@@ -91,6 +92,9 @@ func RunChain33(name string) {
if
*
fixtime
{
if
*
fixtime
{
cfg
.
FixTime
=
*
fixtime
cfg
.
FixTime
=
*
fixtime
}
}
if
*
waitPid
{
cfg
.
P2P
.
WaitPid
=
*
waitPid
}
//set test net flag
//set test net flag
types
.
Init
(
cfg
.
Title
,
cfg
)
types
.
Init
(
cfg
.
Title
,
cfg
)
if
cfg
.
FixTime
{
if
cfg
.
FixTime
{
...
...
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