Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
MetaProtocol
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
Nebula
MetaProtocol
Commits
86fce5f4
Commit
86fce5f4
authored
Dec 01, 2022
by
Ubuntu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add empty grpc
parent
30c64eea
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
440 additions
and
58 deletions
+440
-58
resource.proto
baseapi/base/v1/resource.proto
+3
-3
service.pb.go
gen/proto/go/ring/v1/service.pb.go
+187
-53
service_grpc.pb.go
gen/proto/go/ring/v1/service_grpc.pb.go
+73
-0
grcp-tx_test.go
grcp-tx_test.go
+166
-2
service.proto
ringapi/ring/v1/service.proto
+11
-0
No files found.
baseapi/base/v1/resource.proto
View file @
86fce5f4
...
...
@@ -6,8 +6,8 @@ import "google/protobuf/timestamp.proto";
import
"google/protobuf/any.proto"
;
import
"google/protobuf/descriptor.proto"
;
import
"github.com/gogo/protobuf/gogoproto/gogo.proto"
;
//
import "google/protobuf/descriptor.proto";
//
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
// import "base/v1/options.proto";
...
...
@@ -92,7 +92,7 @@ message TxProof{
message
Transaction
{
TxProof
tx_proof
=
1
;
int64
timeout_block_num
=
2
;
google.protobuf.Any
tx
=
3
[(
gogoproto.customtype
)
=
"InterfaceType"
]
;
// EthTx StdTx
google.protobuf.Any
tx
=
3
;
// EthTx StdTx
}
//2. eth std: proto3 eth tx --> grpc --->proto3 eth tx
...
...
gen/proto/go/ring/v1/service.pb.go
View file @
86fce5f4
This diff is collapsed.
Click to expand it.
gen/proto/go/ring/v1/service_grpc.pb.go
View file @
86fce5f4
...
...
@@ -12,6 +12,7 @@ import (
grpc
"google.golang.org/grpc"
codes
"google.golang.org/grpc/codes"
status
"google.golang.org/grpc/status"
emptypb
"google.golang.org/protobuf/types/known/emptypb"
)
// This is a compile-time assertion to ensure that this generated file
...
...
@@ -28,6 +29,8 @@ type RingServiceClient interface {
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
)
SendEmpty
(
ctx
context
.
Context
,
in
*
emptypb
.
Empty
,
opts
...
grpc
.
CallOption
)
(
*
emptypb
.
Empty
,
error
)
SendEmptyMsg
(
ctx
context
.
Context
,
in
*
EmptyRequest
,
opts
...
grpc
.
CallOption
)
(
*
EmptyResponse
,
error
)
// rpc SendRawTransaction(base.v1.EthTx) returns (SendRawTransactionResponse) {};
Nonce
(
ctx
context
.
Context
,
in
*
NonceRequest
,
opts
...
grpc
.
CallOption
)
(
*
NonceResponse
,
error
)
}
...
...
@@ -76,6 +79,24 @@ func (c *ringServiceClient) SendTxAsBytes(ctx context.Context, in *v1.Transactio
return
out
,
nil
}
func
(
c
*
ringServiceClient
)
SendEmpty
(
ctx
context
.
Context
,
in
*
emptypb
.
Empty
,
opts
...
grpc
.
CallOption
)
(
*
emptypb
.
Empty
,
error
)
{
out
:=
new
(
emptypb
.
Empty
)
err
:=
c
.
cc
.
Invoke
(
ctx
,
"/ring.v1.RingService/SendEmpty"
,
in
,
out
,
opts
...
)
if
err
!=
nil
{
return
nil
,
err
}
return
out
,
nil
}
func
(
c
*
ringServiceClient
)
SendEmptyMsg
(
ctx
context
.
Context
,
in
*
EmptyRequest
,
opts
...
grpc
.
CallOption
)
(
*
EmptyResponse
,
error
)
{
out
:=
new
(
EmptyResponse
)
err
:=
c
.
cc
.
Invoke
(
ctx
,
"/ring.v1.RingService/SendEmptyMsg"
,
in
,
out
,
opts
...
)
if
err
!=
nil
{
return
nil
,
err
}
return
out
,
nil
}
func
(
c
*
ringServiceClient
)
Nonce
(
ctx
context
.
Context
,
in
*
NonceRequest
,
opts
...
grpc
.
CallOption
)
(
*
NonceResponse
,
error
)
{
out
:=
new
(
NonceResponse
)
err
:=
c
.
cc
.
Invoke
(
ctx
,
"/ring.v1.RingService/Nonce"
,
in
,
out
,
opts
...
)
...
...
@@ -94,6 +115,8 @@ type RingServiceServer interface {
SendTxAsStd
(
context
.
Context
,
*
v1
.
TransactionStd
)
(
*
SendRawTransactionResponse
,
error
)
SendTxAsAny
(
context
.
Context
,
*
v1
.
Transaction
)
(
*
SendRawTransactionResponse
,
error
)
SendTxAsBytes
(
context
.
Context
,
*
v1
.
TransactionBytes
)
(
*
SendRawTransactionResponse
,
error
)
SendEmpty
(
context
.
Context
,
*
emptypb
.
Empty
)
(
*
emptypb
.
Empty
,
error
)
SendEmptyMsg
(
context
.
Context
,
*
EmptyRequest
)
(
*
EmptyResponse
,
error
)
// rpc SendRawTransaction(base.v1.EthTx) returns (SendRawTransactionResponse) {};
Nonce
(
context
.
Context
,
*
NonceRequest
)
(
*
NonceResponse
,
error
)
mustEmbedUnimplementedRingServiceServer
()
...
...
@@ -115,6 +138,12 @@ func (UnimplementedRingServiceServer) SendTxAsAny(context.Context, *v1.Transacti
func
(
UnimplementedRingServiceServer
)
SendTxAsBytes
(
context
.
Context
,
*
v1
.
TransactionBytes
)
(
*
SendRawTransactionResponse
,
error
)
{
return
nil
,
status
.
Errorf
(
codes
.
Unimplemented
,
"method SendTxAsBytes not implemented"
)
}
func
(
UnimplementedRingServiceServer
)
SendEmpty
(
context
.
Context
,
*
emptypb
.
Empty
)
(
*
emptypb
.
Empty
,
error
)
{
return
nil
,
status
.
Errorf
(
codes
.
Unimplemented
,
"method SendEmpty not implemented"
)
}
func
(
UnimplementedRingServiceServer
)
SendEmptyMsg
(
context
.
Context
,
*
EmptyRequest
)
(
*
EmptyResponse
,
error
)
{
return
nil
,
status
.
Errorf
(
codes
.
Unimplemented
,
"method SendEmptyMsg not implemented"
)
}
func
(
UnimplementedRingServiceServer
)
Nonce
(
context
.
Context
,
*
NonceRequest
)
(
*
NonceResponse
,
error
)
{
return
nil
,
status
.
Errorf
(
codes
.
Unimplemented
,
"method Nonce not implemented"
)
}
...
...
@@ -203,6 +232,42 @@ func _RingService_SendTxAsBytes_Handler(srv interface{}, ctx context.Context, de
return
interceptor
(
ctx
,
in
,
info
,
handler
)
}
func
_RingService_SendEmpty_Handler
(
srv
interface
{},
ctx
context
.
Context
,
dec
func
(
interface
{})
error
,
interceptor
grpc
.
UnaryServerInterceptor
)
(
interface
{},
error
)
{
in
:=
new
(
emptypb
.
Empty
)
if
err
:=
dec
(
in
);
err
!=
nil
{
return
nil
,
err
}
if
interceptor
==
nil
{
return
srv
.
(
RingServiceServer
)
.
SendEmpty
(
ctx
,
in
)
}
info
:=
&
grpc
.
UnaryServerInfo
{
Server
:
srv
,
FullMethod
:
"/ring.v1.RingService/SendEmpty"
,
}
handler
:=
func
(
ctx
context
.
Context
,
req
interface
{})
(
interface
{},
error
)
{
return
srv
.
(
RingServiceServer
)
.
SendEmpty
(
ctx
,
req
.
(
*
emptypb
.
Empty
))
}
return
interceptor
(
ctx
,
in
,
info
,
handler
)
}
func
_RingService_SendEmptyMsg_Handler
(
srv
interface
{},
ctx
context
.
Context
,
dec
func
(
interface
{})
error
,
interceptor
grpc
.
UnaryServerInterceptor
)
(
interface
{},
error
)
{
in
:=
new
(
EmptyRequest
)
if
err
:=
dec
(
in
);
err
!=
nil
{
return
nil
,
err
}
if
interceptor
==
nil
{
return
srv
.
(
RingServiceServer
)
.
SendEmptyMsg
(
ctx
,
in
)
}
info
:=
&
grpc
.
UnaryServerInfo
{
Server
:
srv
,
FullMethod
:
"/ring.v1.RingService/SendEmptyMsg"
,
}
handler
:=
func
(
ctx
context
.
Context
,
req
interface
{})
(
interface
{},
error
)
{
return
srv
.
(
RingServiceServer
)
.
SendEmptyMsg
(
ctx
,
req
.
(
*
EmptyRequest
))
}
return
interceptor
(
ctx
,
in
,
info
,
handler
)
}
func
_RingService_Nonce_Handler
(
srv
interface
{},
ctx
context
.
Context
,
dec
func
(
interface
{})
error
,
interceptor
grpc
.
UnaryServerInterceptor
)
(
interface
{},
error
)
{
in
:=
new
(
NonceRequest
)
if
err
:=
dec
(
in
);
err
!=
nil
{
...
...
@@ -244,6 +309,14 @@ var RingService_ServiceDesc = grpc.ServiceDesc{
MethodName
:
"SendTxAsBytes"
,
Handler
:
_RingService_SendTxAsBytes_Handler
,
},
{
MethodName
:
"SendEmpty"
,
Handler
:
_RingService_SendEmpty_Handler
,
},
{
MethodName
:
"SendEmptyMsg"
,
Handler
:
_RingService_SendEmptyMsg_Handler
,
},
{
MethodName
:
"Nonce"
,
Handler
:
_RingService_Nonce_Handler
,
...
...
grcp-tx_test.go
View file @
86fce5f4
...
...
@@ -17,12 +17,15 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/protobuf/types/known/anypb"
"google.golang.org/protobuf/types/known/emptypb"
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/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"unsafe"
)
var
countParallelAsEth
int64
...
...
@@ -34,6 +37,14 @@ type RingServer struct {
ring
.
UnimplementedRingServiceServer
}
func
(
*
RingServer
)
SendEmptyMsg
(
context
.
Context
,
*
ring
.
EmptyRequest
)
(
*
ring
.
EmptyResponse
,
error
)
{
return
&
ring
.
EmptyResponse
{},
nil
}
func
(
*
RingServer
)
SendEmpty
(
context
.
Context
,
*
emptypb
.
Empty
)
(
*
emptypb
.
Empty
,
error
)
{
return
&
emptypb
.
Empty
{},
nil
}
func
(
*
RingServer
)
SendTxAsEth
(
ctx
context
.
Context
,
in
*
base
.
TransactionEth
)
(
*
ring
.
SendRawTransactionResponse
,
error
)
{
addr
:=
common
.
Address
{}
...
...
@@ -178,10 +189,26 @@ func pricedTransaction(to common.Address, nonce uint64, gaslimit uint64, gaspric
}
// go test -v -run EthTx -bench=. -benchtime=3s
// go test -v -run BenchmarkAnyTxEth -bench BenchmarkAnyTxEth -benchtime=3s -benchmem
// go test -v -run BenchmarkAnyTxStd -bench BenchmarkAnyTxStd -benchtime=3s -benchmem
// go test -v -run BenchmarkEthTx -bench BenchmarkEthTx -benchtime=3s -benchmem
// go test -v -run BenchmarkStdTx -bench BenchmarkStdTx -benchtime=3s -benchmem
// go test -v -run BenchmarkAnyTx -bench BenchmarkAnyTx -benchtime=3s -benchmem
//
//
go test -v -run BenchmarkAnyTx -bench BenchmarkAnyTx -benchtime=3s -benchmem
// go test -v -run BenchmarkBytesEth -bench BenchmarkBytesEth -benchtime=3s -benchmem
// go test -v -run BenchmarkEmpty -bench BenchmarkEmpty -benchtime=3s -benchmem
// go test -v -run BenchmarkEmptyMsg -bench BenchmarkEmptyMsg -benchtime=3s -benchmem
// go test -v -run BenchmarkAnyTxEth -bench BenchmarkAnyTxEth -benchtime=20000x -benchmem
// go test -v -run BenchmarkAnyTxStd -bench BenchmarkAnyTxStd -benchtime=20000x -benchmem
// go test -v -run BenchmarkEthTx -bench BenchmarkEthTx -benchtime=20000x -benchmem
// go test -v -run BenchmarkStdTx -bench BenchmarkStdTx -benchtime=20000x -benchmem
//// go test -v -run BenchmarkAnyTx -bench BenchmarkAnyTx -benchtime=20000x -benchmem
// go test -v -run BenchmarkBytesEth -bench BenchmarkBytesEth -benchtime=20000x -benchmem
// go test -v -run BenchmarkEmpty -bench BenchmarkEmpty -benchtime=20000x -benchmem
// go test -v -run BenchmarkEmptyMsg -bench BenchmarkEmptyMsg -benchtime=20000x -benchmem
//BenchmarkEmptyMsg
// go test -v -run BenchmarkEthTx -bench BenchmarkEthTx -benchtime=1s
// go test -v -run BenchmarkStdTx -bench BenchmarkStdTx -benchtime=1s
...
...
@@ -216,6 +243,10 @@ var fromAddr common.Address
// var local, remote *ecdsa.PrivateKey
func
TestTxSizeOf
(
t
*
testing
.
T
)
{
fmt
.
Println
(
unsafe
.
Sizeof
(
*
tx
))
//88
}
func
int
()
{
local
,
_
:=
crypto
.
HexToECDSA
(
"FD5CC6F5E7E2805E920AC5DC83D5AF1106F9C92F0C04F9D5E1FD4261B4B4464A"
)
...
...
@@ -233,6 +264,64 @@ var countParallel int64
var
onceHash
sync
.
Once
func
BenchmarkEmpty
(
b
*
testing
.
B
)
{
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
()
res
,
err
:=
c
.
SendEmpty
(
ctx
,
&
emptypb
.
Empty
{})
if
err
!=
nil
{
b
.
Fatal
(
err
)
}
_
=
res
}
})
}
func
BenchmarkEmptyMsg
(
b
*
testing
.
B
)
{
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
()
c
.
SendEmptyMsg
(
ctx
,
&
ring
.
EmptyRequest
{})
res
,
err
:=
c
.
SendEmpty
(
ctx
,
&
emptypb
.
Empty
{})
if
err
!=
nil
{
b
.
Fatal
(
err
)
}
_
=
res
}
})
}
func
BenchmarkEthTx
(
b
*
testing
.
B
)
{
b
.
Logf
(
"b.N: %d
\n
"
,
b
.
N
)
...
...
@@ -377,7 +466,7 @@ func BenchmarkStdTx(b *testing.B) {
})
}
func
BenchmarkAnyTx
(
b
*
testing
.
B
)
{
func
BenchmarkAnyTx
Eth
(
b
*
testing
.
B
)
{
onceFunc
:=
func
()
{
local
,
_
:=
crypto
.
HexToECDSA
(
"FD5CC6F5E7E2805E920AC5DC83D5AF1106F9C92F0C04F9D5E1FD4261B4B4464A"
)
...
...
@@ -452,6 +541,81 @@ func BenchmarkAnyTx(b *testing.B) {
})
}
func
BenchmarkAnyTxStd
(
b
*
testing
.
B
)
{
onceFunc
:=
func
()
{
local
,
_
:=
crypto
.
HexToECDSA
(
"FD5CC6F5E7E2805E920AC5DC83D5AF1106F9C92F0C04F9D5E1FD4261B4B4464A"
)
publicKey
:=
local
.
Public
()
publicKeyECDSA
,
_
:=
publicKey
.
(
*
ecdsa
.
PublicKey
)
fromAddr
=
crypto
.
PubkeyToAddress
(
*
publicKeyECDSA
)
remote
,
_
:=
crypto
.
GenerateKey
()
tx
=
pricedTransaction
(
crypto
.
PubkeyToAddress
(
remote
.
PublicKey
),
0
,
100000
,
big
.
NewInt
(
1
),
local
)
}
once
.
Do
(
onceFunc
)
b
.
ResetTimer
()
// The loop body is executed b.N times total across all goroutines.
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
.
StdTxData
{
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
stdTx
:=
base
.
StdTx
{
Inner
:
&
inner
}
stdTxAsAny
,
err
:=
anypb
.
New
(
&
stdTx
)
res
,
err
:=
c
.
SendTxAsAny
(
ctx
,
&
base
.
Transaction
{
Tx
:
stdTxAsAny
})
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
BenchmarkBytesEth
(
b
*
testing
.
B
)
{
onceFunc
:=
func
()
{
...
...
ringapi/ring/v1/service.proto
View file @
86fce5f4
...
...
@@ -7,6 +7,8 @@ import "ring/v1/request_response.proto";
import
"ring/v1/account_req_res.proto"
;
import
"base/v1/resource.proto"
;
// import "google/protobuf/empty.proto";
service
RingService
{
// account info service
...
...
@@ -18,7 +20,16 @@ service RingService{
rpc
SendTxAsBytes
(
base.v1.TransactionBytes
)
returns
(
SendRawTransactionResponse
)
{};
rpc
SendEmpty
(
google.protobuf.Empty
)
returns
(
google.protobuf.Empty
)
{};
rpc
SendEmptyMsg
(
EmptyRequest
)
returns
(
EmptyResponse
)
{};
//rpc SendRawTransaction(base.v1.EthTx) returns (SendRawTransactionResponse) {};
rpc
Nonce
(
NonceRequest
)
returns
(
NonceResponse
)
{};
}
message
EmptyRequest
{
}
message
EmptyResponse
{
}
\ No newline at end of file
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