diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-10-17 03:35:24 +0800 |
---|---|---|
committer | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-10-17 03:35:24 +0800 |
commit | 10ed107ba2001d1aabba3d319ba88c5ce6e8fdc0 (patch) | |
tree | 7c79e36cadcc57a8c936f06838a061cdf7e3fd8a /eth/backend.go | |
parent | c5ef2afda56c069fda5528c48bd3d831b81455dc (diff) | |
parent | 6dc14788a238f3e0ec786c6c04d476a3b957e645 (diff) | |
download | go-tangerine-10ed107ba2001d1aabba3d319ba88c5ce6e8fdc0.tar go-tangerine-10ed107ba2001d1aabba3d319ba88c5ce6e8fdc0.tar.gz go-tangerine-10ed107ba2001d1aabba3d319ba88c5ce6e8fdc0.tar.bz2 go-tangerine-10ed107ba2001d1aabba3d319ba88c5ce6e8fdc0.tar.lz go-tangerine-10ed107ba2001d1aabba3d319ba88c5ce6e8fdc0.tar.xz go-tangerine-10ed107ba2001d1aabba3d319ba88c5ce6e8fdc0.tar.zst go-tangerine-10ed107ba2001d1aabba3d319ba88c5ce6e8fdc0.zip |
Merge pull request #1899 from obscuren/mipmap-bloom
core, eth/filters, miner, xeth: Optimised log filtering
Diffstat (limited to 'eth/backend.go')
-rw-r--r-- | eth/backend.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/eth/backend.go b/eth/backend.go index dc16ba4cf..9ec3c1440 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -47,6 +47,7 @@ import ( "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p/discover" "github.com/ethereum/go-ethereum/p2p/nat" + "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/whisper" ) @@ -288,6 +289,9 @@ func New(config *Config) (*Ethereum, error) { if err := upgradeChainDatabase(chainDb); err != nil { return nil, err } + if err := addMipmapBloomBins(chainDb); err != nil { + return nil, err + } dappDb, err := newdb(filepath.Join(config.DataDir, "dapp")) if err != nil { @@ -758,3 +762,45 @@ func upgradeChainDatabase(db ethdb.Database) error { } return nil } + +func addMipmapBloomBins(db ethdb.Database) (err error) { + const mipmapVersion uint = 2 + + // check if the version is set. We ignore data for now since there's + // only one version so we can easily ignore it for now + var data []byte + data, _ = db.Get([]byte("setting-mipmap-version")) + if len(data) > 0 { + var version uint + if err := rlp.DecodeBytes(data, &version); err == nil && version == mipmapVersion { + return nil + } + } + + defer func() { + if err == nil { + var val []byte + val, err = rlp.EncodeToBytes(mipmapVersion) + if err == nil { + err = db.Put([]byte("setting-mipmap-version"), val) + } + return + } + }() + latestBlock := core.GetBlock(db, core.GetHeadBlockHash(db)) + if latestBlock == nil { // clean database + return + } + + tstart := time.Now() + glog.V(logger.Info).Infoln("upgrading db log bloom bins") + for i := uint64(0); i <= latestBlock.NumberU64(); i++ { + hash := core.GetCanonicalHash(db, i) + if (hash == common.Hash{}) { + return fmt.Errorf("chain db corrupted. Could not find block %d.", i) + } + core.WriteMipmapBloom(db, i, core.GetBlockReceipts(db, hash)) + } + glog.V(logger.Info).Infoln("upgrade completed in", time.Since(tstart)) + return nil +} |