-
-
Notifications
You must be signed in to change notification settings - Fork 50
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
Fix consensus ordering for cross-chains #275
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #275 +/- ##
========================================
+ Coverage 13.2% 14.2% +1.0%
========================================
Files 29 29
Lines 3883 3938 +55
========================================
+ Hits 513 558 +45
- Misses 3370 3380 +10
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
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.
two different chains are used, and one doesn't report timestamps properly
Could you please explain how does this PR address this?
testnet may have blocks which timestamps are not aligned with their heights
56ca936
to
4d4078a
Compare
self.timestamp.cmp(&other.timestamp) | ||
const BLOCK_TIME: i64 = 10 /*min*/ * 60 /*secs*/; | ||
match (self.layer1, other.layer1) { | ||
(a, b) if a == b => self.height.cmp(&other.height), |
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.
here #117 you said:
using block height and position in the block of the witness transaction
but this code isn't doing this, is the code incomplete or the documentation old? To me it seems a rule we should keep, to allow ordering of TXs in the same block
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 do not get: the code is exactly compares the block height, i.e. is doing what is said
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.
To me it seems it's comparing just the block height, not the position of the TX in the block
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.
Oh, I see now.
#117 is outdated. In reality it happened that it is impossible to use position in the block since it is hard to compute from indexer's data. So instead we have started using opid
value, which can be seen from the OpOrd
structure (the ultimate operation ordering) below in this file.
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.
Could you please explain how the OpId
helps ordering TXs mined in the same block? From what I see the OpId
is the commitment hash of the RGB operation, it seems unrelated to the mining status of the TX.
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.
We need to order operations, not transactions. We just utilize anchors and witness transaction to order operations, but we are not locked to just transaction information.
Since witness transactions may contain multiple operations (two anchors, a bundle per anchor, multiple state transitions per bundle, plus arbitrary large number of state extensions) txid or inside-block ordering won't help anyway
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.
Still I don't understand how the OpId
should allow a meaningful ordering of operations, since its just a hash. Could you please clarify this?
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.
Opid is just one of the factors of ordering. You asked "why we do not account for block position of witness transaction" and the answer here is "we do not need it".
Consensus ordering of operations takes many factors (listed in their priority):
- Blockchain
- Block height (or timestamp, when compared cross-chain in large window)
- Operation type (extensions go in front of transitions)
- Nonce
- Opid
1-2 are related to witness transactions, and 3-5 to operations themselves. Normally you use nonce (which we discussed a lot with you!) to do definite ordering within the same block! But if you misused nonce and gave two different state transition the same one, then (and only then!) opid comes into play. Yes, this is not a meaningful, but at least deterministic. For meaningful ordering one must use nonce properly.
Co-authored-by: Stefano Pellegrini <[email protected]>
Implementation of RCP-20241013A
Alternative to #274 which takes care of situations where