I wonder if wrapping it in a transaction would have resulted in the same improvement.
> This is mostly the real code, the only difference is we also rollback the transaction on failure. It's extremely important that this happens in a transaction and both the messages and merkle trie are updated atomically.