From 3ada92944a976042f0170f4aa3563c356a06f100 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Mon, 7 Oct 2019 19:55:33 +0300 Subject: [PATCH] storage: drop Len from the Batch interface It's almost meaningless now and we can easily live without it. --- pkg/core/blockchain.go | 3 ++- pkg/core/storage/memory_store.go | 5 ----- pkg/core/storage/store.go | 1 - 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index 0365c2517..4a4afba09 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -238,6 +238,7 @@ func (bc *Blockchain) AddHeaders(headers ...*Header) (err error) { ) bc.headersOp <- func(headerList *HeaderHashList) { + oldlen := headerList.Len() for _, h := range headers { if int(h.Index-1) >= headerList.Len() { err = fmt.Errorf( @@ -258,7 +259,7 @@ func (bc *Blockchain) AddHeaders(headers ...*Header) (err error) { } } - if batch.Len() > 0 { + if oldlen != headerList.Len() { if err = bc.memStore.PutBatch(batch); err != nil { return } diff --git a/pkg/core/storage/memory_store.go b/pkg/core/storage/memory_store.go index 571ab64e5..75493914c 100644 --- a/pkg/core/storage/memory_store.go +++ b/pkg/core/storage/memory_store.go @@ -37,11 +37,6 @@ func (b *MemoryBatch) Delete(k []byte) { b.del[kcopy] = true } -// Len implements the Batch interface. -func (b *MemoryBatch) Len() int { - return len(b.m) -} - // NewMemoryStore creates a new MemoryStore object. func NewMemoryStore() *MemoryStore { return &MemoryStore{ diff --git a/pkg/core/storage/store.go b/pkg/core/storage/store.go index a9bbacd5b..15a25f12e 100644 --- a/pkg/core/storage/store.go +++ b/pkg/core/storage/store.go @@ -46,7 +46,6 @@ type ( Batch interface { Delete(k []byte) Put(k, v []byte) - Len() int } // KeyPrefix is a constant byte added as a prefix for each key