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

move txvalidation flag util to internal/pkg from ledger #927

Merged
merged 1 commit into from
Apr 3, 2020

Conversation

cendhu
Copy link
Contributor

@cendhu cendhu commented Mar 27, 2020

Type of change

  • Improvement (improvement to code)

Description

The txvalidation-flag util package helps in creating transaction validation flags that would be assigned to the block metadata. This function is used by the v14 and v20 validation as it is needed by these packages to record invalid tx as per policy evaluation. This validation flag is also reused in the mvcc validator to mark valid/invalid transactions. Further, the txvalidation-flag util is referred in many other packages including test, hence, we move the util to internal/pkg/txflags

Additional details

Before starting the ledger checkpointing code, we would like to refactor the ledger package. If we continue to add new features with the current package structure, after a few years, it will be unmaintainable. We plan to have nearly 10 such PRs. Note that each PR may modify many files and we cannot do much about it. We might be okay to get some review burden than having an unmaintainable code in the longer term.

Related issues

FAB-17677

@cendhu cendhu requested a review from a team as a code owner March 27, 2020 19:09
@lindluni
Copy link
Contributor

Hit Flake: FAB-17611
Has potential fix #895

@cendhu cendhu force-pushed the mv-txvalidation-flag branch from e0de8fb to 6f8aed5 Compare March 30, 2020 03:00
@cendhu
Copy link
Contributor Author

cendhu commented Mar 30, 2020

/ci-run

@github-actions
Copy link

AZP build triggered!

@cendhu cendhu changed the title [for v2.2.0] move txvalidation flag util to txvalidator package from ledger [for v2.2.0] move txvalidation flag util to txvalidator package from ledger [2] Mar 30, 2020
@cendhu cendhu force-pushed the mv-txvalidation-flag branch from 6f8aed5 to fb10fef Compare March 30, 2020 13:17
@cendhu cendhu changed the title [for v2.2.0] move txvalidation flag util to txvalidator package from ledger [2] move txvalidation flag util to txvalidator package from ledger [merge-order-2] Mar 31, 2020
Copy link
Contributor

@manish-sethi manish-sethi 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 a nit-picking comment. I am fine if you do not want to take that suggestion.
This PR got into a conflict now and I am fine with merging after you rebase

@@ -209,7 +209,7 @@ func TestBlockfileMgrGetTxByIdDuplicateTxid(t *testing.T) {
},
[]string{"txid-1", "txid-2", "txid-1"},
)
txValidationFlags := ledgerutil.NewTxValidationFlags(3)
txValidationFlags := txflags.NewTxValidationFlags(3)
Copy link
Contributor

Choose a reason for hiding this comment

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

After moving this here, this functions (and the other one) can be renamed to remove redundant info in the package name and the function name. For instance, this function could simply be renamed as "New".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, I agree. Will do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The following changes are done.
TxValidationFlags -> ValidationFlags
NewTxValidationFlags() -> New()
NewTxValidationFlagsSetValue() -> NewWithValues()

Copy link
Contributor

Choose a reason for hiding this comment

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

The following changes are done.
TxValidationFlags -> ValidationFlags
NewTxValidationFlags() -> New()
NewTxValidationFlagsSetValue() -> NewWithValues()

Looks good. I guess that "TxValidationFlags" could be changed to "Values" to match others renames. But I am fine merging this as the larger objective is achieved.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we do that, wouldn't API become little ugly? -- Values vs NewWithValues()
TxValidationFlags -> Values
NewTxValidationFlags() -> New()
NewTxValidationFlagsSetValue() -> NewWithValues()

The reasoning behind the current naming is that txflags.ValidationFlags denotes that we have txflags and one type of the flag is validation flags. I know that we will not have any more types but this makes code more readable IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have contradicted with myself there. With that reasoning, even the New() can be made NewValidationFlags(). Let's see what Gari suggests.

Copy link
Contributor

Choose a reason for hiding this comment

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

As I had mentioned earlier, I am fine with any consistent naming. One alternate could be to use txvalidationflags for the package name, so we don't miss validation in the name and at the same time avoid repetition of flags in package name and in the name of functions/types.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's go with what we have now. Don't want to get blocked on this.

The txvalidation util package helps in creating transaction validation
flags that would be assigned to the block metadata. This function is used
by the v14 and v20 validation as it is needed by these packages to record
invalid tx as per policy evaluation. This validation flags is also reused
in the mvcc validator to mark valid/invalid transactions. In addition to
these two packages, the txflags are referred in so many other packages.
Keeping the txflag in core/ledger/util is not correct. Hence, we move the
txvalidation util package to the internal/pkgs/txflags.

Signed-off-by: senthil <cendhu@gmail.com>
@cendhu cendhu force-pushed the mv-txvalidation-flag branch from fb10fef to 3ab231a Compare April 1, 2020 10:52
@cendhu cendhu changed the title move txvalidation flag util to txvalidator package from ledger [merge-order-2] move txvalidation flag util to txvalidator package from ledger Apr 1, 2020
@cendhu
Copy link
Contributor Author

cendhu commented Apr 2, 2020

@mastersingh24 your approval is still pending. Can you please ack on the following?

@manish-sethi and I discussed offline on the package/variable/init function naming. Though it is very minor, we thought of doing it in the correct way as we are already changing 29 files. Though these discussions might look unnecessary, we feel that this knowledge will help in future PRs.

Proposed Convention.
package name: internal/pkg/txvalidation
variable name: Flags
Initialization: NewFlags(), NewInitializedFlags()

Current Convention as used in this PR.
package name: internal/pkg/txflags
variable name: ValidationFlags
Initialization: New(), NewWithValues()

If you agree with the proposed convention, I will make the modification.

@cendhu cendhu changed the title move txvalidation flag util to txvalidator package from ledger move txvalidation flag util to internal/pkg from ledger Apr 2, 2020
@mastersingh24 mastersingh24 merged commit 2f90167 into hyperledger:master Apr 3, 2020
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.

4 participants