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

Implement NotaryAssisted transaction attribute #3175

Open
wants to merge 25 commits into
base: master
Choose a base branch
from

Conversation

AnnaShaleva
Copy link
Member

@AnnaShaleva AnnaShaleva commented Mar 6, 2024

Description

Close #2896. Use a stub for native Notary contract hash since this contract is not implemented yet. Thus, technically, NotaryAssisted attribute verification will always fail on real network until native Notary is implemented.

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • A group of unit tests for NotaryAssisted attribute.

Checklist:

Close neo-project#2896. Use a stub for native Notary contract hash since this
contract is not implemented yet. Thus, technically, NotaryAssisted
attribute verification will always fail on real network until native
Notary is implemented.

Signed-off-by: Anna Shaleva <[email protected]>
AnnaShaleva added a commit to AnnaShaleva/neo-devpack-dotnet that referenced this pull request Mar 6, 2024
AnnaShaleva added a commit to AnnaShaleva/neo-modules that referenced this pull request Mar 6, 2024
@AnnaShaleva
Copy link
Member Author

I'm not allowed to request review, set labels or resolve conversations. Maybe someone from neo-project with access rights can allow me at least to request review?

@shargon
Copy link
Member

shargon commented Mar 6, 2024

I'm not allowed to request review, set labels or resolve conversations. Maybe someone from neo-project with access rights can allow me at least to request review?

You didn't accept your role xD, I sent you an invitation time ago... Time to review your email? 😄

@Jim8y
Copy link
Contributor

Jim8y commented Mar 6, 2024

Hi @AnnaShaleva , we are trying to add as much comments in the core as possible, may you please add comments to explain CalculateNetworkFee.

@AnnaShaleva
Copy link
Member Author

may you please add comments to explain CalculateNetworkFee.

Sure, fixed.

@AnnaShaleva AnnaShaleva requested review from shargon and Jim8y March 6, 2024 15:12
Copy link
Contributor

@roman-khimov roman-khimov left a comment

Choose a reason for hiding this comment

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

GAS.OnPersist change is missing for the attribute.

src/Neo/Network/P2P/Payloads/TransactionAttributeType.cs Outdated Show resolved Hide resolved
Transactions network fee should be split between Primary node and Notary
nodes.

Signed-off-by: Anna Shaleva <[email protected]>
Once Notary contract is implemented, this hash will be replaced by a
proper Notary contract hash. The exact value won't be changed since
Notary contract has constant hash as any other native contract.

Signed-off-by: Anna Shaleva <[email protected]>
@AnnaShaleva
Copy link
Member Author

GAS.OnPersist change is missing for the attribute.

Completely forgot about it, fixed.

@AnnaShaleva AnnaShaleva requested a review from roman-khimov March 7, 2024 09:41
@vncoelho
Copy link
Member

vncoelho commented Mar 7, 2024

Maybe this PR we merge after next release.

@AnnaShaleva
Copy link
Member Author

Maybe this PR we merge after next release.

This PR doesn't hurt because currently in real network NotaryAssisted attribute is always invalid since transaction must have Notary contract as a signer, and Notary contract is not implemented yet.

Thus, I vote to merge it before 3.7. What do you think?

@roman-khimov
Copy link
Contributor

It goes step by step, @vncoelho. What this delay would buy us? The attribute logic is rather simple on its own.

roman-khimov
roman-khimov previously approved these changes Mar 7, 2024
Copy link
Member

@shargon shargon left a comment

Choose a reason for hiding this comment

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

I need more time to review the notary proposal, honestly, I didn't expect it to be merged in 3.7 and it is already beginning to produce changes in the core

D hardfork was occupied by 3.7.5, thus use the next available one.

Signed-off-by: Anna Shaleva <[email protected]>
@AnnaShaleva
Copy link
Member Author

UPD: we're aware of the Technical Committee decision to postpone the Notary subsystem implementation. However, we think that it's good to keep this code up-to-date wrt the current master so that it'll be easier for us to review and merge it once the time comes. Hence, I've updated the code to the latest master and moved the NotaryAssisted attribute under the next available hardfork (HF_Echidna).

No functional changes, just build fixes required by updated master
branch.

Signed-off-by: Anna Shaleva <[email protected]>
@AnnaShaleva
Copy link
Member Author

@neo-project/core let's resume our work on this PR. I've updated it to fetch fresh master, NotaryAssisted attribute will be enabled starting from Echidna.

@@ -16,6 +16,7 @@ public enum Hardfork : byte
HF_Aspidochelone,
HF_Basilisk,
HF_Cockatrice,
HF_Domovoi
HF_Domovoi,
HF_Echidna,
Copy link
Member Author

Choose a reason for hiding this comment

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

I'll refactor this code after the merge of #3454.

cschuchardt88
cschuchardt88 previously approved these changes Jan 17, 2025
AnnaShaleva and others added 2 commits January 23, 2025 17:00
Related to additional storage entries added by the previous changes.

Signed-off-by: Anna Shaleva <[email protected]>
var notaryAssisted = tx.GetAttribute<NotaryAssisted>();
if (notaryAssisted is not null)
{
totalNetworkFee -= (notaryAssisted.NKeys + 1) * Policy.GetAttributeFee(engine.SnapshotCache, (byte)notaryAssisted.Type);
Copy link
Member

Choose a reason for hiding this comment

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

@AnnaShaleva AttributeFee in memory pool can be 1, and during the block persistence can be changed to 2, this could underflow totalNetworkFee and produce a denial of service.

/// <param name="attributeType">Attribute type excluding <see cref="TransactionAttributeType.NotaryAssisted"/></param>
/// <param name="value">Attribute fee value</param>
/// <returns>The fee for attribute.</returns>
[ContractMethod(Hardfork.HF_Echidna, CpuFee = 1 << 15, RequiredCallFlags = CallFlags.States, Name = "setAttributeFee")]
Copy link
Member

Choose a reason for hiding this comment

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

I think we don't need to change the manifest if only the logic changed, we can do it in the same method

private uint GetAttributeFee(DataCache snapshot, byte attributeType, bool allowNotaryAssisted)
{
if (!Enum.IsDefined(typeof(TransactionAttributeType), attributeType) || (!allowNotaryAssisted && attributeType == (byte)(TransactionAttributeType.NotaryAssisted)))
throw new InvalidOperationException();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
throw new InvalidOperationException();
throw new InvalidOperationException($"Invalid value {attributeType} of {nameof(attributeType)}");

{
if (!Enum.IsDefined(typeof(TransactionAttributeType), attributeType)) throw new InvalidOperationException();
if (!Enum.IsDefined(typeof(TransactionAttributeType), attributeType) || (!allowNotaryAssisted && attributeType == (byte)(TransactionAttributeType.NotaryAssisted)))
throw new InvalidOperationException();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
throw new InvalidOperationException();
throw new InvalidOperationException($"Invalid value {attributeType} of {nameof(attributeType)}");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a NotaryAssisted transaction attribute
8 participants