From 258d8be1dda8dd3679da1e5ad226c5ddd7bf1c5a Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Thu, 27 Feb 2020 16:42:17 +0300 Subject: [PATCH] core: store all accumulated SystemFee with every block --- pkg/core/blockchain.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index 5a4364b27..b47c08e10 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -427,13 +427,24 @@ func (bc *Blockchain) processHeader(h *block.Header, batch storage.Batch, header return nil } +// bc.GetHeaderHash(int(endHeight)) returns sum of all system fees for blocks up to h. +// and 0 if no such block exists. +func (bc *Blockchain) getSystemFeeAmount(h util.Uint256) uint32 { + _, sf, _ := bc.dao.GetBlock(h) + return sf +} + // TODO: storeBlock needs some more love, its implemented as in the original // project. This for the sake of development speed and understanding of what // is happening here, quite allot as you can see :). If things are wired together // and all tests are in place, we can make a more optimized and cleaner implementation. func (bc *Blockchain) storeBlock(block *block.Block) error { cache := newCachedDao(bc.dao.store) - if err := cache.StoreAsBlock(block, 0); err != nil { + fee := bc.getSystemFeeAmount(block.PrevHash) + for _, tx := range block.Transactions { + fee += uint32(bc.SystemFee(tx).Int64Value()) + } + if err := cache.StoreAsBlock(block, fee); err != nil { return err }