Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
multisend
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
李伟@五瓣科技
multisend
Commits
ae2ca46c
Commit
ae2ca46c
authored
Feb 24, 2022
by
李伟@五瓣科技
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
upadte send msg to redis
parent
bd65d8fc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
110 additions
and
32 deletions
+110
-32
originalTx.go
originalTx.go
+29
-32
redis.go
redis.go
+81
-0
No files found.
originalTx.go
View file @
ae2ca46c
package
multisend
package
multisend
import
(
import
(
"context"
"crypto/ecdsa"
"crypto/ecdsa"
"encoding/json"
"fmt"
"fmt"
"math/big"
"math/big"
"sync"
"sync"
...
@@ -14,7 +12,6 @@ import (
...
@@ -14,7 +12,6 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto"
"github.com/go-redis/redis/v8"
// "github.com/cbergoon/merkletree"
// "github.com/cbergoon/merkletree"
)
)
...
@@ -24,8 +21,8 @@ var originalTxsHashQueue chan *[]byte = make(chan *[]byte, 1000)
...
@@ -24,8 +21,8 @@ var originalTxsHashQueue chan *[]byte = make(chan *[]byte, 1000)
var
originalTxsWithFromQueue
chan
*
TxsHash
=
make
(
chan
*
TxsHash
,
2000000
)
var
originalTxsWithFromQueue
chan
*
TxsHash
=
make
(
chan
*
TxsHash
,
2000000
)
const
batchSize
=
5
const
batchSize
=
100
const
hashRootSize
=
2
const
hashRootSize
=
2
00
func
init
()
{
func
init
()
{
...
@@ -121,32 +118,32 @@ func ProduceOriginalTx() error {
...
@@ -121,32 +118,32 @@ func ProduceOriginalTx() error {
}
}
var
ctx
=
context
.
Background
()
//
var ctx = context.Background()
var
rdb
=
redis
.
NewClient
(
&
redis
.
Options
{
//
var rdb = redis.NewClient(&redis.Options{
Addr
:
"54.250.115.98:6379"
,
//
Addr: "54.250.115.98:6379",
Password
:
"redis20220217"
,
// no password set
//
Password: "redis20220217", // no password set
DB
:
0
,
// use default DB
//
DB: 0, // use default DB
})
//
})
func
SendMd5Tx
()
{
//
func SendMd5Tx() {
//超时 超量
//
//超时 超量
// count := 0
//
// count := 0
// sendTicker := time.NewTicker(time.Duration(5) * time.Second)
//
// sendTicker := time.NewTicker(time.Duration(5) * time.Second)
for
{
//
for {
select
{
//
select {
case
txs
:=
<-
originalTxsWithFromQueue
:
//
case txs := <-originalTxsWithFromQueue:
txsAsJson
,
err
:=
json
.
Marshal
(
txs
)
//
txsAsJson, err := json.Marshal(txs)
if
err
!=
nil
{
//
if err != nil {
fmt
.
Println
(
err
.
Error
())
//
fmt.Println(err.Error())
continue
//
continue
}
//
}
rdb
.
LPush
(
ctx
,
"list"
,
txsAsJson
)
//
rdb.LPush(ctx, "list", txsAsJson)
}
//
}
}
//
}
}
//
}
func
StartProduceTx
()
{
func
StartProduceTx
()
{
wg
:=
sync
.
WaitGroup
{}
wg
:=
sync
.
WaitGroup
{}
...
@@ -163,7 +160,7 @@ func StartProduceTx() {
...
@@ -163,7 +160,7 @@ func StartProduceTx() {
go
func
()
{
go
func
()
{
defer
wg
.
Done
()
defer
wg
.
Done
()
S
endMd5Tx
()
S
tart
()
}()
}()
wg
.
Wait
()
wg
.
Wait
()
...
...
redis.go
0 → 100644
View file @
ae2ca46c
package
multisend
import
(
"context"
"encoding/json"
"fmt"
"runtime"
"time"
"github.com/go-redis/redis/v8"
)
var
(
jobnum
=
runtime
.
NumCPU
()
)
type
Job
struct
{
Client
*
redis
.
Client
}
func
initClient
(
poolSize
int
)
*
redis
.
Client
{
client
:=
redis
.
NewClient
(
&
redis
.
Options
{
Addr
:
"54.250.115.98:6379"
,
DialTimeout
:
time
.
Second
,
ReadTimeout
:
time
.
Second
,
WriteTimeout
:
time
.
Second
,
PoolSize
:
poolSize
,
Password
:
"redis20220217"
,
DB
:
0
,
})
if
err
:=
client
.
FlushAll
(
context
.
Background
())
.
Err
();
err
!=
nil
{
panic
(
err
)
}
return
client
}
func
Start
()
{
//任务channel 定义缓冲器为job数量
jobs
:=
make
(
chan
Job
,
jobnum
)
client
:=
initClient
(
10
)
//defer client.Close()
//定义每个任务执行的方法
jobfunc
:=
func
(
client
*
redis
.
Client
)
error
{
for
{
select
{
case
txs
:=
<-
originalTxsWithFromQueue
:
txsAsJson
,
err
:=
json
.
Marshal
(
txs
)
if
err
!=
nil
{
return
err
}
if
err
:=
client
.
LPush
(
context
.
Background
(),
"list"
,
txsAsJson
)
.
Err
();
err
!=
nil
{
fmt
.
Println
(
err
.
Error
())
}
}
}
}
//1 添加 job 到 channel
go
func
()
{
for
index
:=
0
;
index
<
jobnum
;
index
++
{
jobs
<-
Job
{
client
}
}
defer
close
(
jobs
)
}()
//2 并行执行 jobs
for
j
:=
range
jobs
{
go
func
(
job
Job
)
{
if
err
:=
jobfunc
(
client
);
err
!=
nil
{
panic
(
err
.
Error
())
}
}(
j
)
}
}
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