Browse Source

moved out log and median

master
Loki Verloren 6 months ago
parent
commit
5dc89b0b7f

blockchain/log.go → blockchain/bclog/log.go View File

@@ -1,13 +1,13 @@
1
-package blockchain
1
+package bclog
2 2
 
3 3
 import (
4 4
 	"git.parallelcoin.io/dev/btcd/btclog"
5 5
 )
6 6
 
7
-// log is a logger that is initialized with no output filters.  This
7
+// Log is a logger that is initialized with no output filters.  This
8 8
 // means the package will not perform any logging by default until the caller
9 9
 // requests it.
10
-var log btclog.Logger
10
+var Log btclog.Logger
11 11
 
12 12
 // The default amount of logging is none.
13 13
 func init() {
@@ -17,10 +17,10 @@ func init() {
17 17
 // DisableLog disables all library log output.  Logging output is disabled
18 18
 // by default until UseLogger is called.
19 19
 func DisableLog() {
20
-	log = btclog.Disabled
20
+	Log = btclog.Disabled
21 21
 }
22 22
 
23 23
 // UseLogger uses a specified Logger to output package logging info.
24 24
 func UseLogger(logger btclog.Logger) {
25
-	log = logger
25
+	Log = logger
26 26
 }

+ 2
- 2
blockchain/best/beststate.go View File

@@ -24,7 +24,7 @@ type State struct {
24 24
 	BlockWeight uint64         // The weight of the block.
25 25
 	NumTxns     uint64         // The number of txns in the block.
26 26
 	TotalTxns   uint64         // The total number of txns in the chain.
27
-	MedianTime  time.Time      // Median time as per CalcPastMedianTime.
27
+	Time  time.Time      // Median time as per CalcPastMedianTime.
28 28
 }
29 29
 
30 30
 // NewState returns a new best stats instance for the given parameters.
@@ -39,6 +39,6 @@ func NewState(n *node.Block, blockSize, blockWeight, numTxns,
39 39
 		BlockWeight: blockWeight,
40 40
 		NumTxns:     numTxns,
41 41
 		TotalTxns:   totalTxns,
42
-		MedianTime:  medianTime,
42
+		Time:  medianTime,
43 43
 	}
44 44
 }

+ 15
- 12
blockchain/chain.go View File

@@ -11,10 +11,13 @@ import (
11 11
 	"sync"
12 12
 	"time"
13 13
 
14
+	"git.parallelcoin.io/dev/btcd/blockchain/bclog"
15
+
14 16
 	"git.parallelcoin.io/dev/btcd/blockchain/best"
15 17
 	"git.parallelcoin.io/dev/btcd/blockchain/db"
16 18
 	"git.parallelcoin.io/dev/btcd/blockchain/er"
17 19
 	"git.parallelcoin.io/dev/btcd/blockchain/index"
20
+	"git.parallelcoin.io/dev/btcd/blockchain/median"
18 21
 	"git.parallelcoin.io/dev/btcd/blockchain/node"
19 22
 	"git.parallelcoin.io/dev/btcd/blockchain/status"
20 23
 	"git.parallelcoin.io/dev/btcd/txscript/sig"
@@ -70,7 +73,7 @@ type BlockChain struct {
70 73
 	CheckpointsByHeight map[int32]*chaincfg.Checkpoint
71 74
 	DB                  database.DB
72 75
 	ChainParams         *chaincfg.Params
73
-	TimeSource          MedianTimeSource
76
+	TimeSource          median.TimeSource
74 77
 	SigCache            *sig.Cache
75 78
 	IndexManager        IndexManager
76 79
 	HashCache           *hash.Cache
@@ -1030,12 +1033,12 @@ func (b *BlockChain) ReorganizeChain(detachNodes, attachNodes *list.List) error
1030 1033
 	// Log the point where the chain forked and old and new best chain
1031 1034
 	// heads.
1032 1035
 	if forkNode != nil {
1033
-		log.Infof("REORGANIZE: Chain forks at %v (height %v)", forkNode.Hash,
1036
+		bclog.Log.Infof("REORGANIZE: Chain forks at %v (height %v)", forkNode.Hash,
1034 1037
 			forkNode.Height)
1035 1038
 	}
1036
-	log.Infof("REORGANIZE: Old best chain head was %v (height %v)",
1039
+	bclog.Log.Infof("REORGANIZE: Old best chain head was %v (height %v)",
1037 1040
 		&oldBest.Hash, oldBest.Height)
1038
-	log.Infof("REORGANIZE: New best chain head is %v (height %v)",
1041
+	bclog.Log.Infof("REORGANIZE: New best chain head is %v (height %v)",
1039 1042
 		newBest.Hash, newBest.Height)
1040 1043
 
1041 1044
 	return nil
@@ -1064,7 +1067,7 @@ func (b *BlockChain) ConnectBestChain(nn *node.Block, bb *block.Block, flags Beh
1064 1067
 		// valid, we flush in connectBlock and if the block is invalid, the
1065 1068
 		// worst that can happen is we revalidate the block after a restart.
1066 1069
 		if writeErr := b.Index.FlushToDB(); writeErr != nil {
1067
-			log.Warnf("Error flushing block index changes to disk: %v",
1070
+			bclog.Log.Warnf("Error flushing block index changes to disk: %v",
1068 1071
 				writeErr)
1069 1072
 		}
1070 1073
 	}
@@ -1142,7 +1145,7 @@ func (b *BlockChain) ConnectBestChain(nn *node.Block, bb *block.Block, flags Beh
1142 1145
 		return true, nil
1143 1146
 	}
1144 1147
 	if fastAdd {
1145
-		log.Warnf("fastAdd set in the side chain case? %v\n",
1148
+		bclog.Log.Warnf("fastAdd set in the side chain case? %v\n",
1146 1149
 			bb.Hash())
1147 1150
 	}
1148 1151
 
@@ -1152,11 +1155,11 @@ func (b *BlockChain) ConnectBestChain(nn *node.Block, bb *block.Block, flags Beh
1152 1155
 		// Log information about how the block is forking the chain.
1153 1156
 		fork := b.BestChain.FindFork(nn)
1154 1157
 		if fork.Hash.IsEqual(parentHash) {
1155
-			log.Infof("FORK: Block %v forks the chain at height %d"+
1158
+			bclog.Log.Infof("FORK: Block %v forks the chain at height %d"+
1156 1159
 				"/block %v, but does not cause a reorganize",
1157 1160
 				nn.Hash, fork.Height, fork.Hash)
1158 1161
 		} else {
1159
-			log.Infof("EXTEND FORK: Block %v extends a side chain "+
1162
+			bclog.Log.Infof("EXTEND FORK: Block %v extends a side chain "+
1160 1163
 				"which forks the chain at height %d/block %v",
1161 1164
 				nn.Hash, fork.Height, fork.Hash)
1162 1165
 		}
@@ -1174,7 +1177,7 @@ func (b *BlockChain) ConnectBestChain(nn *node.Block, bb *block.Block, flags Beh
1174 1177
 	detachNodes, attachNodes := b.GetReorganizeNodes(nn)
1175 1178
 
1176 1179
 	// Reorganize the chain.
1177
-	log.Infof("REORGANIZE: Block %v is causing a reorganize.", nn.Hash)
1180
+	bclog.Log.Infof("REORGANIZE: Block %v is causing a reorganize.", nn.Hash)
1178 1181
 	err := b.ReorganizeChain(detachNodes, attachNodes)
1179 1182
 
1180 1183
 	// Either getReorganizeNodes or reorganizeChain could have made unsaved
@@ -1182,7 +1185,7 @@ func (b *BlockChain) ConnectBestChain(nn *node.Block, bb *block.Block, flags Beh
1182 1185
 	// error. The index would only be dirty if the block failed to connect, so
1183 1186
 	// we can ignore any errors writing.
1184 1187
 	if writeErr := b.Index.FlushToDB(); writeErr != nil {
1185
-		log.Warnf("Error flushing block index changes to disk: %v", writeErr)
1188
+		bclog.Log.Warnf("Error flushing block index changes to disk: %v", writeErr)
1186 1189
 	}
1187 1190
 
1188 1191
 	return err == nil, err
@@ -1657,7 +1660,7 @@ type Config struct {
1657 1660
 	// The caller is expected to keep a reference to the time source as well
1658 1661
 	// and add time samples from other peers on the network so the local
1659 1662
 	// time is adjusted to be in agreement with other peers.
1660
-	TimeSource MedianTimeSource
1663
+	TimeSource median.TimeSource
1661 1664
 
1662 1665
 	// SigCache defines a signature cache to use when when validating
1663 1666
 	// signatures.  This is typically most useful when individual
@@ -1768,7 +1771,7 @@ func New(config *Config) (*BlockChain, error) {
1768 1771
 	}
1769 1772
 
1770 1773
 	bestNode := b.BestChain.GetTip()
1771
-	log.Infof("Chain state (height %d, hash %v, totaltx %d, work %v)",
1774
+	bclog.Log.Infof("Chain state (height %d, hash %v, totaltx %d, work %v)",
1772 1775
 		bestNode.Height, bestNode.Hash, b.StateSnapshot.TotalTxns,
1773 1776
 		bestNode.WorkSum)
1774 1777
 

+ 4
- 3
blockchain/chainio.go View File

@@ -11,6 +11,7 @@ import (
11 11
 	"sync"
12 12
 	"time"
13 13
 
14
+	"git.parallelcoin.io/dev/btcd/blockchain/bclog"
14 15
 	"git.parallelcoin.io/dev/btcd/blockchain/best"
15 16
 	"git.parallelcoin.io/dev/btcd/blockchain/bucket"
16 17
 	"git.parallelcoin.io/dev/btcd/blockchain/db"
@@ -751,7 +752,7 @@ func (b *BlockChain) InitChainState() error {
751 752
 		// initialized for use with chain yet, so break out now to allow
752 753
 		// that to happen under a writable database transaction.
753 754
 		serializedData := dbTx.Metadata().Get(ChainStateKeyName)
754
-		log.Tracef("Serialized chain state: %x", serializedData)
755
+		bclog.Log.Tracef("Serialized chain state: %x", serializedData)
755 756
 		state, err := DeserializeBestChainState(serializedData)
756 757
 		if err != nil {
757 758
 			return err
@@ -762,7 +763,7 @@ func (b *BlockChain) InitChainState() error {
762 763
 		// number of nodes are already known, perform a single alloc
763 764
 		// for them versus a whole bunch of little ones to reduce
764 765
 		// pressure on the GC.
765
-		log.Infof("Loading block index...")
766
+		bclog.Log.Infof("Loading block index...")
766 767
 
767 768
 		blockIndexBucket := dbTx.Metadata().Bucket(bucket.BlockIndexName)
768 769
 
@@ -848,7 +849,7 @@ func (b *BlockChain) InitChainState() error {
848 849
 			// we'll mark it as valid now to ensure consistency once
849 850
 			// we're up and running.
850 851
 			if !iterNode.Status.KnownValid() {
851
-				log.Infof("Block %v (height=%v) ancestor of "+
852
+				bclog.Log.Infof("Block %v (height=%v) ancestor of "+
852 853
 					"chain tip not marked as valid, "+
853 854
 					"upgrading to valid for consistency",
854 855
 					iterNode.Hash, iterNode.Height)

+ 2
- 1
blockchain/checkpoints.go View File

@@ -4,6 +4,7 @@ import (
4 4
 	"fmt"
5 5
 	"time"
6 6
 
7
+	"git.parallelcoin.io/dev/btcd/blockchain/bclog"
7 8
 	"git.parallelcoin.io/dev/btcd/blockchain/er"
8 9
 	"git.parallelcoin.io/dev/btcd/blockchain/node"
9 10
 	"git.parallelcoin.io/dev/btcd/btcutil/block"
@@ -73,7 +74,7 @@ func (b *BlockChain) VerifyCheckpoint(height int32, hash *chainhash.Hash) bool {
73 74
 		return false
74 75
 	}
75 76
 
76
-	log.Infof("Verified checkpoint at height %d/block %s", checkpoint.Height,
77
+	bclog.Log.Infof("Verified checkpoint at height %d/block %s", checkpoint.Height,
77 78
 		checkpoint.Hash)
78 79
 	return true
79 80
 }

+ 3
- 2
blockchain/common_test.go View File

@@ -15,6 +15,7 @@ import (
15 15
 	"time"
16 16
 
17 17
 	"git.parallelcoin.io/dev/btcd/blockchain/index"
18
+	"git.parallelcoin.io/dev/btcd/blockchain/median"
18 19
 	"git.parallelcoin.io/dev/btcd/blockchain/node"
19 20
 	"git.parallelcoin.io/dev/btcd/wire/msg"
20 21
 
@@ -182,7 +183,7 @@ func ChainSetup(dbName string, params *chaincfg.Params) (*BlockChain, func(), er
182 183
 		DB:          db,
183 184
 		ChainParams: &paramsCopy,
184 185
 		Checkpoints: nil,
185
-		TimeSource:  NewMedianTime(),
186
+		TimeSource:  median.NewTime(),
186 187
 		SigCache:    sig.NewCache(1000),
187 188
 	})
188 189
 	if err != nil {
@@ -365,7 +366,7 @@ func NewFakeChain(params *chaincfg.Params) *BlockChain {
365 366
 	adjustmentFactor := params.RetargetAdjustmentFactor
366 367
 	return &BlockChain{
367 368
 		ChainParams:         params,
368
-		TimeSource:          NewMedianTime(),
369
+		TimeSource:          median.NewTime(),
369 370
 		MinRetargetTimespan: targetTimespan / adjustmentFactor,
370 371
 		MaxRetargetTimespan: targetTimespan * adjustmentFactor,
371 372
 		BlocksPerRetarget:   int32(targetTimespan / targetTimePerBlock),

+ 5
- 4
blockchain/difficulty.go View File

@@ -4,6 +4,7 @@ import (
4 4
 	"math/big"
5 5
 	"time"
6 6
 
7
+	"git.parallelcoin.io/dev/btcd/blockchain/bclog"
7 8
 	"git.parallelcoin.io/dev/btcd/blockchain/er"
8 9
 	"git.parallelcoin.io/dev/btcd/blockchain/node"
9 10
 	"git.parallelcoin.io/dev/btcd/util/diff"
@@ -145,10 +146,10 @@ func (b *BlockChain) CalcNextRequiredDifficultyAnyBlock(lastNode *node.Block, ne
145 146
 	// newTarget since conversion to the compact representation loses
146 147
 	// precision.
147 148
 	newTargetBits := diff.BigToCompact(newTarget)
148
-	log.Debugf("Difficulty retarget at block height %d", lastNode.Height+1)
149
-	log.Debugf("Old target %08x (%064x)", lastNode.Bits, oldTarget)
150
-	log.Debugf("New target %08x (%064x)", newTargetBits, diff.CompactToBig(newTargetBits))
151
-	log.Debugf("Actual timespan %v, adjusted timespan %v, target timespan %v",
149
+	bclog.Log.Debugf("Difficulty retarget at block height %d", lastNode.Height+1)
150
+	bclog.Log.Debugf("Old target %08x (%064x)", lastNode.Bits, oldTarget)
151
+	bclog.Log.Debugf("New target %08x (%064x)", newTargetBits, diff.CompactToBig(newTargetBits))
152
+	bclog.Log.Debugf("Actual timespan %v, adjusted timespan %v, target timespan %v",
152 153
 		time.Duration(actualTimespan)*time.Second,
153 154
 		time.Duration(adjustedTimespan)*time.Second,
154 155
 		b.ChainParams.TargetTimespan)

+ 3
- 2
blockchain/example_test.go View File

@@ -9,8 +9,9 @@ import (
9 9
 	"os"
10 10
 	"path/filepath"
11 11
 
12
-	"git.parallelcoin.io/dev/btcd/btcutil/block"
13 12
 	"git.parallelcoin.io/dev/btcd/blockchain"
13
+	"git.parallelcoin.io/dev/btcd/blockchain/median"
14
+	"git.parallelcoin.io/dev/btcd/btcutil/block"
14 15
 	"git.parallelcoin.io/dev/btcd/chaincfg"
15 16
 	"git.parallelcoin.io/dev/btcd/database"
16 17
 	_ "git.parallelcoin.io/dev/btcd/database/ffldb"
@@ -47,7 +48,7 @@ func ExampleBlockChain_ProcessBlock() {
47 48
 	chain, err := blockchain.New(&blockchain.Config{
48 49
 		DB:          db,
49 50
 		ChainParams: &chaincfg.MainNetParams,
50
-		TimeSource:  blockchain.NewMedianTime(),
51
+		TimeSource:  median.NewTime(),
51 52
 	})
52 53
 	if err != nil {
53 54
 		fmt.Printf("Failed to create chain instance: %v\n", err)

+ 2
- 1
blockchain/fullblocks_test.go View File

@@ -20,6 +20,7 @@ import (
20 20
 	"git.parallelcoin.io/dev/btcd/blockchain"
21 21
 	"git.parallelcoin.io/dev/btcd/blockchain/er"
22 22
 	"git.parallelcoin.io/dev/btcd/blockchain/fullblocktests"
23
+	"git.parallelcoin.io/dev/btcd/blockchain/median"
23 24
 	"git.parallelcoin.io/dev/btcd/chaincfg"
24 25
 	"git.parallelcoin.io/dev/btcd/chaincfg/chainhash"
25 26
 	"git.parallelcoin.io/dev/btcd/database"
@@ -121,7 +122,7 @@ func chainSetup(dbName string, params *chaincfg.Params) (*blockchain.BlockChain,
121 122
 		DB:          db,
122 123
 		ChainParams: &paramsCopy,
123 124
 		Checkpoints: nil,
124
-		TimeSource:  blockchain.NewMedianTime(),
125
+		TimeSource:  median.NewTime(),
125 126
 		SigCache:    sig.NewCache(1000),
126 127
 	})
127 128
 	if err != nil {

blockchain/mediantime.go → blockchain/median/mediantime.go View File

@@ -2,38 +2,41 @@
2 2
 // Use of this source code is governed by an ISC
3 3
 // license that can be found in the LICENSE file.
4 4
 
5
-package blockchain
5
+package median
6 6
 
7 7
 import (
8 8
 	"math"
9 9
 	"sort"
10 10
 	"sync"
11 11
 	"time"
12
+
13
+	"git.parallelcoin.io/dev/btcd/blockchain/bclog"
14
+	"git.parallelcoin.io/dev/btcd/blockchain/sorter"
12 15
 )
13 16
 
14 17
 const (
15
-	// maxAllowedOffsetSeconds is the maximum number of seconds in either
18
+	// MaxAllowedOffsetSecs is the maximum number of seconds in either
16 19
 	// direction that local clock will be adjusted.  When the median time
17 20
 	// of the network is outside of this range, no offset will be applied.
18
-	maxAllowedOffsetSecs = 70 * 60 // 1 hour 10 minutes
21
+	MaxAllowedOffsetSecs = 70 * 60 // 1 hour 10 minutes
19 22
 
20
-	// similarTimeSecs is the number of seconds in either direction from the
23
+	// SimilarTimeSecs is the number of seconds in either direction from the
21 24
 	// local clock that is used to determine that it is likely wrong and
22 25
 	// hence to show a warning.
23
-	similarTimeSecs = 5 * 60 // 5 minutes
26
+	SimilarTimeSecs = 5 * 60 // 5 minutes
24 27
 )
25 28
 
26 29
 var (
27
-	// maxMedianTimeEntries is the maximum number of entries allowed in the
30
+	// MaxTimeEntries is the maximum number of entries allowed in the
28 31
 	// median time data.  This is a variable as opposed to a constant so the
29 32
 	// test code can modify it.
30
-	maxMedianTimeEntries = 200
33
+	MaxTimeEntries = 200
31 34
 )
32 35
 
33
-// MedianTimeSource provides a mechanism to add several time samples which are
36
+// TimeSource provides a mechanism to add several time samples which are
34 37
 // used to determine a median time which is then used as an offset to the local
35 38
 // clock.
36
-type MedianTimeSource interface {
39
+type TimeSource interface {
37 40
 	// AdjustedTime returns the current time adjusted by the median time
38 41
 	// offset as calculated from the time samples added by AddTimeSample.
39 42
 	AdjustedTime() time.Time
@@ -47,34 +50,11 @@ type MedianTimeSource interface {
47 50
 	Offset() time.Duration
48 51
 }
49 52
 
50
-// int64Sorter implements sort.Interface to allow a slice of 64-bit integers to
51
-// be sorted.
52
-type int64Sorter []int64
53
-
54
-// Len returns the number of 64-bit integers in the slice.  It is part of the
55
-// sort.Interface implementation.
56
-func (s int64Sorter) Len() int {
57
-	return len(s)
58
-}
59
-
60
-// Swap swaps the 64-bit integers at the passed indices.  It is part of the
61
-// sort.Interface implementation.
62
-func (s int64Sorter) Swap(i, j int) {
63
-	s[i], s[j] = s[j], s[i]
64
-}
65
-
66
-// Less returns whether the 64-bit integer with index i should sort before the
67
-// 64-bit integer with index j.  It is part of the sort.Interface
68
-// implementation.
69
-func (s int64Sorter) Less(i, j int) bool {
70
-	return s[i] < s[j]
71
-}
72
-
73
-// medianTime provides an implementation of the MedianTimeSource interface.
53
+// Time provides an implementation of the TimeSource interface.
74 54
 // It is limited to maxMedianTimeEntries includes the same buggy behavior as
75 55
 // the time offset mechanism in Bitcoin Core.  This is necessary because it is
76 56
 // used in the consensus code.
77
-type medianTime struct {
57
+type Time struct {
78 58
 	mtx                sync.Mutex
79 59
 	knownIDs           map[string]struct{}
80 60
 	offsets            []int64
@@ -82,15 +62,15 @@ type medianTime struct {
82 62
 	invalidTimeChecked bool
83 63
 }
84 64
 
85
-// Ensure the medianTime type implements the MedianTimeSource interface.
86
-var _ MedianTimeSource = (*medianTime)(nil)
65
+// Ensure the medianTime type implements the TimeSource interface.
66
+var _ TimeSource = (*Time)(nil)
87 67
 
88 68
 // AdjustedTime returns the current time adjusted by the median time offset as
89 69
 // calculated from the time samples added by AddTimeSample.
90 70
 //
91 71
 // This function is safe for concurrent access and is part of the
92
-// MedianTimeSource interface implementation.
93
-func (m *medianTime) AdjustedTime() time.Time {
72
+// TimeSource interface implementation.
73
+func (m *Time) AdjustedTime() time.Time {
94 74
 	m.mtx.Lock()
95 75
 	defer m.mtx.Unlock()
96 76
 
@@ -103,8 +83,8 @@ func (m *medianTime) AdjustedTime() time.Time {
103 83
 // time of the added samples.
104 84
 //
105 85
 // This function is safe for concurrent access and is part of the
106
-// MedianTimeSource interface implementation.
107
-func (m *medianTime) AddTimeSample(sourceID string, timeVal time.Time) {
86
+// TimeSource interface implementation.
87
+func (m *Time) AddTimeSample(sourceID string, timeVal time.Time) {
108 88
 	m.mtx.Lock()
109 89
 	defer m.mtx.Unlock()
110 90
 
@@ -121,7 +101,7 @@ func (m *medianTime) AddTimeSample(sourceID string, timeVal time.Time) {
121 101
 	now := time.Unix(time.Now().Unix(), 0)
122 102
 	offsetSecs := int64(timeVal.Sub(now).Seconds())
123 103
 	numOffsets := len(m.offsets)
124
-	if numOffsets == maxMedianTimeEntries && maxMedianTimeEntries > 0 {
104
+	if numOffsets == MaxTimeEntries && MaxTimeEntries > 0 {
125 105
 		m.offsets = m.offsets[1:]
126 106
 		numOffsets--
127 107
 	}
@@ -131,10 +111,10 @@ func (m *medianTime) AddTimeSample(sourceID string, timeVal time.Time) {
131 111
 	// Sort the offsets so the median can be obtained as needed later.
132 112
 	sortedOffsets := make([]int64, numOffsets)
133 113
 	copy(sortedOffsets, m.offsets)
134
-	sort.Sort(int64Sorter(sortedOffsets))
114
+	sort.Sort(sorter.Int64(sortedOffsets))
135 115
 
136 116
 	offsetDuration := time.Duration(offsetSecs) * time.Second
137
-	log.Debugf("Added time sample of %v (total: %v)", offsetDuration,
117
+	bclog.Log.Debugf("Added time sample of %v (total: %v)", offsetDuration,
138 118
 		numOffsets)
139 119
 
140 120
 	// NOTE: The following code intentionally has a bug to mirror the
@@ -159,7 +139,7 @@ func (m *medianTime) AddTimeSample(sourceID string, timeVal time.Time) {
159 139
 
160 140
 	// Set the new offset when the median offset is within the allowed
161 141
 	// offset range.
162
-	if math.Abs(float64(median)) < maxAllowedOffsetSecs {
142
+	if math.Abs(float64(median)) < MaxAllowedOffsetSecs {
163 143
 		m.offsetSecs = median
164 144
 	} else {
165 145
 		// The median offset of all added time data is larger than the
@@ -174,7 +154,7 @@ func (m *medianTime) AddTimeSample(sourceID string, timeVal time.Time) {
174 154
 			// to the local time.
175 155
 			var remoteHasCloseTime bool
176 156
 			for _, offset := range sortedOffsets {
177
-				if math.Abs(float64(offset)) < similarTimeSecs {
157
+				if math.Abs(float64(offset)) < SimilarTimeSecs {
178 158
 					remoteHasCloseTime = true
179 159
 					break
180 160
 				}
@@ -182,7 +162,7 @@ func (m *medianTime) AddTimeSample(sourceID string, timeVal time.Time) {
182 162
 
183 163
 			// Warn if none of the time samples are close.
184 164
 			if !remoteHasCloseTime {
185
-				log.Warnf("Please check your date and time " +
165
+				bclog.Log.Warnf("Please check your date and time " +
186 166
 					"are correct!  btcd will not work " +
187 167
 					"properly with an invalid time")
188 168
 			}
@@ -190,29 +170,29 @@ func (m *medianTime) AddTimeSample(sourceID string, timeVal time.Time) {
190 170
 	}
191 171
 
192 172
 	medianDuration := time.Duration(m.offsetSecs) * time.Second
193
-	log.Debugf("New time offset: %v", medianDuration)
173
+	bclog.Log.Debugf("New time offset: %v", medianDuration)
194 174
 }
195 175
 
196 176
 // Offset returns the number of seconds to adjust the local clock based upon the
197 177
 // median of the time samples added by AddTimeData.
198 178
 //
199 179
 // This function is safe for concurrent access and is part of the
200
-// MedianTimeSource interface implementation.
201
-func (m *medianTime) Offset() time.Duration {
180
+// TimeSource interface implementation.
181
+func (m *Time) Offset() time.Duration {
202 182
 	m.mtx.Lock()
203 183
 	defer m.mtx.Unlock()
204 184
 
205 185
 	return time.Duration(m.offsetSecs) * time.Second
206 186
 }
207 187
 
208
-// NewMedianTime returns a new instance of concurrency-safe implementation of
209
-// the MedianTimeSource interface.  The returned implementation contains the
188
+// NewTime returns a new instance of concurrency-safe implementation of
189
+// the TimeSource interface.  The returned implementation contains the
210 190
 // rules necessary for proper time handling in the chain consensus rules and
211 191
 // expects the time samples to be added from the timestamp field of the version
212 192
 // message received from remote peers that successfully connect and negotiate.
213
-func NewMedianTime() MedianTimeSource {
214
-	return &medianTime{
193
+func NewTime() TimeSource {
194
+	return &Time{
215 195
 		knownIDs: make(map[string]struct{}),
216
-		offsets:  make([]int64, 0, maxMedianTimeEntries),
196
+		offsets:  make([]int64, 0, MaxTimeEntries),
217 197
 	}
218 198
 }

blockchain/mediantime_test.go → blockchain/median/mediantime_test.go View File

@@ -2,7 +2,7 @@
2 2
 // Use of this source code is governed by an ISC
3 3
 // license that can be found in the LICENSE file.
4 4
 
5
-package blockchain
5
+package median
6 6
 
7 7
 import (
8 8
 	"strconv"
@@ -53,11 +53,11 @@ func TestMedianTime(t *testing.T) {
53 53
 	}
54 54
 
55 55
 	// Modify the max number of allowed median time entries for these tests.
56
-	maxMedianTimeEntries = 10
57
-	defer func() { maxMedianTimeEntries = 200 }()
56
+	MaxTimeEntries = 10
57
+	defer func() { MaxTimeEntries = 200 }()
58 58
 
59 59
 	for i, test := range tests {
60
-		filter := NewMedianTime()
60
+		filter := NewTime()
61 61
 		for j, offset := range test.in {
62 62
 			id := strconv.Itoa(j)
63 63
 			now := time.Unix(time.Now().Unix(), 0)

+ 5
- 4
blockchain/process.go View File

@@ -4,6 +4,7 @@ import (
4 4
 	"fmt"
5 5
 	"time"
6 6
 
7
+	"git.parallelcoin.io/dev/btcd/blockchain/bclog"
7 8
 	"git.parallelcoin.io/dev/btcd/blockchain/er"
8 9
 	"git.parallelcoin.io/dev/btcd/btcutil/block"
9 10
 	"git.parallelcoin.io/dev/btcd/chaincfg/chainhash"
@@ -101,7 +102,7 @@ func (b *BlockChain) processOrphans(hash *chainhash.Hash, flags BehaviorFlags) e
101 102
 		for i := 0; i < len(b.PrevOrphans[*processHash]); i++ {
102 103
 			orphan := b.PrevOrphans[*processHash][i]
103 104
 			if orphan == nil {
104
-				log.Warnf("Found a nil entry at index %d in the "+
105
+				bclog.Log.Warnf("Found a nil entry at index %d in the "+
105 106
 					"orphan dependency list for block %v", i,
106 107
 					processHash)
107 108
 				continue
@@ -144,7 +145,7 @@ func (b *BlockChain) ProcessBlock(block *block.Block, flags BehaviorFlags) (bool
144 145
 	fastAdd := flags&BFFastAdd == BFFastAdd
145 146
 
146 147
 	blockHash := block.Hash()
147
-	log.Tracef("Processing block %v", blockHash)
148
+	bclog.Log.Tracef("Processing block %v", blockHash)
148 149
 
149 150
 	// The block must not already exist in the main chain or side chains.
150 151
 	exists, err := b.blockExists(blockHash)
@@ -215,7 +216,7 @@ func (b *BlockChain) ProcessBlock(block *block.Block, flags BehaviorFlags) (bool
215 216
 		return false, false, err
216 217
 	}
217 218
 	if !prevHashExists {
218
-		log.Infof("Adding orphan block %v with parent %v", blockHash, prevHash)
219
+		bclog.Log.Infof("Adding orphan block %v with parent %v", blockHash, prevHash)
219 220
 		b.AddOrphanBlock(block)
220 221
 
221 222
 		return false, true, nil
@@ -236,7 +237,7 @@ func (b *BlockChain) ProcessBlock(block *block.Block, flags BehaviorFlags) (bool
236 237
 		return false, false, err
237 238
 	}
238 239
 
239
-	log.Debugf("Accepted block %v", blockHash)
240
+	bclog.Log.Debugf("Accepted block %v", blockHash)
240 241
 
241 242
 	return isMainChain, false, nil
242 243
 }

+ 2
- 1
blockchain/scriptval.go View File

@@ -6,6 +6,7 @@ import (
6 6
 	"runtime"
7 7
 	"time"
8 8
 
9
+	"git.parallelcoin.io/dev/btcd/blockchain/bclog"
9 10
 	"git.parallelcoin.io/dev/btcd/blockchain/er"
10 11
 	"git.parallelcoin.io/dev/btcd/txscript/hash"
11 12
 	"git.parallelcoin.io/dev/btcd/txscript/sf"
@@ -304,7 +305,7 @@ func checkBlockScripts(block *block.Block, utxoView *UtxoViewpoint,
304 305
 	}
305 306
 	elapsed := time.Since(start)
306 307
 
307
-	log.Tracef("block %v took %v to verify", block.Hash(), elapsed)
308
+	bclog.Log.Tracef("block %v took %v to verify", block.Hash(), elapsed)
308 309
 
309 310
 	// If the HashCache is present, once we have validated the block, we no
310 311
 	// longer need the cached hashes for these transactions, so we purge

+ 24
- 0
blockchain/sorter/int64sorter.go View File

@@ -0,0 +1,24 @@
1
+package sorter
2
+
3
+// Int64 implements sort.Interface to allow a slice of 64-bit integers to
4
+// be sorted.
5
+type Int64 []int64
6
+
7
+// Len returns the number of 64-bit integers in the slice.  It is part of the
8
+// sort.Interface implementation.
9
+func (s Int64) Len() int {
10
+	return len(s)
11
+}
12
+
13
+// Swap swaps the 64-bit integers at the passed indices.  It is part of the
14
+// sort.Interface implementation.
15
+func (s Int64) Swap(i, j int) {
16
+	s[i], s[j] = s[j], s[i]
17
+}
18
+
19
+// Less returns whether the 64-bit integer with index i should sort before the
20
+// 64-bit integer with index j.  It is part of the sort.Interface
21
+// implementation.
22
+func (s Int64) Less(i, j int) bool {
23
+	return s[i] < s[j]
24
+}

+ 6
- 5
blockchain/upgrade.go View File

@@ -11,6 +11,7 @@ import (
11 11
 	"fmt"
12 12
 	"time"
13 13
 
14
+	"git.parallelcoin.io/dev/btcd/blockchain/bclog"
14 15
 	"git.parallelcoin.io/dev/btcd/blockchain/bucket"
15 16
 	"git.parallelcoin.io/dev/btcd/blockchain/db"
16 17
 	"git.parallelcoin.io/dev/btcd/blockchain/status"
@@ -73,7 +74,7 @@ func migrateBlockIndex(db database.DB) error {
73 74
 			return fmt.Errorf("Bucket %s does not exist", v1BucketName)
74 75
 		}
75 76
 
76
-		log.Info("Re-indexing block information in the database. This might take a while...")
77
+		bclog.Log.Info("Re-indexing block information in the database. This might take a while...")
77 78
 
78 79
 		v2BlockIdxBucket, err :=
79 80
 			dbTx.Metadata().CreateBucketIfNotExists(v2BucketName)
@@ -146,7 +147,7 @@ func migrateBlockIndex(db database.DB) error {
146 147
 		return err
147 148
 	}
148 149
 
149
-	log.Infof("Block database migration complete")
150
+	bclog.Log.Infof("Block database migration complete")
150 151
 	return nil
151 152
 }
152 153
 
@@ -448,7 +449,7 @@ func upgradeUtxoSetToV2(d database.DB, interrupt <-chan struct{}) error {
448 449
 		v2BucketName = []byte("utxosetv2")
449 450
 	)
450 451
 
451
-	log.Infof("Upgrading utxo set to v2.  This will take a while...")
452
+	bclog.Log.Infof("Upgrading utxo set to v2.  This will take a while...")
452 453
 	start := time.Now()
453 454
 
454 455
 	// Create the new utxo set bucket as needed.
@@ -555,7 +556,7 @@ func upgradeUtxoSetToV2(d database.DB, interrupt <-chan struct{}) error {
555 556
 		}
556 557
 
557 558
 		totalUtxos += uint64(numUtxos)
558
-		log.Infof("Migrated %d utxos (%d total)", numUtxos, totalUtxos)
559
+		bclog.Log.Infof("Migrated %d utxos (%d total)", numUtxos, totalUtxos)
559 560
 	}
560 561
 
561 562
 	// Remove the old bucket and update the utxo set version once it has
@@ -573,7 +574,7 @@ func upgradeUtxoSetToV2(d database.DB, interrupt <-chan struct{}) error {
573 574
 	}
574 575
 
575 576
 	seconds := int64(time.Since(start) / time.Second)
576
-	log.Infof("Done upgrading utxo set.  Total utxos: %d in %d seconds",
577
+	bclog.Log.Infof("Done upgrading utxo set.  Total utxos: %d in %d seconds",
577 578
 		totalUtxos, seconds)
578 579
 	return nil
579 580
 }

+ 4
- 3
blockchain/validate.go View File

@@ -9,6 +9,7 @@ import (
9 9
 
10 10
 	"git.parallelcoin.io/dev/btcd/blockchain/db"
11 11
 	"git.parallelcoin.io/dev/btcd/blockchain/er"
12
+	"git.parallelcoin.io/dev/btcd/blockchain/median"
12 13
 	"git.parallelcoin.io/dev/btcd/blockchain/node"
13 14
 	"git.parallelcoin.io/dev/btcd/txscript/sf"
14 15
 	"git.parallelcoin.io/dev/btcd/wire/msg"
@@ -427,7 +428,7 @@ func CountP2SHSigOps(tx *tx.Tx, isCoinBaseTx bool, utxoView *UtxoViewpoint) (int
427 428
 //
428 429
 // The flags do not modify the behavior of this function directly, however they
429 430
 // are needed to pass along to checkProofOfWork.
430
-func checkBlockHeaderSanity(header *msg.BlockHeader, powLimit *big.Int, timeSource MedianTimeSource, flags BehaviorFlags) error {
431
+func checkBlockHeaderSanity(header *msg.BlockHeader, powLimit *big.Int, timeSource median.TimeSource, flags BehaviorFlags) error {
431 432
 	// Ensure the proof of work bits in the block header is in min/max range
432 433
 	// and the block hash is less than the target value described by the
433 434
 	// bits.
@@ -464,7 +465,7 @@ func checkBlockHeaderSanity(header *msg.BlockHeader, powLimit *big.Int, timeSour
464 465
 //
465 466
 // The flags do not modify the behavior of this function directly, however they
466 467
 // are needed to pass along to checkBlockHeaderSanity.
467
-func checkBlockSanity(block *block.Block, powLimit *big.Int, timeSource MedianTimeSource, flags BehaviorFlags) error {
468
+func checkBlockSanity(block *block.Block, powLimit *big.Int, timeSource median.TimeSource, flags BehaviorFlags) error {
468 469
 	msgBlock := block.MsgBlock()
469 470
 	header := &msgBlock.Header
470 471
 	err := checkBlockHeaderSanity(header, powLimit, timeSource, flags)
@@ -571,7 +572,7 @@ func checkBlockSanity(block *block.Block, powLimit *big.Int, timeSource MedianTi
571 572
 
572 573
 // CheckBlockSanity performs some preliminary checks on a block to ensure it is
573 574
 // sane before continuing with block processing.  These checks are context free.
574
-func CheckBlockSanity(block *block.Block, powLimit *big.Int, timeSource MedianTimeSource) error {
575
+func CheckBlockSanity(block *block.Block, powLimit *big.Int, timeSource median.TimeSource) error {
575 576
 	return checkBlockSanity(block, powLimit, timeSource, BFNone)
576 577
 }
577 578
 

+ 2
- 1
blockchain/validate_test.go View File

@@ -11,6 +11,7 @@ import (
11 11
 	"time"
12 12
 
13 13
 	"git.parallelcoin.io/dev/btcd/blockchain/er"
14
+	"git.parallelcoin.io/dev/btcd/blockchain/median"
14 15
 	"git.parallelcoin.io/dev/btcd/btcutil/block"
15 16
 	"git.parallelcoin.io/dev/btcd/btcutil/tx"
16 17
 	"git.parallelcoin.io/dev/btcd/wire/msg"
@@ -156,7 +157,7 @@ func TestCheckConnectBlockTemplate(t *testing.T) {
156 157
 func TestCheckBlockSanity(t *testing.T) {
157 158
 	powLimit := chaincfg.MainNetParams.PowLimit
158 159
 	bb := block.New(&block.Block100000)
159
-	timeSource := NewMedianTime()
160
+	timeSource := median.NewTime()
160 161
 	err := CheckBlockSanity(bb, powLimit, timeSource)
161 162
 	if err != nil {
162 163
 		t.Errorf("CheckBlockSanity: %v", err)

+ 4
- 3
blockchain/versionbits.go View File

@@ -7,6 +7,7 @@ package blockchain
7 7
 import (
8 8
 	"math"
9 9
 
10
+	"git.parallelcoin.io/dev/btcd/blockchain/bclog"
10 11
 	"git.parallelcoin.io/dev/btcd/blockchain/node"
11 12
 	"git.parallelcoin.io/dev/btcd/chaincfg"
12 13
 )
@@ -250,7 +251,7 @@ func (b *BlockChain) warnUnknownRuleActivations(nn *node.Block) error {
250 251
 		switch state {
251 252
 		case ThresholdActive:
252 253
 			if !b.UnknownRulesWarned {
253
-				log.Warnf("Unknown new rules activated (bit %d)",
254
+				bclog.Log.Warnf("Unknown new rules activated (bit %d)",
254 255
 					bit)
255 256
 				b.UnknownRulesWarned = true
256 257
 			}
@@ -258,7 +259,7 @@ func (b *BlockChain) warnUnknownRuleActivations(nn *node.Block) error {
258 259
 		case ThresholdLockedIn:
259 260
 			window := int32(checker.MinerConfirmationWindow())
260 261
 			activationHeight := window - (nn.Height % window)
261
-			log.Warnf("Unknown new rules are about to activate in "+
262
+			bclog.Log.Warnf("Unknown new rules are about to activate in "+
262 263
 				"%d blocks (bit %d)", activationHeight, bit)
263 264
 		}
264 265
 	}
@@ -292,7 +293,7 @@ func (b *BlockChain) warnUnknownVersions(nn *node.Block) error {
292 293
 		nn = nn.Parent
293 294
 	}
294 295
 	if numUpgraded > unknownVerWarnNum {
295
-		log.Warn("Unknown block versions are being mined, so new " +
296
+		bclog.Log.Warn("Unknown block versions are being mined, so new " +
296 297
 			"rules might be in effect.  Are you running the " +
297 298
 			"latest version of the software?")
298 299
 		b.UnknownVersionsWarned = true

+ 1
- 1
btcjson/chainsvrresults.go View File

@@ -105,7 +105,7 @@ type GetBlockChainInfoResult struct {
105 105
 	Headers              int32                               `json:"headers"`
106 106
 	BestBlockHash        string                              `json:"bestblockhash"`
107 107
 	Difficulty           float64                             `json:"difficulty"`
108
-	MedianTime           int64                               `json:"mediantime"`
108
+	Time           int64                               `json:"mediantime"`
109 109
 	VerificationProgress float64                             `json:"verificationprogress,omitempty"`
110 110
 	Pruned               bool                                `json:"pruned"`
111 111
 	PruneHeight          int32                               `json:"pruneheight,omitempty"`

+ 3
- 4
cmd/addblock/addblock.go View File

@@ -1,4 +1,3 @@
1
-
2 1
 package main
3 2
 
4 3
 import (
@@ -6,11 +5,11 @@ import (
6 5
 	"path/filepath"
7 6
 	"runtime"
8 7
 
9
-	"git.parallelcoin.io/dev/btcd/blockchain"
8
+	"git.parallelcoin.io/dev/btcd/blockchain/bclog"
10 9
 	"git.parallelcoin.io/dev/btcd/blockchain/indexers"
10
+	"git.parallelcoin.io/dev/btcd/btclog"
11 11
 	"git.parallelcoin.io/dev/btcd/database"
12 12
 	"git.parallelcoin.io/dev/btcd/limits"
13
-	"git.parallelcoin.io/dev/btcd/btclog"
14 13
 )
15 14
 
16 15
 const (
@@ -70,7 +69,7 @@ func realMain() error {
70 69
 	defer os.Stdout.Sync()
71 70
 	log = backendLogger.Logger("MAIN")
72 71
 	database.UseLogger(backendLogger.Logger("BCDB"))
73
-	blockchain.UseLogger(backendLogger.Logger("CHAN"))
72
+	bclog.UseLogger(backendLogger.Logger("CHAN"))
74 73
 	indexers.UseLogger(backendLogger.Logger("INDX"))
75 74
 
76 75
 	// Load the block database.

+ 2
- 1
cmd/addblock/import.go View File

@@ -12,6 +12,7 @@ import (
12 12
 
13 13
 	"git.parallelcoin.io/dev/btcd/blockchain"
14 14
 	"git.parallelcoin.io/dev/btcd/blockchain/indexers"
15
+	"git.parallelcoin.io/dev/btcd/blockchain/median"
15 16
 	"git.parallelcoin.io/dev/btcd/chaincfg/chainhash"
16 17
 	"git.parallelcoin.io/dev/btcd/database"
17 18
 )
@@ -330,7 +331,7 @@ func newBlockImporter(db database.DB, r io.ReadSeeker) (*blockImporter, error) {
330 331
 	chain, err := blockchain.New(&blockchain.Config{
331 332
 		DB:           db,
332 333
 		ChainParams:  activeNetParams,
333
-		TimeSource:   blockchain.NewMedianTime(),
334
+		TimeSource:   median.NewTime(),
334 335
 		IndexManager: indexManager,
335 336
 	})
336 337
 	if err != nil {

+ 2
- 2
cmd/findcheckpoint/findcheckpoint.go View File

@@ -1,4 +1,3 @@
1
-
2 1
 package main
3 2
 
4 3
 import (
@@ -7,6 +6,7 @@ import (
7 6
 	"path/filepath"
8 7
 
9 8
 	"git.parallelcoin.io/dev/btcd/blockchain"
9
+	"git.parallelcoin.io/dev/btcd/blockchain/median"
10 10
 	"git.parallelcoin.io/dev/btcd/chaincfg"
11 11
 	"git.parallelcoin.io/dev/btcd/chaincfg/chainhash"
12 12
 	"git.parallelcoin.io/dev/btcd/database"
@@ -150,7 +150,7 @@ func main() {
150 150
 	chain, err := blockchain.New(&blockchain.Config{
151 151
 		DB:          db,
152 152
 		ChainParams: activeNetParams,
153
-		TimeSource:  blockchain.NewMedianTime(),
153
+		TimeSource:  median.NewTime(),
154 154
 	})
155 155
 	if err != nil {
156 156
 		fmt.Fprintf(os.Stderr, "failed to initialize chain: %v\n", err)

+ 2
- 2
integration/csv_fork_test.go View File

@@ -155,7 +155,7 @@ func TestBIP0113Activation(t *testing.T) {
155 155
 	if err != nil {
156 156
 		t.Fatalf("unable to query for chain info: %v", err)
157 157
 	}
158
-	tx.LockTime = uint32(chainInfo.MedianTime) + 1
158
+	tx.LockTime = uint32(chainInfo.Time) + 1
159 159
 
160 160
 	sigScript, err := txscript.SignatureScript(tx, 0, testPkScript,
161 161
 		txscript.SigHashAll, outputKey, true)
@@ -224,7 +224,7 @@ func TestBIP0113Activation(t *testing.T) {
224 224
 		if err != nil {
225 225
 			t.Fatalf("unable to query for chain info: %v", err)
226 226
 		}
227
-		medianTimePast := chainInfo.MedianTime
227
+		medianTimePast := chainInfo.Time
228 228
 
229 229
 		// Create another test output to be spent shortly below.
230 230
 		outputKey, testOutput, testPkScript, err = makeTestOutput(r, t,

+ 5
- 4
mining/mining.go View File

@@ -11,6 +11,7 @@ import (
11 11
 	"time"
12 12
 
13 13
 	"git.parallelcoin.io/dev/btcd/blockchain/best"
14
+	"git.parallelcoin.io/dev/btcd/blockchain/median"
14 15
 	"git.parallelcoin.io/dev/btcd/wire/msg"
15 16
 
16 17
 	"git.parallelcoin.io/dev/btcd/txscript/hash"
@@ -326,13 +327,13 @@ func logSkippedDeps(tx *tx.Tx, deps map[chainhash.Hash]*txPrioItem) {
326 327
 // the median timestamp of the last several blocks per the chain consensus
327 328
 // rules.
328 329
 func MinimumMedianTime(chainState *best.State) time.Time {
329
-	return chainState.MedianTime.Add(time.Second)
330
+	return chainState.Time.Add(time.Second)
330 331
 }
331 332
 
332 333
 // medianAdjustedTime returns the current time adjusted to ensure it is at least
333 334
 // one second after the median timestamp of the last several blocks per the
334 335
 // chain consensus rules.
335
-func medianAdjustedTime(chainState *best.State, timeSource blockchain.MedianTimeSource) time.Time {
336
+func medianAdjustedTime(chainState *best.State, timeSource median.TimeSource) time.Time {
336 337
 	// The timestamp for the block must not be before the median timestamp
337 338
 	// of the last several blocks.  Thus, choose the maximum between the
338 339
 	// current time and one second after the past median time.  The current
@@ -357,7 +358,7 @@ type BlkTmplGenerator struct {
357 358
 	chainParams *chaincfg.Params
358 359
 	txSource    TxSource
359 360
 	chain       *blockchain.BlockChain
360
-	timeSource  blockchain.MedianTimeSource
361
+	timeSource  median.TimeSource
361 362
 	sigCache    *sig.Cache
362 363
 	hashCache   *hash.Cache
363 364
 }
@@ -370,7 +371,7 @@ type BlkTmplGenerator struct {
370 371
 // consensus rules.
371 372
 func NewBlkTmplGenerator(policy *Policy, params *chaincfg.Params,
372 373
 	txSource TxSource, chain *blockchain.BlockChain,
373
-	timeSource blockchain.MedianTimeSource,
374
+	timeSource median.TimeSource,
374 375
 	sigCache *sig.Cache,
375 376
 	hashCache *hash.Cache) *BlkTmplGenerator {
376 377
 

+ 2
- 2
node/log/log.go View File

@@ -8,7 +8,7 @@ import (
8 8
 	"strings"
9 9
 
10 10
 	"git.parallelcoin.io/dev/btcd/addrmgr"
11
-	"git.parallelcoin.io/dev/btcd/blockchain"
11
+	"git.parallelcoin.io/dev/btcd/blockchain/bclog"
12 12
 	"git.parallelcoin.io/dev/btcd/blockchain/indexers"
13 13
 	"git.parallelcoin.io/dev/btcd/connmgr"
14 14
 	"git.parallelcoin.io/dev/btcd/database"
@@ -221,7 +221,7 @@ func init() {
221 221
 	addrmgr.UseLogger(Amgr)
222 222
 	connmgr.UseLogger(Cmgr)
223 223
 	database.UseLogger(Bcdb)
224
-	blockchain.UseLogger(Chan)
224
+	bclog.UseLogger(Chan)
225 225
 	indexers.UseLogger(Indx)
226 226
 	mining.UseLogger(Minr)
227 227
 	cpuminer.UseLogger(Minr)

+ 3
- 2
node/rpc/gbtworkstate.go View File

@@ -12,6 +12,7 @@ import (
12 12
 	"time"
13 13
 
14 14
 	"git.parallelcoin.io/dev/btcd/blockchain"
15
+	"git.parallelcoin.io/dev/btcd/blockchain/median"
15 16
 	"git.parallelcoin.io/dev/btcd/btcjson"
16 17
 	"git.parallelcoin.io/dev/btcd/btcutil/ad"
17 18
 	"git.parallelcoin.io/dev/btcd/btcutil/block"
@@ -100,12 +101,12 @@ type WorkState struct {
100 101
 	minTimestamp  time.Time
101 102
 	template      *mining.BlockTemplate
102 103
 	notifyMap     map[chainhash.Hash]map[int64]chan struct{}
103
-	timeSource    blockchain.MedianTimeSource
104
+	timeSource    median.TimeSource
104 105
 }
105 106
 
106 107
 // NewGbtWorkState returns a new instance of a WorkState with all internal
107 108
 // fields initialized and ready to use.
108
-func NewGbtWorkState(timeSource blockchain.MedianTimeSource) *WorkState {
109
+func NewGbtWorkState(timeSource median.TimeSource) *WorkState {
109 110
 	return &WorkState{
110 111
 		notifyMap:  make(map[chainhash.Hash]map[int64]chan struct{}),
111 112
 		timeSource: timeSource,

+ 1
- 1
node/rpc/rpchandlers.go View File

@@ -695,7 +695,7 @@ func HandleGetBlockChainInfo(s *Server, cmd interface{}, closeChan <-chan struct
695 695
 		Headers:       chainSnapshot.Height,
696 696
 		BestBlockHash: chainSnapshot.Hash.String(),
697 697
 		Difficulty:    GetDifficultyRatio(chainSnapshot.Bits, params),
698
-		MedianTime:    chainSnapshot.MedianTime.Unix(),
698
+		Time:    chainSnapshot.Time.Unix(),
699 699
 		Pruned:        false,
700 700
 		Bip9SoftForks: make(map[string]*btcjson.Bip9SoftForkDescription),
701 701
 	}

+ 2
- 1
node/rpcserver/rpcserverconfig/config.go View File

@@ -5,6 +5,7 @@ import (
5 5
 
6 6
 	"git.parallelcoin.io/dev/btcd/blockchain"
7 7
 	"git.parallelcoin.io/dev/btcd/blockchain/indexers"
8
+	"git.parallelcoin.io/dev/btcd/blockchain/median"
8 9
 	"git.parallelcoin.io/dev/btcd/chaincfg"
9 10
 	"git.parallelcoin.io/dev/btcd/database"
10 11
 	"git.parallelcoin.io/dev/btcd/mempool/estimator"
@@ -36,7 +37,7 @@ type Config struct {
36 37
 
37 38
 	// These fields allow the RPC server to interface with the local block
38 39
 	// chain data and state.
39
-	TimeSource  blockchain.MedianTimeSource
40
+	TimeSource  median.TimeSource
40 41
 	Chain       *blockchain.BlockChain
41 42
 	ChainParams *chaincfg.Params
42 43
 	DB          database.DB

+ 4
- 3
node/server.go View File

@@ -21,6 +21,7 @@ import (
21 21
 	"git.parallelcoin.io/dev/btcd/addrmgr/network"
22 22
 	"git.parallelcoin.io/dev/btcd/blockchain"
23 23
 	"git.parallelcoin.io/dev/btcd/blockchain/indexers"
24
+	"git.parallelcoin.io/dev/btcd/blockchain/median"
24 25
 	"git.parallelcoin.io/dev/btcd/btcutil/merkle"
25 26
 	"git.parallelcoin.io/dev/btcd/btcutil/tx"
26 27
 	"git.parallelcoin.io/dev/btcd/chaincfg"
@@ -78,7 +79,7 @@ type Server struct {
78 79
 	Quit                 chan struct{}
79 80
 	Nat                  upnp.NAT
80 81
 	Db                   database.DB
81
-	TimeSource           blockchain.MedianTimeSource
82
+	TimeSource           median.TimeSource
82 83
 	Services             service.Flag
83 84
 
84 85
 	// The following fields are used for optional indexes.  They will be nil
@@ -158,7 +159,7 @@ func NewServer(cfg *cnf.Config, listenAddrs, agentBlacklist, agentWhitelist []st
158 159
 		PeerHeightsUpdate:    make(chan UpdatePeerHeightsMsg),
159 160
 		Nat:                  nat,
160 161
 		Db:                   db,
161
-		TimeSource:           blockchain.NewMedianTime(),
162
+		TimeSource:           median.NewTime(),
162 163
 		Services:             services,
163 164
 		SigCache:             sig.NewCache(cfg.SigCacheMaxSize),
164 165
 		HashCache:            hash.CreateCache(cfg.SigCacheMaxSize),
@@ -272,7 +273,7 @@ func NewServer(cfg *cnf.Config, listenAddrs, agentBlacklist, agentWhitelist []st
272 273
 		ChainParams:    chainParams,
273 274
 		FetchUtxoView:  s.Chain.FetchUtxoView,
274 275
 		BestHeight:     func() int32 { return s.Chain.BestSnapshot().Height },
275
-		MedianTimePast: func() time.Time { return s.Chain.BestSnapshot().MedianTime },
276
+		MedianTimePast: func() time.Time { return s.Chain.BestSnapshot().Time },
276 277
 		CalcSequenceLock: func(t *tx.Tx, view *blockchain.UtxoViewpoint) (*blockchain.SequenceLock, error) {
277 278
 			return s.Chain.CalcSequenceLock(t, view, true)
278 279
 		},

Loading…
Cancel
Save