mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-05-05 23:55:11 +00:00
core: don't search through the whole DAO in isTxStillRelevant
New transactions are added to the chain with blocks. If there is no transaction X at height N in DAO, it could only be added with block N+1, so it has to be present there. Therefore we can replace `dao.HasTransaction()` check with a search through in-block transactions. HasTransaction() is nasty in that it may add useless load the DB and this code is being run with a big Blockchain lock held, so we don't want to be delayed here at all. Improves single-node TPS by ~2%.
This commit is contained in:
parent
3a379e4f3e
commit
c7032022f8
2 changed files with 46 additions and 10 deletions
|
@ -402,6 +402,34 @@ func TestVerifyHashAgainstScript(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestMemPoolRemoval(t *testing.T) {
|
||||
const added = 16
|
||||
const notAdded = 32
|
||||
bc := newTestChain(t)
|
||||
defer bc.Close()
|
||||
addedTxes := make([]*transaction.Transaction, added)
|
||||
notAddedTxes := make([]*transaction.Transaction, notAdded)
|
||||
for i := range addedTxes {
|
||||
addedTxes[i] = bc.newTestTx(testchain.MultisigScriptHash(), []byte{byte(opcode.PUSH1)})
|
||||
require.NoError(t, signTx(bc, addedTxes[i]))
|
||||
require.NoError(t, bc.PoolTx(addedTxes[i]))
|
||||
}
|
||||
for i := range notAddedTxes {
|
||||
notAddedTxes[i] = bc.newTestTx(testchain.MultisigScriptHash(), []byte{byte(opcode.PUSH1)})
|
||||
require.NoError(t, signTx(bc, notAddedTxes[i]))
|
||||
require.NoError(t, bc.PoolTx(notAddedTxes[i]))
|
||||
}
|
||||
b := bc.newBlock(addedTxes...)
|
||||
require.NoError(t, bc.AddBlock(b))
|
||||
mempool := bc.GetMemPool()
|
||||
for _, tx := range addedTxes {
|
||||
require.False(t, mempool.ContainsKey(tx.Hash()))
|
||||
}
|
||||
for _, tx := range notAddedTxes {
|
||||
require.True(t, mempool.ContainsKey(tx.Hash()))
|
||||
}
|
||||
}
|
||||
|
||||
func TestHasBlock(t *testing.T) {
|
||||
bc := newTestChain(t)
|
||||
blocks, err := bc.genBlocks(50)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue