this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

switch to atproto/syntax TID generator (#1028)

repo and repomgr packages rely on incorrect TID generation functions
which do not enforce lengths properly unlike the ones in the syntax
package, producing strings of 12 characters instead of 13, due to not
padding the clock id, breaking lexicon validation when used in the
context of atproto. This removes the `tid.go` file to use the other
implementation instead.

authored by

bnewbold and committed by
GitHub
60a73800 8500c47d

+16 -48
+9 -2
repo/repo.go
··· 7 7 "io" 8 8 9 9 "github.com/bluesky-social/indigo/atproto/repo" 10 + "github.com/bluesky-social/indigo/atproto/syntax" 10 11 lexutil "github.com/bluesky-social/indigo/lex/util" 11 12 "github.com/bluesky-social/indigo/mst" 12 13 "github.com/bluesky-social/indigo/util" ··· 49 50 mst *mst.MerkleSearchTree 50 51 51 52 dirty bool 53 + 54 + clk *syntax.TIDClock 52 55 } 53 56 54 57 // Returns a copy of commit without the Sig field. Helpful when verifying signature. ··· 111 114 112 115 func NewRepo(ctx context.Context, did string, bs cbor.IpldBlockstore) *Repo { 113 116 cst := util.CborStore(bs) 117 + clk := syntax.NewTIDClock(0) 114 118 115 119 t := mst.NewEmptyMST(cst) 116 120 sc := SignedCommit{ ··· 124 128 mst: t, 125 129 sc: sc, 126 130 dirty: true, 131 + clk: &clk, 127 132 } 128 133 } 129 134 130 135 func OpenRepo(ctx context.Context, bs cbor.IpldBlockstore, root cid.Cid) (*Repo, error) { 131 136 cst := util.CborStore(bs) 137 + clk := syntax.NewTIDClock(0) 132 138 133 139 var sc SignedCommit 134 140 if err := cst.Get(ctx, root, &sc); err != nil { ··· 144 150 bs: bs, 145 151 cst: cst, 146 152 repoCid: root, 153 + clk: &clk, 147 154 }, nil 148 155 } 149 156 ··· 191 198 return cid.Undef, "", err 192 199 } 193 200 194 - tid := NextTID() 201 + tid := r.clk.Next().String() 195 202 196 203 nmst, err := t.Add(ctx, nsid+"/"+tid, k, -1) 197 204 if err != nil { ··· 294 301 Did: r.RepoDid(), 295 302 Version: ATP_REPO_VERSION, 296 303 Data: rcid, 297 - Rev: NextTID(), 304 + Rev: r.clk.Next().String(), 298 305 } 299 306 300 307 sb, err := ncom.BytesForSigning()
-41
repo/tid.go
··· 1 - package repo 2 - 3 - import ( 4 - "math/rand" 5 - "sync" 6 - "time" 7 - ) 8 - 9 - const alpha = "234567abcdefghijklmnopqrstuvwxyz" 10 - 11 - func s32encode(i uint64) string { 12 - var s string 13 - for i > 0 { 14 - c := i & 0x1f 15 - i = i >> 5 16 - s = alpha[c:c+1] + s 17 - } 18 - return s 19 - } 20 - 21 - func init() { 22 - clockId = uint64(rand.Int() & 0x1f) 23 - } 24 - 25 - var lastTime uint64 26 - var clockId uint64 27 - var ltLock sync.Mutex 28 - 29 - func NextTID() string { 30 - t := uint64(time.Now().UnixMicro()) 31 - 32 - ltLock.Lock() 33 - if lastTime >= t { 34 - t = lastTime + 1 35 - } 36 - 37 - lastTime = t 38 - ltLock.Unlock() 39 - 40 - return s32encode(uint64(t)) + s32encode(clockId) 41 - }
+7 -5
repomgr/repomgr.go
··· 13 13 14 14 atproto "github.com/bluesky-social/indigo/api/atproto" 15 15 bsky "github.com/bluesky-social/indigo/api/bsky" 16 + "github.com/bluesky-social/indigo/atproto/syntax" 16 17 "github.com/bluesky-social/indigo/carstore" 17 18 lexutil "github.com/bluesky-social/indigo/lex/util" 18 19 "github.com/bluesky-social/indigo/models" ··· 38 39 if _, ok := cs.(*carstore.NonArchivalCarstore); ok { 39 40 noArchive = true 40 41 } 42 + 43 + clk := syntax.NewTIDClock(0) 41 44 42 45 return &RepoManager{ 43 46 cs: cs, ··· 45 48 kmgr: kmgr, 46 49 log: slog.Default().With("system", "repomgr"), 47 50 noArchive: noArchive, 51 + clk: &clk, 48 52 } 49 53 } 50 54 ··· 70 74 71 75 log *slog.Logger 72 76 noArchive bool 77 + 78 + clk *syntax.TIDClock 73 79 } 74 80 75 81 type ActorInfo struct { ··· 771 777 return nil 772 778 } 773 779 774 - func rkeyForCollection(collection string) string { 775 - return repo.NextTID() 776 - } 777 - 778 780 func (rm *RepoManager) BatchWrite(ctx context.Context, user models.Uid, writes []*atproto.RepoApplyWrites_Input_Writes_Elem) error { 779 781 ctx, span := otel.Tracer("repoman").Start(ctx, "BatchWrite") 780 782 defer span.End() ··· 807 809 if c.Rkey != nil { 808 810 rkey = *c.Rkey 809 811 } else { 810 - rkey = rkeyForCollection(c.Collection) 812 + rkey = rm.clk.Next().String() 811 813 } 812 814 813 815 nsid := c.Collection + "/" + rkey