Fix transaction pruning in tx-pool (#6276)

The `tree_route` generated by the import notification is only from the
old best block to the new best parent. This means, it does not contain
the new best block in `enacted()`. We need to prune the transactions of
the new best block "manually" to fix this bug.

Besides that, this pr also changed the `id` parameter of the `NewBlock`
chain event to `hash`. The hash of a block is unique in contrast to the
block number. (Block id can either be number or hash)
This commit is contained in:
Bastian Köcher
2020-06-08 12:38:19 +02:00
committed by GitHub
parent 84cdb02963
commit 663cd09be9
11 changed files with 134 additions and 81 deletions
@@ -351,11 +351,11 @@ mod tests {
}.into_signed_tx()
}
fn chain_event<B: BlockT>(block_number: u64, header: B::Header) -> ChainEvent<B>
fn chain_event<B: BlockT>(header: B::Header) -> ChainEvent<B>
where NumberFor<B>: From<u64>
{
ChainEvent::NewBlock {
id: BlockId::Number(block_number.into()),
hash: header.hash(),
tree_route: None,
is_new_best: true,
header,
@@ -380,8 +380,9 @@ mod tests {
futures::executor::block_on(
txpool.maintain(chain_event(
0,
client.header(&BlockId::Number(0u64)).expect("header get error").expect("there should be header")
client.header(&BlockId::Number(0u64))
.expect("header get error")
.expect("there should be header")
))
);
@@ -470,7 +471,6 @@ mod tests {
futures::executor::block_on(
txpool.maintain(chain_event(
0,
client.header(&BlockId::Number(0u64))
.expect("header get error")
.expect("there should be header"),
@@ -574,8 +574,9 @@ mod tests {
futures::executor::block_on(
txpool.maintain(chain_event(
0,
client.header(&BlockId::Number(0u64)).expect("header get error").expect("there should be header")
client.header(&BlockId::Number(0u64))
.expect("header get error")
.expect("there should be header")
))
);
@@ -585,8 +586,9 @@ mod tests {
futures::executor::block_on(
txpool.maintain(chain_event(
1,
client.header(&BlockId::Number(1)).expect("header get error").expect("there should be header")
client.header(&BlockId::Number(1))
.expect("header get error")
.expect("there should be header")
))
);