diff --git a/.go-version b/.go-version deleted file mode 100644 index 88ebadf2c..000000000 --- a/.go-version +++ /dev/null @@ -1 +0,0 @@ -1.19.10 diff --git a/config/config.go b/config/config.go index 9c6167b81..b16e918bc 100644 --- a/config/config.go +++ b/config/config.go @@ -5,6 +5,7 @@ import ( "path/filepath" "time" + "github.com/dymensionxyz/dymint/da/grpc" "github.com/dymensionxyz/dymint/settlement" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -32,7 +33,9 @@ type NodeConfig struct { SettlementLayer string `mapstructure:"settlement_layer"` SettlementConfig settlement.Config `mapstructure:",squash"` Instrumentation *InstrumentationConfig `mapstructure:"instrumentation"` - BootstrapTime time.Duration `mapstructure:"bootstrap_time"` + //Config params for mock grpc da + DAGrpc grpc.Config `mapstructure:",squash"` + BootstrapTime time.Duration `mapstructure:"bootstrap_time"` } // BlockManagerConfig consists of all parameters required by BlockManagerConfig diff --git a/config/defaults.go b/config/defaults.go index 307e08aa4..8346ba86f 100644 --- a/config/defaults.go +++ b/config/defaults.go @@ -4,6 +4,7 @@ import ( "path/filepath" "time" + "github.com/dymensionxyz/dymint/da/grpc" "github.com/dymensionxyz/dymint/settlement" ) @@ -50,6 +51,13 @@ func DefaultConfig(home, chainId string) *NodeConfig { chainId = DefaultChainID } + //Setting default params for sl grpc mock + defaultSlGrpcConfig := settlement.GrpcConfig{ + Host: "127.0.0.1", + Port: 7981, + RefreshTime: 1000, + } + defaultSLconfig := settlement.Config{ KeyringBackend: "test", NodeAddress: "http://127.0.0.1:36657", @@ -57,8 +65,16 @@ func DefaultConfig(home, chainId string) *NodeConfig { KeyringHomeDir: keyringDir, DymAccountName: "sequencer", GasPrices: "0.025udym", + SLGrpc: defaultSlGrpcConfig, } cfg.SettlementConfig = defaultSLconfig + //Setting default params for da grpc mock + defaultDAGrpc := grpc.Config{ + Host: "127.0.0.1", + Port: 7980, + } + cfg.DAGrpc = defaultDAGrpc + return cfg } diff --git a/settlement/config.go b/settlement/config.go index 71d633148..1ee1b2183 100644 --- a/settlement/config.go +++ b/settlement/config.go @@ -15,6 +15,14 @@ type Config struct { //For testing only. probably should be refactored ProposerPubKey string `json:"proposer_pub_key"` + //Config used for sl shared grpc mock + SLGrpc GrpcConfig `mapstructure:",squash"` +} + +type GrpcConfig struct { + Host string `json:"host"` + Port int `json:"port"` + RefreshTime int `json:"refresh_time"` } func (c Config) Validate() error { diff --git a/settlement/grpc/grpc.go b/settlement/grpc/grpc.go new file mode 100644 index 000000000..8dcd036a7 --- /dev/null +++ b/settlement/grpc/grpc.go @@ -0,0 +1,319 @@ +package grpc + +import ( + "context" + "crypto/rand" + "encoding/hex" + "encoding/json" + "errors" + "path/filepath" + "strconv" + "sync/atomic" + "time" + + "github.com/libp2p/go-libp2p/core/crypto" + tmp2p "github.com/tendermint/tendermint/p2p" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" + + "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + rollapptypes "github.com/dymensionxyz/dymension/x/rollapp/types" + "github.com/dymensionxyz/dymint/da" + "github.com/dymensionxyz/dymint/log" + "github.com/dymensionxyz/dymint/settlement" + "github.com/dymensionxyz/dymint/types" + + "github.com/tendermint/tendermint/libs/pubsub" + + slmock "github.com/dymensionxyz/dymint/settlement/grpc/mockserv/proto" +) + +// LayerClient is an extension of the base settlement layer client +// for usage in tests and local development. +type LayerClient struct { + *settlement.BaseLayerClient +} + +var _ settlement.LayerI = (*LayerClient)(nil) + +// Init initializes the mock layer client. +func (m *LayerClient) Init(config settlement.Config, pubsub *pubsub.Server, logger log.Logger, options ...settlement.Option) error { + HubClientMock, err := newHubClient(config, pubsub, logger) + if err != nil { + return err + } + baseOptions := []settlement.Option{ + settlement.WithHubClient(HubClientMock), + } + if options == nil { + options = baseOptions + } else { + options = append(baseOptions, options...) + } + m.BaseLayerClient = &settlement.BaseLayerClient{} + err = m.BaseLayerClient.Init(config, pubsub, logger, options...) + if err != nil { + return err + } + return nil +} + +// HubClient implements The HubClient interface +type HubGrpcClient struct { + ctx context.Context + ProposerPubKey string + slStateIndex uint64 + logger log.Logger + pubsub *pubsub.Server + latestHeight uint64 + conn *grpc.ClientConn + sl slmock.MockSLClient + stopchan chan struct{} + refreshTime int +} + +var _ settlement.HubClient = &HubGrpcClient{} + +func newHubClient(config settlement.Config, pubsub *pubsub.Server, logger log.Logger) (*HubGrpcClient, error) { + ctx := context.Background() + + latestHeight := uint64(0) + slStateIndex := uint64(0) + proposer, err := initConfig(config) + if err != nil { + return nil, err + } + var opts []grpc.DialOption + opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials())) + + logger.Debug("GRPC Dial ", "ip", config.SLGrpc.Host) + + conn, err := grpc.Dial(config.SLGrpc.Host+":"+strconv.Itoa(config.SLGrpc.Port), opts...) + if err != nil { + logger.Error("Error grpc sl connecting") + return nil, err + } + + client := slmock.NewMockSLClient(conn) + stopchan := make(chan struct{}) + + index, err := client.GetIndex(ctx, &slmock.SLGetIndexRequest{}) + if err == nil { + slStateIndex = index.GetIndex() + var settlementBatch rollapptypes.MsgUpdateState + batchReply, err := client.GetBatch(ctx, &slmock.SLGetBatchRequest{Index: slStateIndex}) + if err != nil { + return nil, err + } + err = json.Unmarshal(batchReply.GetBatch(), &settlementBatch) + if err != nil { + return nil, errors.New("error unmarshalling batch") + } + latestHeight = settlementBatch.StartHeight + settlementBatch.NumBlocks - 1 + } + logger.Debug("Starting grpc SL ", "index", slStateIndex) + + return &HubGrpcClient{ + ctx: ctx, + ProposerPubKey: proposer, + logger: logger, + pubsub: pubsub, + latestHeight: latestHeight, + slStateIndex: slStateIndex, + conn: conn, + sl: client, + stopchan: stopchan, + refreshTime: config.SLGrpc.RefreshTime, + }, nil +} + +func initConfig(conf settlement.Config) (proposer string, err error) { + if conf.KeyringHomeDir == "" { + + if conf.ProposerPubKey != "" { + proposer = conf.ProposerPubKey + } else { + _, proposerPubKey, err := crypto.GenerateEd25519Key(rand.Reader) + if err != nil { + return "", err + } + pubKeybytes, err := proposerPubKey.Raw() + if err != nil { + return "", err + } + + proposer = hex.EncodeToString(pubKeybytes) + } + } else { + proposerKeyPath := filepath.Join(conf.KeyringHomeDir, "config/priv_validator_key.json") + key, err := tmp2p.LoadOrGenNodeKey(proposerKeyPath) + if err != nil { + return "", err + } + proposer = hex.EncodeToString(key.PubKey().Bytes()) + } + + return +} + +// Start starts the mock client +func (c *HubGrpcClient) Start() error { + c.logger.Info("Starting grpc mock settlement") + + go func() { + tick := time.NewTicker(time.Duration(c.refreshTime) * time.Millisecond) + defer tick.Stop() + for { + select { + case <-c.stopchan: + // stop + return + case <-tick.C: + index, err := c.sl.GetIndex(c.ctx, &slmock.SLGetIndexRequest{}) + if err == nil { + if c.slStateIndex < index.GetIndex() { + c.logger.Info("Simulating new batch event") + + time.Sleep(10 * time.Millisecond) + b, err := c.retrieveBatchAtStateIndex(index.GetIndex()) + if err != nil { + panic(err) + } + err = c.pubsub.PublishWithEvents(context.Background(), &settlement.EventDataNewSettlementBatchAccepted{EndHeight: b.EndHeight}, map[string][]string{settlement.EventTypeKey: {settlement.EventNewSettlementBatchAccepted}}) + if err != nil { + panic(err) + } + c.slStateIndex = index.GetIndex() + } + } + } + } + }() + return nil +} + +// Stop stops the mock client +func (c *HubGrpcClient) Stop() error { + c.logger.Info("Stopping grpc mock settlement") + close(c.stopchan) + return nil +} + +// PostBatch saves the batch to the kv store +func (c *HubGrpcClient) PostBatch(batch *types.Batch, daClient da.Client, daResult *da.ResultSubmitBatch) { + settlementBatch := c.convertBatchtoSettlementBatch(batch, daClient, daResult) + c.saveBatch(settlementBatch) + go func() { + // sleep for 10 miliseconds to mimic a delay in batch acceptance + time.Sleep(10 * time.Millisecond) + err := c.pubsub.PublishWithEvents(context.Background(), &settlement.EventDataNewSettlementBatchAccepted{EndHeight: settlementBatch.EndHeight}, map[string][]string{settlement.EventTypeKey: {settlement.EventNewSettlementBatchAccepted}}) + if err != nil { + panic(err) + } + }() +} + +// GetLatestBatch returns the latest batch from the kv store +func (c *HubGrpcClient) GetLatestBatch(rollappID string) (*settlement.ResultRetrieveBatch, error) { + c.logger.Info("GetLatestBatch grpc", "index", c.slStateIndex) + batchResult, err := c.GetBatchAtIndex(rollappID, atomic.LoadUint64(&c.slStateIndex)) + if err != nil { + return nil, err + } + return batchResult, nil +} + +// GetBatchAtIndex returns the batch at the given index +func (c *HubGrpcClient) GetBatchAtIndex(rollappID string, index uint64) (*settlement.ResultRetrieveBatch, error) { + batchResult, err := c.retrieveBatchAtStateIndex(index) + if err != nil { + return &settlement.ResultRetrieveBatch{ + BaseResult: settlement.BaseResult{Code: settlement.StatusError, Message: err.Error()}, + }, err + } + return batchResult, nil +} + +// GetSequencers returns a list of sequencers. Currently only returns a single sequencer +func (c *HubGrpcClient) GetSequencers(rollappID string) ([]*types.Sequencer, error) { + pubKeyBytes, err := hex.DecodeString(c.ProposerPubKey) + if err != nil { + return nil, err + } + var pubKey cryptotypes.PubKey = &ed25519.PubKey{Key: pubKeyBytes} + return []*types.Sequencer{ + { + PublicKey: pubKey, + Status: types.Proposer, + }, + }, nil +} + +func (c *HubGrpcClient) saveBatch(batch *settlement.Batch) { + c.logger.Debug("Saving batch to grpc settlement layer", "start height", + batch.StartHeight, "end height", batch.EndHeight) + b, err := json.Marshal(batch) + if err != nil { + panic(err) + } + // Save the batch to the next state index + c.logger.Debug("Saving batch to grpc settlement layer", "index", c.slStateIndex+1) + setBatchReply, err := c.sl.SetBatch(c.ctx, &slmock.SLSetBatchRequest{Index: c.slStateIndex + 1, Batch: b}) + if err != nil { + panic(err) + } + if setBatchReply.GetResult() != c.slStateIndex+1 { + panic(err) + } + + c.slStateIndex = setBatchReply.GetResult() + + setIndexReply, err := c.sl.SetIndex(c.ctx, &slmock.SLSetIndexRequest{Index: c.slStateIndex}) + if err != nil || setIndexReply.GetIndex() != c.slStateIndex { + panic(err) + } + c.logger.Debug("Setting grpc SL Index to ", "index", setIndexReply.GetIndex()) + // Save latest height in memory and in store + atomic.StoreUint64(&c.latestHeight, batch.EndHeight) +} + +func (c *HubGrpcClient) convertBatchtoSettlementBatch(batch *types.Batch, daClient da.Client, daResult *da.ResultSubmitBatch) *settlement.Batch { + settlementBatch := &settlement.Batch{ + StartHeight: batch.StartHeight, + EndHeight: batch.EndHeight, + MetaData: &settlement.BatchMetaData{ + DA: &settlement.DAMetaData{ + Height: daResult.DAHeight, + Client: daClient, + }, + }, + } + for _, block := range batch.Blocks { + settlementBatch.AppHashes = append(settlementBatch.AppHashes, block.Header.AppHash) + } + return settlementBatch +} + +func (c *HubGrpcClient) retrieveBatchAtStateIndex(slStateIndex uint64) (*settlement.ResultRetrieveBatch, error) { + c.logger.Debug("Retrieving batch from grpc settlement layer", "SL state index", slStateIndex) + + getBatchReply, err := c.sl.GetBatch(c.ctx, &slmock.SLGetBatchRequest{Index: slStateIndex}) + if err != nil { + return nil, settlement.ErrBatchNotFound + } + b := getBatchReply.GetBatch() + if b == nil { + return nil, settlement.ErrBatchNotFound + } + var settlementBatch settlement.Batch + err = json.Unmarshal(b, &settlementBatch) + if err != nil { + return nil, errors.New("error unmarshalling batch") + } + batchResult := settlement.ResultRetrieveBatch{ + BaseResult: settlement.BaseResult{Code: settlement.StatusSuccess, StateIndex: slStateIndex}, + Batch: &settlementBatch, + } + return &batchResult, nil +} diff --git a/settlement/grpc/mockserv/cmd/main.go b/settlement/grpc/mockserv/cmd/main.go new file mode 100644 index 000000000..cbe1f4746 --- /dev/null +++ b/settlement/grpc/mockserv/cmd/main.go @@ -0,0 +1,32 @@ +package main + +import ( + "flag" + "log" + "net" + "strconv" + + "github.com/dymensionxyz/dymint/settlement" + "github.com/dymensionxyz/dymint/settlement/grpc/mockserv" +) + +func main() { + conf := settlement.GrpcConfig{ + Host: "127.0.0.1", + Port: 7981, + } + + flag.IntVar(&conf.Port, "port", conf.Port, "listening port") + flag.StringVar(&conf.Host, "host", "0.0.0.0", "listening address") + flag.Parse() + + lis, err := net.Listen("tcp", conf.Host+":"+strconv.Itoa(conf.Port)) + if err != nil { + log.Panic(err) + } + log.Println("Listening on:", lis.Addr()) + srv := mockserv.GetServer(conf) + if err := srv.Serve(lis); err != nil { + log.Println("error while serving:", err) + } +} diff --git a/settlement/grpc/mockserv/mockserv.go b/settlement/grpc/mockserv/mockserv.go new file mode 100644 index 000000000..31fcc761d --- /dev/null +++ b/settlement/grpc/mockserv/mockserv.go @@ -0,0 +1,76 @@ +package mockserv + +import ( + "context" + "encoding/binary" + + "google.golang.org/grpc" + + "github.com/dymensionxyz/dymint/settlement" + slmock "github.com/dymensionxyz/dymint/settlement/grpc/mockserv/proto" + "github.com/dymensionxyz/dymint/store" +) + +var settlementKVPrefix = []byte{0} +var slStateIndexKey = []byte("slStateIndex") + +type server struct { + slmock.UnimplementedMockSLServer + kv store.KVStore +} + +func getKey(key uint64) []byte { + b := make([]byte, 8) + binary.BigEndian.PutUint64(b, key) + return b +} + +func (s *server) GetIndex(ctx context.Context, in *slmock.SLGetIndexRequest) (*slmock.SLGetIndexReply, error) { + b, err := s.kv.Get(slStateIndexKey) + if err != nil { + return nil, err + } + slStateIndex := binary.BigEndian.Uint64(b) + + return &slmock.SLGetIndexReply{Index: slStateIndex}, nil +} + +func (s *server) SetIndex(ctx context.Context, in *slmock.SLSetIndexRequest) (*slmock.SLSetIndexResult, error) { + slStateIndex := in.GetIndex() + b := make([]byte, 8) + binary.BigEndian.PutUint64(b, slStateIndex) + err := s.kv.Set(slStateIndexKey, b) + if err != nil { + return nil, err + } + return &slmock.SLSetIndexResult{Index: binary.BigEndian.Uint64(b)}, nil +} + +func (s *server) GetBatch(ctx context.Context, in *slmock.SLGetBatchRequest) (*slmock.SLGetBatchReply, error) { + b, err := s.kv.Get(getKey(in.GetIndex())) + if err != nil { + return nil, err + } + return &slmock.SLGetBatchReply{Index: in.GetIndex(), Batch: b}, nil +} + +func (s *server) SetBatch(ctx context.Context, in *slmock.SLSetBatchRequest) (*slmock.SLSetBatchReply, error) { + err := s.kv.Set(getKey(in.GetIndex()), in.GetBatch()) + if err != nil { + return nil, err + } + return &slmock.SLSetBatchReply{Result: in.GetIndex()}, nil +} + +func GetServer(conf settlement.GrpcConfig) *grpc.Server { + + srv := grpc.NewServer() + + slstore := store.NewDefaultKVStore(".", "db", "settlement") + kv := store.NewPrefixKV(slstore, settlementKVPrefix) + + mockImpl := &server{kv: kv} + + slmock.RegisterMockSLServer(srv, mockImpl) + return srv +} diff --git a/settlement/grpc/mockserv/proto/sl.pb.go b/settlement/grpc/mockserv/proto/sl.pb.go new file mode 100644 index 000000000..795b8219a --- /dev/null +++ b/settlement/grpc/mockserv/proto/sl.pb.go @@ -0,0 +1,638 @@ +// Copyright 2015 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.31.0 +// protoc v4.25.1 +// source: sl.proto + +package settlement + +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) +) + +// The request message containing the user's name. +type SLGetIndexRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *SLGetIndexRequest) Reset() { + *x = SLGetIndexRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_sl_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SLGetIndexRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SLGetIndexRequest) ProtoMessage() {} + +func (x *SLGetIndexRequest) ProtoReflect() protoreflect.Message { + mi := &file_sl_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 SLGetIndexRequest.ProtoReflect.Descriptor instead. +func (*SLGetIndexRequest) Descriptor() ([]byte, []int) { + return file_sl_proto_rawDescGZIP(), []int{0} +} + +// The response message containing the greetings +type SLGetIndexReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Index uint64 `protobuf:"varint,1,opt,name=index,proto3" json:"index,omitempty"` +} + +func (x *SLGetIndexReply) Reset() { + *x = SLGetIndexReply{} + if protoimpl.UnsafeEnabled { + mi := &file_sl_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SLGetIndexReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SLGetIndexReply) ProtoMessage() {} + +func (x *SLGetIndexReply) ProtoReflect() protoreflect.Message { + mi := &file_sl_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 SLGetIndexReply.ProtoReflect.Descriptor instead. +func (*SLGetIndexReply) Descriptor() ([]byte, []int) { + return file_sl_proto_rawDescGZIP(), []int{1} +} + +func (x *SLGetIndexReply) GetIndex() uint64 { + if x != nil { + return x.Index + } + return 0 +} + +// The request message containing the user's name. +type SLSetIndexRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Index uint64 `protobuf:"varint,1,opt,name=index,proto3" json:"index,omitempty"` +} + +func (x *SLSetIndexRequest) Reset() { + *x = SLSetIndexRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_sl_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SLSetIndexRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SLSetIndexRequest) ProtoMessage() {} + +func (x *SLSetIndexRequest) ProtoReflect() protoreflect.Message { + mi := &file_sl_proto_msgTypes[2] + 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 SLSetIndexRequest.ProtoReflect.Descriptor instead. +func (*SLSetIndexRequest) Descriptor() ([]byte, []int) { + return file_sl_proto_rawDescGZIP(), []int{2} +} + +func (x *SLSetIndexRequest) GetIndex() uint64 { + if x != nil { + return x.Index + } + return 0 +} + +// The request message containing the user's name. +type SLSetIndexResult struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Index uint64 `protobuf:"varint,1,opt,name=index,proto3" json:"index,omitempty"` +} + +func (x *SLSetIndexResult) Reset() { + *x = SLSetIndexResult{} + if protoimpl.UnsafeEnabled { + mi := &file_sl_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SLSetIndexResult) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SLSetIndexResult) ProtoMessage() {} + +func (x *SLSetIndexResult) ProtoReflect() protoreflect.Message { + mi := &file_sl_proto_msgTypes[3] + 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 SLSetIndexResult.ProtoReflect.Descriptor instead. +func (*SLSetIndexResult) Descriptor() ([]byte, []int) { + return file_sl_proto_rawDescGZIP(), []int{3} +} + +func (x *SLSetIndexResult) GetIndex() uint64 { + if x != nil { + return x.Index + } + return 0 +} + +type SLSetBatchRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Index uint64 `protobuf:"varint,1,opt,name=index,proto3" json:"index,omitempty"` + Batch []byte `protobuf:"bytes,2,opt,name=batch,proto3" json:"batch,omitempty"` +} + +func (x *SLSetBatchRequest) Reset() { + *x = SLSetBatchRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_sl_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SLSetBatchRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SLSetBatchRequest) ProtoMessage() {} + +func (x *SLSetBatchRequest) ProtoReflect() protoreflect.Message { + mi := &file_sl_proto_msgTypes[4] + 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 SLSetBatchRequest.ProtoReflect.Descriptor instead. +func (*SLSetBatchRequest) Descriptor() ([]byte, []int) { + return file_sl_proto_rawDescGZIP(), []int{4} +} + +func (x *SLSetBatchRequest) GetIndex() uint64 { + if x != nil { + return x.Index + } + return 0 +} + +func (x *SLSetBatchRequest) GetBatch() []byte { + if x != nil { + return x.Batch + } + return nil +} + +type SLSetBatchReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Result uint64 `protobuf:"varint,1,opt,name=result,proto3" json:"result,omitempty"` +} + +func (x *SLSetBatchReply) Reset() { + *x = SLSetBatchReply{} + if protoimpl.UnsafeEnabled { + mi := &file_sl_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SLSetBatchReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SLSetBatchReply) ProtoMessage() {} + +func (x *SLSetBatchReply) ProtoReflect() protoreflect.Message { + mi := &file_sl_proto_msgTypes[5] + 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 SLSetBatchReply.ProtoReflect.Descriptor instead. +func (*SLSetBatchReply) Descriptor() ([]byte, []int) { + return file_sl_proto_rawDescGZIP(), []int{5} +} + +func (x *SLSetBatchReply) GetResult() uint64 { + if x != nil { + return x.Result + } + return 0 +} + +type SLGetBatchRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Index uint64 `protobuf:"varint,1,opt,name=index,proto3" json:"index,omitempty"` +} + +func (x *SLGetBatchRequest) Reset() { + *x = SLGetBatchRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_sl_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SLGetBatchRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SLGetBatchRequest) ProtoMessage() {} + +func (x *SLGetBatchRequest) ProtoReflect() protoreflect.Message { + mi := &file_sl_proto_msgTypes[6] + 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 SLGetBatchRequest.ProtoReflect.Descriptor instead. +func (*SLGetBatchRequest) Descriptor() ([]byte, []int) { + return file_sl_proto_rawDescGZIP(), []int{6} +} + +func (x *SLGetBatchRequest) GetIndex() uint64 { + if x != nil { + return x.Index + } + return 0 +} + +type SLGetBatchReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Index uint64 `protobuf:"varint,1,opt,name=index,proto3" json:"index,omitempty"` + Batch []byte `protobuf:"bytes,2,opt,name=batch,proto3" json:"batch,omitempty"` +} + +func (x *SLGetBatchReply) Reset() { + *x = SLGetBatchReply{} + if protoimpl.UnsafeEnabled { + mi := &file_sl_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SLGetBatchReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SLGetBatchReply) ProtoMessage() {} + +func (x *SLGetBatchReply) ProtoReflect() protoreflect.Message { + mi := &file_sl_proto_msgTypes[7] + 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 SLGetBatchReply.ProtoReflect.Descriptor instead. +func (*SLGetBatchReply) Descriptor() ([]byte, []int) { + return file_sl_proto_rawDescGZIP(), []int{7} +} + +func (x *SLGetBatchReply) GetIndex() uint64 { + if x != nil { + return x.Index + } + return 0 +} + +func (x *SLGetBatchReply) GetBatch() []byte { + if x != nil { + return x.Batch + } + return nil +} + +var File_sl_proto protoreflect.FileDescriptor + +var file_sl_proto_rawDesc = []byte{ + 0x0a, 0x08, 0x73, 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0a, 0x73, 0x65, 0x74, 0x74, + 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x22, 0x13, 0x0a, 0x11, 0x53, 0x4c, 0x47, 0x65, 0x74, 0x49, + 0x6e, 0x64, 0x65, 0x78, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x27, 0x0a, 0x0f, 0x53, + 0x4c, 0x47, 0x65, 0x74, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x14, + 0x0a, 0x05, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x05, 0x69, + 0x6e, 0x64, 0x65, 0x78, 0x22, 0x29, 0x0a, 0x11, 0x53, 0x4c, 0x53, 0x65, 0x74, 0x49, 0x6e, 0x64, + 0x65, 0x78, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x69, 0x6e, 0x64, + 0x65, 0x78, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x05, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x22, + 0x28, 0x0a, 0x10, 0x53, 0x4c, 0x53, 0x65, 0x74, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x52, 0x65, 0x73, + 0x75, 0x6c, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x04, 0x52, 0x05, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x22, 0x3f, 0x0a, 0x11, 0x53, 0x4c, 0x53, + 0x65, 0x74, 0x42, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, + 0x0a, 0x05, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x05, 0x69, + 0x6e, 0x64, 0x65, 0x78, 0x12, 0x14, 0x0a, 0x05, 0x62, 0x61, 0x74, 0x63, 0x68, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x0c, 0x52, 0x05, 0x62, 0x61, 0x74, 0x63, 0x68, 0x22, 0x29, 0x0a, 0x0f, 0x53, 0x4c, + 0x53, 0x65, 0x74, 0x42, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x16, 0x0a, + 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x72, + 0x65, 0x73, 0x75, 0x6c, 0x74, 0x22, 0x29, 0x0a, 0x11, 0x53, 0x4c, 0x47, 0x65, 0x74, 0x42, 0x61, + 0x74, 0x63, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x69, 0x6e, + 0x64, 0x65, 0x78, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x05, 0x69, 0x6e, 0x64, 0x65, 0x78, + 0x22, 0x3d, 0x0a, 0x0f, 0x53, 0x4c, 0x47, 0x65, 0x74, 0x42, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, + 0x70, 0x6c, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x04, 0x52, 0x05, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x12, 0x14, 0x0a, 0x05, 0x62, 0x61, 0x74, + 0x63, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x62, 0x61, 0x74, 0x63, 0x68, 0x32, + 0xb1, 0x02, 0x0a, 0x06, 0x4d, 0x6f, 0x63, 0x6b, 0x53, 0x4c, 0x12, 0x48, 0x0a, 0x08, 0x47, 0x65, + 0x74, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x12, 0x1d, 0x2e, 0x73, 0x65, 0x74, 0x74, 0x6c, 0x65, 0x6d, + 0x65, 0x6e, 0x74, 0x2e, 0x53, 0x4c, 0x47, 0x65, 0x74, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x73, 0x65, 0x74, 0x74, 0x6c, 0x65, 0x6d, 0x65, + 0x6e, 0x74, 0x2e, 0x53, 0x4c, 0x47, 0x65, 0x74, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x52, 0x65, 0x70, + 0x6c, 0x79, 0x22, 0x00, 0x12, 0x49, 0x0a, 0x08, 0x53, 0x65, 0x74, 0x49, 0x6e, 0x64, 0x65, 0x78, + 0x12, 0x1d, 0x2e, 0x73, 0x65, 0x74, 0x74, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x53, 0x4c, + 0x53, 0x65, 0x74, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x1c, 0x2e, 0x73, 0x65, 0x74, 0x74, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x53, 0x4c, 0x53, + 0x65, 0x74, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x22, 0x00, 0x12, + 0x48, 0x0a, 0x08, 0x53, 0x65, 0x74, 0x42, 0x61, 0x74, 0x63, 0x68, 0x12, 0x1d, 0x2e, 0x73, 0x65, + 0x74, 0x74, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x53, 0x4c, 0x53, 0x65, 0x74, 0x42, 0x61, + 0x74, 0x63, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x73, 0x65, 0x74, + 0x74, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x53, 0x4c, 0x53, 0x65, 0x74, 0x42, 0x61, 0x74, + 0x63, 0x68, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x12, 0x48, 0x0a, 0x08, 0x47, 0x65, 0x74, + 0x42, 0x61, 0x74, 0x63, 0x68, 0x12, 0x1d, 0x2e, 0x73, 0x65, 0x74, 0x74, 0x6c, 0x65, 0x6d, 0x65, + 0x6e, 0x74, 0x2e, 0x53, 0x4c, 0x47, 0x65, 0x74, 0x42, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x73, 0x65, 0x74, 0x74, 0x6c, 0x65, 0x6d, 0x65, 0x6e, + 0x74, 0x2e, 0x53, 0x4c, 0x47, 0x65, 0x74, 0x42, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, 0x70, 0x6c, + 0x79, 0x22, 0x00, 0x42, 0x47, 0x5a, 0x45, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, + 0x6d, 0x2f, 0x64, 0x79, 0x6d, 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x78, 0x79, 0x7a, 0x2f, 0x64, + 0x79, 0x6d, 0x69, 0x6e, 0x74, 0x2f, 0x73, 0x65, 0x74, 0x74, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, + 0x2f, 0x6d, 0x6f, 0x63, 0x6b, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x2f, 0x73, 0x65, 0x74, 0x74, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x62, 0x06, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_sl_proto_rawDescOnce sync.Once + file_sl_proto_rawDescData = file_sl_proto_rawDesc +) + +func file_sl_proto_rawDescGZIP() []byte { + file_sl_proto_rawDescOnce.Do(func() { + file_sl_proto_rawDescData = protoimpl.X.CompressGZIP(file_sl_proto_rawDescData) + }) + return file_sl_proto_rawDescData +} + +var file_sl_proto_msgTypes = make([]protoimpl.MessageInfo, 8) +var file_sl_proto_goTypes = []interface{}{ + (*SLGetIndexRequest)(nil), // 0: settlement.SLGetIndexRequest + (*SLGetIndexReply)(nil), // 1: settlement.SLGetIndexReply + (*SLSetIndexRequest)(nil), // 2: settlement.SLSetIndexRequest + (*SLSetIndexResult)(nil), // 3: settlement.SLSetIndexResult + (*SLSetBatchRequest)(nil), // 4: settlement.SLSetBatchRequest + (*SLSetBatchReply)(nil), // 5: settlement.SLSetBatchReply + (*SLGetBatchRequest)(nil), // 6: settlement.SLGetBatchRequest + (*SLGetBatchReply)(nil), // 7: settlement.SLGetBatchReply +} +var file_sl_proto_depIdxs = []int32{ + 0, // 0: settlement.MockSL.GetIndex:input_type -> settlement.SLGetIndexRequest + 2, // 1: settlement.MockSL.SetIndex:input_type -> settlement.SLSetIndexRequest + 4, // 2: settlement.MockSL.SetBatch:input_type -> settlement.SLSetBatchRequest + 6, // 3: settlement.MockSL.GetBatch:input_type -> settlement.SLGetBatchRequest + 1, // 4: settlement.MockSL.GetIndex:output_type -> settlement.SLGetIndexReply + 3, // 5: settlement.MockSL.SetIndex:output_type -> settlement.SLSetIndexResult + 5, // 6: settlement.MockSL.SetBatch:output_type -> settlement.SLSetBatchReply + 7, // 7: settlement.MockSL.GetBatch:output_type -> settlement.SLGetBatchReply + 4, // [4:8] is the sub-list for method output_type + 0, // [0:4] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_sl_proto_init() } +func file_sl_proto_init() { + if File_sl_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_sl_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*SLGetIndexRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_sl_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*SLGetIndexReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_sl_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*SLSetIndexRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_sl_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*SLSetIndexResult); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_sl_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*SLSetBatchRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_sl_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*SLSetBatchReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_sl_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*SLGetBatchRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_sl_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*SLGetBatchReply); 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_sl_proto_rawDesc, + NumEnums: 0, + NumMessages: 8, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_sl_proto_goTypes, + DependencyIndexes: file_sl_proto_depIdxs, + MessageInfos: file_sl_proto_msgTypes, + }.Build() + File_sl_proto = out.File + file_sl_proto_rawDesc = nil + file_sl_proto_goTypes = nil + file_sl_proto_depIdxs = nil +} diff --git a/settlement/grpc/mockserv/proto/sl.proto b/settlement/grpc/mockserv/proto/sl.proto new file mode 100644 index 000000000..c9457f374 --- /dev/null +++ b/settlement/grpc/mockserv/proto/sl.proto @@ -0,0 +1,53 @@ +syntax = "proto3"; + +option go_package = "github.com/dymensionxyz/dymint/settlement/mockserver/proto/settlement"; + +package settlement; + +// The greeting service definition. +service MockSL { + // Sends a greeting + rpc GetIndex (SLGetIndexRequest) returns (SLGetIndexReply) {} + rpc SetIndex (SLSetIndexRequest) returns (SLSetIndexResult) {} + rpc SetBatch (SLSetBatchRequest) returns (SLSetBatchReply) {} + rpc GetBatch (SLGetBatchRequest) returns (SLGetBatchReply) {} + +} + +// The request message containing the user's name. +message SLGetIndexRequest { +} + +// The response message containing the greetings +message SLGetIndexReply { + uint64 index = 1; +} + +// The request message containing the user's name. +message SLSetIndexRequest { + uint64 index = 1; +} + +// The request message containing the user's name. +message SLSetIndexResult { + uint64 index = 1; +} + +message SLSetBatchRequest { + uint64 index = 1; + bytes batch = 2; +} + +message SLSetBatchReply { + uint64 result = 1; +} + +message SLGetBatchRequest { + uint64 index = 1; +} + +message SLGetBatchReply { + uint64 index = 1; + bytes batch = 2; +} + diff --git a/settlement/grpc/mockserv/proto/sl_grpc.pb.go b/settlement/grpc/mockserv/proto/sl_grpc.pb.go new file mode 100644 index 000000000..5afb663c6 --- /dev/null +++ b/settlement/grpc/mockserv/proto/sl_grpc.pb.go @@ -0,0 +1,236 @@ +// Copyright 2015 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.3.0 +// - protoc v4.25.1 +// source: sl.proto + +package settlement + +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 ( + MockSL_GetIndex_FullMethodName = "/settlement.MockSL/GetIndex" + MockSL_SetIndex_FullMethodName = "/settlement.MockSL/SetIndex" + MockSL_SetBatch_FullMethodName = "/settlement.MockSL/SetBatch" + MockSL_GetBatch_FullMethodName = "/settlement.MockSL/GetBatch" +) + +// MockSLClient is the client API for MockSL 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 MockSLClient interface { + // Sends a greeting + GetIndex(ctx context.Context, in *SLGetIndexRequest, opts ...grpc.CallOption) (*SLGetIndexReply, error) + SetIndex(ctx context.Context, in *SLSetIndexRequest, opts ...grpc.CallOption) (*SLSetIndexResult, error) + SetBatch(ctx context.Context, in *SLSetBatchRequest, opts ...grpc.CallOption) (*SLSetBatchReply, error) + GetBatch(ctx context.Context, in *SLGetBatchRequest, opts ...grpc.CallOption) (*SLGetBatchReply, error) +} + +type mockSLClient struct { + cc grpc.ClientConnInterface +} + +func NewMockSLClient(cc grpc.ClientConnInterface) MockSLClient { + return &mockSLClient{cc} +} + +func (c *mockSLClient) GetIndex(ctx context.Context, in *SLGetIndexRequest, opts ...grpc.CallOption) (*SLGetIndexReply, error) { + out := new(SLGetIndexReply) + err := c.cc.Invoke(ctx, MockSL_GetIndex_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *mockSLClient) SetIndex(ctx context.Context, in *SLSetIndexRequest, opts ...grpc.CallOption) (*SLSetIndexResult, error) { + out := new(SLSetIndexResult) + err := c.cc.Invoke(ctx, MockSL_SetIndex_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *mockSLClient) SetBatch(ctx context.Context, in *SLSetBatchRequest, opts ...grpc.CallOption) (*SLSetBatchReply, error) { + out := new(SLSetBatchReply) + err := c.cc.Invoke(ctx, MockSL_SetBatch_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *mockSLClient) GetBatch(ctx context.Context, in *SLGetBatchRequest, opts ...grpc.CallOption) (*SLGetBatchReply, error) { + out := new(SLGetBatchReply) + err := c.cc.Invoke(ctx, MockSL_GetBatch_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MockSLServer is the server API for MockSL service. +// All implementations must embed UnimplementedMockSLServer +// for forward compatibility +type MockSLServer interface { + // Sends a greeting + GetIndex(context.Context, *SLGetIndexRequest) (*SLGetIndexReply, error) + SetIndex(context.Context, *SLSetIndexRequest) (*SLSetIndexResult, error) + SetBatch(context.Context, *SLSetBatchRequest) (*SLSetBatchReply, error) + GetBatch(context.Context, *SLGetBatchRequest) (*SLGetBatchReply, error) + mustEmbedUnimplementedMockSLServer() +} + +// UnimplementedMockSLServer must be embedded to have forward compatible implementations. +type UnimplementedMockSLServer struct { +} + +func (UnimplementedMockSLServer) GetIndex(context.Context, *SLGetIndexRequest) (*SLGetIndexReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetIndex not implemented") +} +func (UnimplementedMockSLServer) SetIndex(context.Context, *SLSetIndexRequest) (*SLSetIndexResult, error) { + return nil, status.Errorf(codes.Unimplemented, "method SetIndex not implemented") +} +func (UnimplementedMockSLServer) SetBatch(context.Context, *SLSetBatchRequest) (*SLSetBatchReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method SetBatch not implemented") +} +func (UnimplementedMockSLServer) GetBatch(context.Context, *SLGetBatchRequest) (*SLGetBatchReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetBatch not implemented") +} +func (UnimplementedMockSLServer) mustEmbedUnimplementedMockSLServer() {} + +// UnsafeMockSLServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to MockSLServer will +// result in compilation errors. +type UnsafeMockSLServer interface { + mustEmbedUnimplementedMockSLServer() +} + +func RegisterMockSLServer(s grpc.ServiceRegistrar, srv MockSLServer) { + s.RegisterService(&MockSL_ServiceDesc, srv) +} + +func _MockSL_GetIndex_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(SLGetIndexRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MockSLServer).GetIndex(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: MockSL_GetIndex_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MockSLServer).GetIndex(ctx, req.(*SLGetIndexRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _MockSL_SetIndex_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(SLSetIndexRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MockSLServer).SetIndex(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: MockSL_SetIndex_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MockSLServer).SetIndex(ctx, req.(*SLSetIndexRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _MockSL_SetBatch_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(SLSetBatchRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MockSLServer).SetBatch(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: MockSL_SetBatch_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MockSLServer).SetBatch(ctx, req.(*SLSetBatchRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _MockSL_GetBatch_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(SLGetBatchRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MockSLServer).GetBatch(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: MockSL_GetBatch_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MockSLServer).GetBatch(ctx, req.(*SLGetBatchRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// MockSL_ServiceDesc is the grpc.ServiceDesc for MockSL service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var MockSL_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "settlement.MockSL", + HandlerType: (*MockSLServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetIndex", + Handler: _MockSL_GetIndex_Handler, + }, + { + MethodName: "SetIndex", + Handler: _MockSL_SetIndex_Handler, + }, + { + MethodName: "SetBatch", + Handler: _MockSL_SetBatch_Handler, + }, + { + MethodName: "GetBatch", + Handler: _MockSL_GetBatch_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "sl.proto", +} diff --git a/settlement/registry/registry.go b/settlement/registry/registry.go index 82dc15001..794192efe 100644 --- a/settlement/registry/registry.go +++ b/settlement/registry/registry.go @@ -3,6 +3,7 @@ package registry import ( "github.com/dymensionxyz/dymint/settlement" "github.com/dymensionxyz/dymint/settlement/dymension" + "github.com/dymensionxyz/dymint/settlement/grpc" "github.com/dymensionxyz/dymint/settlement/mock" ) @@ -14,12 +15,15 @@ const ( Mock Client = "mock" // Dymension is a client for interacting with dymension settlement layer Dymension Client = "dymension" + // Mock client using grpc for a shared use + Grpc Client = "grpc" ) // A central registry for all Settlement Layer Clients var clients = map[Client]func() settlement.LayerI{ Mock: func() settlement.LayerI { return &mock.LayerClient{} }, Dymension: func() settlement.LayerI { return &dymension.LayerClient{} }, + Grpc: func() settlement.LayerI { return &grpc.LayerClient{} }, } // GetClient returns client identified by name. diff --git a/settlement/registry/registry_test.go b/settlement/registry/registry_test.go index 04ae1b856..2905faa07 100644 --- a/settlement/registry/registry_test.go +++ b/settlement/registry/registry_test.go @@ -10,7 +10,7 @@ import ( func TestRegistery(t *testing.T) { assert := assert.New(t) - expected := []registry.Client{registry.Mock, registry.Dymension} + expected := []registry.Client{registry.Mock, registry.Dymension, registry.Grpc} actual := registry.RegisteredClients() assert.ElementsMatch(expected, actual)