Skip to content

Remove invalid transactions from PrepareRequest payload#984

Merged
superboyiii merged 4 commits intoneo-project:master-n3from
erikzhang:remove-invalid-tx
Jan 27, 2026
Merged

Remove invalid transactions from PrepareRequest payload#984
superboyiii merged 4 commits intoneo-project:master-n3from
erikzhang:remove-invalid-tx

Conversation

@erikzhang
Copy link
Member

If the policy configurations among consensus nodes are inconsistent (e.g., MaxBlockSize or MaxBlockSystemFee), it may lead to some invalid transactions being persistently retained in some consensus nodes, preventing block creation. A mechanism is needed to ensure that when a transaction is identified as invalid by more than F consensus nodes, all consensus nodes will refrain from including that transaction in the PrepareRequest payload.

@github-actions github-actions bot added the N3 label Jan 23, 2026
@coveralls
Copy link

coveralls commented Jan 23, 2026

Pull Request Test Coverage Report for Build 21316142171

Details

  • 3 of 36 (8.33%) changed or added relevant lines in 5 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.07%) to 38.907%

Changes Missing Coverage Covered Lines Changed/Added Lines %
plugins/DBFTPlugin/Consensus/ConsensusContext.MakePayload.cs 0 4 0.0%
plugins/DBFTPlugin/Consensus/ConsensusService.cs 1 9 11.11%
plugins/DBFTPlugin/Consensus/ConsensusService.OnMessage.cs 0 9 0.0%
plugins/DBFTPlugin/Messages/ChangeView.cs 1 13 7.69%
Files with Coverage Reduction New Missed Lines %
plugins/DBFTPlugin/Messages/ChangeView.cs 1 24.24%
Totals Coverage Status
Change from base Build 21311977432: -0.07%
Covered Lines: 7079
Relevant Lines: 16868

💛 - Coveralls

Copy link

@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.

  1. Consistent policy configuration can be achieved via Policy contract.
  2. Node disputes are to be resolved via CV, some other node will propose something acceptable. Bad primaries are to de-elected.
  3. Nodes directly telling other nodes what's right or wrong doesn't seem reliable, we need BFT number of them following the protocol, that's it.

@shargon
Copy link
Member

shargon commented Jan 23, 2026

  1. Consistent policy configuration can be achieved via Policy contract.
  2. Node disputes are to be resolved via CV, some other node will propose something acceptable. Bad primaries are to de-elected.
  3. Nodes directly telling other nodes what's right or wrong doesn't seem reliable, we need BFT number of them following the protocol, that's it.

But currently they will change view forever and de-election is not something automatically, require vote changing

@roman-khimov
Copy link

But currently they will change view forever

Why? Node A proposes "bad" tx T, CV happens, node B proposes another set of transactions without T, everyone agrees (no policy conflict), block produced.

@erikzhang
Copy link
Member Author

If the transaction is still in the memory pool, A will submit this transaction in each round.

@roman-khimov
Copy link

If the transaction is still in the memory pool, A will submit this transaction in each round.

Yes. And it's not a problem to me. This (incorrect Primary) can be discovered quickly and either configuration will be fixed or node will be voted out. Otherwise policies are for Policy contract, it has (almost) all the mechanisms for that.

@erikzhang
Copy link
Member Author

I would not call it "incorrect." The policy for each node may differ and may not necessarily be correct or incorrect. Therefore, we need a mechanism to intersect the policy of each node when more than F nodes are inconsistent, in order to enhance the stability of the consensus protocol.

@roman-khimov
Copy link

The policy for each node may differ and may not necessarily be correct or incorrect.

As long as BFT number of nodes agree we're OK. If we're to imagine each node doing local policing of any kind we're in trouble and this PR can't fix it. A node can have a policy of always using 42 as block nonce and rejecting any other proposals for example.

we need a mechanism to intersect the policy

The mechanism for that is CV. Just like in any other case where agreement can't be reach for the current proposal (or proposal is missing).

{
case ChangeViewReason.TxRejectedByPolicy:
case ChangeViewReason.TxInvalid:
RejectedHashes = reader.ReadSerializableArray<UInt256>(ushort.MaxValue);
Copy link
Member

@shargon shargon Jan 23, 2026

Choose a reason for hiding this comment

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

If it's the end of the stream we should deserialize as empty, or we will be incompatible with other nodes (hardfork)

Copy link
Member Author

Choose a reason for hiding this comment

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

Currently, there is no way to determine if the MemoryReader has reached the end of the data. Modifying the MemoryReader would require releasing a new version of Neo. Therefore, we will not make any changes for now and will release the update with the next version. This only involves modifications to the consensus protocol and will not result in a hard fork.

Copy link
Member

@vncoelho vncoelho left a comment

Choose a reason for hiding this comment

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

This is related to neo-project/neo#4333

It is needed

// Iterate transaction until reach the size or maximum system fee
foreach (Transaction tx in txs)
{
if (InvalidTransactions.TryGetValue(tx.Hash, out var hashset))
Copy link
Member

Choose a reason for hiding this comment

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

Add some comment

// Verify if there is, at least, one honest node that consider this TX as invalid. If so, skip it.

Copy link
Member Author

Choose a reason for hiding this comment

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

One is not enough; at least more than F are needed.

Copy link
Member

Choose a reason for hiding this comment

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

That means one honest

Copy link
Member

@vncoelho vncoelho left a comment

Choose a reason for hiding this comment

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

LGTM

@superboyiii superboyiii merged commit 1a9f049 into neo-project:master-n3 Jan 27, 2026
5 checks passed
@erikzhang erikzhang deleted the remove-invalid-tx branch January 27, 2026 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants