Start preparing the ground for layer {0,1} filters
This commit is contained in:
parent
472141f88d
commit
57995fd111
1 changed files with 20 additions and 17 deletions
|
@ -18,19 +18,22 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// cfIndexName is the human-readable name for the index.
|
// cfIndexName is the human-readable name for the index.
|
||||||
cfIndexName = "committed bloom filter index"
|
cfIndexName = "committed filter index"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// cfIndexKey is the name of the db bucket used to house the
|
// cfBasicIndexKey is the name of the db bucket used to house the
|
||||||
// block hash -> CF index.
|
// block hash -> Basic CF index (CF #0).
|
||||||
cfIndexKey = []byte("cfbyhashidx")
|
cfBasicIndexKey = []byte("cf0byhashidx")
|
||||||
|
// cfExtendedIndexKey is the name of the db bucket used to house the
|
||||||
|
// block hash -> Extended CF index (CF #1).
|
||||||
|
cfExtendedIndexKey = []byte("cf1byhashidx")
|
||||||
)
|
)
|
||||||
|
|
||||||
func dbFetchCFIndexEntry(dbTx database.Tx, blockHash *chainhash.Hash) ([]byte,
|
func dbFetchCFIndexEntry(dbTx database.Tx, blockHash *chainhash.Hash) ([]byte,
|
||||||
error) {
|
error) {
|
||||||
// Load the record from the database and return now if it doesn't exist.
|
// Load the record from the database and return now if it doesn't exist.
|
||||||
index := dbTx.Metadata().Bucket(cfIndexKey)
|
index := dbTx.Metadata().Bucket(cfBasicIndexKey)
|
||||||
serializedFilter := index.Get(blockHash[:])
|
serializedFilter := index.Get(blockHash[:])
|
||||||
if len(serializedFilter) == 0 {
|
if len(serializedFilter) == 0 {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
@ -64,10 +67,8 @@ func (idx *CFIndex) Init() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Key returns the database key to use for the index as a byte slice.
|
// Key returns the database key to use for the index as a byte slice.
|
||||||
//
|
|
||||||
// This is part of the Indexer interface.
|
|
||||||
func (idx *CFIndex) Key() []byte {
|
func (idx *CFIndex) Key() []byte {
|
||||||
return cfIndexKey
|
return cfBasicIndexKey
|
||||||
}
|
}
|
||||||
|
|
||||||
// Name returns the human-readable name of the index.
|
// Name returns the human-readable name of the index.
|
||||||
|
@ -77,14 +78,16 @@ func (idx *CFIndex) Name() string {
|
||||||
return cfIndexName
|
return cfIndexName
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create is invoked when the indexer manager determines the index needs
|
// Create is invoked when the indexer manager determines the index needs to be
|
||||||
// to be created for the first time. It creates the buckets for the hash-based
|
// created for the first time. It creates buckets for the two hash-based CF
|
||||||
// CF index.
|
// indexes (simple, extended).
|
||||||
//
|
|
||||||
// This is part of the Indexer interface.
|
|
||||||
func (idx *CFIndex) Create(dbTx database.Tx) error {
|
func (idx *CFIndex) Create(dbTx database.Tx) error {
|
||||||
meta := dbTx.Metadata()
|
meta := dbTx.Metadata()
|
||||||
_, err := meta.CreateBucket(cfIndexKey)
|
_, err := meta.CreateBucket(cfBasicIndexKey)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = meta.CreateBucket(cfExtendedIndexKey)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +122,7 @@ func (idx *CFIndex) ConnectBlock(dbTx database.Tx, block *btcutil.Block,
|
||||||
}
|
}
|
||||||
|
|
||||||
meta := dbTx.Metadata()
|
meta := dbTx.Metadata()
|
||||||
index := meta.Bucket(cfIndexKey)
|
index := meta.Bucket(cfBasicIndexKey)
|
||||||
err = index.Put(block.Hash()[:], filterBytes)
|
err = index.Put(block.Hash()[:], filterBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -137,7 +140,7 @@ func (idx *CFIndex) ConnectBlock(dbTx database.Tx, block *btcutil.Block,
|
||||||
// This is part of the Indexer interface.
|
// This is part of the Indexer interface.
|
||||||
func (idx *CFIndex) DisconnectBlock(dbTx database.Tx, block *btcutil.Block,
|
func (idx *CFIndex) DisconnectBlock(dbTx database.Tx, block *btcutil.Block,
|
||||||
view *blockchain.UtxoViewpoint) error {
|
view *blockchain.UtxoViewpoint) error {
|
||||||
index := dbTx.Metadata().Bucket(cfIndexKey)
|
index := dbTx.Metadata().Bucket(cfBasicIndexKey)
|
||||||
filterBytes := index.Get(block.Hash()[:])
|
filterBytes := index.Get(block.Hash()[:])
|
||||||
if len(filterBytes) == 0 {
|
if len(filterBytes) == 0 {
|
||||||
return fmt.Errorf("can't remove non-existent filter %s from " +
|
return fmt.Errorf("can't remove non-existent filter %s from " +
|
||||||
|
@ -169,5 +172,5 @@ func NewCFIndex(db database.DB) *CFIndex {
|
||||||
|
|
||||||
// DropCFIndex drops the CF index from the provided database if exists.
|
// DropCFIndex drops the CF index from the provided database if exists.
|
||||||
func DropCFIndex(db database.DB) error {
|
func DropCFIndex(db database.DB) error {
|
||||||
return dropIndex(db, cfIndexKey, cfIndexName)
|
return dropIndex(db, cfBasicIndexKey, cfIndexName)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue