From 50aedbf6915a8879635d01481298c72879ce52ce Mon Sep 17 00:00:00 2001 From: Kay Date: Mon, 8 Jul 2024 09:49:46 +0000 Subject: [PATCH 1/3] feat(store): prune block function --- store/store.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/store/store.go b/store/store.go index 0621b85ed..c763cdb4f 100644 --- a/store/store.go +++ b/store/store.go @@ -378,3 +378,28 @@ func (s *store) WriteBatch() error { func (s *store) IsBanned(addr crypto.Address) bool { return s.config.BannedAddrs[addr] } + +func (s *store) pruneBlock(batch *leveldb.Batch, blockHeight uint32) (bool, error) { //nolint + s.lk.Lock() + defer s.lk.Unlock() + + blkData, err := s.blockStore.block(blockHeight) + if err != nil { + return false, err + } + + blk, err := block.FromBytes(blkData) + if err != nil { + return false, err + } + + if err := s.blockStore.db.Delete(blk.Hash().Bytes(), nil); err != nil { + return false, err + } + + for _, t := range blk.Transactions() { + batch.Delete(t.ID().Bytes()) + } + + return true, nil +} From 6f14fbe15f98dfe8f537ddc0f534293966846e6e Mon Sep 17 00:00:00 2001 From: Kay Date: Mon, 8 Jul 2024 10:44:20 +0000 Subject: [PATCH 2/3] fix: use store batch --- store/store.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/store/store.go b/store/store.go index c763cdb4f..169a6ea4b 100644 --- a/store/store.go +++ b/store/store.go @@ -379,7 +379,7 @@ func (s *store) IsBanned(addr crypto.Address) bool { return s.config.BannedAddrs[addr] } -func (s *store) pruneBlock(batch *leveldb.Batch, blockHeight uint32) (bool, error) { //nolint +func (s *store) pruneBlock(blockHeight uint32) (bool, error) { //nolint s.lk.Lock() defer s.lk.Unlock() @@ -398,7 +398,7 @@ func (s *store) pruneBlock(batch *leveldb.Batch, blockHeight uint32) (bool, erro } for _, t := range blk.Transactions() { - batch.Delete(t.ID().Bytes()) + s.batch.Delete(t.ID().Bytes()) } return true, nil From e38f8bb4493519657a62013db058fd527ddb3b93 Mon Sep 17 00:00:00 2001 From: Kay Date: Mon, 8 Jul 2024 13:00:25 +0000 Subject: [PATCH 3/3] fix: use batch to remove block with hashkey --- store/store.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/store/store.go b/store/store.go index 169a6ea4b..79adf11d4 100644 --- a/store/store.go +++ b/store/store.go @@ -393,9 +393,7 @@ func (s *store) pruneBlock(blockHeight uint32) (bool, error) { //nolint return false, err } - if err := s.blockStore.db.Delete(blk.Hash().Bytes(), nil); err != nil { - return false, err - } + s.batch.Delete(blockHashKey(blk.Hash())) for _, t := range blk.Transactions() { s.batch.Delete(t.ID().Bytes())