mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-05 13:46:42 +00:00
[DEV-54] Rename "chainXXX", "bestXXX", etc. inside blockdag package (#25)
* [DEV-54] Renamed chainXXX to dagXXX. * [DEV-54] Additional chain -> dag renamings. * [DEV-54] Renamed a couple of more "chain"s I missed.
This commit is contained in:
parent
f4a0ec175d
commit
b07805cc12
@ -20,7 +20,7 @@ import (
|
||||
// their documentation for how the flags modify their behavior.
|
||||
//
|
||||
// This function MUST be called with the chain state lock held (for writes).
|
||||
func (b *BlockChain) maybeAcceptBlock(block *btcutil.Block, flags BehaviorFlags) error {
|
||||
func (b *BlockDAG) maybeAcceptBlock(block *btcutil.Block, flags BehaviorFlags) error {
|
||||
// The height of this block is one more than the referenced previous
|
||||
// block.
|
||||
parents, err := lookupPreviousNodes(block, b)
|
||||
@ -78,24 +78,24 @@ func (b *BlockChain) maybeAcceptBlock(block *btcutil.Block, flags BehaviorFlags)
|
||||
// Notify the caller that the new block was accepted into the block
|
||||
// chain. The caller would typically want to react by relaying the
|
||||
// inventory to other peers.
|
||||
b.chainLock.Unlock()
|
||||
b.dagLock.Unlock()
|
||||
b.sendNotification(NTBlockAccepted, block)
|
||||
b.chainLock.Lock()
|
||||
b.dagLock.Lock()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func lookupPreviousNodes(block *btcutil.Block, blockChain *BlockChain) (blockSet, error) {
|
||||
func lookupPreviousNodes(block *btcutil.Block, blockDAG *BlockDAG) (blockSet, error) {
|
||||
header := block.MsgBlock().Header
|
||||
prevHashes := header.PrevBlocks
|
||||
|
||||
nodes := newSet()
|
||||
for _, prevHash := range prevHashes {
|
||||
node := blockChain.index.LookupNode(&prevHash)
|
||||
node := blockDAG.index.LookupNode(&prevHash)
|
||||
if node == nil {
|
||||
str := fmt.Sprintf("previous block %s is unknown", prevHashes)
|
||||
return nil, ruleError(ErrPreviousBlockUnknown, str)
|
||||
} else if blockChain.index.NodeStatus(node).KnownInvalid() {
|
||||
} else if blockDAG.index.NodeStatus(node).KnownInvalid() {
|
||||
str := fmt.Sprintf("previous block %s is known to be invalid", prevHashes)
|
||||
return nil, ruleError(ErrInvalidAncestorBlock, str)
|
||||
}
|
||||
|
@ -236,8 +236,8 @@ type blockIndex struct {
|
||||
// The following fields are set when the instance is created and can't
|
||||
// be changed afterwards, so there is no need to protect them with a
|
||||
// separate mutex.
|
||||
db database.DB
|
||||
chainParams *dagconfig.Params
|
||||
db database.DB
|
||||
dagParams *dagconfig.Params
|
||||
|
||||
sync.RWMutex
|
||||
index map[daghash.Hash]*blockNode
|
||||
@ -247,12 +247,12 @@ type blockIndex struct {
|
||||
// newBlockIndex returns a new empty instance of a block index. The index will
|
||||
// be dynamically populated as block nodes are loaded from the database and
|
||||
// manually added.
|
||||
func newBlockIndex(db database.DB, chainParams *dagconfig.Params) *blockIndex {
|
||||
func newBlockIndex(db database.DB, dagParams *dagconfig.Params) *blockIndex {
|
||||
return &blockIndex{
|
||||
db: db,
|
||||
chainParams: chainParams,
|
||||
index: make(map[daghash.Hash]*blockNode),
|
||||
dirty: make(map[*blockNode]struct{}),
|
||||
db: db,
|
||||
dagParams: dagParams,
|
||||
index: make(map[daghash.Hash]*blockNode),
|
||||
dirty: make(map[*blockNode]struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,14 +32,14 @@ func newHashFromStr(hexStr string) *daghash.Hash {
|
||||
// nil.
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (b *BlockChain) Checkpoints() []dagconfig.Checkpoint {
|
||||
func (b *BlockDAG) Checkpoints() []dagconfig.Checkpoint {
|
||||
return b.checkpoints
|
||||
}
|
||||
|
||||
// HasCheckpoints returns whether this BlockChain has checkpoints defined.
|
||||
// HasCheckpoints returns whether this BlockDAG has checkpoints defined.
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (b *BlockChain) HasCheckpoints() bool {
|
||||
func (b *BlockDAG) HasCheckpoints() bool {
|
||||
return len(b.checkpoints) > 0
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ func (b *BlockChain) HasCheckpoints() bool {
|
||||
// instance, it will return nil.
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (b *BlockChain) LatestCheckpoint() *dagconfig.Checkpoint {
|
||||
func (b *BlockDAG) LatestCheckpoint() *dagconfig.Checkpoint {
|
||||
if !b.HasCheckpoints() {
|
||||
return nil
|
||||
}
|
||||
@ -58,7 +58,7 @@ func (b *BlockChain) LatestCheckpoint() *dagconfig.Checkpoint {
|
||||
// verifyCheckpoint returns whether the passed block height and hash combination
|
||||
// match the checkpoint data. It also returns true if there is no checkpoint
|
||||
// data for the passed block height.
|
||||
func (b *BlockChain) verifyCheckpoint(height int32, hash *daghash.Hash) bool {
|
||||
func (b *BlockDAG) verifyCheckpoint(height int32, hash *daghash.Hash) bool {
|
||||
if !b.HasCheckpoints() {
|
||||
return true
|
||||
}
|
||||
@ -84,7 +84,7 @@ func (b *BlockChain) verifyCheckpoint(height int32, hash *daghash.Hash) bool {
|
||||
// should really only happen for blocks before the first checkpoint).
|
||||
//
|
||||
// This function MUST be called with the chain lock held (for reads).
|
||||
func (b *BlockChain) findPreviousCheckpoint() (*blockNode, error) {
|
||||
func (b *BlockDAG) findPreviousCheckpoint() (*blockNode, error) {
|
||||
if !b.HasCheckpoints() {
|
||||
return nil, nil
|
||||
}
|
||||
@ -99,7 +99,7 @@ func (b *BlockChain) findPreviousCheckpoint() (*blockNode, error) {
|
||||
// that is already available.
|
||||
for i := numCheckpoints - 1; i >= 0; i-- {
|
||||
node := b.index.LookupNode(checkpoints[i].Hash)
|
||||
if node == nil || !b.bestChain.Contains(node) {
|
||||
if node == nil || !b.dag.Contains(node) {
|
||||
continue
|
||||
}
|
||||
|
||||
@ -130,7 +130,7 @@ func (b *BlockChain) findPreviousCheckpoint() (*blockNode, error) {
|
||||
// When there is a next checkpoint and the height of the current best
|
||||
// chain does not exceed it, the current checkpoint lockin is still
|
||||
// the latest known checkpoint.
|
||||
if b.bestChain.SelectedTip().height < b.nextCheckpoint.Height {
|
||||
if b.dag.SelectedTip().height < b.nextCheckpoint.Height {
|
||||
return b.checkpointNode, nil
|
||||
}
|
||||
|
||||
@ -197,13 +197,13 @@ func isNonstandardTransaction(tx *btcutil.Tx) bool {
|
||||
// decision and then manually added to the list of checkpoints for a network.
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (b *BlockChain) IsCheckpointCandidate(block *btcutil.Block) (bool, error) {
|
||||
b.chainLock.RLock()
|
||||
defer b.chainLock.RUnlock()
|
||||
func (b *BlockDAG) IsCheckpointCandidate(block *btcutil.Block) (bool, error) {
|
||||
b.dagLock.RLock()
|
||||
defer b.dagLock.RUnlock()
|
||||
|
||||
// A checkpoint must be in the main chain.
|
||||
node := b.index.LookupNode(block.Hash())
|
||||
if node == nil || !b.bestChain.Contains(node) {
|
||||
if node == nil || !b.dag.Contains(node) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
@ -218,7 +218,7 @@ func (b *BlockChain) IsCheckpointCandidate(block *btcutil.Block) (bool, error) {
|
||||
|
||||
// A checkpoint must be at least CheckpointConfirmations blocks
|
||||
// before the end of the main chain.
|
||||
mainChainHeight := b.bestChain.SelectedTip().height
|
||||
mainChainHeight := b.dag.SelectedTip().height
|
||||
if node.height > (mainChainHeight - CheckpointConfirmations) {
|
||||
return false, nil
|
||||
}
|
||||
@ -228,7 +228,7 @@ func (b *BlockChain) IsCheckpointCandidate(block *btcutil.Block) (bool, error) {
|
||||
// This should always succeed since the check above already made sure it
|
||||
// is CheckpointConfirmations back, but be safe in case the constant
|
||||
// changes.
|
||||
nextNode := b.bestChain.Next(node)
|
||||
nextNode := b.dag.Next(node)
|
||||
if nextNode == nil {
|
||||
return false, nil
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ func loadBlocks(filename string) (blocks []*btcutil.Block, err error) {
|
||||
// chainSetup is used to create a new db and chain instance with the genesis
|
||||
// block already inserted. In addition to the new chain instance, it returns
|
||||
// a teardown function the caller should invoke when done testing to clean up.
|
||||
func chainSetup(dbName string, params *dagconfig.Params) (*BlockChain, func(), error) {
|
||||
func chainSetup(dbName string, params *dagconfig.Params) (*BlockDAG, func(), error) {
|
||||
if !isSupportedDbType(testDbType) {
|
||||
return nil, nil, fmt.Errorf("unsupported db type %v", testDbType)
|
||||
}
|
||||
@ -174,7 +174,7 @@ func chainSetup(dbName string, params *dagconfig.Params) (*BlockChain, func(), e
|
||||
// Create the main chain instance.
|
||||
chain, err := New(&Config{
|
||||
DB: db,
|
||||
ChainParams: ¶msCopy,
|
||||
DAGParams: ¶msCopy,
|
||||
Checkpoints: nil,
|
||||
TimeSource: NewMedianTime(),
|
||||
SigCache: txscript.NewSigCache(1000),
|
||||
@ -193,7 +193,7 @@ func loadUtxoView(filename string) (*UtxoViewpoint, error) {
|
||||
// <tx hash><output index><serialized utxo len><serialized utxo>
|
||||
//
|
||||
// The output index and serialized utxo len are little endian uint32s
|
||||
// and the serialized utxo uses the format described in chainio.go.
|
||||
// and the serialized utxo uses the format described in dagio.go.
|
||||
|
||||
filename = filepath.Join("testdata", filename)
|
||||
fi, err := os.Open(filename)
|
||||
@ -339,15 +339,15 @@ func convertUtxoStore(r io.Reader, w io.Writer) error {
|
||||
|
||||
// TstSetCoinbaseMaturity makes the ability to set the coinbase maturity
|
||||
// available when running tests.
|
||||
func (b *BlockChain) TstSetCoinbaseMaturity(maturity uint16) {
|
||||
b.chainParams.CoinbaseMaturity = maturity
|
||||
func (b *BlockDAG) TstSetCoinbaseMaturity(maturity uint16) {
|
||||
b.dagParams.CoinbaseMaturity = maturity
|
||||
}
|
||||
|
||||
// newFakeDag returns a chain that is usable for syntetic tests. It is
|
||||
// important to note that this chain has no database associated with it, so
|
||||
// it is not usable with all functions and the tests must take care when making
|
||||
// use of it.
|
||||
func newFakeDag(params *dagconfig.Params) *BlockChain {
|
||||
func newFakeDag(params *dagconfig.Params) *BlockDAG {
|
||||
// Create a genesis block node and block index index populated with it
|
||||
// for use when creating the fake chain below.
|
||||
node := newBlockNode(¶ms.GenesisBlock.Header, newSet())
|
||||
@ -357,14 +357,14 @@ func newFakeDag(params *dagconfig.Params) *BlockChain {
|
||||
targetTimespan := int64(params.TargetTimespan / time.Second)
|
||||
targetTimePerBlock := int64(params.TargetTimePerBlock / time.Second)
|
||||
adjustmentFactor := params.RetargetAdjustmentFactor
|
||||
return &BlockChain{
|
||||
chainParams: params,
|
||||
return &BlockDAG{
|
||||
dagParams: params,
|
||||
timeSource: NewMedianTime(),
|
||||
minRetargetTimespan: targetTimespan / adjustmentFactor,
|
||||
maxRetargetTimespan: targetTimespan * adjustmentFactor,
|
||||
blocksPerRetarget: int32(targetTimespan / targetTimePerBlock),
|
||||
index: index,
|
||||
bestChain: newChainView(node),
|
||||
dag: newDAGView(node),
|
||||
warningCaches: newThresholdCaches(vbNumBits),
|
||||
deploymentCaches: newThresholdCaches(dagconfig.DefinedDeployments),
|
||||
}
|
||||
|
@ -81,18 +81,18 @@ func newBestState(node *blockNode, blockSize, numTxns,
|
||||
}
|
||||
}
|
||||
|
||||
// BlockChain provides functions for working with the bitcoin block chain.
|
||||
// BlockDAG provides functions for working with the bitcoin block chain.
|
||||
// It includes functionality such as rejecting duplicate blocks, ensuring blocks
|
||||
// follow all rules, orphan handling, checkpoint handling, and best chain
|
||||
// selection with reorganization.
|
||||
type BlockChain struct {
|
||||
type BlockDAG struct {
|
||||
// The following fields are set when the instance is created and can't
|
||||
// be changed afterwards, so there is no need to protect them with a
|
||||
// separate mutex.
|
||||
checkpoints []dagconfig.Checkpoint
|
||||
checkpointsByHeight map[int32]*dagconfig.Checkpoint
|
||||
db database.DB
|
||||
chainParams *dagconfig.Params
|
||||
dagParams *dagconfig.Params
|
||||
timeSource MedianTimeSource
|
||||
sigCache *txscript.SigCache
|
||||
indexManager IndexManager
|
||||
@ -105,9 +105,9 @@ type BlockChain struct {
|
||||
maxRetargetTimespan int64 // target timespan * adjustment factor
|
||||
blocksPerRetarget int32 // target timespan / target time per block
|
||||
|
||||
// chainLock protects concurrent access to the vast majority of the
|
||||
// dagLock protects concurrent access to the vast majority of the
|
||||
// fields in this struct below this point.
|
||||
chainLock sync.RWMutex
|
||||
dagLock sync.RWMutex
|
||||
|
||||
// These fields are related to the memory block index. They both have
|
||||
// their own locks, however they are often also protected by the chain
|
||||
@ -116,10 +116,10 @@ type BlockChain struct {
|
||||
// index houses the entire block index in memory. The block index is
|
||||
// a tree-shaped structure.
|
||||
//
|
||||
// bestChain tracks the current active chain by making use of an
|
||||
// dag tracks the current active chain by making use of an
|
||||
// efficient chain view into the block index.
|
||||
index *blockIndex
|
||||
bestChain *chainView
|
||||
index *blockIndex
|
||||
dag *dagView
|
||||
|
||||
// These fields are related to handling of orphan blocks. They are
|
||||
// protected by a combination of the chain lock and the orphan lock.
|
||||
@ -186,7 +186,7 @@ type BlockChain struct {
|
||||
// be like part of the main chain, on a side chain, or in the orphan pool.
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (b *BlockChain) HaveBlock(hash *daghash.Hash) (bool, error) {
|
||||
func (b *BlockDAG) HaveBlock(hash *daghash.Hash) (bool, error) {
|
||||
exists, err := b.blockExists(hash)
|
||||
if err != nil {
|
||||
return false, err
|
||||
@ -204,7 +204,7 @@ func (b *BlockChain) HaveBlock(hash *daghash.Hash) (bool, error) {
|
||||
// duplicate orphans and react accordingly.
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (b *BlockChain) IsKnownOrphan(hash *daghash.Hash) bool {
|
||||
func (b *BlockDAG) IsKnownOrphan(hash *daghash.Hash) bool {
|
||||
// Protect concurrent access. Using a read lock only so multiple
|
||||
// readers can query without blocking each other.
|
||||
b.orphanLock.RLock()
|
||||
@ -218,7 +218,7 @@ func (b *BlockChain) IsKnownOrphan(hash *daghash.Hash) bool {
|
||||
// map of orphan blocks.
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (b *BlockChain) GetOrphanRoot(hash *daghash.Hash) *daghash.Hash {
|
||||
func (b *BlockDAG) GetOrphanRoot(hash *daghash.Hash) *daghash.Hash {
|
||||
// Protect concurrent access. Using a read lock only so multiple
|
||||
// readers can query without blocking each other.
|
||||
b.orphanLock.RLock()
|
||||
@ -242,7 +242,7 @@ func (b *BlockChain) GetOrphanRoot(hash *daghash.Hash) *daghash.Hash {
|
||||
|
||||
// removeOrphanBlock removes the passed orphan block from the orphan pool and
|
||||
// previous orphan index.
|
||||
func (b *BlockChain) removeOrphanBlock(orphan *orphanBlock) {
|
||||
func (b *BlockDAG) removeOrphanBlock(orphan *orphanBlock) {
|
||||
// Protect concurrent access.
|
||||
b.orphanLock.Lock()
|
||||
defer b.orphanLock.Unlock()
|
||||
@ -281,7 +281,7 @@ func (b *BlockChain) removeOrphanBlock(orphan *orphanBlock) {
|
||||
// It also imposes a maximum limit on the number of outstanding orphan
|
||||
// blocks and will remove the oldest received orphan block if the limit is
|
||||
// exceeded.
|
||||
func (b *BlockChain) addOrphanBlock(block *btcutil.Block) {
|
||||
func (b *BlockDAG) addOrphanBlock(block *btcutil.Block) {
|
||||
// Remove expired orphan blocks.
|
||||
for _, oBlock := range b.orphans {
|
||||
if time.Now().After(oBlock.expiration) {
|
||||
@ -343,18 +343,18 @@ type SequenceLock struct {
|
||||
// the candidate transaction to be included in a block.
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (b *BlockChain) CalcSequenceLock(tx *btcutil.Tx, utxoView *UtxoViewpoint, mempool bool) (*SequenceLock, error) {
|
||||
b.chainLock.Lock()
|
||||
defer b.chainLock.Unlock()
|
||||
func (b *BlockDAG) CalcSequenceLock(tx *btcutil.Tx, utxoView *UtxoViewpoint, mempool bool) (*SequenceLock, error) {
|
||||
b.dagLock.Lock()
|
||||
defer b.dagLock.Unlock()
|
||||
|
||||
return b.calcSequenceLock(b.bestChain.SelectedTip(), tx, utxoView, mempool)
|
||||
return b.calcSequenceLock(b.dag.SelectedTip(), tx, utxoView, mempool)
|
||||
}
|
||||
|
||||
// calcSequenceLock computes the relative lock-times for the passed
|
||||
// transaction. See the exported version, CalcSequenceLock for further details.
|
||||
//
|
||||
// This function MUST be called with the chain state lock held (for writes).
|
||||
func (b *BlockChain) calcSequenceLock(node *blockNode, tx *btcutil.Tx, utxoView *UtxoViewpoint, mempool bool) (*SequenceLock, error) {
|
||||
func (b *BlockDAG) calcSequenceLock(node *blockNode, tx *btcutil.Tx, utxoView *UtxoViewpoint, mempool bool) (*SequenceLock, error) {
|
||||
// A value of -1 for each relative lock type represents a relative time
|
||||
// lock value that will allow a transaction to be included in a block
|
||||
// at any given height or time. This value is returned as the relative
|
||||
@ -493,7 +493,7 @@ func LockTimeToSequence(isSeconds bool, locktime uint32) uint32 {
|
||||
// it would be inefficient to repeat it.
|
||||
//
|
||||
// This function MUST be called with the chain state lock held (for writes).
|
||||
func (b *BlockChain) connectBlock(node *blockNode, block *btcutil.Block, view *UtxoViewpoint, stxos []spentTxOut) error {
|
||||
func (b *BlockDAG) connectBlock(node *blockNode, block *btcutil.Block, view *UtxoViewpoint, stxos []spentTxOut) error {
|
||||
// Sanity check the correct number of stxos are provided.
|
||||
if len(stxos) != countSpentOutputs(block) {
|
||||
return AssertError("connectBlock called with inconsistent " +
|
||||
@ -583,7 +583,7 @@ func (b *BlockChain) connectBlock(node *blockNode, block *btcutil.Block, view *U
|
||||
view.commit()
|
||||
|
||||
// This node is now the end of the best chain.
|
||||
b.bestChain.SetTip(node)
|
||||
b.dag.SetTip(node)
|
||||
|
||||
// Update the state for the best block. Notice how this replaces the
|
||||
// entire struct instead of updating the existing one. This effectively
|
||||
@ -597,9 +597,9 @@ func (b *BlockChain) connectBlock(node *blockNode, block *btcutil.Block, view *U
|
||||
// Notify the caller that the block was connected to the main chain.
|
||||
// The caller would typically want to react with actions such as
|
||||
// updating wallets.
|
||||
b.chainLock.Unlock()
|
||||
b.dagLock.Unlock()
|
||||
b.sendNotification(NTBlockConnected, block)
|
||||
b.chainLock.Lock()
|
||||
b.dagLock.Lock()
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -621,7 +621,7 @@ func countSpentOutputs(block *btcutil.Block) int {
|
||||
// This is useful when using checkpoints.
|
||||
//
|
||||
// This function MUST be called with the chain state lock held (for writes).
|
||||
func (b *BlockChain) connectToDAG(node *blockNode, parentNodes blockSet, block *btcutil.Block, flags BehaviorFlags) error {
|
||||
func (b *BlockDAG) connectToDAG(node *blockNode, parentNodes blockSet, block *btcutil.Block, flags BehaviorFlags) error {
|
||||
// Skip checks if node has already been fully validated.
|
||||
fastAdd := flags&BFFastAdd == BFFastAdd || b.index.NodeStatus(node).KnownValid()
|
||||
|
||||
@ -686,11 +686,11 @@ func (b *BlockChain) connectToDAG(node *blockNode, parentNodes blockSet, block *
|
||||
// - Latest block has a timestamp newer than 24 hours ago
|
||||
//
|
||||
// This function MUST be called with the chain state lock held (for reads).
|
||||
func (b *BlockChain) isCurrent() bool {
|
||||
func (b *BlockDAG) isCurrent() bool {
|
||||
// Not current if the latest main (best) chain height is before the
|
||||
// latest known good checkpoint (when checkpoints are enabled).
|
||||
checkpoint := b.LatestCheckpoint()
|
||||
if checkpoint != nil && b.bestChain.SelectedTip().height < checkpoint.Height {
|
||||
if checkpoint != nil && b.dag.SelectedTip().height < checkpoint.Height {
|
||||
return false
|
||||
}
|
||||
|
||||
@ -700,7 +700,7 @@ func (b *BlockChain) isCurrent() bool {
|
||||
// The chain appears to be current if none of the checks reported
|
||||
// otherwise.
|
||||
minus24Hours := b.timeSource.AdjustedTime().Add(-24 * time.Hour).Unix()
|
||||
return b.bestChain.SelectedTip().timestamp >= minus24Hours
|
||||
return b.dag.SelectedTip().timestamp >= minus24Hours
|
||||
}
|
||||
|
||||
// IsCurrent returns whether or not the chain believes it is current. Several
|
||||
@ -710,9 +710,9 @@ func (b *BlockChain) isCurrent() bool {
|
||||
// - Latest block has a timestamp newer than 24 hours ago
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (b *BlockChain) IsCurrent() bool {
|
||||
b.chainLock.RLock()
|
||||
defer b.chainLock.RUnlock()
|
||||
func (b *BlockDAG) IsCurrent() bool {
|
||||
b.dagLock.RLock()
|
||||
defer b.dagLock.RUnlock()
|
||||
|
||||
return b.isCurrent()
|
||||
}
|
||||
@ -722,7 +722,7 @@ func (b *BlockChain) IsCurrent() bool {
|
||||
// treated as immutable since it is shared by all callers.
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (b *BlockChain) BestSnapshot() *BestState {
|
||||
func (b *BlockDAG) BestSnapshot() *BestState {
|
||||
b.stateLock.RLock()
|
||||
snapshot := b.stateSnapshot
|
||||
b.stateLock.RUnlock()
|
||||
@ -731,7 +731,7 @@ func (b *BlockChain) BestSnapshot() *BestState {
|
||||
|
||||
// FetchHeader returns the block header identified by the given hash or an error
|
||||
// if it doesn't exist.
|
||||
func (b *BlockChain) FetchHeader(hash *daghash.Hash) (wire.BlockHeader, error) {
|
||||
func (b *BlockDAG) FetchHeader(hash *daghash.Hash) (wire.BlockHeader, error) {
|
||||
// Reconstruct the header from the block index if possible.
|
||||
if node := b.index.LookupNode(hash); node != nil {
|
||||
return node.Header(), nil
|
||||
@ -754,9 +754,9 @@ func (b *BlockChain) FetchHeader(hash *daghash.Hash) (wire.BlockHeader, error) {
|
||||
// the main chain.
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (b *BlockChain) MainChainHasBlock(hash *daghash.Hash) bool {
|
||||
func (b *BlockDAG) MainChainHasBlock(hash *daghash.Hash) bool {
|
||||
node := b.index.LookupNode(hash)
|
||||
return node != nil && b.bestChain.Contains(node)
|
||||
return node != nil && b.dag.Contains(node)
|
||||
}
|
||||
|
||||
// BlockLocatorFromHash returns a block locator for the passed block hash.
|
||||
@ -767,11 +767,11 @@ func (b *BlockChain) MainChainHasBlock(hash *daghash.Hash) bool {
|
||||
// the passed hash is not currently known.
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (b *BlockChain) BlockLocatorFromHash(hash *daghash.Hash) BlockLocator {
|
||||
b.chainLock.RLock()
|
||||
func (b *BlockDAG) BlockLocatorFromHash(hash *daghash.Hash) BlockLocator {
|
||||
b.dagLock.RLock()
|
||||
node := b.index.LookupNode(hash)
|
||||
locator := b.bestChain.blockLocator(node)
|
||||
b.chainLock.RUnlock()
|
||||
locator := b.dag.blockLocator(node)
|
||||
b.dagLock.RUnlock()
|
||||
return locator
|
||||
}
|
||||
|
||||
@ -779,10 +779,10 @@ func (b *BlockChain) BlockLocatorFromHash(hash *daghash.Hash) BlockLocator {
|
||||
// main (best) chain.
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (b *BlockChain) LatestBlockLocator() (BlockLocator, error) {
|
||||
b.chainLock.RLock()
|
||||
locator := b.bestChain.BlockLocator(nil)
|
||||
b.chainLock.RUnlock()
|
||||
func (b *BlockDAG) LatestBlockLocator() (BlockLocator, error) {
|
||||
b.dagLock.RLock()
|
||||
locator := b.dag.BlockLocator(nil)
|
||||
b.dagLock.RUnlock()
|
||||
return locator, nil
|
||||
}
|
||||
|
||||
@ -790,9 +790,9 @@ func (b *BlockChain) LatestBlockLocator() (BlockLocator, error) {
|
||||
// main chain.
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (b *BlockChain) BlockHeightByHash(hash *daghash.Hash) (int32, error) {
|
||||
func (b *BlockDAG) BlockHeightByHash(hash *daghash.Hash) (int32, error) {
|
||||
node := b.index.LookupNode(hash)
|
||||
if node == nil || !b.bestChain.Contains(node) {
|
||||
if node == nil || !b.dag.Contains(node) {
|
||||
str := fmt.Sprintf("block %s is not in the main chain", hash)
|
||||
return 0, errNotInMainChain(str)
|
||||
}
|
||||
@ -804,8 +804,8 @@ func (b *BlockChain) BlockHeightByHash(hash *daghash.Hash) (int32, error) {
|
||||
// main chain.
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (b *BlockChain) BlockHashByHeight(blockHeight int32) (*daghash.Hash, error) {
|
||||
node := b.bestChain.NodeByHeight(blockHeight)
|
||||
func (b *BlockDAG) BlockHashByHeight(blockHeight int32) (*daghash.Hash, error) {
|
||||
node := b.dag.NodeByHeight(blockHeight)
|
||||
if node == nil {
|
||||
str := fmt.Sprintf("no block at height %d exists", blockHeight)
|
||||
return nil, errNotInMainChain(str)
|
||||
@ -820,7 +820,7 @@ func (b *BlockChain) BlockHashByHeight(blockHeight int32) (*daghash.Hash, error)
|
||||
// height. The end height will be limited to the current main chain height.
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (b *BlockChain) HeightRange(startHeight, endHeight int32) ([]daghash.Hash, error) {
|
||||
func (b *BlockDAG) HeightRange(startHeight, endHeight int32) ([]daghash.Hash, error) {
|
||||
// Ensure requested heights are sane.
|
||||
if startHeight < 0 {
|
||||
return nil, fmt.Errorf("start height of fetch range must not "+
|
||||
@ -840,12 +840,12 @@ func (b *BlockChain) HeightRange(startHeight, endHeight int32) ([]daghash.Hash,
|
||||
|
||||
// Grab a lock on the chain view to prevent it from changing due to a
|
||||
// reorg while building the hashes.
|
||||
b.bestChain.mtx.Lock()
|
||||
defer b.bestChain.mtx.Unlock()
|
||||
b.dag.mtx.Lock()
|
||||
defer b.dag.mtx.Unlock()
|
||||
|
||||
// When the requested start height is after the most recent best chain
|
||||
// height, there is nothing to do.
|
||||
latestHeight := b.bestChain.tip().height
|
||||
latestHeight := b.dag.tip().height
|
||||
if startHeight > latestHeight {
|
||||
return nil, nil
|
||||
}
|
||||
@ -858,7 +858,7 @@ func (b *BlockChain) HeightRange(startHeight, endHeight int32) ([]daghash.Hash,
|
||||
// Fetch as many as are available within the specified range.
|
||||
hashes := make([]daghash.Hash, 0, endHeight-startHeight)
|
||||
for i := startHeight; i < endHeight; i++ {
|
||||
hashes = append(hashes, b.bestChain.nodeByHeight(i).hash)
|
||||
hashes = append(hashes, b.dag.nodeByHeight(i).hash)
|
||||
}
|
||||
return hashes, nil
|
||||
}
|
||||
@ -869,7 +869,7 @@ func (b *BlockChain) HeightRange(startHeight, endHeight int32) ([]daghash.Hash,
|
||||
// end hash must belong to a block that is known to be valid.
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (b *BlockChain) HeightToHashRange(startHeight int32,
|
||||
func (b *BlockDAG) HeightToHashRange(startHeight int32,
|
||||
endHash *daghash.Hash, maxResults int) ([]daghash.Hash, error) {
|
||||
|
||||
endNode := b.index.LookupNode(endHash)
|
||||
@ -909,7 +909,7 @@ func (b *BlockChain) HeightToHashRange(startHeight int32,
|
||||
// endHash where the block height is a positive multiple of interval.
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (b *BlockChain) IntervalBlockHashes(endHash *daghash.Hash, interval int,
|
||||
func (b *BlockDAG) IntervalBlockHashes(endHash *daghash.Hash, interval int,
|
||||
) ([]daghash.Hash, error) {
|
||||
|
||||
endNode := b.index.LookupNode(endHash)
|
||||
@ -924,16 +924,16 @@ func (b *BlockChain) IntervalBlockHashes(endHash *daghash.Hash, interval int,
|
||||
resultsLength := int(endHeight) / interval
|
||||
hashes := make([]daghash.Hash, resultsLength)
|
||||
|
||||
b.bestChain.mtx.Lock()
|
||||
defer b.bestChain.mtx.Unlock()
|
||||
b.dag.mtx.Lock()
|
||||
defer b.dag.mtx.Unlock()
|
||||
|
||||
blockNode := endNode
|
||||
for index := int(endHeight) / interval; index > 0; index-- {
|
||||
// Use the bestChain chainView for faster lookups once lookup intersects
|
||||
// Use the bestChain dagView for faster lookups once lookup intersects
|
||||
// the best chain.
|
||||
blockHeight := int32(index * interval)
|
||||
if b.bestChain.contains(blockNode) {
|
||||
blockNode = b.bestChain.nodeByHeight(blockHeight)
|
||||
if b.dag.contains(blockNode) {
|
||||
blockNode = b.dag.nodeByHeight(blockHeight)
|
||||
} else {
|
||||
blockNode = blockNode.Ancestor(blockHeight)
|
||||
}
|
||||
@ -960,7 +960,7 @@ func (b *BlockChain) IntervalBlockHashes(endHash *daghash.Hash, interval int,
|
||||
// functions.
|
||||
//
|
||||
// This function MUST be called with the chain state lock held (for reads).
|
||||
func (b *BlockChain) locateInventory(locator BlockLocator, hashStop *daghash.Hash, maxEntries uint32) (*blockNode, uint32) {
|
||||
func (b *BlockDAG) locateInventory(locator BlockLocator, hashStop *daghash.Hash, maxEntries uint32) (*blockNode, uint32) {
|
||||
// There are no block locators so a specific block is being requested
|
||||
// as identified by the stop hash.
|
||||
stopNode := b.index.LookupNode(hashStop)
|
||||
@ -976,10 +976,10 @@ func (b *BlockChain) locateInventory(locator BlockLocator, hashStop *daghash.Has
|
||||
// Find the most recent locator block hash in the main chain. In the
|
||||
// case none of the hashes in the locator are in the main chain, fall
|
||||
// back to the genesis block.
|
||||
startNode := b.bestChain.Genesis()
|
||||
startNode := b.dag.Genesis()
|
||||
for _, hash := range locator {
|
||||
node := b.index.LookupNode(hash)
|
||||
if node != nil && b.bestChain.Contains(node) {
|
||||
if node != nil && b.dag.Contains(node) {
|
||||
startNode = node
|
||||
break
|
||||
}
|
||||
@ -988,14 +988,14 @@ func (b *BlockChain) locateInventory(locator BlockLocator, hashStop *daghash.Has
|
||||
// Start at the block after the most recently known block. When there
|
||||
// is no next block it means the most recently known block is the tip of
|
||||
// the best chain, so there is nothing more to do.
|
||||
startNode = b.bestChain.Next(startNode)
|
||||
startNode = b.dag.Next(startNode)
|
||||
if startNode == nil {
|
||||
return nil, 0
|
||||
}
|
||||
|
||||
// Calculate how many entries are needed.
|
||||
total := uint32((b.bestChain.SelectedTip().height - startNode.height) + 1)
|
||||
if stopNode != nil && b.bestChain.Contains(stopNode) &&
|
||||
total := uint32((b.dag.SelectedTip().height - startNode.height) + 1)
|
||||
if stopNode != nil && b.dag.Contains(stopNode) &&
|
||||
stopNode.height >= startNode.height {
|
||||
|
||||
total = uint32((stopNode.height - startNode.height) + 1)
|
||||
@ -1014,7 +1014,7 @@ func (b *BlockChain) locateInventory(locator BlockLocator, hashStop *daghash.Has
|
||||
// See the comment on the exported function for more details on special cases.
|
||||
//
|
||||
// This function MUST be called with the chain state lock held (for reads).
|
||||
func (b *BlockChain) locateBlocks(locator BlockLocator, hashStop *daghash.Hash, maxHashes uint32) []daghash.Hash {
|
||||
func (b *BlockDAG) locateBlocks(locator BlockLocator, hashStop *daghash.Hash, maxHashes uint32) []daghash.Hash {
|
||||
// Find the node after the first known block in the locator and the
|
||||
// total number of nodes after it needed while respecting the stop hash
|
||||
// and max entries.
|
||||
@ -1027,7 +1027,7 @@ func (b *BlockChain) locateBlocks(locator BlockLocator, hashStop *daghash.Hash,
|
||||
hashes := make([]daghash.Hash, 0, total)
|
||||
for i := uint32(0); i < total; i++ {
|
||||
hashes = append(hashes, node.hash)
|
||||
node = b.bestChain.Next(node)
|
||||
node = b.dag.Next(node)
|
||||
}
|
||||
return hashes
|
||||
}
|
||||
@ -1045,10 +1045,10 @@ func (b *BlockChain) locateBlocks(locator BlockLocator, hashStop *daghash.Hash,
|
||||
// after the genesis block will be returned
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (b *BlockChain) LocateBlocks(locator BlockLocator, hashStop *daghash.Hash, maxHashes uint32) []daghash.Hash {
|
||||
b.chainLock.RLock()
|
||||
func (b *BlockDAG) LocateBlocks(locator BlockLocator, hashStop *daghash.Hash, maxHashes uint32) []daghash.Hash {
|
||||
b.dagLock.RLock()
|
||||
hashes := b.locateBlocks(locator, hashStop, maxHashes)
|
||||
b.chainLock.RUnlock()
|
||||
b.dagLock.RUnlock()
|
||||
return hashes
|
||||
}
|
||||
|
||||
@ -1059,7 +1059,7 @@ func (b *BlockChain) LocateBlocks(locator BlockLocator, hashStop *daghash.Hash,
|
||||
// See the comment on the exported function for more details on special cases.
|
||||
//
|
||||
// This function MUST be called with the chain state lock held (for reads).
|
||||
func (b *BlockChain) locateHeaders(locator BlockLocator, hashStop *daghash.Hash, maxHeaders uint32) []wire.BlockHeader {
|
||||
func (b *BlockDAG) locateHeaders(locator BlockLocator, hashStop *daghash.Hash, maxHeaders uint32) []wire.BlockHeader {
|
||||
// Find the node after the first known block in the locator and the
|
||||
// total number of nodes after it needed while respecting the stop hash
|
||||
// and max entries.
|
||||
@ -1072,7 +1072,7 @@ func (b *BlockChain) locateHeaders(locator BlockLocator, hashStop *daghash.Hash,
|
||||
headers := make([]wire.BlockHeader, 0, total)
|
||||
for i := uint32(0); i < total; i++ {
|
||||
headers = append(headers, node.Header())
|
||||
node = b.bestChain.Next(node)
|
||||
node = b.dag.Next(node)
|
||||
}
|
||||
return headers
|
||||
}
|
||||
@ -1090,10 +1090,10 @@ func (b *BlockChain) locateHeaders(locator BlockLocator, hashStop *daghash.Hash,
|
||||
// after the genesis block will be returned
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (b *BlockChain) LocateHeaders(locator BlockLocator, hashStop *daghash.Hash) []wire.BlockHeader {
|
||||
b.chainLock.RLock()
|
||||
func (b *BlockDAG) LocateHeaders(locator BlockLocator, hashStop *daghash.Hash) []wire.BlockHeader {
|
||||
b.dagLock.RLock()
|
||||
headers := b.locateHeaders(locator, hashStop, wire.MaxBlockHeadersPerMsg)
|
||||
b.chainLock.RUnlock()
|
||||
b.dagLock.RUnlock()
|
||||
return headers
|
||||
}
|
||||
|
||||
@ -1106,7 +1106,7 @@ type IndexManager interface {
|
||||
// channel parameter specifies a channel the caller can close to signal
|
||||
// that the process should be interrupted. It can be nil if that
|
||||
// behavior is not desired.
|
||||
Init(*BlockChain, <-chan struct{}) error
|
||||
Init(*BlockDAG, <-chan struct{}) error
|
||||
|
||||
// ConnectBlock is invoked when a new block has been connected to the
|
||||
// main chain.
|
||||
@ -1132,14 +1132,14 @@ type Config struct {
|
||||
// This field can be nil if the caller does not desire the behavior.
|
||||
Interrupt <-chan struct{}
|
||||
|
||||
// ChainParams identifies which chain parameters the chain is associated
|
||||
// DAGParams identifies which chain parameters the chain is associated
|
||||
// with.
|
||||
//
|
||||
// This field is required.
|
||||
ChainParams *dagconfig.Params
|
||||
DAGParams *dagconfig.Params
|
||||
|
||||
// Checkpoints hold caller-defined checkpoints that should be added to
|
||||
// the default checkpoints in ChainParams. Checkpoints must be sorted
|
||||
// the default checkpoints in DAGParams. Checkpoints must be sorted
|
||||
// by height.
|
||||
//
|
||||
// This field can be nil if the caller does not wish to specify any
|
||||
@ -1171,13 +1171,13 @@ type Config struct {
|
||||
IndexManager IndexManager
|
||||
}
|
||||
|
||||
// New returns a BlockChain instance using the provided configuration details.
|
||||
func New(config *Config) (*BlockChain, error) {
|
||||
// New returns a BlockDAG instance using the provided configuration details.
|
||||
func New(config *Config) (*BlockDAG, error) {
|
||||
// Enforce required config fields.
|
||||
if config.DB == nil {
|
||||
return nil, AssertError("blockchain.New database is nil")
|
||||
}
|
||||
if config.ChainParams == nil {
|
||||
if config.DAGParams == nil {
|
||||
return nil, AssertError("blockchain.New chain parameters nil")
|
||||
}
|
||||
if config.TimeSource == nil {
|
||||
@ -1202,15 +1202,15 @@ func New(config *Config) (*BlockChain, error) {
|
||||
}
|
||||
}
|
||||
|
||||
params := config.ChainParams
|
||||
params := config.DAGParams
|
||||
targetTimespan := int64(params.TargetTimespan / time.Second)
|
||||
targetTimePerBlock := int64(params.TargetTimePerBlock / time.Second)
|
||||
adjustmentFactor := params.RetargetAdjustmentFactor
|
||||
b := BlockChain{
|
||||
b := BlockDAG{
|
||||
checkpoints: config.Checkpoints,
|
||||
checkpointsByHeight: checkpointsByHeight,
|
||||
db: config.DB,
|
||||
chainParams: params,
|
||||
dagParams: params,
|
||||
timeSource: config.TimeSource,
|
||||
sigCache: config.SigCache,
|
||||
indexManager: config.IndexManager,
|
||||
@ -1218,7 +1218,7 @@ func New(config *Config) (*BlockChain, error) {
|
||||
maxRetargetTimespan: targetTimespan * adjustmentFactor,
|
||||
blocksPerRetarget: int32(targetTimespan / targetTimePerBlock),
|
||||
index: newBlockIndex(config.DB, params),
|
||||
bestChain: newChainView(nil),
|
||||
dag: newDAGView(nil),
|
||||
orphans: make(map[daghash.Hash]*orphanBlock),
|
||||
prevOrphans: make(map[daghash.Hash][]*orphanBlock),
|
||||
warningCaches: newThresholdCaches(vbNumBits),
|
||||
@ -1251,7 +1251,7 @@ func New(config *Config) (*BlockChain, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
bestNode := b.bestChain.SelectedTip()
|
||||
bestNode := b.dag.SelectedTip()
|
||||
log.Infof("Chain state (height %d, hash %v, totaltx %d, work %v)",
|
||||
bestNode.height, bestNode.hash, b.stateSnapshot.TotalTxns,
|
||||
bestNode.workSum)
|
@ -126,14 +126,14 @@ func TestCalcSequenceLock(t *testing.T) {
|
||||
|
||||
// Generate enough synthetic blocks to activate CSV.
|
||||
chain := newFakeDag(netParams)
|
||||
node := chain.bestChain.SelectedTip()
|
||||
node := chain.dag.SelectedTip()
|
||||
blockTime := node.Header().Timestamp
|
||||
numBlocksToActivate := (netParams.MinerConfirmationWindow * 3)
|
||||
for i := uint32(0); i < numBlocksToActivate; i++ {
|
||||
blockTime = blockTime.Add(time.Second)
|
||||
node = newFakeNode(node, blockVersion, 0, blockTime)
|
||||
chain.index.AddNode(node)
|
||||
chain.bestChain.SetTip(node)
|
||||
chain.dag.SetTip(node)
|
||||
}
|
||||
|
||||
// Create a utxo view with a fake utxo for the inputs used in the
|
||||
@ -470,7 +470,7 @@ func TestLocateInventory(t *testing.T) {
|
||||
// \-> 16a -> 17a
|
||||
tip := tstTip
|
||||
dag := newFakeDag(&dagconfig.MainNetParams)
|
||||
branch0Nodes := chainedNodes(setFromSlice(dag.bestChain.Genesis()), 18)
|
||||
branch0Nodes := chainedNodes(setFromSlice(dag.dag.Genesis()), 18)
|
||||
branch1Nodes := chainedNodes(setFromSlice(branch0Nodes[14]), 2)
|
||||
for _, node := range branch0Nodes {
|
||||
dag.index.AddNode(node)
|
||||
@ -478,17 +478,17 @@ func TestLocateInventory(t *testing.T) {
|
||||
for _, node := range branch1Nodes {
|
||||
dag.index.AddNode(node)
|
||||
}
|
||||
dag.bestChain.SetTip(tip(branch0Nodes))
|
||||
dag.dag.SetTip(tip(branch0Nodes))
|
||||
|
||||
// Create chain views for different branches of the overall chain to
|
||||
// simulate a local and remote node on different parts of the chain.
|
||||
localView := newChainView(tip(branch0Nodes))
|
||||
remoteView := newChainView(tip(branch1Nodes))
|
||||
localView := newDAGView(tip(branch0Nodes))
|
||||
remoteView := newDAGView(tip(branch1Nodes))
|
||||
|
||||
// Create a chain view for a completely unrelated block chain to
|
||||
// simulate a remote node on a totally different chain.
|
||||
unrelatedBranchNodes := chainedNodes(newSet(), 5)
|
||||
unrelatedView := newChainView(tip(unrelatedBranchNodes))
|
||||
unrelatedView := newDAGView(tip(unrelatedBranchNodes))
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
@ -772,10 +772,10 @@ func TestLocateInventory(t *testing.T) {
|
||||
if test.maxAllowed != 0 {
|
||||
// Need to use the unexported function to override the
|
||||
// max allowed for headers.
|
||||
dag.chainLock.RLock()
|
||||
dag.dagLock.RLock()
|
||||
headers = dag.locateHeaders(test.locator,
|
||||
&test.hashStop, test.maxAllowed)
|
||||
dag.chainLock.RUnlock()
|
||||
dag.dagLock.RUnlock()
|
||||
} else {
|
||||
headers = dag.LocateHeaders(test.locator,
|
||||
&test.hashStop)
|
||||
@ -810,7 +810,7 @@ func TestHeightToHashRange(t *testing.T) {
|
||||
// \-> 16a -> 17a -> 18a (unvalidated)
|
||||
tip := tstTip
|
||||
chain := newFakeDag(&dagconfig.MainNetParams)
|
||||
branch0Nodes := chainedNodes(setFromSlice(chain.bestChain.Genesis()), 18)
|
||||
branch0Nodes := chainedNodes(setFromSlice(chain.dag.Genesis()), 18)
|
||||
branch1Nodes := chainedNodes(setFromSlice(branch0Nodes[14]), 3)
|
||||
for _, node := range branch0Nodes {
|
||||
chain.index.SetStatusFlags(node, statusValid)
|
||||
@ -822,7 +822,7 @@ func TestHeightToHashRange(t *testing.T) {
|
||||
}
|
||||
chain.index.AddNode(node)
|
||||
}
|
||||
chain.bestChain.SetTip(tip(branch0Nodes))
|
||||
chain.dag.SetTip(tip(branch0Nodes))
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
@ -902,7 +902,7 @@ func TestIntervalBlockHashes(t *testing.T) {
|
||||
// \-> 16a -> 17a -> 18a (unvalidated)
|
||||
tip := tstTip
|
||||
chain := newFakeDag(&dagconfig.MainNetParams)
|
||||
branch0Nodes := chainedNodes(setFromSlice(chain.bestChain.Genesis()), 18)
|
||||
branch0Nodes := chainedNodes(setFromSlice(chain.dag.Genesis()), 18)
|
||||
branch1Nodes := chainedNodes(setFromSlice(branch0Nodes[14]), 3)
|
||||
for _, node := range branch0Nodes {
|
||||
chain.index.SetStatusFlags(node, statusValid)
|
||||
@ -914,7 +914,7 @@ func TestIntervalBlockHashes(t *testing.T) {
|
||||
}
|
||||
chain.index.AddNode(node)
|
||||
}
|
||||
chain.bestChain.SetTip(tip(branch0Nodes))
|
||||
chain.dag.SetTip(tip(branch0Nodes))
|
||||
|
||||
tests := []struct {
|
||||
name string
|
@ -971,14 +971,14 @@ func dbPutBestState(dbTx database.Tx, snapshot *BestState, workSum *big.Int) err
|
||||
// createChainState initializes both the database and the chain state to the
|
||||
// genesis block. This includes creating the necessary buckets and inserting
|
||||
// the genesis block, so it must only be called on an uninitialized database.
|
||||
func (b *BlockChain) createChainState() error {
|
||||
func (b *BlockDAG) createChainState() error {
|
||||
// Create a new node from the genesis block and set it as the best node.
|
||||
genesisBlock := btcutil.NewBlock(b.chainParams.GenesisBlock)
|
||||
genesisBlock := btcutil.NewBlock(b.dagParams.GenesisBlock)
|
||||
genesisBlock.SetHeight(0)
|
||||
header := &genesisBlock.MsgBlock().Header
|
||||
node := newBlockNode(header, nil)
|
||||
node.status = statusDataStored | statusValid
|
||||
b.bestChain.SetTip(node)
|
||||
b.dag.SetTip(node)
|
||||
|
||||
// Add the new node to the index which is used for faster lookups.
|
||||
b.index.addNode(node)
|
||||
@ -1069,7 +1069,7 @@ func (b *BlockChain) createChainState() error {
|
||||
// initChainState attempts to load and initialize the chain state from the
|
||||
// database. When the db does not yet contain any chain state, both it and the
|
||||
// chain state are initialized to the genesis block.
|
||||
func (b *BlockChain) initChainState() error {
|
||||
func (b *BlockDAG) initChainState() error {
|
||||
// Determine the state of the chain database. We may need to initialize
|
||||
// everything from scratch or upgrade certain buckets.
|
||||
var initialized, hasBlockIndex bool
|
||||
@ -1141,7 +1141,7 @@ func (b *BlockChain) initChainState() error {
|
||||
var parent *blockNode
|
||||
if lastNode == nil {
|
||||
blockHash := header.BlockHash()
|
||||
if !blockHash.IsEqual(b.chainParams.GenesisHash) {
|
||||
if !blockHash.IsEqual(b.dagParams.GenesisHash) {
|
||||
return AssertError(fmt.Sprintf("initChainState: Expected "+
|
||||
"first entry in block index to be genesis block, "+
|
||||
"found %s", blockHash))
|
||||
@ -1176,7 +1176,7 @@ func (b *BlockChain) initChainState() error {
|
||||
return AssertError(fmt.Sprintf("initChainState: cannot find "+
|
||||
"chain tip %s in block index", state.hash))
|
||||
}
|
||||
b.bestChain.SetTip(tip)
|
||||
b.dag.SetTip(tip)
|
||||
|
||||
// Load the raw block bytes for the best block.
|
||||
blockBytes, err := dbTx.FetchBlock(&state.hash)
|
||||
@ -1313,9 +1313,9 @@ func blockIndexKey(blockHash *daghash.Hash, blockHeight uint32) []byte {
|
||||
// BlockByHeight returns the block at the given height in the main chain.
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (b *BlockChain) BlockByHeight(blockHeight int32) (*btcutil.Block, error) {
|
||||
func (b *BlockDAG) BlockByHeight(blockHeight int32) (*btcutil.Block, error) {
|
||||
// Lookup the block height in the best chain.
|
||||
node := b.bestChain.NodeByHeight(blockHeight)
|
||||
node := b.dag.NodeByHeight(blockHeight)
|
||||
if node == nil {
|
||||
str := fmt.Sprintf("no block at height %d exists", blockHeight)
|
||||
return nil, errNotInMainChain(str)
|
||||
@ -1335,11 +1335,11 @@ func (b *BlockChain) BlockByHeight(blockHeight int32) (*btcutil.Block, error) {
|
||||
// the appropriate chain height set.
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (b *BlockChain) BlockByHash(hash *daghash.Hash) (*btcutil.Block, error) {
|
||||
func (b *BlockDAG) BlockByHash(hash *daghash.Hash) (*btcutil.Block, error) {
|
||||
// Lookup the block hash in block index and ensure it is in the best
|
||||
// chain.
|
||||
node := b.index.LookupNode(hash)
|
||||
if node == nil || !b.bestChain.Contains(node) {
|
||||
if node == nil || !b.dag.Contains(node) {
|
||||
str := fmt.Sprintf("block %s is not in the main chain", hash)
|
||||
return nil, errNotInMainChain(str)
|
||||
}
|
@ -31,7 +31,7 @@ func fastLog2Floor(n uint32) uint8 {
|
||||
return rv
|
||||
}
|
||||
|
||||
// chainView provides a flat view of a specific branch of the block chain from
|
||||
// dagView provides a flat view of a specific branch of the block chain from
|
||||
// its tip back to the genesis block and provides various convenience functions
|
||||
// for comparing chains.
|
||||
//
|
||||
@ -41,17 +41,17 @@ func fastLog2Floor(n uint32) uint8 {
|
||||
//
|
||||
// The chain view for the branch ending in 6a consists of:
|
||||
// genesis -> 1 -> 2 -> 3 -> 4a -> 5a -> 6a
|
||||
type chainView struct {
|
||||
type dagView struct {
|
||||
mtx sync.Mutex
|
||||
nodes []*blockNode
|
||||
}
|
||||
|
||||
// newChainView returns a new chain view for the given tip block node. Passing
|
||||
// newDAGView returns a new chain view for the given tip block node. Passing
|
||||
// nil as the tip will result in a chain view that is not initialized. The tip
|
||||
// can be updated at any time via the setTip function.
|
||||
func newChainView(tip *blockNode) *chainView {
|
||||
func newDAGView(tip *blockNode) *dagView {
|
||||
// The mutex is intentionally not held since this is a constructor.
|
||||
var c chainView
|
||||
var c dagView
|
||||
c.setTip(tip)
|
||||
return &c
|
||||
}
|
||||
@ -61,7 +61,7 @@ func newChainView(tip *blockNode) *chainView {
|
||||
// held.
|
||||
//
|
||||
// This function MUST be called with the view mutex locked (for reads).
|
||||
func (c *chainView) genesis() *blockNode {
|
||||
func (c *dagView) genesis() *blockNode {
|
||||
if len(c.nodes) == 0 {
|
||||
return nil
|
||||
}
|
||||
@ -72,7 +72,7 @@ func (c *chainView) genesis() *blockNode {
|
||||
// Genesis returns the genesis block for the chain view.
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (c *chainView) Genesis() *blockNode {
|
||||
func (c *dagView) Genesis() *blockNode {
|
||||
c.mtx.Lock()
|
||||
genesis := c.genesis()
|
||||
c.mtx.Unlock()
|
||||
@ -84,7 +84,7 @@ func (c *chainView) Genesis() *blockNode {
|
||||
// it is up to the caller to ensure the lock is held.
|
||||
//
|
||||
// This function MUST be called with the view mutex locked (for reads).
|
||||
func (c *chainView) tip() *blockNode {
|
||||
func (c *dagView) tip() *blockNode {
|
||||
if len(c.nodes) == 0 {
|
||||
return nil
|
||||
}
|
||||
@ -96,7 +96,7 @@ func (c *chainView) tip() *blockNode {
|
||||
// an empty slice if there is no tip.
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (c *chainView) Tips() blockSet {
|
||||
func (c *dagView) Tips() blockSet {
|
||||
c.mtx.Lock()
|
||||
tip := c.tip()
|
||||
c.mtx.Unlock()
|
||||
@ -112,7 +112,7 @@ func (c *chainView) Tips() blockSet {
|
||||
// It will return nil if there is no tip.
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (c *chainView) SelectedTip() *blockNode {
|
||||
func (c *dagView) SelectedTip() *blockNode {
|
||||
return c.Tips().first()
|
||||
}
|
||||
|
||||
@ -124,7 +124,7 @@ func (c *chainView) SelectedTip() *blockNode {
|
||||
// up to the caller to ensure the lock is held.
|
||||
//
|
||||
// This function MUST be called with the view mutex locked (for writes).
|
||||
func (c *chainView) setTip(node *blockNode) {
|
||||
func (c *dagView) setTip(node *blockNode) {
|
||||
if node == nil {
|
||||
// Keep the backing array around for potential future use.
|
||||
c.nodes = c.nodes[:0]
|
||||
@ -165,7 +165,7 @@ func (c *chainView) setTip(node *blockNode) {
|
||||
// tips is efficient.
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (c *chainView) SetTip(node *blockNode) {
|
||||
func (c *dagView) SetTip(node *blockNode) {
|
||||
c.mtx.Lock()
|
||||
c.setTip(node)
|
||||
c.mtx.Unlock()
|
||||
@ -177,7 +177,7 @@ func (c *chainView) SetTip(node *blockNode) {
|
||||
// to the caller to ensure the lock is held.
|
||||
//
|
||||
// This function MUST be called with the view mutex locked (for reads).
|
||||
func (c *chainView) height() int32 {
|
||||
func (c *dagView) height() int32 {
|
||||
return int32(len(c.nodes) - 1)
|
||||
}
|
||||
|
||||
@ -186,7 +186,7 @@ func (c *chainView) height() int32 {
|
||||
// initialized).
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (c *chainView) Height() int32 {
|
||||
func (c *dagView) Height() int32 {
|
||||
c.mtx.Lock()
|
||||
height := c.height()
|
||||
c.mtx.Unlock()
|
||||
@ -198,7 +198,7 @@ func (c *chainView) Height() int32 {
|
||||
// version in that it is up to the caller to ensure the lock is held.
|
||||
//
|
||||
// This function MUST be called with the view mutex locked (for reads).
|
||||
func (c *chainView) nodeByHeight(height int32) *blockNode {
|
||||
func (c *dagView) nodeByHeight(height int32) *blockNode {
|
||||
if height < 0 || height >= int32(len(c.nodes)) {
|
||||
return nil
|
||||
}
|
||||
@ -210,7 +210,7 @@ func (c *chainView) nodeByHeight(height int32) *blockNode {
|
||||
// returned if the height does not exist.
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (c *chainView) NodeByHeight(height int32) *blockNode {
|
||||
func (c *dagView) NodeByHeight(height int32) *blockNode {
|
||||
c.mtx.Lock()
|
||||
node := c.nodeByHeight(height)
|
||||
c.mtx.Unlock()
|
||||
@ -221,7 +221,7 @@ func (c *chainView) NodeByHeight(height int32) *blockNode {
|
||||
// views (tip set to nil) are considered equal.
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (c *chainView) Equals(other *chainView) bool {
|
||||
func (c *dagView) Equals(other *dagView) bool {
|
||||
c.mtx.Lock()
|
||||
other.mtx.Lock()
|
||||
equals := len(c.nodes) == len(other.nodes) && c.tip() == other.tip()
|
||||
@ -235,7 +235,7 @@ func (c *chainView) Equals(other *chainView) bool {
|
||||
// caller to ensure the lock is held.
|
||||
//
|
||||
// This function MUST be called with the view mutex locked (for reads).
|
||||
func (c *chainView) contains(node *blockNode) bool {
|
||||
func (c *dagView) contains(node *blockNode) bool {
|
||||
return c.nodeByHeight(node.height) == node
|
||||
}
|
||||
|
||||
@ -243,7 +243,7 @@ func (c *chainView) contains(node *blockNode) bool {
|
||||
// node.
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (c *chainView) Contains(node *blockNode) bool {
|
||||
func (c *dagView) Contains(node *blockNode) bool {
|
||||
c.mtx.Lock()
|
||||
contains := c.contains(node)
|
||||
c.mtx.Unlock()
|
||||
@ -258,7 +258,7 @@ func (c *chainView) Contains(node *blockNode) bool {
|
||||
// See the comment on the exported function for more details.
|
||||
//
|
||||
// This function MUST be called with the view mutex locked (for reads).
|
||||
func (c *chainView) next(node *blockNode) *blockNode {
|
||||
func (c *dagView) next(node *blockNode) *blockNode {
|
||||
if node == nil || !c.contains(node) {
|
||||
return nil
|
||||
}
|
||||
@ -283,7 +283,7 @@ func (c *chainView) next(node *blockNode) *blockNode {
|
||||
// of the view.
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (c *chainView) Next(node *blockNode) *blockNode {
|
||||
func (c *dagView) Next(node *blockNode) *blockNode {
|
||||
c.mtx.Lock()
|
||||
next := c.next(node)
|
||||
c.mtx.Unlock()
|
||||
@ -298,7 +298,7 @@ func (c *chainView) Next(node *blockNode) *blockNode {
|
||||
// See the exported FindFork comments for more details.
|
||||
//
|
||||
// This function MUST be called with the view mutex locked (for reads).
|
||||
func (c *chainView) findFork(node *blockNode) *blockNode {
|
||||
func (c *dagView) findFork(node *blockNode) *blockNode {
|
||||
// No fork point for node that doesn't exist.
|
||||
if node == nil {
|
||||
return nil
|
||||
@ -346,7 +346,7 @@ func (c *chainView) findFork(node *blockNode) *blockNode {
|
||||
// the branch formed by the view.
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (c *chainView) FindFork(node *blockNode) *blockNode {
|
||||
func (c *dagView) FindFork(node *blockNode) *blockNode {
|
||||
c.mtx.Lock()
|
||||
fork := c.findFork(node)
|
||||
c.mtx.Unlock()
|
||||
@ -361,7 +361,7 @@ func (c *chainView) FindFork(node *blockNode) *blockNode {
|
||||
// See the exported BlockLocator function comments for more details.
|
||||
//
|
||||
// This function MUST be called with the view mutex locked (for reads).
|
||||
func (c *chainView) blockLocator(node *blockNode) BlockLocator {
|
||||
func (c *dagView) blockLocator(node *blockNode) BlockLocator {
|
||||
// Use the current tip if requested.
|
||||
if node == nil {
|
||||
node = c.tip()
|
||||
@ -428,7 +428,7 @@ func (c *chainView) blockLocator(node *blockNode) BlockLocator {
|
||||
// locator.
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (c *chainView) BlockLocator(node *blockNode) BlockLocator {
|
||||
func (c *dagView) BlockLocator(node *blockNode) BlockLocator {
|
||||
c.mtx.Lock()
|
||||
locator := c.blockLocator(node)
|
||||
c.mtx.Unlock()
|
@ -82,48 +82,48 @@ func TestChainView(t *testing.T) {
|
||||
tip := tstTip
|
||||
tests := []struct {
|
||||
name string
|
||||
view *chainView // active view
|
||||
view *dagView // active view
|
||||
genesis *blockNode // expected genesis block of active view
|
||||
tip *blockNode // expected tip of active view
|
||||
side *chainView // side chain view
|
||||
side *dagView // side chain view
|
||||
sideTip *blockNode // expected tip of side chain view
|
||||
fork *blockNode // expected fork node
|
||||
contains []*blockNode // expected nodes in active view
|
||||
noContains []*blockNode // expected nodes NOT in active view
|
||||
equal *chainView // view expected equal to active view
|
||||
unequal *chainView // view expected NOT equal to active
|
||||
equal *dagView // view expected equal to active view
|
||||
unequal *dagView // view expected NOT equal to active
|
||||
locator BlockLocator // expected locator for active view tip
|
||||
}{
|
||||
{
|
||||
// Create a view for branch 0 as the active chain and
|
||||
// another view for branch 1 as the side chain.
|
||||
name: "chain0-chain1",
|
||||
view: newChainView(tip(branch0Nodes)),
|
||||
view: newDAGView(tip(branch0Nodes)),
|
||||
genesis: branch0Nodes[0],
|
||||
tip: tip(branch0Nodes),
|
||||
side: newChainView(tip(branch1Nodes)),
|
||||
side: newDAGView(tip(branch1Nodes)),
|
||||
sideTip: tip(branch1Nodes),
|
||||
fork: branch0Nodes[1],
|
||||
contains: branch0Nodes,
|
||||
noContains: branch1Nodes,
|
||||
equal: newChainView(tip(branch0Nodes)),
|
||||
unequal: newChainView(tip(branch1Nodes)),
|
||||
equal: newDAGView(tip(branch0Nodes)),
|
||||
unequal: newDAGView(tip(branch1Nodes)),
|
||||
locator: locatorHashes(branch0Nodes, 4, 3, 2, 1, 0),
|
||||
},
|
||||
{
|
||||
// Create a view for branch 1 as the active chain and
|
||||
// another view for branch 2 as the side chain.
|
||||
name: "chain1-chain2",
|
||||
view: newChainView(tip(branch1Nodes)),
|
||||
view: newDAGView(tip(branch1Nodes)),
|
||||
genesis: branch0Nodes[0],
|
||||
tip: tip(branch1Nodes),
|
||||
side: newChainView(tip(branch2Nodes)),
|
||||
side: newDAGView(tip(branch2Nodes)),
|
||||
sideTip: tip(branch2Nodes),
|
||||
fork: branch1Nodes[0],
|
||||
contains: branch1Nodes,
|
||||
noContains: branch2Nodes,
|
||||
equal: newChainView(tip(branch1Nodes)),
|
||||
unequal: newChainView(tip(branch2Nodes)),
|
||||
equal: newDAGView(tip(branch1Nodes)),
|
||||
unequal: newDAGView(tip(branch2Nodes)),
|
||||
locator: zipLocators(
|
||||
locatorHashes(branch1Nodes, 24, 23, 22, 21, 20,
|
||||
19, 18, 17, 16, 15, 14, 13, 11, 7),
|
||||
@ -133,16 +133,16 @@ func TestChainView(t *testing.T) {
|
||||
// Create a view for branch 2 as the active chain and
|
||||
// another view for branch 0 as the side chain.
|
||||
name: "chain2-chain0",
|
||||
view: newChainView(tip(branch2Nodes)),
|
||||
view: newDAGView(tip(branch2Nodes)),
|
||||
genesis: branch0Nodes[0],
|
||||
tip: tip(branch2Nodes),
|
||||
side: newChainView(tip(branch0Nodes)),
|
||||
side: newDAGView(tip(branch0Nodes)),
|
||||
sideTip: tip(branch0Nodes),
|
||||
fork: branch0Nodes[1],
|
||||
contains: branch2Nodes,
|
||||
noContains: branch0Nodes[2:],
|
||||
equal: newChainView(tip(branch2Nodes)),
|
||||
unequal: newChainView(tip(branch0Nodes)),
|
||||
equal: newDAGView(tip(branch2Nodes)),
|
||||
unequal: newDAGView(tip(branch0Nodes)),
|
||||
locator: zipLocators(
|
||||
locatorHashes(branch2Nodes, 2, 1, 0),
|
||||
locatorHashes(branch1Nodes, 0),
|
||||
@ -308,8 +308,8 @@ func TestChainViewForkCorners(t *testing.T) {
|
||||
unrelatedBranchNodes := chainedNodes(nil, 7)
|
||||
|
||||
// Create chain views for the two unrelated histories.
|
||||
view1 := newChainView(tstTip(branchNodes))
|
||||
view2 := newChainView(tstTip(unrelatedBranchNodes))
|
||||
view1 := newDAGView(tstTip(branchNodes))
|
||||
view2 := newDAGView(tstTip(unrelatedBranchNodes))
|
||||
|
||||
// Ensure attempting to find a fork point with a node that doesn't exist
|
||||
// doesn't produce a node.
|
||||
@ -346,7 +346,7 @@ func TestChainViewSetTip(t *testing.T) {
|
||||
tip := tstTip
|
||||
tests := []struct {
|
||||
name string
|
||||
view *chainView // active view
|
||||
view *dagView // active view
|
||||
tips []*blockNode // tips to set
|
||||
contains [][]*blockNode // expected nodes in view for each tip
|
||||
}{
|
||||
@ -354,7 +354,7 @@ func TestChainViewSetTip(t *testing.T) {
|
||||
// Create an empty view and set the tip to increasingly
|
||||
// longer chains.
|
||||
name: "increasing",
|
||||
view: newChainView(nil),
|
||||
view: newDAGView(nil),
|
||||
tips: []*blockNode{tip(branch0Nodes), tip(branch1Nodes)},
|
||||
contains: [][]*blockNode{branch0Nodes, branch1Nodes},
|
||||
},
|
||||
@ -362,7 +362,7 @@ func TestChainViewSetTip(t *testing.T) {
|
||||
// Create a view with a longer chain and set the tip to
|
||||
// increasingly shorter chains.
|
||||
name: "decreasing",
|
||||
view: newChainView(tip(branch1Nodes)),
|
||||
view: newDAGView(tip(branch1Nodes)),
|
||||
tips: []*blockNode{tip(branch0Nodes), nil},
|
||||
contains: [][]*blockNode{branch0Nodes, nil},
|
||||
},
|
||||
@ -371,7 +371,7 @@ func TestChainViewSetTip(t *testing.T) {
|
||||
// a longer chain followed by setting it back to the
|
||||
// shorter chain.
|
||||
name: "small-large-small",
|
||||
view: newChainView(tip(branch0Nodes)),
|
||||
view: newDAGView(tip(branch0Nodes)),
|
||||
tips: []*blockNode{tip(branch1Nodes), tip(branch0Nodes)},
|
||||
contains: [][]*blockNode{branch1Nodes, branch0Nodes},
|
||||
},
|
||||
@ -380,7 +380,7 @@ func TestChainViewSetTip(t *testing.T) {
|
||||
// a smaller chain followed by setting it back to the
|
||||
// longer chain.
|
||||
name: "large-small-large",
|
||||
view: newChainView(tip(branch1Nodes)),
|
||||
view: newDAGView(tip(branch1Nodes)),
|
||||
tips: []*blockNode{tip(branch0Nodes), tip(branch1Nodes)},
|
||||
contains: [][]*blockNode{branch0Nodes, branch1Nodes},
|
||||
},
|
||||
@ -415,8 +415,8 @@ testLoop:
|
||||
// as expected.
|
||||
func TestChainViewNil(t *testing.T) {
|
||||
// Ensure two unininitialized views are considered equal.
|
||||
view := newChainView(nil)
|
||||
if !view.Equals(newChainView(nil)) {
|
||||
view := newDAGView(nil)
|
||||
if !view.Equals(newDAGView(nil)) {
|
||||
t.Fatal("uninitialized nil views unequal")
|
||||
}
|
||||
|
@ -156,19 +156,19 @@ func CalcWork(bits uint32) *big.Int {
|
||||
// can have given starting difficulty bits and a duration. It is mainly used to
|
||||
// verify that claimed proof of work by a block is sane as compared to a
|
||||
// known good checkpoint.
|
||||
func (b *BlockChain) calcEasiestDifficulty(bits uint32, duration time.Duration) uint32 {
|
||||
func (b *BlockDAG) calcEasiestDifficulty(bits uint32, duration time.Duration) uint32 {
|
||||
// Convert types used in the calculations below.
|
||||
durationVal := int64(duration / time.Second)
|
||||
adjustmentFactor := big.NewInt(b.chainParams.RetargetAdjustmentFactor)
|
||||
adjustmentFactor := big.NewInt(b.dagParams.RetargetAdjustmentFactor)
|
||||
|
||||
// The test network rules allow minimum difficulty blocks after more
|
||||
// than twice the desired amount of time needed to generate a block has
|
||||
// elapsed.
|
||||
if b.chainParams.ReduceMinDifficulty {
|
||||
reductionTime := int64(b.chainParams.MinDiffReductionTime /
|
||||
if b.dagParams.ReduceMinDifficulty {
|
||||
reductionTime := int64(b.dagParams.MinDiffReductionTime /
|
||||
time.Second)
|
||||
if durationVal > reductionTime {
|
||||
return b.chainParams.PowLimitBits
|
||||
return b.dagParams.PowLimitBits
|
||||
}
|
||||
}
|
||||
|
||||
@ -177,14 +177,14 @@ func (b *BlockChain) calcEasiestDifficulty(bits uint32, duration time.Duration)
|
||||
// the number of retargets for the duration and starting difficulty
|
||||
// multiplied by the max adjustment factor.
|
||||
newTarget := CompactToBig(bits)
|
||||
for durationVal > 0 && newTarget.Cmp(b.chainParams.PowLimit) < 0 {
|
||||
for durationVal > 0 && newTarget.Cmp(b.dagParams.PowLimit) < 0 {
|
||||
newTarget.Mul(newTarget, adjustmentFactor)
|
||||
durationVal -= b.maxRetargetTimespan
|
||||
}
|
||||
|
||||
// Limit new value to the proof of work limit.
|
||||
if newTarget.Cmp(b.chainParams.PowLimit) > 0 {
|
||||
newTarget.Set(b.chainParams.PowLimit)
|
||||
if newTarget.Cmp(b.dagParams.PowLimit) > 0 {
|
||||
newTarget.Set(b.dagParams.PowLimit)
|
||||
}
|
||||
|
||||
return BigToCompact(newTarget)
|
||||
@ -194,19 +194,19 @@ func (b *BlockChain) calcEasiestDifficulty(bits uint32, duration time.Duration)
|
||||
// did not have the special testnet minimum difficulty rule applied.
|
||||
//
|
||||
// This function MUST be called with the chain state lock held (for writes).
|
||||
func (b *BlockChain) findPrevTestNetDifficulty(startNode *blockNode) uint32 {
|
||||
func (b *BlockDAG) findPrevTestNetDifficulty(startNode *blockNode) uint32 {
|
||||
// Search backwards through the chain for the last block without
|
||||
// the special rule applied.
|
||||
iterNode := startNode
|
||||
for iterNode != nil && iterNode.height%b.blocksPerRetarget != 0 &&
|
||||
iterNode.bits == b.chainParams.PowLimitBits {
|
||||
iterNode.bits == b.dagParams.PowLimitBits {
|
||||
|
||||
iterNode = iterNode.selectedParent
|
||||
}
|
||||
|
||||
// Return the found difficulty or the minimum difficulty if no
|
||||
// appropriate block was found.
|
||||
lastBits := b.chainParams.PowLimitBits
|
||||
lastBits := b.dagParams.PowLimitBits
|
||||
if iterNode != nil {
|
||||
lastBits = iterNode.bits
|
||||
}
|
||||
@ -218,10 +218,10 @@ func (b *BlockChain) findPrevTestNetDifficulty(startNode *blockNode) uint32 {
|
||||
// This function differs from the exported CalcNextRequiredDifficulty in that
|
||||
// the exported version uses the current best chain as the previous block node
|
||||
// while this function accepts any block node.
|
||||
func (b *BlockChain) calcNextRequiredDifficulty(lastNode *blockNode, newBlockTime time.Time) (uint32, error) {
|
||||
func (b *BlockDAG) calcNextRequiredDifficulty(lastNode *blockNode, newBlockTime time.Time) (uint32, error) {
|
||||
// Genesis block.
|
||||
if lastNode == nil {
|
||||
return b.chainParams.PowLimitBits, nil
|
||||
return b.dagParams.PowLimitBits, nil
|
||||
}
|
||||
|
||||
// Return the previous block's difficulty requirements if this block
|
||||
@ -230,14 +230,14 @@ func (b *BlockChain) calcNextRequiredDifficulty(lastNode *blockNode, newBlockTim
|
||||
// For networks that support it, allow special reduction of the
|
||||
// required difficulty once too much time has elapsed without
|
||||
// mining a block.
|
||||
if b.chainParams.ReduceMinDifficulty {
|
||||
if b.dagParams.ReduceMinDifficulty {
|
||||
// Return minimum difficulty when more than the desired
|
||||
// amount of time has elapsed without mining a block.
|
||||
reductionTime := int64(b.chainParams.MinDiffReductionTime /
|
||||
reductionTime := int64(b.dagParams.MinDiffReductionTime /
|
||||
time.Second)
|
||||
allowMinTime := lastNode.timestamp + reductionTime
|
||||
if newBlockTime.Unix() > allowMinTime {
|
||||
return b.chainParams.PowLimitBits, nil
|
||||
return b.dagParams.PowLimitBits, nil
|
||||
}
|
||||
|
||||
// The block was mined within the desired timeframe, so
|
||||
@ -275,12 +275,12 @@ func (b *BlockChain) calcNextRequiredDifficulty(lastNode *blockNode, newBlockTim
|
||||
// result.
|
||||
oldTarget := CompactToBig(lastNode.bits)
|
||||
newTarget := new(big.Int).Mul(oldTarget, big.NewInt(adjustedTimespan))
|
||||
targetTimeSpan := int64(b.chainParams.TargetTimespan / time.Second)
|
||||
targetTimeSpan := int64(b.dagParams.TargetTimespan / time.Second)
|
||||
newTarget.Div(newTarget, big.NewInt(targetTimeSpan))
|
||||
|
||||
// Limit new value to the proof of work limit.
|
||||
if newTarget.Cmp(b.chainParams.PowLimit) > 0 {
|
||||
newTarget.Set(b.chainParams.PowLimit)
|
||||
if newTarget.Cmp(b.dagParams.PowLimit) > 0 {
|
||||
newTarget.Set(b.dagParams.PowLimit)
|
||||
}
|
||||
|
||||
// Log new target difficulty and return it. The new target logging is
|
||||
@ -294,7 +294,7 @@ func (b *BlockChain) calcNextRequiredDifficulty(lastNode *blockNode, newBlockTim
|
||||
log.Debugf("Actual timespan %v, adjusted timespan %v, target timespan %v",
|
||||
time.Duration(actualTimespan)*time.Second,
|
||||
time.Duration(adjustedTimespan)*time.Second,
|
||||
b.chainParams.TargetTimespan)
|
||||
b.dagParams.TargetTimespan)
|
||||
|
||||
return newTargetBits, nil
|
||||
}
|
||||
@ -304,9 +304,9 @@ func (b *BlockChain) calcNextRequiredDifficulty(lastNode *blockNode, newBlockTim
|
||||
// rules.
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (b *BlockChain) CalcNextRequiredDifficulty(timestamp time.Time) (uint32, error) {
|
||||
b.chainLock.Lock()
|
||||
difficulty, err := b.calcNextRequiredDifficulty(b.bestChain.SelectedTip(), timestamp)
|
||||
b.chainLock.Unlock()
|
||||
func (b *BlockDAG) CalcNextRequiredDifficulty(timestamp time.Time) (uint32, error) {
|
||||
b.dagLock.Lock()
|
||||
difficulty, err := b.calcNextRequiredDifficulty(b.dag.SelectedTip(), timestamp)
|
||||
b.dagLock.Unlock()
|
||||
return difficulty, err
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ func ExampleBlockChain_ProcessBlock() {
|
||||
defer os.RemoveAll(dbPath)
|
||||
defer db.Close()
|
||||
|
||||
// Create a new BlockChain instance using the underlying database for
|
||||
// Create a new BlockDAG instance using the underlying database for
|
||||
// the main bitcoin network. This example does not demonstrate some
|
||||
// of the other available configuration options such as specifying a
|
||||
// notification callback and signature cache. Also, the caller would
|
||||
@ -46,9 +46,9 @@ func ExampleBlockChain_ProcessBlock() {
|
||||
// values obtained from other peers on the network so the local time is
|
||||
// adjusted to be in agreement with other peers.
|
||||
chain, err := blockdag.New(&blockdag.Config{
|
||||
DB: db,
|
||||
ChainParams: &dagconfig.MainNetParams,
|
||||
TimeSource: blockdag.NewMedianTime(),
|
||||
DB: db,
|
||||
DAGParams: &dagconfig.MainNetParams,
|
||||
TimeSource: blockdag.NewMedianTime(),
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to create chain instance: %v\n", err)
|
||||
|
@ -60,7 +60,7 @@ func isSupportedDbType(dbType string) bool {
|
||||
// chainSetup is used to create a new db and chain instance with the genesis
|
||||
// block already inserted. In addition to the new chain instance, it returns
|
||||
// a teardown function the caller should invoke when done testing to clean up.
|
||||
func chainSetup(dbName string, params *dagconfig.Params) (*blockdag.BlockChain, func(), error) {
|
||||
func chainSetup(dbName string, params *dagconfig.Params) (*blockdag.BlockDAG, func(), error) {
|
||||
if !isSupportedDbType(testDbType) {
|
||||
return nil, nil, fmt.Errorf("unsupported db type %v", testDbType)
|
||||
}
|
||||
@ -116,7 +116,7 @@ func chainSetup(dbName string, params *dagconfig.Params) (*blockdag.BlockChain,
|
||||
// Create the main chain instance.
|
||||
chain, err := blockdag.New(&blockdag.Config{
|
||||
DB: db,
|
||||
ChainParams: ¶msCopy,
|
||||
DAGParams: ¶msCopy,
|
||||
Checkpoints: nil,
|
||||
TimeSource: blockdag.NewMedianTime(),
|
||||
SigCache: txscript.NewSigCache(1000),
|
||||
|
@ -552,8 +552,8 @@ type AddrIndex struct {
|
||||
// The following fields are set when the instance is created and can't
|
||||
// be changed afterwards, so there is no need to protect them with a
|
||||
// separate mutex.
|
||||
db database.DB
|
||||
chainParams *dagconfig.Params
|
||||
db database.DB
|
||||
dagParams *dagconfig.Params
|
||||
|
||||
// The following fields are used to quickly link transactions and
|
||||
// addresses that have not been included into a block yet when an
|
||||
@ -633,7 +633,7 @@ func (idx *AddrIndex) indexPkScript(data writeIndexData, pkScript []byte, txIdx
|
||||
// Nothing to index if the script is non-standard or otherwise doesn't
|
||||
// contain any addresses.
|
||||
_, addrs, _, err := txscript.ExtractPkScriptAddrs(pkScript,
|
||||
idx.chainParams)
|
||||
idx.dagParams)
|
||||
if err != nil || len(addrs) == 0 {
|
||||
return
|
||||
}
|
||||
@ -796,7 +796,7 @@ func (idx *AddrIndex) indexUnconfirmedAddresses(pkScript []byte, tx *btcutil.Tx)
|
||||
// script fails to parse and it was already validated before being
|
||||
// admitted to the mempool.
|
||||
_, addresses, _, _ := txscript.ExtractPkScriptAddrs(pkScript,
|
||||
idx.chainParams)
|
||||
idx.dagParams)
|
||||
for _, addr := range addresses {
|
||||
// Ignore unsupported address types.
|
||||
addrKey, err := addrToKey(addr)
|
||||
@ -914,12 +914,12 @@ func (idx *AddrIndex) UnconfirmedTxnsForAddress(addr btcutil.Address) []*btcutil
|
||||
// It implements the Indexer interface which plugs into the IndexManager that in
|
||||
// turn is used by the blockchain package. This allows the index to be
|
||||
// seamlessly maintained along with the chain.
|
||||
func NewAddrIndex(db database.DB, chainParams *dagconfig.Params) *AddrIndex {
|
||||
func NewAddrIndex(db database.DB, dagParams *dagconfig.Params) *AddrIndex {
|
||||
return &AddrIndex{
|
||||
db: db,
|
||||
chainParams: chainParams,
|
||||
txnsByAddr: make(map[[addrKeySize]byte]map[daghash.Hash]*btcutil.Tx),
|
||||
addrsByTx: make(map[daghash.Hash]map[[addrKeySize]byte]struct{}),
|
||||
db: db,
|
||||
dagParams: dagParams,
|
||||
txnsByAddr: make(map[[addrKeySize]byte]map[daghash.Hash]*btcutil.Tx),
|
||||
addrsByTx: make(map[daghash.Hash]map[[addrKeySize]byte]struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,8 +79,8 @@ func dbDeleteFilterIdxEntry(dbTx database.Tx, key []byte, h *daghash.Hash) error
|
||||
|
||||
// CfIndex implements a committed filter (cf) by hash index.
|
||||
type CfIndex struct {
|
||||
db database.DB
|
||||
chainParams *dagconfig.Params
|
||||
db database.DB
|
||||
dagParams *dagconfig.Params
|
||||
}
|
||||
|
||||
// Ensure the CfIndex type implements the Indexer interface.
|
||||
@ -344,8 +344,8 @@ func (idx *CfIndex) FilterHashesByBlockHashes(blockHashes []*daghash.Hash,
|
||||
// It implements the Indexer interface which plugs into the IndexManager that
|
||||
// in turn is used by the blockchain package. This allows the index to be
|
||||
// seamlessly maintained along with the chain.
|
||||
func NewCfIndex(db database.DB, chainParams *dagconfig.Params) *CfIndex {
|
||||
return &CfIndex{db: db, chainParams: chainParams}
|
||||
func NewCfIndex(db database.DB, dagParams *dagconfig.Params) *CfIndex {
|
||||
return &CfIndex{db: db, dagParams: dagParams}
|
||||
}
|
||||
|
||||
// DropCfIndex drops the CF index from the provided database if exists.
|
||||
|
@ -229,7 +229,7 @@ func (m *Manager) maybeCreateIndexes(dbTx database.Tx) error {
|
||||
// catch up due to the I/O contention.
|
||||
//
|
||||
// This is part of the blockchain.IndexManager interface.
|
||||
func (m *Manager) Init(chain *blockdag.BlockChain, interrupt <-chan struct{}) error {
|
||||
func (m *Manager) Init(chain *blockdag.BlockDAG, interrupt <-chan struct{}) error {
|
||||
// Nothing to do when no indexes are enabled.
|
||||
if len(m.enabledIndexes) == 0 {
|
||||
return nil
|
||||
|
@ -61,7 +61,7 @@ type Notification struct {
|
||||
// Subscribe to block chain notifications. Registers a callback to be executed
|
||||
// when various events take place. See the documentation on Notification and
|
||||
// NotificationType for details on the types and contents of notifications.
|
||||
func (b *BlockChain) Subscribe(callback NotificationCallback) {
|
||||
func (b *BlockDAG) Subscribe(callback NotificationCallback) {
|
||||
b.notificationsLock.Lock()
|
||||
b.notifications = append(b.notifications, callback)
|
||||
b.notificationsLock.Unlock()
|
||||
@ -70,7 +70,7 @@ func (b *BlockChain) Subscribe(callback NotificationCallback) {
|
||||
// sendNotification sends a notification with the passed type and data if the
|
||||
// caller requested notifications by providing a callback function in the call
|
||||
// to New.
|
||||
func (b *BlockChain) sendNotification(typ NotificationType, data interface{}) {
|
||||
func (b *BlockDAG) sendNotification(typ NotificationType, data interface{}) {
|
||||
// Generate and send the notification.
|
||||
n := Notification{Type: typ, Data: data}
|
||||
b.notificationsLock.RLock()
|
||||
|
@ -37,7 +37,7 @@ const (
|
||||
// the main chain or any side chains.
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (b *BlockChain) blockExists(hash *daghash.Hash) (bool, error) {
|
||||
func (b *BlockDAG) blockExists(hash *daghash.Hash) (bool, error) {
|
||||
// Check block index first (could be main chain or side chain blocks).
|
||||
if b.index.HaveBlock(hash) {
|
||||
return true, nil
|
||||
@ -80,7 +80,7 @@ func (b *BlockChain) blockExists(hash *daghash.Hash) (bool, error) {
|
||||
// are needed to pass along to maybeAcceptBlock.
|
||||
//
|
||||
// This function MUST be called with the chain state lock held (for writes).
|
||||
func (b *BlockChain) processOrphans(hash *daghash.Hash, flags BehaviorFlags) error {
|
||||
func (b *BlockDAG) processOrphans(hash *daghash.Hash, flags BehaviorFlags) error {
|
||||
// Start with processing at least the passed hash. Leave a little room
|
||||
// for additional orphan blocks that need to be processed without
|
||||
// needing to grow the array in the common case.
|
||||
@ -138,9 +138,9 @@ func (b *BlockChain) processOrphans(hash *daghash.Hash, flags BehaviorFlags) err
|
||||
// whether or not the block is an orphan.
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (b *BlockChain) ProcessBlock(block *btcutil.Block, flags BehaviorFlags) (bool, error) {
|
||||
b.chainLock.Lock()
|
||||
defer b.chainLock.Unlock()
|
||||
func (b *BlockDAG) ProcessBlock(block *btcutil.Block, flags BehaviorFlags) (bool, error) {
|
||||
b.dagLock.Lock()
|
||||
defer b.dagLock.Unlock()
|
||||
|
||||
fastAdd := flags&BFFastAdd == BFFastAdd
|
||||
|
||||
@ -164,7 +164,7 @@ func (b *BlockChain) ProcessBlock(block *btcutil.Block, flags BehaviorFlags) (bo
|
||||
}
|
||||
|
||||
// Perform preliminary sanity checks on the block and its transactions.
|
||||
err = checkBlockSanity(block, b.chainParams.PowLimit, b.timeSource, flags)
|
||||
err = checkBlockSanity(block, b.dagParams.PowLimit, b.timeSource, flags)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ func newThresholdCaches(numCaches uint32) []thresholdStateCache {
|
||||
// threshold states for previous windows are only calculated once.
|
||||
//
|
||||
// This function MUST be called with the chain state lock held (for writes).
|
||||
func (b *BlockChain) thresholdState(prevNode *blockNode, checker thresholdConditionChecker, cache *thresholdStateCache) (ThresholdState, error) {
|
||||
func (b *BlockDAG) thresholdState(prevNode *blockNode, checker thresholdConditionChecker, cache *thresholdStateCache) (ThresholdState, error) {
|
||||
// The threshold state for the window that contains the genesis block is
|
||||
// defined by definition.
|
||||
confirmationWindow := int32(checker.MinerConfirmationWindow())
|
||||
@ -263,10 +263,10 @@ func (b *BlockChain) thresholdState(prevNode *blockNode, checker thresholdCondit
|
||||
// deployment ID for the block AFTER the end of the current best chain.
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (b *BlockChain) ThresholdState(deploymentID uint32) (ThresholdState, error) {
|
||||
b.chainLock.Lock()
|
||||
state, err := b.deploymentState(b.bestChain.SelectedTip(), deploymentID)
|
||||
b.chainLock.Unlock()
|
||||
func (b *BlockDAG) ThresholdState(deploymentID uint32) (ThresholdState, error) {
|
||||
b.dagLock.Lock()
|
||||
state, err := b.deploymentState(b.dag.SelectedTip(), deploymentID)
|
||||
b.dagLock.Unlock()
|
||||
|
||||
return state, err
|
||||
}
|
||||
@ -275,10 +275,10 @@ func (b *BlockChain) ThresholdState(deploymentID uint32) (ThresholdState, error)
|
||||
// false otherwise.
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (b *BlockChain) IsDeploymentActive(deploymentID uint32) (bool, error) {
|
||||
b.chainLock.Lock()
|
||||
state, err := b.deploymentState(b.bestChain.SelectedTip(), deploymentID)
|
||||
b.chainLock.Unlock()
|
||||
func (b *BlockDAG) IsDeploymentActive(deploymentID uint32) (bool, error) {
|
||||
b.dagLock.Lock()
|
||||
state, err := b.deploymentState(b.dag.SelectedTip(), deploymentID)
|
||||
b.dagLock.Unlock()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@ -296,12 +296,12 @@ func (b *BlockChain) IsDeploymentActive(deploymentID uint32) (bool, error) {
|
||||
// AFTER the passed node.
|
||||
//
|
||||
// This function MUST be called with the chain state lock held (for writes).
|
||||
func (b *BlockChain) deploymentState(prevNode *blockNode, deploymentID uint32) (ThresholdState, error) {
|
||||
if deploymentID > uint32(len(b.chainParams.Deployments)) {
|
||||
func (b *BlockDAG) deploymentState(prevNode *blockNode, deploymentID uint32) (ThresholdState, error) {
|
||||
if deploymentID > uint32(len(b.dagParams.Deployments)) {
|
||||
return ThresholdFailed, DeploymentError(deploymentID)
|
||||
}
|
||||
|
||||
deployment := &b.chainParams.Deployments[deploymentID]
|
||||
deployment := &b.dagParams.Deployments[deploymentID]
|
||||
checker := deploymentChecker{deployment: deployment, chain: b}
|
||||
cache := &b.deploymentCaches[deploymentID]
|
||||
|
||||
@ -311,12 +311,12 @@ func (b *BlockChain) deploymentState(prevNode *blockNode, deploymentID uint32) (
|
||||
// initThresholdCaches initializes the threshold state caches for each warning
|
||||
// bit and defined deployment and provides warnings if the chain is current per
|
||||
// the warnUnknownVersions and warnUnknownRuleActivations functions.
|
||||
func (b *BlockChain) initThresholdCaches() error {
|
||||
func (b *BlockDAG) initThresholdCaches() error {
|
||||
// Initialize the warning and deployment caches by calculating the
|
||||
// threshold state for each of them. This will ensure the caches are
|
||||
// populated and any states that needed to be recalculated due to
|
||||
// definition changes is done now.
|
||||
prevNode := b.bestChain.SelectedTip().selectedParent
|
||||
prevNode := b.dag.SelectedTip().selectedParent
|
||||
for bit := uint32(0); bit < vbNumBits; bit++ {
|
||||
checker := bitConditionChecker{bit: bit, chain: b}
|
||||
cache := &b.warningCaches[bit]
|
||||
@ -325,8 +325,8 @@ func (b *BlockChain) initThresholdCaches() error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for id := 0; id < len(b.chainParams.Deployments); id++ {
|
||||
deployment := &b.chainParams.Deployments[id]
|
||||
for id := 0; id < len(b.dagParams.Deployments); id++ {
|
||||
deployment := &b.dagParams.Deployments[id]
|
||||
cache := &b.deploymentCaches[id]
|
||||
checker := deploymentChecker{deployment: deployment, chain: b}
|
||||
_, err := b.thresholdState(prevNode, checker, cache)
|
||||
@ -340,7 +340,7 @@ func (b *BlockChain) initThresholdCaches() error {
|
||||
if b.isCurrent() {
|
||||
// Warn if a high enough percentage of the last blocks have
|
||||
// unexpected versions.
|
||||
bestNode := b.bestChain.SelectedTip()
|
||||
bestNode := b.dag.SelectedTip()
|
||||
if err := b.warnUnknownVersions(bestNode); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -578,7 +578,7 @@ func upgradeUtxoSetToV2(db database.DB, interrupt <-chan struct{}) error {
|
||||
//
|
||||
// All buckets used by this package are guaranteed to be the latest version if
|
||||
// this function returns without error.
|
||||
func (b *BlockChain) maybeUpgradeDbBuckets(interrupt <-chan struct{}) error {
|
||||
func (b *BlockDAG) maybeUpgradeDbBuckets(interrupt <-chan struct{}) error {
|
||||
// Load or create bucket versions as needed.
|
||||
var utxoSetVersion uint32
|
||||
err := b.db.Update(func(dbTx database.Tx) error {
|
||||
|
@ -467,7 +467,7 @@ func NewUtxoViewpoint() *UtxoViewpoint {
|
||||
// so the returned view can be examined for duplicate transactions.
|
||||
//
|
||||
// This function is safe for concurrent access however the returned view is NOT.
|
||||
func (b *BlockChain) FetchUtxoView(tx *btcutil.Tx) (*UtxoViewpoint, error) {
|
||||
func (b *BlockDAG) FetchUtxoView(tx *btcutil.Tx) (*UtxoViewpoint, error) {
|
||||
// Create a set of needed outputs based on those referenced by the
|
||||
// inputs of the passed transaction and the outputs of the transaction
|
||||
// itself.
|
||||
@ -486,9 +486,9 @@ func (b *BlockChain) FetchUtxoView(tx *btcutil.Tx) (*UtxoViewpoint, error) {
|
||||
// Request the utxos from the point of view of the end of the main
|
||||
// chain.
|
||||
view := NewUtxoViewpoint()
|
||||
b.chainLock.RLock()
|
||||
b.dagLock.RLock()
|
||||
err := view.fetchUtxosMain(b.db, neededSet)
|
||||
b.chainLock.RUnlock()
|
||||
b.dagLock.RUnlock()
|
||||
return view, err
|
||||
}
|
||||
|
||||
@ -502,9 +502,9 @@ func (b *BlockChain) FetchUtxoView(tx *btcutil.Tx) (*UtxoViewpoint, error) {
|
||||
//
|
||||
// This function is safe for concurrent access however the returned entry (if
|
||||
// any) is NOT.
|
||||
func (b *BlockChain) FetchUtxoEntry(outpoint wire.OutPoint) (*UtxoEntry, error) {
|
||||
b.chainLock.RLock()
|
||||
defer b.chainLock.RUnlock()
|
||||
func (b *BlockDAG) FetchUtxoEntry(outpoint wire.OutPoint) (*UtxoEntry, error) {
|
||||
b.dagLock.RLock()
|
||||
defer b.dagLock.RUnlock()
|
||||
|
||||
var entry *UtxoEntry
|
||||
err := b.db.View(func(dbTx database.Tx) error {
|
||||
|
@ -199,13 +199,13 @@ func isBIP0030Node(node *blockNode) bool {
|
||||
//
|
||||
// At the target block generation rate for the main network, this is
|
||||
// approximately every 4 years.
|
||||
func CalcBlockSubsidy(height int32, chainParams *dagconfig.Params) int64 {
|
||||
if chainParams.SubsidyReductionInterval == 0 {
|
||||
func CalcBlockSubsidy(height int32, dagParams *dagconfig.Params) int64 {
|
||||
if dagParams.SubsidyReductionInterval == 0 {
|
||||
return baseSubsidy
|
||||
}
|
||||
|
||||
// Equivalent to: baseSubsidy / 2^(height/subsidyHalvingInterval)
|
||||
return baseSubsidy >> uint(height/chainParams.SubsidyReductionInterval)
|
||||
return baseSubsidy >> uint(height/dagParams.SubsidyReductionInterval)
|
||||
}
|
||||
|
||||
// CheckTransactionSanity performs some preliminary checks on a transaction to
|
||||
@ -649,7 +649,7 @@ func checkSerializedHeight(coinbaseTx *btcutil.Tx, wantHeight int32) error {
|
||||
// the checkpoints are not performed.
|
||||
//
|
||||
// This function MUST be called with the chain state lock held (for writes).
|
||||
func (b *BlockChain) checkBlockHeaderContext(header *wire.BlockHeader, selectedParent *blockNode, flags BehaviorFlags) error {
|
||||
func (b *BlockDAG) checkBlockHeaderContext(header *wire.BlockHeader, selectedParent *blockNode, flags BehaviorFlags) error {
|
||||
fastAdd := flags&BFFastAdd == BFFastAdd
|
||||
if !fastAdd {
|
||||
// Ensure the difficulty specified in the block header matches
|
||||
@ -707,7 +707,7 @@ func (b *BlockChain) checkBlockHeaderContext(header *wire.BlockHeader, selectedP
|
||||
// Reject outdated block versions once a majority of the network
|
||||
// has upgraded. These were originally voted on by BIP0034,
|
||||
// BIP0065, and BIP0066.
|
||||
params := b.chainParams
|
||||
params := b.dagParams
|
||||
if header.Version < 2 && blockHeight >= params.BIP0034Height ||
|
||||
header.Version < 3 && blockHeight >= params.BIP0066Height ||
|
||||
header.Version < 4 && blockHeight >= params.BIP0065Height {
|
||||
@ -731,7 +731,7 @@ func (b *BlockChain) checkBlockHeaderContext(header *wire.BlockHeader, selectedP
|
||||
// for how the flags modify its behavior.
|
||||
//
|
||||
// This function MUST be called with the chain state lock held (for writes).
|
||||
func (b *BlockChain) checkBlockContext(block *btcutil.Block, selectedParent *blockNode, flags BehaviorFlags) error {
|
||||
func (b *BlockDAG) checkBlockContext(block *btcutil.Block, selectedParent *blockNode, flags BehaviorFlags) error {
|
||||
// Perform all block header related validation checks.
|
||||
header := &block.MsgBlock().Header
|
||||
err := b.checkBlockHeaderContext(header, selectedParent, flags)
|
||||
@ -777,7 +777,7 @@ func (b *BlockChain) checkBlockContext(block *btcutil.Block, selectedParent *blo
|
||||
// once a majority of the network has upgraded. This is part of
|
||||
// BIP0034.
|
||||
if ShouldHaveSerializedBlockHeight(header) &&
|
||||
blockHeight >= b.chainParams.BIP0034Height {
|
||||
blockHeight >= b.dagParams.BIP0034Height {
|
||||
|
||||
coinbaseTx := block.Transactions()[0]
|
||||
err := checkSerializedHeight(coinbaseTx, blockHeight)
|
||||
@ -801,7 +801,7 @@ func (b *BlockChain) checkBlockContext(block *btcutil.Block, selectedParent *blo
|
||||
// http://r6.ca/blog/20120206T005236Z.html.
|
||||
//
|
||||
// This function MUST be called with the chain state lock held (for reads).
|
||||
func (b *BlockChain) checkBIP0030(node *blockNode, block *btcutil.Block, view *UtxoViewpoint) error {
|
||||
func (b *BlockDAG) checkBIP0030(node *blockNode, block *btcutil.Block, view *UtxoViewpoint) error {
|
||||
// Fetch utxos for all of the transaction ouputs in this block.
|
||||
// Typically, there will not be any utxos for any of the outputs.
|
||||
fetchSet := make(map[wire.OutPoint]struct{})
|
||||
@ -843,7 +843,7 @@ func (b *BlockChain) checkBIP0030(node *blockNode, block *btcutil.Block, view *U
|
||||
//
|
||||
// NOTE: The transaction MUST have already been sanity checked with the
|
||||
// CheckTransactionSanity function prior to calling this function.
|
||||
func CheckTransactionInputs(tx *btcutil.Tx, txHeight int32, utxoView *UtxoViewpoint, chainParams *dagconfig.Params) (int64, error) {
|
||||
func CheckTransactionInputs(tx *btcutil.Tx, txHeight int32, utxoView *UtxoViewpoint, dagParams *dagconfig.Params) (int64, error) {
|
||||
// Coinbase transactions have no inputs.
|
||||
if IsCoinBase(tx) {
|
||||
return 0, nil
|
||||
@ -867,7 +867,7 @@ func CheckTransactionInputs(tx *btcutil.Tx, txHeight int32, utxoView *UtxoViewpo
|
||||
if utxo.IsCoinBase() {
|
||||
originHeight := utxo.BlockHeight()
|
||||
blocksSincePrev := txHeight - originHeight
|
||||
coinbaseMaturity := int32(chainParams.CoinbaseMaturity)
|
||||
coinbaseMaturity := int32(dagParams.CoinbaseMaturity)
|
||||
if blocksSincePrev < coinbaseMaturity {
|
||||
str := fmt.Sprintf("tried to spend coinbase "+
|
||||
"transaction output %v from height %v "+
|
||||
@ -958,7 +958,7 @@ func CheckTransactionInputs(tx *btcutil.Tx, txHeight int32, utxoView *UtxoViewpo
|
||||
// with that node.
|
||||
//
|
||||
// This function MUST be called with the chain state lock held (for writes).
|
||||
func (b *BlockChain) checkConnectBlock(node *blockNode, block *btcutil.Block, view *UtxoViewpoint, stxos *[]spentTxOut) error {
|
||||
func (b *BlockDAG) checkConnectBlock(node *blockNode, block *btcutil.Block, view *UtxoViewpoint, stxos *[]spentTxOut) error {
|
||||
// If the side chain blocks end up in the database, a call to
|
||||
// CheckBlockSanity should be done here in case a previous version
|
||||
// allowed a block that is no longer valid. However, since the
|
||||
@ -967,7 +967,7 @@ func (b *BlockChain) checkConnectBlock(node *blockNode, block *btcutil.Block, vi
|
||||
|
||||
// The coinbase for the Genesis block is not spendable, so just return
|
||||
// an error now.
|
||||
if node.hash.IsEqual(b.chainParams.GenesisHash) {
|
||||
if node.hash.IsEqual(b.dagParams.GenesisHash) {
|
||||
str := "the coinbase for the genesis block is not spendable"
|
||||
return ruleError(ErrMissingTxOut, str)
|
||||
}
|
||||
@ -996,7 +996,7 @@ func (b *BlockChain) checkConnectBlock(node *blockNode, block *btcutil.Block, vi
|
||||
// BIP0034 is not yet active. This is a useful optimization because the
|
||||
// BIP0030 check is expensive since it involves a ton of cache misses in
|
||||
// the utxoset.
|
||||
if !isBIP0030Node(node) && (node.height < b.chainParams.BIP0034Height) {
|
||||
if !isBIP0030Node(node) && (node.height < b.dagParams.BIP0034Height) {
|
||||
err := b.checkBIP0030(node, block, view)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -1065,7 +1065,7 @@ func (b *BlockChain) checkConnectBlock(node *blockNode, block *btcutil.Block, vi
|
||||
var totalFees int64
|
||||
for _, tx := range transactions {
|
||||
txFee, err := CheckTransactionInputs(tx, node.height, view,
|
||||
b.chainParams)
|
||||
b.dagParams)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -1098,7 +1098,7 @@ func (b *BlockChain) checkConnectBlock(node *blockNode, block *btcutil.Block, vi
|
||||
for _, txOut := range transactions[0].MsgTx().TxOut {
|
||||
totalSatoshiOut += txOut.Value
|
||||
}
|
||||
expectedSatoshiOut := CalcBlockSubsidy(node.height, b.chainParams) +
|
||||
expectedSatoshiOut := CalcBlockSubsidy(node.height, b.dagParams) +
|
||||
totalFees
|
||||
if totalSatoshiOut > expectedSatoshiOut {
|
||||
str := fmt.Sprintf("coinbase transaction for block pays %v "+
|
||||
@ -1129,13 +1129,13 @@ func (b *BlockChain) checkConnectBlock(node *blockNode, block *btcutil.Block, vi
|
||||
// Enforce DER signatures for block versions 3+ once the historical
|
||||
// activation threshold has been reached. This is part of BIP0066.
|
||||
blockHeader := &block.MsgBlock().Header
|
||||
if blockHeader.Version >= 3 && node.height >= b.chainParams.BIP0066Height {
|
||||
if blockHeader.Version >= 3 && node.height >= b.dagParams.BIP0066Height {
|
||||
scriptFlags |= txscript.ScriptVerifyDERSignatures
|
||||
}
|
||||
|
||||
// Enforce CHECKLOCKTIMEVERIFY for block versions 4+ once the historical
|
||||
// activation threshold has been reached. This is part of BIP0065.
|
||||
if blockHeader.Version >= 4 && node.height >= b.chainParams.BIP0065Height {
|
||||
if blockHeader.Version >= 4 && node.height >= b.dagParams.BIP0065Height {
|
||||
scriptFlags |= txscript.ScriptVerifyCheckLockTimeVerify
|
||||
}
|
||||
|
||||
@ -1201,16 +1201,16 @@ func (b *BlockChain) checkConnectBlock(node *blockNode, block *btcutil.Block, vi
|
||||
// work requirement. The block must connect to the current tip of the main chain.
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (b *BlockChain) CheckConnectBlockTemplate(block *btcutil.Block) error {
|
||||
b.chainLock.Lock()
|
||||
defer b.chainLock.Unlock()
|
||||
func (b *BlockDAG) CheckConnectBlockTemplate(block *btcutil.Block) error {
|
||||
b.dagLock.Lock()
|
||||
defer b.dagLock.Unlock()
|
||||
|
||||
// Skip the proof of work check as this is just a block template.
|
||||
flags := BFNoPoWCheck
|
||||
|
||||
// This only checks whether the block can be connected to the tip of the
|
||||
// current chain.
|
||||
tips := b.bestChain.Tips()
|
||||
tips := b.dag.Tips()
|
||||
header := block.MsgBlock().Header
|
||||
prevHashes := header.PrevBlocks
|
||||
if !tips.hashesEqual(prevHashes) {
|
||||
@ -1219,12 +1219,12 @@ func (b *BlockChain) CheckConnectBlockTemplate(block *btcutil.Block) error {
|
||||
return ruleError(ErrPrevBlockNotBest, str)
|
||||
}
|
||||
|
||||
err := checkBlockSanity(block, b.chainParams.PowLimit, b.timeSource, flags)
|
||||
err := checkBlockSanity(block, b.dagParams.PowLimit, b.timeSource, flags)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = b.checkBlockContext(block, b.bestChain.SelectedTip(), flags)
|
||||
err = b.checkBlockContext(block, b.dag.SelectedTip(), flags)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -1233,6 +1233,6 @@ func (b *BlockChain) CheckConnectBlockTemplate(block *btcutil.Block) error {
|
||||
// is not needed and thus extra work can be avoided.
|
||||
view := NewUtxoViewpoint()
|
||||
view.SetTips(tips)
|
||||
newNode := newBlockNode(&header, b.bestChain.Tips())
|
||||
newNode := newBlockNode(&header, b.dag.Tips())
|
||||
return b.checkConnectBlock(newNode, block, view, nil)
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ const (
|
||||
// unknown rule activations.
|
||||
type bitConditionChecker struct {
|
||||
bit uint32
|
||||
chain *BlockChain
|
||||
chain *BlockDAG
|
||||
}
|
||||
|
||||
// Ensure the bitConditionChecker type implements the thresholdConditionChecker
|
||||
@ -82,7 +82,7 @@ func (c bitConditionChecker) EndTime() uint64 {
|
||||
//
|
||||
// This is part of the thresholdConditionChecker interface implementation.
|
||||
func (c bitConditionChecker) RuleChangeActivationThreshold() uint32 {
|
||||
return c.chain.chainParams.RuleChangeActivationThreshold
|
||||
return c.chain.dagParams.RuleChangeActivationThreshold
|
||||
}
|
||||
|
||||
// MinerConfirmationWindow is the number of blocks in each threshold state
|
||||
@ -93,7 +93,7 @@ func (c bitConditionChecker) RuleChangeActivationThreshold() uint32 {
|
||||
//
|
||||
// This is part of the thresholdConditionChecker interface implementation.
|
||||
func (c bitConditionChecker) MinerConfirmationWindow() uint32 {
|
||||
return c.chain.chainParams.MinerConfirmationWindow
|
||||
return c.chain.dagParams.MinerConfirmationWindow
|
||||
}
|
||||
|
||||
// Condition returns true when the specific bit associated with the checker is
|
||||
@ -125,7 +125,7 @@ func (c bitConditionChecker) Condition(node *blockNode) (bool, error) {
|
||||
// and activating consensus rule changes.
|
||||
type deploymentChecker struct {
|
||||
deployment *dagconfig.ConsensusDeployment
|
||||
chain *BlockChain
|
||||
chain *BlockDAG
|
||||
}
|
||||
|
||||
// Ensure the deploymentChecker type implements the thresholdConditionChecker
|
||||
@ -163,7 +163,7 @@ func (c deploymentChecker) EndTime() uint64 {
|
||||
//
|
||||
// This is part of the thresholdConditionChecker interface implementation.
|
||||
func (c deploymentChecker) RuleChangeActivationThreshold() uint32 {
|
||||
return c.chain.chainParams.RuleChangeActivationThreshold
|
||||
return c.chain.dagParams.RuleChangeActivationThreshold
|
||||
}
|
||||
|
||||
// MinerConfirmationWindow is the number of blocks in each threshold state
|
||||
@ -174,7 +174,7 @@ func (c deploymentChecker) RuleChangeActivationThreshold() uint32 {
|
||||
//
|
||||
// This is part of the thresholdConditionChecker interface implementation.
|
||||
func (c deploymentChecker) MinerConfirmationWindow() uint32 {
|
||||
return c.chain.chainParams.MinerConfirmationWindow
|
||||
return c.chain.dagParams.MinerConfirmationWindow
|
||||
}
|
||||
|
||||
// Condition returns true when the specific bit defined by the deployment
|
||||
@ -197,13 +197,13 @@ func (c deploymentChecker) Condition(node *blockNode) (bool, error) {
|
||||
// while this function accepts any block node.
|
||||
//
|
||||
// This function MUST be called with the chain state lock held (for writes).
|
||||
func (b *BlockChain) calcNextBlockVersion(prevNode *blockNode) (int32, error) {
|
||||
func (b *BlockDAG) calcNextBlockVersion(prevNode *blockNode) (int32, error) {
|
||||
// Set the appropriate bits for each actively defined rule deployment
|
||||
// that is either in the process of being voted on, or locked in for the
|
||||
// activation at the next threshold window change.
|
||||
expectedVersion := uint32(vbTopBits)
|
||||
for id := 0; id < len(b.chainParams.Deployments); id++ {
|
||||
deployment := &b.chainParams.Deployments[id]
|
||||
for id := 0; id < len(b.dagParams.Deployments); id++ {
|
||||
deployment := &b.dagParams.Deployments[id]
|
||||
cache := &b.deploymentCaches[id]
|
||||
checker := deploymentChecker{deployment: deployment, chain: b}
|
||||
state, err := b.thresholdState(prevNode, checker, cache)
|
||||
@ -222,10 +222,10 @@ func (b *BlockChain) calcNextBlockVersion(prevNode *blockNode) (int32, error) {
|
||||
// rule change deployments.
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (b *BlockChain) CalcNextBlockVersion() (int32, error) {
|
||||
b.chainLock.Lock()
|
||||
version, err := b.calcNextBlockVersion(b.bestChain.SelectedTip())
|
||||
b.chainLock.Unlock()
|
||||
func (b *BlockDAG) CalcNextBlockVersion() (int32, error) {
|
||||
b.dagLock.Lock()
|
||||
version, err := b.calcNextBlockVersion(b.dag.SelectedTip())
|
||||
b.dagLock.Unlock()
|
||||
return version, err
|
||||
}
|
||||
|
||||
@ -235,7 +235,7 @@ func (b *BlockChain) CalcNextBlockVersion() (int32, error) {
|
||||
// activated.
|
||||
//
|
||||
// This function MUST be called with the chain state lock held (for writes)
|
||||
func (b *BlockChain) warnUnknownRuleActivations(node *blockNode) error {
|
||||
func (b *BlockDAG) warnUnknownRuleActivations(node *blockNode) error {
|
||||
// Warn if any unknown new rules are either about to activate or have
|
||||
// already been activated.
|
||||
for bit := uint32(0); bit < vbNumBits; bit++ {
|
||||
@ -269,7 +269,7 @@ func (b *BlockChain) warnUnknownRuleActivations(node *blockNode) error {
|
||||
// blocks have unexpected versions.
|
||||
//
|
||||
// This function MUST be called with the chain state lock held (for writes)
|
||||
func (b *BlockChain) warnUnknownVersions(node *blockNode) error {
|
||||
func (b *BlockDAG) warnUnknownVersions(node *blockNode) error {
|
||||
// Nothing to do if already warned.
|
||||
if b.unknownVersionsWarned {
|
||||
return nil
|
||||
|
@ -32,7 +32,7 @@ type importResults struct {
|
||||
// file to the block database.
|
||||
type blockImporter struct {
|
||||
db database.DB
|
||||
chain *blockdag.BlockChain
|
||||
dag *blockdag.BlockDAG
|
||||
r io.ReadSeeker
|
||||
processQueue chan []byte
|
||||
doneChan chan bool
|
||||
@ -105,7 +105,7 @@ func (bi *blockImporter) processBlock(serializedBlock []byte) (bool, error) {
|
||||
|
||||
// Skip blocks that already exist.
|
||||
blockHash := block.Hash()
|
||||
exists, err := bi.chain.HaveBlock(blockHash)
|
||||
exists, err := bi.dag.HaveBlock(blockHash)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@ -116,7 +116,7 @@ func (bi *blockImporter) processBlock(serializedBlock []byte) (bool, error) {
|
||||
// Don't bother trying to process orphans.
|
||||
prevHash := &block.MsgBlock().Header.PrevBlock
|
||||
if !prevHash.IsEqual(&zeroHash) {
|
||||
exists, err := bi.chain.HaveBlock(prevHash)
|
||||
exists, err := bi.dag.HaveBlock(prevHash)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@ -129,7 +129,7 @@ func (bi *blockImporter) processBlock(serializedBlock []byte) (bool, error) {
|
||||
|
||||
// Ensure the blocks follows all of the chain rules and match up to the
|
||||
// known checkpoints.
|
||||
isOrphan, err := bi.chain.ProcessBlock(block,
|
||||
isOrphan, err := bi.dag.ProcessBlock(block,
|
||||
blockdag.BFFastAdd)
|
||||
if err != nil {
|
||||
return false, err
|
||||
@ -326,9 +326,9 @@ func newBlockImporter(db database.DB, r io.ReadSeeker) (*blockImporter, error) {
|
||||
indexManager = indexers.NewManager(db, indexes)
|
||||
}
|
||||
|
||||
chain, err := blockdag.New(&blockdag.Config{
|
||||
dag, err := blockdag.New(&blockdag.Config{
|
||||
DB: db,
|
||||
ChainParams: activeNetParams,
|
||||
DAGParams: activeNetParams,
|
||||
TimeSource: blockdag.NewMedianTime(),
|
||||
IndexManager: indexManager,
|
||||
})
|
||||
@ -343,7 +343,7 @@ func newBlockImporter(db database.DB, r io.ReadSeeker) (*blockImporter, error) {
|
||||
doneChan: make(chan bool),
|
||||
errChan: make(chan error),
|
||||
quit: make(chan struct{}),
|
||||
chain: chain,
|
||||
dag: dag,
|
||||
lastLogTime: time.Now(),
|
||||
}, nil
|
||||
}
|
||||
|
@ -39,15 +39,15 @@ func loadBlockDB() (database.DB, error) {
|
||||
// candidates at the last checkpoint that is already hard coded into btcchain
|
||||
// since there is no point in finding candidates before already existing
|
||||
// checkpoints.
|
||||
func findCandidates(chain *blockdag.BlockChain, latestHash *daghash.Hash) ([]*dagconfig.Checkpoint, error) {
|
||||
func findCandidates(dag *blockdag.BlockDAG, latestHash *daghash.Hash) ([]*dagconfig.Checkpoint, error) {
|
||||
// Start with the latest block of the main chain.
|
||||
block, err := chain.BlockByHash(latestHash)
|
||||
block, err := dag.BlockByHash(latestHash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Get the latest known checkpoint.
|
||||
latestCheckpoint := chain.LatestCheckpoint()
|
||||
latestCheckpoint := dag.LatestCheckpoint()
|
||||
if latestCheckpoint == nil {
|
||||
// Set the latest checkpoint to the genesis block if there isn't
|
||||
// already one.
|
||||
@ -92,7 +92,7 @@ func findCandidates(chain *blockdag.BlockChain, latestHash *daghash.Hash) ([]*da
|
||||
}
|
||||
|
||||
// Determine if this block is a checkpoint candidate.
|
||||
isCandidate, err := chain.IsCheckpointCandidate(block)
|
||||
isCandidate, err := dag.IsCheckpointCandidate(block)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -108,7 +108,7 @@ func findCandidates(chain *blockdag.BlockChain, latestHash *daghash.Hash) ([]*da
|
||||
}
|
||||
|
||||
prevHash := &block.MsgBlock().Header.PrevBlock
|
||||
block, err = chain.BlockByHash(prevHash)
|
||||
block, err = dag.BlockByHash(prevHash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -150,10 +150,10 @@ func main() {
|
||||
|
||||
// Setup chain. Ignore notifications since they aren't needed for this
|
||||
// util.
|
||||
chain, err := blockdag.New(&blockdag.Config{
|
||||
DB: db,
|
||||
ChainParams: activeNetParams,
|
||||
TimeSource: blockdag.NewMedianTime(),
|
||||
dag, err := blockdag.New(&blockdag.Config{
|
||||
DB: db,
|
||||
DAGParams: activeNetParams,
|
||||
TimeSource: blockdag.NewMedianTime(),
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "failed to initialize chain: %v\n", err)
|
||||
@ -162,11 +162,11 @@ func main() {
|
||||
|
||||
// Get the latest block hash and height from the database and report
|
||||
// status.
|
||||
best := chain.BestSnapshot()
|
||||
best := dag.BestSnapshot()
|
||||
fmt.Printf("Block database loaded with block height %d\n", best.Height)
|
||||
|
||||
// Find checkpoint candidates.
|
||||
candidates, err := findCandidates(chain, &best.Hash)
|
||||
candidates, err := findCandidates(dag, &best.Hash)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "Unable to identify candidates:", err)
|
||||
return
|
||||
|
@ -342,7 +342,7 @@ type BlkTmplGenerator struct {
|
||||
policy *Policy
|
||||
chainParams *dagconfig.Params
|
||||
txSource TxSource
|
||||
chain *blockdag.BlockChain
|
||||
dag *blockdag.BlockDAG
|
||||
timeSource blockdag.MedianTimeSource
|
||||
sigCache *txscript.SigCache
|
||||
}
|
||||
@ -354,7 +354,7 @@ type BlkTmplGenerator struct {
|
||||
// templates are built on top of the current best chain and adhere to the
|
||||
// consensus rules.
|
||||
func NewBlkTmplGenerator(policy *Policy, params *dagconfig.Params,
|
||||
txSource TxSource, chain *blockdag.BlockChain,
|
||||
txSource TxSource, dag *blockdag.BlockDAG,
|
||||
timeSource blockdag.MedianTimeSource,
|
||||
sigCache *txscript.SigCache) *BlkTmplGenerator {
|
||||
|
||||
@ -362,7 +362,7 @@ func NewBlkTmplGenerator(policy *Policy, params *dagconfig.Params,
|
||||
policy: policy,
|
||||
chainParams: params,
|
||||
txSource: txSource,
|
||||
chain: chain,
|
||||
dag: dag,
|
||||
timeSource: timeSource,
|
||||
sigCache: sigCache,
|
||||
}
|
||||
@ -432,7 +432,7 @@ func NewBlkTmplGenerator(policy *Policy, params *dagconfig.Params,
|
||||
// ----------------------------------- --
|
||||
func (g *BlkTmplGenerator) NewBlockTemplate(payToAddress btcutil.Address) (*BlockTemplate, error) {
|
||||
// Extend the most recently known best block.
|
||||
best := g.chain.BestSnapshot()
|
||||
best := g.dag.BestSnapshot()
|
||||
nextBlockHeight := best.Height + 1
|
||||
|
||||
// Create a standard coinbase transaction paying to the provided
|
||||
@ -515,7 +515,7 @@ mempoolLoop:
|
||||
// mempool since a transaction which depends on other
|
||||
// transactions in the mempool must come after those
|
||||
// dependencies in the final generated block.
|
||||
utxos, err := g.chain.FetchUtxoView(tx)
|
||||
utxos, err := g.dag.FetchUtxoView(tx)
|
||||
if err != nil {
|
||||
log.Warnf("Unable to fetch utxo view for tx %s: %v",
|
||||
tx.Hash(), err)
|
||||
@ -747,14 +747,14 @@ mempoolLoop:
|
||||
// is potentially adjusted to ensure it comes after the median time of
|
||||
// the last several blocks per the chain consensus rules.
|
||||
ts := medianAdjustedTime(best, g.timeSource)
|
||||
reqDifficulty, err := g.chain.CalcNextRequiredDifficulty(ts)
|
||||
reqDifficulty, err := g.dag.CalcNextRequiredDifficulty(ts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Calculate the next expected block version based on the state of the
|
||||
// rule change deployments.
|
||||
nextBlockVersion, err := g.chain.CalcNextBlockVersion()
|
||||
nextBlockVersion, err := g.dag.CalcNextBlockVersion()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -780,7 +780,7 @@ mempoolLoop:
|
||||
// chain with no issues.
|
||||
block := btcutil.NewBlock(&msgBlock)
|
||||
block.SetHeight(nextBlockHeight)
|
||||
if err := g.chain.CheckConnectBlockTemplate(block); err != nil {
|
||||
if err := g.dag.CheckConnectBlockTemplate(block); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -808,12 +808,12 @@ func (g *BlkTmplGenerator) UpdateBlockTime(msgBlock *wire.MsgBlock) error {
|
||||
// The new timestamp is potentially adjusted to ensure it comes after
|
||||
// the median time of the last several blocks per the chain consensus
|
||||
// rules.
|
||||
newTime := medianAdjustedTime(g.chain.BestSnapshot(), g.timeSource)
|
||||
newTime := medianAdjustedTime(g.dag.BestSnapshot(), g.timeSource)
|
||||
msgBlock.Header.Timestamp = newTime
|
||||
|
||||
// Recalculate the difficulty if running on a network that requires it.
|
||||
if g.chainParams.ReduceMinDifficulty {
|
||||
difficulty, err := g.chain.CalcNextRequiredDifficulty(newTime)
|
||||
difficulty, err := g.dag.CalcNextRequiredDifficulty(newTime)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -858,7 +858,7 @@ func (g *BlkTmplGenerator) UpdateExtraNonce(msgBlock *wire.MsgBlock, blockHeight
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (g *BlkTmplGenerator) BestSnapshot() *blockdag.BestState {
|
||||
return g.chain.BestSnapshot()
|
||||
return g.dag.BestSnapshot()
|
||||
}
|
||||
|
||||
// TxSource returns the associated transaction source.
|
||||
|
@ -30,7 +30,7 @@ type PeerNotifier interface {
|
||||
// Config is a configuration struct used to initialize a new SyncManager.
|
||||
type Config struct {
|
||||
PeerNotifier PeerNotifier
|
||||
Chain *blockdag.BlockChain
|
||||
DAG *blockdag.BlockDAG
|
||||
TxMemPool *mempool.TxPool
|
||||
ChainParams *dagconfig.Params
|
||||
|
||||
|
@ -147,7 +147,7 @@ type SyncManager struct {
|
||||
peerNotifier PeerNotifier
|
||||
started int32
|
||||
shutdown int32
|
||||
chain *blockdag.BlockChain
|
||||
dag *blockdag.BlockDAG
|
||||
txMemPool *mempool.TxPool
|
||||
chainParams *dagconfig.Params
|
||||
progressLogger *blockProgressLogger
|
||||
@ -193,7 +193,7 @@ func (sm *SyncManager) resetHeaderState(newestHash *daghash.Hash, newestHeight i
|
||||
// later than the final checkpoint or some other reason such as disabled
|
||||
// checkpoints.
|
||||
func (sm *SyncManager) findNextHeaderCheckpoint(height int32) *dagconfig.Checkpoint {
|
||||
checkpoints := sm.chain.Checkpoints()
|
||||
checkpoints := sm.dag.Checkpoints()
|
||||
if len(checkpoints) == 0 {
|
||||
return nil
|
||||
}
|
||||
@ -226,7 +226,7 @@ func (sm *SyncManager) startSync() {
|
||||
return
|
||||
}
|
||||
|
||||
best := sm.chain.BestSnapshot()
|
||||
best := sm.dag.BestSnapshot()
|
||||
var bestPeer *peerpkg.Peer
|
||||
for peer, state := range sm.peerStates {
|
||||
if !state.syncCandidate {
|
||||
@ -256,7 +256,7 @@ func (sm *SyncManager) startSync() {
|
||||
// to send.
|
||||
sm.requestedBlocks = make(map[daghash.Hash]struct{})
|
||||
|
||||
locator, err := sm.chain.LatestBlockLocator()
|
||||
locator, err := sm.dag.LatestBlockLocator()
|
||||
if err != nil {
|
||||
log.Errorf("Failed to get block locator for the "+
|
||||
"latest block: %v", err)
|
||||
@ -392,7 +392,7 @@ func (sm *SyncManager) handleDonePeerMsg(peer *peerpkg.Peer) {
|
||||
if sm.syncPeer == peer {
|
||||
sm.syncPeer = nil
|
||||
if sm.headersFirstMode {
|
||||
best := sm.chain.BestSnapshot()
|
||||
best := sm.dag.BestSnapshot()
|
||||
sm.resetHeaderState(&best.Hash, best.Height)
|
||||
}
|
||||
sm.startSync()
|
||||
@ -470,7 +470,7 @@ func (sm *SyncManager) handleTxMsg(tmsg *txMsg) {
|
||||
// current returns true if we believe we are synced with our peers, false if we
|
||||
// still have blocks to check
|
||||
func (sm *SyncManager) current() bool {
|
||||
if !sm.chain.IsCurrent() {
|
||||
if !sm.dag.IsCurrent() {
|
||||
return false
|
||||
}
|
||||
|
||||
@ -482,7 +482,7 @@ func (sm *SyncManager) current() bool {
|
||||
|
||||
// No matter what chain thinks, if we are below the block we are syncing
|
||||
// to we are not current.
|
||||
if sm.chain.BestSnapshot().Height < sm.syncPeer.LastBlock() {
|
||||
if sm.dag.BestSnapshot().Height < sm.syncPeer.LastBlock() {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
@ -544,7 +544,7 @@ func (sm *SyncManager) handleBlockMsg(bmsg *blockMsg) {
|
||||
delete(sm.requestedBlocks, *blockHash)
|
||||
|
||||
// Process the block to include validation, orphan handling, etc.
|
||||
isOrphan, err := sm.chain.ProcessBlock(bmsg.block, behaviorFlags)
|
||||
isOrphan, err := sm.dag.ProcessBlock(bmsg.block, behaviorFlags)
|
||||
if err != nil {
|
||||
// When the error is a rule error, it means the block was simply
|
||||
// rejected as opposed to something actually going wrong, so log
|
||||
@ -603,8 +603,8 @@ func (sm *SyncManager) handleBlockMsg(bmsg *blockMsg) {
|
||||
}
|
||||
}
|
||||
|
||||
orphanRoot := sm.chain.GetOrphanRoot(blockHash)
|
||||
locator, err := sm.chain.LatestBlockLocator()
|
||||
orphanRoot := sm.dag.GetOrphanRoot(blockHash)
|
||||
locator, err := sm.dag.LatestBlockLocator()
|
||||
if err != nil {
|
||||
log.Warnf("Failed to get block locator for the "+
|
||||
"latest block: %v", err)
|
||||
@ -618,7 +618,7 @@ func (sm *SyncManager) handleBlockMsg(bmsg *blockMsg) {
|
||||
|
||||
// Update this peer's latest block height, for future
|
||||
// potential sync node candidacy.
|
||||
best := sm.chain.BestSnapshot()
|
||||
best := sm.dag.BestSnapshot()
|
||||
heightUpdate = best.Height
|
||||
blkHashUpdate = &best.Hash
|
||||
|
||||
@ -855,7 +855,7 @@ func (sm *SyncManager) haveInventory(invVect *wire.InvVect) (bool, error) {
|
||||
case wire.InvTypeBlock:
|
||||
// Ask chain if the block is known to it in any form (main
|
||||
// chain, side chain, or orphan).
|
||||
return sm.chain.HaveBlock(&invVect.Hash)
|
||||
return sm.dag.HaveBlock(&invVect.Hash)
|
||||
|
||||
case wire.InvTypeTx:
|
||||
// Ask the transaction memory pool if the transaction is known
|
||||
@ -875,7 +875,7 @@ func (sm *SyncManager) haveInventory(invVect *wire.InvVect) (bool, error) {
|
||||
prevOut := wire.OutPoint{Hash: invVect.Hash}
|
||||
for i := uint32(0); i < 2; i++ {
|
||||
prevOut.Index = i
|
||||
entry, err := sm.chain.FetchUtxoEntry(prevOut)
|
||||
entry, err := sm.dag.FetchUtxoEntry(prevOut)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@ -931,7 +931,7 @@ func (sm *SyncManager) handleInvMsg(imsg *invMsg) {
|
||||
// If our chain is current and a peer announces a block we already
|
||||
// know of, then update their current block height.
|
||||
if lastBlock != -1 && sm.current() {
|
||||
blkHeight, err := sm.chain.BlockHeightByHash(&invVects[lastBlock].Hash)
|
||||
blkHeight, err := sm.dag.BlockHeightByHash(&invVects[lastBlock].Hash)
|
||||
if err == nil {
|
||||
peer.UpdateLastBlockHeight(blkHeight)
|
||||
}
|
||||
@ -992,12 +992,12 @@ func (sm *SyncManager) handleInvMsg(imsg *invMsg) {
|
||||
// resending the orphan block as an available block
|
||||
// to signal there are more missing blocks that need to
|
||||
// be requested.
|
||||
if sm.chain.IsKnownOrphan(&iv.Hash) {
|
||||
if sm.dag.IsKnownOrphan(&iv.Hash) {
|
||||
// Request blocks starting at the latest known
|
||||
// up to the root of the orphan that just came
|
||||
// in.
|
||||
orphanRoot := sm.chain.GetOrphanRoot(&iv.Hash)
|
||||
locator, err := sm.chain.LatestBlockLocator()
|
||||
orphanRoot := sm.dag.GetOrphanRoot(&iv.Hash)
|
||||
locator, err := sm.dag.LatestBlockLocator()
|
||||
if err != nil {
|
||||
log.Errorf("PEER: Failed to get block "+
|
||||
"locator for the latest block: "+
|
||||
@ -1016,7 +1016,7 @@ func (sm *SyncManager) handleInvMsg(imsg *invMsg) {
|
||||
// Request blocks after this one up to the
|
||||
// final one the remote peer knows about (zero
|
||||
// stop hash).
|
||||
locator := sm.chain.BlockLocatorFromHash(&iv.Hash)
|
||||
locator := sm.dag.BlockLocatorFromHash(&iv.Hash)
|
||||
peer.PushGetBlocksMsg(locator, &zeroHash)
|
||||
}
|
||||
}
|
||||
@ -1126,7 +1126,7 @@ out:
|
||||
msg.reply <- peerID
|
||||
|
||||
case processBlockMsg:
|
||||
isOrphan, err := sm.chain.ProcessBlock(
|
||||
isOrphan, err := sm.dag.ProcessBlock(
|
||||
msg.block, msg.flags)
|
||||
if err != nil {
|
||||
msg.reply <- processBlockResponse{
|
||||
@ -1385,7 +1385,7 @@ func (sm *SyncManager) Pause() chan<- struct{} {
|
||||
func New(config *Config) (*SyncManager, error) {
|
||||
sm := SyncManager{
|
||||
peerNotifier: config.PeerNotifier,
|
||||
chain: config.Chain,
|
||||
dag: config.DAG,
|
||||
txMemPool: config.TxMemPool,
|
||||
chainParams: config.ChainParams,
|
||||
rejectedTxns: make(map[daghash.Hash]struct{}),
|
||||
@ -1399,7 +1399,7 @@ func New(config *Config) (*SyncManager, error) {
|
||||
feeEstimator: config.FeeEstimator,
|
||||
}
|
||||
|
||||
best := sm.chain.BestSnapshot()
|
||||
best := sm.dag.BestSnapshot()
|
||||
if !config.DisableCheckpoints {
|
||||
// Initialize the next checkpoint based on the current height.
|
||||
sm.nextCheckpoint = sm.findNextHeaderCheckpoint(best.Height)
|
||||
@ -1410,7 +1410,7 @@ func New(config *Config) (*SyncManager, error) {
|
||||
log.Info("Checkpoints are disabled")
|
||||
}
|
||||
|
||||
sm.chain.Subscribe(sm.handleBlockchainNotification)
|
||||
sm.dag.Subscribe(sm.handleBlockchainNotification)
|
||||
|
||||
return &sm, nil
|
||||
}
|
||||
|
@ -275,5 +275,5 @@ func (b *rpcSyncMgr) SyncPeerID() int32 {
|
||||
// This function is safe for concurrent access and is part of the
|
||||
// rpcserverSyncManager interface implementation.
|
||||
func (b *rpcSyncMgr) LocateHeaders(locators []*daghash.Hash, hashStop *daghash.Hash) []wire.BlockHeader {
|
||||
return b.server.chain.LocateHeaders(locators, hashStop)
|
||||
return b.server.dag.LocateHeaders(locators, hashStop)
|
||||
}
|
||||
|
72
rpcserver.go
72
rpcserver.go
@ -1002,7 +1002,7 @@ func handleGetBestBlock(s *rpcServer, cmd interface{}, closeChan <-chan struct{}
|
||||
// All other "get block" commands give either the height, the
|
||||
// hash, or both but require the block SHA. This gets both for
|
||||
// the best block.
|
||||
best := s.cfg.Chain.BestSnapshot()
|
||||
best := s.cfg.DAG.BestSnapshot()
|
||||
result := &btcjson.GetBestBlockResult{
|
||||
Hash: best.Hash.String(),
|
||||
Height: best.Height,
|
||||
@ -1012,7 +1012,7 @@ func handleGetBestBlock(s *rpcServer, cmd interface{}, closeChan <-chan struct{}
|
||||
|
||||
// handleGetBestBlockHash implements the getbestblockhash command.
|
||||
func handleGetBestBlockHash(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
|
||||
best := s.cfg.Chain.BestSnapshot()
|
||||
best := s.cfg.DAG.BestSnapshot()
|
||||
return best.Hash.String(), nil
|
||||
}
|
||||
|
||||
@ -1074,18 +1074,18 @@ func handleGetBlock(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (i
|
||||
}
|
||||
|
||||
// Get the block height from chain.
|
||||
blockHeight, err := s.cfg.Chain.BlockHeightByHash(hash)
|
||||
blockHeight, err := s.cfg.DAG.BlockHeightByHash(hash)
|
||||
if err != nil {
|
||||
context := "Failed to obtain block height"
|
||||
return nil, internalRPCError(err.Error(), context)
|
||||
}
|
||||
blk.SetHeight(blockHeight)
|
||||
best := s.cfg.Chain.BestSnapshot()
|
||||
best := s.cfg.DAG.BestSnapshot()
|
||||
|
||||
// Get next block hash unless there are none.
|
||||
var nextHashString string
|
||||
if blockHeight < best.Height {
|
||||
nextHash, err := s.cfg.Chain.BlockHashByHeight(blockHeight + 1)
|
||||
nextHash, err := s.cfg.DAG.BlockHashByHeight(blockHeight + 1)
|
||||
if err != nil {
|
||||
context := "No next block"
|
||||
return nil, internalRPCError(err.Error(), context)
|
||||
@ -1161,7 +1161,7 @@ func handleGetBlockChainInfo(s *rpcServer, cmd interface{}, closeChan <-chan str
|
||||
// Obtain a snapshot of the current best known blockchain state. We'll
|
||||
// populate the response to this call primarily from this snapshot.
|
||||
params := s.cfg.ChainParams
|
||||
chain := s.cfg.Chain
|
||||
chain := s.cfg.DAG
|
||||
chainSnapshot := chain.BestSnapshot()
|
||||
|
||||
chainInfo := &btcjson.GetBlockChainInfoResult{
|
||||
@ -1265,14 +1265,14 @@ func handleGetBlockChainInfo(s *rpcServer, cmd interface{}, closeChan <-chan str
|
||||
|
||||
// handleGetBlockCount implements the getblockcount command.
|
||||
func handleGetBlockCount(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
|
||||
best := s.cfg.Chain.BestSnapshot()
|
||||
best := s.cfg.DAG.BestSnapshot()
|
||||
return int64(best.Height), nil
|
||||
}
|
||||
|
||||
// handleGetBlockHash implements the getblockhash command.
|
||||
func handleGetBlockHash(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
|
||||
c := cmd.(*btcjson.GetBlockHashCmd)
|
||||
hash, err := s.cfg.Chain.BlockHashByHeight(int32(c.Index))
|
||||
hash, err := s.cfg.DAG.BlockHashByHeight(int32(c.Index))
|
||||
if err != nil {
|
||||
return nil, &btcjson.RPCError{
|
||||
Code: btcjson.ErrRPCOutOfRange,
|
||||
@ -1292,7 +1292,7 @@ func handleGetBlockHeader(s *rpcServer, cmd interface{}, closeChan <-chan struct
|
||||
if err != nil {
|
||||
return nil, rpcDecodeHexError(c.Hash)
|
||||
}
|
||||
blockHeader, err := s.cfg.Chain.FetchHeader(hash)
|
||||
blockHeader, err := s.cfg.DAG.FetchHeader(hash)
|
||||
if err != nil {
|
||||
return nil, &btcjson.RPCError{
|
||||
Code: btcjson.ErrRPCBlockNotFound,
|
||||
@ -1315,17 +1315,17 @@ func handleGetBlockHeader(s *rpcServer, cmd interface{}, closeChan <-chan struct
|
||||
// The verbose flag is set, so generate the JSON object and return it.
|
||||
|
||||
// Get the block height from chain.
|
||||
blockHeight, err := s.cfg.Chain.BlockHeightByHash(hash)
|
||||
blockHeight, err := s.cfg.DAG.BlockHeightByHash(hash)
|
||||
if err != nil {
|
||||
context := "Failed to obtain block height"
|
||||
return nil, internalRPCError(err.Error(), context)
|
||||
}
|
||||
best := s.cfg.Chain.BestSnapshot()
|
||||
best := s.cfg.DAG.BestSnapshot()
|
||||
|
||||
// Get next block hash unless there are none.
|
||||
var nextHashString string
|
||||
if blockHeight < best.Height {
|
||||
nextHash, err := s.cfg.Chain.BlockHashByHeight(blockHeight + 1)
|
||||
nextHash, err := s.cfg.DAG.BlockHashByHeight(blockHeight + 1)
|
||||
if err != nil {
|
||||
context := "No next block"
|
||||
return nil, internalRPCError(err.Error(), context)
|
||||
@ -1516,7 +1516,7 @@ func (state *gbtWorkState) updateBlockTemplate(s *rpcServer, useCoinbaseValue bo
|
||||
// generated.
|
||||
var msgBlock *wire.MsgBlock
|
||||
var targetDifficulty string
|
||||
latestHash := &s.cfg.Chain.BestSnapshot().Hash
|
||||
latestHash := &s.cfg.DAG.BestSnapshot().Hash
|
||||
template := state.template
|
||||
if template == nil || state.prevHash == nil ||
|
||||
!state.prevHash.IsEqual(latestHash) ||
|
||||
@ -1555,7 +1555,7 @@ func (state *gbtWorkState) updateBlockTemplate(s *rpcServer, useCoinbaseValue bo
|
||||
// Get the minimum allowed timestamp for the block based on the
|
||||
// median timestamp of the last several blocks per the chain
|
||||
// consensus rules.
|
||||
best := s.cfg.Chain.BestSnapshot()
|
||||
best := s.cfg.DAG.BestSnapshot()
|
||||
minTimestamp := mining.MinimumMedianTime(best)
|
||||
|
||||
// Update work state to ensure another block template isn't
|
||||
@ -1912,7 +1912,7 @@ func handleGetBlockTemplateRequest(s *rpcServer, request *btcjson.TemplateReques
|
||||
}
|
||||
|
||||
// No point in generating or accepting work before the chain is synced.
|
||||
currentHeight := s.cfg.Chain.BestSnapshot().Height
|
||||
currentHeight := s.cfg.DAG.BestSnapshot().Height
|
||||
if currentHeight != 0 && !s.cfg.SyncMgr.IsCurrent() {
|
||||
return nil, &btcjson.RPCError{
|
||||
Code: btcjson.ErrRPCClientInInitialDownload,
|
||||
@ -2077,13 +2077,13 @@ func handleGetBlockTemplateProposal(s *rpcServer, request *btcjson.TemplateReque
|
||||
block := btcutil.NewBlock(&msgBlock)
|
||||
|
||||
// Ensure the block is building from the expected previous block.
|
||||
expectedPrevHash := s.cfg.Chain.BestSnapshot().Hash
|
||||
expectedPrevHash := s.cfg.DAG.BestSnapshot().Hash
|
||||
prevHash := &block.MsgBlock().Header.PrevBlock
|
||||
if !expectedPrevHash.IsEqual(prevHash) {
|
||||
return "bad-prevblk", nil
|
||||
}
|
||||
|
||||
if err := s.cfg.Chain.CheckConnectBlockTemplate(block); err != nil {
|
||||
if err := s.cfg.DAG.CheckConnectBlockTemplate(block); err != nil {
|
||||
if _, ok := err.(blockdag.RuleError); !ok {
|
||||
errStr := fmt.Sprintf("Failed to process block proposal: %v", err)
|
||||
rpcsLog.Error(errStr)
|
||||
@ -2199,7 +2199,7 @@ func handleGetCurrentNet(s *rpcServer, cmd interface{}, closeChan <-chan struct{
|
||||
|
||||
// handleGetDifficulty implements the getdifficulty command.
|
||||
func handleGetDifficulty(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
|
||||
best := s.cfg.Chain.BestSnapshot()
|
||||
best := s.cfg.DAG.BestSnapshot()
|
||||
return getDifficultyRatio(best.Bits, s.cfg.ChainParams), nil
|
||||
}
|
||||
|
||||
@ -2257,7 +2257,7 @@ func handleGetHeaders(s *rpcServer, cmd interface{}, closeChan <-chan struct{})
|
||||
// handleGetInfo implements the getinfo command. We only return the fields
|
||||
// that are not related to wallet functionality.
|
||||
func handleGetInfo(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
|
||||
best := s.cfg.Chain.BestSnapshot()
|
||||
best := s.cfg.DAG.BestSnapshot()
|
||||
ret := &btcjson.InfoChainResult{
|
||||
Version: int32(1000000*appMajor + 10000*appMinor + 100*appPatch),
|
||||
ProtocolVersion: int32(maxProtocolVersion),
|
||||
@ -2309,7 +2309,7 @@ func handleGetMiningInfo(s *rpcServer, cmd interface{}, closeChan <-chan struct{
|
||||
}
|
||||
}
|
||||
|
||||
best := s.cfg.Chain.BestSnapshot()
|
||||
best := s.cfg.DAG.BestSnapshot()
|
||||
result := btcjson.GetMiningInfoResult{
|
||||
Blocks: int64(best.Height),
|
||||
CurrentBlockSize: best.BlockSize,
|
||||
@ -2348,7 +2348,7 @@ func handleGetNetworkHashPS(s *rpcServer, cmd interface{}, closeChan <-chan stru
|
||||
// since we can't reasonably calculate the number of network hashes
|
||||
// per second from invalid values. When it's negative, use the current
|
||||
// best block height.
|
||||
best := s.cfg.Chain.BestSnapshot()
|
||||
best := s.cfg.DAG.BestSnapshot()
|
||||
endHeight := int32(-1)
|
||||
if c.Height != nil {
|
||||
endHeight = int32(*c.Height)
|
||||
@ -2390,14 +2390,14 @@ func handleGetNetworkHashPS(s *rpcServer, cmd interface{}, closeChan <-chan stru
|
||||
var minTimestamp, maxTimestamp time.Time
|
||||
totalWork := big.NewInt(0)
|
||||
for curHeight := startHeight; curHeight <= endHeight; curHeight++ {
|
||||
hash, err := s.cfg.Chain.BlockHashByHeight(curHeight)
|
||||
hash, err := s.cfg.DAG.BlockHashByHeight(curHeight)
|
||||
if err != nil {
|
||||
context := "Failed to fetch block hash"
|
||||
return nil, internalRPCError(err.Error(), context)
|
||||
}
|
||||
|
||||
// Fetch the header from chain.
|
||||
header, err := s.cfg.Chain.FetchHeader(hash)
|
||||
header, err := s.cfg.DAG.FetchHeader(hash)
|
||||
if err != nil {
|
||||
context := "Failed to fetch block header"
|
||||
return nil, internalRPCError(err.Error(), context)
|
||||
@ -2550,7 +2550,7 @@ func handleGetRawTransaction(s *rpcServer, cmd interface{}, closeChan <-chan str
|
||||
|
||||
// Grab the block height.
|
||||
blkHash = blockRegion.Hash
|
||||
blkHeight, err = s.cfg.Chain.BlockHeightByHash(blkHash)
|
||||
blkHeight, err = s.cfg.DAG.BlockHeightByHash(blkHash)
|
||||
if err != nil {
|
||||
context := "Failed to retrieve block height"
|
||||
return nil, internalRPCError(err.Error(), context)
|
||||
@ -2589,7 +2589,7 @@ func handleGetRawTransaction(s *rpcServer, cmd interface{}, closeChan <-chan str
|
||||
var chainHeight int32
|
||||
if blkHash != nil {
|
||||
// Fetch the header from chain.
|
||||
header, err := s.cfg.Chain.FetchHeader(blkHash)
|
||||
header, err := s.cfg.DAG.FetchHeader(blkHash)
|
||||
if err != nil {
|
||||
context := "Failed to fetch block header"
|
||||
return nil, internalRPCError(err.Error(), context)
|
||||
@ -2597,7 +2597,7 @@ func handleGetRawTransaction(s *rpcServer, cmd interface{}, closeChan <-chan str
|
||||
|
||||
blkHeader = &header
|
||||
blkHashStr = blkHash.String()
|
||||
chainHeight = s.cfg.Chain.BestSnapshot().Height
|
||||
chainHeight = s.cfg.DAG.BestSnapshot().Height
|
||||
}
|
||||
|
||||
rawTxn, err := createTxRawResult(s.cfg.ChainParams, mtx, txHash.String(),
|
||||
@ -2653,7 +2653,7 @@ func handleGetTxOut(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (i
|
||||
return nil, internalRPCError(errStr, "")
|
||||
}
|
||||
|
||||
best := s.cfg.Chain.BestSnapshot()
|
||||
best := s.cfg.DAG.BestSnapshot()
|
||||
bestBlockHash = best.Hash.String()
|
||||
confirmations = 0
|
||||
value = txOut.Value
|
||||
@ -2661,7 +2661,7 @@ func handleGetTxOut(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (i
|
||||
isCoinbase = blockdag.IsCoinBaseTx(mtx)
|
||||
} else {
|
||||
out := wire.OutPoint{Hash: *txHash, Index: c.Vout}
|
||||
entry, err := s.cfg.Chain.FetchUtxoEntry(out)
|
||||
entry, err := s.cfg.DAG.FetchUtxoEntry(out)
|
||||
if err != nil {
|
||||
return nil, rpcNoTxInfoError(txHash)
|
||||
}
|
||||
@ -2675,7 +2675,7 @@ func handleGetTxOut(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (i
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
best := s.cfg.Chain.BestSnapshot()
|
||||
best := s.cfg.DAG.BestSnapshot()
|
||||
bestBlockHash = best.Hash.String()
|
||||
confirmations = 1 + best.Height - entry.BlockHeight()
|
||||
value = entry.Amount()
|
||||
@ -3170,7 +3170,7 @@ func handleSearchRawTransactions(s *rpcServer, cmd interface{}, closeChan <-chan
|
||||
}
|
||||
|
||||
// The verbose flag is set, so generate the JSON object and return it.
|
||||
best := s.cfg.Chain.BestSnapshot()
|
||||
best := s.cfg.DAG.BestSnapshot()
|
||||
srtList := make([]btcjson.SearchRawTransactionsResult, len(addressTxns))
|
||||
for i := range addressTxns {
|
||||
// The deserialized transaction is needed, so deserialize the
|
||||
@ -3213,7 +3213,7 @@ func handleSearchRawTransactions(s *rpcServer, cmd interface{}, closeChan <-chan
|
||||
var blkHeight int32
|
||||
if blkHash := rtx.blkHash; blkHash != nil {
|
||||
// Fetch the header from chain.
|
||||
header, err := s.cfg.Chain.FetchHeader(blkHash)
|
||||
header, err := s.cfg.DAG.FetchHeader(blkHash)
|
||||
if err != nil {
|
||||
return nil, &btcjson.RPCError{
|
||||
Code: btcjson.ErrRPCBlockNotFound,
|
||||
@ -3222,7 +3222,7 @@ func handleSearchRawTransactions(s *rpcServer, cmd interface{}, closeChan <-chan
|
||||
}
|
||||
|
||||
// Get the block height from chain.
|
||||
height, err := s.cfg.Chain.BlockHeightByHash(blkHash)
|
||||
height, err := s.cfg.DAG.BlockHeightByHash(blkHash)
|
||||
if err != nil {
|
||||
context := "Failed to obtain block height"
|
||||
return nil, internalRPCError(err.Error(), context)
|
||||
@ -3425,7 +3425,7 @@ func handleValidateAddress(s *rpcServer, cmd interface{}, closeChan <-chan struc
|
||||
}
|
||||
|
||||
func verifyChain(s *rpcServer, level, depth int32) error {
|
||||
best := s.cfg.Chain.BestSnapshot()
|
||||
best := s.cfg.DAG.BestSnapshot()
|
||||
finishHeight := best.Height - depth
|
||||
if finishHeight < 0 {
|
||||
finishHeight = 0
|
||||
@ -3435,7 +3435,7 @@ func verifyChain(s *rpcServer, level, depth int32) error {
|
||||
|
||||
for height := best.Height; height > finishHeight; height-- {
|
||||
// Level 0 just looks up the block.
|
||||
block, err := s.cfg.Chain.BlockByHeight(height)
|
||||
block, err := s.cfg.DAG.BlockByHeight(height)
|
||||
if err != nil {
|
||||
rpcsLog.Errorf("Verify is unable to fetch block at "+
|
||||
"height %d: %v", height, err)
|
||||
@ -4198,7 +4198,7 @@ type rpcserverConfig struct {
|
||||
// These fields allow the RPC server to interface with the local block
|
||||
// chain data and state.
|
||||
TimeSource blockdag.MedianTimeSource
|
||||
Chain *blockdag.BlockChain
|
||||
DAG *blockdag.BlockDAG
|
||||
ChainParams *dagconfig.Params
|
||||
DB database.DB
|
||||
|
||||
@ -4245,7 +4245,7 @@ func newRPCServer(config *rpcserverConfig) (*rpcServer, error) {
|
||||
rpc.limitauthsha = sha256.Sum256([]byte(auth))
|
||||
}
|
||||
rpc.ntfnMgr = newWsNotificationManager(&rpc)
|
||||
rpc.cfg.Chain.Subscribe(rpc.handleBlockchainNotification)
|
||||
rpc.cfg.DAG.Subscribe(rpc.handleBlockchainNotification)
|
||||
|
||||
return &rpc, nil
|
||||
}
|
||||
|
@ -2237,7 +2237,7 @@ func handleRescanBlocks(wsc *wsClient, icmd interface{}) (interface{}, error) {
|
||||
|
||||
// Iterate over each block in the request and rescan. When a block
|
||||
// contains relevant transactions, add it to the response.
|
||||
bc := wsc.server.cfg.Chain
|
||||
bc := wsc.server.cfg.DAG
|
||||
params := wsc.server.cfg.ChainParams
|
||||
var lastBlockHash *daghash.Hash
|
||||
for i := range blockHashes {
|
||||
@ -2274,10 +2274,10 @@ func handleRescanBlocks(wsc *wsClient, icmd interface{}) (interface{}, error) {
|
||||
// verifies that the new range of blocks is on the same fork as a previous
|
||||
// range of blocks. If this condition does not hold true, the JSON-RPC error
|
||||
// for an unrecoverable reorganize is returned.
|
||||
func recoverFromReorg(chain *blockdag.BlockChain, minBlock, maxBlock int32,
|
||||
func recoverFromReorg(dag *blockdag.BlockDAG, minBlock, maxBlock int32,
|
||||
lastBlock *daghash.Hash) ([]daghash.Hash, error) {
|
||||
|
||||
hashList, err := chain.HeightRange(minBlock, maxBlock)
|
||||
hashList, err := dag.HeightRange(minBlock, maxBlock)
|
||||
if err != nil {
|
||||
rpcsLog.Errorf("Error looking up block range: %v", err)
|
||||
return nil, &btcjson.RPCError{
|
||||
@ -2289,7 +2289,7 @@ func recoverFromReorg(chain *blockdag.BlockChain, minBlock, maxBlock int32,
|
||||
return hashList, nil
|
||||
}
|
||||
|
||||
blk, err := chain.BlockByHash(&hashList[0])
|
||||
blk, err := dag.BlockByHash(&hashList[0])
|
||||
if err != nil {
|
||||
rpcsLog.Errorf("Error looking up possibly reorged block: %v",
|
||||
err)
|
||||
@ -2410,13 +2410,13 @@ func handleRescan(wsc *wsClient, icmd interface{}) (interface{}, error) {
|
||||
lookups.unspent[*outpoint] = struct{}{}
|
||||
}
|
||||
|
||||
chain := wsc.server.cfg.Chain
|
||||
dag := wsc.server.cfg.DAG
|
||||
|
||||
minBlockHash, err := daghash.NewHashFromStr(cmd.BeginBlock)
|
||||
if err != nil {
|
||||
return nil, rpcDecodeHexError(cmd.BeginBlock)
|
||||
}
|
||||
minBlock, err := chain.BlockHeightByHash(minBlockHash)
|
||||
minBlock, err := dag.BlockHeightByHash(minBlockHash)
|
||||
if err != nil {
|
||||
return nil, &btcjson.RPCError{
|
||||
Code: btcjson.ErrRPCBlockNotFound,
|
||||
@ -2430,7 +2430,7 @@ func handleRescan(wsc *wsClient, icmd interface{}) (interface{}, error) {
|
||||
if err != nil {
|
||||
return nil, rpcDecodeHexError(*cmd.EndBlock)
|
||||
}
|
||||
maxBlock, err = chain.BlockHeightByHash(maxBlockHash)
|
||||
maxBlock, err = dag.BlockHeightByHash(maxBlockHash)
|
||||
if err != nil {
|
||||
return nil, &btcjson.RPCError{
|
||||
Code: btcjson.ErrRPCBlockNotFound,
|
||||
@ -2462,7 +2462,7 @@ fetchRange:
|
||||
if maxLoopBlock-minBlock > wire.MaxInvPerMsg {
|
||||
maxLoopBlock = minBlock + wire.MaxInvPerMsg
|
||||
}
|
||||
hashList, err := chain.HeightRange(minBlock, maxLoopBlock)
|
||||
hashList, err := dag.HeightRange(minBlock, maxLoopBlock)
|
||||
if err != nil {
|
||||
rpcsLog.Errorf("Error looking up block range: %v", err)
|
||||
return nil, &btcjson.RPCError{
|
||||
@ -2491,7 +2491,7 @@ fetchRange:
|
||||
// continue the fetch loop again to rescan the new
|
||||
// blocks (or error due to an irrecoverable reorganize).
|
||||
pauseGuard := wsc.server.cfg.SyncMgr.Pause()
|
||||
best := wsc.server.cfg.Chain.BestSnapshot()
|
||||
best := wsc.server.cfg.DAG.BestSnapshot()
|
||||
curHash := &best.Hash
|
||||
again := true
|
||||
if lastBlockHash == nil || *lastBlockHash == *curHash {
|
||||
@ -2518,7 +2518,7 @@ fetchRange:
|
||||
|
||||
loopHashList:
|
||||
for i := range hashList {
|
||||
blk, err := chain.BlockByHash(&hashList[i])
|
||||
blk, err := dag.BlockByHash(&hashList[i])
|
||||
if err != nil {
|
||||
// Only handle reorgs if a block could not be
|
||||
// found for the hash.
|
||||
@ -2554,7 +2554,7 @@ fetchRange:
|
||||
// before the range was evaluated, as it must be
|
||||
// reevaluated for the new hashList.
|
||||
minBlock += int32(i)
|
||||
hashList, err = recoverFromReorg(chain,
|
||||
hashList, err = recoverFromReorg(dag,
|
||||
minBlock, maxBlock, lastBlockHash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
40
server.go
40
server.go
@ -210,7 +210,7 @@ type server struct {
|
||||
sigCache *txscript.SigCache
|
||||
rpcServer *rpcServer
|
||||
syncManager *netsync.SyncManager
|
||||
chain *blockdag.BlockChain
|
||||
dag *blockdag.BlockDAG
|
||||
txMemPool *mempool.TxPool
|
||||
cpuMiner *cpuminer.CPUMiner
|
||||
modifyRebroadcastInv chan interface{}
|
||||
@ -288,7 +288,7 @@ func newServerPeer(s *server, isPersistent bool) *serverPeer {
|
||||
// newestBlock returns the current best block hash and height using the format
|
||||
// required by the configuration for the peer package.
|
||||
func (sp *serverPeer) newestBlock() (*daghash.Hash, int32, error) {
|
||||
best := sp.server.chain.BestSnapshot()
|
||||
best := sp.server.dag.BestSnapshot()
|
||||
return &best.Hash, best.Height, nil
|
||||
}
|
||||
|
||||
@ -669,7 +669,7 @@ func (sp *serverPeer) OnGetBlocks(_ *peer.Peer, msg *wire.MsgGetBlocks) {
|
||||
// over with the genesis block if unknown block locators are provided.
|
||||
//
|
||||
// This mirrors the behavior in the reference implementation.
|
||||
chain := sp.server.chain
|
||||
chain := sp.server.dag
|
||||
hashList := chain.LocateBlocks(msg.BlockLocatorHashes, &msg.HashStop,
|
||||
wire.MaxBlocksPerMsg)
|
||||
|
||||
@ -713,7 +713,7 @@ func (sp *serverPeer) OnGetHeaders(_ *peer.Peer, msg *wire.MsgGetHeaders) {
|
||||
// over with the genesis block if unknown block locators are provided.
|
||||
//
|
||||
// This mirrors the behavior in the reference implementation.
|
||||
chain := sp.server.chain
|
||||
chain := sp.server.dag
|
||||
headers := chain.LocateHeaders(msg.BlockLocatorHashes, &msg.HashStop)
|
||||
if len(headers) == 0 {
|
||||
// Nothing to send.
|
||||
@ -735,7 +735,7 @@ func (sp *serverPeer) OnGetCFilters(_ *peer.Peer, msg *wire.MsgGetCFilters) {
|
||||
return
|
||||
}
|
||||
|
||||
hashes, err := sp.server.chain.HeightToHashRange(int32(msg.StartHeight),
|
||||
hashes, err := sp.server.dag.HeightToHashRange(int32(msg.StartHeight),
|
||||
&msg.StopHash, wire.MaxGetCFiltersReqRange)
|
||||
if err != nil {
|
||||
peerLog.Debugf("Invalid getcfilters request: %v", err)
|
||||
@ -784,7 +784,7 @@ func (sp *serverPeer) OnGetCFHeaders(_ *peer.Peer, msg *wire.MsgGetCFHeaders) {
|
||||
}
|
||||
|
||||
// Fetch the hashes from the block index.
|
||||
hashList, err := sp.server.chain.HeightToHashRange(startHeight,
|
||||
hashList, err := sp.server.dag.HeightToHashRange(startHeight,
|
||||
&msg.StopHash, maxResults)
|
||||
if err != nil {
|
||||
peerLog.Debugf("Invalid getcfheaders request: %v", err)
|
||||
@ -875,7 +875,7 @@ func (sp *serverPeer) OnGetCFCheckpt(_ *peer.Peer, msg *wire.MsgGetCFCheckpt) {
|
||||
return
|
||||
}
|
||||
|
||||
blockHashes, err := sp.server.chain.IntervalBlockHashes(&msg.StopHash,
|
||||
blockHashes, err := sp.server.dag.IntervalBlockHashes(&msg.StopHash,
|
||||
wire.CFCheckptInterval)
|
||||
if err != nil {
|
||||
peerLog.Debugf("Invalid getcfilters request: %v", err)
|
||||
@ -1337,7 +1337,7 @@ func (s *server) pushBlockMsg(sp *serverPeer, hash *daghash.Hash, doneChan chan<
|
||||
// to trigger it to issue another getblocks message for the next
|
||||
// batch of inventory.
|
||||
if sendInv {
|
||||
best := sp.server.chain.BestSnapshot()
|
||||
best := sp.server.dag.BestSnapshot()
|
||||
invMsg := wire.NewMsgInvSizeHint(1)
|
||||
iv := wire.NewInvVect(wire.InvTypeBlock, &best.Hash)
|
||||
invMsg.AddInvVect(iv)
|
||||
@ -1363,7 +1363,7 @@ func (s *server) pushMerkleBlockMsg(sp *serverPeer, hash *daghash.Hash,
|
||||
}
|
||||
|
||||
// Fetch the raw block bytes from the database.
|
||||
blk, err := sp.server.chain.BlockByHash(hash)
|
||||
blk, err := sp.server.dag.BlockByHash(hash)
|
||||
if err != nil {
|
||||
peerLog.Tracef("Unable to fetch requested block hash %v: %v",
|
||||
hash, err)
|
||||
@ -2483,10 +2483,10 @@ func newServer(listenAddrs []string, db database.DB, chainParams *dagconfig.Para
|
||||
|
||||
// Create a new block chain instance with the appropriate configuration.
|
||||
var err error
|
||||
s.chain, err = blockdag.New(&blockdag.Config{
|
||||
s.dag, err = blockdag.New(&blockdag.Config{
|
||||
DB: s.db,
|
||||
Interrupt: interrupt,
|
||||
ChainParams: s.chainParams,
|
||||
DAGParams: s.chainParams,
|
||||
Checkpoints: checkpoints,
|
||||
TimeSource: s.timeSource,
|
||||
SigCache: s.sigCache,
|
||||
@ -2520,7 +2520,7 @@ func newServer(listenAddrs []string, db database.DB, chainParams *dagconfig.Para
|
||||
|
||||
// If no feeEstimator has been found, or if the one that has been found
|
||||
// is behind somehow, create a new one and start over.
|
||||
if s.feeEstimator == nil || s.feeEstimator.LastKnownHeight() != s.chain.BestSnapshot().Height {
|
||||
if s.feeEstimator == nil || s.feeEstimator.LastKnownHeight() != s.dag.BestSnapshot().Height {
|
||||
s.feeEstimator = mempool.NewFeeEstimator(
|
||||
mempool.DefaultEstimateFeeMaxRollback,
|
||||
mempool.DefaultEstimateFeeMinRegisteredBlocks)
|
||||
@ -2538,13 +2538,13 @@ func newServer(listenAddrs []string, db database.DB, chainParams *dagconfig.Para
|
||||
MaxTxVersion: 2,
|
||||
},
|
||||
ChainParams: chainParams,
|
||||
FetchUtxoView: s.chain.FetchUtxoView,
|
||||
BestHeight: func() int32 { return s.chain.BestSnapshot().Height },
|
||||
MedianTimePast: func() time.Time { return s.chain.BestSnapshot().MedianTime },
|
||||
FetchUtxoView: s.dag.FetchUtxoView,
|
||||
BestHeight: func() int32 { return s.dag.BestSnapshot().Height },
|
||||
MedianTimePast: func() time.Time { return s.dag.BestSnapshot().MedianTime },
|
||||
CalcSequenceLock: func(tx *btcutil.Tx, view *blockdag.UtxoViewpoint) (*blockdag.SequenceLock, error) {
|
||||
return s.chain.CalcSequenceLock(tx, view, true)
|
||||
return s.dag.CalcSequenceLock(tx, view, true)
|
||||
},
|
||||
IsDeploymentActive: s.chain.IsDeploymentActive,
|
||||
IsDeploymentActive: s.dag.IsDeploymentActive,
|
||||
SigCache: s.sigCache,
|
||||
AddrIndex: s.addrIndex,
|
||||
FeeEstimator: s.feeEstimator,
|
||||
@ -2553,7 +2553,7 @@ func newServer(listenAddrs []string, db database.DB, chainParams *dagconfig.Para
|
||||
|
||||
s.syncManager, err = netsync.New(&netsync.Config{
|
||||
PeerNotifier: &s,
|
||||
Chain: s.chain,
|
||||
DAG: s.dag,
|
||||
TxMemPool: s.txMemPool,
|
||||
ChainParams: s.chainParams,
|
||||
DisableCheckpoints: cfg.DisableCheckpoints,
|
||||
@ -2576,7 +2576,7 @@ func newServer(listenAddrs []string, db database.DB, chainParams *dagconfig.Para
|
||||
TxMinFreeFee: cfg.minRelayTxFee,
|
||||
}
|
||||
blockTemplateGenerator := mining.NewBlkTmplGenerator(&policy,
|
||||
s.chainParams, s.txMemPool, s.chain, s.timeSource, s.sigCache)
|
||||
s.chainParams, s.txMemPool, s.dag, s.timeSource, s.sigCache)
|
||||
s.cpuMiner = cpuminer.New(&cpuminer.Config{
|
||||
ChainParams: chainParams,
|
||||
BlockTemplateGenerator: blockTemplateGenerator,
|
||||
@ -2685,7 +2685,7 @@ func newServer(listenAddrs []string, db database.DB, chainParams *dagconfig.Para
|
||||
ConnMgr: &rpcConnManager{&s},
|
||||
SyncMgr: &rpcSyncMgr{&s, s.syncManager},
|
||||
TimeSource: s.timeSource,
|
||||
Chain: s.chain,
|
||||
DAG: s.dag,
|
||||
ChainParams: chainParams,
|
||||
DB: db,
|
||||
TxMemPool: s.txMemPool,
|
||||
|
Loading…
x
Reference in New Issue
Block a user