Support the DID DHT API#76
Conversation
| } | ||
| } | ||
|
|
||
| if err = s.db.WriteDID(storage.GatewayRecord{ |
There was a problem hiding this comment.
Is there a possible race condition when publishing the same did? Perhaps some idempotency key is necessary.
There was a problem hiding this comment.
yeah I'm also worried about multiple DIDs updating the type index at the same time...
| } | ||
|
|
||
| var ( | ||
| knownTypes = []TypeMapping{ |
There was a problem hiding this comment.
Side question: how are types registered? Is it a centralized registry?
There was a problem hiding this comment.
| } | ||
|
|
||
| // WriteDID writes a DID to the storage and adds it to the type index(es) it is associated with | ||
| func (s *Storage) WriteDID(record GatewayRecord) error { |
There was a problem hiding this comment.
How do you intend to handle failures in the middle? For example, the write succeeds, but the update does not.
There was a problem hiding this comment.
ideally this should be a txn with rollbacks
| for _, currType := range currTypes { | ||
| if _, ok := newTypeMap[currType]; !ok { | ||
| if err := s.RemoveDIDFromTypeIndex(id, currType); err != nil { | ||
| return err | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // add the DID to any type indexes it is now associated with | ||
| for _, newType := range newTypes { | ||
| if _, ok := currTypeMap[newType]; !ok { | ||
| if err := s.AddDIDToTypeIndex(id, newType); err != nil { | ||
| return err | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Removing and then adding add steps which may fail in the middle.
Instead, consider replacing the types with the new value. This might be more easily supported by the storage layer.
There was a problem hiding this comment.
good idea will update
Fix #43 #13 #24 #72