Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored sequence_number and fixed bidirectional object transfer #50

Merged
merged 10 commits into from
Dec 21, 2021

Conversation

patrickkuo
Copy link
Contributor

  • removed sequence_number from ClientState
  • Added sequence number to object_id, each object have its own sequence id now
  • update client's object_id and sequence_number in receive_from_fastpay
  • updated test for bidirectional object transaction

@patrickkuo patrickkuo changed the base branch from main to pat/client_test_refactoring December 11, 2021 16:50
@patrickkuo patrickkuo linked an issue Dec 12, 2021 that may be closed by this pull request
@@ -98,8 +99,7 @@ pub struct UserAccount {
)]
pub address: FastPayAddress,
pub key: KeyPair,
pub next_sequence_number: SequenceNumber,
pub object_ids: Vec<ObjectID>,
pub object_ids: HashMap<ObjectID, SequenceNumber>,
Copy link
Collaborator

@sblackshear sblackshear Dec 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use TreeMap instead of HashMap if I'm planning on iterating over the map (as line 114). HashMap iteration order is nondeterministic, which can cause flakiness and other unexpected problems...

object_ids: Vec<ObjectID>,
received_certificates: BTreeMap<ObjectRef, CertifiedOrder>,
/// The known objects with it's sequence number owned by the client.
object_ids: HashMap<ObjectID, SequenceNumber>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar here, since line 484 iterates over object_id's.

@patrickkuo patrickkuo force-pushed the pat/client_sequence_number_refacotring branch from f628dcf to 7936233 Compare December 13, 2021 14:35
@patrickkuo patrickkuo force-pushed the pat/client_test_refactoring branch from b10ec4f to 20e28f7 Compare December 14, 2021 10:09
@patrickkuo patrickkuo force-pushed the pat/client_sequence_number_refacotring branch 3 times, most recently from 66335ed to 8ad8ebf Compare December 17, 2021 11:34
@patrickkuo patrickkuo changed the base branch from pat/client_test_refactoring to main December 17, 2021 11:34
@patrickkuo patrickkuo force-pushed the pat/client_sequence_number_refacotring branch from 8ad8ebf to 25dbe5c Compare December 17, 2021 19:10
@patrickkuo patrickkuo self-assigned this Dec 20, 2021
@patrickkuo patrickkuo marked this pull request as ready for review December 20, 2021 12:45
@patrickkuo patrickkuo force-pushed the pat/client_sequence_number_refacotring branch from fde71ea to 77123e4 Compare December 20, 2021 12:57
Copy link
Collaborator

@gdanezis gdanezis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one. See my comments about the structures to store certs etc. I do wonder if some of the client could reuse structures from the authority logic to (1) make sure the info is stored in the most handy way, and (2) potentially facilitate a unified sync client <-> authority, and authority <-> authority.

fn get_spendable_amount(
&mut self,
object_id: ObjectID,
) -> AsyncResult<'_, Amount, anyhow::Error>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I correct in thinking this function will probably have to go? Since we do not deal with amounts any more.

object_id,
);

let mut number = SequenceNumber::from(0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we always start looking at 0, or should we start at the highest known cert here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is remnant of fastpay, shouldn't need to loop through all the certs after we change how we store certs in client, will add a TODO

// Sanity check
// Some certificates of the object will be from received_certs if the object is originated from other sender.
// TODO: Maybe we should store certificates in one place sorted by object_ref instead of sent/received?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, i think that is a good idea. In fact the structures a client needs to store certs may be remarkable similar to the structures within an authority? Ie, an index from object ref to cert that created it?

@@ -708,4 +706,29 @@ where
Ok(new_certificate)
})
}

fn get_spendable_amount(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should rename this now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will remove this in Client API expansion task

Amount::zero()
} else {
Amount::try_from(self.balance).unwrap_or_else(|_| std::u64::MAX.into())
};*/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... and delete the dead code, which will never be revived.

…m to confirm the client have ownership of an object in test
* Added sequence number to object_id, each object have its own sequence id now
* update client's object_id and sequence_number in receive_from_fastpay
* updated test for bidirectional object transaction
@patrickkuo patrickkuo force-pushed the pat/client_sequence_number_refacotring branch from 77123e4 to 526e8a6 Compare December 21, 2021 01:32
removed dead code
@patrickkuo patrickkuo merged commit 8acfa8e into main Dec 21, 2021
@patrickkuo patrickkuo deleted the pat/client_sequence_number_refacotring branch January 12, 2022 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[fastx distsys] Refactor Sequence number
3 participants