dao: simplify buffer management for private DAO

Private DAO is only used in a single thread which means we can safely reuse
key/data buffers most of the time and handle it all in DAO.

Doesn't affect any benchmarks.
This commit is contained in:
Roman Khimov 2022-02-16 23:33:53 +03:00
parent 9bfb3357f2
commit 7dc8fc443f
5 changed files with 102 additions and 78 deletions

View file

@ -330,19 +330,16 @@ func (s *Module) AddBlock(block *block.Block) error {
}
}
cache := s.dao.GetPrivate()
writeBuf := io.NewBufBinWriter()
if err := cache.StoreAsBlock(block, nil, nil, writeBuf); err != nil {
if err := cache.StoreAsBlock(block, nil, nil); err != nil {
return err
}
writeBuf.Reset()
cache.PutStateSyncCurrentBlockHeight(block.Index)
for _, tx := range block.Transactions {
if err := cache.StoreAsTransaction(tx, block.Index, nil, writeBuf); err != nil {
if err := cache.StoreAsTransaction(tx, block.Index, nil); err != nil {
return err
}
writeBuf.Reset()
}
_, err := cache.Persist()