-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Disallow the same bridge on one chain: #4720
Conversation
src/test/app/XChain_test.cpp
Outdated
@@ -631,10 +632,12 @@ struct XChain_test : public beast::unit_test::suite, | |||
env.tx(create_bridge(a1, bridge(a1, GUSD, B, BUSD))).close(); | |||
env.tx(create_bridge(a2, bridge(a2, GUSD, B, BUSD))).close(); | |||
|
|||
// Add the exact same bridge to two different accoutns (one must locking | |||
// account and one must be issuing) | |||
// Add the exact same bridge to two different accoutns (one locking |
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.
While you're here:
// Add the exact same bridge to two different accoutns (one locking | |
// Add the exact same bridge to two different accounts (one locking |
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.
Fixed in 211ccc6fd9 [fold] Add additional test
env.tx(create_bridge(a3, bridge(a3, GUSD, a4, a4["USD"]))).close(); | ||
env.tx(create_bridge(a4, bridge(a3, GUSD, a4, a4["USD"]))).close(); | ||
env.tx(create_bridge(a4, bridge(a3, GUSD, a4, a4["USD"])), | ||
ter(tecDUPLICATE)) | ||
.close(); |
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.
Perhaps this should check the reverse situation compared to the above test change - issuing chain then locking chain.
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.
Fixed in 211ccc6fd9 [fold] Add additional test
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.
LGTM 👍. I've offered a small optimization to consider, but it's at your discretion.
{ | ||
return tecDUPLICATE; | ||
auto hasBridge = [&](STXChainBridge::ChainType ct) -> bool { | ||
return !!ctx.view.read(keylet::bridge(bridgeSpec, ct)); |
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.
As a small optimization, consider calling ctx.view.exists()
instead, like this:
return ctx.view.exists(keylet::bridge(bridgeSpec, ct));
This will avoid deserializing the bridge to check the LedgerEntryType
. Just a thought.
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.
Love it. Fixed in 8bbf7b9e21 [fold] Use exists instead of read to check if ledger object exists
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.
👍 Looks great.
Before this patch, two door accounts on the same chain could could own the same bridge spec (of course, one would have to be the issuer and one would have to be the locker). While this is silly, it does not violate any bridge invariants. However, on further review if we allow this then the `claim` transactions would need to change. Since it's hard to see a use case for two doors to own the same bridge, this patch disallows it. (The transaction will return tecDUPLICATE).
8bbf7b9
to
df63e1f
Compare
Squashed and rebased on the latest dev. This is ready to merge into develop. |
note: have tests for this (Ram) |
Modify the `XChainBridge` amendment. Before this patch, two door accounts on the same chain could could own the same bridge spec (of course, one would have to be the issuer and one would have to be the locker). While this is silly, it does not violate any bridge invariants. However, on further review, if we allow this then the `claim` transactions would need to change. Since it's hard to see a use case for two doors to own the same bridge, this patch disallows it. (The transaction will return tecDUPLICATE).
Before this patch, two door accounts on the same chain could could own the same bridge spec (of course, one would have to be the issuer and one would have to be the locker). While this is silly, it does not violate any bridge invariants. However, on further review if we allow this then the
claim
transactions would need to change. Since it's hard to see a use case for two doors to own the same bridge, this patch disallows it. (The transaction will return tecDUPLICATE).