-
Notifications
You must be signed in to change notification settings - Fork 1k
Implement NotaryAssisted transaction attribute #3175
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
6da4ae2
Implement NotaryAssisted transaction attribute
AnnaShaleva acec1b0
Payloads: add doc to CalculateNetworkFee method of NotaryAssisted att…
AnnaShaleva 1508d4f
Native: add NotaryAssisted attributes handler to Gas OnPersist
AnnaShaleva 8b547c9
Payloads: adjust comment to NotaryAssisted attribute
AnnaShaleva b16a28c
Payloads: temporary use hard-coded Notary contract hash
AnnaShaleva 00b54ff
Merge branch 'master' into notary-assisted
24135ff
Payloads: replace hard-coded Notary hash value with calculated one
AnnaShaleva 2fb879d
Merge branch 'master' into notary-assisted
shargon a260253
Merge branch 'master' into notary-assisted
shargon e2f0360
Merge branch 'master' into notary-assisted
cschuchardt88 fbf5eae
NeoModules: integrate NotaryAssisted attribute
AnnaShaleva 151f859
Payloads: fix XML comment formatting
AnnaShaleva 042440f
Merge branch 'master' into notary-assisted
AnnaShaleva c229cd5
P2P: move NotaryAssisted transaction attribute under D hardfork
AnnaShaleva 01ddf78
Merge branch 'master' into notary-assisted
AnnaShaleva 4d5cee9
P2P: move NotaryAssisted transaction attribute under E hardfork
AnnaShaleva 53a031d
Merge branch 'master' into notary-assisted
AnnaShaleva 8e33ca4
tests: fix build errors
AnnaShaleva 08a41ce
NotaryAssisted: update copyright date
AnnaShaleva 0d3012e
Merge branch 'master' into notary-assisted
AnnaShaleva ab422d7
Merge branch 'master' into notary-assisted
cschuchardt88 4af93c8
Merge branch 'master' into notary-assisted
AnnaShaleva ec4e3d6
SmartContract: refactor obsolete code
AnnaShaleva bf4b294
Persistance: fix UT
AnnaShaleva d5f37df
Clean comments
shargon fb35cec
Merge branch 'master' into notary-assisted
AnnaShaleva 5648a9b
Native: improve exception message for Policy's getFee/setFee
AnnaShaleva 9385746
EC Recover (#3696)
shargon 470e0d9
Improve MaxNestingDepth of WitnessCondition (#3761)
roman-khimov f73364d
Add Support for Plugin Loading by Assembly (#3755)
cschuchardt88 7d73ebe
Optimize `StorageKey` creation (#3756)
shargon cb41f92
[`Fix`] Linux File Access (#3769)
cschuchardt88 8af28d1
Update src/Neo/SmartContract/Native/PolicyContract.cs
shargon 2544d26
Merge branch 'master' into notary-assisted
AnnaShaleva 0785c0f
Merge branch 'master' into notary-assisted
shargon ee4232a
Merge branch 'master' into notary-assisted
AnnaShaleva 803d872
UnitTests: migrate NotaryAssisted test from MSTestV1 to MSTestV2
AnnaShaleva File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| // Copyright (C) 2015-2024 The Neo Project. | ||
| // | ||
| // NotaryAssisted.cs file belongs to the neo project and is free | ||
| // software distributed under the MIT software license, see the | ||
| // accompanying file LICENSE in the main directory of the | ||
| // repository or http://www.opensource.org/licenses/mit-license.php | ||
| // for more details. | ||
| // | ||
| // Redistribution and use in source and binary forms with or without | ||
| // modifications are permitted. | ||
|
|
||
| using Neo.IO; | ||
| using Neo.Json; | ||
| using Neo.Persistence; | ||
| using Neo.SmartContract.Native; | ||
| using System.IO; | ||
| using System.Linq; | ||
|
|
||
| namespace Neo.Network.P2P.Payloads | ||
| { | ||
| public class NotaryAssisted : TransactionAttribute | ||
| { | ||
| /// <summary> | ||
| /// Native Notary contract hash stub used until native Notary contract is properly implemented. | ||
| /// </summary> | ||
| private static readonly UInt160 notaryHash = UInt160.Parse("0xc1e14f19c3e60d0b9244d06dd7ba9b113135ec3b"); | ||
|
|
||
| /// <summary> | ||
| /// Indicates the number of keys participating in the transaction (main or fallback) signing process. | ||
| /// </summary> | ||
| public byte NKeys; | ||
|
|
||
| public override TransactionAttributeType Type => TransactionAttributeType.NotaryAssisted; | ||
|
|
||
| public override bool AllowMultiple => false; | ||
|
|
||
| public override int Size => base.Size + sizeof(byte); | ||
|
|
||
| protected override void DeserializeWithoutType(ref MemoryReader reader) | ||
| { | ||
| NKeys = reader.ReadByte(); | ||
| } | ||
|
|
||
| protected override void SerializeWithoutType(BinaryWriter writer) | ||
| { | ||
| writer.Write(NKeys); | ||
| } | ||
|
|
||
| public override JObject ToJson() | ||
| { | ||
| JObject json = base.ToJson(); | ||
| json["nkeys"] = NKeys; | ||
| return json; | ||
| } | ||
|
|
||
| public override bool Verify(DataCache snapshot, Transaction tx) | ||
AnnaShaleva marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| return tx.Signers.Any(p => p.Account.Equals(notaryHash)); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Calculates the network fee needed to pay for NotaryAssisted attribute. According to the | ||
| /// https://github.com/neo-project/neo/issues/1573#issuecomment-704874472, network fee consists of | ||
| /// the base Notary service fee per key multiplied by the expected number of transactions that should | ||
| /// be collected by the service to complete Notary request increased by one (for Notary node witness | ||
| /// itself). | ||
| /// </summary> | ||
| /// <param name="snapshot">The snapshot used to read data.</param> | ||
| /// <param name="tx">The transaction to calculate.</param> | ||
| /// <returns>The network fee of the NotaryAssisted attribute.</returns> | ||
| public override long CalculateNetworkFee(DataCache snapshot, Transaction tx) | ||
| { | ||
| return (NKeys + 1) * base.CalculateNetworkFee(snapshot, tx); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
tests/Neo.UnitTests/Network/P2P/Payloads/UT_NotaryAssisted.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| // Copyright (C) 2015-2024 The Neo Project. | ||
| // | ||
| // UT_NotaryAssisted.cs file belongs to the neo project and is free | ||
| // software distributed under the MIT software license, see the | ||
| // accompanying file LICENSE in the main directory of the | ||
| // repository or http://www.opensource.org/licenses/mit-license.php | ||
| // for more details. | ||
| // | ||
| // Redistribution and use in source and binary forms with or without | ||
| // modifications are permitted. | ||
|
|
||
| using FluentAssertions; | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
| using Neo.IO; | ||
| using Neo.Network.P2P.Payloads; | ||
| using Neo.SmartContract; | ||
| using Neo.SmartContract.Native; | ||
| using Neo.VM; | ||
| using System; | ||
|
|
||
| namespace Neo.UnitTests.Network.P2P.Payloads | ||
| { | ||
| [TestClass] | ||
| public class UT_NotaryAssisted | ||
| { | ||
| private static readonly UInt160 notaryHash = UInt160.Parse("0xc1e14f19c3e60d0b9244d06dd7ba9b113135ec3b"); | ||
|
|
||
| [TestMethod] | ||
| public void Size_Get() | ||
| { | ||
| var attr = new NotaryAssisted() { NKeys = 4 }; | ||
| attr.Size.Should().Be(1 + 1); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void ToJson() | ||
| { | ||
| var attr = new NotaryAssisted() { NKeys = 4 }; | ||
| var json = attr.ToJson().ToString(); | ||
| Assert.AreEqual(@"{""type"":""NotaryAssisted"",""nkeys"":4}", json); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void DeserializeAndSerialize() | ||
| { | ||
| var attr = new NotaryAssisted() { NKeys = 4 }; | ||
|
|
||
| var clone = attr.ToArray().AsSerializable<NotaryAssisted>(); | ||
| Assert.AreEqual(clone.Type, attr.Type); | ||
|
|
||
| // As transactionAttribute | ||
| byte[] buffer = attr.ToArray(); | ||
| var reader = new MemoryReader(buffer); | ||
| clone = TransactionAttribute.DeserializeFrom(ref reader) as NotaryAssisted; | ||
| Assert.AreEqual(clone.Type, attr.Type); | ||
|
|
||
| // Wrong type | ||
| buffer[0] = 0xff; | ||
| Assert.ThrowsException<FormatException>(() => | ||
| { | ||
| var reader = new MemoryReader(buffer); | ||
| TransactionAttribute.DeserializeFrom(ref reader); | ||
| }); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void Verify() | ||
| { | ||
| var attr = new NotaryAssisted() { NKeys = 4 }; | ||
|
|
||
| // Temporary use Notary contract hash stub for valid transaction. | ||
| var txGood = new Transaction { Signers = new Signer[] { new Signer() { Account = notaryHash } } }; | ||
| var txBad = new Transaction { Signers = new Signer[] { new Signer() { Account = UInt160.Parse("0xa400ff00ff00ff00ff00ff00ff00ff00ff00ff01") } } }; | ||
| var snapshot = TestBlockchain.GetTestSnapshot(); | ||
|
|
||
| Assert.IsTrue(attr.Verify(snapshot, txGood)); | ||
| Assert.IsFalse(attr.Verify(snapshot, txBad)); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void CalculateNetworkFee() | ||
| { | ||
| var snapshot = TestBlockchain.GetTestSnapshot(); | ||
| var attr = new NotaryAssisted() { NKeys = 4 }; | ||
| var tx = new Transaction { Signers = new Signer[] { new Signer() { Account = notaryHash } } }; | ||
|
|
||
| Assert.AreEqual((4 + 1) * 1000_0000, attr.CalculateNetworkFee(snapshot, tx)); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.