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

Payloads: implement Conflicts attribute #2818

Merged
merged 27 commits into from
Sep 4, 2023

Conversation

AnnaShaleva
Copy link
Member

Closes #1991. Partially based on #2661, but verification-related logic is refactored to match the initial behaviour design.

Depends on #2812.

@Jim8y
Copy link
Contributor

Jim8y commented Mar 4, 2023

@shargon @AnnaShaleva This pr is in 3.6 list, may you please update and review it.

Comment on lines 481 to 494
var persisted = block.Transactions.Select(t => t.Hash);
var stale = new List<UInt256>();
foreach (var item in _sortedTransactions)
{
if (conflicts.Contains(item.Tx.Hash) || item.Tx.GetAttributes<Conflicts>().Select(a => a.Hash).Intersect(persisted).Count() > 0)
{
stale.Add(item.Tx.Hash);
conflictingItems.Add(item.Tx);
}
}
foreach (var h in stale)
{
if (!TryRemoveVerified(h, out _)) TryRemoveUnVerified(h, out _);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

IIRC LINQ is somewhat slower, but I'm OK either way. @shargon?

src/Neo/Ledger/MemoryPool.cs Outdated Show resolved Hide resolved
src/Neo/Ledger/TransactionVerificationContext.cs Outdated Show resolved Hide resolved
AnnaShaleva added a commit to AnnaShaleva/neo that referenced this pull request Mar 9, 2023
AnnaShaleva added a commit to AnnaShaleva/neo that referenced this pull request Mar 9, 2023
@AnnaShaleva AnnaShaleva requested review from shargon, roman-khimov and Jim8y and removed request for shargon, roman-khimov and Jim8y March 9, 2023 11:28
@AnnaShaleva
Copy link
Member Author

Rebased onto current master, ready for review.

@AnnaShaleva
Copy link
Member Author

AnnaShaleva commented Apr 6, 2023

@shargon, @Liaojinghui, @vncoelho, let's review this PR one more time and move on with it, the previously added conversations are fixed.

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.

I am reviewing again, can you clarify the trimmed a little bit more to me?

@AnnaShaleva
Copy link
Member Author

can you clarify the trimmed a little bit more

Sure. Consider the situation when transaction A has the Conflicts attribute with hash of transaction B specified inside this attribute. Consider the transaction A is being accepted to the chain in some block whereas transaction B is not pooled to the network yet. Then the transaction A should be stored in the DB/Ledger contract in a common way. Along with that, we extract the B's hash from the Conflicts attribute of transaction A and do store the "dummy" transaction B inside the DB/Ledger contract. It is done to prevent transaction B from being included into one of the subsequent blocks since transaction B conflicts with transaction A. Note that the only thing we know about transaction B is its hash. But how do we store the transaction B if we know only its hash? We use Trimmed field for that. Basically, the Trimmed field means that there's only transaction's hash is being stored.

@AnnaShaleva AnnaShaleva requested a review from Jim8y April 6, 2023 14:44
@AnnaShaleva
Copy link
Member Author

AnnaShaleva commented Aug 24, 2023

@shargon, take a look at the latest commit, please. Turns out I've accidentally missed this patch when I was fixing our #2818 (comment) conversation. This patch should be a part of fd1748d commit actually (and I did all the things right in NeoGo in nspcc-dev/neo-go@ee4b8f8#diff-aec93d55c952fa59b011c31e50ccae3fb3303260537d58df6a70309bb94af622R551-R560).

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
@AnnaShaleva
Copy link
Member Author

AnnaShaleva commented Aug 24, 2023

@shargon, take a look at the test, please: b6856ff. I've adjusted it, the idea is to persist conflicting tx1 with malicious signer on chain and after that to pool the original tx2 (with different signer), we expect it to be pooled successfully. But I can't properly organize the test, I've got InsufficientFunds while adding tx2 (it's not connected with Conflicts logic, I just don't know how to add enough GAS to the tx2 sender account).

@AnnaShaleva is this UT or a similar one added?

BTW, this scenario was tested by @superboyiii, IINM, it was passed OK. And we have a set of tests in NeoGo testing that on-chain conflicts work as expected, see the tests added in nspcc-dev/neo-go@ee4b8f8#diff-aec93d55c952fa59b011c31e50ccae3fb3303260537d58df6a70309bb94af622R551-R560.

@cschuchardt88
Copy link
Member

cschuchardt88 commented Aug 27, 2023

I just don't know how to add enough GAS to the tx2 sender account).

Check out for adding gas lines 46 to 51

var key = new KeyBuilder(NativeContract.GAS.Id, 20).Add(acc.ScriptHash);

Move it to the UT_Blockchain.cs file and refactor it a bit to make it
actually pass as expected.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
@AnnaShaleva
Copy link
Member Author

AnnaShaleva commented Aug 28, 2023

@shargon, I've managed to fix the InsuficientFunds error in Malicious_OnChain_Conflict, please, see the updated test. Now it passes as expected.

@superboyiii
Copy link
Member

If this PR can't be merged before 4th Sep, we will release v3.6.0 directly. Too much time for waiting. We can add this to v3.7.0.
https://github.com/orgs/neo-project/teams/core @vncoelho @roman-khimov @AnnaShaleva @Liaojinghui @shargon @devhawk

@AnnaShaleva
Copy link
Member Author

It’s ready for review, all issues are fixed.

src/Neo/Network/P2P/Payloads/Conflicts.cs Show resolved Hide resolved
src/Neo/Ledger/MemoryPool.cs Outdated Show resolved Hide resolved
@superboyiii
Copy link
Member

@shargon Need your merge.

@Jim8y Jim8y dismissed vncoelho’s stale review September 4, 2023 02:16

No change need to make and need to perpare for merge

@shargon shargon merged commit 6398801 into neo-project:master Sep 4, 2023
1 check passed
superboyiii added a commit to neo-project/neo-modules that referenced this pull request Sep 5, 2023
* DBFTPlugin: adapt Conflicts attribute verification

Depends on neo-project/neo#2818, see the
neo-project/neo#2818 (comment).

Signed-off-by: Anna Shaleva <anna@nspcc.ru>

* Fix Conflicts attribute verification

Fetch the update from core: neo-project/neo#2818 (comment).

* Fetch on-chain conflict signer fix from core

Use new API from neo-project/neo@ee7333f.

---------

Signed-off-by: Anna Shaleva <anna@nspcc.ru>
Co-authored-by: Vitor Nazário Coelho <vncoelho@gmail.com>
Co-authored-by: Owen Zhang <38493437+superboyiii@users.noreply.github.com>
Co-authored-by: Jimmy <jinghui@wayne.edu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Conflicts" transaction attribute type
7 participants