Skip to content

Commit

Permalink
refactor: minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ninabarbakadze committed Mar 25, 2024
1 parent bcd56c2 commit 74abc3b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
6 changes: 3 additions & 3 deletions rpc/core/blocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,10 @@ func randomBlocks(height int64) []*types.Block {

func makeTxs(height int64) (txs []types.Tx) {
for i := 0; i < 10; i++ {
numbytes := make([]byte, 8)
binary.BigEndian.PutUint64(numbytes, uint64(height))
numBytes := make([]byte, 8)
binary.BigEndian.PutUint64(numBytes, uint64(height))

txs = append(txs, types.Tx(append(numbytes, byte(i))))
txs = append(txs, types.Tx(append(numBytes, byte(i))))
}
return txs
}
Expand Down
8 changes: 1 addition & 7 deletions store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
cmtsync "github.com/cometbft/cometbft/libs/sync"
cmtstore "github.com/cometbft/cometbft/proto/tendermint/store"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"

"github.com/cometbft/cometbft/types"
)

Expand Down Expand Up @@ -285,7 +284,6 @@ func (bs *BlockStore) PruneBlocks(height int64) (uint64, error) {
pruned := uint64(0)
batch := bs.db.NewBatch()
defer batch.Close()

flush := func(batch dbm.Batch, base int64) error {
// We can't trust batches to be atomic, so update base first to make sure no one
// tries to access missing blocks.
Expand All @@ -297,7 +295,6 @@ func (bs *BlockStore) PruneBlocks(height int64) (uint64, error) {
if err := batch.WriteSync(); err != nil {
return fmt.Errorf("failed to prune up to height %v: %w", base, err)
}

batch.Close()
return nil
}
Expand Down Expand Up @@ -333,17 +330,14 @@ func (bs *BlockStore) PruneBlocks(height int64) (uint64, error) {
pruned++

// flush every 1000 blocks to avoid batches becoming too large
// when flushing every 1000 blocks, we need to flush the txs as well that accumulated over the time
if pruned%1000 == 0 && pruned > 0 {

err := flush(batch, h)
if err != nil {
return 0, err
}
batch = bs.db.NewBatch()
defer func() {
batch.Close()
}()
batch.Close()
}
}

Expand Down
6 changes: 3 additions & 3 deletions store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ func makeTestCommit(height int64, timestamp time.Time) *types.Commit {

func makeTxs(height int64) (txs []types.Tx) {
for i := 0; i < 10; i++ {
numbytes := make([]byte, 8)
binary.BigEndian.PutUint64(numbytes, uint64(height))
numBytes := make([]byte, 8)
binary.BigEndian.PutUint64(numBytes, uint64(height))

txs = append(txs, types.Tx(append(numbytes, byte(i))))
txs = append(txs, types.Tx(append(numBytes, byte(i))))
}
return txs
}
Expand Down

0 comments on commit 74abc3b

Please sign in to comment.