Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
ChainGrpcPro
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
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
duanjinfei
ChainGrpcPro
Commits
05d36acb
Commit
05d36acb
authored
Mar 10, 2023
by
duanjinfei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
batch get acc nonce
parent
bca8d77d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
19 deletions
+55
-19
startTest.go
startTest.go
+6
-1
signedTx.go
transaction/signedTx.go
+49
-18
No files found.
startTest.go
View file @
05d36acb
...
...
@@ -26,7 +26,12 @@ func startTest() {
cfg
.
GoRoutineCount
=
goRoutineCount
cfg
.
SignCount
=
txCount
/
100
cfg
.
BatchCount
=
batchCount
arr
:=
transaction
.
SignedTxArr
(
SendTxAccountArr
,
cfg
)
err
,
syncMap
:=
transaction
.
InitAccNonce
(
SendTxAccountArr
,
cfg
)
if
err
!=
nil
{
log
.
Errorf
(
"Bath Send Tran error: %s"
,
err
)
return
}
arr
:=
transaction
.
SignedTxArr
(
syncMap
,
SendTxAccountArr
,
cfg
)
if
broadcastTxArr
{
if
err
:=
transaction
.
BroadcastTxArr
(
arr
,
cfg
);
err
!=
nil
{
log
.
Errorf
(
"Bath Send Tran error: %s"
,
err
)
...
...
transaction/signedTx.go
View file @
05d36acb
...
...
@@ -45,7 +45,7 @@ var (
signTranArr
=
&
SignTranArr
{
TranArr
:
make
([]
*
types
.
Transaction
,
0
),
}
batchSignCount
int32
batchSignCount
,
handleNonceCount
int32
)
func
newTransactor
(
cfg
TranConfig
)
(
*
Transactor
,
error
)
{
...
...
@@ -87,32 +87,63 @@ func ProtocolAndAddress(listenAddr string) (string, string) {
return
protocol
,
address
}
// SignedTxArr 获取全部签名数据
func
SignedTxArr
(
sendTxAccountArr
[][]
string
,
cfg
*
tool
.
Config
)
[]
*
types
.
Transaction
{
for
i
:=
0
;
i
<
cfg
.
GoRoutineCount
;
i
++
{
go
signedTxFunc
()
}
func
InitAccNonce
(
sendTxAccountArr
[][]
string
,
cfg
*
tool
.
Config
)
(
error
,
sync
.
Map
)
{
var
accountsNonceMap
sync
.
Map
rowsCh
:=
make
(
chan
[]
string
,
1000000
)
client
,
err
:=
grpc
.
Dial
(
cfg
.
RpcNode
,
grpc
.
WithInsecure
(),
grpc
.
WithContextDialer
(
dialerFunc
))
if
err
!=
nil
{
log
.
Error
(
"grpc dial error:"
,
err
)
return
nil
return
err
,
sync
.
Map
{}
}
defer
client
.
Close
()
serviceClient
:=
ring
.
NewRingServiceClient
(
client
)
for
i
:=
0
;
i
<
cfg
.
GoRoutineCount
;
i
++
{
go
func
()
{
for
{
select
{
case
sendTxAccount
:=
<-
rowsCh
:
addressRow
:=
sendTxAccount
[
0
]
privateKey
:=
sendTxAccount
[
1
]
fromAddr
:=
metatypes
.
HexToAddress
(
addressRow
)
nonceReq
:=
&
ring
.
NonceRequest
{
Address
:
(
*
metatypes
.
Address
)(
fromAddr
.
Bytes
()),
}
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Second
*
1
)
defer
cancel
()
response
,
err
:=
serviceClient
.
Nonce
(
ctx
,
nonceReq
)
if
err
!=
nil
{
log
.
Error
(
"get account nonce error:"
,
err
)
}
accountsNonceMap
.
Store
(
privateKey
,
response
.
Nonce
)
atomic
.
AddInt32
(
&
handleNonceCount
,
1
)
}
}
}()
}
for
_
,
rows
:=
range
sendTxAccountArr
{
privateKey
:=
rows
[
1
]
fromAddr
:=
metatypes
.
HexToAddress
(
rows
[
0
])
nonceReq
:=
&
ring
.
NonceRequest
{
Address
:
(
*
metatypes
.
Address
)(
fromAddr
.
Bytes
()),
rowsCh
<-
rows
}
for
{
if
handleNonceCount
==
int32
(
len
(
sendTxAccountArr
))
{
log
.
Info
(
"Wait get all acc nonce successful"
)
return
nil
,
accountsNonceMap
}
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Second
*
1
)
defer
cancel
()
response
,
err
:=
serviceClient
.
Nonce
(
ctx
,
nonceReq
)
if
err
!=
nil
{
log
.
Error
(
"get account nonce error:"
,
err
)
return
nil
}
}
// SignedTxArr 获取全部签名数据
func
SignedTxArr
(
syncMap
sync
.
Map
,
sendTxAccountArr
[][]
string
,
cfg
*
tool
.
Config
)
[]
*
types
.
Transaction
{
for
i
:=
0
;
i
<
cfg
.
GoRoutineCount
;
i
++
{
go
signedTxFunc
()
}
for
_
,
rows
:=
range
sendTxAccountArr
{
privateKey
:=
rows
[
1
]
value
,
ok
:=
syncMap
.
Load
(
privateKey
)
if
!
ok
{
log
.
Error
(
"Load nonce map error..........."
)
continue
}
nonce
:=
new
(
big
.
Int
)
.
SetUint64
(
response
.
Nonce
)
nonce
:=
new
(
big
.
Int
)
.
SetUint64
(
value
.
(
uint64
)
)
log
.
Infof
(
"from addr:%s,nonce:%d"
,
fromAddr
,
nonce
)
for
signCount
:=
0
;
signCount
<
cfg
.
SignCount
;
signCount
++
{
tranCfg
:=
TranConfig
{
...
...
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