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
1310ccf2
Commit
1310ccf2
authored
Feb 25, 2021
by
caopingcp
Committed by
vipwzw
Mar 08, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tendermint check new tx
parent
7d55e0d5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
188 additions
and
32 deletions
+188
-32
tendermint.go
plugin/consensus/tendermint/tendermint.go
+5
-23
nonePerf.go
plugin/consensus/tendermint/tools/nonePerf.go
+183
-9
No files found.
plugin/consensus/tendermint/tendermint.go
View file @
1310ccf2
...
@@ -442,11 +442,13 @@ func (client *Client) CreateBlock() {
...
@@ -442,11 +442,13 @@ func (client *Client) CreateBlock() {
continue
continue
}
}
if
!
client
.
CheckTxsAvailable
(
height
)
{
if
!
client
.
CheckTxsAvailable
(
height
)
{
time
.
Sleep
(
5
00
*
time
.
Millisecond
)
time
.
Sleep
(
10
00
*
time
.
Millisecond
)
continue
continue
}
}
client
.
txsAvailable
<-
height
+
1
if
height
+
1
==
client
.
csState
.
GetRoundState
()
.
Height
{
client
.
txsAvailable
<-
height
+
1
}
time
.
Sleep
(
time
.
Duration
(
timeoutTxAvail
)
*
time
.
Millisecond
)
time
.
Sleep
(
time
.
Duration
(
timeoutTxAvail
)
*
time
.
Millisecond
)
}
}
}
}
...
@@ -469,29 +471,9 @@ func (client *Client) StopC() <-chan struct{} {
...
@@ -469,29 +471,9 @@ func (client *Client) StopC() <-chan struct{} {
return
client
.
stopC
return
client
.
stopC
}
}
// GetMempoolSize get tx num in mempool
func
(
client
*
Client
)
GetMempoolSize
()
int64
{
msg
:=
client
.
GetQueueClient
()
.
NewMessage
(
"mempool"
,
types
.
EventGetMempoolSize
,
nil
)
err
:=
client
.
GetQueueClient
()
.
Send
(
msg
,
true
)
if
err
!=
nil
{
tendermintlog
.
Error
(
"GetMempoolSize send"
,
"err"
,
err
)
return
0
}
resp
,
err
:=
client
.
GetQueueClient
()
.
Wait
(
msg
)
if
err
!=
nil
{
tendermintlog
.
Error
(
"GetMempoolSize result"
,
"err"
,
err
)
return
0
}
return
resp
.
GetData
()
.
(
*
types
.
MempoolSize
)
.
GetSize
()
}
// CheckTxsAvailable check whether some new transactions arriving
// CheckTxsAvailable check whether some new transactions arriving
func
(
client
*
Client
)
CheckTxsAvailable
(
height
int64
)
bool
{
func
(
client
*
Client
)
CheckTxsAvailable
(
height
int64
)
bool
{
num
:=
client
.
GetMempoolSize
()
txs
:=
client
.
RequestTx
(
1
,
nil
)
if
num
==
0
{
return
false
}
txs
:=
client
.
RequestTx
(
int
(
num
),
nil
)
txs
=
client
.
CheckTxDup
(
txs
,
height
)
txs
=
client
.
CheckTxDup
(
txs
,
height
)
return
len
(
txs
)
!=
0
return
len
(
txs
)
!=
0
}
}
...
...
plugin/consensus/tendermint/tools/nonePerf.go
View file @
1310ccf2
...
@@ -6,6 +6,7 @@ package main
...
@@ -6,6 +6,7 @@ package main
import
(
import
(
"bytes"
"bytes"
"context"
"encoding/hex"
"encoding/hex"
"encoding/json"
"encoding/json"
"errors"
"errors"
...
@@ -14,19 +15,26 @@ import (
...
@@ -14,19 +15,26 @@ import (
"math/rand"
"math/rand"
"net/http"
"net/http"
"os"
"os"
"runtime"
"strconv"
"strconv"
"strings"
"sync"
"sync/atomic"
"time"
"time"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/common/crypto"
"github.com/33cn/chain33/common/crypto"
"github.com/33cn/chain33/common/log/log15"
rpctypes
"github.com/33cn/chain33/rpc/types"
rpctypes
"github.com/33cn/chain33/rpc/types"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/types"
ty
"github.com/33cn/plugin/plugin/dapp/valnode/types"
ty
"github.com/33cn/plugin/plugin/dapp/valnode/types"
"google.golang.org/grpc"
_
"google.golang.org/grpc/encoding/gzip"
)
)
const
fee
=
1e6
const
fee
=
1e6
const
letterBytes
=
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
const
letterBytes
=
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
123456789-=_+=/<>!@#$%^&
"
var
r
*
rand
.
Rand
var
r
*
rand
.
Rand
...
@@ -68,20 +76,186 @@ func main() {
...
@@ -68,20 +76,186 @@ func main() {
return
return
}
}
ValNode
(
argsWithoutProg
[
1
],
argsWithoutProg
[
2
],
argsWithoutProg
[
3
])
ValNode
(
argsWithoutProg
[
1
],
argsWithoutProg
[
2
],
argsWithoutProg
[
3
])
case
"perfOld"
:
if
len
(
argsWithoutProg
)
!=
6
{
fmt
.
Print
(
errors
.
New
(
"参数错误"
)
.
Error
())
return
}
PerfOld
(
argsWithoutProg
[
1
],
argsWithoutProg
[
2
],
argsWithoutProg
[
3
],
argsWithoutProg
[
4
],
argsWithoutProg
[
5
])
}
}
}
}
// LoadHelp ...
// LoadHelp ...
func
LoadHelp
()
{
func
LoadHelp
()
{
fmt
.
Println
(
"Available Commands:"
)
fmt
.
Println
(
"Available Commands:"
)
fmt
.
Println
(
"perf [
ip, size, num, interval, duration] : 写数据性能测试
"
)
fmt
.
Println
(
"perf [
host, size, num, interval, duration] : 写数据性能测试,interval单位为100毫秒,host形式为ip:port
"
)
fmt
.
Println
(
"put [ip, size] : 写数据"
)
fmt
.
Println
(
"put [ip, size] : 写数据"
)
fmt
.
Println
(
"get [ip, hash] : 读数据"
)
fmt
.
Println
(
"get [ip, hash] : 读数据"
)
fmt
.
Println
(
"valnode [ip, pubkey, power] : 增加/删除/修改tendermint节点"
)
fmt
.
Println
(
"valnode [ip, pubkey, power] : 增加/删除/修改tendermint节点"
)
fmt
.
Println
(
"perfOld [ip, size, num, interval, duration] : 不推荐使用,写数据性能测试,interval单位为100毫秒"
)
}
// Perf 性能测试
func
Perf
(
host
,
txsize
,
num
,
sleepinterval
,
totalduration
string
)
{
var
numThread
int
numInt
,
err
:=
strconv
.
Atoi
(
num
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
err
)
return
}
sleep
,
err
:=
strconv
.
Atoi
(
sleepinterval
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
err
)
return
}
durInt
,
err
:=
strconv
.
Atoi
(
totalduration
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
err
)
return
}
sizeInt
,
_
:=
strconv
.
Atoi
(
txsize
)
if
numInt
<
10
{
numThread
=
1
}
else
if
numInt
>
100
{
numThread
=
10
}
else
{
numThread
=
numInt
/
10
}
numThread
=
runtime
.
NumCPU
()
ch
:=
make
(
chan
struct
{},
numThread
)
chSend
:=
make
(
chan
struct
{},
numThread
*
2
)
txChan
:=
make
(
chan
*
types
.
Transaction
,
numInt
)
//payload := RandStringBytes(sizeInt)
var
blockHeight
int64
total
:=
int64
(
0
)
success
:=
int64
(
0
)
go
func
()
{
ch
<-
struct
{}{}
conn
:=
newGrpcConn
(
host
)
defer
conn
.
Close
()
gcli
:=
types
.
NewChain33Client
(
conn
)
for
{
height
,
err
:=
getHeight
(
gcli
)
if
err
!=
nil
{
//conn.Close()
log
.
Error
(
"getHeight"
,
"err"
,
err
)
//conn = newGrpcConn(ip)
//gcli = types.NewChain33Client(conn)
time
.
Sleep
(
time
.
Second
)
}
else
{
atomic
.
StoreInt64
(
&
blockHeight
,
height
)
}
time
.
Sleep
(
time
.
Millisecond
*
500
)
}
}()
<-
ch
for
i
:=
0
;
i
<
numThread
;
i
++
{
go
func
()
{
_
,
priv
:=
genaddress
()
for
sec
:=
0
;
durInt
==
0
||
sec
<
durInt
;
sec
++
{
height
:=
atomic
.
LoadInt64
(
&
blockHeight
)
for
txs
:=
0
;
txs
<
numInt
/
numThread
;
txs
++
{
//构造存证交易
tx
:=
txPool
.
Get
()
.
(
*
types
.
Transaction
)
tx
.
To
=
execAddr
tx
.
Fee
=
rand
.
Int63
()
tx
.
Nonce
=
time
.
Now
()
.
UnixNano
()
tx
.
Expire
=
height
+
types
.
TxHeightFlag
+
types
.
LowAllowPackHeight
tx
.
Payload
=
RandStringBytes
(
sizeInt
)
//交易签名
tx
.
Sign
(
types
.
SECP256K1
,
priv
)
txChan
<-
tx
}
if
sleep
>
0
{
time
.
Sleep
(
100
*
time
.
Millisecond
*
time
.
Duration
(
sleep
))
}
}
ch
<-
struct
{}{}
}()
}
for
i
:=
0
;
i
<
numThread
*
2
;
i
++
{
go
func
()
{
conn
:=
newGrpcConn
(
host
)
defer
conn
.
Close
()
gcli
:=
types
.
NewChain33Client
(
conn
)
for
tx
:=
range
txChan
{
//发送交易
_
,
err
:=
gcli
.
SendTransaction
(
context
.
Background
(),
tx
,
grpc
.
UseCompressor
(
"gzip"
))
txPool
.
Put
(
tx
)
atomic
.
AddInt64
(
&
total
,
1
)
if
err
!=
nil
{
if
strings
.
Contains
(
err
.
Error
(),
"ErrTxExpire"
)
{
continue
}
if
strings
.
Contains
(
err
.
Error
(),
"ErrMemFull"
)
{
time
.
Sleep
(
time
.
Second
)
continue
}
log
.
Error
(
"sendtx"
,
"err"
,
err
)
time
.
Sleep
(
time
.
Second
)
//conn.Close()
//conn = newGrpcConn(ip)
//gcli = types.NewChain33Client(conn)
}
else
{
atomic
.
AddInt64
(
&
success
,
1
)
}
}
chSend
<-
struct
{}{}
}()
}
for
j
:=
0
;
j
<
numThread
;
j
++
{
<-
ch
}
close
(
txChan
)
for
k
:=
0
;
k
<
numThread
*
2
;
k
++
{
<-
chSend
}
//打印发送的交易总数
log
.
Info
(
"sendtx total tx"
,
"total"
,
total
)
//打印成功发送的交易总数
log
.
Info
(
"sendtx success tx"
,
"success"
,
success
)
}
var
(
log
=
log15
.
New
()
execAddr
=
address
.
ExecAddress
(
"user.write"
)
)
func
getHeight
(
gcli
types
.
Chain33Client
)
(
int64
,
error
)
{
header
,
err
:=
gcli
.
GetLastHeader
(
context
.
Background
(),
&
types
.
ReqNil
{})
if
err
!=
nil
{
log
.
Error
(
"getHeight"
,
"err"
,
err
)
return
0
,
err
}
return
header
.
Height
,
nil
}
var
txPool
=
sync
.
Pool
{
New
:
func
()
interface
{}
{
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
"user.write"
)}
return
tx
},
}
func
newGrpcConn
(
host
string
)
*
grpc
.
ClientConn
{
conn
,
err
:=
grpc
.
Dial
(
host
,
grpc
.
WithInsecure
())
for
err
!=
nil
{
log
.
Error
(
"grpc dial"
,
"err"
,
err
)
time
.
Sleep
(
time
.
Millisecond
*
100
)
conn
,
err
=
grpc
.
Dial
(
host
,
grpc
.
WithInsecure
())
}
return
conn
}
}
// Perf ...
// Perf
Old
...
func
Perf
(
ip
,
size
,
num
,
interval
,
duration
string
)
{
func
Perf
Old
(
ip
,
size
,
num
,
interval
,
duration
string
)
{
var
numThread
int
var
numThread
int
numInt
,
err
:=
strconv
.
Atoi
(
num
)
numInt
,
err
:=
strconv
.
Atoi
(
num
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -121,7 +295,7 @@ func Perf(ip, size, num, interval, duration string) {
...
@@ -121,7 +295,7 @@ func Perf(ip, size, num, interval, duration string) {
Put
(
ip
,
size
,
common
.
ToHex
(
priv
.
Bytes
()))
Put
(
ip
,
size
,
common
.
ToHex
(
priv
.
Bytes
()))
txCount
++
txCount
++
}
}
time
.
Sleep
(
time
.
S
econd
*
time
.
Duration
(
intervalInt
))
time
.
Sleep
(
100
*
time
.
Millis
econd
*
time
.
Duration
(
intervalInt
))
sec
+=
intervalInt
sec
+=
intervalInt
}
}
ch
<-
struct
{}{}
ch
<-
struct
{}{}
...
@@ -145,9 +319,9 @@ func Put(ip string, size string, privkey string) {
...
@@ -145,9 +319,9 @@ func Put(ip string, size string, privkey string) {
privkey
=
common
.
ToHex
(
priv
.
Bytes
())
privkey
=
common
.
ToHex
(
priv
.
Bytes
())
}
}
payload
:=
RandStringBytes
(
sizeInt
)
payload
:=
RandStringBytes
(
sizeInt
)
//fmt.Println("payload:", common.ToHex(
[]byte(payload)
))
//fmt.Println("payload:", common.ToHex(
payload
))
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
"user.write"
),
Payload
:
[]
byte
(
payload
)
,
Fee
:
1e6
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
"user.write"
),
Payload
:
payload
,
Fee
:
1e6
}
tx
.
To
=
address
.
ExecAddress
(
"user.write"
)
tx
.
To
=
address
.
ExecAddress
(
"user.write"
)
tx
.
Expire
=
TxHeightOffset
+
types
.
TxHeightFlag
tx
.
Expire
=
TxHeightOffset
+
types
.
TxHeightFlag
tx
.
Sign
(
types
.
SECP256K1
,
getprivkey
(
privkey
))
tx
.
Sign
(
types
.
SECP256K1
,
getprivkey
(
privkey
))
...
@@ -253,13 +427,13 @@ func genaddress() (string, crypto.PrivKey) {
...
@@ -253,13 +427,13 @@ func genaddress() (string, crypto.PrivKey) {
}
}
// RandStringBytes ...
// RandStringBytes ...
func
RandStringBytes
(
n
int
)
string
{
func
RandStringBytes
(
n
int
)
[]
byte
{
b
:=
make
([]
byte
,
n
)
b
:=
make
([]
byte
,
n
)
rand
.
Seed
(
time
.
Now
()
.
UnixNano
())
rand
.
Seed
(
time
.
Now
()
.
UnixNano
())
for
i
:=
range
b
{
for
i
:=
range
b
{
b
[
i
]
=
letterBytes
[
rand
.
Intn
(
len
(
letterBytes
))]
b
[
i
]
=
letterBytes
[
rand
.
Intn
(
len
(
letterBytes
))]
}
}
return
string
(
b
)
return
b
}
}
// ValNode ...
// ValNode ...
...
...
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