Skip to content

Commit

Permalink
Return option for object get in authorities (MystenLabs#329)
Browse files Browse the repository at this point in the history
* Return option for object get in authorities
  • Loading branch information
oxade authored Feb 1, 2022
1 parent bf2b82d commit e79df80
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 67 deletions.
10 changes: 5 additions & 5 deletions fastpay_core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,9 @@ impl AuthorityState {

// Always attempt to return the latest version of the object and the
// current lock if any.
let object_result = self.object_state(&request.object_id).await;
let object_result = self.get_object(&request.object_id).await;
let object_and_lock = match object_result {
Ok(object) => {
Ok(Some(object)) => {
let lock = if object.is_read_only() {
// Read only objects have no locks.
None
Expand All @@ -430,8 +430,8 @@ impl AuthorityState {

Some(ObjectResponse { object, lock })
}
Err(FastPayError::ObjectNotFound { .. }) => None,
Err(e) => return Err(e),
_ => None,
};

Ok(ObjectInfoResponse {
Expand Down Expand Up @@ -487,8 +487,8 @@ impl AuthorityState {
}
}

async fn object_state(&self, object_id: &ObjectID) -> Result<Object, FastPayError> {
self._database.object_state(object_id)
async fn get_object(&self, object_id: &ObjectID) -> Result<Option<Object>, FastPayError> {
self._database.get_object(object_id)
}

pub async fn insert_object(&self, object: Object) {
Expand Down
8 changes: 2 additions & 6 deletions fastpay_core/src/authority/authority_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,8 @@ impl AuthorityStore {
}

/// Read an object and return it, or Err(ObjectNotFound) if the object was not found.
pub fn object_state(&self, object_id: &ObjectID) -> Result<Object, FastPayError> {
self.objects
.get(object_id)?
.ok_or(FastPayError::ObjectNotFound {
object_id: *object_id,
})
pub fn get_object(&self, object_id: &ObjectID) -> Result<Option<Object>, FastPayError> {
self.objects.get(object_id).map_err(|e| e.into())
}

/// Get many objects
Expand Down
12 changes: 4 additions & 8 deletions fastpay_core/src/authority/temporary_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,10 @@ impl Storage for AuthorityTemporaryStore {
fn read_object(&self, id: &ObjectID) -> Option<Object> {
match self.objects.get(id) {
Some(x) => Some(x.clone()),
None => {
let object = self.object_store.object_state(id);
match object {
Ok(o) => Some(o),
Err(FastPayError::ObjectNotFound { .. }) => None,
_ => panic!("Could not read object"),
}
}
None => match self.object_store.get_object(id) {
Ok(o) => o,
Err(e) => panic!("Could not read object {}", e),
},
}
}

Expand Down
Loading

0 comments on commit e79df80

Please sign in to comment.