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

feat: add support for current sidechain design #2039

Merged
merged 137 commits into from
Sep 26, 2023
Merged

feat: add support for current sidechain design #2039

merged 137 commits into from
Sep 26, 2023

Conversation

mvadari
Copy link
Collaborator

@mvadari mvadari commented Jul 11, 2022

High Level Overview of Change

This PR adds support for the latest version of the sidechain design.

There are 8 new transaction types:

  • XChainCreateBridge (creates a new cross-chain bridge)
  • XChainModifyBridge (modifies the properties of a cross-chain bridge)
  • XChainCreateClaimID (creates a new cross-chain claim ID)
  • XChainCommit (locks/burns the funds on the source chain)
  • XChainAccountCreateCommit (creates an account on the destination chain)
  • XChainClaim (claims the transfer funds on the destination chain)
  • XChainAddClaimAttestation (submits a claim attestation from a witness server)
  • XChainAddAccountCreateAttestation (submits an account creation attestation from a witness server)

#2059 and #2301 should be merged into this PR before this PR is merged.

Context of Change

sidechain prod release

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Before / After

Test Plan

Tests were added for all the new features. CI passes.

@mvadari mvadari changed the base branch from main to xrpl-codec-gen July 11, 2022 21:37
Base automatically changed from xrpl-codec-gen to main July 19, 2022 20:01
@mvadari mvadari changed the title feat: add support for current sidechain design [DO NOT MERGE] feat: add support for current sidechain design Aug 16, 2022
@mvadari mvadari marked this pull request as ready for review August 16, 2022 11:51
khancode
khancode previously approved these changes Aug 30, 2022
Copy link
Collaborator

@khancode khancode left a comment

Choose a reason for hiding this comment

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

Approving since it's fine to omit docstrings for a beta release.

export function validateXChainModifyBridge(tx: Record<string, unknown>): void {
validateBaseTransaction(tx)

if (tx.XChainBridge == null) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

A lot of this logic is shared between multiple transaction types. Maybe have a base xchain validation function.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is already done with isXChainBridge. I don't think it matters that much for the two if statements that are replicated between all the transactions. I'm can change this if you object though.

Copy link
Collaborator Author

@mvadari mvadari Sep 21, 2023

Choose a reason for hiding this comment

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

Fixed in 6594c19 - the helper functions aren't going to be used in existing models in this PR because that would be a lot of work (and make this PR even more gargantuan), but the script should work for those as well.

@@ -152,6 +153,30 @@ export interface LedgerEntryRequest extends BaseRequest, LookupByLedgerRequest {
* Must be the object ID of the NFToken page, as hexadecimal
*/
nft_page?: string

bridge_account?: string
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: document these new fields.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

* common parameters.
*/
XChainCreateAccountAttestations: Array<{
// TODO: add docs
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: forgotten TODO.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ledgersWaited = 0
while (ledgersWaited < MAX_LEDGERS_WAITED) {
await sleep(LEDGER_CLOSE_TIME)
const currentBalance = await issuingClient.getXrpBalance(
Copy link
Collaborator

Choose a reason for hiding this comment

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

That error might be helpful regardless of it if is sidechain or not.

import {
XChainModifyBridge,
validateXChainModifyBridge,
} from './XChainModifyBridge'

/**
Copy link
Collaborator

Choose a reason for hiding this comment

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

Rolling out a tx system like the explorer could clean this up a bit. Maybe something for 4.0

Copy link
Collaborator

@ckniffen ckniffen left a comment

Choose a reason for hiding this comment

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

Approving ahead of the documentation additions.

* signature.
*/
XChainClaimAttestations: Array<{
// TODO: add docs
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this TODO being tracked somewhere?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes - @oeggert has it in his backlog

@@ -78,7 +78,7 @@ describe('BaseTransaction', function () {
assert.throws(
() => validateBaseTransaction(invalidFee),
ValidationError,
'BaseTransaction: invalid Fee',
'Payment: invalid field Fee',
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was this changed from BaseTransaction to Payment?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The error was changed when I refactored the validateBaseTransaction method to use the new helper functions.

Copy link
Contributor

@JST5000 JST5000 left a comment

Choose a reason for hiding this comment

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

LGTM - documentation changes can be added in a separate PR

* add XChainAddAttestation tests, fix model

* add XChainClaim model tests

* add XChainCommit model tests, fix typo

* add XChainCreateBridge model tests

* add XChainCreateClaimID model tests

* fix tests

* add XChainModifyBridge tests

* fix tests

* fix more tests

* fix linting errors

* update to most recent version of code

* remove XChainAddAttestationBatch tests

* fix rebase issues

* fix linter issues

* add more validation tests

* fix linter errors

* fix tests

* switch createValidateTests to JS
@mvadari mvadari changed the title [DO NOT MERGE] feat: add support for current sidechain design feat: add support for current sidechain design Sep 26, 2023
@mvadari mvadari merged commit 91e7369 into main Sep 26, 2023
17 checks passed
@mvadari mvadari deleted the sidechain-2.5 branch September 26, 2023 14:01
Copy link
Collaborator

@khancode khancode left a comment

Choose a reason for hiding this comment

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

LGTM, just nit comments

Comment on lines +66 to +83
if (value instanceof XChainBridge) {
return value
}

if (isXChainBridgeObject(value)) {
const bytes: Array<Buffer> = []
this.TYPE_ORDER.forEach((item) => {
const { name, type } = item
if (type === AccountID) {
bytes.push(Buffer.from([0x14]))
}
const object = type.from(value[name])
bytes.push(object.toBytes())
})
return new XChainBridge(Buffer.concat(bytes))
}

throw new Error('Invalid type to construct an XChainBridge')
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: I prefer throwing validation errors near the top of a function.

Suggested change
if (value instanceof XChainBridge) {
return value
}
if (isXChainBridgeObject(value)) {
const bytes: Array<Buffer> = []
this.TYPE_ORDER.forEach((item) => {
const { name, type } = item
if (type === AccountID) {
bytes.push(Buffer.from([0x14]))
}
const object = type.from(value[name])
bytes.push(object.toBytes())
})
return new XChainBridge(Buffer.concat(bytes))
}
throw new Error('Invalid type to construct an XChainBridge')
if (value instanceof XChainBridge) {
return value
}
if (!isXChainBridgeObject(value)) {
throw new Error('Invalid type to construct an XChainBridge')
}
const bytes: Array<Buffer> = []
this.TYPE_ORDER.forEach((item) => {
const { name, type } = item
if (type === AccountID) {
bytes.push(Buffer.from([0x14]))
}
const object = type.from(value[name])
bytes.push(object.toBytes())
})
return new XChainBridge(Buffer.concat(bytes))

* transaction. If this isn't present, the {@link XChainAccountCreateCommit}
* transaction will fail. This field can only be present on XRP-XRP bridges.
*/
MinAccountCreateAmount?: string
Copy link
Collaborator

Choose a reason for hiding this comment

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

I also prefer optional fields being after required ones. Personally, it's easier to read. :)

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.

5 participants