qdrvm / kagome

Kagome - C++20 implementation of Polkadot Host
https://kagome.readthedocs.io
Apache License 2.0
158 stars 33 forks source link

[Bug]: TopperTrieBatchImpl::empty ignores cached clearPrefix calls #2106

Closed Harrm closed 4 months ago

Harrm commented 4 months ago

Bug Summary

TopperTrieBatchImpl::empty ignores cached clearPrefix calls.

Bug Description

TopperTrieBatchImpl caches clearPrefix call separately for performance. This makes honest TopperTrieBatchImpl::empty implementation more expensive, because it would need to check that if the underlying trie is not empty, then it could become empty after applying all clearPrefixes. It doesn't do this currently, as this seems to be a very rare scenario.

Steps to Reproduce

A topper trie batch that is empty, but has pending clear prefix calls. Its underlying trie is not empty, but will become empty if 'clear prefix'es are applied. In this case TopperTrieBatchImpl::empty should return true, but will return false.

Effects of the Bug

Incorrect behaviour of TopperTrieBatchImpl::empty in a very rare case.

Expected Behavior

See 'Steps to Reproduce'.

System Information

Any system.

Additional Context

No response