From 0f265e6f2776253f97ab1513e811e1e81ad6fe55 Mon Sep 17 00:00:00 2001 From: ivansukach <47761294+ivansukach@users.noreply.github.com> Date: Thu, 2 May 2024 21:02:01 +0200 Subject: [PATCH] introduce messenger and toEngine channel (#15) * introduce messenger and toEngine channel * get rid of avalanchego libs, add toEngine * get rid of grpcutils * regenerate proto files with buf 1.31.0 * close goroutine that listen toEngine * add transport credentials * add http import * use mock for gRPC client connection for unit tests * mempool handler: trigger `toEngine` channel when transaction appear in mempool * fix static check error: should use for range instead of for { select {} } (S1000) https://github.com/dominikh/go-tools/issues/503#issuecomment-497020529 --------- Co-authored-by: Ivan Sukach Co-authored-by: ramil --- proto/messenger/messenger.pb.go | 265 +++++++++++++++++++++++++++ proto/messenger/messenger.proto | 21 +++ proto/messenger/messenger_grpc.pb.go | 107 +++++++++++ vm/vm.go | 72 +++++++- vm/vm_test.go | 42 +++-- 5 files changed, 490 insertions(+), 17 deletions(-) create mode 100644 proto/messenger/messenger.pb.go create mode 100644 proto/messenger/messenger.proto create mode 100644 proto/messenger/messenger_grpc.pb.go diff --git a/proto/messenger/messenger.pb.go b/proto/messenger/messenger.pb.go new file mode 100644 index 0000000..2f740f9 --- /dev/null +++ b/proto/messenger/messenger.pb.go @@ -0,0 +1,265 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.33.0 +// protoc (unknown) +// source: messenger/messenger.proto + +package messenger + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type Message int32 + +const ( + Message_MESSAGE_UNSPECIFIED Message = 0 + Message_MESSAGE_BUILD_BLOCK Message = 1 + Message_MESSAGE_STATE_SYNC_FINISHED Message = 2 +) + +// Enum value maps for Message. +var ( + Message_name = map[int32]string{ + 0: "MESSAGE_UNSPECIFIED", + 1: "MESSAGE_BUILD_BLOCK", + 2: "MESSAGE_STATE_SYNC_FINISHED", + } + Message_value = map[string]int32{ + "MESSAGE_UNSPECIFIED": 0, + "MESSAGE_BUILD_BLOCK": 1, + "MESSAGE_STATE_SYNC_FINISHED": 2, + } +) + +func (x Message) Enum() *Message { + p := new(Message) + *p = x + return p +} + +func (x Message) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (Message) Descriptor() protoreflect.EnumDescriptor { + return file_messenger_messenger_proto_enumTypes[0].Descriptor() +} + +func (Message) Type() protoreflect.EnumType { + return &file_messenger_messenger_proto_enumTypes[0] +} + +func (x Message) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use Message.Descriptor instead. +func (Message) EnumDescriptor() ([]byte, []int) { + return file_messenger_messenger_proto_rawDescGZIP(), []int{0} +} + +type NotifyRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Message Message `protobuf:"varint,1,opt,name=message,proto3,enum=messenger.Message" json:"message,omitempty"` +} + +func (x *NotifyRequest) Reset() { + *x = NotifyRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_messenger_messenger_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *NotifyRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*NotifyRequest) ProtoMessage() {} + +func (x *NotifyRequest) ProtoReflect() protoreflect.Message { + mi := &file_messenger_messenger_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use NotifyRequest.ProtoReflect.Descriptor instead. +func (*NotifyRequest) Descriptor() ([]byte, []int) { + return file_messenger_messenger_proto_rawDescGZIP(), []int{0} +} + +func (x *NotifyRequest) GetMessage() Message { + if x != nil { + return x.Message + } + return Message_MESSAGE_UNSPECIFIED +} + +type NotifyResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *NotifyResponse) Reset() { + *x = NotifyResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_messenger_messenger_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *NotifyResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*NotifyResponse) ProtoMessage() {} + +func (x *NotifyResponse) ProtoReflect() protoreflect.Message { + mi := &file_messenger_messenger_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use NotifyResponse.ProtoReflect.Descriptor instead. +func (*NotifyResponse) Descriptor() ([]byte, []int) { + return file_messenger_messenger_proto_rawDescGZIP(), []int{1} +} + +var File_messenger_messenger_proto protoreflect.FileDescriptor + +var file_messenger_messenger_proto_rawDesc = []byte{ + 0x0a, 0x19, 0x6d, 0x65, 0x73, 0x73, 0x65, 0x6e, 0x67, 0x65, 0x72, 0x2f, 0x6d, 0x65, 0x73, 0x73, + 0x65, 0x6e, 0x67, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x09, 0x6d, 0x65, 0x73, + 0x73, 0x65, 0x6e, 0x67, 0x65, 0x72, 0x22, 0x3d, 0x0a, 0x0d, 0x4e, 0x6f, 0x74, 0x69, 0x66, 0x79, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x2c, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, + 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x12, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x65, + 0x6e, 0x67, 0x65, 0x72, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x07, 0x6d, 0x65, + 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x10, 0x0a, 0x0e, 0x4e, 0x6f, 0x74, 0x69, 0x66, 0x79, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2a, 0x5c, 0x0a, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, + 0x67, 0x65, 0x12, 0x17, 0x0a, 0x13, 0x4d, 0x45, 0x53, 0x53, 0x41, 0x47, 0x45, 0x5f, 0x55, 0x4e, + 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x17, 0x0a, 0x13, 0x4d, + 0x45, 0x53, 0x53, 0x41, 0x47, 0x45, 0x5f, 0x42, 0x55, 0x49, 0x4c, 0x44, 0x5f, 0x42, 0x4c, 0x4f, + 0x43, 0x4b, 0x10, 0x01, 0x12, 0x1f, 0x0a, 0x1b, 0x4d, 0x45, 0x53, 0x53, 0x41, 0x47, 0x45, 0x5f, + 0x53, 0x54, 0x41, 0x54, 0x45, 0x5f, 0x53, 0x59, 0x4e, 0x43, 0x5f, 0x46, 0x49, 0x4e, 0x49, 0x53, + 0x48, 0x45, 0x44, 0x10, 0x02, 0x32, 0x4a, 0x0a, 0x09, 0x4d, 0x65, 0x73, 0x73, 0x65, 0x6e, 0x67, + 0x65, 0x72, 0x12, 0x3d, 0x0a, 0x06, 0x4e, 0x6f, 0x74, 0x69, 0x66, 0x79, 0x12, 0x18, 0x2e, 0x6d, + 0x65, 0x73, 0x73, 0x65, 0x6e, 0x67, 0x65, 0x72, 0x2e, 0x4e, 0x6f, 0x74, 0x69, 0x66, 0x79, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x65, 0x6e, 0x67, + 0x65, 0x72, 0x2e, 0x4e, 0x6f, 0x74, 0x69, 0x66, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x42, 0x37, 0x5a, 0x35, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, + 0x63, 0x6f, 0x6e, 0x73, 0x69, 0x64, 0x65, 0x72, 0x69, 0x74, 0x64, 0x6f, 0x6e, 0x65, 0x2f, 0x6c, + 0x61, 0x6e, 0x64, 0x73, 0x6c, 0x69, 0x64, 0x65, 0x76, 0x6d, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x2f, 0x6d, 0x65, 0x73, 0x73, 0x65, 0x6e, 0x67, 0x65, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, +} + +var ( + file_messenger_messenger_proto_rawDescOnce sync.Once + file_messenger_messenger_proto_rawDescData = file_messenger_messenger_proto_rawDesc +) + +func file_messenger_messenger_proto_rawDescGZIP() []byte { + file_messenger_messenger_proto_rawDescOnce.Do(func() { + file_messenger_messenger_proto_rawDescData = protoimpl.X.CompressGZIP(file_messenger_messenger_proto_rawDescData) + }) + return file_messenger_messenger_proto_rawDescData +} + +var file_messenger_messenger_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_messenger_messenger_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_messenger_messenger_proto_goTypes = []interface{}{ + (Message)(0), // 0: messenger.Message + (*NotifyRequest)(nil), // 1: messenger.NotifyRequest + (*NotifyResponse)(nil), // 2: messenger.NotifyResponse +} +var file_messenger_messenger_proto_depIdxs = []int32{ + 0, // 0: messenger.NotifyRequest.message:type_name -> messenger.Message + 1, // 1: messenger.Messenger.Notify:input_type -> messenger.NotifyRequest + 2, // 2: messenger.Messenger.Notify:output_type -> messenger.NotifyResponse + 2, // [2:3] is the sub-list for method output_type + 1, // [1:2] is the sub-list for method input_type + 1, // [1:1] is the sub-list for extension type_name + 1, // [1:1] is the sub-list for extension extendee + 0, // [0:1] is the sub-list for field type_name +} + +func init() { file_messenger_messenger_proto_init() } +func file_messenger_messenger_proto_init() { + if File_messenger_messenger_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_messenger_messenger_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*NotifyRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_messenger_messenger_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*NotifyResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_messenger_messenger_proto_rawDesc, + NumEnums: 1, + NumMessages: 2, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_messenger_messenger_proto_goTypes, + DependencyIndexes: file_messenger_messenger_proto_depIdxs, + EnumInfos: file_messenger_messenger_proto_enumTypes, + MessageInfos: file_messenger_messenger_proto_msgTypes, + }.Build() + File_messenger_messenger_proto = out.File + file_messenger_messenger_proto_rawDesc = nil + file_messenger_messenger_proto_goTypes = nil + file_messenger_messenger_proto_depIdxs = nil +} diff --git a/proto/messenger/messenger.proto b/proto/messenger/messenger.proto new file mode 100644 index 0000000..fe3ec8f --- /dev/null +++ b/proto/messenger/messenger.proto @@ -0,0 +1,21 @@ +syntax = "proto3"; + +package messenger; + +option go_package = "github.com/consideritdone/landslidevm/proto/messenger"; + +service Messenger { + rpc Notify(NotifyRequest) returns (NotifyResponse); +} + +enum Message { + MESSAGE_UNSPECIFIED = 0; + MESSAGE_BUILD_BLOCK = 1; + MESSAGE_STATE_SYNC_FINISHED = 2; +} + +message NotifyRequest { + Message message = 1; +} + +message NotifyResponse {} diff --git a/proto/messenger/messenger_grpc.pb.go b/proto/messenger/messenger_grpc.pb.go new file mode 100644 index 0000000..6ebf49a --- /dev/null +++ b/proto/messenger/messenger_grpc.pb.go @@ -0,0 +1,107 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.3.0 +// - protoc (unknown) +// source: messenger/messenger.proto + +package messenger + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +const ( + Messenger_Notify_FullMethodName = "/messenger.Messenger/Notify" +) + +// MessengerClient is the client API for Messenger service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type MessengerClient interface { + Notify(ctx context.Context, in *NotifyRequest, opts ...grpc.CallOption) (*NotifyResponse, error) +} + +type messengerClient struct { + cc grpc.ClientConnInterface +} + +func NewMessengerClient(cc grpc.ClientConnInterface) MessengerClient { + return &messengerClient{cc} +} + +func (c *messengerClient) Notify(ctx context.Context, in *NotifyRequest, opts ...grpc.CallOption) (*NotifyResponse, error) { + out := new(NotifyResponse) + err := c.cc.Invoke(ctx, Messenger_Notify_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MessengerServer is the server API for Messenger service. +// All implementations should embed UnimplementedMessengerServer +// for forward compatibility +type MessengerServer interface { + Notify(context.Context, *NotifyRequest) (*NotifyResponse, error) +} + +// UnimplementedMessengerServer should be embedded to have forward compatible implementations. +type UnimplementedMessengerServer struct { +} + +func (UnimplementedMessengerServer) Notify(context.Context, *NotifyRequest) (*NotifyResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Notify not implemented") +} + +// UnsafeMessengerServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to MessengerServer will +// result in compilation errors. +type UnsafeMessengerServer interface { + mustEmbedUnimplementedMessengerServer() +} + +func RegisterMessengerServer(s grpc.ServiceRegistrar, srv MessengerServer) { + s.RegisterService(&Messenger_ServiceDesc, srv) +} + +func _Messenger_Notify_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(NotifyRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MessengerServer).Notify(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Messenger_Notify_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MessengerServer).Notify(ctx, req.(*NotifyRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// Messenger_ServiceDesc is the grpc.ServiceDesc for Messenger service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var Messenger_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "messenger.Messenger", + HandlerType: (*MessengerServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Notify", + Handler: _Messenger_Notify_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "messenger/messenger.proto", +} diff --git a/vm/vm.go b/vm/vm.go index b1d7e58..fa520d3 100644 --- a/vm/vm.go +++ b/vm/vm.go @@ -12,6 +12,8 @@ import ( "sync" "time" + messengerpb "github.com/consideritdone/landslidevm/proto/messenger" + dbm "github.com/cometbft/cometbft-db" abcitypes "github.com/cometbft/cometbft/abci/types" "github.com/cometbft/cometbft/config" @@ -105,6 +107,9 @@ type ( appOpts *AppCreatorOpts logger log.Logger + toEngine chan messengerpb.Message + closed chan struct{} + blockStore *store.BlockStore stateStore state.Store state state.State @@ -125,6 +130,8 @@ type ( vmconnected *vmtypes.Atomic[bool] verifiedBlocks sync.Map preferred [32]byte + + clientConn grpc.ClientConnInterface } ) @@ -132,8 +139,8 @@ func New(creator AppCreator) *LandslideVM { return NewViaDB(nil, creator) } -func NewViaDB(database dbm.DB, creator AppCreator) *LandslideVM { - return &LandslideVM{ +func NewViaDB(database dbm.DB, creator AppCreator, options ...func(*LandslideVM)) *LandslideVM { + vm := &LandslideVM{ appCreator: creator, database: database, allowShutdown: vmtypes.NewAtomic(true), @@ -143,6 +150,18 @@ func NewViaDB(database dbm.DB, creator AppCreator) *LandslideVM { bootstrapped: vmtypes.NewAtomic(false), verifiedBlocks: sync.Map{}, } + + for _, o := range options { + o(vm) + } + + return vm +} + +func WithClientConn(clientConn grpc.ClientConnInterface) func(vm *LandslideVM) { + return func(vm *LandslideVM) { + vm.clientConn = clientConn + } } // Initialize this VM. @@ -170,6 +189,45 @@ func (vm *LandslideVM) Initialize(_ context.Context, req *vmpb.InitializeRequest // Register metrics for each Go plugin processes vm.processMetrics = registerer + if vm.clientConn == nil { + clientConn, err := grpc.Dial( + "passthrough:///"+req.ServerAddr, + grpc.WithChainUnaryInterceptor(grpcClientMetrics.UnaryClientInterceptor()), + grpc.WithChainStreamInterceptor(grpcClientMetrics.StreamClientInterceptor()), + grpc.WithTransportCredentials(insecure.NewCredentials()), + ) + if err != nil { + // Ignore closing errors to return the original error + _ = vm.connCloser.Close() + return nil, err + } + + // TODO: add to connCloser even we have defined vm.clientConn via Option + vm.connCloser.Add(clientConn) + vm.clientConn = clientConn + } + + msgClient := messengerpb.NewMessengerClient(vm.clientConn) + + vm.toEngine = make(chan messengerpb.Message, 1) + vm.closed = make(chan struct{}) + go func() { + for { + select { + case msg, ok := <-vm.toEngine: + if !ok { + return + } + // Nothing to do with the error within the goroutine + _, _ = msgClient.Notify(context.Background(), &messengerpb.NotifyRequest{ + Message: msg, + }) + case <-vm.closed: + return + } + } + }() + // Dial the database if vm.database == nil { dbClientConn, err := grpc.Dial( @@ -279,6 +337,13 @@ func (vm *LandslideVM) Initialize(_ context.Context, req *vmpb.InitializeRequest vm.mempool.SetLogger(vm.logger.With("module", "mempool")) vm.mempool.EnableTxsAvailable() + go func() { + for { + <-vm.mempool.TxsAvailable() + vm.toEngine <- messengerpb.Message_MESSAGE_BUILD_BLOCK + } + }() + var blk *types.Block if vm.state.LastBlockHeight > 0 { blk = vm.blockStore.LoadBlock(vm.state.LastBlockHeight) @@ -362,6 +427,9 @@ func (vm *LandslideVM) CanShutdown() bool { // Shutdown is called when the node is shutting down. func (vm *LandslideVM) Shutdown(context.Context, *emptypb.Empty) (*emptypb.Empty, error) { vm.allowShutdown.Set(true) + if vm.closed != nil { + close(vm.closed) + } var err error if vm.indexerService != nil { err = vm.indexerService.Stop() diff --git a/vm/vm_test.go b/vm/vm_test.go index f5ce75e..dc4e31c 100644 --- a/vm/vm_test.go +++ b/vm/vm_test.go @@ -7,8 +7,8 @@ import ( dbm "github.com/cometbft/cometbft-db" "github.com/cometbft/cometbft/abci/example/kvstore" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "google.golang.org/grpc" vmpb "github.com/consideritdone/landslidevm/proto/vm" ) @@ -18,25 +18,37 @@ var ( kvstorevmGenesis []byte ) +type mockClientConn struct { +} + +func (m *mockClientConn) Invoke(ctx context.Context, method string, args any, reply any, opts ...grpc.CallOption) error { + return nil +} + +func (m *mockClientConn) NewStream(ctx context.Context, desc *grpc.StreamDesc, method string, opts ...grpc.CallOption) (grpc.ClientStream, error) { + return nil, nil +} + func newKvApp(t *testing.T, vmdb, appdb dbm.DB) vmpb.VMServer { + mockConn := &mockClientConn{} vm := NewViaDB(vmdb, func(*AppCreatorOpts) (Application, error) { return kvstore.NewApplication(appdb), nil - }) + }, WithClientConn(mockConn)) require.NotNil(t, vm) initRes, err := vm.Initialize(context.TODO(), &vmpb.InitializeRequest{ DbServerAddr: "inmemory", GenesisBytes: kvstorevmGenesis, }) - assert.NoError(t, err) - assert.NotNil(t, initRes) - assert.Equal(t, initRes.Height, uint64(1)) + require.NoError(t, err) + require.NotNil(t, initRes) + require.Equal(t, initRes.Height, uint64(1)) blockRes, err := vm.GetBlock(context.TODO(), &vmpb.GetBlockRequest{ Id: initRes.LastAcceptedId, }) - assert.NoError(t, err) - assert.NotNil(t, blockRes) - assert.NotEqual(t, blockRes.Err, vmpb.Error_ERROR_NOT_FOUND) + require.NoError(t, err) + require.NotNil(t, blockRes) + require.NotEqual(t, blockRes.Err, vmpb.Error_ERROR_NOT_FOUND) return vm } @@ -67,11 +79,11 @@ func TestBuildBlock(t *testing.T) { buildRes1, err := vm.BuildBlock(context.Background(), &vmpb.BuildBlockRequest{}) require.NoError(t, err) - assert.Equal(t, buildRes1.Height, uint64(2)) + require.Equal(t, buildRes1.Height, uint64(2)) buildRes2, err := vm.BuildBlock(context.Background(), &vmpb.BuildBlockRequest{}) require.NoError(t, err) - assert.Equal(t, buildRes2.Height, uint64(2)) + require.Equal(t, buildRes2.Height, uint64(2)) } func TestRejectBlock(t *testing.T) { @@ -79,21 +91,21 @@ func TestRejectBlock(t *testing.T) { buildRes1, err := vm.BuildBlock(context.Background(), &vmpb.BuildBlockRequest{}) require.NoError(t, err) - assert.Equal(t, buildRes1.Height, uint64(2)) + require.Equal(t, buildRes1.Height, uint64(2)) buildRes2, err := vm.BuildBlock(context.Background(), &vmpb.BuildBlockRequest{}) require.NoError(t, err) - assert.Equal(t, buildRes2.Height, uint64(2)) + require.Equal(t, buildRes2.Height, uint64(2)) _, err = vm.BlockReject(context.Background(), &vmpb.BlockRejectRequest{ Id: buildRes1.Id, }) - assert.NoError(t, err) + require.NoError(t, err) _, err = vm.BlockReject(context.Background(), &vmpb.BlockRejectRequest{ Id: buildRes2.Id, }) - assert.NoError(t, err) + require.NoError(t, err) } func TestAcceptBlock(t *testing.T) { @@ -101,7 +113,7 @@ func TestAcceptBlock(t *testing.T) { buildRes, err := vm.BuildBlock(context.Background(), &vmpb.BuildBlockRequest{}) require.NoError(t, err) - assert.Equal(t, buildRes.Height, uint64(2)) + require.Equal(t, buildRes.Height, uint64(2)) _, err = vm.BlockAccept(context.Background(), &vmpb.BlockAcceptRequest{ Id: buildRes.GetId(),