remove blocks compression (#1453)

This commit is contained in:
Alex Sharov 2021-01-27 20:11:34 +07:00 committed by GitHub
parent c35b07df3d
commit 6faec7e834
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 42 deletions

View File

@ -6,11 +6,6 @@ import (
"sync/atomic" "sync/atomic"
) )
var (
compressBlocks bool
getCompressBlocks sync.Once
)
// atomic: bit 0 is the value, bit 1 is the initialized flag // atomic: bit 0 is the value, bit 1 is the initialized flag
var getNodeData uint32 var getNodeData uint32
@ -47,13 +42,6 @@ func OverrideGetNodeData(val bool) {
} }
} }
func IsBlockCompressionEnabled() bool {
getCompressBlocks.Do(func() {
_, compressBlocks = os.LookupEnv("COMPRESS_BLOCKS")
})
return compressBlocks
}
var ( var (
testDB string testDB string
getTestDB sync.Once getTestDB sync.Once

View File

@ -24,17 +24,13 @@ import (
"fmt" "fmt"
"math/big" "math/big"
"github.com/ledgerwatch/turbo-geth/ethdb"
"github.com/ledgerwatch/turbo-geth/ethdb/cbor"
"github.com/ledgerwatch/turbo-geth/common" "github.com/ledgerwatch/turbo-geth/common"
"github.com/ledgerwatch/turbo-geth/common/dbutils" "github.com/ledgerwatch/turbo-geth/common/dbutils"
"github.com/ledgerwatch/turbo-geth/common/debug"
"github.com/ledgerwatch/turbo-geth/core/types" "github.com/ledgerwatch/turbo-geth/core/types"
"github.com/ledgerwatch/turbo-geth/ethdb"
"github.com/ledgerwatch/turbo-geth/ethdb/cbor"
"github.com/ledgerwatch/turbo-geth/log" "github.com/ledgerwatch/turbo-geth/log"
"github.com/ledgerwatch/turbo-geth/rlp" "github.com/ledgerwatch/turbo-geth/rlp"
"github.com/golang/snappy"
) )
// ReadCanonicalHash retrieves the hash assigned to a canonical block number. // ReadCanonicalHash retrieves the hash assigned to a canonical block number.
@ -334,9 +330,6 @@ func WriteTransactions(db ethdb.Database, txs []*types.Transaction, baseTxId uin
// WriteBodyRLP stores an RLP encoded block body into the database. // WriteBodyRLP stores an RLP encoded block body into the database.
func WriteBodyRLP(db DatabaseWriter, hash common.Hash, number uint64, rlp rlp.RawValue) { func WriteBodyRLP(db DatabaseWriter, hash common.Hash, number uint64, rlp rlp.RawValue) {
if debug.IsBlockCompressionEnabled() {
rlp = snappy.Encode(nil, rlp)
}
if err := db.Put(dbutils.BlockBodyPrefix, dbutils.BlockBodyKey(number, hash), rlp); err != nil { if err := db.Put(dbutils.BlockBodyPrefix, dbutils.BlockBodyKey(number, hash), rlp); err != nil {
log.Crit("Failed to store block body", "err", err) log.Crit("Failed to store block body", "err", err)
} }

View File

@ -6,9 +6,7 @@ import (
"fmt" "fmt"
"time" "time"
"github.com/golang/snappy"
"github.com/ledgerwatch/turbo-geth/common/dbutils" "github.com/ledgerwatch/turbo-geth/common/dbutils"
"github.com/ledgerwatch/turbo-geth/common/debug"
"github.com/ledgerwatch/turbo-geth/common/etl" "github.com/ledgerwatch/turbo-geth/common/etl"
"github.com/ledgerwatch/turbo-geth/core/types" "github.com/ledgerwatch/turbo-geth/core/types"
"github.com/ledgerwatch/turbo-geth/ethdb" "github.com/ledgerwatch/turbo-geth/ethdb"
@ -23,18 +21,6 @@ var transactionsTable = Migration{
defer logEvery.Stop() defer logEvery.Stop()
logPrefix := "tx_table" logPrefix := "tx_table"
decompressBlockBody := func(compressed []byte) ([]byte, error) {
if !debug.IsBlockCompressionEnabled() || len(compressed) == 0 {
return compressed, nil
}
var bodyRlp []byte
bodyRlp, err = snappy.Decode(nil, compressed)
if err != nil {
return nil, fmt.Errorf("err on decode block: %w", err)
}
return bodyRlp, nil
}
const loadStep = "load" const loadStep = "load"
reader := bytes.NewReader(nil) reader := bytes.NewReader(nil)
buf := bytes.NewBuffer(make([]byte, 4096)) buf := bytes.NewBuffer(make([]byte, 4096))
@ -102,13 +88,7 @@ var transactionsTable = Migration{
} }
// don't need canonical check // don't need canonical check
var bodyRlp []byte reader.Reset(v)
bodyRlp, err = decompressBlockBody(v)
if err != nil {
return false, err
}
reader.Reset(bodyRlp)
if err = rlp.Decode(reader, body); err != nil { if err = rlp.Decode(reader, body); err != nil {
return false, fmt.Errorf("[%s]: invalid block body RLP: %w", logPrefix, err) return false, fmt.Errorf("[%s]: invalid block body RLP: %w", logPrefix, err)
} }