Flush on log size instead of transaction count

Backported from bitcoin commit e88ed65a39eb86ffd4d0720852d7e5f3d021f792