NEXT_FEE_BASE = BLOCK_SIZE * PREV_FEE / TARGET_BYTES_PER_BLOCK
NEXT_FEE = (PREV_FEE * 99 + NEXT_FEE_BASE)/100
if( NEXT_FEE < MIN_FEE ) NEXT_FEE = MIN_FEE
My mistake... I meant to use PREV_FEE * 99 not MIN_FEE...
Yeah, that nearly looks like my first post
That one looks fine to me. It should pull the long term average block size
towards below TARGET_BYTES_PER_BLOCK.
The reason I put 1% of MIN_FEE into my first post was to make it slowly forget too large blocks. After 100 blocks of 2x target yours needs, e.g., 1000 blocks of 0.9x target for the fee to reach MIN_FEE again. Mine would fall back slowly even if block_size remains at 1x target whereas yours would then stay at a constant higher fee level. I guess it doesn't really matter.
I crossed out the towards because of the MIN_FEE rule. It causes series of blocks smaller than target size preceding series of large blocks to be ignored. (Once the average block size is below the target size, saving space is not credited)