Commit 18c0e034 authored by Ubuntu's avatar Ubuntu

add repeated tx with test stat

parent 0669b3d3
......@@ -37,6 +37,9 @@ message Address {
// AddressLength = 20
// )
message EthTx {
EthTxData Inner = 1;
google.protobuf.Timestamp time =2;
......@@ -105,6 +108,10 @@ message TransactionEth{
EthTx tx =3;
}
message RepeatedEthTx{
repeated TransactionEth txs =1;
}
message TransactionStd{
TxProof tx_proof=1;
......@@ -113,6 +120,10 @@ message TransactionStd{
}
message RepeatedStdTx{
repeated TransactionStd txs =1;
}
//3. bytes
message TransactionBytes{
......
package benchmark
import (
"fmt"
"testing"
ring "github.com/CaduceusMetaverseProtocol/metaprotocol/gen/proto/go/ring/v1"
......@@ -20,7 +19,7 @@ func TestSendEmptyMsg(t *testing.T) {
mockGreeterClient := NewMockRingServiceClient(ctrl)
mockGreeterClient.EXPECT().SendEmptyMsg(gomock.Any(), gomock.Any()).Return(&ring.EmptyResponse{}, nil).AnyTimes()
mockGreeterClient.EXPECT().SendEmptyMsg(gomock.Any(), &ring.EmptyRequest{}).Return(&ring.EmptyResponse{}, nil).AnyTimes()
// gomock.Any(), // expect any value for first parameter
// gomock.Any(), // expect any value for second parameter
......@@ -30,17 +29,17 @@ type rpcMsg struct {
msg proto.Message
}
func (r *rpcMsg) Matches(msg interface{}) bool {
m, ok := msg.(proto.Message)
if !ok {
return false
}
return proto.Equal(m, r.msg)
}
func (r *rpcMsg) String() string {
return fmt.Sprintf("is %s", r.msg)
}
// func (r *rpcMsg) Matches(msg interface{}) bool {
// m, ok := msg.(proto.Message)
// if !ok {
// return false
// }
// return proto.Equal(m, r.msg)
// }
// func (r *rpcMsg) String() string {
// return fmt.Sprintf("is %s", r.msg)
// }
func TestHelloWorld(t *testing.T) {
......
package benchmark_test
import (
"context"
"crypto/ecdsa"
"fmt"
"testing"
"time"
"math/big"
base "github.com/CaduceusMetaverseProtocol/metaprotocol/gen/proto/go/base/v1"
ring "github.com/CaduceusMetaverseProtocol/metaprotocol/gen/proto/go/ring/v1"
"github.com/ethereum/go-ethereum/crypto"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
var tableTx = []struct {
input int
}{
{input: 200},
{input: 500},
{input: 1000},
{input: 2000},
{input: 5000},
}
func RepeatedEthTx(txl int, b *testing.B) {
//b.Logf("b.N: %d\n", b.N)
local, err := crypto.HexToECDSA("FD5CC6F5E7E2805E920AC5DC83D5AF1106F9C92F0C04F9D5E1FD4261B4B4464A")
if err != nil {
b.Fatal(err)
}
publicKey := local.Public()
publicKeyECDSA, _ := publicKey.(*ecdsa.PublicKey)
fromAddr := crypto.PubkeyToAddress(*publicKeyECDSA)
remote, err := crypto.GenerateKey()
if err != nil {
b.Fatal(err)
}
tx, err := pricedTransaction(crypto.PubkeyToAddress(remote.PublicKey), 0, 100000, big.NewInt(1), local)
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
conn, err := grpc.Dial("127.0.0.1:9006", grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
b.Fatal(err)
}
defer conn.Close()
c := ring.NewRingServiceClient(conn)
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
inner := base.EthTxData{
AccountNonce: tx.Nonce(),
Price: tx.GasPrice().Bytes(),
GasLimit: tx.Gas(),
Payload: tx.Data(),
}
v, r, sigs := tx.RawSignatureValues()
inner.V = v.Bytes()
inner.R = r.Bytes()
inner.S = sigs.Bytes()
inner.Amount = tx.Value().Bytes()
addr := base.Address{Address: tx.To().Bytes()}
inner.Recipient = &addr
inner.From = fromAddr.Bytes()
txs := make([]*base.TransactionEth, 0, txl)
for i := 0; i < txl; i++ {
txs = append(txs, &base.TransactionEth{Tx: &base.EthTx{Inner: &inner}})
}
res, err := c.SendRepeatedEthTx(ctx, &base.RepeatedEthTx{Txs: txs})
if err != nil {
b.Fatal(err)
}
_ = res
// if bytes.Compare(tx.Hash().Bytes(), res.TxHash) != 0 {
// b.Fatal(err)
// }
// onceHash.Do(func() {
// b.Logf("response: %x local: %x \n", res.TxHash, tx.Hash().Bytes())
// })
}
})
}
func BenchmarkRepeated(b *testing.B) {
for _, v := range tableTx {
b.Run(fmt.Sprintf("input_size_%d", v.input), func(b *testing.B) {
RepeatedEthTx(v.input, b)
})
}
}
// 验证和 b.Run sub-benchmark的时间一致;
func Benchmark200RepeatedEthTx(b *testing.B) {
RepeatedEthTx(5000, b)
}
......@@ -33,6 +33,18 @@ type RingServer struct {
ring.UnimplementedRingServiceServer
}
func (*RingServer) SendRepeatedStdTx(context.Context, *base.RepeatedStdTx) (*ring.SendRawTransactionResponse, error) {
//fmt.Printf("SendEmptyMsg: %s \n", time.Now())
return &ring.SendRawTransactionResponse{}, nil
}
func (*RingServer) SendRepeatedEthTx(context.Context, *base.RepeatedEthTx) (*ring.SendRawTransactionResponse, error) {
//fmt.Printf("SendEmptyMsg: %s \n", time.Now())
return &ring.SendRawTransactionResponse{}, nil
}
func (*RingServer) SendEmptyMsg(context.Context, *ring.EmptyRequest) (*ring.EmptyResponse, error) {
//fmt.Printf("SendEmptyMsg: %s \n", time.Now())
......
This diff is collapsed.
This diff is collapsed.
......@@ -26,6 +26,8 @@ const _ = grpc.SupportPackageIsVersion7
type RingServiceClient interface {
// account info service
SendTxAsEth(ctx context.Context, in *v1.TransactionEth, opts ...grpc.CallOption) (*SendRawTransactionResponse, error)
SendRepeatedEthTx(ctx context.Context, in *v1.RepeatedEthTx, opts ...grpc.CallOption) (*SendRawTransactionResponse, error)
SendRepeatedStdTx(ctx context.Context, in *v1.RepeatedStdTx, opts ...grpc.CallOption) (*SendRawTransactionResponse, error)
SendTxAsStd(ctx context.Context, in *v1.TransactionStd, opts ...grpc.CallOption) (*SendRawTransactionResponse, error)
SendTxAsAny(ctx context.Context, in *v1.Transaction, opts ...grpc.CallOption) (*SendRawTransactionResponse, error)
SendTxAsBytes(ctx context.Context, in *v1.TransactionBytes, opts ...grpc.CallOption) (*SendRawTransactionResponse, error)
......@@ -52,6 +54,24 @@ func (c *ringServiceClient) SendTxAsEth(ctx context.Context, in *v1.TransactionE
return out, nil
}
func (c *ringServiceClient) SendRepeatedEthTx(ctx context.Context, in *v1.RepeatedEthTx, opts ...grpc.CallOption) (*SendRawTransactionResponse, error) {
out := new(SendRawTransactionResponse)
err := c.cc.Invoke(ctx, "/ring.v1.RingService/SendRepeatedEthTx", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *ringServiceClient) SendRepeatedStdTx(ctx context.Context, in *v1.RepeatedStdTx, opts ...grpc.CallOption) (*SendRawTransactionResponse, error) {
out := new(SendRawTransactionResponse)
err := c.cc.Invoke(ctx, "/ring.v1.RingService/SendRepeatedStdTx", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *ringServiceClient) SendTxAsStd(ctx context.Context, in *v1.TransactionStd, opts ...grpc.CallOption) (*SendRawTransactionResponse, error) {
out := new(SendRawTransactionResponse)
err := c.cc.Invoke(ctx, "/ring.v1.RingService/SendTxAsStd", in, out, opts...)
......@@ -112,6 +132,8 @@ func (c *ringServiceClient) Nonce(ctx context.Context, in *NonceRequest, opts ..
type RingServiceServer interface {
// account info service
SendTxAsEth(context.Context, *v1.TransactionEth) (*SendRawTransactionResponse, error)
SendRepeatedEthTx(context.Context, *v1.RepeatedEthTx) (*SendRawTransactionResponse, error)
SendRepeatedStdTx(context.Context, *v1.RepeatedStdTx) (*SendRawTransactionResponse, error)
SendTxAsStd(context.Context, *v1.TransactionStd) (*SendRawTransactionResponse, error)
SendTxAsAny(context.Context, *v1.Transaction) (*SendRawTransactionResponse, error)
SendTxAsBytes(context.Context, *v1.TransactionBytes) (*SendRawTransactionResponse, error)
......@@ -129,6 +151,12 @@ type UnimplementedRingServiceServer struct {
func (UnimplementedRingServiceServer) SendTxAsEth(context.Context, *v1.TransactionEth) (*SendRawTransactionResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method SendTxAsEth not implemented")
}
func (UnimplementedRingServiceServer) SendRepeatedEthTx(context.Context, *v1.RepeatedEthTx) (*SendRawTransactionResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method SendRepeatedEthTx not implemented")
}
func (UnimplementedRingServiceServer) SendRepeatedStdTx(context.Context, *v1.RepeatedStdTx) (*SendRawTransactionResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method SendRepeatedStdTx not implemented")
}
func (UnimplementedRingServiceServer) SendTxAsStd(context.Context, *v1.TransactionStd) (*SendRawTransactionResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method SendTxAsStd not implemented")
}
......@@ -178,6 +206,42 @@ func _RingService_SendTxAsEth_Handler(srv interface{}, ctx context.Context, dec
return interceptor(ctx, in, info, handler)
}
func _RingService_SendRepeatedEthTx_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(v1.RepeatedEthTx)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(RingServiceServer).SendRepeatedEthTx(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/ring.v1.RingService/SendRepeatedEthTx",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(RingServiceServer).SendRepeatedEthTx(ctx, req.(*v1.RepeatedEthTx))
}
return interceptor(ctx, in, info, handler)
}
func _RingService_SendRepeatedStdTx_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(v1.RepeatedStdTx)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(RingServiceServer).SendRepeatedStdTx(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/ring.v1.RingService/SendRepeatedStdTx",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(RingServiceServer).SendRepeatedStdTx(ctx, req.(*v1.RepeatedStdTx))
}
return interceptor(ctx, in, info, handler)
}
func _RingService_SendTxAsStd_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(v1.TransactionStd)
if err := dec(in); err != nil {
......@@ -297,6 +361,14 @@ var RingService_ServiceDesc = grpc.ServiceDesc{
MethodName: "SendTxAsEth",
Handler: _RingService_SendTxAsEth_Handler,
},
{
MethodName: "SendRepeatedEthTx",
Handler: _RingService_SendRepeatedEthTx_Handler,
},
{
MethodName: "SendRepeatedStdTx",
Handler: _RingService_SendRepeatedStdTx_Handler,
},
{
MethodName: "SendTxAsStd",
Handler: _RingService_SendTxAsStd_Handler,
......
......@@ -62,6 +62,7 @@ golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHl
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20211013180041-c96bc1413d57 h1:LQmS1nU0twXLA96Kt7U9qtHJEbBk3z6Q0V4UXjZkpr4=
golang.org/x/mod v0.6.0-dev.0.20211013180041-c96bc1413d57/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
......@@ -105,6 +106,7 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.8-0.20211029000441-d6a9af8af023 h1:0c3L82FDQ5rt1bjTBlchS8t6RQ6299/+5bWMnRLh+uI=
golang.org/x/tools v0.1.8-0.20211029000441-d6a9af8af023/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU=
golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
......
......@@ -14,6 +14,10 @@ service RingService{
// account info service
rpc SendTxAsEth(base.v1.TransactionEth) returns (SendRawTransactionResponse) {};
rpc SendRepeatedEthTx(base.v1.RepeatedEthTx) returns (SendRawTransactionResponse) {};
rpc SendRepeatedStdTx(base.v1.RepeatedStdTx) returns (SendRawTransactionResponse) {};
rpc SendTxAsStd(base.v1.TransactionStd) returns (SendRawTransactionResponse) {};
rpc SendTxAsAny(base.v1.Transaction) returns (SendRawTransactionResponse) {};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment