-
Notifications
You must be signed in to change notification settings - Fork 11.4k
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
Conversation
patrickkuo
commented
Dec 11, 2021
- 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
fastpay/src/config.rs
Outdated
@@ -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>, |
There was a problem hiding this comment.
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...
fastpay_core/src/client.rs
Outdated
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>, |
There was a problem hiding this comment.
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.
f628dcf
to
7936233
Compare
b10ec4f
to
20e28f7
Compare
66335ed
to
8ad8ebf
Compare
8ad8ebf
to
25dbe5c
Compare
fde71ea
to
77123e4
Compare
There was a problem hiding this 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>; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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? |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
fastpay_core/src/client.rs
Outdated
Amount::zero() | ||
} else { | ||
Amount::try_from(self.balance).unwrap_or_else(|_| std::u64::MAX.into()) | ||
};*/ |
There was a problem hiding this comment.
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
77123e4
to
526e8a6
Compare
removed dead code