A very experimental PLC implementation which uses BFT consensus for decentralization
24
fork

Configure Feed

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

Remove useless mutex

gbl08ma.com a9223d48 69c6f7c4

verified
-29
-29
plc/impl.go
··· 2 2 3 3 import ( 4 4 "context" 5 - "sync" 6 5 7 6 "github.com/bluesky-social/indigo/atproto/syntax" 8 7 "github.com/did-method-plc/go-didplc" ··· 15 14 ) 16 15 17 16 type plcImpl struct { 18 - mu sync.Mutex // probably redundant, but let's keep for now 19 17 validator OperationValidator 20 18 } 21 19 ··· 29 27 } 30 28 31 29 func (plc *plcImpl) ValidateOperation(ctx context.Context, readTx transaction.Read, did string, opBytes []byte) error { 32 - plc.mu.Lock() 33 - defer plc.mu.Unlock() 34 - 35 30 timestamp := syntax.Datetime(readTx.Timestamp().Format(types.ActualAtprotoDatetimeLayout)) 36 31 37 32 // TODO set true to false only while importing old ops ··· 44 39 } 45 40 46 41 func (plc *plcImpl) ExecuteOperation(ctx context.Context, tx transaction.Write, did string, opBytes []byte) error { 47 - plc.mu.Lock() 48 - defer plc.mu.Unlock() 49 - 50 42 timestamp := syntax.Datetime(tx.Timestamp().Format(types.ActualAtprotoDatetimeLayout)) 51 43 52 44 // TODO set true to false only while importing old ops ··· 63 55 return nil 64 56 } 65 57 func (plc *plcImpl) ImportOperationFromAuthoritativeSource(ctx context.Context, tx transaction.Write, newEntry didplc.LogEntry) error { 66 - plc.mu.Lock() 67 - defer plc.mu.Unlock() 68 - 69 58 newCID := newEntry.CID 70 59 newPrev := newEntry.Operation.AsOperation().PrevCIDStr() 71 60 ··· 139 128 } 140 129 141 130 func (plc *plcImpl) Resolve(ctx context.Context, tx transaction.Read, did string) (didplc.Doc, error) { 142 - plc.mu.Lock() 143 - defer plc.mu.Unlock() 144 - 145 131 l, _, err := store.Tree.AuditLog(ctx, tx, did, false) 146 132 if err != nil { 147 133 return didplc.Doc{}, stacktrace.Propagate(err, "") ··· 163 149 // if missing -> returns ErrDIDNotFound 164 150 // if tombstone -> returns log as normal 165 151 166 - plc.mu.Lock() 167 - defer plc.mu.Unlock() 168 - 169 152 l, _, err := store.Tree.AuditLog(ctx, tx, did, false) 170 153 if err != nil { 171 154 return nil, stacktrace.Propagate(err, "") ··· 188 171 // GetPlcAuditLog - /:did/log/audit - full audit log, with nullified 189 172 // if missing -> returns ErrDIDNotFound 190 173 // if tombstone -> returns log as normal 191 - plc.mu.Lock() 192 - defer plc.mu.Unlock() 193 - 194 174 l, _, err := store.Tree.AuditLog(ctx, tx, did, false) 195 175 if err != nil { 196 176 return nil, stacktrace.Propagate(err, "") ··· 209 189 // GetLastOp - /:did/log/last - latest op from audit log which isn't nullified (the latest op is guaranteed not to be nullified) 210 190 // if missing -> returns ErrDIDNotFound 211 191 // if tombstone -> returns tombstone op 212 - plc.mu.Lock() 213 - defer plc.mu.Unlock() 214 - 215 192 l, _, err := store.Tree.AuditLog(ctx, tx, did, false) 216 193 if err != nil { 217 194 return didplc.OpEnum{}, stacktrace.Propagate(err, "") ··· 228 205 // GetPlcData - /:did/data - similar to GetLastOp but applies a transformation on the op which normalizes it into a modern op 229 206 // if missing -> returns ErrDIDNotFound 230 207 // if tombstone -> returns ErrDIDGone 231 - plc.mu.Lock() 232 - defer plc.mu.Unlock() 233 - 234 208 l, _, err := store.Tree.AuditLog(ctx, tx, did, false) 235 209 if err != nil { 236 210 return didplc.RegularOp{}, stacktrace.Propagate(err, "") ··· 252 226 } 253 227 254 228 func (plc *plcImpl) Export(ctx context.Context, tx transaction.Read, after uint64, count int) ([]types.SequencedLogEntry, error) { 255 - plc.mu.Lock() 256 - defer plc.mu.Unlock() 257 - 258 229 entries, err := store.Tree.ExportOperations(ctx, tx, after, count) 259 230 return entries, stacktrace.Propagate(err, "") 260 231 }