Skip to content

Commit 6037687

Browse files
authored
Merge pull request #356 from anyproto/GO-4663-upgrade-any-sync-version
GO-4663: Upgrade protocol
2 parents 93eaa99 + fdc6e4b commit 6037687

File tree

4 files changed

+8
-116
lines changed

4 files changed

+8
-116
lines changed

commonspace/deletion_test.go

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"github.com/anyproto/any-sync/commonspace/settings"
1717
"github.com/anyproto/any-sync/commonspace/settings/settingsstate"
1818
"github.com/anyproto/any-sync/commonspace/spacestorage"
19-
"github.com/anyproto/any-sync/commonspace/spacesyncproto"
2019
"github.com/anyproto/any-sync/commonspace/syncstatus"
2120
"github.com/anyproto/any-sync/util/crypto"
2221
)
@@ -127,95 +126,6 @@ func createTree(t *testing.T, ctx context.Context, spc Space, acc *accountdata.A
127126
return tr.Id()
128127
}
129128

130-
func TestSpaceDeleteIdsIncorrectSnapshot(t *testing.T) {
131-
fx := newFixture(t)
132-
acc := fx.account.Account()
133-
rk := crypto.NewAES()
134-
privKey, _, _ := crypto.GenerateRandomEd25519KeyPair()
135-
ctx := context.Background()
136-
totalObjs := 1500
137-
partialObjs := 300
138-
139-
// creating space
140-
sp, err := fx.spaceService.CreateSpace(ctx, SpaceCreatePayload{
141-
SigningKey: acc.SignKey,
142-
SpaceType: "type",
143-
ReadKey: rk,
144-
MetadataKey: privKey,
145-
ReplicationKey: 10,
146-
MasterKey: acc.PeerKey,
147-
})
148-
require.NoError(t, err)
149-
require.NotNil(t, sp)
150-
151-
// initializing space
152-
spc, err := fx.spaceService.NewSpace(ctx, sp, Deps{TreeSyncer: mockTreeSyncer{}, SyncStatus: syncstatus.NewNoOpSyncStatus()})
153-
require.NoError(t, err)
154-
require.NotNil(t, spc)
155-
// adding space to tree manager
156-
fx.treeManager.space = spc
157-
err = spc.Init(ctx)
158-
close(fx.treeManager.waitLoad)
159-
require.NoError(t, err)
160-
161-
settingsObject := spc.(*space).app.MustComponent(settings.CName).(settings.Settings).SettingsObject()
162-
var ids []string
163-
for i := 0; i < totalObjs; i++ {
164-
id := createTree(t, ctx, spc, acc)
165-
ids = append(ids, id)
166-
}
167-
// copying storage, so we will have all the trees locally
168-
inmemory := spc.Storage().(*spacestorage.InMemorySpaceStorage)
169-
storageCopy := inmemory.CopyStorage()
170-
treesCopy := inmemory.AllTrees()
171-
172-
// deleting trees
173-
for _, id := range ids {
174-
err = spc.DeleteTree(ctx, id)
175-
require.NoError(t, err)
176-
}
177-
mapIds := map[string]struct{}{}
178-
for _, id := range ids[:partialObjs] {
179-
mapIds[id] = struct{}{}
180-
}
181-
// adding snapshot that breaks the state
182-
err = addIncorrectSnapshot(settingsObject, acc, mapIds, ids[partialObjs])
183-
require.NoError(t, err)
184-
// copying the contents of the settings tree
185-
treesCopy[settingsObject.Id()] = settingsObject.Storage()
186-
storageCopy.SetTrees(treesCopy)
187-
spc.Close()
188-
time.Sleep(100 * time.Millisecond)
189-
// now we replace the storage, so the trees are back, but the settings object says that they are deleted
190-
fx.storageProvider.(*spacestorage.InMemorySpaceStorageProvider).SetStorage(storageCopy)
191-
192-
spc, err = fx.spaceService.NewSpace(ctx, sp, Deps{TreeSyncer: mockTreeSyncer{}, SyncStatus: syncstatus.NewNoOpSyncStatus()})
193-
require.NoError(t, err)
194-
require.NotNil(t, spc)
195-
fx.treeManager.waitLoad = make(chan struct{})
196-
fx.treeManager.space = spc
197-
fx.treeManager.deletedIds = nil
198-
fx.treeManager.wait = true
199-
err = spc.Init(ctx)
200-
require.NoError(t, err)
201-
close(fx.treeManager.waitLoad)
202-
203-
// waiting until everything is deleted
204-
time.Sleep(6 * time.Second)
205-
require.Equal(t, len(ids), len(fx.treeManager.deletedIds))
206-
207-
// checking that new snapshot will contain all the changes
208-
settingsObject = spc.(*space).app.MustComponent(settings.CName).(settings.Settings).SettingsObject()
209-
settings.DoSnapshot = func(treeLen int) bool {
210-
return true
211-
}
212-
id := createTree(t, ctx, spc, acc)
213-
err = spc.DeleteTree(ctx, id)
214-
require.NoError(t, err)
215-
delIds := settingsObject.Root().Model.(*spacesyncproto.SettingsData).Snapshot.DeletedIds
216-
require.Equal(t, totalObjs+1, len(delIds))
217-
}
218-
219129
func TestSpaceDeleteIdsMarkDeleted(t *testing.T) {
220130
fx := newFixture(t)
221131
acc := fx.account.Account()

commonspace/object/acl/syncacl/syncacl.go

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,17 @@ import (
77

88
"go.uber.org/zap"
99

10-
"github.com/anyproto/any-sync/commonspace/object/acl/syncacl/headupdater"
11-
"github.com/anyproto/any-sync/commonspace/sync"
12-
"github.com/anyproto/any-sync/commonspace/sync/objectsync/objectmessages"
13-
"github.com/anyproto/any-sync/commonspace/sync/syncdeps"
14-
"github.com/anyproto/any-sync/net/peer"
15-
"github.com/anyproto/any-sync/net/secureservice"
16-
1710
"github.com/anyproto/any-sync/accountservice"
1811
"github.com/anyproto/any-sync/app"
1912
"github.com/anyproto/any-sync/app/logger"
2013
"github.com/anyproto/any-sync/commonspace/object/acl/list"
14+
"github.com/anyproto/any-sync/commonspace/object/acl/syncacl/headupdater"
2115
"github.com/anyproto/any-sync/commonspace/spacestorage"
16+
"github.com/anyproto/any-sync/commonspace/sync"
17+
"github.com/anyproto/any-sync/commonspace/sync/objectsync/objectmessages"
18+
"github.com/anyproto/any-sync/commonspace/sync/syncdeps"
2219
"github.com/anyproto/any-sync/consensus/consensusproto"
20+
"github.com/anyproto/any-sync/net/peer"
2321
)
2422

2523
const CName = "common.acl.syncacl"
@@ -142,13 +140,6 @@ func (s *syncAcl) AddRawRecords(rawRecords []*consensusproto.RawRecordWithId) (e
142140
func (s *syncAcl) SyncWithPeer(ctx context.Context, p peer.Peer) (err error) {
143141
s.Lock()
144142
defer s.Unlock()
145-
protoVersion, err := peer.CtxProtoVersion(p.Context())
146-
if err != nil {
147-
return
148-
}
149-
if protoVersion <= secureservice.CompatibleVersion {
150-
return nil
151-
}
152143
req := s.syncClient.CreateFullSyncRequest(p.Id(), s)
153144
return s.syncClient.QueueRequest(ctx, req)
154145
}

commonspace/object/tree/synctree/synctree.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"github.com/anyproto/any-sync/commonspace/sync/syncdeps"
2020
"github.com/anyproto/any-sync/commonspace/syncstatus"
2121
"github.com/anyproto/any-sync/net/peer"
22-
"github.com/anyproto/any-sync/net/secureservice"
2322
"github.com/anyproto/any-sync/nodeconf"
2423
"github.com/anyproto/any-sync/util/slice"
2524
)
@@ -330,13 +329,6 @@ func (s *syncTree) SyncWithPeer(ctx context.Context, p peer.Peer) (err error) {
330329
if objecttree.IsEmptyDerivedTree(s.ObjectTree) {
331330
return
332331
}
333-
protoVersion, err := peer.CtxProtoVersion(p.Context())
334-
if err != nil {
335-
return
336-
}
337-
if protoVersion <= secureservice.CompatibleVersion {
338-
return nil
339-
}
340332
req := s.syncClient.CreateFullSyncRequest(p.Id(), s)
341333
return s.syncClient.QueueRequest(ctx, req)
342334
}

net/secureservice/secureservice.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,12 @@ var (
3030
// ProtoVersion 3 - acl with breaking changes / multiplayer
3131
// ProtoVersion 4 - new sync compatible version
3232
// ProtoVersion 5 - sync with no entry space
33-
CompatibleVersion = uint32(3)
34-
ProtoVersion = uint32(4)
35-
NoEntrySpaceVersion = uint32(5)
33+
CompatibleVersion = uint32(4)
34+
ProtoVersion = uint32(5)
3635
)
3736

3837
var (
39-
compatibleVersions = []uint32{CompatibleVersion, ProtoVersion, NoEntrySpaceVersion}
38+
compatibleVersions = []uint32{CompatibleVersion, ProtoVersion}
4039
)
4140

4241
func New() SecureService {

0 commit comments

Comments
 (0)