Skip to content

Commit

Permalink
multi: remove chainState deps in server & cpuminer.
Browse files Browse the repository at this point in the history
Port of upstream commit 2274d36 (subset). In preparation of the
removal of chainState.
  • Loading branch information
dnldd committed Sep 12, 2018
1 parent fbbfb22 commit c0b0b6c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cpuminer.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ out:
// Hacks to make dcr work with Decred PoC (simnet only)
// TODO Remove before production.
if cfg.SimNet {
_, curHeight := m.server.blockManager.chainState.Best()
curHeight := m.server.blockManager.chain.BestSnapshot().Height

if curHeight == 1 {
time.Sleep(5500 * time.Millisecond) // let wallet reconn
Expand Down
23 changes: 11 additions & 12 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,10 +494,10 @@ func (sp *serverPeer) OnGetMiningState(p *peer.Peer, msg *wire.MsgGetMiningState
// Access the block manager and get the list of best blocks to mine on.
bm := sp.server.blockManager
mp := sp.server.txMemPool
newest, height := bm.chainState.Best()
best := bm.chain.BestSnapshot()

// Send out blank mining states if it's early in the blockchain.
if height < activeNetParams.StakeValidationHeight-1 {
if best.Height < activeNetParams.StakeValidationHeight-1 {
err := sp.pushMiningStateMsg(0, nil, nil)
if err != nil {
peerLog.Warnf("unexpected error while pushing data for "+
Expand All @@ -512,15 +512,15 @@ func (sp *serverPeer) OnGetMiningState(p *peer.Peer, msg *wire.MsgGetMiningState
children, err := bm.TipGeneration()
if err != nil {
peerLog.Warnf("failed to access block manager to get the generation "+
"for a mining state request (block: %v): %v", newest, err)
"for a mining state request (block: %v): %v", best.Hash, err)
return
}

// Get the list of blocks of blocks that are eligible to built on and
// limit the list to the maximum number of allowed eligible block hashes
// per mining state message. There is nothing to send when there are no
// eligible blocks.
blockHashes := SortParentsByVotes(mp, *newest, children,
blockHashes := SortParentsByVotes(mp, best.Hash, children,
bm.server.chainParams)
numBlocks := len(blockHashes)
if numBlocks == 0 {
Expand All @@ -545,7 +545,7 @@ func (sp *serverPeer) OnGetMiningState(p *peer.Peer, msg *wire.MsgGetMiningState
voteHashes = append(voteHashes, vhsForBlock...)
}

err = sp.pushMiningStateMsg(uint32(height), blockHashes, voteHashes)
err = sp.pushMiningStateMsg(uint32(best.Height), blockHashes, voteHashes)
if err != nil {
peerLog.Warnf("unexpected error while pushing data for "+
"mining state request: %v", err.Error())
Expand Down Expand Up @@ -2499,10 +2499,7 @@ func newServer(listenAddrs []string, db database.DB, chainParams *chaincfg.Param
},
ChainParams: chainParams,
NextStakeDifficulty: func() (int64, error) {
bm.chainState.Lock()
sDiff := bm.chainState.nextStakeDifficulty
bm.chainState.Unlock()
return sDiff, nil
return bm.chain.BestSnapshot().NextStakeDiff, nil
},
FetchUtxoView: bm.chain.FetchUtxoView,
BlockByHash: bm.chain.BlockByHash,
Expand All @@ -2511,9 +2508,11 @@ func newServer(listenAddrs []string, db database.DB, chainParams *chaincfg.Param
CalcSequenceLock: bm.chain.CalcSequenceLock,
SubsidyCache: bm.chain.FetchSubsidyCache(),
SigCache: s.sigCache,
PastMedianTime: func() time.Time { return bm.chain.BestSnapshot().MedianTime },
AddrIndex: s.addrIndex,
ExistsAddrIndex: s.existsAddrIndex,
PastMedianTime: func() time.Time {
return bm.chain.BestSnapshot().MedianTime
},
AddrIndex: s.addrIndex,
ExistsAddrIndex: s.existsAddrIndex,
}
s.txMemPool = mempool.New(&txC)

Expand Down

0 comments on commit c0b0b6c

Please sign in to comment.