diff --git a/packages/network/src/workers/syncUtils.ts b/packages/network/src/workers/syncUtils.ts index 64884f35e0..68d99059be 100644 --- a/packages/network/src/workers/syncUtils.ts +++ b/packages/network/src/workers/syncUtils.ts @@ -1,6 +1,6 @@ import { JsonRpcProvider } from "@ethersproject/providers"; import { EntityID, ComponentValue, Components } from "@latticexyz/recs"; -import { to256BitString, awaitPromise, range } from "@latticexyz/utils"; +import { to256BitString, awaitPromise, range, Uint8ArrayToHexString } from "@latticexyz/utils"; import { BytesLike, Contract, BigNumber } from "ethers"; import { Observable, map, concatMap, of, from } from "rxjs"; import { createDecoder } from "../createDecoder"; @@ -8,6 +8,7 @@ import { createTopics } from "../createTopics"; import { fetchEventsInBlockRange } from "../networkUtils"; import { ECSStateReply, + ECSStateReplyV2, ECSStateSnapshotServiceClient, ECSStateSnapshotServiceDefinition, } from "@latticexyz/services/protobuf/ts/ecs-snapshot/ecs-snapshot"; @@ -23,7 +24,6 @@ import { CacheStore, createCacheStore, storeEvent, storeEvents } from "./CacheSt import { abi as ComponentAbi } from "@latticexyz/solecs/abi/Component.json"; import { abi as WorldAbi } from "@latticexyz/solecs/abi/World.json"; import { Component, World } from "@latticexyz/solecs/types/ethers-contracts"; -import { SyncState } from "./constants"; import { ECSStreamBlockBundleReply, ECSStreamServiceClient, @@ -80,6 +80,7 @@ export async function getSnapshotBlockNumber( * @param worldAddress Address of the World contract to get the snapshot for. * @param decode Function to decode raw component values ({@link createDecode}). * @returns Promise resolving with {@link CacheStore} containing the snapshot state. + * @deprecated this util will be removed in a future version, use fetchSnapshotChunked instead */ export async function fetchSnapshot( snapshotClient: ECSStateSnapshotServiceClient, @@ -115,20 +116,24 @@ export async function fetchSnapshotChunked( pruneOptions?: { playerAddress: string; hashedComponentId: string } ): Promise { const cacheStore = createCacheStore(); - const chunkPercentage = 100 / numChunks; + const chunkPercentage = Math.ceil(100 / numChunks); try { const response = pruneOptions - ? snapshotClient.getStateLatestStreamPruned({ + ? snapshotClient.getStateLatestStreamPrunedV2({ worldAddress, chunkPercentage, - pruneAddress: pruneOptions.playerAddress, - pruneComponentId: pruneOptions.hashedComponentId, + pruneAddress: pruneOptions?.playerAddress, + pruneComponentId: pruneOptions?.hashedComponentId, }) - : snapshotClient.getStateLatestStream({ worldAddress, chunkPercentage }); + : snapshotClient.getStateLatestStreamV2({ + worldAddress, + chunkPercentage, + }); + let i = 0; for await (const responseChunk of response) { - await reduceFetchedState(responseChunk, cacheStore, decode); + await reduceFetchedStateV2(responseChunk, cacheStore, decode); setPercentage && setPercentage((i++ / numChunks) * 100); } } catch (e) { @@ -145,6 +150,7 @@ export async function fetchSnapshotChunked( * @param cacheStore {@link CacheStore} to store snapshot state into. * @param decode Function to decode raw component values ({@link createDecode}). * @returns Promise resolving once state is reduced into {@link CacheStore}. + * @deprecated this util will be removed in a future version, use reduceFetchedStateV2 instead */ export async function reduceFetchedState( response: ECSStateReply, @@ -161,6 +167,32 @@ export async function reduceFetchedState( } } +/** + * Reduces a snapshot response by storing corresponding ECS events into the cache store. + * + * @param response ECSStateReplyV2 + * @param cacheStore {@link CacheStore} to store snapshot state into. + * @param decode Function to decode raw component values ({@link createDecode}). + * @returns Promise resolving once state is reduced into {@link CacheStore}. + */ +export async function reduceFetchedStateV2( + response: ECSStateReplyV2, + cacheStore: CacheStore, + decode: ReturnType +): Promise { + const { state, blockNumber, stateComponents, stateEntities } = response; + const stateEntitiesHex = stateEntities.map((e) => Uint8ArrayToHexString(e) as EntityID); + const stateComponentsHex = stateComponents.map((e) => to256BitString(e)); + + for (const { componentIdIdx, entityIdIdx, value: rawValue } of state) { + const component = stateComponentsHex[componentIdIdx]; + const entity = stateEntitiesHex[entityIdIdx]; + if (entity == undefined) console.log("invalid entity index", stateEntities.length, entityIdIdx); + const value = await decode(component, rawValue); + storeEvent(cacheStore, { type: NetworkEvents.NetworkComponentUpdate, component, entity, value, blockNumber }); + } +} + /** * Create a RxJS stream of {@link NetworkComponentUpdate}s by subscribing to a * gRPC streaming service. diff --git a/packages/services/pkg/grpc/snapshot.go b/packages/services/pkg/grpc/snapshot.go index 7642a3f039..ad6064be4e 100644 --- a/packages/services/pkg/grpc/snapshot.go +++ b/packages/services/pkg/grpc/snapshot.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "latticexyz/mud/packages/services/pkg/snapshot" + "latticexyz/mud/packages/services/pkg/utils" pb "latticexyz/mud/packages/services/protobuf/go/ecs-snapshot" ) @@ -124,3 +125,63 @@ func (server *ecsSnapshotServer) GetStateBlockLatest(ctx context.Context, in *pb func (server *ecsSnapshotServer) GetStateAtBlock(ctx context.Context, in *pb.ECSStateRequestAtBlock) (*pb.ECSStateReply, error) { return nil, fmt.Errorf("not implemented") } + +// +// V2 endpoints +// + +func (server *ecsSnapshotServer) GetStateLatestStreamV2(in *pb.ECSStateRequestLatestStream, stream pb.ECSStateSnapshotService_GetStateLatestStreamV2Server) error { + if !snapshot.IsSnaphotAvailableLatest(in.WorldAddress) { + return fmt.Errorf("no snapshot") + } + latestSnapshot := snapshot.RawReadStateSnapshotLatest(in.WorldAddress) + + // Respond in fraction chunks. If request has specified a chunk percentage, use that value. + chunkPercentage := server.config.DefaultSnapshotChunkPercentage + if in.ChunkPercentage != nil { + chunkPercentage = int(*in.ChunkPercentage) + } + + latestSnapshotChunked := snapshot.ChunkRawStateSnapshot(latestSnapshot, chunkPercentage) + + for _, snapshotChunk := range latestSnapshotChunked { + stream.Send(&pb.ECSStateReplyV2{ + State: snapshotChunk.State, + StateComponents: snapshotChunk.StateComponents, + StateEntities: utils.HexStringArrayToBytesArray(snapshotChunk.StateEntities), + StateHash: snapshotChunk.StateHash, + BlockNumber: snapshotChunk.EndBlockNumber, + }) + } + return nil +} + +func (server *ecsSnapshotServer) GetStateLatestStreamPrunedV2(request *pb.ECSStateRequestLatestStreamPruned, stream pb.ECSStateSnapshotService_GetStateLatestStreamPrunedV2Server) error { + if !snapshot.IsSnaphotAvailableLatest(request.WorldAddress) { + return fmt.Errorf("no snapshot") + } + if len(request.PruneAddress) == 0 { + return fmt.Errorf("address for which to prune for required") + } + latestSnapshot := snapshot.RawReadStateSnapshotLatest(request.WorldAddress) + latestSnapshotPruned := snapshot.PruneSnapshotOwnedByComponent(latestSnapshot, request.PruneAddress) + + // Respond in fraction chunks. If request has specified a chunk percentage, use that value. + chunkPercentage := server.config.DefaultSnapshotChunkPercentage + if request.ChunkPercentage != nil { + chunkPercentage = int(*request.ChunkPercentage) + } + + latestSnapshotChunked := snapshot.ChunkRawStateSnapshot(latestSnapshotPruned, chunkPercentage) + + for _, snapshotChunk := range latestSnapshotChunked { + stream.Send(&pb.ECSStateReplyV2{ + State: snapshotChunk.State, + StateComponents: snapshotChunk.StateComponents, + StateEntities: utils.HexStringArrayToBytesArray(snapshotChunk.StateEntities), + StateHash: snapshotChunk.StateHash, + BlockNumber: snapshotChunk.EndBlockNumber, + }) + } + return nil +} diff --git a/packages/services/pkg/utils/general.go b/packages/services/pkg/utils/general.go index 43d30e71dc..7ae7c6b8cd 100644 --- a/packages/services/pkg/utils/general.go +++ b/packages/services/pkg/utils/general.go @@ -1,8 +1,27 @@ package utils +import ( + "latticexyz/mud/packages/services/pkg/logger" + + "github.com/ethereum/go-ethereum/common/hexutil" + "go.uber.org/zap" +) + func Min(a, b int) int { if a < b { return a } return b } + +func HexStringArrayToBytesArray(strArray []string) [][]byte { + bytesArray := [][]byte{} + for _, str := range strArray { + entityIdBigInt, err := hexutil.DecodeBig(str) + if err != nil { + logger.GetLogger().Error("can't parse entity ID", zap.String("string", str), zap.Error(err)) + } + bytesArray = append(bytesArray, entityIdBigInt.Bytes()) + } + return bytesArray +} diff --git a/packages/services/proto/ecs-snapshot.proto b/packages/services/proto/ecs-snapshot.proto index 71756c7907..48ad9d737f 100644 --- a/packages/services/proto/ecs-snapshot.proto +++ b/packages/services/proto/ecs-snapshot.proto @@ -31,9 +31,19 @@ service ECSStateSnapshotService { // Requests the latest ECS state in stream format, which will chunk the state. rpc GetStateLatestStream (ECSStateRequestLatestStream) returns (stream ECSStateReply) {} + // Requests the latest ECS state in stream format, which will chunk the state. + // + // V2 version optimized to return entities as raw bytes. + rpc GetStateLatestStreamV2 (ECSStateRequestLatestStream) returns (stream ECSStateReplyV2) {} + // Requests the latest ECS state, with aditional pruning. rpc GetStateLatestStreamPruned (ECSStateRequestLatestStreamPruned) returns (stream ECSStateReply) {} + // Requests the latest ECS state, with aditional pruning. + // + // V2 version optimized to return entities as raw bytes. + rpc GetStateLatestStreamPrunedV2 (ECSStateRequestLatestStreamPruned) returns (stream ECSStateReplyV2) {} + // Requests the latest block number based on the latest ECS state. rpc GetStateBlockLatest (ECSStateBlockRequestLatest) returns (ECSStateBlockReply) {} @@ -87,6 +97,14 @@ message ECSStateReply { uint32 blockNumber = 5; } +message ECSStateReplyV2 { + repeated ECSState state = 1; + repeated string stateComponents = 2; + repeated bytes stateEntities = 3; + string stateHash = 4; + uint32 blockNumber = 5; +} + message ECSStateBlockReply { uint32 blockNumber = 1; } diff --git a/packages/services/protobuf/go/ecs-snapshot/ecs-snapshot.pb.go b/packages/services/protobuf/go/ecs-snapshot/ecs-snapshot.pb.go index 12f4abcc1a..184d571175 100644 --- a/packages/services/protobuf/go/ecs-snapshot/ecs-snapshot.pb.go +++ b/packages/services/protobuf/go/ecs-snapshot/ecs-snapshot.pb.go @@ -616,6 +616,85 @@ func (x *ECSStateReply) GetBlockNumber() uint32 { return 0 } +type ECSStateReplyV2 struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + State []*ECSState `protobuf:"bytes,1,rep,name=state,proto3" json:"state,omitempty"` + StateComponents []string `protobuf:"bytes,2,rep,name=stateComponents,proto3" json:"stateComponents,omitempty"` + StateEntities [][]byte `protobuf:"bytes,3,rep,name=stateEntities,proto3" json:"stateEntities,omitempty"` + StateHash string `protobuf:"bytes,4,opt,name=stateHash,proto3" json:"stateHash,omitempty"` + BlockNumber uint32 `protobuf:"varint,5,opt,name=blockNumber,proto3" json:"blockNumber,omitempty"` +} + +func (x *ECSStateReplyV2) Reset() { + *x = ECSStateReplyV2{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_ecs_snapshot_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ECSStateReplyV2) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ECSStateReplyV2) ProtoMessage() {} + +func (x *ECSStateReplyV2) ProtoReflect() protoreflect.Message { + mi := &file_proto_ecs_snapshot_proto_msgTypes[10] + 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 ECSStateReplyV2.ProtoReflect.Descriptor instead. +func (*ECSStateReplyV2) Descriptor() ([]byte, []int) { + return file_proto_ecs_snapshot_proto_rawDescGZIP(), []int{10} +} + +func (x *ECSStateReplyV2) GetState() []*ECSState { + if x != nil { + return x.State + } + return nil +} + +func (x *ECSStateReplyV2) GetStateComponents() []string { + if x != nil { + return x.StateComponents + } + return nil +} + +func (x *ECSStateReplyV2) GetStateEntities() [][]byte { + if x != nil { + return x.StateEntities + } + return nil +} + +func (x *ECSStateReplyV2) GetStateHash() string { + if x != nil { + return x.StateHash + } + return "" +} + +func (x *ECSStateReplyV2) GetBlockNumber() uint32 { + if x != nil { + return x.BlockNumber + } + return 0 +} + type ECSStateBlockReply struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -627,7 +706,7 @@ type ECSStateBlockReply struct { func (x *ECSStateBlockReply) Reset() { *x = ECSStateBlockReply{} if protoimpl.UnsafeEnabled { - mi := &file_proto_ecs_snapshot_proto_msgTypes[10] + mi := &file_proto_ecs_snapshot_proto_msgTypes[11] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -640,7 +719,7 @@ func (x *ECSStateBlockReply) String() string { func (*ECSStateBlockReply) ProtoMessage() {} func (x *ECSStateBlockReply) ProtoReflect() protoreflect.Message { - mi := &file_proto_ecs_snapshot_proto_msgTypes[10] + mi := &file_proto_ecs_snapshot_proto_msgTypes[11] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -653,7 +732,7 @@ func (x *ECSStateBlockReply) ProtoReflect() protoreflect.Message { // Deprecated: Use ECSStateBlockReply.ProtoReflect.Descriptor instead. func (*ECSStateBlockReply) Descriptor() ([]byte, []int) { - return file_proto_ecs_snapshot_proto_rawDescGZIP(), []int{10} + return file_proto_ecs_snapshot_proto_rawDescGZIP(), []int{11} } func (x *ECSStateBlockReply) GetBlockNumber() uint32 { @@ -746,48 +825,75 @@ var file_proto_ecs_snapshot_proto_rawDesc = []byte{ 0x61, 0x73, 0x68, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x74, 0x61, 0x74, 0x65, 0x48, 0x61, 0x73, 0x68, 0x12, 0x20, 0x0a, 0x0b, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0b, 0x62, 0x6c, 0x6f, 0x63, 0x6b, - 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0x36, 0x0a, 0x12, 0x45, 0x43, 0x53, 0x53, 0x74, 0x61, - 0x74, 0x65, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x20, 0x0a, 0x0b, - 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x0d, 0x52, 0x0b, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x32, 0xb6, - 0x04, 0x0a, 0x17, 0x45, 0x43, 0x53, 0x53, 0x74, 0x61, 0x74, 0x65, 0x53, 0x6e, 0x61, 0x70, 0x73, - 0x68, 0x6f, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x52, 0x0a, 0x0e, 0x47, 0x65, - 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x4c, 0x61, 0x74, 0x65, 0x73, 0x74, 0x12, 0x22, 0x2e, 0x65, - 0x63, 0x73, 0x73, 0x6e, 0x61, 0x70, 0x73, 0x68, 0x6f, 0x74, 0x2e, 0x45, 0x43, 0x53, 0x53, 0x74, - 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x4c, 0x61, 0x74, 0x65, 0x73, 0x74, - 0x1a, 0x1a, 0x2e, 0x65, 0x63, 0x73, 0x73, 0x6e, 0x61, 0x70, 0x73, 0x68, 0x6f, 0x74, 0x2e, 0x45, - 0x43, 0x53, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x12, 0x60, - 0x0a, 0x14, 0x47, 0x65, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x4c, 0x61, 0x74, 0x65, 0x73, 0x74, - 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x28, 0x2e, 0x65, 0x63, 0x73, 0x73, 0x6e, 0x61, 0x70, - 0x73, 0x68, 0x6f, 0x74, 0x2e, 0x45, 0x43, 0x53, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x4c, 0x61, 0x74, 0x65, 0x73, 0x74, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, - 0x1a, 0x1a, 0x2e, 0x65, 0x63, 0x73, 0x73, 0x6e, 0x61, 0x70, 0x73, 0x68, 0x6f, 0x74, 0x2e, 0x45, - 0x43, 0x53, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x30, 0x01, - 0x12, 0x6c, 0x0a, 0x1a, 0x47, 0x65, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x4c, 0x61, 0x74, 0x65, - 0x73, 0x74, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x50, 0x72, 0x75, 0x6e, 0x65, 0x64, 0x12, 0x2e, - 0x2e, 0x65, 0x63, 0x73, 0x73, 0x6e, 0x61, 0x70, 0x73, 0x68, 0x6f, 0x74, 0x2e, 0x45, 0x43, 0x53, - 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x4c, 0x61, 0x74, 0x65, - 0x73, 0x74, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x50, 0x72, 0x75, 0x6e, 0x65, 0x64, 0x1a, 0x1a, - 0x2e, 0x65, 0x63, 0x73, 0x73, 0x6e, 0x61, 0x70, 0x73, 0x68, 0x6f, 0x74, 0x2e, 0x45, 0x43, 0x53, - 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x30, 0x01, 0x12, 0x61, - 0x0a, 0x13, 0x47, 0x65, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x4c, - 0x61, 0x74, 0x65, 0x73, 0x74, 0x12, 0x27, 0x2e, 0x65, 0x63, 0x73, 0x73, 0x6e, 0x61, 0x70, 0x73, - 0x68, 0x6f, 0x74, 0x2e, 0x45, 0x43, 0x53, 0x53, 0x74, 0x61, 0x74, 0x65, 0x42, 0x6c, 0x6f, 0x63, - 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x4c, 0x61, 0x74, 0x65, 0x73, 0x74, 0x1a, 0x1f, - 0x2e, 0x65, 0x63, 0x73, 0x73, 0x6e, 0x61, 0x70, 0x73, 0x68, 0x6f, 0x74, 0x2e, 0x45, 0x43, 0x53, - 0x53, 0x74, 0x61, 0x74, 0x65, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, - 0x00, 0x12, 0x54, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x41, 0x74, 0x42, - 0x6c, 0x6f, 0x63, 0x6b, 0x12, 0x23, 0x2e, 0x65, 0x63, 0x73, 0x73, 0x6e, 0x61, 0x70, 0x73, 0x68, - 0x6f, 0x74, 0x2e, 0x45, 0x43, 0x53, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x41, 0x74, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x1a, 0x1a, 0x2e, 0x65, 0x63, 0x73, 0x73, + 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0xce, 0x01, 0x0a, 0x0f, 0x45, 0x43, 0x53, 0x53, 0x74, + 0x61, 0x74, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x56, 0x32, 0x12, 0x2b, 0x0a, 0x05, 0x73, 0x74, + 0x61, 0x74, 0x65, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x65, 0x63, 0x73, 0x73, 0x6e, 0x61, 0x70, 0x73, 0x68, 0x6f, 0x74, 0x2e, 0x45, 0x43, 0x53, 0x53, 0x74, 0x61, 0x74, 0x65, - 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x12, 0x3e, 0x0a, 0x09, 0x47, 0x65, 0x74, 0x57, 0x6f, - 0x72, 0x6c, 0x64, 0x73, 0x12, 0x1a, 0x2e, 0x65, 0x63, 0x73, 0x73, 0x6e, 0x61, 0x70, 0x73, 0x68, - 0x6f, 0x74, 0x2e, 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x1a, 0x13, 0x2e, 0x65, 0x63, 0x73, 0x73, 0x6e, 0x61, 0x70, 0x73, 0x68, 0x6f, 0x74, 0x2e, 0x57, - 0x6f, 0x72, 0x6c, 0x64, 0x73, 0x22, 0x00, 0x42, 0x1a, 0x5a, 0x18, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x62, 0x75, 0x66, 0x2f, 0x67, 0x6f, 0x2f, 0x65, 0x63, 0x73, 0x2d, 0x73, 0x6e, 0x61, 0x70, 0x73, - 0x68, 0x6f, 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x12, 0x28, 0x0a, 0x0f, 0x73, 0x74, 0x61, 0x74, 0x65, + 0x43, 0x6f, 0x6d, 0x70, 0x6f, 0x6e, 0x65, 0x6e, 0x74, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, + 0x52, 0x0f, 0x73, 0x74, 0x61, 0x74, 0x65, 0x43, 0x6f, 0x6d, 0x70, 0x6f, 0x6e, 0x65, 0x6e, 0x74, + 0x73, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x61, 0x74, 0x65, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x69, + 0x65, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x0d, 0x73, 0x74, 0x61, 0x74, 0x65, 0x45, + 0x6e, 0x74, 0x69, 0x74, 0x69, 0x65, 0x73, 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x74, 0x61, 0x74, 0x65, + 0x48, 0x61, 0x73, 0x68, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x74, 0x61, 0x74, + 0x65, 0x48, 0x61, 0x73, 0x68, 0x12, 0x20, 0x0a, 0x0b, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x4e, 0x75, + 0x6d, 0x62, 0x65, 0x72, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0b, 0x62, 0x6c, 0x6f, 0x63, + 0x6b, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0x36, 0x0a, 0x12, 0x45, 0x43, 0x53, 0x53, 0x74, + 0x61, 0x74, 0x65, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x20, 0x0a, + 0x0b, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x0d, 0x52, 0x0b, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x32, + 0x8e, 0x06, 0x0a, 0x17, 0x45, 0x43, 0x53, 0x53, 0x74, 0x61, 0x74, 0x65, 0x53, 0x6e, 0x61, 0x70, + 0x73, 0x68, 0x6f, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x52, 0x0a, 0x0e, 0x47, + 0x65, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x4c, 0x61, 0x74, 0x65, 0x73, 0x74, 0x12, 0x22, 0x2e, + 0x65, 0x63, 0x73, 0x73, 0x6e, 0x61, 0x70, 0x73, 0x68, 0x6f, 0x74, 0x2e, 0x45, 0x43, 0x53, 0x53, + 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x4c, 0x61, 0x74, 0x65, 0x73, + 0x74, 0x1a, 0x1a, 0x2e, 0x65, 0x63, 0x73, 0x73, 0x6e, 0x61, 0x70, 0x73, 0x68, 0x6f, 0x74, 0x2e, + 0x45, 0x43, 0x53, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x12, + 0x60, 0x0a, 0x14, 0x47, 0x65, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x4c, 0x61, 0x74, 0x65, 0x73, + 0x74, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x28, 0x2e, 0x65, 0x63, 0x73, 0x73, 0x6e, 0x61, + 0x70, 0x73, 0x68, 0x6f, 0x74, 0x2e, 0x45, 0x43, 0x53, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x4c, 0x61, 0x74, 0x65, 0x73, 0x74, 0x53, 0x74, 0x72, 0x65, 0x61, + 0x6d, 0x1a, 0x1a, 0x2e, 0x65, 0x63, 0x73, 0x73, 0x6e, 0x61, 0x70, 0x73, 0x68, 0x6f, 0x74, 0x2e, + 0x45, 0x43, 0x53, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x30, + 0x01, 0x12, 0x64, 0x0a, 0x16, 0x47, 0x65, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x4c, 0x61, 0x74, + 0x65, 0x73, 0x74, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x56, 0x32, 0x12, 0x28, 0x2e, 0x65, 0x63, + 0x73, 0x73, 0x6e, 0x61, 0x70, 0x73, 0x68, 0x6f, 0x74, 0x2e, 0x45, 0x43, 0x53, 0x53, 0x74, 0x61, + 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x4c, 0x61, 0x74, 0x65, 0x73, 0x74, 0x53, + 0x74, 0x72, 0x65, 0x61, 0x6d, 0x1a, 0x1c, 0x2e, 0x65, 0x63, 0x73, 0x73, 0x6e, 0x61, 0x70, 0x73, + 0x68, 0x6f, 0x74, 0x2e, 0x45, 0x43, 0x53, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x70, 0x6c, + 0x79, 0x56, 0x32, 0x22, 0x00, 0x30, 0x01, 0x12, 0x6c, 0x0a, 0x1a, 0x47, 0x65, 0x74, 0x53, 0x74, + 0x61, 0x74, 0x65, 0x4c, 0x61, 0x74, 0x65, 0x73, 0x74, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x50, + 0x72, 0x75, 0x6e, 0x65, 0x64, 0x12, 0x2e, 0x2e, 0x65, 0x63, 0x73, 0x73, 0x6e, 0x61, 0x70, 0x73, + 0x68, 0x6f, 0x74, 0x2e, 0x45, 0x43, 0x53, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x4c, 0x61, 0x74, 0x65, 0x73, 0x74, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x50, + 0x72, 0x75, 0x6e, 0x65, 0x64, 0x1a, 0x1a, 0x2e, 0x65, 0x63, 0x73, 0x73, 0x6e, 0x61, 0x70, 0x73, + 0x68, 0x6f, 0x74, 0x2e, 0x45, 0x43, 0x53, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x70, 0x6c, + 0x79, 0x22, 0x00, 0x30, 0x01, 0x12, 0x70, 0x0a, 0x1c, 0x47, 0x65, 0x74, 0x53, 0x74, 0x61, 0x74, + 0x65, 0x4c, 0x61, 0x74, 0x65, 0x73, 0x74, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x50, 0x72, 0x75, + 0x6e, 0x65, 0x64, 0x56, 0x32, 0x12, 0x2e, 0x2e, 0x65, 0x63, 0x73, 0x73, 0x6e, 0x61, 0x70, 0x73, + 0x68, 0x6f, 0x74, 0x2e, 0x45, 0x43, 0x53, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x4c, 0x61, 0x74, 0x65, 0x73, 0x74, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x50, + 0x72, 0x75, 0x6e, 0x65, 0x64, 0x1a, 0x1c, 0x2e, 0x65, 0x63, 0x73, 0x73, 0x6e, 0x61, 0x70, 0x73, + 0x68, 0x6f, 0x74, 0x2e, 0x45, 0x43, 0x53, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x70, 0x6c, + 0x79, 0x56, 0x32, 0x22, 0x00, 0x30, 0x01, 0x12, 0x61, 0x0a, 0x13, 0x47, 0x65, 0x74, 0x53, 0x74, + 0x61, 0x74, 0x65, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x4c, 0x61, 0x74, 0x65, 0x73, 0x74, 0x12, 0x27, + 0x2e, 0x65, 0x63, 0x73, 0x73, 0x6e, 0x61, 0x70, 0x73, 0x68, 0x6f, 0x74, 0x2e, 0x45, 0x43, 0x53, + 0x53, 0x74, 0x61, 0x74, 0x65, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x4c, 0x61, 0x74, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x65, 0x63, 0x73, 0x73, 0x6e, 0x61, + 0x70, 0x73, 0x68, 0x6f, 0x74, 0x2e, 0x45, 0x43, 0x53, 0x53, 0x74, 0x61, 0x74, 0x65, 0x42, 0x6c, + 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x12, 0x54, 0x0a, 0x0f, 0x47, 0x65, + 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x41, 0x74, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x12, 0x23, 0x2e, + 0x65, 0x63, 0x73, 0x73, 0x6e, 0x61, 0x70, 0x73, 0x68, 0x6f, 0x74, 0x2e, 0x45, 0x43, 0x53, 0x53, + 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x41, 0x74, 0x42, 0x6c, 0x6f, + 0x63, 0x6b, 0x1a, 0x1a, 0x2e, 0x65, 0x63, 0x73, 0x73, 0x6e, 0x61, 0x70, 0x73, 0x68, 0x6f, 0x74, + 0x2e, 0x45, 0x43, 0x53, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, + 0x12, 0x3e, 0x0a, 0x09, 0x47, 0x65, 0x74, 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x73, 0x12, 0x1a, 0x2e, + 0x65, 0x63, 0x73, 0x73, 0x6e, 0x61, 0x70, 0x73, 0x68, 0x6f, 0x74, 0x2e, 0x57, 0x6f, 0x72, 0x6c, + 0x64, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x65, 0x63, 0x73, 0x73, + 0x6e, 0x61, 0x70, 0x73, 0x68, 0x6f, 0x74, 0x2e, 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x73, 0x22, 0x00, + 0x42, 0x1a, 0x5a, 0x18, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x67, 0x6f, 0x2f, + 0x65, 0x63, 0x73, 0x2d, 0x73, 0x6e, 0x61, 0x70, 0x73, 0x68, 0x6f, 0x74, 0x62, 0x06, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -802,7 +908,7 @@ func file_proto_ecs_snapshot_proto_rawDescGZIP() []byte { return file_proto_ecs_snapshot_proto_rawDescData } -var file_proto_ecs_snapshot_proto_msgTypes = make([]protoimpl.MessageInfo, 11) +var file_proto_ecs_snapshot_proto_msgTypes = make([]protoimpl.MessageInfo, 12) var file_proto_ecs_snapshot_proto_goTypes = []interface{}{ (*ECSState)(nil), // 0: ecssnapshot.ECSState (*ECSStateSnapshot)(nil), // 1: ecssnapshot.ECSStateSnapshot @@ -814,28 +920,34 @@ var file_proto_ecs_snapshot_proto_goTypes = []interface{}{ (*ECSStateRequestAtBlock)(nil), // 7: ecssnapshot.ECSStateRequestAtBlock (*WorldsRequest)(nil), // 8: ecssnapshot.WorldsRequest (*ECSStateReply)(nil), // 9: ecssnapshot.ECSStateReply - (*ECSStateBlockReply)(nil), // 10: ecssnapshot.ECSStateBlockReply + (*ECSStateReplyV2)(nil), // 10: ecssnapshot.ECSStateReplyV2 + (*ECSStateBlockReply)(nil), // 11: ecssnapshot.ECSStateBlockReply } var file_proto_ecs_snapshot_proto_depIdxs = []int32{ 0, // 0: ecssnapshot.ECSStateSnapshot.state:type_name -> ecssnapshot.ECSState 0, // 1: ecssnapshot.ECSStateReply.state:type_name -> ecssnapshot.ECSState - 3, // 2: ecssnapshot.ECSStateSnapshotService.GetStateLatest:input_type -> ecssnapshot.ECSStateRequestLatest - 5, // 3: ecssnapshot.ECSStateSnapshotService.GetStateLatestStream:input_type -> ecssnapshot.ECSStateRequestLatestStream - 4, // 4: ecssnapshot.ECSStateSnapshotService.GetStateLatestStreamPruned:input_type -> ecssnapshot.ECSStateRequestLatestStreamPruned - 6, // 5: ecssnapshot.ECSStateSnapshotService.GetStateBlockLatest:input_type -> ecssnapshot.ECSStateBlockRequestLatest - 7, // 6: ecssnapshot.ECSStateSnapshotService.GetStateAtBlock:input_type -> ecssnapshot.ECSStateRequestAtBlock - 8, // 7: ecssnapshot.ECSStateSnapshotService.GetWorlds:input_type -> ecssnapshot.WorldsRequest - 9, // 8: ecssnapshot.ECSStateSnapshotService.GetStateLatest:output_type -> ecssnapshot.ECSStateReply - 9, // 9: ecssnapshot.ECSStateSnapshotService.GetStateLatestStream:output_type -> ecssnapshot.ECSStateReply - 9, // 10: ecssnapshot.ECSStateSnapshotService.GetStateLatestStreamPruned:output_type -> ecssnapshot.ECSStateReply - 10, // 11: ecssnapshot.ECSStateSnapshotService.GetStateBlockLatest:output_type -> ecssnapshot.ECSStateBlockReply - 9, // 12: ecssnapshot.ECSStateSnapshotService.GetStateAtBlock:output_type -> ecssnapshot.ECSStateReply - 2, // 13: ecssnapshot.ECSStateSnapshotService.GetWorlds:output_type -> ecssnapshot.Worlds - 8, // [8:14] is the sub-list for method output_type - 2, // [2:8] is the sub-list for method input_type - 2, // [2:2] is the sub-list for extension type_name - 2, // [2:2] is the sub-list for extension extendee - 0, // [0:2] is the sub-list for field type_name + 0, // 2: ecssnapshot.ECSStateReplyV2.state:type_name -> ecssnapshot.ECSState + 3, // 3: ecssnapshot.ECSStateSnapshotService.GetStateLatest:input_type -> ecssnapshot.ECSStateRequestLatest + 5, // 4: ecssnapshot.ECSStateSnapshotService.GetStateLatestStream:input_type -> ecssnapshot.ECSStateRequestLatestStream + 5, // 5: ecssnapshot.ECSStateSnapshotService.GetStateLatestStreamV2:input_type -> ecssnapshot.ECSStateRequestLatestStream + 4, // 6: ecssnapshot.ECSStateSnapshotService.GetStateLatestStreamPruned:input_type -> ecssnapshot.ECSStateRequestLatestStreamPruned + 4, // 7: ecssnapshot.ECSStateSnapshotService.GetStateLatestStreamPrunedV2:input_type -> ecssnapshot.ECSStateRequestLatestStreamPruned + 6, // 8: ecssnapshot.ECSStateSnapshotService.GetStateBlockLatest:input_type -> ecssnapshot.ECSStateBlockRequestLatest + 7, // 9: ecssnapshot.ECSStateSnapshotService.GetStateAtBlock:input_type -> ecssnapshot.ECSStateRequestAtBlock + 8, // 10: ecssnapshot.ECSStateSnapshotService.GetWorlds:input_type -> ecssnapshot.WorldsRequest + 9, // 11: ecssnapshot.ECSStateSnapshotService.GetStateLatest:output_type -> ecssnapshot.ECSStateReply + 9, // 12: ecssnapshot.ECSStateSnapshotService.GetStateLatestStream:output_type -> ecssnapshot.ECSStateReply + 10, // 13: ecssnapshot.ECSStateSnapshotService.GetStateLatestStreamV2:output_type -> ecssnapshot.ECSStateReplyV2 + 9, // 14: ecssnapshot.ECSStateSnapshotService.GetStateLatestStreamPruned:output_type -> ecssnapshot.ECSStateReply + 10, // 15: ecssnapshot.ECSStateSnapshotService.GetStateLatestStreamPrunedV2:output_type -> ecssnapshot.ECSStateReplyV2 + 11, // 16: ecssnapshot.ECSStateSnapshotService.GetStateBlockLatest:output_type -> ecssnapshot.ECSStateBlockReply + 9, // 17: ecssnapshot.ECSStateSnapshotService.GetStateAtBlock:output_type -> ecssnapshot.ECSStateReply + 2, // 18: ecssnapshot.ECSStateSnapshotService.GetWorlds:output_type -> ecssnapshot.Worlds + 11, // [11:19] is the sub-list for method output_type + 3, // [3:11] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 3, // [3:3] is the sub-list for extension extendee + 0, // [0:3] is the sub-list for field type_name } func init() { file_proto_ecs_snapshot_proto_init() } @@ -965,6 +1077,18 @@ func file_proto_ecs_snapshot_proto_init() { } } file_proto_ecs_snapshot_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ECSStateReplyV2); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_ecs_snapshot_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*ECSStateBlockReply); i { case 0: return &v.state @@ -985,7 +1109,7 @@ func file_proto_ecs_snapshot_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_proto_ecs_snapshot_proto_rawDesc, NumEnums: 0, - NumMessages: 11, + NumMessages: 12, NumExtensions: 0, NumServices: 1, }, diff --git a/packages/services/protobuf/go/ecs-snapshot/ecs-snapshot_grpc.pb.go b/packages/services/protobuf/go/ecs-snapshot/ecs-snapshot_grpc.pb.go index 4fbc1379f0..3ba6d80afb 100644 --- a/packages/services/protobuf/go/ecs-snapshot/ecs-snapshot_grpc.pb.go +++ b/packages/services/protobuf/go/ecs-snapshot/ecs-snapshot_grpc.pb.go @@ -26,8 +26,16 @@ type ECSStateSnapshotServiceClient interface { GetStateLatest(ctx context.Context, in *ECSStateRequestLatest, opts ...grpc.CallOption) (*ECSStateReply, error) // Requests the latest ECS state in stream format, which will chunk the state. GetStateLatestStream(ctx context.Context, in *ECSStateRequestLatestStream, opts ...grpc.CallOption) (ECSStateSnapshotService_GetStateLatestStreamClient, error) + // Requests the latest ECS state in stream format, which will chunk the state. + // + // V2 version optimized to return entities as raw bytes. + GetStateLatestStreamV2(ctx context.Context, in *ECSStateRequestLatestStream, opts ...grpc.CallOption) (ECSStateSnapshotService_GetStateLatestStreamV2Client, error) // Requests the latest ECS state, with aditional pruning. GetStateLatestStreamPruned(ctx context.Context, in *ECSStateRequestLatestStreamPruned, opts ...grpc.CallOption) (ECSStateSnapshotService_GetStateLatestStreamPrunedClient, error) + // Requests the latest ECS state, with aditional pruning. + // + // V2 version optimized to return entities as raw bytes. + GetStateLatestStreamPrunedV2(ctx context.Context, in *ECSStateRequestLatestStreamPruned, opts ...grpc.CallOption) (ECSStateSnapshotService_GetStateLatestStreamPrunedV2Client, error) // Requests the latest block number based on the latest ECS state. GetStateBlockLatest(ctx context.Context, in *ECSStateBlockRequestLatest, opts ...grpc.CallOption) (*ECSStateBlockReply, error) // Requests the ECS state at specific block. @@ -85,8 +93,40 @@ func (x *eCSStateSnapshotServiceGetStateLatestStreamClient) Recv() (*ECSStateRep return m, nil } +func (c *eCSStateSnapshotServiceClient) GetStateLatestStreamV2(ctx context.Context, in *ECSStateRequestLatestStream, opts ...grpc.CallOption) (ECSStateSnapshotService_GetStateLatestStreamV2Client, error) { + stream, err := c.cc.NewStream(ctx, &ECSStateSnapshotService_ServiceDesc.Streams[1], "/ecssnapshot.ECSStateSnapshotService/GetStateLatestStreamV2", opts...) + if err != nil { + return nil, err + } + x := &eCSStateSnapshotServiceGetStateLatestStreamV2Client{stream} + if err := x.ClientStream.SendMsg(in); err != nil { + return nil, err + } + if err := x.ClientStream.CloseSend(); err != nil { + return nil, err + } + return x, nil +} + +type ECSStateSnapshotService_GetStateLatestStreamV2Client interface { + Recv() (*ECSStateReplyV2, error) + grpc.ClientStream +} + +type eCSStateSnapshotServiceGetStateLatestStreamV2Client struct { + grpc.ClientStream +} + +func (x *eCSStateSnapshotServiceGetStateLatestStreamV2Client) Recv() (*ECSStateReplyV2, error) { + m := new(ECSStateReplyV2) + if err := x.ClientStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + func (c *eCSStateSnapshotServiceClient) GetStateLatestStreamPruned(ctx context.Context, in *ECSStateRequestLatestStreamPruned, opts ...grpc.CallOption) (ECSStateSnapshotService_GetStateLatestStreamPrunedClient, error) { - stream, err := c.cc.NewStream(ctx, &ECSStateSnapshotService_ServiceDesc.Streams[1], "/ecssnapshot.ECSStateSnapshotService/GetStateLatestStreamPruned", opts...) + stream, err := c.cc.NewStream(ctx, &ECSStateSnapshotService_ServiceDesc.Streams[2], "/ecssnapshot.ECSStateSnapshotService/GetStateLatestStreamPruned", opts...) if err != nil { return nil, err } @@ -117,6 +157,38 @@ func (x *eCSStateSnapshotServiceGetStateLatestStreamPrunedClient) Recv() (*ECSSt return m, nil } +func (c *eCSStateSnapshotServiceClient) GetStateLatestStreamPrunedV2(ctx context.Context, in *ECSStateRequestLatestStreamPruned, opts ...grpc.CallOption) (ECSStateSnapshotService_GetStateLatestStreamPrunedV2Client, error) { + stream, err := c.cc.NewStream(ctx, &ECSStateSnapshotService_ServiceDesc.Streams[3], "/ecssnapshot.ECSStateSnapshotService/GetStateLatestStreamPrunedV2", opts...) + if err != nil { + return nil, err + } + x := &eCSStateSnapshotServiceGetStateLatestStreamPrunedV2Client{stream} + if err := x.ClientStream.SendMsg(in); err != nil { + return nil, err + } + if err := x.ClientStream.CloseSend(); err != nil { + return nil, err + } + return x, nil +} + +type ECSStateSnapshotService_GetStateLatestStreamPrunedV2Client interface { + Recv() (*ECSStateReplyV2, error) + grpc.ClientStream +} + +type eCSStateSnapshotServiceGetStateLatestStreamPrunedV2Client struct { + grpc.ClientStream +} + +func (x *eCSStateSnapshotServiceGetStateLatestStreamPrunedV2Client) Recv() (*ECSStateReplyV2, error) { + m := new(ECSStateReplyV2) + if err := x.ClientStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + func (c *eCSStateSnapshotServiceClient) GetStateBlockLatest(ctx context.Context, in *ECSStateBlockRequestLatest, opts ...grpc.CallOption) (*ECSStateBlockReply, error) { out := new(ECSStateBlockReply) err := c.cc.Invoke(ctx, "/ecssnapshot.ECSStateSnapshotService/GetStateBlockLatest", in, out, opts...) @@ -152,8 +224,16 @@ type ECSStateSnapshotServiceServer interface { GetStateLatest(context.Context, *ECSStateRequestLatest) (*ECSStateReply, error) // Requests the latest ECS state in stream format, which will chunk the state. GetStateLatestStream(*ECSStateRequestLatestStream, ECSStateSnapshotService_GetStateLatestStreamServer) error + // Requests the latest ECS state in stream format, which will chunk the state. + // + // V2 version optimized to return entities as raw bytes. + GetStateLatestStreamV2(*ECSStateRequestLatestStream, ECSStateSnapshotService_GetStateLatestStreamV2Server) error // Requests the latest ECS state, with aditional pruning. GetStateLatestStreamPruned(*ECSStateRequestLatestStreamPruned, ECSStateSnapshotService_GetStateLatestStreamPrunedServer) error + // Requests the latest ECS state, with aditional pruning. + // + // V2 version optimized to return entities as raw bytes. + GetStateLatestStreamPrunedV2(*ECSStateRequestLatestStreamPruned, ECSStateSnapshotService_GetStateLatestStreamPrunedV2Server) error // Requests the latest block number based on the latest ECS state. GetStateBlockLatest(context.Context, *ECSStateBlockRequestLatest) (*ECSStateBlockReply, error) // Requests the ECS state at specific block. @@ -173,9 +253,15 @@ func (UnimplementedECSStateSnapshotServiceServer) GetStateLatest(context.Context func (UnimplementedECSStateSnapshotServiceServer) GetStateLatestStream(*ECSStateRequestLatestStream, ECSStateSnapshotService_GetStateLatestStreamServer) error { return status.Errorf(codes.Unimplemented, "method GetStateLatestStream not implemented") } +func (UnimplementedECSStateSnapshotServiceServer) GetStateLatestStreamV2(*ECSStateRequestLatestStream, ECSStateSnapshotService_GetStateLatestStreamV2Server) error { + return status.Errorf(codes.Unimplemented, "method GetStateLatestStreamV2 not implemented") +} func (UnimplementedECSStateSnapshotServiceServer) GetStateLatestStreamPruned(*ECSStateRequestLatestStreamPruned, ECSStateSnapshotService_GetStateLatestStreamPrunedServer) error { return status.Errorf(codes.Unimplemented, "method GetStateLatestStreamPruned not implemented") } +func (UnimplementedECSStateSnapshotServiceServer) GetStateLatestStreamPrunedV2(*ECSStateRequestLatestStreamPruned, ECSStateSnapshotService_GetStateLatestStreamPrunedV2Server) error { + return status.Errorf(codes.Unimplemented, "method GetStateLatestStreamPrunedV2 not implemented") +} func (UnimplementedECSStateSnapshotServiceServer) GetStateBlockLatest(context.Context, *ECSStateBlockRequestLatest) (*ECSStateBlockReply, error) { return nil, status.Errorf(codes.Unimplemented, "method GetStateBlockLatest not implemented") } @@ -238,6 +324,27 @@ func (x *eCSStateSnapshotServiceGetStateLatestStreamServer) Send(m *ECSStateRepl return x.ServerStream.SendMsg(m) } +func _ECSStateSnapshotService_GetStateLatestStreamV2_Handler(srv interface{}, stream grpc.ServerStream) error { + m := new(ECSStateRequestLatestStream) + if err := stream.RecvMsg(m); err != nil { + return err + } + return srv.(ECSStateSnapshotServiceServer).GetStateLatestStreamV2(m, &eCSStateSnapshotServiceGetStateLatestStreamV2Server{stream}) +} + +type ECSStateSnapshotService_GetStateLatestStreamV2Server interface { + Send(*ECSStateReplyV2) error + grpc.ServerStream +} + +type eCSStateSnapshotServiceGetStateLatestStreamV2Server struct { + grpc.ServerStream +} + +func (x *eCSStateSnapshotServiceGetStateLatestStreamV2Server) Send(m *ECSStateReplyV2) error { + return x.ServerStream.SendMsg(m) +} + func _ECSStateSnapshotService_GetStateLatestStreamPruned_Handler(srv interface{}, stream grpc.ServerStream) error { m := new(ECSStateRequestLatestStreamPruned) if err := stream.RecvMsg(m); err != nil { @@ -259,6 +366,27 @@ func (x *eCSStateSnapshotServiceGetStateLatestStreamPrunedServer) Send(m *ECSSta return x.ServerStream.SendMsg(m) } +func _ECSStateSnapshotService_GetStateLatestStreamPrunedV2_Handler(srv interface{}, stream grpc.ServerStream) error { + m := new(ECSStateRequestLatestStreamPruned) + if err := stream.RecvMsg(m); err != nil { + return err + } + return srv.(ECSStateSnapshotServiceServer).GetStateLatestStreamPrunedV2(m, &eCSStateSnapshotServiceGetStateLatestStreamPrunedV2Server{stream}) +} + +type ECSStateSnapshotService_GetStateLatestStreamPrunedV2Server interface { + Send(*ECSStateReplyV2) error + grpc.ServerStream +} + +type eCSStateSnapshotServiceGetStateLatestStreamPrunedV2Server struct { + grpc.ServerStream +} + +func (x *eCSStateSnapshotServiceGetStateLatestStreamPrunedV2Server) Send(m *ECSStateReplyV2) error { + return x.ServerStream.SendMsg(m) +} + func _ECSStateSnapshotService_GetStateBlockLatest_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(ECSStateBlockRequestLatest) if err := dec(in); err != nil { @@ -343,11 +471,21 @@ var ECSStateSnapshotService_ServiceDesc = grpc.ServiceDesc{ Handler: _ECSStateSnapshotService_GetStateLatestStream_Handler, ServerStreams: true, }, + { + StreamName: "GetStateLatestStreamV2", + Handler: _ECSStateSnapshotService_GetStateLatestStreamV2_Handler, + ServerStreams: true, + }, { StreamName: "GetStateLatestStreamPruned", Handler: _ECSStateSnapshotService_GetStateLatestStreamPruned_Handler, ServerStreams: true, }, + { + StreamName: "GetStateLatestStreamPrunedV2", + Handler: _ECSStateSnapshotService_GetStateLatestStreamPrunedV2_Handler, + ServerStreams: true, + }, }, Metadata: "proto/ecs-snapshot.proto", } diff --git a/packages/services/protobuf/ts/ecs-snapshot/ecs-snapshot.ts b/packages/services/protobuf/ts/ecs-snapshot/ecs-snapshot.ts index 3b896e5773..7e83f4b500 100644 --- a/packages/services/protobuf/ts/ecs-snapshot/ecs-snapshot.ts +++ b/packages/services/protobuf/ts/ecs-snapshot/ecs-snapshot.ts @@ -66,6 +66,14 @@ export interface ECSStateReply { blockNumber: number; } +export interface ECSStateReplyV2 { + state: ECSState[]; + stateComponents: string[]; + stateEntities: Uint8Array[]; + stateHash: string; + blockNumber: number; +} + export interface ECSStateBlockReply { blockNumber: number; } @@ -553,6 +561,71 @@ export const ECSStateReply = { }, }; +function createBaseECSStateReplyV2(): ECSStateReplyV2 { + return { state: [], stateComponents: [], stateEntities: [], stateHash: "", blockNumber: 0 }; +} + +export const ECSStateReplyV2 = { + encode(message: ECSStateReplyV2, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + for (const v of message.state) { + ECSState.encode(v!, writer.uint32(10).fork()).ldelim(); + } + for (const v of message.stateComponents) { + writer.uint32(18).string(v!); + } + for (const v of message.stateEntities) { + writer.uint32(26).bytes(v!); + } + if (message.stateHash !== "") { + writer.uint32(34).string(message.stateHash); + } + if (message.blockNumber !== 0) { + writer.uint32(40).uint32(message.blockNumber); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): ECSStateReplyV2 { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseECSStateReplyV2(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.state.push(ECSState.decode(reader, reader.uint32())); + break; + case 2: + message.stateComponents.push(reader.string()); + break; + case 3: + message.stateEntities.push(reader.bytes()); + break; + case 4: + message.stateHash = reader.string(); + break; + case 5: + message.blockNumber = reader.uint32(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromPartial(object: DeepPartial): ECSStateReplyV2 { + const message = createBaseECSStateReplyV2(); + message.state = object.state?.map((e) => ECSState.fromPartial(e)) || []; + message.stateComponents = object.stateComponents?.map((e) => e) || []; + message.stateEntities = object.stateEntities?.map((e) => e) || []; + message.stateHash = object.stateHash ?? ""; + message.blockNumber = object.blockNumber ?? 0; + return message; + }, +}; + function createBaseECSStateBlockReply(): ECSStateBlockReply { return { blockNumber: 0 }; } @@ -614,6 +687,19 @@ export const ECSStateSnapshotServiceDefinition = { responseStream: true, options: {}, }, + /** + * Requests the latest ECS state in stream format, which will chunk the state. + * + * V2 version optimized to return entities as raw bytes. + */ + getStateLatestStreamV2: { + name: "GetStateLatestStreamV2", + requestType: ECSStateRequestLatestStream, + requestStream: false, + responseType: ECSStateReplyV2, + responseStream: true, + options: {}, + }, /** Requests the latest ECS state, with aditional pruning. */ getStateLatestStreamPruned: { name: "GetStateLatestStreamPruned", @@ -623,6 +709,19 @@ export const ECSStateSnapshotServiceDefinition = { responseStream: true, options: {}, }, + /** + * Requests the latest ECS state, with aditional pruning. + * + * V2 version optimized to return entities as raw bytes. + */ + getStateLatestStreamPrunedV2: { + name: "GetStateLatestStreamPrunedV2", + requestType: ECSStateRequestLatestStreamPruned, + requestStream: false, + responseType: ECSStateReplyV2, + responseStream: true, + options: {}, + }, /** Requests the latest block number based on the latest ECS state. */ getStateBlockLatest: { name: "GetStateBlockLatest", @@ -664,11 +763,29 @@ export interface ECSStateSnapshotServiceServiceImplementation>; + /** + * Requests the latest ECS state in stream format, which will chunk the state. + * + * V2 version optimized to return entities as raw bytes. + */ + getStateLatestStreamV2( + request: ECSStateRequestLatestStream, + context: CallContext & CallContextExt + ): ServerStreamingMethodResult>; /** Requests the latest ECS state, with aditional pruning. */ getStateLatestStreamPruned( request: ECSStateRequestLatestStreamPruned, context: CallContext & CallContextExt ): ServerStreamingMethodResult>; + /** + * Requests the latest ECS state, with aditional pruning. + * + * V2 version optimized to return entities as raw bytes. + */ + getStateLatestStreamPrunedV2( + request: ECSStateRequestLatestStreamPruned, + context: CallContext & CallContextExt + ): ServerStreamingMethodResult>; /** Requests the latest block number based on the latest ECS state. */ getStateBlockLatest( request: ECSStateBlockRequestLatest, @@ -694,11 +811,29 @@ export interface ECSStateSnapshotServiceClient { request: DeepPartial, options?: CallOptions & CallOptionsExt ): AsyncIterable; + /** + * Requests the latest ECS state in stream format, which will chunk the state. + * + * V2 version optimized to return entities as raw bytes. + */ + getStateLatestStreamV2( + request: DeepPartial, + options?: CallOptions & CallOptionsExt + ): AsyncIterable; /** Requests the latest ECS state, with aditional pruning. */ getStateLatestStreamPruned( request: DeepPartial, options?: CallOptions & CallOptionsExt ): AsyncIterable; + /** + * Requests the latest ECS state, with aditional pruning. + * + * V2 version optimized to return entities as raw bytes. + */ + getStateLatestStreamPrunedV2( + request: DeepPartial, + options?: CallOptions & CallOptionsExt + ): AsyncIterable; /** Requests the latest block number based on the latest ECS state. */ getStateBlockLatest( request: DeepPartial, diff --git a/packages/utils/src/bytes.ts b/packages/utils/src/bytes.ts index e1d1e9c932..d913c9a8b3 100644 --- a/packages/utils/src/bytes.ts +++ b/packages/utils/src/bytes.ts @@ -14,6 +14,7 @@ export function hexStringToUint8Array(hexString: string): Uint8Array { } export function Uint8ArrayToHexString(data: Uint8Array): string { + if (data.length === 0) return "0x00"; return formatHex(data.reduce((str, byte) => str + byte.toString(16).padStart(2, "0"), "")); }