Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

SmartContract: restrict the number of allowed notifications #3548

Merged
merged 28 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
bcc5fd0
add hardofork HF_Echidna
Jim8y Aug 7, 2024
e63f10b
Add entries to `Designation` event (#3397)
shargon Aug 8, 2024
9d16c53
[Neo Core StdLib] Add Base64url (#3453)
Jim8y Aug 8, 2024
f746f8d
add hardofork HF_Echidna
Jim8y Aug 7, 2024
8d7f9e8
Add entries to `Designation` event (#3397)
shargon Aug 8, 2024
3fc8077
[Neo Core StdLib] Add Base64url (#3453)
Jim8y Aug 8, 2024
620d938
Merge branch 'HF_Echidna' of github.com:neo-project/neo into HF_Echidna
Jim8y Oct 2, 2024
b31d95e
SmartContract: restrict the number of allowed notifications
AnnaShaleva Oct 23, 2024
0c72e57
SmartContract: fix format
AnnaShaleva Oct 23, 2024
ee21427
Update src/Neo/SmartContract/ApplicationEngine.Runtime.cs
shargon Oct 23, 2024
4a6f36a
Avoid notification creation
shargon Oct 23, 2024
7e31d0c
add hardofork HF_Echidna
Jim8y Aug 7, 2024
993e3fe
Add entries to `Designation` event (#3397)
shargon Aug 8, 2024
37bf0cb
[Neo Core StdLib] Add Base64url (#3453)
Jim8y Aug 8, 2024
7dba130
format
Jim8y Nov 6, 2024
0457ccd
Merge branch 'HF_Echidna' of github.com:neo-project/neo into HF_Echidna
Jim8y Nov 6, 2024
d7a291e
Merge Master
cschuchardt88 Nov 17, 2024
6e780c0
Fixed typo
cschuchardt88 Nov 17, 2024
6fff362
Merge branch 'HF_Echidna' into restrict-notifications-count
cschuchardt88 Nov 17, 2024
02d6ab9
Added back #3397
cschuchardt88 Nov 17, 2024
4814339
Merge branch 'HF_Echidna' into restrict-notifications-count
cschuchardt88 Nov 17, 2024
9a657a5
fix format
cschuchardt88 Nov 17, 2024
e5e3b08
Merge branch 'master' into restrict-notifications-count
shargon Jan 24, 2025
f43f296
Update src/Neo/SmartContract/Native/RoleManagement.cs
shargon Jan 24, 2025
c309f63
Neo.CLI: revert configuration changes
AnnaShaleva Mar 3, 2025
f5a0482
Merge branch 'master' into restrict-notifications-count
shargon Mar 3, 2025
564a033
Merge branch 'master' into restrict-notifications-count
shargon Mar 4, 2025
3c40720
Merge branch 'master' into restrict-notifications-count
NGDAdmin Mar 5, 2025
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
3 changes: 2 additions & 1 deletion src/Neo.CLI/config.fs.mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"HF_Aspidochelone": 3000000,
"HF_Basilisk": 4500000,
"HF_Cockatrice": 5800000,
"HF_Domovoi": 5800000
"HF_Domovoi": 5800000,
"HF_Echidna": 5800001
Copy link
Member

Choose a reason for hiding this comment

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

@AnnaShaleva Should be removed from config

Copy link
Member

Choose a reason for hiding this comment

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

It comes from the branch change

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Will update.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

},
"StandbyCommittee": [
"026fa34ec057d74c2fdf1a18e336d0bd597ea401a0b2ad57340d5c220d09f44086",
Expand Down
3 changes: 2 additions & 1 deletion src/Neo.CLI/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"HF_Aspidochelone": 1730000,
"HF_Basilisk": 4120000,
"HF_Cockatrice": 5450000,
"HF_Domovoi": 5570000
"HF_Domovoi": 5570000,
"HF_Echidna": 5570001
},
"InitialGasDistribution": 5200000000000000,
"ValidatorsCount": 7,
Expand Down
3 changes: 2 additions & 1 deletion src/Neo.CLI/config.mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"HF_Aspidochelone": 1730000,
"HF_Basilisk": 4120000,
"HF_Cockatrice": 5450000,
"HF_Domovoi": 5570000
"HF_Domovoi": 5570000,
"HF_Echidna": 5570001
},
"InitialGasDistribution": 5200000000000000,
"ValidatorsCount": 7,
Expand Down
3 changes: 2 additions & 1 deletion src/Neo.CLI/config.testnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"HF_Aspidochelone": 210000,
"HF_Basilisk": 2680000,
"HF_Cockatrice": 3967000,
"HF_Domovoi": 4144000
"HF_Domovoi": 4144000,
"HF_Echidna": 4144001
},
"InitialGasDistribution": 5200000000000000,
"ValidatorsCount": 7,
Expand Down
14 changes: 13 additions & 1 deletion src/Neo/SmartContract/ApplicationEngine.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ partial class ApplicationEngine
/// </summary>
public const int MaxNotificationSize = 1024;

/// <summary>
/// The maximum number of notifications per application execution.
/// </summary>
public const int MaxNotificationCount = 512;

private uint random_times = 0;

/// <summary>
Expand Down Expand Up @@ -394,9 +399,16 @@ protected internal void RuntimeNotifyV1(byte[] eventName, Array state)
/// <param name="state">The arguments of the event.</param>
protected internal void SendNotification(UInt160 hash, string eventName, Array state)
{
notifications ??= new List<NotifyEventArgs>();
// Restrict the number of notifications for Application executions. Do not check
// persisting triggers to avoid native persist failure. Do not check verification
// trigger since verification context is loaded with ReadOnly flag.
if (IsHardforkEnabled(Hardfork.HF_Echidna) && Trigger == TriggerType.Application && notifications.Count >= MaxNotificationCount)
{
throw new InvalidOperationException($"Maximum number of notifications `{MaxNotificationCount}` is reached.");
}
NotifyEventArgs notification = new(ScriptContainer, hash, eventName, (Array)state.DeepCopy(asImmutable: true));
Notify?.Invoke(this, notification);
notifications ??= new List<NotifyEventArgs>();
notifications.Add(notification);
CurrentContext.GetState<ExecutionContextState>().NotificationCount++;
}
Expand Down
1 change: 1 addition & 0 deletions src/Neo/SmartContract/Native/RoleManagement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public ECPoint[] GetDesignatedByRole(DataCache snapshot, Role role, uint index)
}

[ContractMethod(CpuFee = 1 << 15, RequiredCallFlags = CallFlags.States | CallFlags.AllowNotify)]
[Obsolete]
private void DesignateAsRole(ApplicationEngine engine, Role role, ECPoint[] nodes)
{
if (nodes.Length == 0 || nodes.Length > 32)
Expand Down
4 changes: 2 additions & 2 deletions tests/Neo.UnitTests/SmartContract/Native/UT_NativeContract.cs

Large diffs are not rendered by default.

Loading