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 native Notary contract #3178

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
6da4ae2
Implement NotaryAssisted transaction attribute
AnnaShaleva Mar 6, 2024
acec1b0
Payloads: add doc to CalculateNetworkFee method of NotaryAssisted att…
AnnaShaleva Mar 6, 2024
1508d4f
Native: add NotaryAssisted attributes handler to Gas OnPersist
AnnaShaleva Mar 7, 2024
8b547c9
Payloads: adjust comment to NotaryAssisted attribute
AnnaShaleva Mar 7, 2024
b16a28c
Payloads: temporary use hard-coded Notary contract hash
AnnaShaleva Mar 7, 2024
00b54ff
Merge branch 'master' into notary-assisted
Jim8y Mar 8, 2024
24135ff
Payloads: replace hard-coded Notary hash value with calculated one
AnnaShaleva Mar 12, 2024
77ffe09
Native: implement native Notary contract
AnnaShaleva Mar 19, 2024
cb4bdda
Native: fix typo in the exception message
AnnaShaleva Mar 21, 2024
8f9f5f7
Native: use more syntactic sugar
AnnaShaleva Mar 21, 2024
5ee1855
Merge branch 'master' into notary-contract
Jim8y Mar 26, 2024
02c6a89
Notary: add unit tests for OnNEP17Payment and ExpirationOf methods
AnnaShaleva Apr 4, 2024
21f5fcf
Fix transfer
shargon Apr 8, 2024
af4a87a
Merge branch 'master' into notary-contract
shargon Apr 8, 2024
e8d384e
Update tests/Neo.UnitTests/SmartContract/Native/UT_Notary.cs
shargon Apr 8, 2024
26c9430
Update UT_Notary.cs
shargon Apr 8, 2024
b23859f
fix
shargon Apr 8, 2024
ecfba77
Merge branch 'notary-contract' of https://github.com/neo-project/neo …
shargon Apr 8, 2024
ff03214
Fix notary
shargon Apr 8, 2024
adf0bb0
Fix notary
shargon Apr 8, 2024
08da1f0
Notary: add unit tests for LockDepositUntil and BalanceOf methods
AnnaShaleva Apr 8, 2024
f7924ca
Merge branch 'master' into notary-contract
AnnaShaleva Apr 10, 2024
6705469
Notary: test GAS distribution with FeePerKey update
AnnaShaleva Apr 10, 2024
8864ff5
Notary: add test for Withdraw
AnnaShaleva Apr 10, 2024
498f2ff
Notary: remove unused code
AnnaShaleva Apr 11, 2024
efa9958
Attributtes: fix NotaryAssisted attribute documentation format
AnnaShaleva Apr 11, 2024
dd0b965
Merge branch 'master' into notary-contract
cschuchardt88 Apr 11, 2024
f6cbd36
Merge branch 'master' into notary-contract
cschuchardt88 May 23, 2024
deafea9
Native: update to the fresh master
AnnaShaleva May 23, 2024
2f1d38c
Merge branch 'master' into notary-contract
shargon May 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Neo.CLI/CLI/MainService.Blockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ public void OnShowTransactionCommand(UInt256 hash)
ConsoleHelper.Info("", " Type: ", $"{n.Type}");
ConsoleHelper.Info("", " Height: ", $"{n.Height}");
break;
case NotaryAssisted n:
ConsoleHelper.Info("", " Type: ", $"{n.Type}");
ConsoleHelper.Info("", " NKeys: ", $"{n.NKeys}");
break;
default:
ConsoleHelper.Info("", " Type: ", $"{attribute.Type}");
ConsoleHelper.Info("", " Size: ", $"{attribute.Size} Byte(s)");
Expand Down
71 changes: 71 additions & 0 deletions src/Neo/Network/P2P/Payloads/NotaryAssisted.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// 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>
/// 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)
{
return tx.Signers.Any(p => p.Account.Equals(NativeContract.Notary.Hash));
}

/// <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);
}
}
}
8 changes: 7 additions & 1 deletion src/Neo/Network/P2P/Payloads/TransactionAttributeType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ public enum TransactionAttributeType : byte
/// Indicates that the transaction conflicts with <see cref="Conflicts.Hash"/>.
/// </summary>
[ReflectionCache(typeof(Conflicts))]
Conflicts = 0x21
Conflicts = 0x21,

/// <summary>
/// Indicates that the transaction uses notary request service with <see cref="NotaryAssisted.NKeys"/> number of keys.
/// </summary>
[ReflectionCache(typeof(NotaryAssisted))]
NotaryAssisted = 0x22
}
}
8 changes: 8 additions & 0 deletions src/Neo/SmartContract/Native/GasToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ internal override async ContractTask OnPersistAsync(ApplicationEngine engine)
{
await Burn(engine, tx.Sender, tx.SystemFee + tx.NetworkFee);
totalNetworkFee += tx.NetworkFee;

// Reward for NotaryAssisted attribute will be minted to designated notary nodes
// by Notary contract.
var notaryAssisted = tx.GetAttribute<NotaryAssisted>();
if (notaryAssisted is not null)
{
totalNetworkFee -= (notaryAssisted.NKeys + 1) * Policy.GetAttributeFee(engine.Snapshot, (byte)notaryAssisted.Type);
AnnaShaleva marked this conversation as resolved.
Show resolved Hide resolved
}
}
ECPoint[] validators = NEO.GetNextBlockValidators(engine.Snapshot, engine.ProtocolSettings.ValidatorsCount);
UInt160 primary = Contract.CreateSignatureRedeemScript(validators[engine.PersistingBlock.PrimaryIndex]).ToScriptHash();
Expand Down
5 changes: 5 additions & 0 deletions src/Neo/SmartContract/Native/NativeContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ public CacheEntry GetAllowedMethods(NativeContract native, ApplicationEngine eng
/// </summary>
public static OracleContract Oracle { get; } = new();

/// <summary>
/// Gets the instance of the <see cref="Notary"/> class.
/// </summary>
public static Notary Notary { get; } = new();

#endregion

/// <summary>
Expand Down
Loading
Loading