tangled
alpha
login
or
join now
gbl08ma.com
/
didplcbft
24
fork
atom
A very experimental PLC implementation which uses BFT consensus for decentralization
24
fork
atom
overview
issues
pulls
pipelines
Remove useless mutex
gbl08ma.com
1 month ago
a9223d48
69c6f7c4
verified
This commit was signed with the committer's
known signature
.
gbl08ma.com
SSH Key Fingerprint:
SHA256:SPYB6pdFx2f9Xq5OXiol0IqoLhhxmlCgkqfaB82rWBw=
-29
1 changed file
expand all
collapse all
unified
split
plc
impl.go
-29
plc/impl.go
···
2
3
import (
4
"context"
5
-
"sync"
6
7
"github.com/bluesky-social/indigo/atproto/syntax"
8
"github.com/did-method-plc/go-didplc"
···
15
)
16
17
type plcImpl struct {
18
-
mu sync.Mutex // probably redundant, but let's keep for now
19
validator OperationValidator
20
}
21
···
29
}
30
31
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
timestamp := syntax.Datetime(readTx.Timestamp().Format(types.ActualAtprotoDatetimeLayout))
36
37
// TODO set true to false only while importing old ops
···
44
}
45
46
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
timestamp := syntax.Datetime(tx.Timestamp().Format(types.ActualAtprotoDatetimeLayout))
51
52
// TODO set true to false only while importing old ops
···
63
return nil
64
}
65
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
newCID := newEntry.CID
70
newPrev := newEntry.Operation.AsOperation().PrevCIDStr()
71
···
139
}
140
141
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
l, _, err := store.Tree.AuditLog(ctx, tx, did, false)
146
if err != nil {
147
return didplc.Doc{}, stacktrace.Propagate(err, "")
···
163
// if missing -> returns ErrDIDNotFound
164
// if tombstone -> returns log as normal
165
166
-
plc.mu.Lock()
167
-
defer plc.mu.Unlock()
168
-
169
l, _, err := store.Tree.AuditLog(ctx, tx, did, false)
170
if err != nil {
171
return nil, stacktrace.Propagate(err, "")
···
188
// GetPlcAuditLog - /:did/log/audit - full audit log, with nullified
189
// if missing -> returns ErrDIDNotFound
190
// if tombstone -> returns log as normal
191
-
plc.mu.Lock()
192
-
defer plc.mu.Unlock()
193
-
194
l, _, err := store.Tree.AuditLog(ctx, tx, did, false)
195
if err != nil {
196
return nil, stacktrace.Propagate(err, "")
···
209
// GetLastOp - /:did/log/last - latest op from audit log which isn't nullified (the latest op is guaranteed not to be nullified)
210
// if missing -> returns ErrDIDNotFound
211
// if tombstone -> returns tombstone op
212
-
plc.mu.Lock()
213
-
defer plc.mu.Unlock()
214
-
215
l, _, err := store.Tree.AuditLog(ctx, tx, did, false)
216
if err != nil {
217
return didplc.OpEnum{}, stacktrace.Propagate(err, "")
···
228
// GetPlcData - /:did/data - similar to GetLastOp but applies a transformation on the op which normalizes it into a modern op
229
// if missing -> returns ErrDIDNotFound
230
// if tombstone -> returns ErrDIDGone
231
-
plc.mu.Lock()
232
-
defer plc.mu.Unlock()
233
-
234
l, _, err := store.Tree.AuditLog(ctx, tx, did, false)
235
if err != nil {
236
return didplc.RegularOp{}, stacktrace.Propagate(err, "")
···
252
}
253
254
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
entries, err := store.Tree.ExportOperations(ctx, tx, after, count)
259
return entries, stacktrace.Propagate(err, "")
260
}
···
2
3
import (
4
"context"
0
5
6
"github.com/bluesky-social/indigo/atproto/syntax"
7
"github.com/did-method-plc/go-didplc"
···
14
)
15
16
type plcImpl struct {
0
17
validator OperationValidator
18
}
19
···
27
}
28
29
func (plc *plcImpl) ValidateOperation(ctx context.Context, readTx transaction.Read, did string, opBytes []byte) error {
0
0
0
30
timestamp := syntax.Datetime(readTx.Timestamp().Format(types.ActualAtprotoDatetimeLayout))
31
32
// TODO set true to false only while importing old ops
···
39
}
40
41
func (plc *plcImpl) ExecuteOperation(ctx context.Context, tx transaction.Write, did string, opBytes []byte) error {
0
0
0
42
timestamp := syntax.Datetime(tx.Timestamp().Format(types.ActualAtprotoDatetimeLayout))
43
44
// TODO set true to false only while importing old ops
···
55
return nil
56
}
57
func (plc *plcImpl) ImportOperationFromAuthoritativeSource(ctx context.Context, tx transaction.Write, newEntry didplc.LogEntry) error {
0
0
0
58
newCID := newEntry.CID
59
newPrev := newEntry.Operation.AsOperation().PrevCIDStr()
60
···
128
}
129
130
func (plc *plcImpl) Resolve(ctx context.Context, tx transaction.Read, did string) (didplc.Doc, error) {
0
0
0
131
l, _, err := store.Tree.AuditLog(ctx, tx, did, false)
132
if err != nil {
133
return didplc.Doc{}, stacktrace.Propagate(err, "")
···
149
// if missing -> returns ErrDIDNotFound
150
// if tombstone -> returns log as normal
151
0
0
0
152
l, _, err := store.Tree.AuditLog(ctx, tx, did, false)
153
if err != nil {
154
return nil, stacktrace.Propagate(err, "")
···
171
// GetPlcAuditLog - /:did/log/audit - full audit log, with nullified
172
// if missing -> returns ErrDIDNotFound
173
// if tombstone -> returns log as normal
0
0
0
174
l, _, err := store.Tree.AuditLog(ctx, tx, did, false)
175
if err != nil {
176
return nil, stacktrace.Propagate(err, "")
···
189
// GetLastOp - /:did/log/last - latest op from audit log which isn't nullified (the latest op is guaranteed not to be nullified)
190
// if missing -> returns ErrDIDNotFound
191
// if tombstone -> returns tombstone op
0
0
0
192
l, _, err := store.Tree.AuditLog(ctx, tx, did, false)
193
if err != nil {
194
return didplc.OpEnum{}, stacktrace.Propagate(err, "")
···
205
// GetPlcData - /:did/data - similar to GetLastOp but applies a transformation on the op which normalizes it into a modern op
206
// if missing -> returns ErrDIDNotFound
207
// if tombstone -> returns ErrDIDGone
0
0
0
208
l, _, err := store.Tree.AuditLog(ctx, tx, did, false)
209
if err != nil {
210
return didplc.RegularOp{}, stacktrace.Propagate(err, "")
···
226
}
227
228
func (plc *plcImpl) Export(ctx context.Context, tx transaction.Read, after uint64, count int) ([]types.SequencedLogEntry, error) {
0
0
0
229
entries, err := store.Tree.ExportOperations(ctx, tx, after, count)
230
return entries, stacktrace.Propagate(err, "")
231
}