Don't write metadata twice.
Don't write metadata immediately if checking the store.
Delete obsolete comment
Consistently use int for block numbers. Metadata uses an int, and in future we may have different FEC algorithms which may need it. We were inconsistent, sometimes using int, sometimes short. Changes the on-disk format.
Don't re-encode the block (refactoring onGotBlock a bit)
Free data earlier and simplify code.
Write metadata lazily after getting a block, even from network. It will get written in 10 minutes or on shutdown, and if we're getting a lot of them in the <10min before a crash then we're gonna re-get them easily enough after it.