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

txpool: where those missing transactions go? #1031

Closed
jangko opened this issue Apr 3, 2022 · 2 comments
Closed

txpool: where those missing transactions go? #1031

jangko opened this issue Apr 3, 2022 · 2 comments

Comments

@jangko
Copy link
Contributor

jangko commented Apr 3, 2022

using the same setup as test_txpool2, below code failed.
the recipient, amount and sender of those transaction are identical. they only differ in the tx nonce. but looks like some of the transaction cannot reach destination block.

var
    env = initEnv(some(100.u256))
    xp = env.xp
    chainDB = env.chainDB
    chain = env.chain
    head = chainDB.getCanonicalHead()
    timestamp = head.timestamp

  const
    txPerblock = 20
    numBlocks = 10

  for n in 0..<numBlocks:
    for tn in 0..<txPerblock:
      let tx = env.makeTx(recipient, amount)
      let res = xp.addLocal(tx, force = true)
      if res.isErr:
        debugEcho res.error
        return

    xp.jobCommit()
    xp.prevRandao = prevRandao
    var blk = xp.ethBlock()
    doAssert chain.isBlockAfterTtd(blk.header)

    timestamp = timestamp + 1.seconds
    blk.header.difficulty = DifficultyInt.zero
    blk.header.prevRandao = prevRandao
    blk.header.nonce = default(BlockNonce)
    blk.header.extraData = @[]
    blk.header.timestamp = timestamp

    let body = BlockBody(
       transactions: blk.txs,
       uncles: blk.uncles
    )

    let rr = chain.persistBlocks([blk.header], [body])
    doAssert rr == ValidationResult.OK

    # PoS block canonical head must be explicitly set using setHead
    chainDB.setHead(blk.header)

    discard xp.jobDeltaTxsHead(blk.header)
    xp.head = blk.header
    xp.jobCommit()

  doAssert chainDB.currentBlock == 10.toBlockNumber
  head = chainDB.getBlockHeader(chainDB.currentBlock)
  var sdb = newAccountStateDB(chainDB.db, head.stateRoot, pruneTrie = false)
  let expectedBalance = u256(txPerblock * numBlocks) * amount
  let balance = sdb.getBalance(recipient)
  debugEcho "BALANCE: ", balance
  debugEcho "EXPECTED: ", expectedBalance
  doAssert balance == expectedBalance

expected output:

BALANCE: 200000
EXPECTED: 200000

current output:

BALANCE: 180000
EXPECTED: 200000

something wrong in the test code, or txPool misuse?

@jangko
Copy link
Contributor Author

jangko commented Apr 4, 2022

log show something like this but I don't know if this is related or not

DBG 2022-04-04 08:17:07.142+07:00 invalid tx: account nonce mismatch
  tid: 4052
  file: validate.nim:320
  txNonce: 0
  accountNonce: 20

@mjfh
Copy link
Contributor

mjfh commented Apr 4, 2022

The code above is all right.

There was typo in the function jobDeltaTxsHead(), see #1034

@mjfh mjfh closed this as completed Apr 5, 2022
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

No branches or pull requests

2 participants