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
Show 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() {
...
@@ -26,7 +26,12 @@ func startTest() {
cfg
.
GoRoutineCount
=
goRoutineCount
cfg
.
GoRoutineCount
=
goRoutineCount
cfg
.
SignCount
=
txCount
/
100
cfg
.
SignCount
=
txCount
/
100
cfg
.
BatchCount
=
batchCount
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
broadcastTxArr
{
if
err
:=
transaction
.
BroadcastTxArr
(
arr
,
cfg
);
err
!=
nil
{
if
err
:=
transaction
.
BroadcastTxArr
(
arr
,
cfg
);
err
!=
nil
{
log
.
Errorf
(
"Bath Send Tran error: %s"
,
err
)
log
.
Errorf
(
"Bath Send Tran error: %s"
,
err
)
...
...
transaction/signedTx.go
View file @
05d36acb
...
@@ -45,7 +45,7 @@ var (
...
@@ -45,7 +45,7 @@ var (
signTranArr
=
&
SignTranArr
{
signTranArr
=
&
SignTranArr
{
TranArr
:
make
([]
*
types
.
Transaction
,
0
),
TranArr
:
make
([]
*
types
.
Transaction
,
0
),
}
}
batchSignCount
int32
batchSignCount
,
handleNonceCount
int32
)
)
func
newTransactor
(
cfg
TranConfig
)
(
*
Transactor
,
error
)
{
func
newTransactor
(
cfg
TranConfig
)
(
*
Transactor
,
error
)
{
...
@@ -87,21 +87,24 @@ func ProtocolAndAddress(listenAddr string) (string, string) {
...
@@ -87,21 +87,24 @@ func ProtocolAndAddress(listenAddr string) (string, string) {
return
protocol
,
address
return
protocol
,
address
}
}
// SignedTxArr 获取全部签名数据
func
InitAccNonce
(
sendTxAccountArr
[][]
string
,
cfg
*
tool
.
Config
)
(
error
,
sync
.
Map
)
{
func
SignedTxArr
(
sendTxAccountArr
[][]
string
,
cfg
*
tool
.
Config
)
[]
*
types
.
Transaction
{
var
accountsNonceMap
sync
.
Map
for
i
:=
0
;
i
<
cfg
.
GoRoutineCount
;
i
++
{
rowsCh
:=
make
(
chan
[]
string
,
1000000
)
go
signedTxFunc
()
}
client
,
err
:=
grpc
.
Dial
(
cfg
.
RpcNode
,
grpc
.
WithInsecure
(),
grpc
.
WithContextDialer
(
dialerFunc
))
client
,
err
:=
grpc
.
Dial
(
cfg
.
RpcNode
,
grpc
.
WithInsecure
(),
grpc
.
WithContextDialer
(
dialerFunc
))
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Error
(
"grpc dial error:"
,
err
)
log
.
Error
(
"grpc dial error:"
,
err
)
return
nil
return
err
,
sync
.
Map
{}
}
}
defer
client
.
Close
()
defer
client
.
Close
()
serviceClient
:=
ring
.
NewRingServiceClient
(
client
)
serviceClient
:=
ring
.
NewRingServiceClient
(
client
)
for
_
,
rows
:=
range
sendTxAccountArr
{
for
i
:=
0
;
i
<
cfg
.
GoRoutineCount
;
i
++
{
privateKey
:=
rows
[
1
]
go
func
()
{
fromAddr
:=
metatypes
.
HexToAddress
(
rows
[
0
])
for
{
select
{
case
sendTxAccount
:=
<-
rowsCh
:
addressRow
:=
sendTxAccount
[
0
]
privateKey
:=
sendTxAccount
[
1
]
fromAddr
:=
metatypes
.
HexToAddress
(
addressRow
)
nonceReq
:=
&
ring
.
NonceRequest
{
nonceReq
:=
&
ring
.
NonceRequest
{
Address
:
(
*
metatypes
.
Address
)(
fromAddr
.
Bytes
()),
Address
:
(
*
metatypes
.
Address
)(
fromAddr
.
Bytes
()),
}
}
...
@@ -110,9 +113,37 @@ func SignedTxArr(sendTxAccountArr [][]string, cfg *tool.Config) []*types.Transac
...
@@ -110,9 +113,37 @@ func SignedTxArr(sendTxAccountArr [][]string, cfg *tool.Config) []*types.Transac
response
,
err
:=
serviceClient
.
Nonce
(
ctx
,
nonceReq
)
response
,
err
:=
serviceClient
.
Nonce
(
ctx
,
nonceReq
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Error
(
"get account nonce error:"
,
err
)
log
.
Error
(
"get account nonce error:"
,
err
)
return
nil
}
}
nonce
:=
new
(
big
.
Int
)
.
SetUint64
(
response
.
Nonce
)
accountsNonceMap
.
Store
(
privateKey
,
response
.
Nonce
)
atomic
.
AddInt32
(
&
handleNonceCount
,
1
)
}
}
}()
}
for
_
,
rows
:=
range
sendTxAccountArr
{
rowsCh
<-
rows
}
for
{
if
handleNonceCount
==
int32
(
len
(
sendTxAccountArr
))
{
log
.
Info
(
"Wait get all acc nonce successful"
)
return
nil
,
accountsNonceMap
}
}
}
// 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
(
value
.
(
uint64
))
log
.
Infof
(
"from addr:%s,nonce:%d"
,
fromAddr
,
nonce
)
log
.
Infof
(
"from addr:%s,nonce:%d"
,
fromAddr
,
nonce
)
for
signCount
:=
0
;
signCount
<
cfg
.
SignCount
;
signCount
++
{
for
signCount
:=
0
;
signCount
<
cfg
.
SignCount
;
signCount
++
{
tranCfg
:=
TranConfig
{
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