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
f1fb7079
Commit
f1fb7079
authored
Mar 09, 2023
by
duanjinfei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add map
parent
cd9a5318
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
9 deletions
+41
-9
bathTest.go
transaction/bathTest.go
+3
-9
signedTx.go
transaction/signedTx.go
+5
-0
txcache.go
txcache/txcache.go
+33
-0
No files found.
transaction/bathTest.go
View file @
f1fb7079
...
...
@@ -3,6 +3,7 @@ package transaction
import
(
"ChainGrpcTest/log"
"ChainGrpcTest/tool"
"ChainGrpcTest/txcache"
"context"
v1
"github.com/CaduceusMetaverseProtocol/MetaProtocol/gen/proto/go/base/v1"
crypterv1
"github.com/CaduceusMetaverseProtocol/MetaProtocol/gen/proto/go/crypter/v1"
...
...
@@ -233,10 +234,9 @@ func batchRecoverTx(client crypterv1.CrypterServiceClient, sleepTime int) {
sinceTime
:=
time
.
Since
(
sendTranStartTime
)
.
Milliseconds
()
atomic
.
AddInt64
(
&
totalSendTime
,
sinceTime
)
for
_
,
tx
:=
range
sign
.
GetRecoverdTx
()
{
if
set
.
contain
(
*
tx
.
From
)
{
continue
if
!
txcache
.
CompareAddress
(
tx
.
TxHash
.
Hex
(),
tx
.
From
.
Hex
()
)
{
log
.
Error
(
"tx.TxHash:"
,
tx
.
TxHash
.
Hex
(),
"tx.From"
,
tx
.
From
.
Hex
())
}
set
.
txArr
=
append
(
set
.
txArr
,
tx
)
}
log
.
Infof
(
"Send transaction time: %d ms"
,
sinceTime
)
}
...
...
@@ -269,12 +269,6 @@ func BatchRecoverTxHandler(tranArr []*types.Transaction, fromAddrArr []common.Ad
}
for
{
if
bathHandleSendCount
==
allSignedTxCount
{
for
_
,
fromAddr
:=
range
fromAddrArr
{
address
:=
metatypes
.
HexToAddress
(
fromAddr
.
Hex
())
if
!
set
.
contain
(
address
)
{
log
.
Error
(
"not contain from addr:"
,
address
)
}
}
log
.
Infof
(
"Send tran count: %d"
,
bathHandleSendCount
)
log
.
Infof
(
"Since time: %d ms"
,
time
.
Since
(
startTime
)
.
Milliseconds
())
break
...
...
transaction/signedTx.go
View file @
f1fb7079
...
...
@@ -3,11 +3,13 @@ package transaction
import
(
"ChainGrpcTest/log"
"ChainGrpcTest/tool"
"ChainGrpcTest/txcache"
"crypto/ecdsa"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"math/big"
"sync"
"time"
)
...
...
@@ -48,6 +50,8 @@ func newTransactor(cfg TranConfig) (*Transactor, error) {
return
&
res
,
nil
}
var
accountsNonceMap
sync
.
Map
// SignedTxArr 获取全部签名数据
func
SignedTxArr
(
sendTxAccountArr
[][]
string
,
cfg
*
tool
.
Config
)
([]
*
types
.
Transaction
,
[]
common
.
Address
)
{
tranArr
:=
make
([]
*
types
.
Transaction
,
0
)
...
...
@@ -68,6 +72,7 @@ func SignedTxArr(sendTxAccountArr [][]string, cfg *tool.Config) ([]*types.Transa
}
t
,
err
:=
newTransactor
(
tranCfg
)
signedTx
,
err
=
t
.
signedTx
()
txcache
.
Add
(
signedTx
.
Hash
()
.
Hex
(),
rows
[
0
])
nonce
=
big
.
NewInt
(
1
)
.
Add
(
nonce
,
big
.
NewInt
(
1
))
if
err
!=
nil
||
signedTx
==
nil
{
log
.
Errorf
(
"signed tx error %s "
,
err
)
...
...
txcache/txcache.go
0 → 100644
View file @
f1fb7079
package
txcache
import
(
"strings"
"sync"
)
var
(
gtxcache
=
&
TxCache
{
cache
:
make
(
map
[
string
]
string
),
}
)
type
TxCache
struct
{
cache
map
[
string
]
string
mux
sync
.
RWMutex
}
func
Add
(
txhash
string
,
address
string
)
{
gtxcache
.
mux
.
Lock
()
defer
gtxcache
.
mux
.
Unlock
()
gtxcache
.
cache
[
txhash
]
=
address
}
func
CompareAddress
(
txhash
string
,
newer
string
)
bool
{
gtxcache
.
mux
.
RLock
()
defer
gtxcache
.
mux
.
RUnlock
()
o
,
exist
:=
gtxcache
.
cache
[
txhash
]
if
!
exist
{
return
false
}
return
strings
.
Compare
(
newer
,
o
)
==
0
}
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