[lbry] configure and pass claimtrie from server
This commit is contained in:
parent
6b55968ccd
commit
2e75ce6583
3 changed files with 47 additions and 16 deletions
|
@ -575,8 +575,10 @@ func (b *BlockChain) connectBlock(node *blockNode, block *btcutil.Block,
|
|||
}
|
||||
|
||||
// Handle LBRY Claim Scripts
|
||||
if err := b.ParseClaimScripts(block, node, view, false); err != nil {
|
||||
return ruleError(ErrBadClaimTrie, err.Error())
|
||||
if b.claimTrie != nil {
|
||||
if err := b.ParseClaimScripts(block, node, view, false); err != nil {
|
||||
return ruleError(ErrBadClaimTrie, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
// No warnings about unknown rules until the chain is current.
|
||||
|
@ -1718,6 +1720,8 @@ type Config struct {
|
|||
// This field can be nil if the caller is not interested in using a
|
||||
// signature cache.
|
||||
HashCache *txscript.HashCache
|
||||
|
||||
ClaimTrie *claimtrie.ClaimTrie
|
||||
}
|
||||
|
||||
// New returns a BlockChain instance using the provided configuration details.
|
||||
|
@ -1772,6 +1776,7 @@ func New(config *Config) (*BlockChain, error) {
|
|||
prevOrphans: make(map[chainhash.Hash][]*orphanBlock),
|
||||
warningCaches: newThresholdCaches(vbNumBits),
|
||||
deploymentCaches: newThresholdCaches(chaincfg.DefinedDeployments),
|
||||
claimTrie: config.ClaimTrie,
|
||||
}
|
||||
|
||||
// Initialize the chain state from the passed database. When the db
|
||||
|
@ -1814,18 +1819,12 @@ func New(config *Config) (*BlockChain, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
ct, err := claimtrie.New(true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
b.claimTrie = ct
|
||||
|
||||
// ct.ResetHeight(760140) // TODO: add an optional CLI parameter for this
|
||||
|
||||
err = rebuildMissingClaimTrieData(&b, config.Interrupt)
|
||||
if err != nil {
|
||||
ct.Close()
|
||||
return nil, err
|
||||
if b.claimTrie != nil {
|
||||
err := rebuildMissingClaimTrieData(&b, config.Interrupt)
|
||||
if err != nil {
|
||||
b.claimTrie.Close()
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
bestNode := b.bestChain.Tip()
|
||||
|
|
4
btcd.go
4
btcd.go
|
@ -165,7 +165,9 @@ func btcdMain(serverChan chan<- *server) error {
|
|||
server.WaitForShutdown()
|
||||
srvrLog.Infof("Server shutdown complete")
|
||||
// TODO: tie into the sync manager for shutdown instead
|
||||
server.chain.ClaimTrie().Close()
|
||||
if ct := server.chain.ClaimTrie(); ct != nil {
|
||||
ct.Close()
|
||||
}
|
||||
}()
|
||||
server.Start()
|
||||
if serverChan != nil {
|
||||
|
|
32
server.go
32
server.go
|
@ -14,6 +14,7 @@ import (
|
|||
"fmt"
|
||||
"math"
|
||||
"net"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strconv"
|
||||
|
@ -27,6 +28,8 @@ import (
|
|||
"github.com/btcsuite/btcd/blockchain/indexers"
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/claimtrie"
|
||||
claimtrieconfig "github.com/btcsuite/btcd/claimtrie/config"
|
||||
"github.com/btcsuite/btcd/connmgr"
|
||||
"github.com/btcsuite/btcd/database"
|
||||
"github.com/btcsuite/btcd/mempool"
|
||||
|
@ -2721,8 +2724,34 @@ func newServer(listenAddrs, agentBlacklist, agentWhitelist []string,
|
|||
checkpoints = mergeCheckpoints(s.chainParams.Checkpoints, cfg.addCheckpoints)
|
||||
}
|
||||
|
||||
// Create a new block chain instance with the appropriate configuration.
|
||||
var err error
|
||||
|
||||
claimTrieCfg := claimtrieconfig.DefaultConfig
|
||||
claimTrieCfg.DataDir = filepath.Join(cfg.DataDir, "claim_dbs")
|
||||
claimTrieCfg.Record = cfg.ClaimTrieRecord
|
||||
|
||||
var ct *claimtrie.ClaimTrie
|
||||
|
||||
switch cfg.ClaimTrieImpl {
|
||||
case "none":
|
||||
// Disable ClaimTrie for development purpose.
|
||||
clmtLog.Infof("ClaimTrie is disabled")
|
||||
default:
|
||||
ct, err = claimtrie.New(claimTrieCfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if h := cfg.ClaimTrieHeight; h != 0 {
|
||||
clmtLog.Infof("Reseting height to %d", h)
|
||||
err := ct.ResetHeight(int32(h))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
clmtLog.Infof("Height is reset to %d", h)
|
||||
}
|
||||
}
|
||||
|
||||
// Create a new block chain instance with the appropriate configuration.
|
||||
s.chain, err = blockchain.New(&blockchain.Config{
|
||||
DB: s.db,
|
||||
Interrupt: interrupt,
|
||||
|
@ -2732,6 +2761,7 @@ func newServer(listenAddrs, agentBlacklist, agentWhitelist []string,
|
|||
SigCache: s.sigCache,
|
||||
IndexManager: indexManager,
|
||||
HashCache: s.hashCache,
|
||||
ClaimTrie: ct,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
Loading…
Add table
Reference in a new issue