diff --git a/blockdag/dag.go b/blockdag/dag.go index fde05c543..79a05489a 100644 --- a/blockdag/dag.go +++ b/blockdag/dag.go @@ -709,20 +709,20 @@ func (dag *BlockDAG) updateFinalityPoint() { dag.lastFinalityPoint = newFinalityPoint } -// NextBlockFeeTransactionWithLock prepares the fee transaction for the next mined block +// NextBlockFeeTransaction prepares the fee transaction for the next mined block // // This function CAN'T be called with the DAG lock not held. -func (dag *BlockDAG) NextBlockFeeTransactionWithLock() (*wire.MsgTx, error) { +func (dag *BlockDAG) NextBlockFeeTransaction() (*wire.MsgTx, error) { dag.dagLock.RLock() defer dag.dagLock.RUnlock() - return dag.NextBlockFeeTransaction() + return dag.NextBlockFeeTransactionNoLock() } -// NextBlockFeeTransaction prepares the fee transaction for the next mined block +// NextBlockFeeTransactionNoLock prepares the fee transaction for the next mined block // // This function MUST be called with the DAG read-lock held -func (dag *BlockDAG) NextBlockFeeTransaction() (*wire.MsgTx, error) { +func (dag *BlockDAG) NextBlockFeeTransactionNoLock() (*wire.MsgTx, error) { _, txsAcceptanceData, _, err := dag.virtual.blockNode.verifyAndBuildUTXO(dag, nil, true) if err != nil { return nil, err diff --git a/blockdag/validate.go b/blockdag/validate.go index e699e1bc9..524b35543 100644 --- a/blockdag/validate.go +++ b/blockdag/validate.go @@ -1183,21 +1183,21 @@ func countSpentOutputs(block *util.Block) int { return numSpent } -// CheckConnectBlockTemplateWithLock fully validates that connecting the passed block to +// CheckConnectBlockTemplate fully validates that connecting the passed block to // the DAG does not violate any consensus rules, aside from the proof of // work requirement. // // This function is safe for concurrent access. -func (dag *BlockDAG) CheckConnectBlockTemplateWithLock(block *util.Block) error { +func (dag *BlockDAG) CheckConnectBlockTemplate(block *util.Block) error { dag.dagLock.RLock() defer dag.dagLock.RUnlock() - return dag.CheckConnectBlockTemplate(block) + return dag.CheckConnectBlockTemplateNoLock(block) } -// CheckConnectBlockTemplate fully validates that connecting the passed block to +// CheckConnectBlockTemplateNoLock fully validates that connecting the passed block to // the DAG does not violate any consensus rules, aside from the proof of // work requirement. The block must connect to the current tip of the main dag. -func (dag *BlockDAG) CheckConnectBlockTemplate(block *util.Block) error { +func (dag *BlockDAG) CheckConnectBlockTemplateNoLock(block *util.Block) error { // Skip the proof of work check as this is just a block template. flags := BFNoPoWCheck diff --git a/blockdag/validate_test.go b/blockdag/validate_test.go index 5beeffbcc..5731ecad5 100644 --- a/blockdag/validate_test.go +++ b/blockdag/validate_test.go @@ -107,14 +107,14 @@ func TestCheckConnectBlockTemplate(t *testing.T) { } // Block 3 should fail to connect since it's already inserted. - err = dag.CheckConnectBlockTemplate(blocks[3]) + err = dag.CheckConnectBlockTemplateNoLock(blocks[3]) if err == nil { t.Fatal("CheckConnectBlockTemplate: Did not received expected error " + "on block 3") } // Block 4 should connect successfully to tip of chain. - err = dag.CheckConnectBlockTemplate(blocks[4]) + err = dag.CheckConnectBlockTemplateNoLock(blocks[4]) if err != nil { t.Fatalf("CheckConnectBlockTemplate: Received unexpected error on "+ "block 4: %v", err) @@ -127,7 +127,7 @@ func TestCheckConnectBlockTemplate(t *testing.T) { // Block 3a should connect even though it does not build on dag tips. blocks[5].SetHeight(3) // set height manually because it was set to 0 in loadBlocks - err = dag.CheckConnectBlockTemplate(blocks[5]) + err = dag.CheckConnectBlockTemplateNoLock(blocks[5]) if err != nil { t.Fatal("CheckConnectBlockTemplate: Recieved unexpected error on " + "block 3a that connects below the tips") @@ -138,7 +138,7 @@ func TestCheckConnectBlockTemplate(t *testing.T) { invalidPowMsgBlock.Header.Nonce++ invalidPowBlock := util.NewBlock(&invalidPowMsgBlock) invalidPowBlock.SetHeight(blocks[4].Height()) - err = dag.CheckConnectBlockTemplate(invalidPowBlock) + err = dag.CheckConnectBlockTemplateNoLock(invalidPowBlock) if err != nil { t.Fatalf("CheckConnectBlockTemplate: Received unexpected error on "+ "block 4 with bad nonce: %v", err) @@ -147,7 +147,7 @@ func TestCheckConnectBlockTemplate(t *testing.T) { // Invalid block building on chain tip should fail to connect. invalidBlock := *blocks[4].MsgBlock() invalidBlock.Header.Bits-- - err = dag.CheckConnectBlockTemplate(util.NewBlock(&invalidBlock)) + err = dag.CheckConnectBlockTemplateNoLock(util.NewBlock(&invalidBlock)) if err == nil { t.Fatal("CheckConnectBlockTemplate: Did not received expected error " + "on block 4 with invalid difficulty bits") diff --git a/dnsseeder/dnsseed.go b/dnsseeder/dnsseed.go index 8d2588ac8..a2ef236f0 100644 --- a/dnsseeder/dnsseed.go +++ b/dnsseeder/dnsseed.go @@ -6,7 +6,6 @@ package main import ( "fmt" - "github.com/daglabs/btcd/dagconfig/daghash" "log" "net" "os" @@ -15,6 +14,8 @@ import ( "sync/atomic" "time" + "github.com/daglabs/btcd/dagconfig/daghash" + "github.com/daglabs/btcd/connmgr" "github.com/daglabs/btcd/peer" "github.com/daglabs/btcd/signal" diff --git a/mining/mining.go b/mining/mining.go index 17dcc927f..088ca37ac 100644 --- a/mining/mining.go +++ b/mining/mining.go @@ -413,7 +413,7 @@ func (g *BlkTmplGenerator) NewBlockTemplate(payToAddress util.Address) (*BlockTe } numCoinbaseSigOps := int64(blockdag.CountSigOps(coinbaseTx)) - msgFeeTransaction, err := g.dag.NextBlockFeeTransaction() + msgFeeTransaction, err := g.dag.NextBlockFeeTransactionNoLock() if err != nil { return nil, err } @@ -675,7 +675,7 @@ func (g *BlkTmplGenerator) NewBlockTemplate(payToAddress util.Address) (*BlockTe block := util.NewBlock(&msgBlock) block.SetHeight(nextBlockHeight) - if err := g.dag.CheckConnectBlockTemplate(block); err != nil { + if err := g.dag.CheckConnectBlockTemplateNoLock(block); err != nil { return nil, err } diff --git a/netsync/manager.go b/netsync/manager.go index 86f3fdc80..b9e9bdfef 100644 --- a/netsync/manager.go +++ b/netsync/manager.go @@ -665,12 +665,12 @@ func (sm *SyncManager) addBlocksToRequestQueue(state *peerSyncState, hashes []*d for _, hash := range hashes { if _, exists := sm.requestedBlocks[*hash]; !exists { iv := wire.NewInvVect(wire.InvTypeBlock, hash) - state.addInvToRequestQueue(iv, isRelayedInv) + state.addInvToRequestQueueNoLock(iv, isRelayedInv) } } } -func (state *peerSyncState) addInvToRequestQueue(iv *wire.InvVect, isRelayedInv bool) { +func (state *peerSyncState) addInvToRequestQueueNoLock(iv *wire.InvVect, isRelayedInv bool) { if isRelayedInv { if _, exists := state.relayedInvsRequestQueueSet[*iv.Hash]; !exists { state.relayedInvsRequestQueueSet[*iv.Hash] = struct{}{} @@ -684,10 +684,10 @@ func (state *peerSyncState) addInvToRequestQueue(iv *wire.InvVect, isRelayedInv } } -func (state *peerSyncState) addInvToRequestQueueWithLock(iv *wire.InvVect, isRelayedInv bool) { +func (state *peerSyncState) addInvToRequestQueue(iv *wire.InvVect, isRelayedInv bool) { state.requestQueueMtx.Lock() defer state.requestQueueMtx.Unlock() - state.addInvToRequestQueue(iv, isRelayedInv) + state.addInvToRequestQueueNoLock(iv, isRelayedInv) } // fetchHeaderBlocks creates and sends a request to the syncPeer for the next @@ -955,7 +955,7 @@ func (sm *SyncManager) handleInvMsg(imsg *invMsg) { } // Add it to the request queue. - state.addInvToRequestQueueWithLock(iv, iv.Type != wire.InvTypeSyncBlock) + state.addInvToRequestQueue(iv, iv.Type != wire.InvTypeSyncBlock) continue } diff --git a/server/rpc/rpcserver.go b/server/rpc/rpcserver.go index b8be9f1a6..83e223da5 100644 --- a/server/rpc/rpcserver.go +++ b/server/rpc/rpcserver.go @@ -2154,7 +2154,7 @@ func handleGetBlockTemplateProposal(s *Server, request *btcjson.TemplateRequest) return "bad-parentblk", nil } - if err := s.cfg.DAG.CheckConnectBlockTemplateWithLock(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: %s", err) log.Error(errStr)