Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

netsync: Split blockmanager into separate package. #2500

Merged
merged 6 commits into from
Dec 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion blockdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func dumpBlockChain(params *chaincfg.Params, b *blockchain.BlockChain) error {
progressLogger.LogBlockHeight(bl.MsgBlock(), tipHeight)
}

bmgrLog.Infof("Successfully dumped the blockchain (%v blocks) to %v.",
srvrLog.Infof("Successfully dumped the blockchain (%v blocks) to %v.",
tipHeight, cfg.DumpBlockchain)

return nil
Expand Down
4 changes: 2 additions & 2 deletions docs/json_rpc_api.mediawiki
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ the method name for further details such as parameter and return information.
: Dynamically changes the debug logging level.
: The levelspec can either be a debug level or of the form <code><subsystem>=<level>,<subsystem2>=<level2>,...</code>
: The valid debug levels are <code>trace</code>, <code>debug</code>, <code>info</code>, <code>warn</code>, <code>error</code>, and <code>critical</code>.
: The valid subsystems are <code>AMGR</code>, <code>ADXR</code>, <code>BCDB</code>, <code>BMGR</code>, <code>DCRD</code>, <code>CHAN</code>, <code>DISC</code>, <code>PEER</code>, <code>RPCS</code>, <code>SCRP</code>, <code>SRVR</code>, and <code>TXMP</code>.
: The valid subsystems are <code>AMGR</code>, <code>ADXR</code>, <code>BCDB</code>, <code>DCRD</code>, <code>CHAN</code>, <code>DISC</code>, <code>PEER</code>, <code>RPCS</code>, <code>SCRP</code>, <code>SRVR</code>, <code>SYNC</code>, and <code>TXMP</code>.
: Additionally, the special keyword <code>show</code> can be used to get a list of the available subsystems.
|-
!Returns
Expand All @@ -559,7 +559,7 @@ the method name for further details such as parameter and return information.
|<code>Done.</code>
|-
!Example <code>show</code> Return
|<code>Supported subsystems [AMGR ADXR BCDB BMGR DCRD CHAN DISC PEER RPCS SCRP SRVR TXMP]</code>
|<code>Supported subsystems [AMGR ADXR BCDB DCRD CHAN DISC PEER RPCS SCRP SRVR SYNC TXMP]</code>
|}

----
Expand Down
10 changes: 5 additions & 5 deletions internal/fees/estimator.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,11 +623,11 @@ func (stats *Estimator) removeFromMemPool(blocksInMemPool int32, rate feeRate) {
// function but not on a previous newMemPoolTx. This leaves the fee db
// in an undefined state and should never happen in regular use. If this
// happens, then there is a logic or coding error somewhere, either in
// the estimator itself or on its hooking to the mempool/blockmanager.
// Either way, the easiest way to fix this is to completely delete the
// database and start again.
// During development, you can use a panic() here and we might return it
// after being confident that the estimator is completely bug free.
// the estimator itself or on its hooking to the mempool/network sync
// manager. Either way, the easiest way to fix this is to completely
// delete the database and start again. During development, you can use
// a panic() here and we might return it after being confident that the
// estimator is completely bug free.
log.Errorf("Transaction count in bucket index %d and confirmation "+
"index %d became < 0", bucketIdx, confirmIdx)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/mining/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type blockManagerFacade interface {
// best chain.
ForceReorganization(formerBest, newBest chainhash.Hash) error

// IsCurrent returns whether or not the block manager believes it is synced
// with the connected peers.
// IsCurrent returns whether or not the net sync manager believes it is
// synced with the connected peers.
IsCurrent() bool
}
21 changes: 21 additions & 0 deletions internal/netsync/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
netsync
=======

[![Build Status](https://github.com/decred/dcrd/workflows/Build%20and%20Test/badge.svg)](https://github.com/decred/dcrd/actions)
[![ISC License](https://img.shields.io/badge/license-ISC-blue.svg)](http://copyfree.org)
[![Doc](https://img.shields.io/badge/doc-reference-blue.svg)](https://pkg.go.dev/github.com/decred/dcrd/internal/netsync)

Package netsync implements a concurrency safe block syncing protocol.

## Overview

The provided implementation of SyncManager communicates with connected peers to
perform an initial block download, keep the chain in sync, and announce new
blocks connected to the chain. Currently the sync manager selects a single sync
peer that it downloads all blocks from until it is up to date with the longest
chain the sync peer is aware of.

## License

Package netsync is licensed under the [copyfree](http://copyfree.org) ISC
License.
14 changes: 14 additions & 0 deletions internal/netsync/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) 2020 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

/*
Package netsync implements a concurrency safe block syncing protocol.

The provided implementation of SyncManager communicates with connected peers to
perform an initial block download, keep the chain in sync, and announce new
blocks connected to the chain. Currently the sync manager selects a single sync
peer that it downloads all blocks from until it is up to date with the longest
chain the sync peer is aware of.
*/
package netsync
23 changes: 23 additions & 0 deletions internal/netsync/interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) 2020 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

package netsync

import (
"github.com/decred/dcrd/chaincfg/chainhash"
"github.com/decred/dcrd/dcrutil/v3"
"github.com/decred/dcrd/peer/v2"
)

// PeerNotifier provides an interface to notify peers of status changes related
// to blocks and transactions.
type PeerNotifier interface {
// AnnounceNewTransactions generates and relays inventory vectors and
// notifies websocket clients of the passed transactions.
AnnounceNewTransactions(txns []*dcrutil.Tx)

// UpdatePeerHeights updates the heights of all peers who have announced the
// latest connected main chain block, or a recognized orphan.
UpdatePeerHeights(latestBlkHash *chainhash.Hash, latestHeight int64, updateSource *peer.Peer)
}
22 changes: 22 additions & 0 deletions internal/netsync/log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) 2020 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

package netsync

import (
"github.com/decred/slog"
)

// log is a logger that is initialized with no output filters. This
// means the package will not perform any logging by default until the caller
// requests it.
// The default amount of logging is none.
var log = slog.Disabled

// UseLogger uses a specified Logger to output package logging info.
// This should be used in preference to SetLogWriter if the caller is also
// using slog.
func UseLogger(logger slog.Logger) {
log = logger
}
Loading