Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
9dd3146
Fix dBFT invalid transaction cache capacity and lifecycle
shargon Oct 30, 2026
8c7c295
Merge branch 'master-n3' into dbft-invalid-transactions-cache
shargon Oct 30, 2026
5307ccf
format
shargon Oct 30, 2026
566e923
Merge branch 'dbft-invalid-transactions-cache' of https://github.com/…
shargon Oct 30, 2026
e8c9768
Merge branch 'master-n3' into dbft-invalid-transactions-cache
ajara87 Nov 2, 2026
7e02b33
Merge branch 'master-n3' into dbft-invalid-transactions-cache
Wi1l-B0t Nov 7, 2026
c81848e
Merge branch 'master-n3' into dbft-invalid-transactions-cache
ajara87 Nov 8, 2026
4d7dfe8
Merge branch 'master-n3' into dbft-invalid-transactions-cache
superboyiii Nov 10, 2026
2eb5c38
Merge branch 'master-n3' into dbft-invalid-transactions-cache
superboyiii Nov 12, 2026
6d69d08
Merge branch 'master-n3' into dbft-invalid-transactions-cache
Wi1l-B0t Nov 14, 2026
34d5353
Merge branch 'master-n3' into dbft-invalid-transactions-cache
ajara87 Nov 20, 2026
65e90b0
Merge branch 'master-n3' into dbft-invalid-transactions-cache
shargon Nov 20, 2026
5c00265
Merge branch 'master-n3' into dbft-invalid-transactions-cache
shargon Nov 23, 2026
53b6730
Merge branch 'master-n3' into dbft-invalid-transactions-cache
ajara87 Nov 24, 2026
0f5574f
Merge branch 'master-n3' into dbft-invalid-transactions-cache
shargon Nov 24, 2026
bc38ed1
Keep rejected transactions cached across blocks
shargon Nov 25, 2026
b084bb7
Merge branch 'master-n3' into dbft-invalid-transactions-cache
shargon Nov 25, 2026
24f7f72
Merge branch 'master-n3' into dbft-invalid-transactions-cache
ajara87 Nov 27, 2026
09feb34
Merge branch 'master-n3' into dbft-invalid-transactions-cache
superboyiii Nov 27, 2026
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 plugins/DBFTPlugin/Consensus/ConsensusContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ public ConsensusContext(NeoSystem neoSystem, DbftSettings settings, ISigner sign
_signer = signer;
this.neoSystem = neoSystem;
dbftSettings = settings;
InvalidTransactions = new InvalidCache(neoSystem.Settings.MemoryPoolMaxTransactions);
// Reserve room for a full ChangeView message in addition to mempool rejection entries.
InvalidTransactions = new InvalidCache(checked(neoSystem.Settings.MemoryPoolMaxTransactions + ushort.MaxValue));

if (dbftSettings.IgnoreRecoveryLogs == false)
{
Expand Down
12 changes: 10 additions & 2 deletions plugins/DBFTPlugin/Consensus/ConsensusService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ internal partial class ConsensusService : UntypedActor
{
public class Start { }
private class Timer { public uint Height; public byte ViewNumber; }
private sealed record TransactionsRemoved(UInt256[] Hashes);

private readonly ConsensusContext context;
private readonly IActorRef localNode;
Expand Down Expand Up @@ -53,13 +54,15 @@ private class Timer { public uint Height; public byte ViewNumber; }
private bool isRecovering = false;
private readonly DbftSettings dbftSettings;
private readonly NeoSystem neoSystem;
private readonly IActorRef self;

public ConsensusService(NeoSystem neoSystem, DbftSettings settings, ISigner signer)
: this(neoSystem, settings, new ConsensusContext(neoSystem, settings, signer)) { }

internal ConsensusService(NeoSystem neoSystem, DbftSettings settings, ConsensusContext context)
{
this.neoSystem = neoSystem;
self = Self;
localNode = neoSystem.LocalNode;
taskManager = neoSystem.TaskManager;
blockchain = neoSystem.Blockchain;
Expand All @@ -78,8 +81,7 @@ private void MemPool_NewTransaction(object sender, NewTransactionEventArgs e)

private void MemPool_TransactionRemoved(object sender, TransactionRemovedEventArgs e)
{
foreach (var tx in e.Transactions)
context.InvalidTransactions.Remove(tx.Hash);
self.Tell(new TransactionsRemoved(e.Transactions.Select(tx => tx.Hash).ToArray()));
}

private void OnPersistCompleted(Block block)
Expand Down Expand Up @@ -141,6 +143,10 @@ protected override void OnReceive(object message)
if (!started) return;
switch (message)
{
case TransactionsRemoved removed:
foreach (var hash in removed.Hashes)
context.InvalidTransactions.Remove(hash);
break;
case Timer timer:
OnTimer(timer);
break;
Expand Down Expand Up @@ -401,6 +407,8 @@ protected override void PostStop()
{
DBFTPlugin.PluginLogger?.Information("ConsensusService stopped");
started = false;
neoSystem.MemPool.NewTransaction -= MemPool_NewTransaction;
neoSystem.MemPool.TransactionRemoved -= MemPool_TransactionRemoved;
Context.System.EventStream.Unsubscribe(Self);
context.Dispose();
base.PostStop();
Expand Down
43 changes: 43 additions & 0 deletions tests/Neo.Plugins.DBFTPlugin.Tests/UT_ChangeView.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (C) 2015-2026 The Neo Project.
//
// UT_ChangeView.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.Extensions;
using Neo.Plugins.DBFTPlugin.Messages;
using Neo.Plugins.DBFTPlugin.Types;

namespace Neo.Plugins.DBFTPlugin.Tests;

[TestClass]
public class UT_ChangeView
{
[TestMethod]
public void DeserializePreservesRejectedHashesLimit()
{
foreach (var reason in new[] { ChangeViewReason.TxInvalid, ChangeViewReason.TxRejectedByPolicy })
{
var message = new ChangeView { Reason = reason };
foreach (var count in new[] { 0, 1, 2, 65535, 65536 })
{
message.RejectedHashes = Enumerable.Repeat(UInt256.Zero, count).ToArray();
if (count <= ushort.MaxValue)
{
var decoded = (ChangeView)ConsensusMessage.DeserializeFrom(message.ToArray());
CollectionAssert.AreEqual(message.RejectedHashes, decoded.RejectedHashes);
}
else
{
Assert.ThrowsExactly<FormatException>(() => ConsensusMessage.DeserializeFrom(message.ToArray()));
}
}
}
}
}

33 changes: 33 additions & 0 deletions tests/Neo.Plugins.DBFTPlugin.Tests/UT_ConsensusService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,39 @@ private ExtensiblePayload CreateConsensusPayload(ConsensusMessage message)
};
}

[TestMethod]
public void InvalidTransactionsRetainExistingEntriesAfterFullChangeView()
{
using var context = new ConsensusContext(neoSystem, MockBlockchain.CreateDefaultSettings(), testWallet);
var originalHash = UInt256.Zero;
context.InvalidTransactions.Add(new ConsensusContext.InvalidTxCacheItem(originalHash, new HashSet<ECPoint>()));
int count = neoSystem.Settings.MemoryPoolMaxTransactions + ushort.MaxValue;
for (int i = 1; i < count; i++)
{
var bytes = new byte[32];
BitConverter.GetBytes(i).CopyTo(bytes, 0);
context.InvalidTransactions.Add(new ConsensusContext.InvalidTxCacheItem(new UInt256(bytes), new HashSet<ECPoint>()));
}
Assert.AreEqual(count, context.InvalidTransactions.Count);
Assert.IsTrue(context.InvalidTransactions.TryGet(originalHash, out _));
}

[TestMethod]
public void InvalidTransactionsSurviveViewChangesAndNewBlocks()
{
using var context = new ConsensusContext(neoSystem, MockBlockchain.CreateDefaultSettings(), testWallet);
context.Reset(0);
context.InvalidTransactions.Add(new ConsensusContext.InvalidTxCacheItem(UInt256.Zero,
context.Validators.Take(context.F + 1).ToHashSet()));
context.Reset(1);
Assert.IsTrue(context.InvalidTransactions.TryGet(UInt256.Zero, out var rejected));
Assert.IsTrue(rejected.Value.Count > context.F);
context.Reset(0);
Assert.IsTrue(context.InvalidTransactions.TryGet(UInt256.Zero, out _));
context.Reset(0);
Assert.IsTrue(context.InvalidTransactions.TryGet(UInt256.Zero, out _));
}

[TestMethod]
public void TestConsensusServiceCreation()
{
Expand Down