From 9ed86d2e9d1fbf79e8338508c8102c09b551af54 Mon Sep 17 00:00:00 2001 From: aaronbuchwald Date: Thu, 14 Sep 2023 13:13:50 -0400 Subject: [PATCH 1/5] database: Comment that Get returns ErrNotFound if the key is not present (#2018) --- database/database.go | 1 + 1 file changed, 1 insertion(+) diff --git a/database/database.go b/database/database.go index 89993a811c2e..d0c274131d75 100644 --- a/database/database.go +++ b/database/database.go @@ -21,6 +21,7 @@ type KeyValueReader interface { Has(key []byte) (bool, error) // Get retrieves the given key if it's present in the key-value data store. + // Returns ErrNotFound if the key is not present in the key-value data store. // // Note: [key] is safe to modify and read after calling Get. // The returned byte slice is safe to read, but cannot be modified. From ed452f0747aff763b860b8f2c7c072f80a0d732a Mon Sep 17 00:00:00 2001 From: Dhruba Basu <7675102+dhrubabasu@users.noreply.github.com> Date: Thu, 14 Sep 2023 17:21:12 -0400 Subject: [PATCH 2/5] Return `height` from `platform.GetCurrentSupply` (#2022) --- vms/platformvm/client.go | 8 ++++---- vms/platformvm/service.go | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/vms/platformvm/client.go b/vms/platformvm/client.go index 9b1bab2feec2..3796ad7ff86a 100644 --- a/vms/platformvm/client.go +++ b/vms/platformvm/client.go @@ -78,8 +78,8 @@ type Client interface { GetCurrentValidators(ctx context.Context, subnetID ids.ID, nodeIDs []ids.NodeID, options ...rpc.Option) ([]ClientPermissionlessValidator, error) // GetPendingValidators returns the list of pending validators for subnet with ID [subnetID] GetPendingValidators(ctx context.Context, subnetID ids.ID, nodeIDs []ids.NodeID, options ...rpc.Option) ([]interface{}, []interface{}, error) - // GetCurrentSupply returns an upper bound on the supply of AVAX in the system - GetCurrentSupply(ctx context.Context, subnetID ids.ID, options ...rpc.Option) (uint64, error) + // GetCurrentSupply returns an upper bound on the supply of AVAX in the system along with the P-chain height + GetCurrentSupply(ctx context.Context, subnetID ids.ID, options ...rpc.Option) (uint64, uint64, error) // SampleValidators returns the nodeIDs of a sample of [sampleSize] validators from the current validator set for subnet with ID [subnetID] SampleValidators(ctx context.Context, subnetID ids.ID, sampleSize uint16, options ...rpc.Option) ([]ids.NodeID, error) // AddValidator issues a transaction to add a validator to the primary network @@ -455,12 +455,12 @@ func (c *client) GetPendingValidators( return res.Validators, res.Delegators, err } -func (c *client) GetCurrentSupply(ctx context.Context, subnetID ids.ID, options ...rpc.Option) (uint64, error) { +func (c *client) GetCurrentSupply(ctx context.Context, subnetID ids.ID, options ...rpc.Option) (uint64, uint64, error) { res := &GetCurrentSupplyReply{} err := c.requester.SendRequest(ctx, "platform.getCurrentSupply", &GetCurrentSupplyArgs{ SubnetID: subnetID, }, res, options...) - return uint64(res.Supply), err + return uint64(res.Supply), uint64(res.Height), err } func (c *client) SampleValidators(ctx context.Context, subnetID ids.ID, sampleSize uint16, options ...rpc.Option) ([]ids.NodeID, error) { diff --git a/vms/platformvm/service.go b/vms/platformvm/service.go index 9e2ea52484cd..db673036f4a2 100644 --- a/vms/platformvm/service.go +++ b/vms/platformvm/service.go @@ -1082,18 +1082,30 @@ type GetCurrentSupplyArgs struct { // GetCurrentSupplyReply are the results from calling GetCurrentSupply type GetCurrentSupplyReply struct { Supply json.Uint64 `json:"supply"` + Height json.Uint64 `json:"height"` } // GetCurrentSupply returns an upper bound on the supply of AVAX in the system -func (s *Service) GetCurrentSupply(_ *http.Request, args *GetCurrentSupplyArgs, reply *GetCurrentSupplyReply) error { +func (s *Service) GetCurrentSupply(r *http.Request, args *GetCurrentSupplyArgs, reply *GetCurrentSupplyReply) error { s.vm.ctx.Log.Debug("API called", zap.String("service", "platform"), zap.String("method", "getCurrentSupply"), ) supply, err := s.vm.state.GetCurrentSupply(args.SubnetID) + if err != nil { + return fmt.Errorf("fetching current supply failed: %w", err) + } reply.Supply = json.Uint64(supply) - return err + + ctx := r.Context() + height, err := s.vm.GetCurrentHeight(ctx) + if err != nil { + return fmt.Errorf("fetching current height failed: %w", err) + } + reply.Height = json.Uint64(height) + + return nil } // SampleValidatorsArgs are the arguments for calling SampleValidators From 6fe9dd03919975fd6b5dcc50ce845549645594fd Mon Sep 17 00:00:00 2001 From: Dhruba Basu <7675102+dhrubabasu@users.noreply.github.com> Date: Thu, 14 Sep 2023 17:49:14 -0400 Subject: [PATCH 3/5] Cleanup `platform.GetHeight` API implementation (#2023) --- vms/platformvm/service.go | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/vms/platformvm/service.go b/vms/platformvm/service.go index db673036f4a2..158cdd2c038e 100644 --- a/vms/platformvm/service.go +++ b/vms/platformvm/service.go @@ -107,16 +107,9 @@ func (s *Service) GetHeight(r *http.Request, _ *struct{}, response *api.GetHeigh ) ctx := r.Context() - lastAcceptedID, err := s.vm.LastAccepted(ctx) - if err != nil { - return fmt.Errorf("couldn't get last accepted block ID: %w", err) - } - lastAccepted, err := s.vm.GetBlock(ctx, lastAcceptedID) - if err != nil { - return fmt.Errorf("couldn't get last accepted block: %w", err) - } - response.Height = json.Uint64(lastAccepted.Height()) - return nil + height, err := s.vm.GetCurrentHeight(ctx) + response.Height = json.Uint64(height) + return err } // ExportKeyArgs are arguments for ExportKey From 3366c15881027406b483e511c3beca7bb6c77840 Mon Sep 17 00:00:00 2001 From: David Boehm <91908103+dboehm-avalabs@users.noreply.github.com> Date: Fri, 15 Sep 2023 10:15:56 -0400 Subject: [PATCH 4/5] Merkle db fix range proof commit bug (#2019) Signed-off-by: David Boehm <91908103+dboehm-avalabs@users.noreply.github.com> Co-authored-by: Darioush Jalali Co-authored-by: Dan Laine --- proto/pb/sync/sync.pb.go | 263 ++++++++++++++++++++------------------- proto/sync/sync.proto | 3 +- x/merkledb/db.go | 23 ++-- x/merkledb/db_test.go | 47 ++++++- x/merkledb/mock_db.go | 8 +- x/sync/g_db/db_client.go | 5 + x/sync/g_db/db_server.go | 7 +- x/sync/manager.go | 15 +-- x/sync/sync_test.go | 1 + 9 files changed, 219 insertions(+), 153 deletions(-) diff --git a/proto/pb/sync/sync.pb.go b/proto/pb/sync/sync.pb.go index 1ae2ee8ed331..9cd9360dccf3 100644 --- a/proto/pb/sync/sync.pb.go +++ b/proto/pb/sync/sync.pb.go @@ -1009,7 +1009,8 @@ type CommitRangeProofRequest struct { unknownFields protoimpl.UnknownFields StartKey *MaybeBytes `protobuf:"bytes,1,opt,name=start_key,json=startKey,proto3" json:"start_key,omitempty"` - RangeProof *RangeProof `protobuf:"bytes,2,opt,name=range_proof,json=rangeProof,proto3" json:"range_proof,omitempty"` + EndKey *MaybeBytes `protobuf:"bytes,2,opt,name=end_key,json=endKey,proto3" json:"end_key,omitempty"` + RangeProof *RangeProof `protobuf:"bytes,3,opt,name=range_proof,json=rangeProof,proto3" json:"range_proof,omitempty"` } func (x *CommitRangeProofRequest) Reset() { @@ -1051,6 +1052,13 @@ func (x *CommitRangeProofRequest) GetStartKey() *MaybeBytes { return nil } +func (x *CommitRangeProofRequest) GetEndKey() *MaybeBytes { + if x != nil { + return x.EndKey + } + return nil +} + func (x *CommitRangeProofRequest) GetRangeProof() *RangeProof { if x != nil { return x.RangeProof @@ -1599,101 +1607,103 @@ var file_sync_sync_proto_rawDesc = []byte{ 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x26, 0x0a, 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, - 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x22, 0x7b, 0x0a, 0x17, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, - 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x12, 0x2d, 0x0a, 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, - 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, 0x08, 0x73, 0x74, 0x61, 0x72, 0x74, 0x4b, 0x65, 0x79, - 0x12, 0x31, 0x0a, 0x0b, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x5f, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x52, 0x61, 0x6e, - 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x0a, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, - 0x6f, 0x6f, 0x66, 0x22, 0x9f, 0x01, 0x0a, 0x0b, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, - 0x6f, 0x6f, 0x66, 0x12, 0x30, 0x0a, 0x0b, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x70, 0x72, 0x6f, - 0x6f, 0x66, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, - 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x0a, 0x73, 0x74, 0x61, 0x72, 0x74, - 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x2c, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x5f, 0x70, 0x72, 0x6f, - 0x6f, 0x66, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, - 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x08, 0x65, 0x6e, 0x64, 0x50, 0x72, - 0x6f, 0x6f, 0x66, 0x12, 0x30, 0x0a, 0x0b, 0x6b, 0x65, 0x79, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x67, - 0x65, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, - 0x4b, 0x65, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x0a, 0x6b, 0x65, 0x79, 0x43, 0x68, - 0x61, 0x6e, 0x67, 0x65, 0x73, 0x22, 0x85, 0x01, 0x0a, 0x0a, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, - 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x25, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x72, 0x74, 0x18, 0x01, 0x20, - 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x50, 0x72, 0x6f, 0x6f, 0x66, - 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x05, 0x73, 0x74, 0x61, 0x72, 0x74, 0x12, 0x21, 0x0a, 0x03, 0x65, - 0x6e, 0x64, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, - 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x03, 0x65, 0x6e, 0x64, 0x12, 0x2d, - 0x0a, 0x0a, 0x6b, 0x65, 0x79, 0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x18, 0x03, 0x20, 0x03, - 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, - 0x75, 0x65, 0x52, 0x09, 0x6b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x22, 0xe1, 0x01, - 0x0a, 0x09, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x4e, 0x6f, 0x64, 0x65, 0x12, 0x26, 0x0a, 0x03, 0x6b, - 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, - 0x53, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x64, 0x50, 0x61, 0x74, 0x68, 0x52, 0x03, - 0x6b, 0x65, 0x79, 0x12, 0x34, 0x0a, 0x0d, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x5f, 0x6f, 0x72, 0x5f, - 0x68, 0x61, 0x73, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, - 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, 0x0b, 0x76, 0x61, - 0x6c, 0x75, 0x65, 0x4f, 0x72, 0x48, 0x61, 0x73, 0x68, 0x12, 0x39, 0x0a, 0x08, 0x63, 0x68, 0x69, - 0x6c, 0x64, 0x72, 0x65, 0x6e, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x73, 0x79, - 0x6e, 0x63, 0x2e, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x4e, 0x6f, 0x64, 0x65, 0x2e, 0x43, 0x68, 0x69, - 0x6c, 0x64, 0x72, 0x65, 0x6e, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x08, 0x63, 0x68, 0x69, 0x6c, - 0x64, 0x72, 0x65, 0x6e, 0x1a, 0x3b, 0x0a, 0x0d, 0x43, 0x68, 0x69, 0x6c, 0x64, 0x72, 0x65, 0x6e, - 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x0d, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, - 0x01, 0x22, 0x45, 0x0a, 0x09, 0x4b, 0x65, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x12, 0x10, - 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x6b, 0x65, 0x79, - 0x12, 0x26, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, - 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, - 0x73, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x4b, 0x0a, 0x0e, 0x53, 0x65, 0x72, 0x69, - 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x64, 0x50, 0x61, 0x74, 0x68, 0x12, 0x23, 0x0a, 0x0d, 0x6e, 0x69, - 0x62, 0x62, 0x6c, 0x65, 0x5f, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x04, 0x52, 0x0c, 0x6e, 0x69, 0x62, 0x62, 0x6c, 0x65, 0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x12, - 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, - 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x41, 0x0a, 0x0a, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, - 0x74, 0x65, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x69, 0x73, 0x5f, - 0x6e, 0x6f, 0x74, 0x68, 0x69, 0x6e, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x69, - 0x73, 0x4e, 0x6f, 0x74, 0x68, 0x69, 0x6e, 0x67, 0x22, 0x32, 0x0a, 0x08, 0x4b, 0x65, 0x79, 0x56, - 0x61, 0x6c, 0x75, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x0c, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x32, 0x8a, 0x04, 0x0a, - 0x02, 0x44, 0x42, 0x12, 0x44, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x4d, 0x65, 0x72, 0x6b, 0x6c, 0x65, - 0x52, 0x6f, 0x6f, 0x74, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x1b, 0x2e, 0x73, - 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x4d, 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x52, 0x6f, 0x6f, - 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x39, 0x0a, 0x08, 0x47, 0x65, 0x74, - 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x15, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, - 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x73, - 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4b, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, - 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1b, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, - 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x68, - 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x12, 0x54, 0x0a, 0x11, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, - 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1e, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x56, 0x65, - 0x72, 0x69, 0x66, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x56, 0x65, - 0x72, 0x69, 0x66, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4b, 0x0a, 0x11, 0x43, 0x6f, 0x6d, 0x6d, 0x69, - 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1e, 0x2e, 0x73, - 0x79, 0x6e, 0x63, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, - 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, - 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, - 0x6d, 0x70, 0x74, 0x79, 0x12, 0x48, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, - 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1a, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, - 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x1a, 0x1b, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x67, - 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x49, - 0x0a, 0x10, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, - 0x6f, 0x66, 0x12, 0x1d, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, - 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x42, 0x2f, 0x5a, 0x2d, 0x67, 0x69, 0x74, - 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x76, 0x61, 0x2d, 0x6c, 0x61, 0x62, 0x73, - 0x2f, 0x61, 0x76, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x68, 0x65, 0x67, 0x6f, 0x2f, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x2f, 0x70, 0x62, 0x2f, 0x73, 0x79, 0x6e, 0x63, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x33, + 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x22, 0xa6, 0x01, 0x0a, 0x17, 0x43, 0x6f, 0x6d, 0x6d, 0x69, + 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x12, 0x2d, 0x0a, 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x6b, 0x65, 0x79, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, + 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, 0x08, 0x73, 0x74, 0x61, 0x72, 0x74, 0x4b, 0x65, + 0x79, 0x12, 0x29, 0x0a, 0x07, 0x65, 0x6e, 0x64, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, + 0x79, 0x74, 0x65, 0x73, 0x52, 0x06, 0x65, 0x6e, 0x64, 0x4b, 0x65, 0x79, 0x12, 0x31, 0x0a, 0x0b, + 0x72, 0x61, 0x6e, 0x67, 0x65, 0x5f, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x03, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, + 0x6f, 0x6f, 0x66, 0x52, 0x0a, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x22, + 0x9f, 0x01, 0x0a, 0x0b, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, + 0x30, 0x0a, 0x0b, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x01, + 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x50, 0x72, 0x6f, 0x6f, + 0x66, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x0a, 0x73, 0x74, 0x61, 0x72, 0x74, 0x50, 0x72, 0x6f, 0x6f, + 0x66, 0x12, 0x2c, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x5f, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x02, + 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x50, 0x72, 0x6f, 0x6f, + 0x66, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x08, 0x65, 0x6e, 0x64, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, + 0x30, 0x0a, 0x0b, 0x6b, 0x65, 0x79, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x73, 0x18, 0x03, + 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4b, 0x65, 0x79, 0x43, + 0x68, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x0a, 0x6b, 0x65, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, + 0x73, 0x22, 0x85, 0x01, 0x0a, 0x0a, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, + 0x12, 0x25, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x72, 0x74, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, + 0x0f, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x4e, 0x6f, 0x64, 0x65, + 0x52, 0x05, 0x73, 0x74, 0x61, 0x72, 0x74, 0x12, 0x21, 0x0a, 0x03, 0x65, 0x6e, 0x64, 0x18, 0x02, + 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x50, 0x72, 0x6f, 0x6f, + 0x66, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x03, 0x65, 0x6e, 0x64, 0x12, 0x2d, 0x0a, 0x0a, 0x6b, 0x65, + 0x79, 0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, + 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x52, 0x09, + 0x6b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x22, 0xe1, 0x01, 0x0a, 0x09, 0x50, 0x72, + 0x6f, 0x6f, 0x66, 0x4e, 0x6f, 0x64, 0x65, 0x12, 0x26, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x53, 0x65, 0x72, 0x69, + 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x64, 0x50, 0x61, 0x74, 0x68, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, + 0x34, 0x0a, 0x0d, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x5f, 0x6f, 0x72, 0x5f, 0x68, 0x61, 0x73, 0x68, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, + 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, 0x0b, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x4f, + 0x72, 0x48, 0x61, 0x73, 0x68, 0x12, 0x39, 0x0a, 0x08, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x72, 0x65, + 0x6e, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x50, + 0x72, 0x6f, 0x6f, 0x66, 0x4e, 0x6f, 0x64, 0x65, 0x2e, 0x43, 0x68, 0x69, 0x6c, 0x64, 0x72, 0x65, + 0x6e, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x08, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x72, 0x65, 0x6e, + 0x1a, 0x3b, 0x0a, 0x0d, 0x43, 0x68, 0x69, 0x6c, 0x64, 0x72, 0x65, 0x6e, 0x45, 0x6e, 0x74, 0x72, + 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x03, + 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x45, 0x0a, + 0x09, 0x4b, 0x65, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, + 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x26, 0x0a, 0x05, + 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, + 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, 0x05, 0x76, + 0x61, 0x6c, 0x75, 0x65, 0x22, 0x4b, 0x0a, 0x0e, 0x53, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x69, 0x7a, + 0x65, 0x64, 0x50, 0x61, 0x74, 0x68, 0x12, 0x23, 0x0a, 0x0d, 0x6e, 0x69, 0x62, 0x62, 0x6c, 0x65, + 0x5f, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0c, 0x6e, + 0x69, 0x62, 0x62, 0x6c, 0x65, 0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x12, 0x14, 0x0a, 0x05, 0x76, + 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, + 0x65, 0x22, 0x41, 0x0a, 0x0a, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x12, + 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, + 0x76, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x69, 0x73, 0x5f, 0x6e, 0x6f, 0x74, 0x68, + 0x69, 0x6e, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x69, 0x73, 0x4e, 0x6f, 0x74, + 0x68, 0x69, 0x6e, 0x67, 0x22, 0x32, 0x0a, 0x08, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x75, 0x65, + 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x6b, + 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x32, 0x8a, 0x04, 0x0a, 0x02, 0x44, 0x42, 0x12, + 0x44, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x4d, 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x52, 0x6f, 0x6f, 0x74, + 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, + 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x1b, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, + 0x47, 0x65, 0x74, 0x4d, 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x52, 0x6f, 0x6f, 0x74, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x39, 0x0a, 0x08, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x6f, + 0x66, 0x12, 0x15, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x6f, + 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, + 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x12, 0x4b, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, + 0x6f, 0x66, 0x12, 0x1b, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, + 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x1c, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, + 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x54, 0x0a, + 0x11, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, + 0x6f, 0x66, 0x12, 0x1e, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, + 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, + 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x12, 0x4b, 0x0a, 0x11, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x43, 0x68, 0x61, + 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1e, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, + 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, + 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, + 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, + 0x12, 0x48, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, + 0x66, 0x12, 0x1a, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x67, + 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, + 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, + 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x49, 0x0a, 0x10, 0x43, 0x6f, + 0x6d, 0x6d, 0x69, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1d, + 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x52, 0x61, 0x6e, 0x67, + 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, + 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, + 0x45, 0x6d, 0x70, 0x74, 0x79, 0x42, 0x2f, 0x5a, 0x2d, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, + 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x76, 0x61, 0x2d, 0x6c, 0x61, 0x62, 0x73, 0x2f, 0x61, 0x76, 0x61, + 0x6c, 0x61, 0x6e, 0x63, 0x68, 0x65, 0x67, 0x6f, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x70, + 0x62, 0x2f, 0x73, 0x79, 0x6e, 0x63, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -1759,36 +1769,37 @@ var file_sync_sync_proto_depIdxs = []int32{ 21, // 19: sync.GetRangeProofRequest.end_key:type_name -> sync.MaybeBytes 17, // 20: sync.GetRangeProofResponse.proof:type_name -> sync.RangeProof 21, // 21: sync.CommitRangeProofRequest.start_key:type_name -> sync.MaybeBytes - 17, // 22: sync.CommitRangeProofRequest.range_proof:type_name -> sync.RangeProof - 18, // 23: sync.ChangeProof.start_proof:type_name -> sync.ProofNode - 18, // 24: sync.ChangeProof.end_proof:type_name -> sync.ProofNode - 19, // 25: sync.ChangeProof.key_changes:type_name -> sync.KeyChange - 18, // 26: sync.RangeProof.start:type_name -> sync.ProofNode - 18, // 27: sync.RangeProof.end:type_name -> sync.ProofNode - 22, // 28: sync.RangeProof.key_values:type_name -> sync.KeyValue - 20, // 29: sync.ProofNode.key:type_name -> sync.SerializedPath - 21, // 30: sync.ProofNode.value_or_hash:type_name -> sync.MaybeBytes - 23, // 31: sync.ProofNode.children:type_name -> sync.ProofNode.ChildrenEntry - 21, // 32: sync.KeyChange.value:type_name -> sync.MaybeBytes - 24, // 33: sync.DB.GetMerkleRoot:input_type -> google.protobuf.Empty - 2, // 34: sync.DB.GetProof:input_type -> sync.GetProofRequest - 7, // 35: sync.DB.GetChangeProof:input_type -> sync.GetChangeProofRequest - 9, // 36: sync.DB.VerifyChangeProof:input_type -> sync.VerifyChangeProofRequest - 11, // 37: sync.DB.CommitChangeProof:input_type -> sync.CommitChangeProofRequest - 13, // 38: sync.DB.GetRangeProof:input_type -> sync.GetRangeProofRequest - 15, // 39: sync.DB.CommitRangeProof:input_type -> sync.CommitRangeProofRequest - 1, // 40: sync.DB.GetMerkleRoot:output_type -> sync.GetMerkleRootResponse - 3, // 41: sync.DB.GetProof:output_type -> sync.GetProofResponse - 8, // 42: sync.DB.GetChangeProof:output_type -> sync.GetChangeProofResponse - 10, // 43: sync.DB.VerifyChangeProof:output_type -> sync.VerifyChangeProofResponse - 24, // 44: sync.DB.CommitChangeProof:output_type -> google.protobuf.Empty - 14, // 45: sync.DB.GetRangeProof:output_type -> sync.GetRangeProofResponse - 24, // 46: sync.DB.CommitRangeProof:output_type -> google.protobuf.Empty - 40, // [40:47] is the sub-list for method output_type - 33, // [33:40] is the sub-list for method input_type - 33, // [33:33] is the sub-list for extension type_name - 33, // [33:33] is the sub-list for extension extendee - 0, // [0:33] is the sub-list for field type_name + 21, // 22: sync.CommitRangeProofRequest.end_key:type_name -> sync.MaybeBytes + 17, // 23: sync.CommitRangeProofRequest.range_proof:type_name -> sync.RangeProof + 18, // 24: sync.ChangeProof.start_proof:type_name -> sync.ProofNode + 18, // 25: sync.ChangeProof.end_proof:type_name -> sync.ProofNode + 19, // 26: sync.ChangeProof.key_changes:type_name -> sync.KeyChange + 18, // 27: sync.RangeProof.start:type_name -> sync.ProofNode + 18, // 28: sync.RangeProof.end:type_name -> sync.ProofNode + 22, // 29: sync.RangeProof.key_values:type_name -> sync.KeyValue + 20, // 30: sync.ProofNode.key:type_name -> sync.SerializedPath + 21, // 31: sync.ProofNode.value_or_hash:type_name -> sync.MaybeBytes + 23, // 32: sync.ProofNode.children:type_name -> sync.ProofNode.ChildrenEntry + 21, // 33: sync.KeyChange.value:type_name -> sync.MaybeBytes + 24, // 34: sync.DB.GetMerkleRoot:input_type -> google.protobuf.Empty + 2, // 35: sync.DB.GetProof:input_type -> sync.GetProofRequest + 7, // 36: sync.DB.GetChangeProof:input_type -> sync.GetChangeProofRequest + 9, // 37: sync.DB.VerifyChangeProof:input_type -> sync.VerifyChangeProofRequest + 11, // 38: sync.DB.CommitChangeProof:input_type -> sync.CommitChangeProofRequest + 13, // 39: sync.DB.GetRangeProof:input_type -> sync.GetRangeProofRequest + 15, // 40: sync.DB.CommitRangeProof:input_type -> sync.CommitRangeProofRequest + 1, // 41: sync.DB.GetMerkleRoot:output_type -> sync.GetMerkleRootResponse + 3, // 42: sync.DB.GetProof:output_type -> sync.GetProofResponse + 8, // 43: sync.DB.GetChangeProof:output_type -> sync.GetChangeProofResponse + 10, // 44: sync.DB.VerifyChangeProof:output_type -> sync.VerifyChangeProofResponse + 24, // 45: sync.DB.CommitChangeProof:output_type -> google.protobuf.Empty + 14, // 46: sync.DB.GetRangeProof:output_type -> sync.GetRangeProofResponse + 24, // 47: sync.DB.CommitRangeProof:output_type -> google.protobuf.Empty + 41, // [41:48] is the sub-list for method output_type + 34, // [34:41] is the sub-list for method input_type + 34, // [34:34] is the sub-list for extension type_name + 34, // [34:34] is the sub-list for extension extendee + 0, // [0:34] is the sub-list for field type_name } func init() { file_sync_sync_proto_init() } diff --git a/proto/sync/sync.proto b/proto/sync/sync.proto index e1c1ccd22ec4..a8a30e061535 100644 --- a/proto/sync/sync.proto +++ b/proto/sync/sync.proto @@ -122,7 +122,8 @@ message GetRangeProofResponse { message CommitRangeProofRequest { MaybeBytes start_key = 1; - RangeProof range_proof = 2; + MaybeBytes end_key = 2; + RangeProof range_proof = 3; } message ChangeProof { diff --git a/x/merkledb/db.go b/x/merkledb/db.go index ee40f43cc69c..df1819fe5983 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -109,8 +109,9 @@ type RangeProofer interface { ) (*RangeProof, error) // CommitRangeProof commits the key/value pairs within the [proof] to the db. - // [start] is the smallest key in the range this [proof] covers. - CommitRangeProof(ctx context.Context, start maybe.Maybe[[]byte], proof *RangeProof) error + // [start] is the smallest possible key in the range this [proof] covers. + // [end] is the largest possible key in the range this [proof] covers. + CommitRangeProof(ctx context.Context, start, end maybe.Maybe[[]byte], proof *RangeProof) error } type MerkleDB interface { @@ -334,7 +335,7 @@ func (db *merkleDB) CommitChangeProof(ctx context.Context, proof *ChangeProof) e return view.commitToDB(ctx) } -func (db *merkleDB) CommitRangeProof(ctx context.Context, start maybe.Maybe[[]byte], proof *RangeProof) error { +func (db *merkleDB) CommitRangeProof(ctx context.Context, start, end maybe.Maybe[[]byte], proof *RangeProof) error { db.commitLock.Lock() defer db.commitLock.Unlock() @@ -352,11 +353,11 @@ func (db *merkleDB) CommitRangeProof(ctx context.Context, start maybe.Maybe[[]by } } - var largestKey []byte + largestKey := end if len(proof.KeyValues) > 0 { - largestKey = proof.KeyValues[len(proof.KeyValues)-1].Key + largestKey = maybe.Some(proof.KeyValues[len(proof.KeyValues)-1].Key) } - keysToDelete, err := db.getKeysNotInSet(start.Value(), largestKey, keys) + keysToDelete, err := db.getKeysNotInSet(start, largestKey, keys) if err != nil { return err } @@ -1128,19 +1129,19 @@ func (db *merkleDB) getHistoricalViewForRange( } // Returns all keys in range [start, end] that aren't in [keySet]. -// If [start] is nil, then the range has no lower bound. -// If [end] is nil, then the range has no upper bound. -func (db *merkleDB) getKeysNotInSet(start, end []byte, keySet set.Set[string]) ([][]byte, error) { +// If [start] is Nothing, then the range has no lower bound. +// If [end] is Nothing, then the range has no upper bound. +func (db *merkleDB) getKeysNotInSet(start, end maybe.Maybe[[]byte], keySet set.Set[string]) ([][]byte, error) { db.lock.RLock() defer db.lock.RUnlock() - it := db.NewIteratorWithStart(start) + it := db.NewIteratorWithStart(start.Value()) defer it.Release() keysNotInSet := make([][]byte, 0, keySet.Len()) for it.Next() { key := it.Key() - if len(end) != 0 && bytes.Compare(key, end) > 0 { + if end.HasValue() && bytes.Compare(key, end.Value()) > 0 { break } if !keySet.Contains(string(key)) { diff --git a/x/merkledb/db_test.go b/x/merkledb/db_test.go index 258bced5e633..899dca4e0a27 100644 --- a/x/merkledb/db_test.go +++ b/x/merkledb/db_test.go @@ -301,7 +301,47 @@ func Test_MerkleDB_Invalidate_Siblings_On_Commit(t *testing.T) { require.False(viewToCommit.(*trieView).isInvalid()) } -func Test_MerkleDB_Commit_Proof_To_Empty_Trie(t *testing.T) { +func Test_MerkleDB_CommitRangeProof_DeletesValuesInRange(t *testing.T) { + require := require.New(t) + + db, err := getBasicDB() + require.NoError(err) + + // value that shouldn't be deleted + require.NoError(db.Put([]byte("key6"), []byte("3"))) + + startRoot, err := db.GetMerkleRoot(context.Background()) + require.NoError(err) + + // Get an empty proof + proof, err := db.GetRangeProof( + context.Background(), + maybe.Nothing[[]byte](), + maybe.Some([]byte("key3")), + 10, + ) + require.NoError(err) + + // confirm there are no key.values in the proof + require.Empty(proof.KeyValues) + + // add values to be deleted by proof commit + batch := db.NewBatch() + require.NoError(batch.Put([]byte("key1"), []byte("1"))) + require.NoError(batch.Put([]byte("key2"), []byte("2"))) + require.NoError(batch.Put([]byte("key3"), []byte("3"))) + require.NoError(batch.Write()) + + // despite having no key/values in it, committing this proof should delete key1-key3. + require.NoError(db.CommitRangeProof(context.Background(), maybe.Nothing[[]byte](), maybe.Some([]byte("key3")), proof)) + + afterCommitRoot, err := db.GetMerkleRoot(context.Background()) + require.NoError(err) + + require.Equal(startRoot, afterCommitRoot) +} + +func Test_MerkleDB_CommitRangeProof_EmptyTrie(t *testing.T) { require := require.New(t) // Populate [db1] with 3 key-value pairs. @@ -326,7 +366,7 @@ func Test_MerkleDB_Commit_Proof_To_Empty_Trie(t *testing.T) { db2, err := getBasicDB() require.NoError(err) - require.NoError(db2.CommitRangeProof(context.Background(), maybe.Some([]byte("key1")), proof)) + require.NoError(db2.CommitRangeProof(context.Background(), maybe.Some([]byte("key1")), maybe.Some([]byte("key3")), proof)) // [db2] should have the same key-value pairs as [db1]. db2Root, err := db2.GetMerkleRoot(context.Background()) @@ -338,7 +378,7 @@ func Test_MerkleDB_Commit_Proof_To_Empty_Trie(t *testing.T) { require.Equal(db1Root, db2Root) } -func Test_MerkleDB_Commit_Proof_To_Filled_Trie(t *testing.T) { +func Test_MerkleDB_CommitRangeProof_TrieWithInitialValues(t *testing.T) { require := require.New(t) // Populate [db1] with 3 key-value pairs. @@ -374,6 +414,7 @@ func Test_MerkleDB_Commit_Proof_To_Filled_Trie(t *testing.T) { require.NoError(db2.CommitRangeProof( context.Background(), maybe.Some([]byte("key1")), + maybe.Some([]byte("key3")), proof, )) diff --git a/x/merkledb/mock_db.go b/x/merkledb/mock_db.go index b12b17bbfba1..88f88149c842 100644 --- a/x/merkledb/mock_db.go +++ b/x/merkledb/mock_db.go @@ -69,17 +69,17 @@ func (mr *MockMerkleDBMockRecorder) CommitChangeProof(arg0, arg1 interface{}) *g } // CommitRangeProof mocks base method. -func (m *MockMerkleDB) CommitRangeProof(arg0 context.Context, arg1 maybe.Maybe[[]uint8], arg2 *RangeProof) error { +func (m *MockMerkleDB) CommitRangeProof(arg0 context.Context, arg1, arg2 maybe.Maybe[[]uint8], arg3 *RangeProof) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "CommitRangeProof", arg0, arg1, arg2) + ret := m.ctrl.Call(m, "CommitRangeProof", arg0, arg1, arg2, arg3) ret0, _ := ret[0].(error) return ret0 } // CommitRangeProof indicates an expected call of CommitRangeProof. -func (mr *MockMerkleDBMockRecorder) CommitRangeProof(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockMerkleDBMockRecorder) CommitRangeProof(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CommitRangeProof", reflect.TypeOf((*MockMerkleDB)(nil).CommitRangeProof), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CommitRangeProof", reflect.TypeOf((*MockMerkleDB)(nil).CommitRangeProof), arg0, arg1, arg2, arg3) } // Compact mocks base method. diff --git a/x/sync/g_db/db_client.go b/x/sync/g_db/db_client.go index ddde3fa67898..0f61cad3ef21 100644 --- a/x/sync/g_db/db_client.go +++ b/x/sync/g_db/db_client.go @@ -157,6 +157,7 @@ func (c *DBClient) GetRangeProofAtRoot( func (c *DBClient) CommitRangeProof( ctx context.Context, startKey maybe.Maybe[[]byte], + endKey maybe.Maybe[[]byte], proof *merkledb.RangeProof, ) error { _, err := c.client.CommitRangeProof(ctx, &pb.CommitRangeProofRequest{ @@ -164,6 +165,10 @@ func (c *DBClient) CommitRangeProof( IsNothing: startKey.IsNothing(), Value: startKey.Value(), }, + EndKey: &pb.MaybeBytes{ + IsNothing: endKey.IsNothing(), + Value: endKey.Value(), + }, RangeProof: proof.ToProto(), }) return err diff --git a/x/sync/g_db/db_server.go b/x/sync/g_db/db_server.go index 4bfad2a685c9..415820193868 100644 --- a/x/sync/g_db/db_server.go +++ b/x/sync/g_db/db_server.go @@ -206,6 +206,11 @@ func (s *DBServer) CommitRangeProof( start = maybe.Some(req.StartKey.Value) } - err := s.db.CommitRangeProof(ctx, start, &proof) + end := maybe.Nothing[[]byte]() + if req.EndKey != nil && !req.EndKey.IsNothing { + end = maybe.Some(req.EndKey.Value) + } + + err := s.db.CommitRangeProof(ctx, start, end, &proof) return &emptypb.Empty{}, err } diff --git a/x/sync/manager.go b/x/sync/manager.go index 3f197883d0a2..6c7fa833970b 100644 --- a/x/sync/manager.go +++ b/x/sync/manager.go @@ -309,7 +309,7 @@ func (m *Manager) getAndApplyChangeProof(ctx context.Context, work *workItem) { largestHandledKey := work.end if len(rangeProof.KeyValues) > 0 { // Add all the key-value pairs we got to the database. - if err := m.config.DB.CommitRangeProof(ctx, work.start, rangeProof); err != nil { + if err := m.config.DB.CommitRangeProof(ctx, work.start, work.end, rangeProof); err != nil { m.setError(err) return } @@ -351,13 +351,14 @@ func (m *Manager) getAndApplyRangeProof(ctx context.Context, work *workItem) { } largestHandledKey := work.end - if len(proof.KeyValues) > 0 { - // Add all the key-value pairs we got to the database. - if err := m.config.DB.CommitRangeProof(ctx, work.start, proof); err != nil { - m.setError(err) - return - } + // Replace all the key-value pairs in the DB from start to end with values from the response. + if err := m.config.DB.CommitRangeProof(ctx, work.start, work.end, proof); err != nil { + m.setError(err) + return + } + + if len(proof.KeyValues) > 0 { largestHandledKey = maybe.Some(proof.KeyValues[len(proof.KeyValues)-1].Key) } diff --git a/x/sync/sync_test.go b/x/sync/sync_test.go index 8af51fbadf01..3655c820744f 100644 --- a/x/sync/sync_test.go +++ b/x/sync/sync_test.go @@ -648,6 +648,7 @@ func TestFindNextKeyRandom(t *testing.T) { require.NoError(localDB.CommitRangeProof( context.Background(), startKey, + endKey, remoteProof, )) From cf1827194d7d40065903b6a4010bb00898644a3f Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Fri, 15 Sep 2023 13:51:03 -0400 Subject: [PATCH 5/5] Add `bag.Of` helper (#2027) --- snow/consensus/snowball/flat_test.go | 7 +- snow/consensus/snowball/tree_test.go | 69 ++++++------------ snow/consensus/snowman/consensus_test.go | 70 ++++++------------- .../poll/early_term_no_traversal_test.go | 53 +++----------- .../snowman/poll/no_early_term_test.go | 15 +--- snow/consensus/snowman/poll/set_test.go | 50 ++++--------- snow/engine/snowman/transitive.go | 6 +- utils/bag/bag.go | 7 ++ utils/bag/bag_test.go | 49 +++++++++++++ 9 files changed, 129 insertions(+), 197 deletions(-) diff --git a/snow/consensus/snowball/flat_test.go b/snow/consensus/snowball/flat_test.go index c5d292d1ec47..0291c03be1aa 100644 --- a/snow/consensus/snowball/flat_test.go +++ b/snow/consensus/snowball/flat_test.go @@ -8,7 +8,6 @@ import ( "github.com/stretchr/testify/require" - "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/bag" ) @@ -26,14 +25,12 @@ func TestFlat(t *testing.T) { require.Equal(Red, f.Preference()) require.False(f.Finalized()) - twoBlue := bag.Bag[ids.ID]{} - twoBlue.Add(Blue, Blue) + twoBlue := bag.Of(Blue, Blue) require.True(f.RecordPoll(twoBlue)) require.Equal(Blue, f.Preference()) require.False(f.Finalized()) - oneRedOneBlue := bag.Bag[ids.ID]{} - oneRedOneBlue.Add(Red, Blue) + oneRedOneBlue := bag.Of(Red, Blue) require.False(f.RecordPoll(oneRedOneBlue)) require.Equal(Blue, f.Preference()) require.False(f.Finalized()) diff --git a/snow/consensus/snowball/tree_test.go b/snow/consensus/snowball/tree_test.go index b11b3286d90b..26406e428023 100644 --- a/snow/consensus/snowball/tree_test.go +++ b/snow/consensus/snowball/tree_test.go @@ -29,8 +29,7 @@ func TestSnowballSingleton(t *testing.T) { require.False(tree.Finalized()) - oneRed := bag.Bag[ids.ID]{} - oneRed.Add(Red) + oneRed := bag.Of(Red) require.True(tree.RecordPoll(oneRed)) require.False(tree.Finalized()) @@ -51,8 +50,7 @@ func TestSnowballSingleton(t *testing.T) { // Because the tree is already finalized, RecordPoll can return either true // or false. - oneBlue := bag.Bag[ids.ID]{} - oneBlue.Add(Blue) + oneBlue := bag.Of(Blue) tree.RecordPoll(oneBlue) require.Equal(Red, tree.Preference()) require.True(tree.Finalized()) @@ -69,8 +67,7 @@ func TestSnowballRecordUnsuccessfulPoll(t *testing.T) { require.False(tree.Finalized()) - oneRed := bag.Bag[ids.ID]{} - oneRed.Add(Red) + oneRed := bag.Of(Red) require.True(tree.RecordPoll(oneRed)) tree.RecordUnsuccessfulPoll() @@ -99,14 +96,12 @@ func TestSnowballBinary(t *testing.T) { require.Equal(Red, tree.Preference()) require.False(tree.Finalized()) - oneBlue := bag.Bag[ids.ID]{} - oneBlue.Add(Blue) + oneBlue := bag.Of(Blue) require.True(tree.RecordPoll(oneBlue)) require.Equal(Blue, tree.Preference()) require.False(tree.Finalized()) - oneRed := bag.Bag[ids.ID]{} - oneRed.Add(Red) + oneRed := bag.Of(Red) require.True(tree.RecordPoll(oneRed)) require.Equal(Blue, tree.Preference()) require.False(tree.Finalized()) @@ -147,8 +142,7 @@ func TestSnowballLastBinary(t *testing.T) { require.Equal(zero, tree.Preference()) require.False(tree.Finalized()) - oneBag := bag.Bag[ids.ID]{} - oneBag.Add(one) + oneBag := bag.Of(one) require.True(tree.RecordPoll(oneBag)) require.Equal(one, tree.Preference()) require.False(tree.Finalized()) @@ -193,8 +187,7 @@ func TestSnowballAddPreviouslyRejected(t *testing.T) { require.False(tree.Finalized()) } - zeroBag := bag.Bag[ids.ID]{} - zeroBag.Add(zero) + zeroBag := bag.Of(zero) require.True(tree.RecordPoll(zeroBag)) { @@ -244,8 +237,7 @@ func TestSnowballNewUnary(t *testing.T) { require.False(tree.Finalized()) } - oneBag := bag.Bag[ids.ID]{} - oneBag.Add(one) + oneBag := bag.Of(one) require.True(tree.RecordPoll(oneBag)) { @@ -297,8 +289,7 @@ func TestSnowballTransitiveReset(t *testing.T) { require.False(tree.Finalized()) } - zeroBag := bag.Bag[ids.ID]{} - zeroBag.Add(zero) + zeroBag := bag.Of(zero) require.True(tree.RecordPoll(zeroBag)) { @@ -375,22 +366,19 @@ func TestSnowballTrinary(t *testing.T) { require.Equal(Green, tree.Preference()) require.False(tree.Finalized()) - redBag := bag.Bag[ids.ID]{} - redBag.Add(Red) + redBag := bag.Of(Red) require.True(tree.RecordPoll(redBag)) require.Equal(Red, tree.Preference()) require.False(tree.Finalized()) - blueBag := bag.Bag[ids.ID]{} - blueBag.Add(Blue) + blueBag := bag.Of(Blue) require.True(tree.RecordPoll(blueBag)) require.Equal(Red, tree.Preference()) require.False(tree.Finalized()) // Here is a case where voting for a color makes a different color become // the preferred color. This is intended behavior. - greenBag := bag.Bag[ids.ID]{} - greenBag.Add(Green) + greenBag := bag.Of(Green) require.True(tree.RecordPoll(greenBag)) require.Equal(Blue, tree.Preference()) require.False(tree.Finalized()) @@ -429,21 +417,18 @@ func TestSnowballCloseTrinary(t *testing.T) { require.Equal(yellow, tree.Preference()) require.False(tree.Finalized()) - yellowBag := bag.Bag[ids.ID]{} - yellowBag.Add(yellow) + yellowBag := bag.Of(yellow) require.True(tree.RecordPoll(yellowBag)) require.Equal(yellow, tree.Preference()) require.False(tree.Finalized()) - magentaBag := bag.Bag[ids.ID]{} - magentaBag.Add(magenta) + magentaBag := bag.Of(magenta) require.True(tree.RecordPoll(magentaBag)) require.Equal(yellow, tree.Preference()) require.False(tree.Finalized()) // Cyan has already been rejected here, so these are not successful polls. - cyanBag := bag.Bag[ids.ID]{} - cyanBag.Add(cyan) + cyanBag := bag.Of(cyan) require.False(tree.RecordPoll(cyanBag)) require.Equal(yellow, tree.Preference()) require.False(tree.Finalized()) @@ -472,8 +457,7 @@ func TestSnowballAddRejected(t *testing.T) { require.Equal(c0000, tree.Preference()) require.False(tree.Finalized()) - c0010Bag := bag.Bag[ids.ID]{} - c0010Bag.Add(c0010) + c0010Bag := bag.Of(c0010) require.True(tree.RecordPoll(c0010Bag)) { @@ -519,8 +503,7 @@ func TestSnowballResetChild(t *testing.T) { require.Equal(c0000, tree.Preference()) require.False(tree.Finalized()) - c0000Bag := bag.Bag[ids.ID]{} - c0000Bag.Add(c0000) + c0000Bag := bag.Of(c0000) require.True(tree.RecordPoll(c0000Bag)) { @@ -580,8 +563,7 @@ func TestSnowballResetSibling(t *testing.T) { require.Equal(c0000, tree.Preference()) require.False(tree.Finalized()) - c0100Bag := bag.Bag[ids.ID]{} - c0100Bag.Add(c0100) + c0100Bag := bag.Of(c0100) require.True(tree.RecordPoll(c0100Bag)) { @@ -595,8 +577,7 @@ func TestSnowballResetSibling(t *testing.T) { require.False(tree.Finalized()) } - c1000Bag := bag.Bag[ids.ID]{} - c1000Bag.Add(c1000) + c1000Bag := bag.Of(c1000) require.True(tree.RecordPoll(c1000Bag)) { @@ -716,8 +697,7 @@ func TestSnowballFineGrained(t *testing.T) { require.False(tree.Finalized()) } - c0000Bag := bag.Bag[ids.ID]{} - c0000Bag.Add(c0000) + c0000Bag := bag.Of(c0000) require.True(tree.RecordPoll(c0000Bag)) { @@ -733,8 +713,7 @@ func TestSnowballFineGrained(t *testing.T) { require.False(tree.Finalized()) } - c0010Bag := bag.Bag[ids.ID]{} - c0010Bag.Add(c0010) + c0010Bag := bag.Of(c0010) require.True(tree.RecordPoll(c0010Bag)) { @@ -840,8 +819,7 @@ func TestSnowballFilterBinaryChildren(t *testing.T) { require.False(tree.Finalized()) } - c0000Bag := bag.Bag[ids.ID]{} - c0000Bag.Add(c0000) + c0000Bag := bag.Of(c0000) require.True(tree.RecordPoll(c0000Bag)) { @@ -868,8 +846,7 @@ func TestSnowballFilterBinaryChildren(t *testing.T) { require.False(tree.Finalized()) } - c0100Bag := bag.Bag[ids.ID]{} - c0100Bag.Add(c0100) + c0100Bag := bag.Of(c0100) require.True(tree.RecordPoll(c0100Bag)) { diff --git a/snow/consensus/snowman/consensus_test.go b/snow/consensus/snowman/consensus_test.go index 3a3815a54f46..b1bbbd71fe5f 100644 --- a/snow/consensus/snowman/consensus_test.go +++ b/snow/consensus/snowman/consensus_test.go @@ -144,8 +144,7 @@ func NumProcessingTest(t *testing.T, factory Factory) { require.Equal(1, sm.NumProcessing()) - votes := bag.Bag[ids.ID]{} - votes.Add(block.ID()) + votes := bag.Of(block.ID()) require.NoError(sm.RecordPoll(context.Background(), votes)) require.Zero(sm.NumProcessing()) @@ -425,8 +424,7 @@ func RecordPollAcceptSingleBlockTest(t *testing.T, factory Factory) { require.NoError(sm.Add(context.Background(), block)) - votes := bag.Bag[ids.ID]{} - votes.Add(block.ID()) + votes := bag.Of(block.ID()) require.NoError(sm.RecordPoll(context.Background(), votes)) require.Equal(block.ID(), sm.Preference()) require.False(sm.Finalized()) @@ -476,8 +474,7 @@ func RecordPollAcceptAndRejectTest(t *testing.T, factory Factory) { require.NoError(sm.Add(context.Background(), firstBlock)) require.NoError(sm.Add(context.Background(), secondBlock)) - votes := bag.Bag[ids.ID]{} - votes.Add(firstBlock.ID()) + votes := bag.Of(firstBlock.ID()) require.NoError(sm.RecordPoll(context.Background(), votes)) require.Equal(firstBlock.ID(), sm.Preference()) @@ -532,9 +529,7 @@ func RecordPollSplitVoteNoChangeTest(t *testing.T, factory Factory) { require.NoError(sm.Add(context.Background(), firstBlock)) require.NoError(sm.Add(context.Background(), secondBlock)) - votes := bag.Bag[ids.ID]{} - votes.Add(firstBlock.ID()) - votes.Add(secondBlock.ID()) + votes := bag.Of(firstBlock.ID(), secondBlock.ID()) // The first poll will accept shared bits require.NoError(sm.RecordPoll(context.Background(), votes)) @@ -573,8 +568,7 @@ func RecordPollWhenFinalizedTest(t *testing.T, factory Factory) { } require.NoError(sm.Initialize(ctx, params, GenesisID, GenesisHeight, GenesisTimestamp)) - votes := bag.Bag[ids.ID]{} - votes.Add(GenesisID) + votes := bag.Of(GenesisID) require.NoError(sm.RecordPoll(context.Background(), votes)) require.True(sm.Finalized()) require.Equal(GenesisID, sm.Preference()) @@ -635,8 +629,7 @@ func RecordPollRejectTransitivelyTest(t *testing.T, factory Factory) { // 2 // Tail = 0 - votes := bag.Bag[ids.ID]{} - votes.Add(block0.ID()) + votes := bag.Of(block0.ID()) require.NoError(sm.RecordPoll(context.Background(), votes)) // Current graph structure: @@ -713,8 +706,7 @@ func RecordPollTransitivelyResetConfidenceTest(t *testing.T, factory Factory) { // / \ // 2 3 - votesFor2 := bag.Bag[ids.ID]{} - votesFor2.Add(block2.ID()) + votesFor2 := bag.Of(block2.ID()) require.NoError(sm.RecordPoll(context.Background(), votesFor2)) require.False(sm.Finalized()) require.Equal(block2.ID(), sm.Preference()) @@ -728,8 +720,7 @@ func RecordPollTransitivelyResetConfidenceTest(t *testing.T, factory Factory) { require.False(sm.Finalized()) require.Equal(block2.ID(), sm.Preference()) - votesFor3 := bag.Bag[ids.ID]{} - votesFor3.Add(block3.ID()) + votesFor3 := bag.Of(block3.ID()) require.NoError(sm.RecordPoll(context.Background(), votesFor3)) require.False(sm.Finalized()) require.Equal(block2.ID(), sm.Preference()) @@ -773,12 +764,10 @@ func RecordPollInvalidVoteTest(t *testing.T, factory Factory) { require.NoError(sm.Add(context.Background(), block)) - validVotes := bag.Bag[ids.ID]{} - validVotes.Add(block.ID()) + validVotes := bag.Of(block.ID()) require.NoError(sm.RecordPoll(context.Background(), validVotes)) - invalidVotes := bag.Bag[ids.ID]{} - invalidVotes.Add(unknownBlockID) + invalidVotes := bag.Of(unknownBlockID) require.NoError(sm.RecordPoll(context.Background(), invalidVotes)) require.NoError(sm.RecordPoll(context.Background(), validVotes)) require.False(sm.Finalized()) @@ -860,12 +849,7 @@ func RecordPollTransitiveVotingTest(t *testing.T, factory Factory) { // 2 4 // Tail = 2 - votes0_2_4 := bag.Bag[ids.ID]{} - votes0_2_4.Add( - block0.ID(), - block2.ID(), - block4.ID(), - ) + votes0_2_4 := bag.Of(block0.ID(), block2.ID(), block4.ID()) require.NoError(sm.RecordPoll(context.Background(), votes0_2_4)) // Current graph structure: @@ -884,8 +868,7 @@ func RecordPollTransitiveVotingTest(t *testing.T, factory Factory) { require.Equal(choices.Processing, block3.Status()) require.Equal(choices.Processing, block4.Status()) - dep2_2_2 := bag.Bag[ids.ID]{} - dep2_2_2.AddCount(block2.ID(), 3) + dep2_2_2 := bag.Of(block2.ID(), block2.ID(), block2.ID()) require.NoError(sm.RecordPoll(context.Background(), dep2_2_2)) // Current graph structure: @@ -958,8 +941,7 @@ func RecordPollDivergedVotingTest(t *testing.T, factory Factory) { // The first bit is contested as either 0 or 1. When voting for [block0] and // when the first bit is 1, the following bits have been decided to follow // the 255 remaining bits of [block0]. - votes0 := bag.Bag[ids.ID]{} - votes0.Add(block0.ID()) + votes0 := bag.Of(block0.ID()) require.NoError(sm.RecordPoll(context.Background(), votes0)) // Although we are adding in [block2] here - the underlying snowball @@ -994,8 +976,7 @@ func RecordPollDivergedVotingTest(t *testing.T, factory Factory) { // [block0]. When [block0] is accepted, [block1] and [block2] are rejected // as conflicting. [block2]'s child, [block3], is then rejected // transitively. - votes3 := bag.Bag[ids.ID]{} - votes3.Add(block3.ID()) + votes3 := bag.Of(block3.ID()) require.NoError(sm.RecordPoll(context.Background(), votes3)) require.True(sm.Finalized(), "finalized too late") @@ -1062,8 +1043,7 @@ func RecordPollDivergedVotingWithNoConflictingBitTest(t *testing.T, factory Fact // second bit is contested as either 0 or 1. For when the second bit is 1, // the following bits have been decided to follow the 254 remaining bits of // [block0]. - votes0 := bag.Bag[ids.ID]{} - votes0.Add(block0.ID()) + votes0 := bag.Of(block0.ID()) require.NoError(sm.RecordPoll(context.Background(), votes0)) // Although we are adding in [block2] here - the underlying snowball @@ -1098,8 +1078,7 @@ func RecordPollDivergedVotingWithNoConflictingBitTest(t *testing.T, factory Fact // dropped. Although the votes for [block3] are still applied, [block3] will // only be marked as accepted after [block2] is marked as accepted; which // will never happen. - votes3 := bag.Bag[ids.ID]{} - votes3.Add(block3.ID()) + votes3 := bag.Of(block3.ID()) require.NoError(sm.RecordPoll(context.Background(), votes3)) require.False(sm.Finalized(), "finalized too early") @@ -1172,9 +1151,7 @@ func RecordPollChangePreferredChainTest(t *testing.T, factory Factory) { require.False(sm.IsPreferred(b1Block)) require.False(sm.IsPreferred(b2Block)) - b2Votes := bag.Bag[ids.ID]{} - b2Votes.Add(b2Block.ID()) - + b2Votes := bag.Of(b2Block.ID()) require.NoError(sm.RecordPoll(context.Background(), b2Votes)) require.Equal(b2Block.ID(), sm.Preference()) @@ -1183,9 +1160,7 @@ func RecordPollChangePreferredChainTest(t *testing.T, factory Factory) { require.True(sm.IsPreferred(b1Block)) require.True(sm.IsPreferred(b2Block)) - a1Votes := bag.Bag[ids.ID]{} - a1Votes.Add(a1Block.ID()) - + a1Votes := bag.Of(a1Block.ID()) require.NoError(sm.RecordPoll(context.Background(), a1Votes)) require.NoError(sm.RecordPoll(context.Background(), a1Votes)) @@ -1349,8 +1324,7 @@ func ErrorOnAcceptTest(t *testing.T, factory Factory) { require.NoError(sm.Add(context.Background(), block)) - votes := bag.Bag[ids.ID]{} - votes.Add(block.ID()) + votes := bag.Of(block.ID()) err := sm.RecordPoll(context.Background(), votes) require.ErrorIs(err, errTest) } @@ -1395,8 +1369,7 @@ func ErrorOnRejectSiblingTest(t *testing.T, factory Factory) { require.NoError(sm.Add(context.Background(), block0)) require.NoError(sm.Add(context.Background(), block1)) - votes := bag.Bag[ids.ID]{} - votes.Add(block0.ID()) + votes := bag.Of(block0.ID()) err := sm.RecordPoll(context.Background(), votes) require.ErrorIs(err, errTest) } @@ -1450,8 +1423,7 @@ func ErrorOnTransitiveRejectionTest(t *testing.T, factory Factory) { require.NoError(sm.Add(context.Background(), block1)) require.NoError(sm.Add(context.Background(), block2)) - votes := bag.Bag[ids.ID]{} - votes.Add(block0.ID()) + votes := bag.Of(block0.ID()) err := sm.RecordPoll(context.Background(), votes) require.ErrorIs(err, errTest) } diff --git a/snow/consensus/snowman/poll/early_term_no_traversal_test.go b/snow/consensus/snowman/poll/early_term_no_traversal_test.go index 627c97b3398b..5b8cb3d35953 100644 --- a/snow/consensus/snowman/poll/early_term_no_traversal_test.go +++ b/snow/consensus/snowman/poll/early_term_no_traversal_test.go @@ -21,8 +21,7 @@ func TestEarlyTermNoTraversalResults(t *testing.T) { vdr1 := ids.NodeID{1} // k = 1 - vdrs := bag.Bag[ids.NodeID]{} - vdrs.Add(vdr1) + vdrs := bag.Of(vdr1) factory := NewEarlyTermNoTraversalFactory(alpha) poll := factory.New(vdrs) @@ -45,11 +44,7 @@ func TestEarlyTermNoTraversalString(t *testing.T) { vdr1 := ids.NodeID{1} vdr2 := ids.NodeID{2} // k = 2 - vdrs := bag.Bag[ids.NodeID]{} - vdrs.Add( - vdr1, - vdr2, - ) + vdrs := bag.Of(vdr1, vdr2) factory := NewEarlyTermNoTraversalFactory(alpha) poll := factory.New(vdrs) @@ -73,11 +68,7 @@ func TestEarlyTermNoTraversalDropsDuplicatedVotes(t *testing.T) { vdr1 := ids.NodeID{1} vdr2 := ids.NodeID{2} // k = 2 - vdrs := bag.Bag[ids.NodeID]{} - vdrs.Add( - vdr1, - vdr2, - ) + vdrs := bag.Of(vdr1, vdr2) factory := NewEarlyTermNoTraversalFactory(alpha) poll := factory.New(vdrs) @@ -105,14 +96,7 @@ func TestEarlyTermNoTraversalTerminatesEarly(t *testing.T) { vdr4 := ids.NodeID{4} vdr5 := ids.NodeID{5} // k = 5 - vdrs := bag.Bag[ids.NodeID]{} - vdrs.Add( - vdr1, - vdr2, - vdr3, - vdr4, - vdr5, - ) + vdrs := bag.Of(vdr1, vdr2, vdr3, vdr4, vdr5) factory := NewEarlyTermNoTraversalFactory(alpha) poll := factory.New(vdrs) @@ -147,13 +131,7 @@ func TestEarlyTermNoTraversalForSharedAncestor(t *testing.T) { vdr3 := ids.NodeID{3} vdr4 := ids.NodeID{4} - vdrs := bag.Bag[ids.NodeID]{} - vdrs.Add( - vdr1, - vdr2, - vdr3, - vdr4, - ) + vdrs := bag.Of(vdr1, vdr2, vdr3, vdr4) factory := NewEarlyTermNoTraversalFactory(alpha) poll := factory.New(vdrs) @@ -180,12 +158,7 @@ func TestEarlyTermNoTraversalWithFastDrops(t *testing.T) { vdr2 := ids.NodeID{2} vdr3 := ids.NodeID{3} // k = 3 - vdrs := bag.Bag[ids.NodeID]{} - vdrs.Add( - vdr1, - vdr2, - vdr3, - ) + vdrs := bag.Of(vdr1, vdr2, vdr3) factory := NewEarlyTermNoTraversalFactory(alpha) poll := factory.New(vdrs) @@ -207,12 +180,7 @@ func TestEarlyTermNoTraversalWithWeightedResponses(t *testing.T) { vdr1 := ids.NodeID{2} vdr2 := ids.NodeID{3} - vdrs := bag.Bag[ids.NodeID]{} - vdrs.Add( - vdr1, - vdr2, - vdr2, - ) // k = 3 + vdrs := bag.Of(vdr1, vdr2, vdr2) // k = 3 factory := NewEarlyTermNoTraversalFactory(alpha) poll := factory.New(vdrs) @@ -233,12 +201,7 @@ func TestEarlyTermNoTraversalDropWithWeightedResponses(t *testing.T) { vdr1 := ids.NodeID{1} vdr2 := ids.NodeID{2} - vdrs := bag.Bag[ids.NodeID]{} - vdrs.Add( - vdr1, - vdr2, - vdr2, - ) // k = 3 + vdrs := bag.Of(vdr1, vdr2, vdr2) // k = 3 factory := NewEarlyTermNoTraversalFactory(alpha) poll := factory.New(vdrs) diff --git a/snow/consensus/snowman/poll/no_early_term_test.go b/snow/consensus/snowman/poll/no_early_term_test.go index 415c46b2e25d..cd130ca7e273 100644 --- a/snow/consensus/snowman/poll/no_early_term_test.go +++ b/snow/consensus/snowman/poll/no_early_term_test.go @@ -19,8 +19,7 @@ func TestNoEarlyTermResults(t *testing.T) { vdr1 := ids.NodeID{1} // k = 1 - vdrs := bag.Bag[ids.NodeID]{} - vdrs.Add(vdr1) + vdrs := bag.Of(vdr1) factory := NewNoEarlyTermFactory() poll := factory.New(vdrs) @@ -41,11 +40,7 @@ func TestNoEarlyTermString(t *testing.T) { vdr1 := ids.NodeID{1} vdr2 := ids.NodeID{2} // k = 2 - vdrs := bag.Bag[ids.NodeID]{} - vdrs.Add( - vdr1, - vdr2, - ) + vdrs := bag.Of(vdr1, vdr2) factory := NewNoEarlyTermFactory() poll := factory.New(vdrs) @@ -67,11 +62,7 @@ func TestNoEarlyTermDropsDuplicatedVotes(t *testing.T) { vdr1 := ids.NodeID{1} vdr2 := ids.NodeID{2} // k = 2 - vdrs := bag.Bag[ids.NodeID]{} - vdrs.Add( - vdr1, - vdr2, - ) + vdrs := bag.Of(vdr1, vdr2) factory := NewNoEarlyTermFactory() poll := factory.New(vdrs) diff --git a/snow/consensus/snowman/poll/set_test.go b/snow/consensus/snowman/poll/set_test.go index 316f0dcb8512..775d6ecd1091 100644 --- a/snow/consensus/snowman/poll/set_test.go +++ b/snow/consensus/snowman/poll/set_test.go @@ -50,12 +50,10 @@ func TestCreateAndFinishPollOutOfOrder_NewerFinishesFirst(t *testing.T) { vdrs := []ids.NodeID{vdr1, vdr2, vdr3} // create two polls for the two vtxs - vdrBag := bag.Bag[ids.NodeID]{} - vdrBag.Add(vdrs...) + vdrBag := bag.Of(vdrs...) require.True(s.Add(1, vdrBag)) - vdrBag = bag.Bag[ids.NodeID]{} - vdrBag.Add(vdrs...) + vdrBag = bag.Of(vdrs...) require.True(s.Add(2, vdrBag)) require.Equal(s.Len(), 2) @@ -64,8 +62,6 @@ func TestCreateAndFinishPollOutOfOrder_NewerFinishesFirst(t *testing.T) { vtx1 := ids.ID{1} vtx2 := ids.ID{2} - var results []bag.Bag[ids.ID] - // vote out of order require.Empty(s.Vote(1, vdr1, vtx1)) require.Empty(s.Vote(2, vdr2, vtx2)) @@ -76,7 +72,7 @@ func TestCreateAndFinishPollOutOfOrder_NewerFinishesFirst(t *testing.T) { require.Empty(s.Vote(1, vdr2, vtx1)) - results = s.Vote(1, vdr3, vtx1) // poll 1 finished, poll 2 should be finished as well + results := s.Vote(1, vdr3, vtx1) // poll 1 finished, poll 2 should be finished as well require.Len(results, 2) require.Equal(vtx1, results[0].List()[0]) require.Equal(vtx2, results[1].List()[0]) @@ -99,12 +95,10 @@ func TestCreateAndFinishPollOutOfOrder_OlderFinishesFirst(t *testing.T) { vdrs := []ids.NodeID{vdr1, vdr2, vdr3} // create two polls for the two vtxs - vdrBag := bag.Bag[ids.NodeID]{} - vdrBag.Add(vdrs...) + vdrBag := bag.Of(vdrs...) require.True(s.Add(1, vdrBag)) - vdrBag = bag.Bag[ids.NodeID]{} - vdrBag.Add(vdrs...) + vdrBag = bag.Of(vdrs...) require.True(s.Add(2, vdrBag)) require.Equal(s.Len(), 2) @@ -113,8 +107,6 @@ func TestCreateAndFinishPollOutOfOrder_OlderFinishesFirst(t *testing.T) { vtx1 := ids.ID{1} vtx2 := ids.ID{2} - var results []bag.Bag[ids.ID] - // vote out of order require.Empty(s.Vote(1, vdr1, vtx1)) require.Empty(s.Vote(2, vdr2, vtx2)) @@ -122,8 +114,8 @@ func TestCreateAndFinishPollOutOfOrder_OlderFinishesFirst(t *testing.T) { require.Empty(s.Vote(1, vdr2, vtx1)) - results = s.Vote(1, vdr3, vtx1) // poll 1 finished, poll 2 still remaining - require.Len(results, 1) // because 1 is the oldest + results := s.Vote(1, vdr3, vtx1) // poll 1 finished, poll 2 still remaining + require.Len(results, 1) // because 1 is the oldest require.Equal(vtx1, results[0].List()[0]) results = s.Vote(2, vdr1, vtx2) // poll 2 finished @@ -148,16 +140,13 @@ func TestCreateAndFinishPollOutOfOrder_UnfinishedPollsGaps(t *testing.T) { vdrs := []ids.NodeID{vdr1, vdr2, vdr3} // create three polls for the two vtxs - vdrBag := bag.Bag[ids.NodeID]{} - vdrBag.Add(vdrs...) + vdrBag := bag.Of(vdrs...) require.True(s.Add(1, vdrBag)) - vdrBag = bag.Bag[ids.NodeID]{} - vdrBag.Add(vdrs...) + vdrBag = bag.Of(vdrs...) require.True(s.Add(2, vdrBag)) - vdrBag = bag.Bag[ids.NodeID]{} - vdrBag.Add(vdrs...) + vdrBag = bag.Of(vdrs...) require.True(s.Add(3, vdrBag)) require.Equal(s.Len(), 3) @@ -168,8 +157,6 @@ func TestCreateAndFinishPollOutOfOrder_UnfinishedPollsGaps(t *testing.T) { vtx2 := ids.ID{2} vtx3 := ids.ID{3} - var results []bag.Bag[ids.ID] - // vote out of order // 2 finishes first to create a gap of finished poll between two unfinished polls 1 and 3 require.Empty(s.Vote(2, vdr3, vtx2)) @@ -184,7 +171,7 @@ func TestCreateAndFinishPollOutOfOrder_UnfinishedPollsGaps(t *testing.T) { // 1 finishes now, 2 and 3 have already finished so we expect 3 items in results require.Empty(s.Vote(1, vdr1, vtx1)) require.Empty(s.Vote(1, vdr2, vtx1)) - results = s.Vote(1, vdr3, vtx1) + results := s.Vote(1, vdr3, vtx1) require.Len(results, 3) require.Equal(vtx1, results[0].List()[0]) require.Equal(vtx2, results[1].List()[0]) @@ -205,11 +192,7 @@ func TestCreateAndFinishSuccessfulPoll(t *testing.T) { vdr1 := ids.NodeID{1} vdr2 := ids.NodeID{2} // k = 2 - vdrs := bag.Bag[ids.NodeID]{} - vdrs.Add( - vdr1, - vdr2, - ) + vdrs := bag.Of(vdr1, vdr2) require.Zero(s.Len()) @@ -243,11 +226,7 @@ func TestCreateAndFinishFailedPoll(t *testing.T) { vdr1 := ids.NodeID{1} vdr2 := ids.NodeID{2} // k = 2 - vdrs := bag.Bag[ids.NodeID]{} - vdrs.Add( - vdr1, - vdr2, - ) + vdrs := bag.Of(vdr1, vdr2) require.Zero(s.Len()) @@ -277,8 +256,7 @@ func TestSetString(t *testing.T) { vdr1 := ids.NodeID{1} // k = 1 - vdrs := bag.Bag[ids.NodeID]{} - vdrs.Add(vdr1) + vdrs := bag.Of(vdr1) expected := `current polls: (Size = 1) RequestID 0: diff --git a/snow/engine/snowman/transitive.go b/snow/engine/snowman/transitive.go index 4bde5518273f..1450fed0163e 100644 --- a/snow/engine/snowman/transitive.go +++ b/snow/engine/snowman/transitive.go @@ -700,8 +700,7 @@ func (t *Transitive) pullQuery(ctx context.Context, blkID ids.ID) { return } - vdrBag := bag.Bag[ids.NodeID]{} - vdrBag.Add(vdrIDs...) + vdrBag := bag.Of(vdrIDs...) t.RequestID++ if t.polls.Add(t.RequestID, vdrBag) { @@ -730,8 +729,7 @@ func (t *Transitive) sendQuery(ctx context.Context, blk snowman.Block, push bool return } - vdrBag := bag.Bag[ids.NodeID]{} - vdrBag.Add(vdrIDs...) + vdrBag := bag.Of(vdrIDs...) t.RequestID++ if t.polls.Add(t.RequestID, vdrBag) { diff --git a/utils/bag/bag.go b/utils/bag/bag.go index 4d9d418add30..496969a01b17 100644 --- a/utils/bag/bag.go +++ b/utils/bag/bag.go @@ -24,6 +24,13 @@ type Bag[T comparable] struct { metThreshold set.Set[T] } +// Of returns a Bag initialized with [elts] +func Of[T comparable](elts ...T) Bag[T] { + var b Bag[T] + b.Add(elts...) + return b +} + func (b *Bag[T]) init() { if b.counts == nil { b.counts = make(map[T]int, minBagSize) diff --git a/utils/bag/bag_test.go b/utils/bag/bag_test.go index ab37c5fd43bf..1a42486560a6 100644 --- a/utils/bag/bag_test.go +++ b/utils/bag/bag_test.go @@ -9,6 +9,55 @@ import ( "github.com/stretchr/testify/require" ) +func TestBagOf(t *testing.T) { + tests := []struct { + name string + elements []int + expectedCounts map[int]int + }{ + { + name: "nil", + elements: nil, + expectedCounts: map[int]int{}, + }, + { + name: "empty", + elements: []int{}, + expectedCounts: map[int]int{}, + }, + { + name: "unique elements", + elements: []int{1, 2, 3}, + expectedCounts: map[int]int{ + 1: 1, + 2: 1, + 3: 1, + }, + }, + { + name: "duplicate elements", + elements: []int{1, 2, 3, 1, 2, 3}, + expectedCounts: map[int]int{ + 1: 2, + 2: 2, + 3: 2, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + require := require.New(t) + + b := Of(tt.elements...) + + require.Equal(len(tt.elements), b.Len()) + for entry, count := range tt.expectedCounts { + require.Equal(count, b.Count(entry)) + } + }) + } +} + func TestBagAdd(t *testing.T) { require := require.New(t)