2019-10-14 01:20:49 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"math/rand"
|
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
|
2020-03-18 20:45:37 +00:00
|
|
|
"github.com/filecoin-project/specs-actors/actors/crypto"
|
|
|
|
|
2019-12-19 20:13:17 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
2019-10-18 04:47:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/api"
|
2020-07-10 14:43:14 +00:00
|
|
|
"github.com/filecoin-project/lotus/build"
|
2019-10-18 04:47:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
lcli "github.com/filecoin-project/lotus/cli"
|
2019-10-14 01:20:49 +00:00
|
|
|
|
2020-06-02 18:12:53 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
2019-10-14 01:20:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
app := &cli.App{
|
|
|
|
Name: "chain-noise",
|
|
|
|
Usage: "Generate some spam transactions in the network",
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "repo",
|
|
|
|
EnvVars: []string{"LOTUS_PATH"},
|
|
|
|
Hidden: true,
|
|
|
|
Value: "~/.lotus", // TODO: Consider XDG_DATA_HOME
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Commands: []*cli.Command{runCmd},
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := app.Run(os.Args); err != nil {
|
|
|
|
fmt.Println("Error: ", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var runCmd = &cli.Command{
|
|
|
|
Name: "run",
|
|
|
|
Action: func(cctx *cli.Context) error {
|
|
|
|
addr, err := address.NewFromString(cctx.Args().First())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
api, closer, err := lcli.GetFullNodeAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
ctx := lcli.ReqContext(cctx)
|
|
|
|
|
2020-05-27 20:53:20 +00:00
|
|
|
return sendSmallFundsTxs(ctx, api, addr, 5)
|
2019-10-14 01:20:49 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func sendSmallFundsTxs(ctx context.Context, api api.FullNode, from address.Address, rate int) error {
|
|
|
|
var sendSet []address.Address
|
|
|
|
for i := 0; i < 20; i++ {
|
2020-02-23 23:39:45 +00:00
|
|
|
naddr, err := api.WalletNew(ctx, crypto.SigTypeSecp256k1)
|
2019-10-14 01:20:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
sendSet = append(sendSet, naddr)
|
|
|
|
}
|
|
|
|
|
2020-07-10 14:43:14 +00:00
|
|
|
tick := build.Clock.Ticker(time.Second / time.Duration(rate))
|
2019-10-14 01:20:49 +00:00
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-tick.C:
|
|
|
|
msg := &types.Message{
|
|
|
|
From: from,
|
|
|
|
To: sendSet[rand.Intn(20)],
|
|
|
|
Value: types.NewInt(1),
|
2020-07-20 17:57:06 +00:00
|
|
|
GasLimit: 0,
|
2019-10-14 01:20:49 +00:00
|
|
|
GasPrice: types.NewInt(0),
|
|
|
|
}
|
|
|
|
|
|
|
|
smsg, err := api.MpoolPushMessage(ctx, msg)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
fmt.Println("Message sent: ", smsg.Cid())
|
|
|
|
case <-ctx.Done():
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|