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

Fix a mix up with AccountSet flags #524

Merged
merged 7 commits into from
Jun 1, 2023

Conversation

rikublock
Copy link
Contributor

@rikublock rikublock commented Feb 20, 2023

High Level Overview of Change

  • rename AccountSetFlag -> AccountSetAsfFlag; defines asf flags (this could be considered a breaking change)
  • add enum AccountSetTfFlag AccountSetFlag (name adjusted, see discussion below); defines transaction tf flags
  • update AccountSetFlagInterface to only use transaction tf flags
  • update/fix tests accordingly

Context of Change

AccountSet has two types of flags.

  • "AccountSet Flags" (prefixed asf), used in SetFlag/ClearFlag field, limited to one per transaction
  • "AccountSet Transaction Flags" (prefixed tf), used in common Flags field, multiple possible (bit-flags)

(AccountSetAsfFlag are not bit-field flags and therefore do not require a FlagInterface)

Reference:

Similar to the implementation found in the xrpl.js framework, this PR creates an enum for each type of flag.

Type of Change

  • Bug fix (possibly breaking change which fixes an issue)

Test Plan

  • only ran poetry run poe test_unit
  • needs better/more testing (and extensive review)

@mvadari
Copy link
Collaborator

mvadari commented Feb 21, 2023

Why is this PR necessary?

@ckniffen
Copy link
Collaborator

Nice catch!

I am in favor of the tf flags and TX_FLAGS which currently has completely incorrect flags listed. That said I don't think AccountSetFlags needs to be renamed.

@ckniffen ckniffen mentioned this pull request Feb 21, 2023
1 task
@rikublock
Copy link
Contributor Author

rikublock commented Feb 22, 2023

Why is this PR necessary?

I think the current implementation is confusing and faulty.

Let me showcase this by example (code taken from unit tests)
https://github.com/XRPLF/xrpl-py/blob/v1.7.0/tests/unit/models/transactions/test_better_transaction_flags.py#L20

        actual = models.AccountSet(
            account=ACCOUNT,
            flags=models.AccountSetFlagInterface(
                asf_account_tx_id=True,
                asf_authorized_nftoken_minter=True,
                asf_default_ripple=True,
                asf_deposit_auth=True,
                asf_disable_master=True,
                asf_disallow_xrp=True,
                asf_global_freeze=True,
                asf_no_freeze=True,
                asf_require_auth=True,
                asf_require_dest=True,
            ),
        )

As outlined before there are two kinds of AccountSet flags, the asf and tf flags. The somewhat special asf flags can take integer values from 1 to 10 (these are just numbers and do not represent bits). At most one asf flag can be set per transaction.

The above code has several issues:

  • a FlagInterface essential represent bits; doing bit operations on asf flags makes no sense
  • the flags parameter accepts tf transaction flags, assigning the asf gibberish produced by the AccountSetFlagInterface makes even less sense

@rikublock
Copy link
Contributor Author

rikublock commented Feb 22, 2023

Nice catch!

I am in favor of the tf flags and TX_FLAGS which currently has completely incorrect flags listed. That said I don't think AccountSetFlags needs to be renamed.

I think the FlagInterface changes are also very much necessary.

In regards to naming. Currently the pattern used throughout the library for naming flags seems to be tx name + 'Flag'. For example:

  • TrustSetFlag for TrustSet
  • OfferCreateFlag for OfferCreate

Following that would result in:

  • AccountSetFlag for the tf transaction flags
  • AccountSetAsfFlag for the asf flags (that's the outlier/special case, should probably also get the outlier name)

The only drawback/consideration would have to be that we are "switching" the flags that were defined in AccountSetFlag (until now asf).

@rikublock
Copy link
Contributor Author

Assuming this PR moves forward eventually, I will have to make some changes:

  • someone (@mvadari ?) has to make a decision regarding the enum names (see above)
  • will need a rebase to resolve some minor conflicts introduced in Add disallow_incoming flags #522
  • will need minor linting fixes

@justinr1234
Copy link
Collaborator

@rikublock would you be able to make those changes now?

@mvadari do you have an opinion on the enum names?

@ckniffen
Copy link
Collaborator

  • AccountSetFlag for the tf transaction flags
  • AccountSetAsfFlag for the asf flags (that's the outlier/special case, should probably also get the outlier name)

I like these names and agree with the logic.

@rikublock
Copy link
Contributor Author

rikublock commented May 23, 2023

@rikublock would you be able to make those changes now?

I'll take a look at it this week.

@JST5000 JST5000 changed the base branch from master to xrpl-py-2.0 May 23, 2023 19:17
@JST5000 JST5000 changed the base branch from xrpl-py-2.0 to master May 23, 2023 19:18
@JST5000
Copy link
Contributor

JST5000 commented May 23, 2023

As a rough plan of action, I think these changes should be included in xrpl-py 2.0, so I'll take it as an action item today/tomorrow to get the xrpl-py 2.0 branch up to date so we can point it at that branch without a lot of unrelated changes appearing in the changelog :)

@rikublock
Copy link
Contributor Author

I added the outstanding changes and fixes. I also split the commits to make each individual change easier to understand/review.

As a rough plan of action, I think these changes should be included in xrpl-py 2.0, so I'll take it as an action item today/tomorrow to get the xrpl-py 2.0 branch up to date so we can point it at that branch without a lot of unrelated changes appearing in the changelog :)

Sounds good. I agree, it might be best to include this in a major release as the PR contains somewhat breaking changes.

@JST5000 JST5000 changed the base branch from master to xrpl-py-2.0 May 24, 2023 16:10
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 - one last thing though could you add a note in the HISTORY.md file about the changes? (I'd recommend including both the name change & bug fix as separate bullets so it's very clear to future readers that there's something they have to do to update)

Note: AccountSetAsfFlags are not bit-field flags and therefore
do not require a FlagInterface. At most one asf flag can be
set per transaction.
@JST5000
Copy link
Contributor

JST5000 commented Jun 1, 2023

@rikublock Ah, didn't realize you were changing things at the moment - I just was rebasing to try to fix the merge conflicts. It seems I have included all the above commits in the final version. Are there any other changes you were hoping to make before we merge it?

@JST5000 JST5000 merged commit 51bbf93 into XRPLF:xrpl-py-2.0 Jun 1, 2023
@JST5000
Copy link
Contributor

JST5000 commented Jun 1, 2023

I think I may have misinterpreted the Git history - if there are changes we need to make we can do a follow up PR :)

@rikublock
Copy link
Contributor Author

@JST5000 As far as I am concerned this PR included all the necessary changes.

JST5000 pushed a commit that referenced this pull request Jun 28, 2023
* rename AccountSetFlag -> AccountSetAsfFlags

* add AccountSetFlag enum to represent transaction flags

Note: AccountSetAsfFlags are not bit-field flags and therefore
do not require a FlagInterface. At most one asf flag can be
set per transaction.
JST5000 pushed a commit that referenced this pull request Jun 28, 2023
* rename AccountSetFlag -> AccountSetAsfFlags

* add AccountSetFlag enum to represent transaction flags

Note: AccountSetAsfFlags are not bit-field flags and therefore
do not require a FlagInterface. At most one asf flag can be
set per transaction.
JST5000 pushed a commit that referenced this pull request Jul 5, 2023
* rename AccountSetFlag -> AccountSetAsfFlags

* add AccountSetFlag enum to represent transaction flags

Note: AccountSetAsfFlags are not bit-field flags and therefore
do not require a FlagInterface. At most one asf flag can be
set per transaction.
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