Bech32HRPSegwit: "tm",
}
-// TestNetParams is the config for test-net
+// SoloNetParams is the config for test-net
var SoloNetParams = Params{
Name: "solo",
Bech32HRPSegwit: "sm",
+++ /dev/null
-package consensus
-
-// ServiceFlag use uint64 to indicate what kind of server this node can provide.
-// one uint64 can represent 64 type of service flag
-type ServiceFlag uint64
-
-const (
- // SFFullNode is a flag used to indicate a peer is a full node.
- SFFullNode ServiceFlag = 1 << iota
-
- DefaultServices = SFFullNode
-)
--- /dev/null
+package consensus
+
+// ServiceFlag use uint64 to indicate what kind of server this node can provide.
+// one uint64 can represent 64 type of service flag
+type ServiceFlag uint64
+
+const (
+ // SFFullNode is a flag used to indicate a peer is a full node.
+ SFFullNode ServiceFlag = 1 << iota
+ // SFFastSync indicate peer support header first mode
+ SFFastSync
+ // DefaultServices is the server that this node support
+ DefaultServices = SFFullNode | SFFastSync
+)
+
+// IsEnable check does the flag support the input flag function
+func (f ServiceFlag) IsEnable(checkFlag ServiceFlag) bool {
+ return f&checkFlag == checkFlag
+}
--- /dev/null
+package consensus
+
+import "testing"
+
+func TestIsEnable(t *testing.T) {
+ cases := []struct {
+ baseFlag ServiceFlag
+ checkFlage ServiceFlag
+ result bool
+ }{
+ {
+ baseFlag: SFFullNode,
+ checkFlage: SFFullNode,
+ result: true,
+ },
+ {
+ baseFlag: SFFullNode,
+ checkFlage: SFFastSync,
+ result: false,
+ },
+ {
+ baseFlag: SFFullNode | SFFastSync,
+ checkFlage: SFFullNode,
+ result: true,
+ },
+ {
+ baseFlag: SFFullNode | SFFastSync,
+ checkFlage: SFFastSync,
+ result: true,
+ },
+ }
+
+ for i, c := range cases {
+ if c.baseFlag.IsEnable(c.checkFlage) != c.result {
+ t.Errorf("test case #%b got %b, want %b", i, c.baseFlag.IsEnable(c.checkFlage), c.result)
+ }
+ }
+}
// Block cache
queue *prque.Prque // Queue containing the import operations (block number sorted)
- queues map[string]int // Per peer block counts to prevent memory exhaustion
queued map[bc.Hash]*blockPending // Set of already queued blocks (to dedup imports)
}
//SyncManager Sync Manager is responsible for the business layer information synchronization
type SyncManager struct {
- networkID uint64
- sw *p2p.Switch
+ sw *p2p.Switch
privKey crypto.PrivKeyEd25519 // local node's p2p key
chain *core.Chain
package netsync
import (
+ "strconv"
"sync"
log "github.com/sirupsen/logrus"
"gopkg.in/fatih/set.v0"
+ "github.com/bytom/consensus"
"github.com/bytom/errors"
"github.com/bytom/p2p"
"github.com/bytom/p2p/trust"
type peer struct {
mtx sync.RWMutex
version int // Protocol version negotiated
+ services consensus.ServiceFlag
id string
height uint64
hash *bc.Hash
}
func newPeer(height uint64, hash *bc.Hash, Peer *p2p.Peer) *peer {
+ services := consensus.SFFullNode
+ if len(Peer.Other) != 0 {
+ if serviceFlag, err := strconv.ParseUint(Peer.Other[0], 10, 64); err != nil {
+ services = consensus.ServiceFlag(serviceFlag)
+ }
+ }
+
return &peer{
version: defaultVersion,
+ services: services,
id: Peer.Key,
height: height,
hash: hash,