From 5e009ee6d903abe066f1f170323c73a6d20144ae Mon Sep 17 00:00:00 2001 From: Bartosz Lenart Date: Wed, 6 Mar 2024 16:27:20 +0100 Subject: [PATCH] 380: Get lacking parent vertex from the connected nodes. (#382) --- artefacts/test_wallet | Bin 175 -> 175 bytes protobuf/gossip.proto | 1 + src/accountant/accountant.go | 13 ++- src/accountant/replier.go | 4 +- src/cmd/wallet/main.go | 14 +-- src/gossip/gossip.go | 115 +++++++++++++++++++------ src/protobufcompiled/gossip.pb.go | 37 ++++---- src/protobufcompiled/gossip_grpc.pb.go | 36 ++++++++ src/spice/spice.go | 10 --- src/spice/spice_test.go | 22 ----- 10 files changed, 171 insertions(+), 81 deletions(-) diff --git a/artefacts/test_wallet b/artefacts/test_wallet index a65ffa1cef13d2051581bc5226e702a0ce8053c9..7c0755f439d74004780f0fde932d373410ff8af4 100644 GIT binary patch literal 175 zcmV;g08sx(Cyw&YW-IGVU})@=|9YK!GFAWPffXT`NZOW*5!N!-MSH}Yz$^XVoe(gb zb_8-}lt0=;?U|3U>FtRak3V`-ZVy#ylq*7Xl^l=9yUdbmSh_;>VY0>5`KpO+!p9Mm zta)M8p>rer)z7Uy^1`vpGoz7TP**R;(!k&TH`!6QjKuh() deRCYsz`#R1Pc$m%NLtTis~ak{w6JcE^~Y_UTekoJ literal 175 zcmV;g08szUc4q}b7g7R^<8oPDXtaz&Q-#`5LV#4CIR)u06SZc0K~PVYsXFruUH6UK zaYqaRKiUhfc9+wa>OTNwpq2e~4MQoq^PG$anz?_JVQWZa-j8}-nK^%5O9L)wSohSj zRlRG3^v+d9c)SIXvyh?&0GJr-?@c~)NzazC7;vv(tM$^UIhm!}Hna+LZ?j^72seWo dsE}Qshmqr;*F#byK?hnZycp34xmK17uCH8 computantis.Transaction @@ -566,14 +571,16 @@ var file_gossip_proto_depIdxs = []int32{ 4, // 9: computantis.GossipAPI.Discover:input_type -> computantis.ConnectionData 2, // 10: computantis.GossipAPI.GossipVrx:input_type -> computantis.VrxMsgGossip 3, // 11: computantis.GossipAPI.GossipTrx:input_type -> computantis.TrxMsgGossip - 8, // 12: computantis.GossipAPI.Alive:output_type -> computantis.AliveData - 0, // 13: computantis.GossipAPI.LoadDag:output_type -> computantis.Vertex - 7, // 14: computantis.GossipAPI.Announce:output_type -> google.protobuf.Empty - 5, // 15: computantis.GossipAPI.Discover:output_type -> computantis.ConnectedNodes - 7, // 16: computantis.GossipAPI.GossipVrx:output_type -> google.protobuf.Empty - 7, // 17: computantis.GossipAPI.GossipTrx:output_type -> google.protobuf.Empty - 12, // [12:18] is the sub-list for method output_type - 6, // [6:12] is the sub-list for method input_type + 8, // 12: computantis.GossipAPI.GetVertex:input_type -> computantis.SignedHash + 9, // 13: computantis.GossipAPI.Alive:output_type -> computantis.AliveData + 0, // 14: computantis.GossipAPI.LoadDag:output_type -> computantis.Vertex + 7, // 15: computantis.GossipAPI.Announce:output_type -> google.protobuf.Empty + 5, // 16: computantis.GossipAPI.Discover:output_type -> computantis.ConnectedNodes + 7, // 17: computantis.GossipAPI.GossipVrx:output_type -> google.protobuf.Empty + 7, // 18: computantis.GossipAPI.GossipTrx:output_type -> google.protobuf.Empty + 0, // 19: computantis.GossipAPI.GetVertex:output_type -> computantis.Vertex + 13, // [13:20] is the sub-list for method output_type + 6, // [6:13] is the sub-list for method input_type 6, // [6:6] is the sub-list for extension type_name 6, // [6:6] is the sub-list for extension extendee 0, // [0:6] is the sub-list for field type_name diff --git a/src/protobufcompiled/gossip_grpc.pb.go b/src/protobufcompiled/gossip_grpc.pb.go index 413a590..5c37c7b 100644 --- a/src/protobufcompiled/gossip_grpc.pb.go +++ b/src/protobufcompiled/gossip_grpc.pb.go @@ -29,6 +29,7 @@ type GossipAPIClient interface { Discover(ctx context.Context, in *ConnectionData, opts ...grpc.CallOption) (*ConnectedNodes, error) GossipVrx(ctx context.Context, in *VrxMsgGossip, opts ...grpc.CallOption) (*emptypb.Empty, error) GossipTrx(ctx context.Context, in *TrxMsgGossip, opts ...grpc.CallOption) (*emptypb.Empty, error) + GetVertex(ctx context.Context, in *SignedHash, opts ...grpc.CallOption) (*Vertex, error) } type gossipAPIClient struct { @@ -116,6 +117,15 @@ func (c *gossipAPIClient) GossipTrx(ctx context.Context, in *TrxMsgGossip, opts return out, nil } +func (c *gossipAPIClient) GetVertex(ctx context.Context, in *SignedHash, opts ...grpc.CallOption) (*Vertex, error) { + out := new(Vertex) + err := c.cc.Invoke(ctx, "/computantis.GossipAPI/GetVertex", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // GossipAPIServer is the server API for GossipAPI service. // All implementations must embed UnimplementedGossipAPIServer // for forward compatibility @@ -126,6 +136,7 @@ type GossipAPIServer interface { Discover(context.Context, *ConnectionData) (*ConnectedNodes, error) GossipVrx(context.Context, *VrxMsgGossip) (*emptypb.Empty, error) GossipTrx(context.Context, *TrxMsgGossip) (*emptypb.Empty, error) + GetVertex(context.Context, *SignedHash) (*Vertex, error) mustEmbedUnimplementedGossipAPIServer() } @@ -151,6 +162,9 @@ func (UnimplementedGossipAPIServer) GossipVrx(context.Context, *VrxMsgGossip) (* func (UnimplementedGossipAPIServer) GossipTrx(context.Context, *TrxMsgGossip) (*emptypb.Empty, error) { return nil, status.Errorf(codes.Unimplemented, "method GossipTrx not implemented") } +func (UnimplementedGossipAPIServer) GetVertex(context.Context, *SignedHash) (*Vertex, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetVertex not implemented") +} func (UnimplementedGossipAPIServer) mustEmbedUnimplementedGossipAPIServer() {} // UnsafeGossipAPIServer may be embedded to opt out of forward compatibility for this service. @@ -275,6 +289,24 @@ func _GossipAPI_GossipTrx_Handler(srv interface{}, ctx context.Context, dec func return interceptor(ctx, in, info, handler) } +func _GossipAPI_GetVertex_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(SignedHash) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(GossipAPIServer).GetVertex(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/computantis.GossipAPI/GetVertex", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(GossipAPIServer).GetVertex(ctx, req.(*SignedHash)) + } + return interceptor(ctx, in, info, handler) +} + // GossipAPI_ServiceDesc is the grpc.ServiceDesc for GossipAPI service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -302,6 +334,10 @@ var GossipAPI_ServiceDesc = grpc.ServiceDesc{ MethodName: "GossipTrx", Handler: _GossipAPI_GossipTrx_Handler, }, + { + MethodName: "GetVertex", + Handler: _GossipAPI_GetVertex_Handler, + }, }, Streams: []grpc.StreamDesc{ { diff --git a/src/spice/spice.go b/src/spice/spice.go index ecfe4cd..0e25866 100644 --- a/src/spice/spice.go +++ b/src/spice/spice.go @@ -51,16 +51,6 @@ func convertFloatToInt(d float64) (int, int) { return intPart, fractionalPart } -func GetSientific(v uint64) string { - var zeros int - for v%10 == 0 { - zeros++ - v /= 10 - } - - return fmt.Sprintf("%v*10^%v", v, zeros) -} - // Melange is an asset that is digitally transferable between two wallets. type Melange struct { Currency uint64 `yaml:"currency" msgpack:"currency"` diff --git a/src/spice/spice_test.go b/src/spice/spice_test.go index 287055a..9e94313 100644 --- a/src/spice/spice_test.go +++ b/src/spice/spice_test.go @@ -159,28 +159,6 @@ func BenchmarkMelangeTransfer(b *testing.B) { } } -func TestPrintGetScientific(t *testing.T) { - cases := []uint64{ - 10, - 100, - 1000, - 10000, - 100000, - 1000000, - 1100000, - 1110000, - 1111000, - 1111100, - 1111110, - } - for _, c := range cases { - t.Run(fmt.Sprintf("get scientific test case %v", c), func(t *testing.T) { - s := GetSientific(c) - fmt.Printf("%s\n", s) - }) - } -} - func TestFromFloat(t *testing.T) { cases := []struct { expected string