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

Remove the lock from SendersFeeMonitor and rename it to TransactionVerificationContext #1756

Merged
merged 13 commits into from
Jul 13, 2020

Conversation

erikzhang
Copy link
Member

No description provided.

@erikzhang
Copy link
Member Author

The UTs need to be fixed.

@Tommo-L
Copy link
Contributor

Tommo-L commented Jul 8, 2020

The UTs need to be fixed.

We'll fix the UT.

@shargon
Copy link
Member

shargon commented Jul 8, 2020

If we remove the lock we should close this (#1507) and add a comment that it's not thread safe

@Tommo-L
Copy link
Contributor

Tommo-L commented Jul 9, 2020

See #1759

@erikzhang
Copy link
Member Author

@neo-project/ngd-shanghai It needs to be tested.

@cloud8little
Copy link
Contributor

@neo-project/ngd-shanghai It needs to be tested.

I will have a test.
Test scenarios:

1.  Send single transaction neo/gas.
2.  Parallel send transaction(neo) when gas is sufficient & insufficient.
3.  Parallel send transaction(gas) when gas is sufficient & insufficient. 
4.  Parallel send transaction(neo) when neo is insufficient.

@cloud8little
Copy link
Contributor

cloud8little commented Jul 9, 2020

There is one issue needed to be investigated. When sending parallel tx, and somehow there are txs can not be relayed and stayed in the memory pool, then send valid tx will not either added in the mempool, or relay to the consensus node.

  1. Send single transaction neo/gas. PASSED
  2. Parallel send transaction(neo) when gas is sufficient & insufficient. PASSED
  3. Parallel send transaction(gas) when gas is sufficient & insufficient. PASSED
  4. Parallel send transaction(neo) when neo is insufficient. PASSED
  5. When mempool has tx, send valid tx. FAIL

@erikzhang
Copy link
Member Author

When mempool has tx, send valid tx. FAIL

How does this happen?

@cloud8little
Copy link
Contributor

When mempool has tx, send valid tx. FAIL

How does this happen?

Not sure how this happen, I am trying to reproduce it. Currently thought it maybe caused by two addresses in the account, and one with insufficient gas and one with enough gas, send massive gas at the same time(use sendtoaddress request).

@Tommo-L
Copy link
Contributor

Tommo-L commented Jul 9, 2020

I'll help investigate the problem tomorrow.

@cloud8little
Copy link
Contributor

When mempool has tx, send valid tx. FAIL

How does this happen?

  1. Prepare a wallet, here I use wallet_1.json, actually it is my CN wallet. with one standard address, one multisig address(m=1); initial asset is
neo> list asset
Nc56Zrq72VN9Xr6wo3HyFn3oFZUvoYQJtj
NEO: 49990000
GAS: 47.3869169

Ncu47NyTJLJPEFi859gmuqQ8fPPt1AVwHX
NEO: 50000000
GAS: 29930613.53667778

----------------------------------------------------
Total:   NEO: 99990000    GAS: 29930660.92359468

NEO hash: 0xde5f57d430d3dece511cf975a8d37848cb9e0525
GAS hash: 0x668e0c1f9d7b70a99dd9e06eadd4c784d641afbc
  1. use Jmeter to run parallel sendtoaddress requests;
{
  "jsonrpc": "2.0",
  "method": "sendtoaddress",
  "params": ["0x668e0c1f9d7b70a99dd9e06eadd4c784d641afbc", "NSJZ186oShqryg6D8xfcv5Te5GhQ8GFno9", 10.23456789],
  "id": 1
}

86c9b7e96c0f96e0ec0fb2f8bfe8be2

  1. when the requests are not finished yet, stop the task.
  2. then I getrawmempool from the node, there are 9 txs in the pool for my case.

4c9a2d36a930f7bfd4cf15b425808f6

List asset:
2e47914282b05b257e83569a6674147

  1. Then send a single sendtoaddress request to the node. From the debug process, MemPool.TryAdd always return Insufficient when deal with the sendtoaddress tx.
    f5c1d81b078d3c7aa63159d57e79437

1de66696c549cf5be2a801611ca58d8

@cloud8little
Copy link
Contributor

For comparison, use Neo without this PR, there is not such issue, when stop sending massive tx, tx in mempool can be sent successfully.

@Qiao-Jin
Copy link
Contributor

Qiao-Jin commented Jul 10, 2020

If we remove the lock we should close this (#1507) and add a comment that it's not thread safe

We don't need to close #1507, as balance checking is not done in parallel in this PR. #1507 only checks witness in parallel.

@shargon
Copy link
Member

shargon commented Jul 10, 2020

We don't need to close #1507, as balance checking is not done in parallel in this PR. #1507 only checks witness in parallel.

I see that it check that it's standard account, very nice!

@erikzhang
Copy link
Member Author

@cloud8little Please test it again.

@cloud8little
Copy link
Contributor

@cloud8little Please test it again.

Got it.

@Tommo-L
Copy link
Contributor

Tommo-L commented Jul 10, 2020

Then send a single sendtoaddress request to the node. From the debug process, MemPool.TryAdd always return Insufficient when deal with the sendtoaddress tx.

This is correct, it's insufficient, as there are 9 txs in mempool.

then I getrawmempool from the node, there are 9 txs in the pool for my case.

The 9 txs need to be rebroadcastet, but it takes a lot of time. This is still under confirmation.

Copy link
Member

@shargon shargon left a comment

Choose a reason for hiding this comment

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

The code looks well, waiting for @cloud8little

@cloud8little
Copy link
Contributor

cloud8little commented Jul 12, 2020

The code looks well, waiting for @cloud8little

There is still the issue, and initial balance is

Nc56Zrq72VN9Xr6wo3HyFn3oFZUvoYQJtj
NEO: 50000000
GAS: 60.3456922

Ncu47NyTJLJPEFi859gmuqQ8fPPt1AVwHX
NEO: 50000000
GAS: 29999870.8971756

after running massive sendtoaddress requests:
there are two txs stay in the mempool and can not added to the blockchain. call self-defined method to print the sender fee as below.
[Highlight part]
(TransactionVerificationContext.cs)

public void Print()
        {
            foreach(var item in senderFee)
            {
                Console.WriteLine("sender: " + item.Key + " fee: " + item.Value);
            }
        }

1eebc7dfb18df3171e6b528af8d4123

8d048fcc67b95bc59f764264ee475d9

Debug info:
d3ba53649e5181f4e831426ecae6a61

428f35223efe9d6980c6f1f3976ea6f

It can be rebroadcast,but can not added to the blockchain.

@erikzhang
Copy link
Member Author

Why they can't be added to blockchain?

@shargon
Copy link
Member

shargon commented Jul 12, 2020

@cloud8little could you try without this PR the same tests?

@cloud8little
Copy link
Contributor

cloud8little commented Jul 13, 2020

@cloud8little could you try without this PR the same tests?

Tried without this PR, with random sending massive tx and with the similar wallet asset configuration, out of 1/10+ times, there will be the same issue: one tx stay in the mempool and can not be broadcast.

e1098e2d90d9569fb713d79a1510384

Compare with this PR(about show up 1/4 times), the issue show up less, it is easier to show up in this PR.

Why they can't be added to blockchain?

Not very clear with this, only found the following lines can be touched. but there is no tx in CN node's mempool.

if (item.LastBroadcastTimestamp < rebroadcastCutOffTime)
{
_system.LocalNode.Tell(new LocalNode.RelayDirectly { Inventory = item.Tx }, _system.Blockchain);
item.LastBroadcastTimestamp = DateTime.UtcNow;
}

@shargon
Copy link
Member

shargon commented Jul 13, 2020

Then I think that it's not related to this PR, we can merge it, and open a new issue

@shargon
Copy link
Member

shargon commented Jul 13, 2020

It's possible that this node have this tx in knownHashes but it removed this tx from his memory pool?

@erikzhang
Copy link
Member Author

erikzhang commented Jul 13, 2020

It's possible that this node have this tx in knownHashes but it removed this tx from his memory pool?

That's it! The transactions are removed by MemoryPool.RemoveOverCapacity(), but they are still in knownHashes.

private List<Transaction> RemoveOverCapacity()
{
List<Transaction> removedTransactions = new List<Transaction>();
do
{
PoolItem minItem = GetLowestFeeTransaction(out var unsortedPool, out var sortedPool);
unsortedPool.Remove(minItem.Tx.Hash);
sortedPool.Remove(minItem);
removedTransactions.Add(minItem.Tx);
} while (Count > Capacity);
return removedTransactions;
}

@erikzhang
Copy link
Member Author

I will merge this PR first.

@erikzhang erikzhang merged commit 54784e0 into master Jul 13, 2020
@erikzhang erikzhang deleted the remove-lock branch July 13, 2020 11:21
shargon added a commit that referenced this pull request Jul 22, 2020
* Allow call from native contract (#1700)

* Fix MethodCallback (#1723)

* Fix #1714 (#1715)

* Add base64 SYSCALLs (#1717)

* Neo.VM.3.0.0-CI00230 (#1725)

* Allow to iterate buffer (#1726)

* Buffer iterator

* Rename

* Remove using

Co-authored-by: Erik Zhang <[email protected]>

* Update StorageContext.cs (#1728)

StorageContext needs to be public so it can be accessed by Neo Debugger

Co-authored-by: Erik Zhang <[email protected]>

* Fix return value check (#1730)

Co-authored-by: Shargon <[email protected]>

* Fix ContractEventDescriptor (#1733)

* fix enumerator (#1744)

Co-authored-by: Tommo-L <[email protected]>

* Change json fields to all lower case for consistency (#1736)

* Replace DataCache.Find by DataCache.Seek (#1740)

* replace DataCache.Find by DataCache.Seek

* fix order

* optimize

* Update ByteArrayComparer.cs

* Update ByteArrayComparer.cs

* Update DataCache.cs

* fix comments

* fix comments

* fix comments

* Update DataCache.cs

* Update DataCache.cs

* Reorder methods

Co-authored-by: Tommo-L <[email protected]>
Co-authored-by: erikzhang <[email protected]>
Co-authored-by: Shargon <[email protected]>

* Add MaxVerificationGas (#1745)

Co-authored-by: Shargon <[email protected]>

* Create KeyBuilder (#1748)

* Speed up the initialization of ApplicationEngine. (#1749)

* Change nef checksum to double SHA256 (#1751)

* Change to double SHA256

* Clean code

* Revert change

* Clean code

* Fix checksum

* Update NefFile.cs

* Fix compile

* Clean code

Clean code
Fix checksum
Update NefFile.cs
Fix compile

* Optimize

* Optimize

* Fix

Co-authored-by: erikzhang <[email protected]>

* Check witnesses on isStandard (#1754)

* Check witness on isStandard

* Add IsDeployed

* Add IsPayable

* Fix UT

* format

* Add coverage

* Remove IsPayable, IsDeployed

* Move NEP10 to manifest (#1729)

* NEP10 abi

* To lower case

* Move to Manifest

* Clean code

* Update ContractManifest.cs

* Update ContractManifest.cs

* Fix native contracts

Co-authored-by: Erik Zhang <[email protected]>

* Capture fault Exception (#1761)

* Capture faultException

* Update Wallet error

* Remove flag check

* Clean code

* Sender from signers (#1752)

* Sender from signers

* Remove co-

* Move signers outside attributes

* Fix UT and remove Signers class

* Fix UT

* Add FeeOnly scope

* Remove orderBy

* Remove _signersCache

* Fix Signers

* Fix WitnessScope

* Fix Sender

* Update TransactionAttributeType.cs

* Update Wallet.cs

* Fix Wallet

* Rename

* Update Wallet.cs

* Update Wallet.cs

* Partial UT fix

* More UT fixes

* Fix Sender's WitnessScope

* Fix Wallet

* Fix UT

* Explicit FeeOnly for DeployNativeContracts

* Same order as serialization

* Test FeeOnly

* dotnet format

* format

Co-authored-by: Erik Zhang <[email protected]>

* IApplicationEngineProvider (#1758)

* Remove the lock from SendersFeeMonitor and rename it to TransactionVerificationContext (#1756)

* Add EffectiveVoterTurnout (#1762)

* Remove AllowedTriggers from SYSCALLs (#1755)

* fix validatorscount (#1770)

Co-authored-by: Tommo-L <[email protected]>

* impl SeekInternal

Co-authored-by: Erik Zhang <[email protected]>
Co-authored-by: Shargon <[email protected]>
Co-authored-by: Harry Pierson <[email protected]>
Co-authored-by: Luchuan <[email protected]>
Co-authored-by: Tommo-L <[email protected]>
Co-authored-by: joeqian <[email protected]>
shargon added a commit that referenced this pull request Jul 23, 2020
* Allow call from native contract (#1700)

* Fix MethodCallback (#1723)

* Fix #1714 (#1715)

* Add base64 SYSCALLs (#1717)

* Neo.VM.3.0.0-CI00230 (#1725)

* Allow to iterate buffer (#1726)

* Buffer iterator

* Rename

* Remove using

Co-authored-by: Erik Zhang <[email protected]>

* Update StorageContext.cs (#1728)

StorageContext needs to be public so it can be accessed by Neo Debugger

Co-authored-by: Erik Zhang <[email protected]>

* Fix return value check (#1730)

Co-authored-by: Shargon <[email protected]>

* Fix ContractEventDescriptor (#1733)

* fix enumerator (#1744)

Co-authored-by: Tommo-L <[email protected]>

* Change json fields to all lower case for consistency (#1736)

* Replace DataCache.Find by DataCache.Seek (#1740)

* replace DataCache.Find by DataCache.Seek

* fix order

* optimize

* Update ByteArrayComparer.cs

* Update ByteArrayComparer.cs

* Update DataCache.cs

* fix comments

* fix comments

* fix comments

* Update DataCache.cs

* Update DataCache.cs

* Reorder methods

Co-authored-by: Tommo-L <[email protected]>
Co-authored-by: erikzhang <[email protected]>
Co-authored-by: Shargon <[email protected]>

* Add MaxVerificationGas (#1745)

Co-authored-by: Shargon <[email protected]>

* Create KeyBuilder (#1748)

* Speed up the initialization of ApplicationEngine. (#1749)

* Change nef checksum to double SHA256 (#1751)

* Change to double SHA256

* Clean code

* Revert change

* Clean code

* Fix checksum

* Update NefFile.cs

* Fix compile

* Clean code

Clean code
Fix checksum
Update NefFile.cs
Fix compile

* Optimize

* Optimize

* Fix

Co-authored-by: erikzhang <[email protected]>

* Check witnesses on isStandard (#1754)

* Check witness on isStandard

* Add IsDeployed

* Add IsPayable

* Fix UT

* format

* Add coverage

* Remove IsPayable, IsDeployed

* Move NEP10 to manifest (#1729)

* NEP10 abi

* To lower case

* Move to Manifest

* Clean code

* Update ContractManifest.cs

* Update ContractManifest.cs

* Fix native contracts

Co-authored-by: Erik Zhang <[email protected]>

* Capture fault Exception (#1761)

* Capture faultException

* Update Wallet error

* Remove flag check

* Clean code

* Sender from signers (#1752)

* Sender from signers

* Remove co-

* Move signers outside attributes

* Fix UT and remove Signers class

* Fix UT

* Add FeeOnly scope

* Remove orderBy

* Remove _signersCache

* Fix Signers

* Fix WitnessScope

* Fix Sender

* Update TransactionAttributeType.cs

* Update Wallet.cs

* Fix Wallet

* Rename

* Update Wallet.cs

* Update Wallet.cs

* Partial UT fix

* More UT fixes

* Fix Sender's WitnessScope

* Fix Wallet

* Fix UT

* Explicit FeeOnly for DeployNativeContracts

* Same order as serialization

* Test FeeOnly

* dotnet format

* format

Co-authored-by: Erik Zhang <[email protected]>

* IApplicationEngineProvider (#1758)

* Remove the lock from SendersFeeMonitor and rename it to TransactionVerificationContext (#1756)

* Add EffectiveVoterTurnout (#1762)

* Remove AllowedTriggers from SYSCALLs (#1755)

* fix validatorscount (#1770)

Co-authored-by: Tommo-L <[email protected]>

* workflows: use checkout action v2 (#1775)

* Update git workflow

* Update .github/workflows/main.yml

Co-authored-by: Erik Zhang <[email protected]>

Co-authored-by: Erik Zhang <[email protected]>

* Add cache to native contract executions V2 (#1766)

* cache v2

* More optimizations

* Policy contract optimization

* Remove interporable variable

* Two more

* Add Set

* Optimizations

* Optimize

Co-authored-by: erikzhang <[email protected]>

* Optimize attributes (#1774)

* Add length before compression data (#1768)

* Add length before compression

* Optimize

* Fix UT

* Add UT

* Add UT

Co-authored-by: erikzhang <[email protected]>

* Fix VerifyWitnesses (#1776)

* Ensure non predictable peers (#1739)

* Plugins from List to array

* Move false to init

* Fix UT

* Refactor

* Add Exception Message For CreateContract (#1787)

* Add Exception Message When Create Contract

* Add Exception Message

* Code optimization

* add UT

Co-authored-by: Shargon <[email protected]>
Co-authored-by: Qiao Jin <[email protected]>

Co-authored-by: Erik Zhang <[email protected]>
Co-authored-by: Shargon <[email protected]>
Co-authored-by: Harry Pierson <[email protected]>
Co-authored-by: Luchuan <[email protected]>
Co-authored-by: Tommo-L <[email protected]>
Co-authored-by: joeqian <[email protected]>
Co-authored-by: cloud8little <[email protected]>
Co-authored-by: Qiao Jin <[email protected]>
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.

6 participants