From 4f60fd3e8e7d27f819e3e205df8e9a0b61d9e810 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Wed, 11 Sep 2019 20:32:30 +0300 Subject: [PATCH] core: optimize persist() for the case when no next block found If there is no next block in the cache, looping through the whole cache won't help. --- pkg/core/blockchain.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index dd8416c35..f37e8441e 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -409,6 +409,9 @@ func (bc *Blockchain) persist(ctx context.Context) (err error) { } bc.blockCache.Delete(hash) persisted++ + } else { + // no next block in the cache, no reason to continue looping + break } } }