mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00
[DEV-376] Changed any instance of %v in format strings with a more specific format token (#188)
* [DEV-376] Changed any instance of %v in format strings with a more specific format token * [DEV-376] Fixed some more wrong formatting strings + removed redundant cast * [DEV-376] Added fmt.Sprintf where it was missing * [DEV-376] use %s for util.Amount, to invoke .String() * [DEV-376] Some more fixes in format strings * [DEV-376] fixed mruinvmap_test to expect the correct behaviour
This commit is contained in:
parent
f615298453
commit
41647fd488
@ -277,7 +277,7 @@ func (a *AddrManager) expireNew(bucket int) {
|
||||
var oldest *KnownAddress
|
||||
for k, v := range a.addrNew[subnetworkID][bucket] {
|
||||
if v.isBad() {
|
||||
log.Tracef("expiring bad address %v", k)
|
||||
log.Tracef("expiring bad address %s", k)
|
||||
delete(a.addrNew[subnetworkID][bucket], k)
|
||||
v.refs--
|
||||
if v.refs == 0 {
|
||||
@ -295,7 +295,7 @@ func (a *AddrManager) expireNew(bucket int) {
|
||||
|
||||
if oldest != nil {
|
||||
key := NetAddressKey(oldest.na)
|
||||
log.Tracef("expiring oldest address %v", key)
|
||||
log.Tracef("expiring oldest address %s", key)
|
||||
|
||||
delete(a.addrNew[subnetworkID][bucket], key)
|
||||
oldest.refs--
|
||||
@ -449,13 +449,13 @@ func (a *AddrManager) savePeers() {
|
||||
|
||||
w, err := os.Create(a.peersFile)
|
||||
if err != nil {
|
||||
log.Errorf("Error opening file %s: %v", a.peersFile, err)
|
||||
log.Errorf("Error opening file %s: %s", a.peersFile, err)
|
||||
return
|
||||
}
|
||||
enc := json.NewEncoder(w)
|
||||
defer w.Close()
|
||||
if err := enc.Encode(&sam); err != nil {
|
||||
log.Errorf("Failed to encode file %s: %v", a.peersFile, err)
|
||||
log.Errorf("Failed to encode file %s: %s", a.peersFile, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -468,11 +468,11 @@ func (a *AddrManager) loadPeers() {
|
||||
|
||||
err := a.deserializePeers(a.peersFile)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to parse file %s: %v", a.peersFile, err)
|
||||
log.Errorf("Failed to parse file %s: %s", a.peersFile, err)
|
||||
// if it is invalid we nuke the old one unconditionally.
|
||||
err = os.Remove(a.peersFile)
|
||||
if err != nil {
|
||||
log.Warnf("Failed to remove corrupt peers file %s: %v",
|
||||
log.Warnf("Failed to remove corrupt peers file %s: %s",
|
||||
a.peersFile, err)
|
||||
}
|
||||
a.reset()
|
||||
@ -489,7 +489,7 @@ func (a *AddrManager) deserializePeers(filePath string) error {
|
||||
}
|
||||
r, err := os.Open(filePath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s error opening file: %v", filePath, err)
|
||||
return fmt.Errorf("%s error opening file: %s", filePath, err)
|
||||
}
|
||||
defer r.Close()
|
||||
|
||||
@ -497,11 +497,11 @@ func (a *AddrManager) deserializePeers(filePath string) error {
|
||||
dec := json.NewDecoder(r)
|
||||
err = dec.Decode(&sam)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading %s: %v", filePath, err)
|
||||
return fmt.Errorf("error reading %s: %s", filePath, err)
|
||||
}
|
||||
|
||||
if sam.Version != serialisationVersion {
|
||||
return fmt.Errorf("unknown version %v in serialized "+
|
||||
return fmt.Errorf("unknown version %d in serialized "+
|
||||
"addrmanager", sam.Version)
|
||||
}
|
||||
copy(a.key[:], sam.Key[:])
|
||||
@ -511,17 +511,17 @@ func (a *AddrManager) deserializePeers(filePath string) error {
|
||||
ka.na, err = a.DeserializeNetAddress(v.Addr)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to deserialize netaddress "+
|
||||
"%s: %v", v.Addr, err)
|
||||
"%s: %s", v.Addr, err)
|
||||
}
|
||||
ka.srcAddr, err = a.DeserializeNetAddress(v.Src)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to deserialize netaddress "+
|
||||
"%s: %v", v.Src, err)
|
||||
"%s: %s", v.Src, err)
|
||||
}
|
||||
ka.subnetworkID, err = subnetworkid.NewFromStr(v.SubnetworkID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to deserialize subnetwork id "+
|
||||
"%s: %v", v.SubnetworkID, err)
|
||||
"%s: %s", v.SubnetworkID, err)
|
||||
}
|
||||
ka.attempts = v.Attempts
|
||||
ka.lastattempt = time.Unix(v.LastAttempt, 0)
|
||||
@ -669,7 +669,7 @@ func (a *AddrManager) AddAddressByIP(addrIP string) error {
|
||||
}
|
||||
port, err := strconv.ParseUint(portStr, 10, 0)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid port %s: %v", portStr, err)
|
||||
return fmt.Errorf("invalid port %s: %s", portStr, err)
|
||||
}
|
||||
na := wire.NewNetAddressIPPort(ip, uint16(port), 0)
|
||||
a.AddAddress(na, na) // XXX use correct src address
|
||||
@ -847,7 +847,7 @@ func (a *AddrManager) GetAddress() *KnownAddress {
|
||||
ka := e.Value.(*KnownAddress)
|
||||
randval := a.rand.Intn(large)
|
||||
if float64(randval) < (factor * ka.chance() * float64(large)) {
|
||||
log.Tracef("Selected %v from tried bucket",
|
||||
log.Tracef("Selected %s from tried bucket",
|
||||
NetAddressKey(ka.na))
|
||||
return ka
|
||||
}
|
||||
@ -875,7 +875,7 @@ func (a *AddrManager) GetAddress() *KnownAddress {
|
||||
}
|
||||
randval := a.rand.Intn(large)
|
||||
if float64(randval) < (factor * ka.chance() * float64(large)) {
|
||||
log.Tracef("Selected %v from new bucket",
|
||||
log.Tracef("Selected %s from new bucket",
|
||||
NetAddressKey(ka.na))
|
||||
return ka
|
||||
}
|
||||
|
@ -366,7 +366,7 @@ func (dag *BlockDAG) calcSequenceLock(node *blockNode, utxoSet UTXOSet, tx *util
|
||||
for txInIndex, txIn := range mTx.TxIn {
|
||||
entry, ok := utxoSet.Get(txIn.PreviousOutPoint)
|
||||
if !ok {
|
||||
str := fmt.Sprintf("output %v referenced from "+
|
||||
str := fmt.Sprintf("output %s referenced from "+
|
||||
"transaction %s:%d either does not exist or "+
|
||||
"has already been spent", txIn.PreviousOutPoint,
|
||||
tx.ID(), txInIndex)
|
||||
@ -482,7 +482,7 @@ func (dag *BlockDAG) connectToDAG(node *blockNode, parentNodes blockSet, block *
|
||||
// invalid, the worst that can happen is we revalidate the block
|
||||
// after a restart.
|
||||
if writeErr := dag.index.flushToDB(); writeErr != nil {
|
||||
log.Warnf("Error flushing block index changes to disk: %v",
|
||||
log.Warnf("Error flushing block index changes to disk: %s",
|
||||
writeErr)
|
||||
}
|
||||
|
||||
@ -690,7 +690,7 @@ func (dag *BlockDAG) applyUTXOChanges(node *blockNode, block *util.Block, fastAd
|
||||
|
||||
newBlockUTXO, acceptedTxData, err := node.verifyAndBuildUTXO(virtualClone, dag, block.Transactions(), fastAdd)
|
||||
if err != nil {
|
||||
newErrString := fmt.Sprintf("error verifying UTXO for %v: %s", node, err)
|
||||
newErrString := fmt.Sprintf("error verifying UTXO for %s: %s", node, err)
|
||||
if err, ok := err.(RuleError); ok {
|
||||
return nil, nil, ruleError(err.ErrorCode, newErrString)
|
||||
}
|
||||
@ -709,7 +709,7 @@ func (dag *BlockDAG) applyUTXOChanges(node *blockNode, block *util.Block, fastAd
|
||||
|
||||
err = node.updateParents(virtualClone, newBlockUTXO)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("failed updating parents of %v: %s", node, err))
|
||||
panic(fmt.Errorf("failed updating parents of %s: %s", node, err))
|
||||
}
|
||||
|
||||
// Update the virtual block's children (the DAG tips) to include the new block.
|
||||
@ -718,7 +718,7 @@ func (dag *BlockDAG) applyUTXOChanges(node *blockNode, block *util.Block, fastAd
|
||||
// Build a UTXO set for the new virtual block and update the DAG tips' diffs.
|
||||
newVirtualUTXO, _, err := virtualClone.blockNode.pastUTXO(virtualClone, dag.db)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("could not restore past UTXO for virtual %v: %s", virtualClone, err))
|
||||
panic(fmt.Sprintf("could not restore past UTXO for virtual %s: %s", virtualClone, err))
|
||||
}
|
||||
|
||||
// Apply new utxoDiffs to all the tips
|
||||
@ -918,7 +918,7 @@ func (dag *BlockDAG) getTXO(outpointBlockNode *blockNode, outpoint wire.OutPoint
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("Couldn't find txo %v", outpoint)
|
||||
return nil, fmt.Errorf("Couldn't find txo %s", outpoint)
|
||||
}
|
||||
|
||||
func (node *blockNode) validateFeeTransaction(dag *BlockDAG, acceptedTxData []*TxWithBlockHash, nodeTransactions []*util.Tx) error {
|
||||
@ -1368,10 +1368,10 @@ func (dag *BlockDAG) HeightToHashRange(startHeight int32,
|
||||
|
||||
endNode := dag.index.LookupNode(endHash)
|
||||
if endNode == nil {
|
||||
return nil, fmt.Errorf("no known block header with hash %v", endHash)
|
||||
return nil, fmt.Errorf("no known block header with hash %s", endHash)
|
||||
}
|
||||
if !dag.index.NodeStatus(endNode).KnownValid() {
|
||||
return nil, fmt.Errorf("block %v is not yet validated", endHash)
|
||||
return nil, fmt.Errorf("block %s is not yet validated", endHash)
|
||||
}
|
||||
endHeight := endNode.height
|
||||
|
||||
@ -1408,10 +1408,10 @@ func (dag *BlockDAG) IntervalBlockHashes(endHash *daghash.Hash, interval int,
|
||||
|
||||
endNode := dag.index.LookupNode(endHash)
|
||||
if endNode == nil {
|
||||
return nil, fmt.Errorf("no known block header with hash %v", endHash)
|
||||
return nil, fmt.Errorf("no known block header with hash %s", endHash)
|
||||
}
|
||||
if !dag.index.NodeStatus(endNode).KnownValid() {
|
||||
return nil, fmt.Errorf("block %v is not yet validated", endHash)
|
||||
return nil, fmt.Errorf("block %s is not yet validated", endHash)
|
||||
}
|
||||
endHeight := endNode.height
|
||||
|
||||
@ -1774,7 +1774,7 @@ func New(config *Config) (*BlockDAG, error) {
|
||||
}
|
||||
|
||||
selectedTip := dag.selectedTip()
|
||||
log.Infof("DAG state (height %d, hash %v, work %v)",
|
||||
log.Infof("DAG state (height %d, hash %s, work %d)",
|
||||
selectedTip.height, selectedTip.hash, selectedTip.workSum)
|
||||
|
||||
return &dag, nil
|
||||
|
@ -289,7 +289,7 @@ func deserializeUTXOEntry(serialized []byte) (*UTXOEntry, error) {
|
||||
amount, pkScript, _, err := decodeCompressedTxOut(serialized[offset:])
|
||||
if err != nil {
|
||||
return nil, errDeserialize(fmt.Sprintf("unable to decode "+
|
||||
"UTXO: %v", err))
|
||||
"UTXO: %s", err))
|
||||
}
|
||||
|
||||
entry := &UTXOEntry{
|
||||
@ -614,7 +614,7 @@ func (dag *BlockDAG) initDAGState() error {
|
||||
if isDeserializeErr(err) {
|
||||
return database.Error{
|
||||
ErrorCode: database.ErrCorruption,
|
||||
Description: fmt.Sprintf("corrupt outPoint: %v", err),
|
||||
Description: fmt.Sprintf("corrupt outPoint: %s", err),
|
||||
}
|
||||
}
|
||||
|
||||
@ -629,7 +629,7 @@ func (dag *BlockDAG) initDAGState() error {
|
||||
if isDeserializeErr(err) {
|
||||
return database.Error{
|
||||
ErrorCode: database.ErrCorruption,
|
||||
Description: fmt.Sprintf("corrupt utxo entry: %v", err),
|
||||
Description: fmt.Sprintf("corrupt utxo entry: %s", err),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -275,7 +275,7 @@ func (dag *BlockDAG) calcNextRequiredDifficulty(lastNode *blockNode, newBlockTim
|
||||
log.Debugf("Difficulty retarget at block height %d", lastNode.height+1)
|
||||
log.Debugf("Old target %08x (%064x)", lastNode.bits, oldTarget)
|
||||
log.Debugf("New target %08x (%064x)", newTargetBits, CompactToBig(newTargetBits))
|
||||
log.Debugf("Actual timespan %v, adjusted timespan %v, target timespan %v",
|
||||
log.Debugf("Actual timespan %s, adjusted timespan %s, target timespan %s",
|
||||
time.Duration(actualTimespan)*time.Second,
|
||||
time.Duration(adjustedTimespan)*time.Second,
|
||||
dag.dagParams.TargetTimespan)
|
||||
|
@ -738,8 +738,8 @@ func (g *testGenerator) assertTipBlockNumTxns(expected int) {
|
||||
func (g *testGenerator) assertTipBlockHash(expected daghash.Hash) {
|
||||
hash := g.tip.BlockHash()
|
||||
if hash != expected {
|
||||
panic(fmt.Sprintf("block hash of block %q (height %d) is %v "+
|
||||
"instead of expected %v", g.tipName, g.tipHeight, hash,
|
||||
panic(fmt.Sprintf("block hash of block %q (height %d) is %s "+
|
||||
"instead of expected %s", g.tipName, g.tipHeight, hash,
|
||||
expected))
|
||||
}
|
||||
}
|
||||
@ -749,8 +749,8 @@ func (g *testGenerator) assertTipBlockHash(expected daghash.Hash) {
|
||||
func (g *testGenerator) assertTipBlockMerkleRoot(expected daghash.Hash) {
|
||||
hash := g.tip.Header.HashMerkleRoot
|
||||
if hash != expected {
|
||||
panic(fmt.Sprintf("merkle root of block %q (height %d) is %v "+
|
||||
"instead of expected %v", g.tipName, g.tipHeight, hash,
|
||||
panic(fmt.Sprintf("merkle root of block %q (height %d) is %s "+
|
||||
"instead of expected %s", g.tipName, g.tipHeight, hash,
|
||||
expected))
|
||||
}
|
||||
}
|
||||
|
@ -308,7 +308,7 @@ func dbFetchAddrIndexEntries(bucket internalBucket, addrKey [addrKeySize]byte, n
|
||||
ErrorCode: database.ErrCorruption,
|
||||
Description: fmt.Sprintf("failed to "+
|
||||
"deserialized address index "+
|
||||
"for key %x: %v", addrKey, err),
|
||||
"for key %x: %s", addrKey, err),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -237,7 +237,7 @@ func dbFetchFirstTxRegion(dbTx database.Tx, txID *daghash.TxID) (*database.Block
|
||||
return nil, database.Error{
|
||||
ErrorCode: database.ErrCorruption,
|
||||
Description: fmt.Sprintf("corrupt transaction index "+
|
||||
"entry for %s: %v", txID, err),
|
||||
"entry for %s: %s", txID, err),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -134,7 +134,7 @@ func (m *medianTime) AddTimeSample(sourceID string, timeVal time.Time) {
|
||||
sort.Sort(int64Sorter(sortedOffsets))
|
||||
|
||||
offsetDuration := time.Duration(offsetSecs) * time.Second
|
||||
log.Debugf("Added time sample of %v (total: %v)", offsetDuration,
|
||||
log.Debugf("Added time sample of %s (total: %d)", offsetDuration,
|
||||
numOffsets)
|
||||
|
||||
// NOTE: The following code intentionally has a bug to mirror the
|
||||
@ -190,7 +190,7 @@ func (m *medianTime) AddTimeSample(sourceID string, timeVal time.Time) {
|
||||
}
|
||||
|
||||
medianDuration := time.Duration(m.offsetSecs) * time.Second
|
||||
log.Debugf("New time offset: %v", medianDuration)
|
||||
log.Debugf("New time offset: %d", medianDuration)
|
||||
}
|
||||
|
||||
// Offset returns the number of seconds to adjust the local clock based upon the
|
||||
|
@ -104,7 +104,7 @@ func (dag *BlockDAG) processOrphans(hash *daghash.Hash, flags BehaviorFlags) err
|
||||
orphan := dag.prevOrphans[*processHash][i]
|
||||
if orphan == nil {
|
||||
log.Warnf("Found a nil entry at index %d in the "+
|
||||
"orphan dependency list for block %v", i,
|
||||
"orphan dependency list for block %s", i,
|
||||
processHash)
|
||||
continue
|
||||
}
|
||||
@ -145,7 +145,7 @@ func (dag *BlockDAG) ProcessBlock(block *util.Block, flags BehaviorFlags) (bool,
|
||||
fastAdd := flags&BFFastAdd == BFFastAdd
|
||||
|
||||
blockHash := block.Hash()
|
||||
log.Tracef("Processing block %v", blockHash)
|
||||
log.Tracef("Processing block %s", blockHash)
|
||||
|
||||
// The block must not already exist in the main chain or side chains.
|
||||
exists, err := dag.blockExists(blockHash)
|
||||
@ -153,13 +153,13 @@ func (dag *BlockDAG) ProcessBlock(block *util.Block, flags BehaviorFlags) (bool,
|
||||
return false, err
|
||||
}
|
||||
if exists {
|
||||
str := fmt.Sprintf("already have block %v", blockHash)
|
||||
str := fmt.Sprintf("already have block %s", blockHash)
|
||||
return false, ruleError(ErrDuplicateBlock, str)
|
||||
}
|
||||
|
||||
// The block must not already exist as an orphan.
|
||||
if _, exists := dag.orphans[*blockHash]; exists {
|
||||
str := fmt.Sprintf("already have block (orphan) %v", blockHash)
|
||||
str := fmt.Sprintf("already have block (orphan) %s", blockHash)
|
||||
return false, ruleError(ErrDuplicateBlock, str)
|
||||
}
|
||||
|
||||
@ -184,8 +184,8 @@ func (dag *BlockDAG) ProcessBlock(block *util.Block, flags BehaviorFlags) (bool,
|
||||
// Ensure the block timestamp is after the checkpoint timestamp.
|
||||
checkpointTime := time.Unix(checkpointNode.timestamp, 0)
|
||||
if blockHeader.Timestamp.Before(checkpointTime) {
|
||||
str := fmt.Sprintf("block %v has timestamp %v before "+
|
||||
"last checkpoint timestamp %v", blockHash,
|
||||
str := fmt.Sprintf("block %s has timestamp %s before "+
|
||||
"last checkpoint timestamp %s", blockHash,
|
||||
blockHeader.Timestamp, checkpointTime)
|
||||
return false, ruleError(ErrCheckpointTimeTooOld, str)
|
||||
}
|
||||
@ -218,7 +218,7 @@ func (dag *BlockDAG) ProcessBlock(block *util.Block, flags BehaviorFlags) (bool,
|
||||
}
|
||||
|
||||
if !parentExists {
|
||||
log.Infof("Adding orphan block %v with parent %v", blockHash, parentHash)
|
||||
log.Infof("Adding orphan block %s with parent %s", blockHash, parentHash)
|
||||
dag.addOrphanBlock(block)
|
||||
|
||||
allParentsExist = false
|
||||
@ -244,7 +244,7 @@ func (dag *BlockDAG) ProcessBlock(block *util.Block, flags BehaviorFlags) (bool,
|
||||
return false, err
|
||||
}
|
||||
|
||||
log.Debugf("Accepted block %v", blockHash)
|
||||
log.Debugf("Accepted block %s", blockHash)
|
||||
|
||||
return false, nil
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ out:
|
||||
entry, ok := v.utxoSet.Get(txIn.PreviousOutPoint)
|
||||
if !ok {
|
||||
str := fmt.Sprintf("unable to find unspent "+
|
||||
"output %v referenced from "+
|
||||
"output %s referenced from "+
|
||||
"transaction %s:%d",
|
||||
txIn.PreviousOutPoint, txVI.tx.ID(),
|
||||
txVI.txInIndex)
|
||||
@ -74,8 +74,8 @@ out:
|
||||
txVI.txInIndex, v.flags, v.sigCache)
|
||||
if err != nil {
|
||||
str := fmt.Sprintf("failed to parse input "+
|
||||
"%s:%d which references output %v - "+
|
||||
"%v (input script bytes %x, prev "+
|
||||
"%s:%d which references output %s - "+
|
||||
"%s (input script bytes %x, prev "+
|
||||
"output script bytes %x)",
|
||||
txVI.tx.ID(), txVI.txInIndex,
|
||||
txIn.PreviousOutPoint, err, sigScript, pkScript)
|
||||
@ -87,8 +87,8 @@ out:
|
||||
// Execute the script pair.
|
||||
if err := vm.Execute(); err != nil {
|
||||
str := fmt.Sprintf("failed to validate input "+
|
||||
"%s:%d which references output %v - "+
|
||||
"%v (input script bytes %x, prev output "+
|
||||
"%s:%d which references output %s - "+
|
||||
"%s (input script bytes %x, prev output "+
|
||||
"script bytes %x)",
|
||||
txVI.tx.ID(), txVI.txInIndex,
|
||||
txIn.PreviousOutPoint, err, sigScript, pkScript)
|
||||
@ -237,7 +237,7 @@ func checkBlockScripts(block *blockNode, utxoSet UTXOSet, transactions []*util.T
|
||||
}
|
||||
elapsed := time.Since(start)
|
||||
|
||||
log.Tracef("block %v took %v to verify", block.hash, elapsed)
|
||||
log.Tracef("block %s took %s to verify", block.hash, elapsed)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ func fileExists(name string) bool {
|
||||
// a teardown function the caller should invoke when done testing to clean up.
|
||||
func DAGSetup(dbName string, config Config) (*BlockDAG, func(), error) {
|
||||
if !isSupportedDbType(testDbType) {
|
||||
return nil, nil, fmt.Errorf("unsupported db type %v", testDbType)
|
||||
return nil, nil, fmt.Errorf("unsupported db type %s", testDbType)
|
||||
}
|
||||
|
||||
var teardown func()
|
||||
@ -66,7 +66,7 @@ func DAGSetup(dbName string, config Config) (*BlockDAG, func(), error) {
|
||||
if !fileExists(testDbRoot) {
|
||||
if err := os.MkdirAll(testDbRoot, 0700); err != nil {
|
||||
err := fmt.Errorf("unable to create test db "+
|
||||
"root: %v", err)
|
||||
"root: %s", err)
|
||||
return nil, nil, err
|
||||
}
|
||||
}
|
||||
@ -76,7 +76,7 @@ func DAGSetup(dbName string, config Config) (*BlockDAG, func(), error) {
|
||||
var err error
|
||||
config.DB, err = database.Create(testDbType, dbPath, blockDataNet)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("error creating db: %v", err)
|
||||
return nil, nil, fmt.Errorf("error creating db: %s", err)
|
||||
}
|
||||
|
||||
// Setup a teardown function for cleaning up. This function is
|
||||
@ -99,7 +99,7 @@ func DAGSetup(dbName string, config Config) (*BlockDAG, func(), error) {
|
||||
dag, err := New(&config)
|
||||
if err != nil {
|
||||
teardown()
|
||||
err := fmt.Errorf("failed to create dag instance: %v", err)
|
||||
err := fmt.Errorf("failed to create dag instance: %s", err)
|
||||
return nil, nil, err
|
||||
}
|
||||
return dag, teardown, nil
|
||||
@ -196,7 +196,7 @@ func GetVirtualFromParentsForTest(dag *BlockDAG, parentHashes []daghash.Hash) (*
|
||||
for _, hash := range parentHashes {
|
||||
parent := dag.index.LookupNode(&hash)
|
||||
if parent == nil {
|
||||
return nil, fmt.Errorf("GetVirtualFromParentsForTest: didn't found node for hash %v", hash)
|
||||
return nil, fmt.Errorf("GetVirtualFromParentsForTest: didn't found node for hash %s", hash)
|
||||
}
|
||||
parents.add(parent)
|
||||
}
|
||||
|
@ -178,7 +178,7 @@ func (dag *BlockDAG) thresholdState(prevNode *blockNode, checker thresholdCondit
|
||||
state, ok = cache.Lookup(&prevNode.hash)
|
||||
if !ok {
|
||||
return ThresholdFailed, AssertError(fmt.Sprintf(
|
||||
"thresholdState: cache lookup failed for %v",
|
||||
"thresholdState: cache lookup failed for %s",
|
||||
prevNode.hash))
|
||||
}
|
||||
}
|
||||
|
@ -170,7 +170,7 @@ func (d *UTXODiff) diffFrom(other *UTXODiff) (*UTXODiff, error) {
|
||||
result.toRemove.add(outPoint, utxoEntry)
|
||||
}
|
||||
if other.toRemove.contains(outPoint) {
|
||||
return nil, fmt.Errorf("diffFrom: outpoint %v both in d.toAdd and in other.toRemove", outPoint)
|
||||
return nil, fmt.Errorf("diffFrom: outpoint %s both in d.toAdd and in other.toRemove", outPoint)
|
||||
}
|
||||
}
|
||||
|
||||
@ -243,7 +243,7 @@ func (d *UTXODiff) WithDiff(diff *UTXODiff) (*UTXODiff, error) {
|
||||
result.toAdd.add(outPoint, utxoEntry)
|
||||
}
|
||||
if diff.toAdd.contains(outPoint) {
|
||||
return nil, ruleError(ErrWithDiff, fmt.Sprintf("WithDiff: outpoint %v both in d.toAdd and in other.toAdd", outPoint))
|
||||
return nil, ruleError(ErrWithDiff, fmt.Sprintf("WithDiff: outpoint %s both in d.toAdd and in other.toAdd", outPoint))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -182,8 +182,8 @@ func CheckTransactionSanity(tx *util.Tx, subnetworkID *subnetworkid.SubnetworkID
|
||||
for _, txOut := range msgTx.TxOut {
|
||||
satoshi := txOut.Value
|
||||
if satoshi > util.MaxSatoshi {
|
||||
str := fmt.Sprintf("transaction output value of %v is "+
|
||||
"higher than max allowed value of %v", satoshi,
|
||||
str := fmt.Sprintf("transaction output value of %d is "+
|
||||
"higher than max allowed value of %f", satoshi,
|
||||
util.MaxSatoshi)
|
||||
return ruleError(ErrBadTxOutValue, str)
|
||||
}
|
||||
@ -194,15 +194,15 @@ func CheckTransactionSanity(tx *util.Tx, subnetworkID *subnetworkid.SubnetworkID
|
||||
newTotalSatoshi := totalSatoshi + satoshi
|
||||
if newTotalSatoshi < totalSatoshi {
|
||||
str := fmt.Sprintf("total value of all transaction "+
|
||||
"outputs exceeds max allowed value of %v",
|
||||
"outputs exceeds max allowed value of %f",
|
||||
util.MaxSatoshi)
|
||||
return ruleError(ErrBadTxOutValue, str)
|
||||
}
|
||||
totalSatoshi = newTotalSatoshi
|
||||
if totalSatoshi > util.MaxSatoshi {
|
||||
str := fmt.Sprintf("total value of all transaction "+
|
||||
"outputs is %v which is higher than max "+
|
||||
"allowed value of %v", totalSatoshi,
|
||||
"outputs is %d which is higher than max "+
|
||||
"allowed value of %f", totalSatoshi,
|
||||
util.MaxSatoshi)
|
||||
return ruleError(ErrBadTxOutValue, str)
|
||||
}
|
||||
@ -359,7 +359,7 @@ func CountP2SHSigOps(tx *util.Tx, isBlockReward bool, utxoSet UTXOSet) (int, err
|
||||
// Ensure the referenced input transaction is available.
|
||||
entry, ok := utxoSet.Get(txIn.PreviousOutPoint)
|
||||
if !ok {
|
||||
str := fmt.Sprintf("output %v referenced from "+
|
||||
str := fmt.Sprintf("output %s referenced from "+
|
||||
"transaction %s:%d either does not exist or "+
|
||||
"has already been spent", txIn.PreviousOutPoint,
|
||||
tx.ID(), txInIndex)
|
||||
@ -385,7 +385,7 @@ func CountP2SHSigOps(tx *util.Tx, isBlockReward bool, utxoSet UTXOSet) (int, err
|
||||
totalSigOps += numSigOps
|
||||
if totalSigOps < lastSigOps {
|
||||
str := fmt.Sprintf("the public key script from output "+
|
||||
"%v contains too many signature operations - "+
|
||||
"%s contains too many signature operations - "+
|
||||
"overflow", txIn.PreviousOutPoint)
|
||||
return 0, ruleError(ErrTooManySigOps, str)
|
||||
}
|
||||
@ -426,7 +426,7 @@ func (dag *BlockDAG) checkBlockHeaderSanity(header *wire.BlockHeader, flags Beha
|
||||
// seconds and it's much nicer to deal with standard Go time values
|
||||
// instead of converting to seconds everywhere.
|
||||
if !header.Timestamp.Equal(time.Unix(header.Timestamp.Unix(), 0)) {
|
||||
str := fmt.Sprintf("block timestamp of %v has a higher "+
|
||||
str := fmt.Sprintf("block timestamp of %s has a higher "+
|
||||
"precision than one second", header.Timestamp)
|
||||
return ruleError(ErrInvalidTime, str)
|
||||
}
|
||||
@ -435,7 +435,7 @@ func (dag *BlockDAG) checkBlockHeaderSanity(header *wire.BlockHeader, flags Beha
|
||||
maxTimestamp := dag.timeSource.AdjustedTime().Add(time.Second *
|
||||
MaxTimeOffsetSeconds)
|
||||
if header.Timestamp.After(maxTimestamp) {
|
||||
str := fmt.Sprintf("block timestamp of %v is too far in the "+
|
||||
str := fmt.Sprintf("block timestamp of %s is too far in the "+
|
||||
"future", header.Timestamp)
|
||||
return ruleError(ErrTimeTooNew, str)
|
||||
}
|
||||
@ -552,7 +552,7 @@ func (dag *BlockDAG) checkBlockSanity(block *util.Block, flags BehaviorFlags) er
|
||||
calculatedHashMerkleRoot := hashMerkleTree.Root()
|
||||
if !header.HashMerkleRoot.IsEqual(calculatedHashMerkleRoot) {
|
||||
str := fmt.Sprintf("block hash merkle root is invalid - block "+
|
||||
"header indicates %v, but calculated value is %v",
|
||||
"header indicates %s, but calculated value is %s",
|
||||
header.HashMerkleRoot, calculatedHashMerkleRoot)
|
||||
return ruleError(ErrBadMerkleRoot, str)
|
||||
}
|
||||
@ -561,7 +561,7 @@ func (dag *BlockDAG) checkBlockSanity(block *util.Block, flags BehaviorFlags) er
|
||||
calculatedIDMerkleRoot := idMerkleTree.Root()
|
||||
if !header.IDMerkleRoot.IsEqual(calculatedIDMerkleRoot) {
|
||||
str := fmt.Sprintf("block ID merkle root is invalid - block "+
|
||||
"header indicates %v, but calculated value is %v",
|
||||
"header indicates %s, but calculated value is %s",
|
||||
header.IDMerkleRoot, calculatedIDMerkleRoot)
|
||||
return ruleError(ErrBadMerkleRoot, str)
|
||||
}
|
||||
@ -574,7 +574,7 @@ func (dag *BlockDAG) checkBlockSanity(block *util.Block, flags BehaviorFlags) er
|
||||
id := tx.ID()
|
||||
if _, exists := existingTxIDs[*id]; exists {
|
||||
str := fmt.Sprintf("block contains duplicate "+
|
||||
"transaction %v", id)
|
||||
"transaction %s", id)
|
||||
return ruleError(ErrDuplicateTx, str)
|
||||
}
|
||||
existingTxIDs[*id] = struct{}{}
|
||||
@ -590,7 +590,7 @@ func (dag *BlockDAG) checkBlockSanity(block *util.Block, flags BehaviorFlags) er
|
||||
totalSigOps += CountSigOps(tx)
|
||||
if totalSigOps < lastSigOps || totalSigOps > MaxSigOpsPerBlock {
|
||||
str := fmt.Sprintf("block contains too many signature "+
|
||||
"operations - got %v, max %v", totalSigOps,
|
||||
"operations - got %d, max %d", totalSigOps,
|
||||
MaxSigOpsPerBlock)
|
||||
return ruleError(ErrTooManySigOps, str)
|
||||
}
|
||||
@ -696,7 +696,7 @@ func (dag *BlockDAG) checkBlockHeaderContext(header *wire.BlockHeader, bluestPar
|
||||
medianTime := bluestParent.CalcPastMedianTime()
|
||||
if header.Timestamp.Before(medianTime) {
|
||||
str := "block timestamp of %s is not after expected %s"
|
||||
str = fmt.Sprintf(str, header.Timestamp.String(), medianTime.String())
|
||||
str = fmt.Sprintf(str, header.Timestamp, medianTime)
|
||||
return ruleError(ErrTimeTooOld, str)
|
||||
}
|
||||
}
|
||||
@ -801,7 +801,7 @@ func (dag *BlockDAG) checkBlockContext(block *util.Block, parents blockSet, blue
|
||||
blockTime) {
|
||||
|
||||
str := fmt.Sprintf("block contains unfinalized "+
|
||||
"transaction %v", tx.ID())
|
||||
"transaction %s", tx.ID())
|
||||
return ruleError(ErrUnfinalizedTx, str)
|
||||
}
|
||||
}
|
||||
@ -848,7 +848,7 @@ func ensureNoDuplicateTx(block *blockNode, utxoSet UTXOSet,
|
||||
for outpoint := range fetchSet {
|
||||
utxo, ok := utxoSet.Get(outpoint)
|
||||
if ok {
|
||||
str := fmt.Sprintf("tried to overwrite transaction %v "+
|
||||
str := fmt.Sprintf("tried to overwrite transaction %s "+
|
||||
"at block height %d that is not fully spent",
|
||||
outpoint.TxID, utxo.BlockHeight())
|
||||
return ruleError(ErrOverwriteTx, str)
|
||||
@ -881,7 +881,7 @@ func CheckTransactionInputs(tx *util.Tx, txHeight int32, utxoSet UTXOSet, dagPar
|
||||
// Ensure the referenced input transaction is available.
|
||||
entry, ok := utxoSet.Get(txIn.PreviousOutPoint)
|
||||
if !ok {
|
||||
str := fmt.Sprintf("output %v referenced from "+
|
||||
str := fmt.Sprintf("output %s referenced from "+
|
||||
"transaction %s:%d either does not exist or "+
|
||||
"has already been spent", txIn.PreviousOutPoint,
|
||||
tx.ID(), txInIndex)
|
||||
@ -896,9 +896,9 @@ func CheckTransactionInputs(tx *util.Tx, txHeight int32, utxoSet UTXOSet, dagPar
|
||||
blockRewardMaturity := int32(dagParams.BlockRewardMaturity)
|
||||
if blocksSincePrev < blockRewardMaturity {
|
||||
str := fmt.Sprintf("tried to spend block reward "+
|
||||
"transaction output %v from height %v "+
|
||||
"at height %v before required maturity "+
|
||||
"of %v blocks", txIn.PreviousOutPoint,
|
||||
"transaction output %s from height %d "+
|
||||
"at height %d before required maturity "+
|
||||
"of %d blocks", txIn.PreviousOutPoint,
|
||||
originHeight, txHeight,
|
||||
blockRewardMaturity)
|
||||
return 0, ruleError(ErrImmatureSpend, str)
|
||||
@ -913,8 +913,8 @@ func CheckTransactionInputs(tx *util.Tx, txHeight int32, utxoSet UTXOSet, dagPar
|
||||
// SatoshiPerBitcoin constant.
|
||||
originTxSatoshi := entry.Amount()
|
||||
if originTxSatoshi > util.MaxSatoshi {
|
||||
str := fmt.Sprintf("transaction output value of %v is "+
|
||||
"higher than max allowed value of %v",
|
||||
str := fmt.Sprintf("transaction output value of %d is "+
|
||||
"higher than max allowed value of %f",
|
||||
util.Amount(originTxSatoshi),
|
||||
util.MaxSatoshi)
|
||||
return 0, ruleError(ErrBadTxOutValue, str)
|
||||
@ -928,8 +928,8 @@ func CheckTransactionInputs(tx *util.Tx, txHeight int32, utxoSet UTXOSet, dagPar
|
||||
if totalSatoshiIn < lastSatoshiIn ||
|
||||
totalSatoshiIn > util.MaxSatoshi {
|
||||
str := fmt.Sprintf("total value of all transaction "+
|
||||
"inputs is %v which is higher than max "+
|
||||
"allowed value of %v", totalSatoshiIn,
|
||||
"inputs is %d which is higher than max "+
|
||||
"allowed value of %f", totalSatoshiIn,
|
||||
util.MaxSatoshi)
|
||||
return 0, ruleError(ErrBadTxOutValue, str)
|
||||
}
|
||||
@ -946,8 +946,8 @@ func CheckTransactionInputs(tx *util.Tx, txHeight int32, utxoSet UTXOSet, dagPar
|
||||
// Ensure the transaction does not spend more than its inputs.
|
||||
if totalSatoshiIn < totalSatoshiOut {
|
||||
str := fmt.Sprintf("total value of all transaction inputs for "+
|
||||
"transaction %v is %v which is less than the amount "+
|
||||
"spent of %v", txID, totalSatoshiIn, totalSatoshiOut)
|
||||
"transaction %s is %d which is less than the amount "+
|
||||
"spent of %d", txID, totalSatoshiIn, totalSatoshiOut)
|
||||
return 0, ruleError(ErrSpendTooHigh, str)
|
||||
}
|
||||
|
||||
@ -1003,7 +1003,7 @@ func (dag *BlockDAG) checkConnectToPastUTXO(block *blockNode, pastUTXO UTXOSet,
|
||||
totalSigOps += numsigOps
|
||||
if totalSigOps < lastSigops || totalSigOps > MaxSigOpsPerBlock {
|
||||
str := fmt.Sprintf("block contains too many "+
|
||||
"signature operations - got %v, max %v",
|
||||
"signature operations - got %d, max %d",
|
||||
totalSigOps, MaxSigOpsPerBlock)
|
||||
return ruleError(ErrTooManySigOps, str)
|
||||
}
|
||||
@ -1045,8 +1045,8 @@ func (dag *BlockDAG) checkConnectToPastUTXO(block *blockNode, pastUTXO UTXOSet,
|
||||
}
|
||||
expectedSatoshiOut := CalcBlockSubsidy(block.height, dag.dagParams)
|
||||
if totalSatoshiOut > expectedSatoshiOut {
|
||||
str := fmt.Sprintf("coinbase transaction for block pays %v "+
|
||||
"which is more than expected value of %v",
|
||||
str := fmt.Sprintf("coinbase transaction for block pays %d "+
|
||||
"which is more than expected value of %d",
|
||||
totalSatoshiOut, expectedSatoshiOut)
|
||||
return ruleError(ErrBadCoinbaseValue, str)
|
||||
}
|
||||
@ -1136,8 +1136,8 @@ func (dag *BlockDAG) CheckConnectBlockTemplate(block *util.Block) error {
|
||||
header := block.MsgBlock().Header
|
||||
parentHashes := header.ParentHashes
|
||||
if !tips.hashesEqual(parentHashes) {
|
||||
str := fmt.Sprintf("parent blocks must be the currents tips %v, "+
|
||||
"instead got %v", tips, parentHashes)
|
||||
str := fmt.Sprintf("parent blocks must be the currents tips %s, "+
|
||||
"instead got %s", tips, parentHashes)
|
||||
return ruleError(ErrParentBlockNotCurrentTips, str)
|
||||
}
|
||||
|
||||
|
27
btcd.go
27
btcd.go
@ -14,6 +14,7 @@ import (
|
||||
"runtime"
|
||||
"runtime/debug"
|
||||
"runtime/pprof"
|
||||
"strings"
|
||||
|
||||
"github.com/daglabs/btcd/blockdag/indexers"
|
||||
"github.com/daglabs/btcd/config"
|
||||
@ -78,7 +79,7 @@ func btcdMain(serverChan chan<- *server.Server) error {
|
||||
profileRedirect := http.RedirectHandler("/debug/pprof",
|
||||
http.StatusSeeOther)
|
||||
http.Handle("/", profileRedirect)
|
||||
btcdLog.Errorf("%v", http.ListenAndServe(listenAddr, nil))
|
||||
btcdLog.Errorf("%s", http.ListenAndServe(listenAddr, nil))
|
||||
}()
|
||||
}
|
||||
|
||||
@ -86,7 +87,7 @@ func btcdMain(serverChan chan<- *server.Server) error {
|
||||
if cfg.CPUProfile != "" {
|
||||
f, err := os.Create(cfg.CPUProfile)
|
||||
if err != nil {
|
||||
btcdLog.Errorf("Unable to create cpu profile: %v", err)
|
||||
btcdLog.Errorf("Unable to create cpu profile: %s", err)
|
||||
return err
|
||||
}
|
||||
pprof.StartCPUProfile(f)
|
||||
@ -96,7 +97,7 @@ func btcdMain(serverChan chan<- *server.Server) error {
|
||||
|
||||
// Perform upgrades to btcd as new versions require it.
|
||||
if err := doUpgrades(); err != nil {
|
||||
btcdLog.Errorf("%v", err)
|
||||
btcdLog.Errorf("%s", err)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -108,7 +109,7 @@ func btcdMain(serverChan chan<- *server.Server) error {
|
||||
// Load the block database.
|
||||
db, err := loadBlockDB()
|
||||
if err != nil {
|
||||
btcdLog.Errorf("%v", err)
|
||||
btcdLog.Errorf("%s", err)
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
@ -128,7 +129,7 @@ func btcdMain(serverChan chan<- *server.Server) error {
|
||||
// drops the address index since it relies on it.
|
||||
if cfg.DropAddrIndex {
|
||||
if err := indexers.DropAddrIndex(db, interrupt); err != nil {
|
||||
btcdLog.Errorf("%v", err)
|
||||
btcdLog.Errorf("%s", err)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -136,7 +137,7 @@ func btcdMain(serverChan chan<- *server.Server) error {
|
||||
}
|
||||
if cfg.DropTxIndex {
|
||||
if err := indexers.DropTxIndex(db, interrupt); err != nil {
|
||||
btcdLog.Errorf("%v", err)
|
||||
btcdLog.Errorf("%s", err)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -144,7 +145,7 @@ func btcdMain(serverChan chan<- *server.Server) error {
|
||||
}
|
||||
if cfg.DropCfIndex {
|
||||
if err := indexers.DropCfIndex(db, interrupt); err != nil {
|
||||
btcdLog.Errorf("%v", err)
|
||||
btcdLog.Errorf("%s", err)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -156,8 +157,8 @@ func btcdMain(serverChan chan<- *server.Server) error {
|
||||
interrupt)
|
||||
if err != nil {
|
||||
// TODO: this logging could do with some beautifying.
|
||||
btcdLog.Errorf("Unable to start server on %v: %v",
|
||||
cfg.Listeners, err)
|
||||
btcdLog.Errorf("Unable to start server on %s: %s",
|
||||
strings.Join(cfg.Listeners, ", "), err)
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
@ -244,9 +245,9 @@ func warnMultipleDBs() {
|
||||
btcdLog.Warnf("WARNING: There are multiple block chain databases "+
|
||||
"using different database types.\nYou probably don't "+
|
||||
"want to waste disk space by having more than one.\n"+
|
||||
"Your current database is located at [%v].\nThe "+
|
||||
"additional database is located at %v", selectedDbPath,
|
||||
duplicateDbPaths)
|
||||
"Your current database is located at [%s].\nThe "+
|
||||
"additional database is located at %s", selectedDbPath,
|
||||
strings.Join(duplicateDbPaths, ", "))
|
||||
}
|
||||
}
|
||||
|
||||
@ -315,7 +316,7 @@ func main() {
|
||||
|
||||
// Up some limits.
|
||||
if err := limits.SetLimits(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "failed to set limits: %v\n", err)
|
||||
fmt.Fprintf(os.Stderr, "failed to set limits: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
@ -181,7 +181,7 @@ func parseSig(sigStr []byte, curve elliptic.Curve, der bool) (*Signature, error)
|
||||
|
||||
// sanity check length parsing
|
||||
if index != len(sigStr) {
|
||||
return nil, fmt.Errorf("malformed signature: bad final length %v != %v",
|
||||
return nil, fmt.Errorf("malformed signature: bad final length %d != %d",
|
||||
index, len(sigStr))
|
||||
}
|
||||
|
||||
|
@ -138,14 +138,14 @@ func UnmarshalCmd(r *Request) (interface{}, error) {
|
||||
fieldName := strings.ToLower(rt.Field(i).Name)
|
||||
if jerr, ok := err.(*json.UnmarshalTypeError); ok {
|
||||
str := fmt.Sprintf("parameter #%d '%s' must "+
|
||||
"be type %v (got %v)", i+1, fieldName,
|
||||
"be type %s (got %s)", i+1, fieldName,
|
||||
jerr.Type, jerr.Value)
|
||||
return nil, makeError(ErrInvalidType, str)
|
||||
}
|
||||
|
||||
// Fallback to showing the underlying error.
|
||||
str := fmt.Sprintf("parameter #%d '%s' failed to "+
|
||||
"unmarshal: %v", i+1, fieldName, err)
|
||||
"unmarshal: %s", i+1, fieldName, err)
|
||||
return nil, makeError(ErrInvalidType, str)
|
||||
}
|
||||
}
|
||||
@ -238,8 +238,8 @@ func assignField(paramNum int, fieldName string, dest reflect.Value, src reflect
|
||||
destBaseType, destIndirects := baseType(dest.Type())
|
||||
srcBaseType, srcIndirects := baseType(src.Type())
|
||||
if !typesMaybeCompatible(destBaseType, srcBaseType) {
|
||||
str := fmt.Sprintf("parameter #%d '%s' must be type %v (got "+
|
||||
"%v)", paramNum, fieldName, destBaseType, srcBaseType)
|
||||
str := fmt.Sprintf("parameter #%d '%s' must be type %s (got "+
|
||||
"%s)", paramNum, fieldName, destBaseType, srcBaseType)
|
||||
return makeError(ErrInvalidType, str)
|
||||
}
|
||||
|
||||
@ -301,7 +301,7 @@ func assignField(paramNum int, fieldName string, dest reflect.Value, src reflect
|
||||
srcInt := src.Int()
|
||||
if dest.OverflowInt(srcInt) {
|
||||
str := fmt.Sprintf("parameter #%d '%s' "+
|
||||
"overflows destination type %v",
|
||||
"overflows destination type %s",
|
||||
paramNum, fieldName, destBaseType)
|
||||
return makeError(ErrInvalidType, str)
|
||||
}
|
||||
@ -315,7 +315,7 @@ func assignField(paramNum int, fieldName string, dest reflect.Value, src reflect
|
||||
srcInt := src.Int()
|
||||
if srcInt < 0 || dest.OverflowUint(uint64(srcInt)) {
|
||||
str := fmt.Sprintf("parameter #%d '%s' "+
|
||||
"overflows destination type %v",
|
||||
"overflows destination type %s",
|
||||
paramNum, fieldName, destBaseType)
|
||||
return makeError(ErrInvalidType, str)
|
||||
}
|
||||
@ -323,7 +323,7 @@ func assignField(paramNum int, fieldName string, dest reflect.Value, src reflect
|
||||
|
||||
default:
|
||||
str := fmt.Sprintf("parameter #%d '%s' must be type "+
|
||||
"%v (got %v)", paramNum, fieldName, destBaseType,
|
||||
"%s (got %s)", paramNum, fieldName, destBaseType,
|
||||
srcBaseType)
|
||||
return makeError(ErrInvalidType, str)
|
||||
}
|
||||
@ -340,13 +340,13 @@ func assignField(paramNum int, fieldName string, dest reflect.Value, src reflect
|
||||
srcUint := src.Uint()
|
||||
if srcUint > uint64(1<<63)-1 {
|
||||
str := fmt.Sprintf("parameter #%d '%s' "+
|
||||
"overflows destination type %v",
|
||||
"overflows destination type %s",
|
||||
paramNum, fieldName, destBaseType)
|
||||
return makeError(ErrInvalidType, str)
|
||||
}
|
||||
if dest.OverflowInt(int64(srcUint)) {
|
||||
str := fmt.Sprintf("parameter #%d '%s' "+
|
||||
"overflows destination type %v",
|
||||
"overflows destination type %s",
|
||||
paramNum, fieldName, destBaseType)
|
||||
return makeError(ErrInvalidType, str)
|
||||
}
|
||||
@ -359,7 +359,7 @@ func assignField(paramNum int, fieldName string, dest reflect.Value, src reflect
|
||||
srcUint := src.Uint()
|
||||
if dest.OverflowUint(srcUint) {
|
||||
str := fmt.Sprintf("parameter #%d '%s' "+
|
||||
"overflows destination type %v",
|
||||
"overflows destination type %s",
|
||||
paramNum, fieldName, destBaseType)
|
||||
return makeError(ErrInvalidType, str)
|
||||
}
|
||||
@ -367,7 +367,7 @@ func assignField(paramNum int, fieldName string, dest reflect.Value, src reflect
|
||||
|
||||
default:
|
||||
str := fmt.Sprintf("parameter #%d '%s' must be type "+
|
||||
"%v (got %v)", paramNum, fieldName, destBaseType,
|
||||
"%s (got %s)", paramNum, fieldName, destBaseType,
|
||||
srcBaseType)
|
||||
return makeError(ErrInvalidType, str)
|
||||
}
|
||||
@ -377,7 +377,7 @@ func assignField(paramNum int, fieldName string, dest reflect.Value, src reflect
|
||||
destKind := dest.Kind()
|
||||
if destKind != reflect.Float32 && destKind != reflect.Float64 {
|
||||
str := fmt.Sprintf("parameter #%d '%s' must be type "+
|
||||
"%v (got %v)", paramNum, fieldName, destBaseType,
|
||||
"%s (got %s)", paramNum, fieldName, destBaseType,
|
||||
srcBaseType)
|
||||
return makeError(ErrInvalidType, str)
|
||||
}
|
||||
@ -385,7 +385,7 @@ func assignField(paramNum int, fieldName string, dest reflect.Value, src reflect
|
||||
srcFloat := src.Float()
|
||||
if dest.OverflowFloat(srcFloat) {
|
||||
str := fmt.Sprintf("parameter #%d '%s' overflows "+
|
||||
"destination type %v", paramNum, fieldName,
|
||||
"destination type %s", paramNum, fieldName,
|
||||
destBaseType)
|
||||
return makeError(ErrInvalidType, str)
|
||||
}
|
||||
@ -399,7 +399,7 @@ func assignField(paramNum int, fieldName string, dest reflect.Value, src reflect
|
||||
b, err := strconv.ParseBool(src.String())
|
||||
if err != nil {
|
||||
str := fmt.Sprintf("parameter #%d '%s' must "+
|
||||
"parse to a %v", paramNum, fieldName,
|
||||
"parse to a %s", paramNum, fieldName,
|
||||
destBaseType)
|
||||
return makeError(ErrInvalidType, str)
|
||||
}
|
||||
@ -412,13 +412,13 @@ func assignField(paramNum int, fieldName string, dest reflect.Value, src reflect
|
||||
srcInt, err := strconv.ParseInt(src.String(), 0, 0)
|
||||
if err != nil {
|
||||
str := fmt.Sprintf("parameter #%d '%s' must "+
|
||||
"parse to a %v", paramNum, fieldName,
|
||||
"parse to a %s", paramNum, fieldName,
|
||||
destBaseType)
|
||||
return makeError(ErrInvalidType, str)
|
||||
}
|
||||
if dest.OverflowInt(srcInt) {
|
||||
str := fmt.Sprintf("parameter #%d '%s' "+
|
||||
"overflows destination type %v",
|
||||
"overflows destination type %s",
|
||||
paramNum, fieldName, destBaseType)
|
||||
return makeError(ErrInvalidType, str)
|
||||
}
|
||||
@ -431,13 +431,13 @@ func assignField(paramNum int, fieldName string, dest reflect.Value, src reflect
|
||||
srcUint, err := strconv.ParseUint(src.String(), 0, 0)
|
||||
if err != nil {
|
||||
str := fmt.Sprintf("parameter #%d '%s' must "+
|
||||
"parse to a %v", paramNum, fieldName,
|
||||
"parse to a %s", paramNum, fieldName,
|
||||
destBaseType)
|
||||
return makeError(ErrInvalidType, str)
|
||||
}
|
||||
if dest.OverflowUint(srcUint) {
|
||||
str := fmt.Sprintf("parameter #%d '%s' "+
|
||||
"overflows destination type %v",
|
||||
"overflows destination type %s",
|
||||
paramNum, fieldName, destBaseType)
|
||||
return makeError(ErrInvalidType, str)
|
||||
}
|
||||
@ -448,13 +448,13 @@ func assignField(paramNum int, fieldName string, dest reflect.Value, src reflect
|
||||
srcFloat, err := strconv.ParseFloat(src.String(), 0)
|
||||
if err != nil {
|
||||
str := fmt.Sprintf("parameter #%d '%s' must "+
|
||||
"parse to a %v", paramNum, fieldName,
|
||||
"parse to a %s", paramNum, fieldName,
|
||||
destBaseType)
|
||||
return makeError(ErrInvalidType, str)
|
||||
}
|
||||
if dest.OverflowFloat(srcFloat) {
|
||||
str := fmt.Sprintf("parameter #%d '%s' "+
|
||||
"overflows destination type %v",
|
||||
"overflows destination type %s",
|
||||
paramNum, fieldName, destBaseType)
|
||||
return makeError(ErrInvalidType, str)
|
||||
}
|
||||
@ -471,7 +471,7 @@ func assignField(paramNum int, fieldName string, dest reflect.Value, src reflect
|
||||
err := json.Unmarshal([]byte(src.String()), &concreteVal)
|
||||
if err != nil {
|
||||
str := fmt.Sprintf("parameter #%d '%s' must "+
|
||||
"be valid JSON which unsmarshals to a %v",
|
||||
"be valid JSON which unsmarshals to a %s",
|
||||
paramNum, fieldName, destBaseType)
|
||||
return makeError(ErrInvalidType, str)
|
||||
}
|
||||
|
@ -7,10 +7,11 @@ package btcjson
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/daglabs/btcd/util"
|
||||
"reflect"
|
||||
"strings"
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/daglabs/btcd/util"
|
||||
)
|
||||
|
||||
// baseHelpDescs house the various help labels, types, and example values used
|
||||
@ -523,14 +524,14 @@ func GenerateHelp(method string, descs map[string]string, resultTypes ...interfa
|
||||
|
||||
rtp := reflect.TypeOf(resultType)
|
||||
if rtp.Kind() != reflect.Ptr {
|
||||
str := fmt.Sprintf("result #%d (%v) is not a pointer",
|
||||
str := fmt.Sprintf("result #%d (%s) is not a pointer",
|
||||
i, rtp.Kind())
|
||||
return "", makeError(ErrInvalidType, str)
|
||||
}
|
||||
|
||||
elemKind := rtp.Elem().Kind()
|
||||
if !isValidResultType(elemKind) {
|
||||
str := fmt.Sprintf("result #%d (%v) is not an allowed "+
|
||||
str := fmt.Sprintf("result #%d (%s) is not an allowed "+
|
||||
"type", i, elemKind)
|
||||
return "", makeError(ErrInvalidType, str)
|
||||
}
|
||||
|
@ -166,7 +166,7 @@ func RegisterCmd(method string, cmd interface{}, flags UsageFlag) error {
|
||||
// Ensure that no unrecognized flag bits were specified.
|
||||
if ^(highestUsageFlagBit-1)&flags != 0 {
|
||||
str := fmt.Sprintf("invalid usage flags specified for method "+
|
||||
"%s: %v", method, flags)
|
||||
"%s: %s", method, flags)
|
||||
return makeError(ErrInvalidUsageFlags, str)
|
||||
}
|
||||
|
||||
@ -271,7 +271,7 @@ func RegisterCmd(method string, cmd interface{}, flags UsageFlag) error {
|
||||
// functions.
|
||||
func MustRegisterCmd(method string, cmd interface{}, flags UsageFlag) {
|
||||
if err := RegisterCmd(method, cmd, flags); err != nil {
|
||||
panic(fmt.Sprintf("failed to register type %q: %v\n", method,
|
||||
panic(fmt.Sprintf("failed to register type %q: %s\n", method,
|
||||
err))
|
||||
}
|
||||
}
|
||||
|
@ -74,14 +74,14 @@ func realMain() error {
|
||||
// Load the block database.
|
||||
db, err := loadBlockDB()
|
||||
if err != nil {
|
||||
log.Errorf("Failed to load database: %v", err)
|
||||
log.Errorf("Failed to load database: %s", err)
|
||||
return err
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
fi, err := os.Open(cfg.InFile)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to open file %v: %v", cfg.InFile, err)
|
||||
log.Errorf("Failed to open file %s: %s", cfg.InFile, err)
|
||||
return err
|
||||
}
|
||||
defer fi.Close()
|
||||
@ -91,7 +91,7 @@ func realMain() error {
|
||||
// anything went wrong.
|
||||
importer, err := newBlockImporter(db, fi)
|
||||
if err != nil {
|
||||
log.Errorf("Failed create block importer: %v", err)
|
||||
log.Errorf("Failed create block importer: %s", err)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -103,7 +103,7 @@ func realMain() error {
|
||||
resultsChan := importer.Import()
|
||||
results := <-resultsChan
|
||||
if results.err != nil {
|
||||
log.Errorf("%v", results.err)
|
||||
log.Errorf("%s", results.err)
|
||||
return results.err
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/daglabs/btcd/dagconfig"
|
||||
"github.com/daglabs/btcd/database"
|
||||
@ -132,9 +133,9 @@ func loadConfig() (*config, []string, error) {
|
||||
|
||||
// Validate database type.
|
||||
if !validDbType(cfg.DbType) {
|
||||
str := "%s: The specified database type [%v] is invalid -- " +
|
||||
"supported types %v"
|
||||
err := fmt.Errorf(str, "loadConfig", cfg.DbType, knownDbTypes)
|
||||
str := "%s: The specified database type [%s] is invalid -- " +
|
||||
"supported types %s"
|
||||
err := fmt.Errorf(str, "loadConfig", cfg.DbType, strings.Join(knownDbTypes, ", "))
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
parser.WriteHelp(os.Stderr)
|
||||
return nil, nil, err
|
||||
@ -150,7 +151,7 @@ func loadConfig() (*config, []string, error) {
|
||||
|
||||
// Ensure the specified block file exists.
|
||||
if !fileExists(cfg.InFile) {
|
||||
str := "%s: The specified block file [%v] does not exist"
|
||||
str := "%s: The specified block file [%s] does not exist"
|
||||
err := fmt.Errorf(str, "loadConfig", cfg.InFile)
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
parser.WriteHelp(os.Stderr)
|
||||
|
@ -133,7 +133,7 @@ func (bi *blockImporter) processBlock(serializedBlock []byte) (bool, error) {
|
||||
}
|
||||
if isOrphan {
|
||||
return false, fmt.Errorf("import file contains an orphan "+
|
||||
"block: %v", blockHash)
|
||||
"block: %s", blockHash)
|
||||
}
|
||||
|
||||
return true, nil
|
||||
@ -150,7 +150,7 @@ out:
|
||||
serializedBlock, err := bi.readBlock()
|
||||
if err != nil {
|
||||
bi.errChan <- fmt.Errorf("Error reading from input "+
|
||||
"file: %v", err.Error())
|
||||
"file: %s", err.Error())
|
||||
break out
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,7 @@ func main() {
|
||||
param, err := bio.ReadString('\n')
|
||||
if err != nil && err != io.EOF {
|
||||
fmt.Fprintf(os.Stderr, "Failed to read data "+
|
||||
"from stdin: %v\n", err)
|
||||
"from stdin: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if err == io.EOF && len(param) == 0 {
|
||||
@ -111,7 +111,7 @@ func main() {
|
||||
// NewCmd function is only supposed to return errors of that
|
||||
// type.
|
||||
if jerr, ok := err.(btcjson.Error); ok {
|
||||
fmt.Fprintf(os.Stderr, "%s command: %v (code: %s)\n",
|
||||
fmt.Fprintf(os.Stderr, "%s error: %s (command code: %s)\n",
|
||||
method, err, jerr.ErrorCode)
|
||||
commandUsage(method)
|
||||
os.Exit(1)
|
||||
@ -120,7 +120,7 @@ func main() {
|
||||
// The error is not a btcjson.Error and this really should not
|
||||
// happen. Nevertheless, fallback to just showing the error
|
||||
// if it should happen due to a bug in the package.
|
||||
fmt.Fprintf(os.Stderr, "%s command: %v\n", method, err)
|
||||
fmt.Fprintf(os.Stderr, "%s error: %s\n", method, err)
|
||||
commandUsage(method)
|
||||
os.Exit(1)
|
||||
}
|
||||
@ -146,7 +146,7 @@ func main() {
|
||||
if strings.HasPrefix(strResult, "{") || strings.HasPrefix(strResult, "[") {
|
||||
var dst bytes.Buffer
|
||||
if err := json.Indent(&dst, result, "", " "); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Failed to format result: %v",
|
||||
fmt.Fprintf(os.Stderr, "Failed to format result: %s",
|
||||
err)
|
||||
os.Exit(1)
|
||||
}
|
||||
@ -155,7 +155,7 @@ func main() {
|
||||
} else if strings.HasPrefix(strResult, `"`) {
|
||||
var str string
|
||||
if err := json.Unmarshal(result, &str); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Failed to unmarshal result: %v",
|
||||
fmt.Fprintf(os.Stderr, "Failed to unmarshal result: %s",
|
||||
err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
@ -221,7 +221,7 @@ func loadConfig() (*config, []string, error) {
|
||||
|
||||
err := createDefaultConfigFile(preCfg.ConfigFile, serverConfigPath)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error creating a default config file: %v\n", err)
|
||||
fmt.Fprintf(os.Stderr, "Error creating a default config file: %s\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -230,7 +230,7 @@ func loadConfig() (*config, []string, error) {
|
||||
err = flags.NewIniParser(parser).ParseFile(preCfg.ConfigFile)
|
||||
if err != nil {
|
||||
if _, ok := err.(*os.PathError); !ok {
|
||||
fmt.Fprintf(os.Stderr, "Error parsing config file: %v\n",
|
||||
fmt.Fprintf(os.Stderr, "Error parsing config file: %s\n",
|
||||
err)
|
||||
fmt.Fprintln(os.Stderr, usageMessage)
|
||||
return nil, nil, err
|
||||
|
@ -98,7 +98,7 @@ func sendPostRequest(marshalledJSON []byte, cfg *config) ([]byte, error) {
|
||||
respBytes, err := ioutil.ReadAll(httpResponse.Body)
|
||||
httpResponse.Body.Close()
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error reading json reply: %v", err)
|
||||
err = fmt.Errorf("error reading json reply: %s", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/daglabs/btcd/dagconfig"
|
||||
"github.com/daglabs/btcd/database"
|
||||
@ -120,9 +121,9 @@ func loadConfig() (*config, []string, error) {
|
||||
|
||||
// Validate database type.
|
||||
if !validDbType(cfg.DbType) {
|
||||
str := "%s: The specified database type [%v] is invalid -- " +
|
||||
"supported types %v"
|
||||
err := fmt.Errorf(str, "loadConfig", cfg.DbType, knownDbTypes)
|
||||
str := "%s: The specified database type [%s] is invalid -- " +
|
||||
"supported types %s"
|
||||
err := fmt.Errorf(str, funcName, cfg.DbType, strings.Join(knownDbTypes, ", "))
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
parser.WriteHelp(os.Stderr)
|
||||
return nil, nil, err
|
||||
@ -139,8 +140,8 @@ func loadConfig() (*config, []string, error) {
|
||||
// Validate the number of candidates.
|
||||
if cfg.NumCandidates < minCandidates || cfg.NumCandidates > maxCandidates {
|
||||
str := "%s: The specified number of candidates is out of " +
|
||||
"range -- parsed [%v]"
|
||||
err = fmt.Errorf(str, "loadConfig", cfg.NumCandidates)
|
||||
"range -- parsed [%d]"
|
||||
err = fmt.Errorf(str, funcName, cfg.NumCandidates)
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
parser.WriteHelp(os.Stderr)
|
||||
return nil, nil, err
|
||||
|
@ -122,12 +122,12 @@ func findCandidates(dag *blockdag.BlockDAG, highestTipHash *daghash.Hash) ([]*da
|
||||
// uses the format the btcchain code expects for checkpoints added to the list.
|
||||
func showCandidate(candidateNum int, checkpoint *dagconfig.Checkpoint) {
|
||||
if cfg.UseGoOutput {
|
||||
fmt.Printf("Candidate %d -- {%d, newShaHashFromStr(\"%v\")},\n",
|
||||
fmt.Printf("Candidate %d -- {%d, newShaHashFromStr(\"%s\")},\n",
|
||||
candidateNum, checkpoint.Height, checkpoint.Hash)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("Candidate %d -- Height: %d, Hash: %v\n", candidateNum,
|
||||
fmt.Printf("Candidate %d -- Height: %d, Hash: %s\n", candidateNum,
|
||||
checkpoint.Height, checkpoint.Hash)
|
||||
|
||||
}
|
||||
@ -156,7 +156,7 @@ func main() {
|
||||
TimeSource: blockdag.NewMedianTime(),
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "failed to initialize chain: %v\n", err)
|
||||
fmt.Fprintf(os.Stderr, "failed to initialize chain: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ func main() {
|
||||
|
||||
if !cfg.Force {
|
||||
if fileExists(certFile) || fileExists(keyFile) {
|
||||
fmt.Fprintf(os.Stderr, "%v: certificate and/or key files exist; use -f to force\n", cfg.Directory)
|
||||
fmt.Fprintf(os.Stderr, "%s: certificate and/or key files exist; use -f to force\n", cfg.Directory)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
@ -60,18 +60,18 @@ func main() {
|
||||
validUntil := time.Now().Add(time.Duration(cfg.Years) * 365 * 24 * time.Hour)
|
||||
cert, key, err := util.NewTLSCertPair(cfg.Organization, validUntil, cfg.ExtraHosts)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "cannot generate certificate pair: %v\n", err)
|
||||
fmt.Fprintf(os.Stderr, "cannot generate certificate pair: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Write cert and key files.
|
||||
if err = ioutil.WriteFile(certFile, cert, 0666); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "cannot write cert: %v\n", err)
|
||||
fmt.Fprintf(os.Stderr, "cannot write cert: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if err = ioutil.WriteFile(keyFile, key, 0600); err != nil {
|
||||
os.Remove(certFile)
|
||||
fmt.Fprintf(os.Stderr, "cannot write key: %v\n", err)
|
||||
fmt.Fprintf(os.Stderr, "cannot write key: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
@ -377,7 +377,7 @@ func loadConfig() (*Config, []string, error) {
|
||||
err := createDefaultConfigFile(preCfg.ConfigFile)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error creating a "+
|
||||
"default config file: %v\n", err)
|
||||
"default config file: %s\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -385,7 +385,7 @@ func loadConfig() (*Config, []string, error) {
|
||||
if err != nil {
|
||||
if _, ok := err.(*os.PathError); !ok {
|
||||
fmt.Fprintf(os.Stderr, "Error parsing config "+
|
||||
"file: %v\n", err)
|
||||
"file: %s\n", err)
|
||||
fmt.Fprintln(os.Stderr, usageMessage)
|
||||
return nil, nil, err
|
||||
}
|
||||
@ -421,7 +421,7 @@ func loadConfig() (*Config, []string, error) {
|
||||
}
|
||||
}
|
||||
|
||||
str := "%s: Failed to create home directory: %v"
|
||||
str := "%s: Failed to create home directory: %s"
|
||||
err := fmt.Errorf(str, funcName, err)
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
return nil, nil, err
|
||||
@ -500,7 +500,7 @@ func loadConfig() (*Config, []string, error) {
|
||||
|
||||
// Parse, validate, and set debug log level(s).
|
||||
if err := logger.ParseAndSetDebugLevels(cfg.DebugLevel); err != nil {
|
||||
err := fmt.Errorf("%s: %v", funcName, err.Error())
|
||||
err := fmt.Errorf("%s: %s", funcName, err.Error())
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
fmt.Fprintln(os.Stderr, usageMessage)
|
||||
return nil, nil, err
|
||||
@ -508,8 +508,8 @@ func loadConfig() (*Config, []string, error) {
|
||||
|
||||
// Validate database type.
|
||||
if !validDbType(cfg.DbType) {
|
||||
str := "%s: The specified database type [%v] is invalid -- " +
|
||||
"supported types %v"
|
||||
str := "%s: The specified database type [%s] is invalid -- " +
|
||||
"supported types %s"
|
||||
err := fmt.Errorf(str, funcName, cfg.DbType, knownDbTypes)
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
fmt.Fprintln(os.Stderr, usageMessage)
|
||||
@ -530,7 +530,7 @@ func loadConfig() (*Config, []string, error) {
|
||||
|
||||
// Don't allow ban durations that are too short.
|
||||
if cfg.BanDuration < time.Second {
|
||||
str := "%s: The banduration option may not be less than 1s -- parsed [%v]"
|
||||
str := "%s: The banduration option may not be less than 1s -- parsed [%s]"
|
||||
err := fmt.Errorf(str, funcName, cfg.BanDuration)
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
fmt.Fprintln(os.Stderr, usageMessage)
|
||||
@ -654,7 +654,7 @@ func loadConfig() (*Config, []string, error) {
|
||||
// Validate the the minrelaytxfee.
|
||||
cfg.MinRelayTxFee, err = util.NewAmount(cfg.configFlags.MinRelayTxFee)
|
||||
if err != nil {
|
||||
str := "%s: invalid minrelaytxfee: %v"
|
||||
str := "%s: invalid minrelaytxfee: %s"
|
||||
err := fmt.Errorf(str, funcName, err)
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
fmt.Fprintln(os.Stderr, usageMessage)
|
||||
@ -737,7 +737,7 @@ func loadConfig() (*Config, []string, error) {
|
||||
for _, strAddr := range cfg.configFlags.MiningAddrs {
|
||||
addr, err := util.DecodeAddress(strAddr, activeNetParams.Prefix)
|
||||
if err != nil {
|
||||
str := "%s: mining address '%s' failed to decode: %v"
|
||||
str := "%s: mining address '%s' failed to decode: %s"
|
||||
err := fmt.Errorf(str, funcName, strAddr, err)
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
fmt.Fprintln(os.Stderr, usageMessage)
|
||||
@ -802,7 +802,7 @@ func loadConfig() (*Config, []string, error) {
|
||||
host, _, err := net.SplitHostPort(addr)
|
||||
if err != nil {
|
||||
str := "%s: RPC listen interface '%s' is " +
|
||||
"invalid: %v"
|
||||
"invalid: %s"
|
||||
err := fmt.Errorf(str, funcName, addr, err)
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
fmt.Fprintln(os.Stderr, usageMessage)
|
||||
@ -839,7 +839,7 @@ func loadConfig() (*Config, []string, error) {
|
||||
// Check the checkpoints for syntax errors.
|
||||
cfg.AddCheckpoints, err = parseCheckpoints(cfg.configFlags.AddCheckpoints)
|
||||
if err != nil {
|
||||
str := "%s: Error parsing checkpoints: %v"
|
||||
str := "%s: Error parsing checkpoints: %s"
|
||||
err := fmt.Errorf(str, funcName, err)
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
fmt.Fprintln(os.Stderr, usageMessage)
|
||||
@ -867,7 +867,7 @@ func loadConfig() (*Config, []string, error) {
|
||||
if cfg.Proxy != "" {
|
||||
_, _, err := net.SplitHostPort(cfg.Proxy)
|
||||
if err != nil {
|
||||
str := "%s: Proxy address '%s' is invalid: %v"
|
||||
str := "%s: Proxy address '%s' is invalid: %s"
|
||||
err := fmt.Errorf(str, funcName, cfg.Proxy, err)
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
fmt.Fprintln(os.Stderr, usageMessage)
|
||||
@ -913,7 +913,7 @@ func loadConfig() (*Config, []string, error) {
|
||||
if cfg.OnionProxy != "" {
|
||||
_, _, err := net.SplitHostPort(cfg.OnionProxy)
|
||||
if err != nil {
|
||||
str := "%s: Onion proxy address '%s' is invalid: %v"
|
||||
str := "%s: Onion proxy address '%s' is invalid: %s"
|
||||
err := fmt.Errorf(str, funcName, cfg.OnionProxy, err)
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
fmt.Fprintln(os.Stderr, usageMessage)
|
||||
@ -964,7 +964,7 @@ func loadConfig() (*Config, []string, error) {
|
||||
// done. This prevents the warning on help messages and invalid
|
||||
// options. Note this should go directly before the return.
|
||||
if configFileError != nil {
|
||||
log.Warnf("%v", configFileError)
|
||||
log.Warnf("%s", configFileError)
|
||||
}
|
||||
|
||||
return &cfg, remainingArgs, nil
|
||||
|
@ -200,7 +200,7 @@ func (cm *ConnManager) handleFailedConn(c *ConnReq) {
|
||||
if d > maxRetryDuration {
|
||||
d = maxRetryDuration
|
||||
}
|
||||
log.Debugf("Retrying connection to %v in %v", c, d)
|
||||
log.Debugf("Retrying connection to %s in %s", c, d)
|
||||
time.AfterFunc(d, func() {
|
||||
cm.Connect(c)
|
||||
})
|
||||
@ -208,7 +208,7 @@ func (cm *ConnManager) handleFailedConn(c *ConnReq) {
|
||||
cm.failedAttempts++
|
||||
if cm.failedAttempts >= maxFailedAttempts {
|
||||
log.Debugf("Max failed connection attempts reached: [%d] "+
|
||||
"-- retrying connection in: %v", maxFailedAttempts,
|
||||
"-- retrying connection in: %s", maxFailedAttempts,
|
||||
cm.cfg.RetryDuration)
|
||||
time.AfterFunc(cm.cfg.RetryDuration, func() {
|
||||
cm.NewConnReq()
|
||||
@ -256,14 +256,14 @@ out:
|
||||
msg.conn.Close()
|
||||
}
|
||||
log.Debugf("Ignoring connection for "+
|
||||
"canceled connreq=%v", connReq)
|
||||
"canceled connreq=%s", connReq)
|
||||
continue
|
||||
}
|
||||
|
||||
connReq.updateState(ConnEstablished)
|
||||
connReq.conn = msg.conn
|
||||
conns[connReq.id] = connReq
|
||||
log.Debugf("Connected to %v", connReq)
|
||||
log.Debugf("Connected to %s", connReq)
|
||||
connReq.retryCount = 0
|
||||
cm.failedAttempts = 0
|
||||
|
||||
@ -288,7 +288,7 @@ out:
|
||||
// ignore a later, successful
|
||||
// connection.
|
||||
connReq.updateState(ConnCanceled)
|
||||
log.Debugf("Canceling: %v", connReq)
|
||||
log.Debugf("Canceling: %s", connReq)
|
||||
delete(pending, msg.id)
|
||||
continue
|
||||
|
||||
@ -297,7 +297,7 @@ out:
|
||||
// An existing connection was located, mark as
|
||||
// disconnected and execute disconnection
|
||||
// callback.
|
||||
log.Debugf("Disconnected from %v", connReq)
|
||||
log.Debugf("Disconnected from %s", connReq)
|
||||
delete(conns, msg.id)
|
||||
|
||||
if connReq.conn != nil {
|
||||
@ -326,7 +326,7 @@ out:
|
||||
connReq.Permanent {
|
||||
|
||||
connReq.updateState(ConnPending)
|
||||
log.Debugf("Reconnecting to %v",
|
||||
log.Debugf("Reconnecting to %s",
|
||||
connReq)
|
||||
pending[msg.id] = connReq
|
||||
cm.handleFailedConn(connReq)
|
||||
@ -337,12 +337,12 @@ out:
|
||||
|
||||
if _, ok := pending[connReq.id]; !ok {
|
||||
log.Debugf("Ignoring connection for "+
|
||||
"canceled conn req: %v", connReq)
|
||||
"canceled conn req: %s", connReq)
|
||||
continue
|
||||
}
|
||||
|
||||
connReq.updateState(ConnFailing)
|
||||
log.Debugf("Failed to connect to %v: %v",
|
||||
log.Debugf("Failed to connect to %s: %s",
|
||||
connReq, msg.err)
|
||||
cm.handleFailedConn(connReq)
|
||||
}
|
||||
@ -431,7 +431,7 @@ func (cm *ConnManager) Connect(c *ConnReq) {
|
||||
}
|
||||
}
|
||||
|
||||
log.Debugf("Attempting to connect to %v", c)
|
||||
log.Debugf("Attempting to connect to %s", c)
|
||||
|
||||
conn, err := cm.cfg.Dial(c.Addr)
|
||||
if err != nil {
|
||||
@ -487,7 +487,7 @@ func (cm *ConnManager) listenHandler(listener net.Listener) {
|
||||
if err != nil {
|
||||
// Only log the error if not forcibly shutting down.
|
||||
if atomic.LoadInt32(&cm.stop) == 0 {
|
||||
log.Errorf("Can't accept connection: %v", err)
|
||||
log.Errorf("Can't accept connection: %s", err)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ type DynamicBanScore struct {
|
||||
// String returns the ban score as a human-readable string.
|
||||
func (s *DynamicBanScore) String() string {
|
||||
s.mtx.Lock()
|
||||
r := fmt.Sprintf("persistent %v + transient %v at %v = %v as of now",
|
||||
r := fmt.Sprintf("persistent %d + transient %f at %d = %d as of now",
|
||||
s.persistent, s.transient, s.lastUnix, s.Int())
|
||||
s.mtx.Unlock()
|
||||
return r
|
||||
|
@ -46,7 +46,7 @@ func SeedFromDNS(dagParams *dagconfig.Params, reqServices wire.ServiceFlag,
|
||||
|
||||
seedpeers, err := lookupFn(host)
|
||||
if err != nil {
|
||||
log.Infof("DNS discovery failed on seed %s: %v", host, err)
|
||||
log.Infof("DNS discovery failed on seed %s: %s", host, err)
|
||||
return
|
||||
}
|
||||
numPeers := len(seedpeers)
|
||||
|
@ -21,7 +21,7 @@ const MaxHashStringSize = HashSize * 2
|
||||
|
||||
// ErrHashStrSize describes an error that indicates the caller specified a hash
|
||||
// string that has too many characters.
|
||||
var ErrHashStrSize = fmt.Errorf("max hash string length is %v bytes", MaxHashStringSize)
|
||||
var ErrHashStrSize = fmt.Errorf("max hash string length is %d bytes", MaxHashStringSize)
|
||||
|
||||
// Hash is used in several of the bitcoin messages and common structures. It
|
||||
// typically represents the double sha256 of data.
|
||||
@ -81,7 +81,7 @@ func (txID *TxID) CloneBytes() []byte {
|
||||
func (hash *Hash) SetBytes(newHash []byte) error {
|
||||
nhlen := len(newHash)
|
||||
if nhlen != HashSize {
|
||||
return fmt.Errorf("invalid hash length of %v, want %v", nhlen,
|
||||
return fmt.Errorf("invalid hash length of %d, want %d", nhlen,
|
||||
HashSize)
|
||||
}
|
||||
copy(hash[:], newHash)
|
||||
|
@ -50,7 +50,7 @@ func (cmd *fetchBlockCmd) Execute(args []string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Infof("Loaded block in %v", time.Since(startTime))
|
||||
log.Infof("Loaded block in %s", time.Since(startTime))
|
||||
log.Infof("Block Hex: %s", hex.EncodeToString(blockBytes))
|
||||
return nil
|
||||
})
|
||||
|
@ -77,7 +77,7 @@ func (cmd *blockRegionCmd) Execute(args []string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Infof("Loaded block region in %v", time.Since(startTime))
|
||||
log.Infof("Loaded block region in %s", time.Since(startTime))
|
||||
log.Infof("Double Hash: %s", daghash.DoubleHashH(regionBytes))
|
||||
log.Infof("Region Hex: %s", hex.EncodeToString(regionBytes))
|
||||
return nil
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/daglabs/btcd/dagconfig"
|
||||
"github.com/daglabs/btcd/database"
|
||||
@ -104,9 +105,9 @@ func setupGlobalConfig() error {
|
||||
|
||||
// Validate database type.
|
||||
if !validDbType(cfg.DbType) {
|
||||
str := "The specified database type [%v] is invalid -- " +
|
||||
"supported types %v"
|
||||
return fmt.Errorf(str, cfg.DbType, knownDbTypes)
|
||||
str := "The specified database type [%s] is invalid -- " +
|
||||
"supported types: %s"
|
||||
return fmt.Errorf(str, cfg.DbType, strings.Join(knownDbTypes, ", "))
|
||||
}
|
||||
|
||||
// Append the network type to the data directory so it is "namespaced"
|
||||
|
@ -138,7 +138,7 @@ func (bi *blockImporter) processBlock(serializedBlock []byte) (bool, error) {
|
||||
}
|
||||
if !exists {
|
||||
return false, fmt.Errorf("import file contains block "+
|
||||
"%v which does not link to the available "+
|
||||
"%s which does not link to the available "+
|
||||
"block chain", parentHash)
|
||||
}
|
||||
}
|
||||
@ -165,7 +165,7 @@ out:
|
||||
serializedBlock, err := bi.readBlock()
|
||||
if err != nil {
|
||||
bi.errChan <- fmt.Errorf("Error reading from input "+
|
||||
"file: %v", err.Error())
|
||||
"file: %s", err.Error())
|
||||
break out
|
||||
}
|
||||
|
||||
@ -328,7 +328,7 @@ func (cmd *importCmd) Execute(args []string) error {
|
||||
|
||||
// Ensure the specified block file exists.
|
||||
if !fileExists(cmd.InFile) {
|
||||
str := "The specified block file [%v] does not exist"
|
||||
str := "The specified block file [%s] does not exist"
|
||||
return fmt.Errorf(str, cmd.InFile)
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ func (cmd *headersCmd) Execute(args []string) error {
|
||||
numLoaded++
|
||||
return nil
|
||||
})
|
||||
log.Infof("Loaded %d headers in %v", numLoaded,
|
||||
log.Infof("Loaded %d headers in %s", numLoaded,
|
||||
time.Since(startTime))
|
||||
return nil
|
||||
})
|
||||
@ -85,7 +85,7 @@ func (cmd *headersCmd) Execute(args []string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Infof("Loaded %d headers in %v", len(hdrs),
|
||||
log.Infof("Loaded %d headers in %s", len(hdrs),
|
||||
time.Since(startTime))
|
||||
return nil
|
||||
})
|
||||
|
@ -241,7 +241,7 @@ func (s *blockStore) openWriteFile(fileNum uint32) (filer, error) {
|
||||
filePath := blockFilePath(s.basePath, fileNum)
|
||||
file, err := os.OpenFile(filePath, os.O_RDWR|os.O_CREATE, 0666)
|
||||
if err != nil {
|
||||
str := fmt.Sprintf("failed to open file %q: %v", filePath, err)
|
||||
str := fmt.Sprintf("failed to open file %q: %s", filePath, err)
|
||||
return nil, makeDbErr(database.ErrDriverSpecific, str, err)
|
||||
}
|
||||
|
||||
@ -387,7 +387,7 @@ func (s *blockStore) writeData(data []byte, fieldName string) error {
|
||||
wc.curOffset += uint32(n)
|
||||
if err != nil {
|
||||
str := fmt.Sprintf("failed to write %s to file %d at "+
|
||||
"offset %d: %v", fieldName, wc.curFileNum,
|
||||
"offset %d: %s", fieldName, wc.curFileNum,
|
||||
wc.curOffset-uint32(n), err)
|
||||
return makeDbErr(database.ErrDriverSpecific, str, err)
|
||||
}
|
||||
@ -525,7 +525,7 @@ func (s *blockStore) readBlock(hash *daghash.Hash, loc blockLocation) ([]byte, e
|
||||
blockFile.RUnlock()
|
||||
if err != nil {
|
||||
str := fmt.Sprintf("failed to read block %s from file %d, "+
|
||||
"offset %d: %v", hash, loc.blockFileNum, loc.fileOffset,
|
||||
"offset %d: %s", hash, loc.blockFileNum, loc.fileOffset,
|
||||
err)
|
||||
return nil, makeDbErr(database.ErrDriverSpecific, str, err)
|
||||
}
|
||||
@ -585,7 +585,7 @@ func (s *blockStore) readBlockRegion(loc blockLocation, offset, numBytes uint32)
|
||||
blockFile.RUnlock()
|
||||
if err != nil {
|
||||
str := fmt.Sprintf("failed to read region from block file %d, "+
|
||||
"offset %d, len %d: %v", loc.blockFileNum, readOffset,
|
||||
"offset %d, len %d: %s", loc.blockFileNum, readOffset,
|
||||
numBytes, err)
|
||||
return nil, makeDbErr(database.ErrDriverSpecific, str, err)
|
||||
}
|
||||
@ -615,7 +615,7 @@ func (s *blockStore) syncBlocks() error {
|
||||
|
||||
// Sync the file to disk.
|
||||
if err := wc.curFile.file.Sync(); err != nil {
|
||||
str := fmt.Sprintf("failed to sync file %d: %v", wc.curFileNum,
|
||||
str := fmt.Sprintf("failed to sync file %d: %s", wc.curFileNum,
|
||||
err)
|
||||
return makeDbErr(database.ErrDriverSpecific, str, err)
|
||||
}
|
||||
@ -683,7 +683,7 @@ func (s *blockStore) handleRollback(oldBlockFileNum, oldBlockOffset uint32) {
|
||||
for ; wc.curFileNum > oldBlockFileNum; wc.curFileNum-- {
|
||||
if err := s.deleteFileFunc(wc.curFileNum); err != nil {
|
||||
log.Warnf("ROLLBACK: Failed to delete block file "+
|
||||
"number %d: %v", wc.curFileNum, err)
|
||||
"number %d: %s", wc.curFileNum, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -694,7 +694,7 @@ func (s *blockStore) handleRollback(oldBlockFileNum, oldBlockOffset uint32) {
|
||||
obf, err := s.openWriteFileFunc(wc.curFileNum)
|
||||
if err != nil {
|
||||
wc.curFile.Unlock()
|
||||
log.Warnf("ROLLBACK: %v", err)
|
||||
log.Warnf("ROLLBACK: %s", err)
|
||||
return
|
||||
}
|
||||
wc.curFile.file = obf
|
||||
@ -703,7 +703,7 @@ func (s *blockStore) handleRollback(oldBlockFileNum, oldBlockOffset uint32) {
|
||||
// Truncate the to the provided rollback offset.
|
||||
if err := wc.curFile.file.Truncate(int64(oldBlockOffset)); err != nil {
|
||||
wc.curFile.Unlock()
|
||||
log.Warnf("ROLLBACK: Failed to truncate file %d: %v",
|
||||
log.Warnf("ROLLBACK: Failed to truncate file %d: %s",
|
||||
wc.curFileNum, err)
|
||||
return
|
||||
}
|
||||
@ -712,7 +712,7 @@ func (s *blockStore) handleRollback(oldBlockFileNum, oldBlockOffset uint32) {
|
||||
err := wc.curFile.file.Sync()
|
||||
wc.curFile.Unlock()
|
||||
if err != nil {
|
||||
log.Warnf("ROLLBACK: Failed to sync file %d: %v",
|
||||
log.Warnf("ROLLBACK: Failed to sync file %d: %s",
|
||||
wc.curFileNum, err)
|
||||
return
|
||||
}
|
||||
|
@ -640,7 +640,7 @@ func (b *bucket) CreateBucket(key []byte) (database.Bucket, error) {
|
||||
// Ensure bucket does not already exist.
|
||||
bidxKey := bucketIndexKey(b.id, key)
|
||||
if b.tx.hasKey(bidxKey) {
|
||||
str := fmt.Sprintf("bucket %v already exists", hex.EncodeToString(bidxKey))
|
||||
str := fmt.Sprintf("bucket %s already exists", hex.EncodeToString(bidxKey))
|
||||
return nil, makeDbErr(database.ErrBucketExists, str, nil)
|
||||
}
|
||||
|
||||
@ -2025,7 +2025,7 @@ func initDB(ldb *leveldb.DB) error {
|
||||
|
||||
// Write everything as a single batch.
|
||||
if err := ldb.Write(batch, nil); err != nil {
|
||||
str := fmt.Sprintf("failed to initialize metadata database: %v",
|
||||
str := fmt.Sprintf("failed to initialize metadata database: %s",
|
||||
err)
|
||||
return convertErr(str, err)
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ func registerDriver() {
|
||||
Open: openDBDriver,
|
||||
}
|
||||
if err := database.RegisterDriver(driver); err != nil {
|
||||
panic(fmt.Sprintf("Failed to regiser database driver '%s': %v",
|
||||
panic(fmt.Sprintf("Failed to regiser database driver '%s': %s",
|
||||
dbType, err))
|
||||
}
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ func reconcileDB(pdb *db, create bool) (database.DB, error) {
|
||||
str := fmt.Sprintf("metadata claims file %d, offset %d, but "+
|
||||
"block data is at file %d, offset %d", curFileNum,
|
||||
curOffset, wc.curFileNum, wc.curOffset)
|
||||
log.Warnf("***Database corruption detected***: %v", str)
|
||||
log.Warnf("***Database corruption detected***: %s", str)
|
||||
return nil, makeDbErr(database.ErrCorruption, str, nil)
|
||||
}
|
||||
|
||||
|
@ -1205,15 +1205,15 @@ func main() {
|
||||
}
|
||||
|
||||
// Display some details about the returned block.
|
||||
log.Printf("Hash: %v\n", block.Hash)
|
||||
log.Printf("Previous Block: %v\n", block.PreviousHash)
|
||||
log.Printf("Next Block: %v\n", block.NextHash)
|
||||
log.Printf("Merkle root: %v\n", block.MerkleRoot)
|
||||
log.Printf("Timestamp: %v\n", time.Unix(block.Time, 0).UTC())
|
||||
log.Printf("Confirmations: %v\n", block.Confirmations)
|
||||
log.Printf("Hash: %s\n", block.Hash)
|
||||
log.Printf("Previous Block: %s\n", block.PreviousHash)
|
||||
log.Printf("Next Block: %s\n", block.NextHash)
|
||||
log.Printf("Merkle root: %s\n", block.MerkleRoot)
|
||||
log.Printf("Timestamp: %s\n", time.Unix(block.Time, 0).UTC())
|
||||
log.Printf("Confirmations: %d\n", block.Confirmations)
|
||||
log.Printf("Difficulty: %f\n", block.Difficulty)
|
||||
log.Printf("Size (in bytes): %v\n", block.Size)
|
||||
log.Printf("Num transactions: %v\n", len(block.Tx))
|
||||
log.Printf("Size (in bytes): %d\n", block.Size)
|
||||
log.Printf("Num transactions: %d\n", len(block.Tx))
|
||||
}
|
||||
```
|
||||
|
||||
@ -1262,10 +1262,10 @@ func main() {
|
||||
// notifications.
|
||||
ntfnHandlers := btcrpcclient.NotificationHandlers{
|
||||
OnBlockConnected: func(hash *chainhash.Hash, height int32) {
|
||||
log.Printf("Block connected: %v (%d)", hash, height)
|
||||
log.Printf("Block connected: %s (%d)", hash, height)
|
||||
},
|
||||
OnBlockDisconnected: func(hash *chainhash.Hash, height int32) {
|
||||
log.Printf("Block disconnected: %v", hash, height)
|
||||
log.Printf("Block disconnected: %s (%d)", hash, height)
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ func btcdExecutablePath() (string, error) {
|
||||
btcdPkgPath := filepath.Join(rpctestDir, "..", "..", "..")
|
||||
btcdPkg, err := build.ImportDir(btcdPkgPath, build.FindOnly)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Failed to build btcd: %v", err)
|
||||
return "", fmt.Errorf("Failed to build btcd: %s", err)
|
||||
}
|
||||
|
||||
// Build btcd and output an executable in a static temp path.
|
||||
@ -64,7 +64,7 @@ func btcdExecutablePath() (string, error) {
|
||||
cmd := exec.Command("go", "build", "-o", outputPath, btcdPkg.ImportPath)
|
||||
err = cmd.Run()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Failed to build btcd: %v", err)
|
||||
return "", fmt.Errorf("Failed to build btcd: %s", err)
|
||||
}
|
||||
|
||||
// Save executable path so future calls do not recompile.
|
||||
|
@ -171,7 +171,7 @@ func (n *nodeConfig) cleanup() error {
|
||||
var err error
|
||||
for _, dir := range dirs {
|
||||
if err = os.RemoveAll(dir); err != nil {
|
||||
log.Printf("Cannot remove dir %s: %v", dir, err)
|
||||
log.Printf("Cannot remove dir %s: %s", dir, err)
|
||||
}
|
||||
}
|
||||
return err
|
||||
@ -249,7 +249,7 @@ func (n *node) stop() error {
|
||||
func (n *node) cleanup() error {
|
||||
if n.pidFile != "" {
|
||||
if err := os.Remove(n.pidFile); err != nil {
|
||||
log.Printf("unable to remove file %s: %v", n.pidFile,
|
||||
log.Printf("unable to remove file %s: %s", n.pidFile,
|
||||
err)
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ func SetLimits() error {
|
||||
return nil
|
||||
}
|
||||
if rLimit.Max < fileLimitMin {
|
||||
err = fmt.Errorf("need at least %v file descriptors",
|
||||
err = fmt.Errorf("need at least %d file descriptors",
|
||||
fileLimitMin)
|
||||
return err
|
||||
}
|
||||
|
@ -131,12 +131,12 @@ func InitLogRotator(logFile string) {
|
||||
logDir, _ := filepath.Split(logFile)
|
||||
err := os.MkdirAll(logDir, 0700)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "failed to create log directory: %v\n", err)
|
||||
fmt.Fprintf(os.Stderr, "failed to create log directory: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
r, err := rotator.New(logFile, 10*1024, false, 3)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "failed to create file rotator: %v\n", err)
|
||||
fmt.Fprintf(os.Stderr, "failed to create file rotator: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
@ -216,7 +216,7 @@ func ParseAndSetDebugLevels(debugLevel string) error {
|
||||
if !strings.Contains(debugLevel, ",") && !strings.Contains(debugLevel, "=") {
|
||||
// Validate debug log level.
|
||||
if !validLogLevel(debugLevel) {
|
||||
str := "The specified debug level [%v] is invalid"
|
||||
str := "The specified debug level [%s] is invalid"
|
||||
return fmt.Errorf(str, debugLevel)
|
||||
}
|
||||
|
||||
@ -231,7 +231,7 @@ func ParseAndSetDebugLevels(debugLevel string) error {
|
||||
for _, logLevelPair := range strings.Split(debugLevel, ",") {
|
||||
if !strings.Contains(logLevelPair, "=") {
|
||||
str := "The specified debug level contains an invalid " +
|
||||
"subsystem/level pair [%v]"
|
||||
"subsystem/level pair [%s]"
|
||||
return fmt.Errorf(str, logLevelPair)
|
||||
}
|
||||
|
||||
@ -241,14 +241,14 @@ func ParseAndSetDebugLevels(debugLevel string) error {
|
||||
|
||||
// Validate subsystem.
|
||||
if _, exists := Get(subsysID); !exists {
|
||||
str := "The specified subsystem [%v] is invalid -- " +
|
||||
"supported subsytems %v"
|
||||
return fmt.Errorf(str, subsysID, SupportedSubsystems())
|
||||
str := "The specified subsystem [%s] is invalid -- " +
|
||||
"supported subsytems %s"
|
||||
return fmt.Errorf(str, subsysID, strings.Join(SupportedSubsystems(), ", "))
|
||||
}
|
||||
|
||||
// Validate log level.
|
||||
if !validLogLevel(logLevel) {
|
||||
str := "The specified debug level [%v] is invalid"
|
||||
str := "The specified debug level [%s] is invalid"
|
||||
return fmt.Errorf(str, logLevel)
|
||||
}
|
||||
|
||||
|
@ -341,7 +341,7 @@ func (mp *TxPool) addOrphan(tx *util.Tx, tag Tag) {
|
||||
mp.orphansByPrev[txIn.PreviousOutPoint][*tx.ID()] = tx
|
||||
}
|
||||
|
||||
log.Debugf("Stored orphan transaction %v (total: %d)", tx.ID(),
|
||||
log.Debugf("Stored orphan transaction %s (total: %d)", tx.ID(),
|
||||
len(mp.orphans))
|
||||
}
|
||||
|
||||
@ -663,8 +663,8 @@ func (mp *TxPool) addTransaction(tx *util.Tx, height int32, fee uint64, parentsI
|
||||
func (mp *TxPool) checkPoolDoubleSpend(tx *util.Tx) error {
|
||||
for _, txIn := range tx.MsgTx().TxIn {
|
||||
if txR, exists := mp.outpoints[txIn.PreviousOutPoint]; exists {
|
||||
str := fmt.Sprintf("output %v already spent by "+
|
||||
"transaction %v in the memory pool",
|
||||
str := fmt.Sprintf("output %s already spent by "+
|
||||
"transaction %s in the memory pool",
|
||||
txIn.PreviousOutPoint, txR.ID())
|
||||
return txRuleError(wire.RejectDuplicate, str)
|
||||
}
|
||||
@ -727,14 +727,14 @@ func (mp *TxPool) maybeAcceptTransaction(tx *util.Tx, isNew, rateLimit, rejectDu
|
||||
if mp.isTransactionInPool(txID) || (rejectDupOrphans &&
|
||||
mp.isOrphanInPool(txID)) {
|
||||
|
||||
str := fmt.Sprintf("already have transaction %v", txID)
|
||||
str := fmt.Sprintf("already have transaction %s", txID)
|
||||
return nil, nil, txRuleError(wire.RejectDuplicate, str)
|
||||
}
|
||||
|
||||
// Don't accept the transaction if it's from an incompatible subnetwork.
|
||||
subnetworkID := mp.cfg.DAG.SubnetworkID()
|
||||
if !tx.MsgTx().IsSubnetworkCompatible(subnetworkID) {
|
||||
str := "tx %v belongs to an invalid subnetwork"
|
||||
str := fmt.Sprintf("tx %s belongs to an invalid subnetwork", tx.ID())
|
||||
return nil, nil, txRuleError(wire.RejectInvalid, str)
|
||||
}
|
||||
|
||||
@ -759,7 +759,7 @@ func (mp *TxPool) maybeAcceptTransaction(tx *util.Tx, isNew, rateLimit, rejectDu
|
||||
return nil, nil, err
|
||||
}
|
||||
if msgTx.Gas > gasLimit {
|
||||
str := fmt.Sprintf("transaction wants more gas %v, than allowed %v",
|
||||
str := fmt.Sprintf("transaction wants more gas %d, than allowed %d",
|
||||
msgTx.Gas, gasLimit)
|
||||
return nil, nil, dagRuleError(blockdag.RuleError{
|
||||
ErrorCode: blockdag.ErrInvalidGas,
|
||||
@ -769,7 +769,7 @@ func (mp *TxPool) maybeAcceptTransaction(tx *util.Tx, isNew, rateLimit, rejectDu
|
||||
|
||||
// A standalone transaction must not be a block reward transaction.
|
||||
if blockdag.IsBlockReward(tx) {
|
||||
str := fmt.Sprintf("transaction %v is an individual block reward transaction",
|
||||
str := fmt.Sprintf("transaction %s is an individual block reward transaction",
|
||||
txID)
|
||||
return nil, nil, txRuleError(wire.RejectInvalid, str)
|
||||
}
|
||||
@ -795,7 +795,7 @@ func (mp *TxPool) maybeAcceptTransaction(tx *util.Tx, isNew, rateLimit, rejectDu
|
||||
if !found {
|
||||
rejectCode = wire.RejectNonstandard
|
||||
}
|
||||
str := fmt.Sprintf("transaction %v is not standard: %v",
|
||||
str := fmt.Sprintf("transaction %s is not standard: %s",
|
||||
txID, err)
|
||||
return nil, nil, txRuleError(rejectCode, str)
|
||||
}
|
||||
@ -890,8 +890,8 @@ func (mp *TxPool) maybeAcceptTransaction(tx *util.Tx, isNew, rateLimit, rejectDu
|
||||
if !found {
|
||||
rejectCode = wire.RejectNonstandard
|
||||
}
|
||||
str := fmt.Sprintf("transaction %v has a non-standard "+
|
||||
"input: %v", txID, err)
|
||||
str := fmt.Sprintf("transaction %s has a non-standard "+
|
||||
"input: %s", txID, err)
|
||||
return nil, nil, txRuleError(rejectCode, str)
|
||||
}
|
||||
}
|
||||
@ -913,7 +913,7 @@ func (mp *TxPool) maybeAcceptTransaction(tx *util.Tx, isNew, rateLimit, rejectDu
|
||||
return nil, nil, err
|
||||
}
|
||||
if sigOpCount > mp.cfg.Policy.MaxSigOpsPerTx {
|
||||
str := fmt.Sprintf("transaction %v sigop count is too high: %d > %d",
|
||||
str := fmt.Sprintf("transaction %s sigop count is too high: %d > %d",
|
||||
txID, sigOpCount, mp.cfg.Policy.MaxSigOpsPerTx)
|
||||
return nil, nil, txRuleError(wire.RejectNonstandard, str)
|
||||
}
|
||||
@ -933,7 +933,7 @@ func (mp *TxPool) maybeAcceptTransaction(tx *util.Tx, isNew, rateLimit, rejectDu
|
||||
minFee := uint64(calcMinRequiredTxRelayFee(serializedSize,
|
||||
mp.cfg.Policy.MinRelayTxFee))
|
||||
if serializedSize >= (DefaultBlockPrioritySize-1000) && txFee < minFee {
|
||||
str := fmt.Sprintf("transaction %v has %d fees which is under "+
|
||||
str := fmt.Sprintf("transaction %s has %d fees which is under "+
|
||||
"the required amount of %d", txID, txFee,
|
||||
minFee)
|
||||
return nil, nil, txRuleError(wire.RejectInsufficientFee, str)
|
||||
@ -947,7 +947,7 @@ func (mp *TxPool) maybeAcceptTransaction(tx *util.Tx, isNew, rateLimit, rejectDu
|
||||
currentPriority := mining.CalcPriority(tx.MsgTx(), mp.mpUTXOSet,
|
||||
nextBlockHeight)
|
||||
if currentPriority <= mining.MinHighPriority {
|
||||
str := fmt.Sprintf("transaction %v has insufficient "+
|
||||
str := fmt.Sprintf("transaction %s has insufficient "+
|
||||
"priority (%g <= %g)", txID,
|
||||
currentPriority, mining.MinHighPriority)
|
||||
return nil, nil, txRuleError(wire.RejectInsufficientFee, str)
|
||||
@ -966,15 +966,15 @@ func (mp *TxPool) maybeAcceptTransaction(tx *util.Tx, isNew, rateLimit, rejectDu
|
||||
|
||||
// Are we still over the limit?
|
||||
if mp.pennyTotal >= mp.cfg.Policy.FreeTxRelayLimit*10*1000 {
|
||||
str := fmt.Sprintf("transaction %v has been rejected "+
|
||||
str := fmt.Sprintf("transaction %s has been rejected "+
|
||||
"by the rate limiter due to low fees", txID)
|
||||
return nil, nil, txRuleError(wire.RejectInsufficientFee, str)
|
||||
}
|
||||
oldTotal := mp.pennyTotal
|
||||
|
||||
mp.pennyTotal += float64(serializedSize)
|
||||
log.Tracef("rate limit: curTotal %v, nextTotal: %v, "+
|
||||
"limit %v", oldTotal, mp.pennyTotal,
|
||||
log.Tracef("rate limit: curTotal %d, nextTotal: %d, "+
|
||||
"limit %d", oldTotal, mp.pennyTotal,
|
||||
mp.cfg.Policy.FreeTxRelayLimit*10*1000)
|
||||
}
|
||||
|
||||
@ -992,7 +992,7 @@ func (mp *TxPool) maybeAcceptTransaction(tx *util.Tx, isNew, rateLimit, rejectDu
|
||||
// Add to transaction pool.
|
||||
txD := mp.addTransaction(tx, bestHeight, txFee, parentsInPool)
|
||||
|
||||
log.Debugf("Accepted transaction %v (pool size: %v)", txID,
|
||||
log.Debugf("Accepted transaction %s (pool size: %d)", txID,
|
||||
len(mp.pool))
|
||||
|
||||
return nil, txD, nil
|
||||
@ -1131,7 +1131,7 @@ func (mp *TxPool) ProcessOrphans(acceptedTx *util.Tx) []*TxDesc {
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (mp *TxPool) ProcessTransaction(tx *util.Tx, allowOrphan, rateLimit bool, tag Tag) ([]*TxDesc, error) {
|
||||
log.Tracef("Processing transaction %v", tx.ID())
|
||||
log.Tracef("Processing transaction %s", tx.ID())
|
||||
|
||||
// Protect concurrent access.
|
||||
mp.mtx.Lock()
|
||||
@ -1172,9 +1172,9 @@ func (mp *TxPool) ProcessTransaction(tx *util.Tx, allowOrphan, rateLimit bool, t
|
||||
// to the limited number of reject codes. Missing
|
||||
// inputs is assumed to mean they are already spent
|
||||
// which is not really always the case.
|
||||
str := fmt.Sprintf("orphan transaction %v references "+
|
||||
str := fmt.Sprintf("orphan transaction %s references "+
|
||||
"outputs of unknown or fully-spent "+
|
||||
"transaction %v", tx.ID(), missingParents[0])
|
||||
"transaction %s", tx.ID(), missingParents[0])
|
||||
return nil, txRuleError(wire.RejectDuplicate, str)
|
||||
}
|
||||
|
||||
|
@ -129,7 +129,7 @@ func checkPkScriptStandard(pkScript []byte, scriptClass txscript.ScriptClass) er
|
||||
numPubKeys, numSigs, err := txscript.CalcMultiSigStats(pkScript)
|
||||
if err != nil {
|
||||
str := fmt.Sprintf("multi-signature script parse "+
|
||||
"failure: %v", err)
|
||||
"failure: %s", err)
|
||||
return txRuleError(wire.RejectNonstandard, str)
|
||||
}
|
||||
|
||||
@ -270,8 +270,8 @@ func checkTransactionStandard(tx *util.Tx, height int32,
|
||||
// attacks.
|
||||
serializedLen := msgTx.SerializeSize()
|
||||
if serializedLen > MaxStandardTxSize {
|
||||
str := fmt.Sprintf("transaction size of %v is larger than max "+
|
||||
"allowed size of %v", serializedLen, MaxStandardTxSize)
|
||||
str := fmt.Sprintf("transaction size of %d is larger than max "+
|
||||
"allowed size of %d", serializedLen, MaxStandardTxSize)
|
||||
return txRuleError(wire.RejectNonstandard, str)
|
||||
}
|
||||
|
||||
@ -292,7 +292,7 @@ func checkTransactionStandard(tx *util.Tx, height int32,
|
||||
// opcodes which push data onto the stack.
|
||||
isPushOnly, err := txscript.IsPushOnlyScript(txIn.SignatureScript)
|
||||
if err != nil {
|
||||
str := fmt.Sprintf("transaction input %d: IsPushOnlyScript: %v", i, err)
|
||||
str := fmt.Sprintf("transaction input %d: IsPushOnlyScript: %t. Error %s", i, isPushOnly, err)
|
||||
return txRuleError(wire.RejectNonstandard, str)
|
||||
}
|
||||
if !isPushOnly {
|
||||
@ -316,7 +316,7 @@ func checkTransactionStandard(tx *util.Tx, height int32,
|
||||
if rejCode, found := extractRejectCode(err); found {
|
||||
rejectCode = rejCode
|
||||
}
|
||||
str := fmt.Sprintf("transaction output %d: %v", i, err)
|
||||
str := fmt.Sprintf("transaction output %d: %s", i, err)
|
||||
return txRuleError(rejectCode, str)
|
||||
}
|
||||
|
||||
|
@ -172,11 +172,11 @@ func (m *CPUMiner) submitBlock(block *util.Block) bool {
|
||||
// so log that error as an internal error.
|
||||
if _, ok := err.(blockdag.RuleError); !ok {
|
||||
log.Errorf("Unexpected error while processing "+
|
||||
"block submitted via CPU miner: %v", err)
|
||||
"block submitted via CPU miner: %s", err)
|
||||
return false
|
||||
}
|
||||
|
||||
log.Debugf("Block submitted via CPU miner rejected: %v", err)
|
||||
log.Debugf("Block submitted via CPU miner rejected: %s", err)
|
||||
return false
|
||||
}
|
||||
if isOrphan {
|
||||
@ -187,7 +187,7 @@ func (m *CPUMiner) submitBlock(block *util.Block) bool {
|
||||
// The block was accepted.
|
||||
coinbaseTx := block.MsgBlock().Transactions[0].TxOut[0]
|
||||
log.Infof("Block submitted via CPU miner accepted (hash %s, "+
|
||||
"amount %v)", block.Hash(), util.Amount(coinbaseTx.Value))
|
||||
"amount %d)", block.Hash(), util.Amount(coinbaseTx.Value))
|
||||
return true
|
||||
}
|
||||
|
||||
@ -216,7 +216,7 @@ func (m *CPUMiner) solveBlock(msgBlock *wire.MsgBlock, blockHeight int32,
|
||||
extraNonce, err := wire.RandomUint64()
|
||||
if err != nil {
|
||||
log.Errorf("Unexpected error while generating random "+
|
||||
"extra nonce offset: %v", err)
|
||||
"extra nonce offset: %s", err)
|
||||
}
|
||||
|
||||
// Update the extra nonce in the block template with the
|
||||
@ -332,7 +332,7 @@ out:
|
||||
m.submitBlockLock.Unlock()
|
||||
if err != nil {
|
||||
errStr := fmt.Sprintf("Failed to create new block "+
|
||||
"template: %v", err)
|
||||
"template: %s", err)
|
||||
log.Errorf(errStr)
|
||||
continue
|
||||
}
|
||||
@ -586,7 +586,7 @@ func (m *CPUMiner) GenerateNBlocks(n uint32) ([]*daghash.Hash, error) {
|
||||
m.submitBlockLock.Unlock()
|
||||
if err != nil {
|
||||
errStr := fmt.Sprintf("Failed to create new block "+
|
||||
"template: %v", err)
|
||||
"template: %s", err)
|
||||
log.Errorf(errStr)
|
||||
continue
|
||||
}
|
||||
|
@ -502,12 +502,12 @@ func (g *BlkTmplGenerator) NewBlockTemplate(payToAddress util.Address) (*BlockTe
|
||||
}
|
||||
gasLimit, err := g.dag.SubnetworkStore.GasLimit(&subnetworkID)
|
||||
if err != nil {
|
||||
log.Errorf("Cannot get GAS limit for subnetwork %v", subnetworkID)
|
||||
log.Errorf("Cannot get GAS limit for subnetwork %s", subnetworkID)
|
||||
continue
|
||||
}
|
||||
txGas := tx.MsgTx().Gas
|
||||
if gasLimit-gasUsage < txGas {
|
||||
log.Tracef("Transaction %v (GAS=%v) ignored because gas overusage (GASUsage=%v) in subnetwork %v (GASLimit=%v)",
|
||||
log.Tracef("Transaction %s (GAS=%d) ignored because gas overusage (GASUsage=%d) in subnetwork %s (GASLimit=%d)",
|
||||
tx.MsgTx().TxID(), txGas, gasUsage, subnetworkID, gasLimit)
|
||||
continue
|
||||
}
|
||||
@ -538,7 +538,7 @@ func (g *BlkTmplGenerator) NewBlockTemplate(payToAddress util.Address) (*BlockTe
|
||||
g.dag.UTXOSet())
|
||||
if err != nil {
|
||||
log.Tracef("Skipping tx %s due to error in "+
|
||||
"GetSigOpCost: %v", tx.ID(), err)
|
||||
"GetSigOpCost: %s", tx.ID(), err)
|
||||
continue
|
||||
}
|
||||
numSigOps += int64(numP2SHSigOps)
|
||||
@ -598,14 +598,14 @@ func (g *BlkTmplGenerator) NewBlockTemplate(payToAddress util.Address) (*BlockTe
|
||||
g.dag.UTXOSet(), g.dagParams)
|
||||
if err != nil {
|
||||
log.Tracef("Skipping tx %s due to error in "+
|
||||
"CheckTransactionInputs: %v", tx.ID(), err)
|
||||
"CheckTransactionInputs: %s", tx.ID(), err)
|
||||
continue
|
||||
}
|
||||
err = blockdag.ValidateTransactionScripts(tx, g.dag.UTXOSet(),
|
||||
txscript.StandardVerifyFlags, g.sigCache)
|
||||
if err != nil {
|
||||
log.Tracef("Skipping tx %s due to error in "+
|
||||
"ValidateTransactionScripts: %v", tx.ID(), err)
|
||||
"ValidateTransactionScripts: %s", tx.ID(), err)
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,7 @@ func PrepareBlockForTest(dag *blockdag.BlockDAG, params *dagconfig.Params, paren
|
||||
}
|
||||
if !found {
|
||||
if !forceTransactions {
|
||||
return nil, fmt.Errorf("tx %v wasn't found in the block", tx.TxHash())
|
||||
return nil, fmt.Errorf("tx %s wasn't found in the block", tx.TxHash())
|
||||
}
|
||||
txsToAdd = append(txsToAdd, tx)
|
||||
}
|
||||
|
@ -256,11 +256,11 @@ func (sm *SyncManager) startSync() {
|
||||
locator, err := sm.dag.LatestBlockLocator()
|
||||
if err != nil {
|
||||
log.Errorf("Failed to get block locator for the "+
|
||||
"latest block: %v", err)
|
||||
"latest block: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Infof("Syncing to block height %d from peer %v",
|
||||
log.Infof("Syncing to block height %d from peer %s",
|
||||
bestPeer.LastBlock(), bestPeer.Addr())
|
||||
|
||||
// When the current height is less than a known checkpoint we
|
||||
@ -408,7 +408,7 @@ func (sm *SyncManager) handleTxMsg(tmsg *txMsg) {
|
||||
// If we didn't ask for this transaction then the peer is misbehaving.
|
||||
txID := tmsg.tx.ID()
|
||||
if _, exists = state.requestedTxns[*txID]; !exists {
|
||||
log.Warnf("Got unrequested transaction %v from %s -- "+
|
||||
log.Warnf("Got unrequested transaction %s from %s -- "+
|
||||
"disconnecting", txID, peer.Addr())
|
||||
peer.Disconnect()
|
||||
return
|
||||
@ -419,7 +419,7 @@ func (sm *SyncManager) handleTxMsg(tmsg *txMsg) {
|
||||
// rejected, the transaction was unsolicited.
|
||||
if _, exists = sm.rejectedTxns[*txID]; exists {
|
||||
log.Debugf("Ignoring unsolicited previously rejected "+
|
||||
"transaction %v from %s", txID, peer)
|
||||
"transaction %s from %s", txID, peer)
|
||||
return
|
||||
}
|
||||
|
||||
@ -446,10 +446,10 @@ func (sm *SyncManager) handleTxMsg(tmsg *txMsg) {
|
||||
// so log it as such. Otherwise, something really did go wrong,
|
||||
// so log it as an actual error.
|
||||
if _, ok := err.(mempool.RuleError); ok {
|
||||
log.Debugf("Rejected transaction %v from %s: %v",
|
||||
log.Debugf("Rejected transaction %s from %s: %s",
|
||||
txID, peer, err)
|
||||
} else {
|
||||
log.Errorf("Failed to process transaction %v: %v",
|
||||
log.Errorf("Failed to process transaction %s: %s",
|
||||
txID, err)
|
||||
}
|
||||
|
||||
@ -502,7 +502,7 @@ func (sm *SyncManager) handleBlockMsg(bmsg *blockMsg) {
|
||||
// mode in this case so the chain code is actually fed the
|
||||
// duplicate blocks.
|
||||
if sm.chainParams != &dagconfig.RegressionNetParams {
|
||||
log.Warnf("Got unrequested block %v from %s -- "+
|
||||
log.Warnf("Got unrequested block %s from %s -- "+
|
||||
"disconnecting", blockHash, peer.Addr())
|
||||
peer.Disconnect()
|
||||
return
|
||||
@ -547,10 +547,10 @@ func (sm *SyncManager) handleBlockMsg(bmsg *blockMsg) {
|
||||
// it as such. Otherwise, something really did go wrong, so log
|
||||
// it as an actual error.
|
||||
if _, ok := err.(blockdag.RuleError); ok {
|
||||
log.Infof("Rejected block %v from %s: %v", blockHash,
|
||||
log.Infof("Rejected block %s from %s: %s", blockHash,
|
||||
peer, err)
|
||||
} else {
|
||||
log.Errorf("Failed to process block %v: %v",
|
||||
log.Errorf("Failed to process block %s: %s",
|
||||
blockHash, err)
|
||||
}
|
||||
if dbErr, ok := err.(database.Error); ok && dbErr.ErrorCode ==
|
||||
@ -588,9 +588,9 @@ func (sm *SyncManager) handleBlockMsg(bmsg *blockMsg) {
|
||||
cbHeight, err := blockdag.ExtractCoinbaseHeight(coinbaseTx)
|
||||
if err != nil {
|
||||
log.Warnf("Unable to extract height from "+
|
||||
"coinbase tx: %v", err)
|
||||
"coinbase tx: %s", err)
|
||||
} else {
|
||||
log.Debugf("Extracted height of %v from "+
|
||||
log.Debugf("Extracted height of %d from "+
|
||||
"orphan block", cbHeight)
|
||||
heightUpdate = cbHeight
|
||||
blkHashUpdate = blockHash
|
||||
@ -600,7 +600,7 @@ func (sm *SyncManager) handleBlockMsg(bmsg *blockMsg) {
|
||||
locator, err := sm.dag.LatestBlockLocator()
|
||||
if err != nil {
|
||||
log.Warnf("Failed to get block locator for the "+
|
||||
"latest block: %v", err)
|
||||
"latest block: %s", err)
|
||||
} else {
|
||||
peer.PushGetBlocksMsg(locator, orphanRoot)
|
||||
}
|
||||
@ -659,7 +659,7 @@ func (sm *SyncManager) handleBlockMsg(bmsg *blockMsg) {
|
||||
err := peer.PushGetHeadersMsg(locator, sm.nextCheckpoint.Hash)
|
||||
if err != nil {
|
||||
log.Warnf("Failed to send getheaders message to "+
|
||||
"peer %s: %v", peer.Addr(), err)
|
||||
"peer %s: %s", peer.Addr(), err)
|
||||
return
|
||||
}
|
||||
log.Infof("Downloading headers for blocks %d to %d from "+
|
||||
@ -677,7 +677,7 @@ func (sm *SyncManager) handleBlockMsg(bmsg *blockMsg) {
|
||||
locator := blockdag.BlockLocator([]*daghash.Hash{blockHash})
|
||||
err = peer.PushGetBlocksMsg(locator, &daghash.ZeroHash)
|
||||
if err != nil {
|
||||
log.Warnf("Failed to send getblocks message to peer %s: %v",
|
||||
log.Warnf("Failed to send getblocks message to peer %s: %s",
|
||||
peer.Addr(), err)
|
||||
return
|
||||
}
|
||||
@ -709,7 +709,7 @@ func (sm *SyncManager) fetchHeaderBlocks() {
|
||||
if err != nil {
|
||||
log.Warnf("Unexpected failure when checking for "+
|
||||
"existing inventory during header block "+
|
||||
"fetch: %v", err)
|
||||
"fetch: %s", err)
|
||||
}
|
||||
if !haveInv {
|
||||
syncPeerState := sm.peerStates[sm.syncPeer]
|
||||
@ -819,7 +819,7 @@ func (sm *SyncManager) handleHeadersMsg(hmsg *headersMsg) {
|
||||
// the next header links properly, it must be removed before
|
||||
// fetching the blocks.
|
||||
sm.headerList.Remove(sm.headerList.Front())
|
||||
log.Infof("Received %v block headers: Fetching blocks",
|
||||
log.Infof("Received %d block headers: Fetching blocks",
|
||||
sm.headerList.Len())
|
||||
sm.progressLogger.SetLastLogTime(time.Now())
|
||||
sm.fetchHeaderBlocks()
|
||||
@ -833,7 +833,7 @@ func (sm *SyncManager) handleHeadersMsg(hmsg *headersMsg) {
|
||||
err := peer.PushGetHeadersMsg(locator, sm.nextCheckpoint.Hash)
|
||||
if err != nil {
|
||||
log.Warnf("Failed to send getheaders message to "+
|
||||
"peer %s: %v", peer.Addr(), err)
|
||||
"peer %s: %s", peer.Addr(), err)
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -951,7 +951,7 @@ func (sm *SyncManager) handleInvMsg(imsg *invMsg) {
|
||||
if err != nil {
|
||||
log.Warnf("Unexpected failure when checking for "+
|
||||
"existing inventory during inv message "+
|
||||
"processing: %v", err)
|
||||
"processing: %s", err)
|
||||
continue
|
||||
}
|
||||
if !haveInv {
|
||||
@ -988,7 +988,7 @@ func (sm *SyncManager) handleInvMsg(imsg *invMsg) {
|
||||
if err != nil {
|
||||
log.Errorf("PEER: Failed to get block "+
|
||||
"locator for the latest block: "+
|
||||
"%v", err)
|
||||
"%s", err)
|
||||
continue
|
||||
}
|
||||
peer.PushGetBlocksMsg(locator, orphanRoot)
|
||||
@ -1203,7 +1203,7 @@ func (sm *SyncManager) handleBlockDAGNotification(notification *blockdag.Notific
|
||||
err := sm.txMemPool.HandleNewBlock(block, ch)
|
||||
close(ch)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("HandleNewBlock failed to handle block %v", block.Hash()))
|
||||
panic(fmt.Sprintf("HandleNewBlock failed to handle block %s", block.Hash()))
|
||||
}
|
||||
}()
|
||||
for msg := range ch {
|
||||
|
@ -32,7 +32,7 @@ func init() {
|
||||
log, _ = logger.Get(logger.SubsystemTags.PEER)
|
||||
}
|
||||
|
||||
// LogClosure is a closure that can be printed with %v to be used to
|
||||
// LogClosure is a closure that can be printed with %s to be used to
|
||||
// generate expensive-to-create data for a detailed log level and avoid doing
|
||||
// the work if the data isn't printed.
|
||||
type logClosure func() string
|
||||
@ -183,10 +183,10 @@ func messageSummary(msg wire.Message) string {
|
||||
// logging.
|
||||
rejCommand := sanitizeString(msg.Cmd, wire.CommandSize)
|
||||
rejReason := sanitizeString(msg.Reason, maxRejectReasonLen)
|
||||
summary := fmt.Sprintf("cmd %v, code %v, reason %v", rejCommand,
|
||||
summary := fmt.Sprintf("cmd %s, code %s, reason %s", rejCommand,
|
||||
msg.Code, rejReason)
|
||||
if rejCommand == wire.CmdBlock || rejCommand == wire.CmdTx {
|
||||
summary += fmt.Sprintf(", hash %v", msg.Hash)
|
||||
summary += fmt.Sprintf(", hash %s", msg.Hash)
|
||||
}
|
||||
return summary
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ func (m *mruInventoryMap) String() string {
|
||||
curEntry := 0
|
||||
buf := bytes.NewBufferString("[")
|
||||
for iv := range m.invMap {
|
||||
buf.WriteString(fmt.Sprintf("%v", iv))
|
||||
buf.WriteString(iv.String())
|
||||
if curEntry < lastEntryNum {
|
||||
buf.WriteString(", ")
|
||||
}
|
||||
|
@ -135,8 +135,8 @@ func TestMruInventoryMapStringer(t *testing.T) {
|
||||
// Ensure the stringer gives the expected result. Since map iteration
|
||||
// is not ordered, either entry could be first, so account for both
|
||||
// cases.
|
||||
wantStr1 := fmt.Sprintf("<%d>[%s, %s]", 2, *iv1, *iv2)
|
||||
wantStr2 := fmt.Sprintf("<%d>[%s, %s]", 2, *iv2, *iv1)
|
||||
wantStr1 := fmt.Sprintf("<%d>[%s, %s]", 2, iv1, iv2)
|
||||
wantStr2 := fmt.Sprintf("<%d>[%s, %s]", 2, iv2, iv1)
|
||||
gotStr := mruInvMap.String()
|
||||
if gotStr != wantStr1 && gotStr != wantStr2 {
|
||||
t.Fatalf("unexpected string representation - got %q, want %q "+
|
||||
|
46
peer/peer.go
46
peer/peer.go
@ -485,7 +485,7 @@ func (p *Peer) String() string {
|
||||
// This function is safe for concurrent access.
|
||||
func (p *Peer) UpdateLastBlockHeight(newHeight int32) {
|
||||
p.statsMtx.Lock()
|
||||
log.Tracef("Updating last block height of peer %v from %v to %v",
|
||||
log.Tracef("Updating last block height of peer %s from %s to %s",
|
||||
p.addr, p.lastBlock, newHeight)
|
||||
p.lastBlock = newHeight
|
||||
p.statsMtx.Unlock()
|
||||
@ -496,7 +496,7 @@ func (p *Peer) UpdateLastBlockHeight(newHeight int32) {
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (p *Peer) UpdateLastAnnouncedBlock(blkHash *daghash.Hash) {
|
||||
log.Tracef("Updating last blk for peer %v, %v", p.addr, blkHash)
|
||||
log.Tracef("Updating last blk for peer %s, %s", p.addr, blkHash)
|
||||
|
||||
p.statsMtx.Lock()
|
||||
p.lastAnnouncedBlock = blkHash
|
||||
@ -923,7 +923,7 @@ func (p *Peer) PushGetBlocksMsg(locator blockdag.BlockLocator, stopHash *daghash
|
||||
|
||||
if isDuplicate {
|
||||
log.Tracef("Filtering duplicate [getblocks] with begin "+
|
||||
"hash %v, stop hash %v", beginHash, stopHash)
|
||||
"hash %s, stop hash %s", beginHash, stopHash)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -966,7 +966,7 @@ func (p *Peer) PushGetHeadersMsg(locator blockdag.BlockLocator, stopHash *daghas
|
||||
p.prevGetHdrsMtx.Unlock()
|
||||
|
||||
if isDuplicate {
|
||||
log.Tracef("Filtering duplicate [getheaders] with begin hash %v",
|
||||
log.Tracef("Filtering duplicate [getheaders] with begin hash %s",
|
||||
beginHash)
|
||||
return nil
|
||||
}
|
||||
@ -1002,7 +1002,7 @@ func (p *Peer) PushRejectMsg(command string, code wire.RejectCode, reason string
|
||||
if command == wire.CmdTx || command == wire.CmdBlock {
|
||||
if hash == nil {
|
||||
log.Warnf("Sending a reject message for command "+
|
||||
"type %v which should have specified a hash "+
|
||||
"type %s which should have specified a hash "+
|
||||
"but does not", command)
|
||||
hash = &daghash.ZeroHash
|
||||
}
|
||||
@ -1126,19 +1126,19 @@ func (p *Peer) readMessage() (wire.Message, []byte, error) {
|
||||
|
||||
// Use closures to log expensive operations so they are only run when
|
||||
// the logging level requires it.
|
||||
log.Debugf("%v", newLogClosure(func() string {
|
||||
log.Debugf("%s", newLogClosure(func() string {
|
||||
// Debug summary of message.
|
||||
summary := messageSummary(msg)
|
||||
if len(summary) > 0 {
|
||||
summary = " (" + summary + ")"
|
||||
}
|
||||
return fmt.Sprintf("Received %v%s from %s",
|
||||
return fmt.Sprintf("Received %s%s from %s",
|
||||
msg.Command(), summary, p)
|
||||
}))
|
||||
log.Tracef("%v", newLogClosure(func() string {
|
||||
log.Tracef("%s", newLogClosure(func() string {
|
||||
return spew.Sdump(msg)
|
||||
}))
|
||||
log.Tracef("%v", newLogClosure(func() string {
|
||||
log.Tracef("%s", newLogClosure(func() string {
|
||||
return spew.Sdump(buf)
|
||||
}))
|
||||
|
||||
@ -1154,19 +1154,19 @@ func (p *Peer) writeMessage(msg wire.Message) error {
|
||||
|
||||
// Use closures to log expensive operations so they are only run when
|
||||
// the logging level requires it.
|
||||
log.Debugf("%v", newLogClosure(func() string {
|
||||
log.Debugf("%s", newLogClosure(func() string {
|
||||
// Debug summary of message.
|
||||
summary := messageSummary(msg)
|
||||
if len(summary) > 0 {
|
||||
summary = " (" + summary + ")"
|
||||
}
|
||||
return fmt.Sprintf("Sending %v%s to %s", msg.Command(),
|
||||
return fmt.Sprintf("Sending %s%s to %s", msg.Command(),
|
||||
summary, p)
|
||||
}))
|
||||
log.Tracef("%v", newLogClosure(func() string {
|
||||
log.Tracef("%s", newLogClosure(func() string {
|
||||
return spew.Sdump(msg)
|
||||
}))
|
||||
log.Tracef("%v", newLogClosure(func() string {
|
||||
log.Tracef("%s", newLogClosure(func() string {
|
||||
var buf bytes.Buffer
|
||||
_, err := wire.WriteMessageN(&buf, msg, p.ProtocolVersion(),
|
||||
p.cfg.DAGParams.Net)
|
||||
@ -1362,7 +1362,7 @@ out:
|
||||
handlerActive = false
|
||||
|
||||
default:
|
||||
log.Warnf("Unsupported message command %v",
|
||||
log.Warnf("Unsupported message command %s",
|
||||
msg.command)
|
||||
}
|
||||
|
||||
@ -1446,7 +1446,7 @@ out:
|
||||
// disconnect the peer when we're in regression test mode and the
|
||||
// error is one of the allowed errors.
|
||||
if p.isAllowedReadError(err) {
|
||||
log.Errorf("Allowed test error from %s: %v", p, err)
|
||||
log.Errorf("Allowed test error from %s: %s", p, err)
|
||||
idleTimer.Reset(idleTimeout)
|
||||
continue
|
||||
}
|
||||
@ -1455,7 +1455,7 @@ out:
|
||||
// local peer is not forcibly disconnecting and the
|
||||
// remote peer has not disconnected.
|
||||
if p.shouldHandleReadError(err) {
|
||||
errMsg := fmt.Sprintf("Can't read message from %s: %v", p, err)
|
||||
errMsg := fmt.Sprintf("Can't read message from %s: %s", p, err)
|
||||
if err != io.ErrUnexpectedEOF {
|
||||
log.Errorf(errMsg)
|
||||
}
|
||||
@ -1489,7 +1489,7 @@ out:
|
||||
// No read lock is necessary because verAckReceived is not written
|
||||
// to in any other goroutine.
|
||||
if p.verAckReceived {
|
||||
log.Infof("Already received 'verack' from peer %v -- "+
|
||||
log.Infof("Already received 'verack' from peer %s -- "+
|
||||
"disconnecting", p)
|
||||
break out
|
||||
}
|
||||
@ -1637,8 +1637,8 @@ out:
|
||||
}
|
||||
|
||||
default:
|
||||
log.Debugf("Received unhandled message of type %v "+
|
||||
"from %v", rmsg.Command(), p)
|
||||
log.Debugf("Received unhandled message of type %s "+
|
||||
"from %s", rmsg.Command(), p)
|
||||
}
|
||||
p.stallControl <- stallControlMsg{sccHandlerDone, rmsg}
|
||||
|
||||
@ -1836,7 +1836,7 @@ out:
|
||||
p.Disconnect()
|
||||
if p.shouldLogWriteError(err) {
|
||||
log.Errorf("Failed to send message to "+
|
||||
"%s: %v", p, err)
|
||||
"%s: %s", p, err)
|
||||
}
|
||||
if msg.doneChan != nil {
|
||||
msg.doneChan <- struct{}{}
|
||||
@ -1893,7 +1893,7 @@ out:
|
||||
case <-pingTicker.C:
|
||||
nonce, err := wire.RandomUint64()
|
||||
if err != nil {
|
||||
log.Errorf("Not sending ping to %s: %v", p, err)
|
||||
log.Errorf("Not sending ping to %s: %s", p, err)
|
||||
continue
|
||||
}
|
||||
p.QueueMessage(wire.NewMsgPing(nonce), nil)
|
||||
@ -1963,7 +1963,7 @@ func (p *Peer) AssociateConnection(conn net.Conn) {
|
||||
// and no point recomputing.
|
||||
na, err := newNetAddress(p.conn.RemoteAddr(), p.services)
|
||||
if err != nil {
|
||||
log.Errorf("Cannot create remote net address: %v", err)
|
||||
log.Errorf("Cannot create remote net address: %s", err)
|
||||
p.Disconnect()
|
||||
return
|
||||
}
|
||||
@ -1972,7 +1972,7 @@ func (p *Peer) AssociateConnection(conn net.Conn) {
|
||||
|
||||
go func() {
|
||||
if err := p.start(); err != nil {
|
||||
log.Debugf("Cannot start peer %v: %v", p, err)
|
||||
log.Debugf("Cannot start peer %s: %s", p, err)
|
||||
p.Disconnect()
|
||||
}
|
||||
}()
|
||||
|
@ -22,11 +22,11 @@ func main() {
|
||||
// NotificationHandlers type for more details about each handler.
|
||||
ntfnHandlers := rpcclient.NotificationHandlers{
|
||||
OnFilteredBlockConnected: func(height int32, header *wire.BlockHeader, txns []*util.Tx) {
|
||||
log.Printf("Block connected: %v (%d) %v",
|
||||
log.Printf("Block connected: %s (%d) %s",
|
||||
header.BlockHash(), height, header.Timestamp)
|
||||
},
|
||||
OnFilteredBlockDisconnected: func(height int32, header *wire.BlockHeader) {
|
||||
log.Printf("Block disconnected: %v (%d) %v",
|
||||
log.Printf("Block disconnected: %s (%d) %s",
|
||||
header.BlockHash(), height, header.Timestamp)
|
||||
},
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ func main() {
|
||||
// NotificationHandlers type for more details about each handler.
|
||||
ntfnHandlers := rpcclient.NotificationHandlers{
|
||||
OnAccountBalance: func(account string, balance util.Amount, confirmed bool) {
|
||||
log.Printf("New balance for account %s: %v", account,
|
||||
log.Printf("New balance for account %s: %s", account,
|
||||
balance)
|
||||
},
|
||||
}
|
||||
@ -53,7 +53,7 @@ func main() {
|
||||
}
|
||||
log.Printf("Num unspent outputs (utxos): %d", len(unspent))
|
||||
if len(unspent) > 0 {
|
||||
log.Printf("First utxo:\n%v", spew.Sdump(unspent[0]))
|
||||
log.Printf("First utxo:\n%s", spew.Sdump(unspent[0]))
|
||||
}
|
||||
|
||||
// For this example gracefully shutdown the client after 10 seconds.
|
||||
|
@ -314,7 +314,7 @@ func (c *Client) handleMessage(msg []byte) {
|
||||
in.rawNotification = new(rawNotification)
|
||||
err := json.Unmarshal(msg, &in)
|
||||
if err != nil {
|
||||
log.Warnf("Remote server sent invalid message: %v", err)
|
||||
log.Warnf("Remote server sent invalid message: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -414,7 +414,7 @@ out:
|
||||
// Log the error if it's not due to disconnecting.
|
||||
if c.shouldLogReadError(err) {
|
||||
log.Errorf("Websocket receive error from "+
|
||||
"%s: %v", c.config.Host, err)
|
||||
"%s: %s", c.config.Host, err)
|
||||
}
|
||||
break out
|
||||
}
|
||||
@ -515,7 +515,7 @@ func (c *Client) reregisterNtfns() error {
|
||||
|
||||
// Reregister notifynewtransactions if needed.
|
||||
if stateCopy.notifyNewTx || stateCopy.notifyNewTxVerbose {
|
||||
log.Debugf("Reregistering [notifynewtransactions] (verbose=%v)",
|
||||
log.Debugf("Reregistering [notifynewtransactions] (verbose=%t)",
|
||||
stateCopy.notifyNewTxVerbose)
|
||||
err := c.NotifyNewTransactions(stateCopy.notifyNewTxVerbose, stateCopy.notifyNewTxSubnetworkID)
|
||||
if err != nil {
|
||||
@ -567,7 +567,7 @@ func (c *Client) resendRequests() {
|
||||
// Set the notification state back up. If anything goes wrong,
|
||||
// disconnect the client.
|
||||
if err := c.reregisterNtfns(); err != nil {
|
||||
log.Warnf("Unable to re-establish notification state: %v", err)
|
||||
log.Warnf("Unable to re-establish notification state: %s", err)
|
||||
c.Disconnect()
|
||||
return
|
||||
}
|
||||
@ -639,7 +639,7 @@ out:
|
||||
wsConn, err := dial(c.config)
|
||||
if err != nil {
|
||||
c.retryCount++
|
||||
log.Infof("Failed to connect to %s: %v",
|
||||
log.Infof("Failed to connect to %s: %s",
|
||||
c.config.Host, err)
|
||||
|
||||
// Scale the retry interval by the number of
|
||||
@ -702,7 +702,7 @@ func (c *Client) handleSendPostMessage(details *sendPostDetails) {
|
||||
respBytes, err := ioutil.ReadAll(httpResponse.Body)
|
||||
httpResponse.Body.Close()
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error reading json reply: %v", err)
|
||||
err = fmt.Errorf("error reading json reply: %s", err)
|
||||
jReq.responseChan <- &response{err: err}
|
||||
return
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ func UseLogger(logger btclog.Logger) {
|
||||
log = logger
|
||||
}
|
||||
|
||||
// LogClosure is a closure that can be printed with %v to be used to
|
||||
// LogClosure is a closure that can be printed with %s to be used to
|
||||
// generate expensive-to-create data for a detailed log level and avoid doing
|
||||
// the work if the data isn't printed.
|
||||
type logClosure func() string
|
||||
|
@ -231,7 +231,7 @@ func (c *Client) handleNotification(ntfn *rawNotification) {
|
||||
blockHash, blockHeight, blockTime, err := parseChainNtfnParams(ntfn.Params)
|
||||
if err != nil {
|
||||
log.Warnf("Received invalid block connected "+
|
||||
"notification: %v", err)
|
||||
"notification: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -249,7 +249,7 @@ func (c *Client) handleNotification(ntfn *rawNotification) {
|
||||
parseFilteredBlockConnectedParams(ntfn.Params)
|
||||
if err != nil {
|
||||
log.Warnf("Received invalid filtered block "+
|
||||
"connected notification: %v", err)
|
||||
"connected notification: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -267,7 +267,7 @@ func (c *Client) handleNotification(ntfn *rawNotification) {
|
||||
blockHash, blockHeight, blockTime, err := parseChainNtfnParams(ntfn.Params)
|
||||
if err != nil {
|
||||
log.Warnf("Received invalid block connected "+
|
||||
"notification: %v", err)
|
||||
"notification: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -285,7 +285,7 @@ func (c *Client) handleNotification(ntfn *rawNotification) {
|
||||
parseFilteredBlockDisconnectedParams(ntfn.Params)
|
||||
if err != nil {
|
||||
log.Warnf("Received invalid filtered block "+
|
||||
"disconnected notification: %v", err)
|
||||
"disconnected notification: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -302,7 +302,7 @@ func (c *Client) handleNotification(ntfn *rawNotification) {
|
||||
|
||||
tx, block, err := parseChainTxNtfnParams(ntfn.Params)
|
||||
if err != nil {
|
||||
log.Warnf("Received invalid recvtx notification: %v",
|
||||
log.Warnf("Received invalid recvtx notification: %s",
|
||||
err)
|
||||
return
|
||||
}
|
||||
@ -320,7 +320,7 @@ func (c *Client) handleNotification(ntfn *rawNotification) {
|
||||
tx, block, err := parseChainTxNtfnParams(ntfn.Params)
|
||||
if err != nil {
|
||||
log.Warnf("Received invalid redeemingtx "+
|
||||
"notification: %v", err)
|
||||
"notification: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -337,7 +337,7 @@ func (c *Client) handleNotification(ntfn *rawNotification) {
|
||||
transaction, err := parseRelevantTxAcceptedParams(ntfn.Params)
|
||||
if err != nil {
|
||||
log.Warnf("Received invalid relevanttxaccepted "+
|
||||
"notification: %v", err)
|
||||
"notification: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -354,7 +354,7 @@ func (c *Client) handleNotification(ntfn *rawNotification) {
|
||||
hash, height, blkTime, err := parseRescanProgressParams(ntfn.Params)
|
||||
if err != nil {
|
||||
log.Warnf("Received invalid rescanfinished "+
|
||||
"notification: %v", err)
|
||||
"notification: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -371,7 +371,7 @@ func (c *Client) handleNotification(ntfn *rawNotification) {
|
||||
hash, height, blkTime, err := parseRescanProgressParams(ntfn.Params)
|
||||
if err != nil {
|
||||
log.Warnf("Received invalid rescanprogress "+
|
||||
"notification: %v", err)
|
||||
"notification: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -388,7 +388,7 @@ func (c *Client) handleNotification(ntfn *rawNotification) {
|
||||
hash, amt, err := parseTxAcceptedNtfnParams(ntfn.Params)
|
||||
if err != nil {
|
||||
log.Warnf("Received invalid tx accepted "+
|
||||
"notification: %v", err)
|
||||
"notification: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -405,7 +405,7 @@ func (c *Client) handleNotification(ntfn *rawNotification) {
|
||||
rawTx, err := parseTxAcceptedVerboseNtfnParams(ntfn.Params)
|
||||
if err != nil {
|
||||
log.Warnf("Received invalid tx accepted verbose "+
|
||||
"notification: %v", err)
|
||||
"notification: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -422,7 +422,7 @@ func (c *Client) handleNotification(ntfn *rawNotification) {
|
||||
connected, err := parseBtcdConnectedNtfnParams(ntfn.Params)
|
||||
if err != nil {
|
||||
log.Warnf("Received invalid btcd connected "+
|
||||
"notification: %v", err)
|
||||
"notification: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -439,7 +439,7 @@ func (c *Client) handleNotification(ntfn *rawNotification) {
|
||||
account, bal, conf, err := parseAccountBalanceNtfnParams(ntfn.Params)
|
||||
if err != nil {
|
||||
log.Warnf("Received invalid account balance "+
|
||||
"notification: %v", err)
|
||||
"notification: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -458,7 +458,7 @@ func (c *Client) handleNotification(ntfn *rawNotification) {
|
||||
_, locked, err := parseWalletLockStateNtfnParams(ntfn.Params)
|
||||
if err != nil {
|
||||
log.Warnf("Received invalid wallet lock state "+
|
||||
"notification: %v", err)
|
||||
"notification: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -336,7 +336,7 @@ func (sp *Peer) pushAddrMsg(addresses []*wire.NetAddress) {
|
||||
}
|
||||
known, err := sp.PushAddrMsg(addrs)
|
||||
if err != nil {
|
||||
peerLog.Errorf("Can't push address message to %s: %v", sp.Peer, err)
|
||||
peerLog.Errorf("Can't push address message to %s: %s", sp.Peer, err)
|
||||
sp.Disconnect()
|
||||
return
|
||||
}
|
||||
@ -442,7 +442,7 @@ func (sp *Peer) OnMemPool(_ *peer.Peer, msg *wire.MsgMemPool) {
|
||||
// Only allow mempool requests if the server has bloom filtering
|
||||
// enabled.
|
||||
if sp.server.services&wire.SFNodeBloom != wire.SFNodeBloom {
|
||||
peerLog.Debugf("peer %v sent mempool request with bloom "+
|
||||
peerLog.Debugf("peer %s sent mempool request with bloom "+
|
||||
"filtering disabled -- disconnecting", sp)
|
||||
sp.Disconnect()
|
||||
return
|
||||
@ -488,7 +488,7 @@ func (sp *Peer) OnMemPool(_ *peer.Peer, msg *wire.MsgMemPool) {
|
||||
// transactions don't rely on the previous one in a linear fashion like blocks.
|
||||
func (sp *Peer) OnTx(_ *peer.Peer, msg *wire.MsgTx) {
|
||||
if config.MainConfig().BlocksOnly {
|
||||
peerLog.Tracef("Ignoring tx %v from %v - blocksonly enabled",
|
||||
peerLog.Tracef("Ignoring tx %s from %s - blocksonly enabled",
|
||||
msg.TxID(), sp)
|
||||
return
|
||||
}
|
||||
@ -550,16 +550,16 @@ func (sp *Peer) OnInv(_ *peer.Peer, msg *wire.MsgInv) {
|
||||
newInv := wire.NewMsgInvSizeHint(uint(len(msg.InvList)))
|
||||
for _, invVect := range msg.InvList {
|
||||
if invVect.Type == wire.InvTypeTx {
|
||||
peerLog.Tracef("Ignoring tx %v in inv from %v -- "+
|
||||
peerLog.Tracef("Ignoring tx %s in inv from %s -- "+
|
||||
"blocksonly enabled", invVect.Hash, sp)
|
||||
peerLog.Infof("Peer %v is announcing "+
|
||||
peerLog.Infof("Peer %s is announcing "+
|
||||
"transactions -- disconnecting", sp)
|
||||
sp.Disconnect()
|
||||
return
|
||||
}
|
||||
err := newInv.AddInvVect(invVect)
|
||||
if err != nil {
|
||||
peerLog.Errorf("Failed to add inventory vector: %v", err)
|
||||
peerLog.Errorf("Failed to add inventory vector: %s", err)
|
||||
break
|
||||
}
|
||||
}
|
||||
@ -727,7 +727,7 @@ func (sp *Peer) OnGetCFilters(_ *peer.Peer, msg *wire.MsgGetCFilters) {
|
||||
hashes, err := sp.server.DAG.HeightToHashRange(int32(msg.StartHeight),
|
||||
&msg.StopHash, wire.MaxGetCFiltersReqRange)
|
||||
if err != nil {
|
||||
peerLog.Debugf("Invalid getcfilters request: %v", err)
|
||||
peerLog.Debugf("Invalid getcfilters request: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -741,13 +741,13 @@ func (sp *Peer) OnGetCFilters(_ *peer.Peer, msg *wire.MsgGetCFilters) {
|
||||
filters, err := sp.server.CfIndex.FiltersByBlockHashes(hashPtrs,
|
||||
msg.FilterType)
|
||||
if err != nil {
|
||||
peerLog.Errorf("Error retrieving cfilters: %v", err)
|
||||
peerLog.Errorf("Error retrieving cfilters: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
for i, filterBytes := range filters {
|
||||
if len(filterBytes) == 0 {
|
||||
peerLog.Warnf("Could not obtain cfilter for %v", hashes[i])
|
||||
peerLog.Warnf("Could not obtain cfilter for %s", hashes[i])
|
||||
return
|
||||
}
|
||||
filterMsg := wire.NewMsgCFilter(msg.FilterType, &hashes[i], filterBytes)
|
||||
@ -776,7 +776,7 @@ func (sp *Peer) OnGetCFHeaders(_ *peer.Peer, msg *wire.MsgGetCFHeaders) {
|
||||
hashList, err := sp.server.DAG.HeightToHashRange(startHeight,
|
||||
&msg.StopHash, maxResults)
|
||||
if err != nil {
|
||||
peerLog.Debugf("Invalid getcfheaders request: %v", err)
|
||||
peerLog.Debugf("Invalid getcfheaders request: %s", err)
|
||||
}
|
||||
|
||||
// This is possible if StartHeight is one greater that the height of
|
||||
@ -798,7 +798,7 @@ func (sp *Peer) OnGetCFHeaders(_ *peer.Peer, msg *wire.MsgGetCFHeaders) {
|
||||
filterHashes, err := sp.server.CfIndex.FilterHashesByBlockHashes(hashPtrs,
|
||||
msg.FilterType)
|
||||
if err != nil {
|
||||
peerLog.Errorf("Error retrieving cfilter hashes: %v", err)
|
||||
peerLog.Errorf("Error retrieving cfilter hashes: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -814,11 +814,11 @@ func (sp *Peer) OnGetCFHeaders(_ *peer.Peer, msg *wire.MsgGetCFHeaders) {
|
||||
headerBytes, err := sp.server.CfIndex.FilterHeaderByBlockHash(
|
||||
parentHash, msg.FilterType)
|
||||
if err != nil {
|
||||
peerLog.Errorf("Error retrieving CF header: %v", err)
|
||||
peerLog.Errorf("Error retrieving CF header: %s", err)
|
||||
return
|
||||
}
|
||||
if len(headerBytes) == 0 {
|
||||
peerLog.Warnf("Could not obtain CF header for %v", parentHash)
|
||||
peerLog.Warnf("Could not obtain CF header for %s", parentHash)
|
||||
return
|
||||
}
|
||||
|
||||
@ -826,7 +826,7 @@ func (sp *Peer) OnGetCFHeaders(_ *peer.Peer, msg *wire.MsgGetCFHeaders) {
|
||||
err = headersMsg.PrevFilterHeader.SetBytes(headerBytes)
|
||||
if err != nil {
|
||||
peerLog.Warnf("Committed filter header deserialize "+
|
||||
"failed: %v", err)
|
||||
"failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -837,7 +837,7 @@ func (sp *Peer) OnGetCFHeaders(_ *peer.Peer, msg *wire.MsgGetCFHeaders) {
|
||||
// Populate HeaderHashes.
|
||||
for i, hashBytes := range filterHashes {
|
||||
if len(hashBytes) == 0 {
|
||||
peerLog.Warnf("Could not obtain CF hash for %v", hashList[i])
|
||||
peerLog.Warnf("Could not obtain CF hash for %s", hashList[i])
|
||||
return
|
||||
}
|
||||
|
||||
@ -845,7 +845,7 @@ func (sp *Peer) OnGetCFHeaders(_ *peer.Peer, msg *wire.MsgGetCFHeaders) {
|
||||
filterHash, err := daghash.NewHash(hashBytes)
|
||||
if err != nil {
|
||||
peerLog.Warnf("Committed filter hash deserialize "+
|
||||
"failed: %v", err)
|
||||
"failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -867,7 +867,7 @@ func (sp *Peer) OnGetCFCheckpt(_ *peer.Peer, msg *wire.MsgGetCFCheckpt) {
|
||||
blockHashes, err := sp.server.DAG.IntervalBlockHashes(&msg.StopHash,
|
||||
wire.CFCheckptInterval)
|
||||
if err != nil {
|
||||
peerLog.Debugf("Invalid getcfilters request: %v", err)
|
||||
peerLog.Debugf("Invalid getcfilters request: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -923,20 +923,20 @@ func (sp *Peer) OnGetCFCheckpt(_ *peer.Peer, msg *wire.MsgGetCFCheckpt) {
|
||||
filterHeaders, err := sp.server.CfIndex.FilterHeadersByBlockHashes(blockHashPtrs,
|
||||
msg.FilterType)
|
||||
if err != nil {
|
||||
peerLog.Errorf("Error retrieving cfilter headers: %v", err)
|
||||
peerLog.Errorf("Error retrieving cfilter headers: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
for i, filterHeaderBytes := range filterHeaders {
|
||||
if len(filterHeaderBytes) == 0 {
|
||||
peerLog.Warnf("Could not obtain CF header for %v", blockHashPtrs[i])
|
||||
peerLog.Warnf("Could not obtain CF header for %s", blockHashPtrs[i])
|
||||
return
|
||||
}
|
||||
|
||||
filterHeader, err := daghash.NewHash(filterHeaderBytes)
|
||||
if err != nil {
|
||||
peerLog.Warnf("Committed filter header deserialize "+
|
||||
"failed: %v", err)
|
||||
"failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -993,7 +993,7 @@ func (sp *Peer) enforceNodeBloomFlag(cmd string) bool {
|
||||
func (sp *Peer) OnFeeFilter(_ *peer.Peer, msg *wire.MsgFeeFilter) {
|
||||
// Check that the passed minimum fee is a valid amount.
|
||||
if msg.MinFee < 0 || msg.MinFee > util.MaxSatoshi {
|
||||
peerLog.Debugf("Peer %v sent an invalid feefilter '%v' -- "+
|
||||
peerLog.Debugf("Peer %s sent an invalid feefilter '%s' -- "+
|
||||
"disconnecting", sp, util.Amount(msg.MinFee))
|
||||
sp.Disconnect()
|
||||
return
|
||||
@ -1077,7 +1077,7 @@ func (sp *Peer) OnGetAddr(_ *peer.Peer, msg *wire.MsgGetAddr) {
|
||||
// fingerprinting attacks.
|
||||
if !sp.Inbound() {
|
||||
peerLog.Debugf("Ignoring getaddr request from outbound peer ",
|
||||
"%v", sp)
|
||||
"%s", sp)
|
||||
return
|
||||
}
|
||||
|
||||
@ -1085,7 +1085,7 @@ func (sp *Peer) OnGetAddr(_ *peer.Peer, msg *wire.MsgGetAddr) {
|
||||
// address stamping of inv announcements.
|
||||
if sp.sentAddrs {
|
||||
peerLog.Debugf("Ignoring repeated getaddr request from peer ",
|
||||
"%v", sp)
|
||||
"%s", sp)
|
||||
return
|
||||
}
|
||||
sp.sentAddrs = true
|
||||
@ -1213,8 +1213,8 @@ func (s *Server) pushTxMsg(sp *Peer, txID *daghash.TxID, doneChan chan<- struct{
|
||||
// to fetch a missing transaction results in the same behavior.
|
||||
tx, err := s.TxMemPool.FetchTransaction(txID)
|
||||
if err != nil {
|
||||
peerLog.Tracef("Unable to fetch tx %v from transaction "+
|
||||
"pool: %v", txID, err)
|
||||
peerLog.Tracef("Unable to fetch tx %s from transaction "+
|
||||
"pool: %s", txID, err)
|
||||
|
||||
if doneChan != nil {
|
||||
doneChan <- struct{}{}
|
||||
@ -1245,7 +1245,7 @@ func (s *Server) pushBlockMsg(sp *Peer, hash *daghash.Hash, doneChan chan<- stru
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
peerLog.Tracef("Unable to fetch requested block hash %v: %v",
|
||||
peerLog.Tracef("Unable to fetch requested block hash %s: %s",
|
||||
hash, err)
|
||||
|
||||
if doneChan != nil {
|
||||
@ -1259,7 +1259,7 @@ func (s *Server) pushBlockMsg(sp *Peer, hash *daghash.Hash, doneChan chan<- stru
|
||||
err = msgBlock.Deserialize(bytes.NewReader(blockBytes))
|
||||
if err != nil {
|
||||
peerLog.Tracef("Unable to deserialize requested block hash "+
|
||||
"%v: %v", hash, err)
|
||||
"%s: %s", hash, err)
|
||||
|
||||
if doneChan != nil {
|
||||
doneChan <- struct{}{}
|
||||
@ -1326,7 +1326,7 @@ func (s *Server) pushMerkleBlockMsg(sp *Peer, hash *daghash.Hash,
|
||||
// Fetch the raw block bytes from the database.
|
||||
blk, err := sp.server.DAG.BlockByHash(hash)
|
||||
if err != nil {
|
||||
peerLog.Tracef("Unable to fetch requested block hash %v: %v",
|
||||
peerLog.Tracef("Unable to fetch requested block hash %s: %s",
|
||||
hash, err)
|
||||
|
||||
if doneChan != nil {
|
||||
@ -1413,13 +1413,13 @@ func (s *Server) handleAddPeerMsg(state *peerState, sp *Peer) bool {
|
||||
// Disconnect banned peers.
|
||||
host, _, err := net.SplitHostPort(sp.Addr())
|
||||
if err != nil {
|
||||
srvrLog.Debugf("can't split hostport %v", err)
|
||||
srvrLog.Debugf("can't split hostport %s", err)
|
||||
sp.Disconnect()
|
||||
return false
|
||||
}
|
||||
if banEnd, ok := state.banned[host]; ok {
|
||||
if time.Now().Before(banEnd) {
|
||||
srvrLog.Debugf("Peer %s is banned for another %v - disconnecting",
|
||||
srvrLog.Debugf("Peer %s is banned for another %s - disconnecting",
|
||||
host, time.Until(banEnd))
|
||||
sp.Disconnect()
|
||||
return false
|
||||
@ -1499,11 +1499,11 @@ func (s *Server) handleDonePeerMsg(state *peerState, sp *Peer) {
|
||||
func (s *Server) handleBanPeerMsg(state *peerState, sp *Peer) {
|
||||
host, _, err := net.SplitHostPort(sp.Addr())
|
||||
if err != nil {
|
||||
srvrLog.Debugf("can't split ban peer %s %v", sp.Addr(), err)
|
||||
srvrLog.Debugf("can't split ban peer %s: %s", sp.Addr(), err)
|
||||
return
|
||||
}
|
||||
direction := logger.DirectionString(sp.Inbound())
|
||||
srvrLog.Infof("Banned peer %s (%s) for %v", host, direction,
|
||||
srvrLog.Infof("Banned peer %s (%s) for %s", host, direction,
|
||||
config.MainConfig().BanDuration)
|
||||
state.banned[host] = time.Now().Add(config.MainConfig().BanDuration)
|
||||
}
|
||||
@ -1529,7 +1529,7 @@ func (s *Server) handleRelayInvMsg(state *peerState, msg relayMsg) {
|
||||
msgHeaders := wire.NewMsgHeaders()
|
||||
if err := msgHeaders.AddBlockHeader(&blockHeader); err != nil {
|
||||
peerLog.Errorf("Failed to add block"+
|
||||
" header: %v", err)
|
||||
" header: %s", err)
|
||||
return
|
||||
}
|
||||
sp.QueueMessage(msgHeaders, nil)
|
||||
@ -1838,7 +1838,7 @@ func (s *Server) outboundPeerConnected(c *connmgr.ConnReq, conn net.Conn) {
|
||||
sp := newServerPeer(s, c.Permanent)
|
||||
p, err := peer.NewOutboundPeer(newPeerConfig(sp), c.Addr.String())
|
||||
if err != nil {
|
||||
srvrLog.Debugf("Cannot create outbound peer %s: %v", c.Addr, err)
|
||||
srvrLog.Debugf("Cannot create outbound peer %s: %s", c.Addr, err)
|
||||
s.connManager.Disconnect(c.ID())
|
||||
}
|
||||
sp.Peer = p
|
||||
@ -1862,7 +1862,7 @@ func (s *Server) peerDoneHandler(sp *Peer) {
|
||||
// Evict any remaining orphans that were sent by the peer.
|
||||
numEvicted := s.TxMemPool.RemoveOrphansByTag(mempool.Tag(sp.ID()))
|
||||
if numEvicted > 0 {
|
||||
txmpLog.Debugf("Evicted %d %s from peer %v (id %d)",
|
||||
txmpLog.Debugf("Evicted %d %s from peer %s (id %d)",
|
||||
numEvicted, logger.PickNoun(numEvicted, "orphan",
|
||||
"orphans"), sp, sp.ID())
|
||||
}
|
||||
@ -2155,7 +2155,7 @@ func (s *Server) ScheduleShutdown(duration time.Duration) {
|
||||
if atomic.AddInt32(&s.shutdownSched, 1) != 1 {
|
||||
return
|
||||
}
|
||||
srvrLog.Warnf("Server shutdown in %v", duration)
|
||||
srvrLog.Warnf("Server shutdown in %s", duration)
|
||||
go func() {
|
||||
remaining := duration
|
||||
tickDuration := dynamicTickDuration(remaining)
|
||||
@ -2181,7 +2181,7 @@ func (s *Server) ScheduleShutdown(duration time.Duration) {
|
||||
ticker.Stop()
|
||||
ticker = time.NewTicker(tickDuration)
|
||||
}
|
||||
srvrLog.Warnf("Server shutdown in %v", remaining)
|
||||
srvrLog.Warnf("Server shutdown in %s", remaining)
|
||||
}
|
||||
}
|
||||
}()
|
||||
@ -2249,14 +2249,14 @@ out:
|
||||
listenPort, err := s.nat.AddPortMapping("tcp", int(lport), int(lport),
|
||||
"btcd listen port", 20*60)
|
||||
if err != nil {
|
||||
srvrLog.Warnf("can't add UPnP port mapping: %v", err)
|
||||
srvrLog.Warnf("can't add UPnP port mapping: %s", err)
|
||||
}
|
||||
if first && err == nil {
|
||||
// TODO: look this up periodically to see if upnp domain changed
|
||||
// and so did ip.
|
||||
externalip, err := s.nat.GetExternalAddress()
|
||||
if err != nil {
|
||||
srvrLog.Warnf("UPnP can't get external address: %v", err)
|
||||
srvrLog.Warnf("UPnP can't get external address: %s", err)
|
||||
continue out
|
||||
}
|
||||
na := wire.NewNetAddressIPPort(externalip, uint16(listenPort),
|
||||
@ -2277,7 +2277,7 @@ out:
|
||||
timer.Stop()
|
||||
|
||||
if err := s.nat.DeletePortMapping("tcp", int(lport), int(lport)); err != nil {
|
||||
srvrLog.Warnf("unable to remove UPnP port mapping: %v", err)
|
||||
srvrLog.Warnf("unable to remove UPnP port mapping: %s", err)
|
||||
} else {
|
||||
srvrLog.Debugf("successfully disestablished UPnP port mapping")
|
||||
}
|
||||
@ -2408,7 +2408,7 @@ func NewServer(listenAddrs []string, db database.DB, dagParams *dagconfig.Params
|
||||
s.FeeEstimator, err = mempool.RestoreFeeEstimator(feeEstimationData)
|
||||
|
||||
if err != nil {
|
||||
peerLog.Errorf("Failed to restore fee estimator %v", err)
|
||||
peerLog.Errorf("Failed to restore fee estimator %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -2562,7 +2562,7 @@ func initListeners(amgr *addrmgr.AddrManager, listenAddrs []string, services wir
|
||||
for _, addr := range netAddrs {
|
||||
listener, err := net.Listen(addr.Network(), addr.String())
|
||||
if err != nil {
|
||||
srvrLog.Warnf("Can't listen on %s: %v", addr, err)
|
||||
srvrLog.Warnf("Can't listen on %s: %s", addr, err)
|
||||
continue
|
||||
}
|
||||
listeners = append(listeners, listener)
|
||||
@ -2572,7 +2572,7 @@ func initListeners(amgr *addrmgr.AddrManager, listenAddrs []string, services wir
|
||||
if len(config.MainConfig().ExternalIPs) != 0 {
|
||||
defaultPort, err := strconv.ParseUint(config.ActiveNetParams().DefaultPort, 10, 16)
|
||||
if err != nil {
|
||||
srvrLog.Errorf("Can not parse default port %s for active chain: %v",
|
||||
srvrLog.Errorf("Can not parse default port %s for active chain: %s",
|
||||
config.ActiveNetParams().DefaultPort, err)
|
||||
return nil, nil, err
|
||||
}
|
||||
@ -2587,20 +2587,20 @@ func initListeners(amgr *addrmgr.AddrManager, listenAddrs []string, services wir
|
||||
port, err := strconv.ParseUint(portstr, 10, 16)
|
||||
if err != nil {
|
||||
srvrLog.Warnf("Can not parse port from %s for "+
|
||||
"externalip: %v", sip, err)
|
||||
"externalip: %s", sip, err)
|
||||
continue
|
||||
}
|
||||
eport = uint16(port)
|
||||
}
|
||||
na, err := amgr.HostToNetAddress(host, eport, services)
|
||||
if err != nil {
|
||||
srvrLog.Warnf("Not adding %s as externalip: %v", sip, err)
|
||||
srvrLog.Warnf("Not adding %s as externalip: %s", sip, err)
|
||||
continue
|
||||
}
|
||||
|
||||
err = amgr.AddLocalAddress(na, addrmgr.ManualPrio)
|
||||
if err != nil {
|
||||
amgrLog.Warnf("Skipping specified external IP: %v", err)
|
||||
amgrLog.Warnf("Skipping specified external IP: %s", err)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -2608,7 +2608,7 @@ func initListeners(amgr *addrmgr.AddrManager, listenAddrs []string, services wir
|
||||
var err error
|
||||
nat, err = serverutils.Discover()
|
||||
if err != nil {
|
||||
srvrLog.Warnf("Can't discover upnp: %v", err)
|
||||
srvrLog.Warnf("Can't discover upnp: %s", err)
|
||||
}
|
||||
// nil nat here is fine, just means no upnp on network.
|
||||
}
|
||||
@ -2618,7 +2618,7 @@ func initListeners(amgr *addrmgr.AddrManager, listenAddrs []string, services wir
|
||||
addr := listener.Addr().String()
|
||||
err := addLocalAddress(amgr, addr, services)
|
||||
if err != nil {
|
||||
amgrLog.Warnf("Skipping bound address %s: %v", addr, err)
|
||||
amgrLog.Warnf("Skipping bound address %s: %s", addr, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2751,7 +2751,7 @@ func isWhitelisted(addr net.Addr) bool {
|
||||
|
||||
host, _, err := net.SplitHostPort(addr.String())
|
||||
if err != nil {
|
||||
srvrLog.Warnf("Unable to SplitHostPort on '%s': %v", addr, err)
|
||||
srvrLog.Warnf("Unable to SplitHostPort on '%s': %s", addr, err)
|
||||
return false
|
||||
}
|
||||
ip := net.ParseIP(host)
|
||||
|
@ -330,7 +330,7 @@ func rpcDecodeHexError(gotHex string) *btcjson.RPCError {
|
||||
// transaction hash.
|
||||
func rpcNoTxInfoError(txID *daghash.TxID) *btcjson.RPCError {
|
||||
return btcjson.NewRPCError(btcjson.ErrRPCNoTxInfo,
|
||||
fmt.Sprintf("No information available about transaction %v",
|
||||
fmt.Sprintf("No information available about transaction %s",
|
||||
txID))
|
||||
}
|
||||
|
||||
@ -641,7 +641,7 @@ func handleDebugLevel(s *Server, cmd interface{}, closeChan <-chan struct{}) (in
|
||||
|
||||
// Special show command to list supported subsystems.
|
||||
if c.LevelSpec == "show" {
|
||||
return fmt.Sprintf("Supported subsystems %v",
|
||||
return fmt.Sprintf("Supported subsystems %s",
|
||||
logger.SupportedSubsystems()), nil
|
||||
}
|
||||
|
||||
@ -1084,7 +1084,7 @@ func getDifficultyRatio(bits uint32, params *dagconfig.Params) float64 {
|
||||
outString := difficulty.FloatString(8)
|
||||
diff, err := strconv.ParseFloat(outString, 64)
|
||||
if err != nil {
|
||||
log.Errorf("Cannot get difficulty: %v", err)
|
||||
log.Errorf("Cannot get difficulty: %s", err)
|
||||
return 0
|
||||
}
|
||||
return diff
|
||||
@ -1248,7 +1248,7 @@ func softForkStatus(state blockdag.ThresholdState) (string, error) {
|
||||
case blockdag.ThresholdFailed:
|
||||
return "failed", nil
|
||||
default:
|
||||
return "", fmt.Errorf("unknown deployment state: %v", state)
|
||||
return "", fmt.Errorf("unknown deployment state: %s", state)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1283,7 +1283,7 @@ func handleGetBlockDAGInfo(s *Server, cmd interface{}, closeChan <-chan struct{}
|
||||
default:
|
||||
return nil, &btcjson.RPCError{
|
||||
Code: btcjson.ErrRPCInternal.Code,
|
||||
Message: fmt.Sprintf("Unknown deployment %v "+
|
||||
Message: fmt.Sprintf("Unknown deployment %d "+
|
||||
"detected", deployment),
|
||||
}
|
||||
}
|
||||
@ -1303,7 +1303,7 @@ func handleGetBlockDAGInfo(s *Server, cmd interface{}, closeChan <-chan struct{}
|
||||
if err != nil {
|
||||
return nil, &btcjson.RPCError{
|
||||
Code: btcjson.ErrRPCInternal.Code,
|
||||
Message: fmt.Sprintf("unknown deployment status: %v",
|
||||
Message: fmt.Sprintf("unknown deployment status: %d",
|
||||
deploymentStatus),
|
||||
}
|
||||
}
|
||||
@ -1428,14 +1428,14 @@ func decodeLongPollID(longPollID string) ([]daghash.Hash, int64, error) {
|
||||
for i := 0; i < len(parentHashesStr); i += daghash.HashSize {
|
||||
hash, err := daghash.NewHashFromStr(parentHashesStr[i : i+daghash.HashSize])
|
||||
if err != nil {
|
||||
return nil, 0, fmt.Errorf("decodeLongPollID: NewHashFromStr: %v", err)
|
||||
return nil, 0, fmt.Errorf("decodeLongPollID: NewHashFromStr: %s", err)
|
||||
}
|
||||
parentHashes = append(parentHashes, *hash)
|
||||
}
|
||||
|
||||
lastGenerated, err := strconv.ParseInt(fields[1], 10, 64)
|
||||
if err != nil {
|
||||
return nil, 0, fmt.Errorf("decodeLongPollID: Cannot parse timestamp: %v", lastGenerated)
|
||||
return nil, 0, fmt.Errorf("decodeLongPollID: Cannot parse timestamp %s: %s", fields[1], err)
|
||||
}
|
||||
|
||||
return parentHashes, lastGenerated, nil
|
||||
@ -1628,7 +1628,7 @@ func (state *gbtWorkState) updateBlockTemplate(s *Server, useCoinbaseValue bool)
|
||||
state.tipHashes = tipHashes
|
||||
state.minTimestamp = minTimestamp
|
||||
|
||||
log.Debugf("Generated block template (timestamp %v, "+
|
||||
log.Debugf("Generated block template (timestamp %s, "+
|
||||
"target %s, merkle root %s)",
|
||||
msgBlock.Header.Timestamp, targetDifficulty,
|
||||
msgBlock.Header.HashMerkleRoot)
|
||||
@ -1682,7 +1682,7 @@ func (state *gbtWorkState) updateBlockTemplate(s *Server, useCoinbaseValue bool)
|
||||
generator.UpdateBlockTime(msgBlock)
|
||||
msgBlock.Header.Nonce = 0
|
||||
|
||||
log.Debugf("Updated block template (timestamp %v, "+
|
||||
log.Debugf("Updated block template (timestamp %s, "+
|
||||
"target %s)", msgBlock.Header.Timestamp,
|
||||
targetDifficulty)
|
||||
}
|
||||
@ -1710,7 +1710,7 @@ func (state *gbtWorkState) blockTemplateResult(useCoinbaseValue bool, submitOld
|
||||
Code: btcjson.ErrRPCOutOfRange,
|
||||
Message: fmt.Sprintf("The template time is after the "+
|
||||
"maximum allowed time for a block - template "+
|
||||
"time %v, maximum time %v", adjustedTime,
|
||||
"time %s, maximum time %s", adjustedTime,
|
||||
maxTime),
|
||||
}
|
||||
}
|
||||
@ -2147,7 +2147,7 @@ func handleGetBlockTemplateProposal(s *Server, request *btcjson.TemplateRequest)
|
||||
|
||||
if err := s.cfg.DAG.CheckConnectBlockTemplate(block); err != nil {
|
||||
if _, ok := err.(blockdag.RuleError); !ok {
|
||||
errStr := fmt.Sprintf("Failed to process block proposal: %v", err)
|
||||
errStr := fmt.Sprintf("Failed to process block proposal: %s", err)
|
||||
log.Error(errStr)
|
||||
return nil, &btcjson.RPCError{
|
||||
Code: btcjson.ErrRPCVerify,
|
||||
@ -2155,7 +2155,7 @@ func handleGetBlockTemplateProposal(s *Server, request *btcjson.TemplateRequest)
|
||||
}
|
||||
}
|
||||
|
||||
log.Infof("Rejected block proposal: %v", err)
|
||||
log.Infof("Rejected block proposal: %s", err)
|
||||
return chainErrToGBTErrString(err), nil
|
||||
}
|
||||
|
||||
@ -2206,7 +2206,7 @@ func handleGetCFilter(s *Server, cmd interface{}, closeChan <-chan struct{}) (in
|
||||
|
||||
filterBytes, err := s.cfg.CfIndex.FilterByBlockHash(hash, c.FilterType)
|
||||
if err != nil {
|
||||
log.Debugf("Could not find committed filter for %v: %v",
|
||||
log.Debugf("Could not find committed filter for %s: %s",
|
||||
hash, err)
|
||||
return nil, &btcjson.RPCError{
|
||||
Code: btcjson.ErrRPCBlockNotFound,
|
||||
@ -2214,7 +2214,7 @@ func handleGetCFilter(s *Server, cmd interface{}, closeChan <-chan struct{}) (in
|
||||
}
|
||||
}
|
||||
|
||||
log.Debugf("Found committed filter for %v", hash)
|
||||
log.Debugf("Found committed filter for %s", hash)
|
||||
return hex.EncodeToString(filterBytes), nil
|
||||
}
|
||||
|
||||
@ -2235,9 +2235,9 @@ func handleGetCFilterHeader(s *Server, cmd interface{}, closeChan <-chan struct{
|
||||
|
||||
headerBytes, err := s.cfg.CfIndex.FilterHeaderByBlockHash(hash, c.FilterType)
|
||||
if len(headerBytes) > 0 {
|
||||
log.Debugf("Found header of committed filter for %v", hash)
|
||||
log.Debugf("Found header of committed filter for %s", hash)
|
||||
} else {
|
||||
log.Debugf("Could not find header of committed filter for %v: %v",
|
||||
log.Debugf("Could not find header of committed filter for %s: %s",
|
||||
hash, err)
|
||||
return nil, &btcjson.RPCError{
|
||||
Code: btcjson.ErrRPCBlockNotFound,
|
||||
@ -2793,7 +2793,7 @@ func fetchInputTxos(s *Server, tx *wire.MsgTx) (map[wire.OutPoint]wire.TxOut, er
|
||||
txOuts := originTx.MsgTx().TxOut
|
||||
if origin.Index >= uint32(len(txOuts)) {
|
||||
errStr := fmt.Sprintf("unable to find output "+
|
||||
"%v referenced from transaction %s:%d",
|
||||
"%s referenced from transaction %s:%d",
|
||||
origin, tx.TxID(), txInIndex)
|
||||
return nil, internalRPCError(errStr, "")
|
||||
}
|
||||
@ -2833,7 +2833,7 @@ func fetchInputTxos(s *Server, tx *wire.MsgTx) (map[wire.OutPoint]wire.TxOut, er
|
||||
|
||||
// Add the referenced output to the map.
|
||||
if origin.Index >= uint32(len(msgTx.TxOut)) {
|
||||
errStr := fmt.Sprintf("unable to find output %v "+
|
||||
errStr := fmt.Sprintf("unable to find output %s "+
|
||||
"referenced from transaction %s:%d", origin,
|
||||
tx.TxID(), txInIndex)
|
||||
return nil, internalRPCError(errStr, "")
|
||||
@ -3277,10 +3277,10 @@ func handleSendRawTransaction(s *Server, cmd interface{}, closeChan <-chan struc
|
||||
// error is returned to the client with the deserialization
|
||||
// error code (to match bitcoind behavior).
|
||||
if _, ok := err.(mempool.RuleError); ok {
|
||||
log.Debugf("Rejected transaction %v: %v", tx.ID(),
|
||||
log.Debugf("Rejected transaction %s: %s", tx.ID(),
|
||||
err)
|
||||
} else {
|
||||
log.Errorf("Failed to process transaction %v: %v",
|
||||
log.Errorf("Failed to process transaction %s: %s",
|
||||
tx.ID(), err)
|
||||
}
|
||||
return nil, &btcjson.RPCError{
|
||||
@ -3302,7 +3302,7 @@ func handleSendRawTransaction(s *Server, cmd interface{}, closeChan <-chan struc
|
||||
return nil, err
|
||||
}
|
||||
|
||||
errStr := fmt.Sprintf("transaction %v is not in accepted list",
|
||||
errStr := fmt.Sprintf("transaction %s is not in accepted list",
|
||||
tx.ID())
|
||||
return nil, internalRPCError(errStr, "")
|
||||
}
|
||||
@ -3446,7 +3446,7 @@ func verifyDAG(s *Server, level, depth int32) error {
|
||||
block, err := s.cfg.DAG.BlockByHash(¤tHash)
|
||||
if err != nil {
|
||||
log.Errorf("Verify is unable to fetch block at "+
|
||||
"height %d: %v", height, err)
|
||||
"height %d: %s", height, err)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -3455,7 +3455,7 @@ func verifyDAG(s *Server, level, depth int32) error {
|
||||
err := s.cfg.DAG.CheckBlockSanity(block, s.cfg.DAGParams.PowLimit, s.cfg.TimeSource)
|
||||
if err != nil {
|
||||
log.Errorf("Verify is unable to validate "+
|
||||
"block at hash %v height %d: %v",
|
||||
"block at hash %s height %d: %s",
|
||||
block.Hash(), height, err)
|
||||
return err
|
||||
}
|
||||
@ -3645,7 +3645,7 @@ func (s *Server) Stop() error {
|
||||
for _, listener := range s.cfg.Listeners {
|
||||
err := listener.Close()
|
||||
if err != nil {
|
||||
log.Errorf("Problem shutting down rpc: %v", err)
|
||||
log.Errorf("Problem shutting down rpc: %s", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
@ -3848,7 +3848,7 @@ func (s *Server) jsonRPCRead(w http.ResponseWriter, r *http.Request, isAdmin boo
|
||||
r.Body.Close()
|
||||
if err != nil {
|
||||
errCode := http.StatusBadRequest
|
||||
http.Error(w, fmt.Sprintf("%d error reading JSON message: %v",
|
||||
http.Error(w, fmt.Sprintf("%d error reading JSON message: %s",
|
||||
errCode, err), errCode)
|
||||
return
|
||||
}
|
||||
@ -3869,7 +3869,7 @@ func (s *Server) jsonRPCRead(w http.ResponseWriter, r *http.Request, isAdmin boo
|
||||
}
|
||||
conn, buf, err := hj.Hijack()
|
||||
if err != nil {
|
||||
log.Warnf("Failed to hijack HTTP connection: %v", err)
|
||||
log.Warnf("Failed to hijack HTTP connection: %s", err)
|
||||
errCode := http.StatusInternalServerError
|
||||
http.Error(w, strconv.Itoa(errCode)+" "+err.Error(), errCode)
|
||||
return
|
||||
@ -3951,7 +3951,7 @@ func (s *Server) jsonRPCRead(w http.ResponseWriter, r *http.Request, isAdmin boo
|
||||
// Marshal the response.
|
||||
msg, err := createMarshalledReply(responseID, result, jsonErr)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to marshal reply: %v", err)
|
||||
log.Errorf("Failed to marshal reply: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -3962,12 +3962,12 @@ func (s *Server) jsonRPCRead(w http.ResponseWriter, r *http.Request, isAdmin boo
|
||||
return
|
||||
}
|
||||
if _, err := buf.Write(msg); err != nil {
|
||||
log.Errorf("Failed to write marshalled reply: %v", err)
|
||||
log.Errorf("Failed to write marshalled reply: %s", err)
|
||||
}
|
||||
|
||||
// Terminate with newline to maintain compatibility with Bitcoin Core.
|
||||
if err := buf.WriteByte('\n'); err != nil {
|
||||
log.Errorf("Failed to append terminating newline to reply: %v", err)
|
||||
log.Errorf("Failed to append terminating newline to reply: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -4028,7 +4028,7 @@ func (s *Server) Start() {
|
||||
ws, err := websocket.Upgrade(w, r, nil, 0, 0)
|
||||
if err != nil {
|
||||
if _, ok := err.(websocket.HandshakeError); !ok {
|
||||
log.Errorf("Unexpected websocket error: %v",
|
||||
log.Errorf("Unexpected websocket error: %s",
|
||||
err)
|
||||
}
|
||||
http.Error(w, "400 Bad Request.", http.StatusBadRequest)
|
||||
@ -4249,7 +4249,7 @@ func setupRPCListeners() ([]net.Listener, error) {
|
||||
for _, addr := range netAddrs {
|
||||
listener, err := listenFunc(addr.Network(), addr.String())
|
||||
if err != nil {
|
||||
log.Warnf("Can't listen on %s: %v", addr, err)
|
||||
log.Warnf("Can't listen on %s: %s", addr, err)
|
||||
continue
|
||||
}
|
||||
listeners = append(listeners, listener)
|
||||
|
@ -15,11 +15,12 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/daglabs/btcd/util/subnetworkid"
|
||||
"io"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/daglabs/btcd/util/subnetworkid"
|
||||
|
||||
"golang.org/x/crypto/ripemd160"
|
||||
|
||||
"github.com/btcsuite/websocket"
|
||||
@ -104,7 +105,7 @@ func (s *Server) WebsocketHandler(conn *websocket.Conn, remoteAddr string,
|
||||
// disconnected), remove it and any notifications it registered for.
|
||||
client, err := newWebsocketClient(s, conn, remoteAddr, authenticated, isAdmin)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to serve client %s: %v", remoteAddr, err)
|
||||
log.Errorf("Failed to serve client %s: %s", remoteAddr, err)
|
||||
conn.Close()
|
||||
return
|
||||
}
|
||||
@ -697,7 +698,7 @@ func (*wsNotificationManager) notifyBlockConnected(clients map[chan struct{}]*ws
|
||||
marshalledJSON, err := btcjson.MarshalCmd(nil, ntfn)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to marshal block connected notification: "+
|
||||
"%v", err)
|
||||
"%s", err)
|
||||
return
|
||||
}
|
||||
for _, wsc := range clients {
|
||||
@ -721,7 +722,7 @@ func (*wsNotificationManager) notifyBlockDisconnected(clients map[chan struct{}]
|
||||
marshalledJSON, err := btcjson.MarshalCmd(nil, ntfn)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to marshal block disconnected "+
|
||||
"notification: %v", err)
|
||||
"notification: %s", err)
|
||||
return
|
||||
}
|
||||
for _, wsc := range clients {
|
||||
@ -740,7 +741,7 @@ func (m *wsNotificationManager) notifyFilteredBlockConnected(clients map[chan st
|
||||
err := block.MsgBlock().Header.Serialize(&w)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to serialize header for filtered block "+
|
||||
"connected notification: %v", err)
|
||||
"connected notification: %s", err)
|
||||
return
|
||||
}
|
||||
ntfn := btcjson.NewFilteredBlockConnectedNtfn(block.Height(),
|
||||
@ -767,7 +768,7 @@ func (m *wsNotificationManager) notifyFilteredBlockConnected(clients map[chan st
|
||||
marshalledJSON, err := btcjson.MarshalCmd(nil, ntfn)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to marshal filtered block "+
|
||||
"connected notification: %v", err)
|
||||
"connected notification: %s", err)
|
||||
return
|
||||
}
|
||||
wsc.QueueNotification(marshalledJSON)
|
||||
@ -790,7 +791,7 @@ func (*wsNotificationManager) notifyFilteredBlockDisconnected(clients map[chan s
|
||||
err := block.MsgBlock().Header.Serialize(&w)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to serialize header for filtered block "+
|
||||
"disconnected notification: %v", err)
|
||||
"disconnected notification: %s", err)
|
||||
return
|
||||
}
|
||||
ntfn := btcjson.NewFilteredBlockDisconnectedNtfn(block.Height(),
|
||||
@ -798,7 +799,7 @@ func (*wsNotificationManager) notifyFilteredBlockDisconnected(clients map[chan s
|
||||
marshalledJSON, err := btcjson.MarshalCmd(nil, ntfn)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to marshal filtered block disconnected "+
|
||||
"notification: %v", err)
|
||||
"notification: %s", err)
|
||||
return
|
||||
}
|
||||
for _, wsc := range clients {
|
||||
@ -938,7 +939,7 @@ func (m *wsNotificationManager) addSpentRequests(opMap map[wire.OutPoint]map[cha
|
||||
spend := m.server.cfg.TxMemPool.CheckSpend(*op)
|
||||
if spend != nil {
|
||||
log.Debugf("Found existing mempool spend for "+
|
||||
"outpoint<%v>: %v", op, spend.Hash())
|
||||
"outpoint<%s>: %s", op, spend.Hash())
|
||||
spends[*spend.Hash()] = spend
|
||||
}
|
||||
}
|
||||
@ -1049,7 +1050,7 @@ func (m *wsNotificationManager) notifyForTxOuts(ops map[wire.OutPoint]map[chan s
|
||||
|
||||
marshalledJSON, err := btcjson.MarshalCmd(nil, ntfn)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to marshal processedtx notification: %v", err)
|
||||
log.Errorf("Failed to marshal processedtx notification: %s", err)
|
||||
continue
|
||||
}
|
||||
|
||||
@ -1080,7 +1081,7 @@ func (m *wsNotificationManager) notifyRelevantTxAccepted(tx *util.Tx,
|
||||
n := btcjson.NewRelevantTxAcceptedNtfn(txHexString(tx.MsgTx()))
|
||||
marshalled, err := btcjson.MarshalCmd(nil, n)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to marshal notification: %v", err)
|
||||
log.Errorf("Failed to marshal notification: %s", err)
|
||||
return
|
||||
}
|
||||
for quitChan := range clientsToNotify {
|
||||
@ -1125,7 +1126,7 @@ func (m *wsNotificationManager) notifyForTxIns(ops map[wire.OutPoint]map[chan st
|
||||
}
|
||||
marshalledJSON, err := newRedeemingTxNotification(txHex, tx.Index(), block)
|
||||
if err != nil {
|
||||
log.Warnf("Failed to marshal redeemingtx notification: %v", err)
|
||||
log.Warnf("Failed to marshal redeemingtx notification: %s", err)
|
||||
continue
|
||||
}
|
||||
for wscQuit, wsc := range cmap {
|
||||
@ -1353,7 +1354,7 @@ out:
|
||||
// Log the error if it's not due to disconnecting.
|
||||
if err != io.EOF {
|
||||
log.Errorf("Websocket receive error from "+
|
||||
"%s: %v", c.addr, err)
|
||||
"%s: %s", c.addr, err)
|
||||
}
|
||||
break out
|
||||
}
|
||||
@ -1372,7 +1373,7 @@ out:
|
||||
reply, err := createMarshalledReply(nil, nil, jsonErr)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to marshal parse failure "+
|
||||
"reply: %v", err)
|
||||
"reply: %s", err)
|
||||
continue
|
||||
}
|
||||
c.SendMessage(reply, nil)
|
||||
@ -1413,7 +1414,7 @@ out:
|
||||
reply, err := createMarshalledReply(cmd.id, nil, cmd.err)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to marshal parse failure "+
|
||||
"reply: %v", err)
|
||||
"reply: %s", err)
|
||||
continue
|
||||
}
|
||||
c.SendMessage(reply, nil)
|
||||
@ -1453,7 +1454,7 @@ out:
|
||||
reply, err := createMarshalledReply(cmd.id, nil, nil)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to marshal authenticate reply: "+
|
||||
"%v", err.Error())
|
||||
"%s", err.Error())
|
||||
continue
|
||||
}
|
||||
c.SendMessage(reply, nil)
|
||||
@ -1472,7 +1473,7 @@ out:
|
||||
reply, err := createMarshalledReply(request.ID, nil, jsonErr)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to marshal parse failure "+
|
||||
"reply: %v", err)
|
||||
"reply: %s", err)
|
||||
continue
|
||||
}
|
||||
c.SendMessage(reply, nil)
|
||||
@ -1533,7 +1534,7 @@ func (c *wsClient) serviceRequest(r *parsedRPCCmd) {
|
||||
reply, err := createMarshalledReply(r.id, result, err)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to marshal reply for <%s> "+
|
||||
"command: %v", r.method, err)
|
||||
"command: %s", r.method, err)
|
||||
return
|
||||
}
|
||||
c.SendMessage(reply, nil)
|
||||
@ -2032,7 +2033,7 @@ func checkAddressValidity(addrs []string, params *dagconfig.Params) error {
|
||||
if err != nil {
|
||||
return &btcjson.RPCError{
|
||||
Code: btcjson.ErrRPCInvalidAddressOrKey,
|
||||
Message: fmt.Sprintf("Invalid address or key: %v",
|
||||
Message: fmt.Sprintf("Invalid address or key: %s",
|
||||
addr),
|
||||
}
|
||||
}
|
||||
@ -2167,7 +2168,7 @@ func handleRescanBlocks(wsc *wsClient, icmd interface{}) (interface{}, error) {
|
||||
if lastBlockHash != nil && block.MsgBlock().Header.ParentHashes[0] != *lastBlockHash { // TODO: (Stas) This is likely wrong. Modified to satisfy compilation.
|
||||
return nil, &btcjson.RPCError{
|
||||
Code: btcjson.ErrRPCInvalidParameter,
|
||||
Message: fmt.Sprintf("Block %v is not a child of %v",
|
||||
Message: fmt.Sprintf("Block %s is not a child of %s",
|
||||
blockHashes[i], lastBlockHash),
|
||||
}
|
||||
}
|
||||
|
@ -194,13 +194,13 @@ func startService() error {
|
||||
|
||||
service, err := serviceManager.OpenService(svcName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not access service: %v", err)
|
||||
return fmt.Errorf("could not access service: %s", err)
|
||||
}
|
||||
defer service.Close()
|
||||
|
||||
err = service.Start(os.Args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not start service: %v", err)
|
||||
return fmt.Errorf("could not start service: %s", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -219,13 +219,13 @@ func controlService(c svc.Cmd, to svc.State) error {
|
||||
|
||||
service, err := serviceManager.OpenService(svcName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not access service: %v", err)
|
||||
return fmt.Errorf("could not access service: %s", err)
|
||||
}
|
||||
defer service.Close()
|
||||
|
||||
status, err := service.Control(c)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not send control=%d: %v", c, err)
|
||||
return fmt.Errorf("could not send control=%d: %s", c, err)
|
||||
}
|
||||
|
||||
// Send the control message.
|
||||
@ -239,7 +239,7 @@ func controlService(c svc.Cmd, to svc.State) error {
|
||||
status, err = service.Query()
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not retrieve service "+
|
||||
"status: %v", err)
|
||||
"status: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -294,7 +294,7 @@ func serviceMain() (bool, error) {
|
||||
|
||||
err = svc.Run(svcName, &btcdService{})
|
||||
if err != nil {
|
||||
elog.Error(1, fmt.Sprintf("Service start failed: %v", err))
|
||||
elog.Error(1, fmt.Sprintf("Service start failed: %s", err))
|
||||
return true, err
|
||||
}
|
||||
|
||||
|
@ -140,12 +140,12 @@ func (vm *Engine) disasm(scriptIdx int, scriptOff int) string {
|
||||
// execution, nil otherwise.
|
||||
func (vm *Engine) validPC() error {
|
||||
if vm.scriptIdx >= len(vm.scripts) {
|
||||
str := fmt.Sprintf("past input scripts %v:%v %v:xxxx",
|
||||
str := fmt.Sprintf("past input scripts %d:%d %d:xxxx",
|
||||
vm.scriptIdx, vm.scriptOff, len(vm.scripts))
|
||||
return scriptError(ErrInvalidProgramCounter, str)
|
||||
}
|
||||
if vm.scriptOff >= len(vm.scripts[vm.scriptIdx]) {
|
||||
str := fmt.Sprintf("past input scripts %v:%v %v:%04d",
|
||||
str := fmt.Sprintf("past input scripts %d:%d %d:%04d",
|
||||
vm.scriptIdx, vm.scriptOff, vm.scriptIdx,
|
||||
len(vm.scripts[vm.scriptIdx]))
|
||||
return scriptError(ErrInvalidProgramCounter, str)
|
||||
@ -222,7 +222,7 @@ func (vm *Engine) CheckErrorCondition(finalScript bool) error {
|
||||
}
|
||||
if !v {
|
||||
// Log interesting data.
|
||||
log.Tracef("%v", newLogClosure(func() string {
|
||||
log.Tracef("%s", newLogClosure(func() string {
|
||||
dis0, _ := vm.DisasmScript(0)
|
||||
dis1, _ := vm.DisasmScript(1)
|
||||
return fmt.Sprintf("scripts failed: script0: %s\n"+
|
||||
@ -321,19 +321,19 @@ func (vm *Engine) Step() (done bool, err error) {
|
||||
func (vm *Engine) Execute() (err error) {
|
||||
done := false
|
||||
for !done {
|
||||
log.Tracef("%v", newLogClosure(func() string {
|
||||
log.Tracef("%s", newLogClosure(func() string {
|
||||
dis, err := vm.DisasmPC()
|
||||
if err != nil {
|
||||
return fmt.Sprintf("stepping (%v)", err)
|
||||
return fmt.Sprintf("stepping (%s)", err)
|
||||
}
|
||||
return fmt.Sprintf("stepping %v", dis)
|
||||
return fmt.Sprintf("stepping %s", dis)
|
||||
}))
|
||||
|
||||
done, err = vm.Step()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Tracef("%v", newLogClosure(func() string {
|
||||
log.Tracef("%s", newLogClosure(func() string {
|
||||
var dstr, astr string
|
||||
|
||||
// if we're tracing, dump the stacks.
|
||||
|
@ -18,7 +18,7 @@ func init() {
|
||||
log, _ = logger.Get(logger.SubsystemTags.SCRP)
|
||||
}
|
||||
|
||||
// LogClosure is a closure that can be printed with %v to be used to
|
||||
// LogClosure is a closure that can be printed with %s to be used to
|
||||
// generate expensive-to-create data for a detailed log level and avoid doing
|
||||
// the work if the data isn't printed.
|
||||
type logClosure func() string
|
||||
|
@ -945,8 +945,8 @@ func popIfBool(vm *Engine) (bool, error) {
|
||||
}
|
||||
|
||||
str := fmt.Sprintf("with OP_IF or OP_NOTIF top stack item MUST "+
|
||||
"be an empty byte array or 0x01, and is instead: %v",
|
||||
so[0])
|
||||
"be an empty byte array or 0x01, and is instead: %x",
|
||||
so)
|
||||
return false, scriptError(ErrMinimalIf, str)
|
||||
}
|
||||
|
||||
|
@ -281,7 +281,7 @@ func shallowCopyTx(tx *wire.MsgTx) wire.MsgTx {
|
||||
func CalcSignatureHash(script []byte, hashType SigHashType, tx *wire.MsgTx, idx int) ([]byte, error) {
|
||||
parsedScript, err := parseScript(script)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot parse output script: %v", err)
|
||||
return nil, fmt.Errorf("cannot parse output script: %s", err)
|
||||
}
|
||||
return calcSignatureHash(parsedScript, hashType, tx, idx)
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/daglabs/btcd/btcec"
|
||||
"github.com/daglabs/btcd/util/bech32"
|
||||
"golang.org/x/crypto/ripemd160"
|
||||
@ -67,7 +68,7 @@ var stringsToBech32Prefixes = map[string]Bech32Prefix{
|
||||
func ParsePrefix(prefixString string) (Bech32Prefix, error) {
|
||||
prefix, ok := stringsToBech32Prefixes[prefixString]
|
||||
if !ok {
|
||||
return Bech32PrefixUnknown, fmt.Errorf("could not parse prefix %v", prefixString)
|
||||
return Bech32PrefixUnknown, fmt.Errorf("could not parse prefix %s", prefixString)
|
||||
}
|
||||
|
||||
return prefix, nil
|
||||
@ -131,15 +132,15 @@ type Address interface {
|
||||
func DecodeAddress(addr string, defaultPrefix Bech32Prefix) (Address, error) {
|
||||
prefixString, decoded, version, err := bech32.Decode(addr)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("decoded address is of unknown format: %v", err)
|
||||
return nil, fmt.Errorf("decoded address is of unknown format: %s", err)
|
||||
}
|
||||
|
||||
prefix, err := ParsePrefix(prefixString)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("decoded address's prefix could not be parsed: %v", err)
|
||||
return nil, fmt.Errorf("decoded address's prefix could not be parsed: %s", err)
|
||||
}
|
||||
if defaultPrefix != prefix {
|
||||
return nil, fmt.Errorf("decoded address is of wrong network: %v", err)
|
||||
return nil, fmt.Errorf("decoded address is of wrong network: %s", err)
|
||||
}
|
||||
|
||||
// Switch on decoded length to determine the type.
|
||||
|
@ -98,7 +98,7 @@ func decode(encoded string) (string, []byte, error) {
|
||||
decoded, err := decodeFromBase32(data)
|
||||
if err != nil {
|
||||
return "", nil, fmt.Errorf("failed converting data to bytes: "+
|
||||
"%v", err)
|
||||
"%s", err)
|
||||
}
|
||||
|
||||
if !verifyChecksum(prefix, decoded) {
|
||||
@ -137,7 +137,7 @@ func decodeFromBase32(base32String string) ([]byte, error) {
|
||||
index := strings.IndexByte(charset, base32String[i])
|
||||
if index < 0 {
|
||||
return nil, fmt.Errorf("invalid character not part of "+
|
||||
"charset: %v", base32String[i])
|
||||
"charset: %c", base32String[i])
|
||||
}
|
||||
decoded = append(decoded, byte(index))
|
||||
}
|
||||
|
@ -120,24 +120,24 @@ func NewTLSCertPair(organization string, validUntil time.Time, extraHosts []stri
|
||||
derBytes, err := x509.CreateCertificate(rand.Reader, &template,
|
||||
&template, &priv.PublicKey, priv)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("failed to create certificate: %v", err)
|
||||
return nil, nil, fmt.Errorf("failed to create certificate: %s", err)
|
||||
}
|
||||
|
||||
certBuf := &bytes.Buffer{}
|
||||
err = pem.Encode(certBuf, &pem.Block{Type: "CERTIFICATE", Bytes: derBytes})
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("failed to encode certificate: %v", err)
|
||||
return nil, nil, fmt.Errorf("failed to encode certificate: %s", err)
|
||||
}
|
||||
|
||||
keybytes, err := x509.MarshalECPrivateKey(priv)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("failed to marshal private key: %v", err)
|
||||
return nil, nil, fmt.Errorf("failed to marshal private key: %s", err)
|
||||
}
|
||||
|
||||
keyBuf := &bytes.Buffer{}
|
||||
err = pem.Encode(keyBuf, &pem.Block{Type: "EC PRIVATE KEY", Bytes: keybytes})
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("failed to encode private key: %v", err)
|
||||
return nil, nil, fmt.Errorf("failed to encode private key: %s", err)
|
||||
}
|
||||
|
||||
return certBuf.Bytes(), keyBuf.Bytes(), nil
|
||||
|
@ -21,7 +21,7 @@ const MaxStringSize = IDLength * 2
|
||||
|
||||
// ErrIDStrSize describes an error that indicates the caller specified an ID
|
||||
// string that has too many characters.
|
||||
var ErrIDStrSize = fmt.Errorf("max ID string length is %v bytes", MaxStringSize)
|
||||
var ErrIDStrSize = fmt.Errorf("max ID string length is %d bytes", MaxStringSize)
|
||||
|
||||
// SubnetworkID is used in several of the bitcoin messages and common structures. It
|
||||
// typically represents ripmed160(sha256(data)).
|
||||
@ -63,7 +63,7 @@ func (id *SubnetworkID) CloneBytes() []byte {
|
||||
func (id *SubnetworkID) SetBytes(newID []byte) error {
|
||||
nhlen := len(newID)
|
||||
if nhlen != IDLength {
|
||||
return fmt.Errorf("invalid ID length of %v, want %v", nhlen,
|
||||
return fmt.Errorf("invalid ID length of %d, want %d", nhlen,
|
||||
IDLength)
|
||||
}
|
||||
copy(id[:], newID)
|
||||
|
@ -100,10 +100,10 @@ switch or type assertion. An example of a type switch follows:
|
||||
switch msg := msg.(type) {
|
||||
case *wire.MsgVersion:
|
||||
// The message is a pointer to a MsgVersion struct.
|
||||
fmt.Printf("Protocol version: %v", msg.ProtocolVersion)
|
||||
fmt.Printf("Protocol version: %d", msg.ProtocolVersion)
|
||||
case *wire.MsgBlock:
|
||||
// The message is a pointer to a MsgBlock struct.
|
||||
fmt.Printf("Number of tx in block: %v", msg.Header.TxnCount)
|
||||
fmt.Printf("Number of tx in block: %d", msg.Header.TxnCount)
|
||||
}
|
||||
|
||||
Reading Messages
|
||||
|
@ -23,7 +23,7 @@ type MessageError struct {
|
||||
// Error satisfies the error interface and prints human-readable errors.
|
||||
func (e *MessageError) Error() string {
|
||||
if e.Func != "" {
|
||||
return fmt.Sprintf("%v: %v", e.Func, e.Description)
|
||||
return fmt.Sprintf("%s: %s", e.Func, e.Description)
|
||||
}
|
||||
return e.Description
|
||||
}
|
||||
|
@ -74,3 +74,7 @@ func readInvVect(r io.Reader, pver uint32, iv *InvVect) error {
|
||||
func writeInvVect(w io.Writer, pver uint32, iv *InvVect) error {
|
||||
return writeElements(w, iv.Type, &iv.Hash)
|
||||
}
|
||||
|
||||
func (iv *InvVect) String() string {
|
||||
return fmt.Sprintf("{%s:%s}", iv.Type, iv.Hash)
|
||||
}
|
||||
|
@ -230,7 +230,7 @@ func WriteMessageN(w io.Writer, msg Message, pver uint32, btcnet BitcoinNet) (in
|
||||
var command [CommandSize]byte
|
||||
cmd := msg.Command()
|
||||
if len(cmd) > CommandSize {
|
||||
str := fmt.Sprintf("command [%s] is too long [max %v]",
|
||||
str := fmt.Sprintf("command [%s] is too long [max %d]",
|
||||
cmd, CommandSize)
|
||||
return totalBytes, messageError("WriteMessage", str)
|
||||
}
|
||||
@ -323,7 +323,7 @@ func ReadMessageN(r io.Reader, pver uint32, btcnet BitcoinNet) (int, Message, []
|
||||
// Check for messages from the wrong bitcoin network.
|
||||
if hdr.magic != btcnet {
|
||||
discardInput(r, hdr.length)
|
||||
str := fmt.Sprintf("message from other network [%v]", hdr.magic)
|
||||
str := fmt.Sprintf("message from other network [%s]", hdr.magic)
|
||||
return totalBytes, nil, nil, messageError("ReadMessage", str)
|
||||
}
|
||||
|
||||
@ -331,7 +331,7 @@ func ReadMessageN(r io.Reader, pver uint32, btcnet BitcoinNet) (int, Message, []
|
||||
command := hdr.command
|
||||
if !utf8.ValidString(command) {
|
||||
discardInput(r, hdr.length)
|
||||
str := fmt.Sprintf("invalid command %v", []byte(command))
|
||||
str := fmt.Sprintf("invalid command %d", []byte(command))
|
||||
return totalBytes, nil, nil, messageError("ReadMessage", str)
|
||||
}
|
||||
|
||||
@ -350,8 +350,8 @@ func ReadMessageN(r io.Reader, pver uint32, btcnet BitcoinNet) (int, Message, []
|
||||
if hdr.length > mpl {
|
||||
discardInput(r, hdr.length)
|
||||
str := fmt.Sprintf("payload exceeds max length - header "+
|
||||
"indicates %v bytes, but max payload size for "+
|
||||
"messages of type [%v] is %v.", hdr.length, command, mpl)
|
||||
"indicates %d bytes, but max payload size for "+
|
||||
"messages of type [%s] is %d.", hdr.length, command, mpl)
|
||||
return totalBytes, nil, nil, messageError("ReadMessage", str)
|
||||
}
|
||||
|
||||
@ -367,7 +367,7 @@ func ReadMessageN(r io.Reader, pver uint32, btcnet BitcoinNet) (int, Message, []
|
||||
checksum := daghash.DoubleHashB(payload)[0:4]
|
||||
if !bytes.Equal(checksum[:], hdr.checksum[:]) {
|
||||
str := fmt.Sprintf("payload checksum failed - header "+
|
||||
"indicates %v, but actual checksum is %v.",
|
||||
"indicates %x, but actual checksum is %x.",
|
||||
hdr.checksum, checksum)
|
||||
return totalBytes, nil, nil, messageError("ReadMessage", str)
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ type MsgAddr struct {
|
||||
// AddAddress adds a known active peer to the message.
|
||||
func (msg *MsgAddr) AddAddress(na *NetAddress) error {
|
||||
if len(msg.AddrList)+1 > MaxAddrPerMsg {
|
||||
str := fmt.Sprintf("too many addresses in message [max %v]",
|
||||
str := fmt.Sprintf("too many addresses in message [max %d]",
|
||||
MaxAddrPerMsg)
|
||||
return messageError("MsgAddr.AddAddress", str)
|
||||
}
|
||||
@ -66,7 +66,7 @@ func (msg *MsgAddr) BtcDecode(r io.Reader, pver uint32) error {
|
||||
// Limit to max addresses per message.
|
||||
if count > MaxAddrPerMsg {
|
||||
str := fmt.Sprintf("too many addresses for message "+
|
||||
"[count %v, max %v]", count, MaxAddrPerMsg)
|
||||
"[count %d, max %d]", count, MaxAddrPerMsg)
|
||||
return messageError("MsgAddr.BtcDecode", str)
|
||||
}
|
||||
|
||||
@ -91,7 +91,7 @@ func (msg *MsgAddr) BtcEncode(w io.Writer, pver uint32) error {
|
||||
count := len(msg.AddrList)
|
||||
if count > MaxAddrPerMsg {
|
||||
str := fmt.Sprintf("too many addresses for message "+
|
||||
"[count %v, max %v]", count, MaxAddrPerMsg)
|
||||
"[count %d, max %d]", count, MaxAddrPerMsg)
|
||||
return messageError("MsgAddr.BtcEncode", str)
|
||||
}
|
||||
|
||||
|
@ -158,7 +158,7 @@ func (alert *Alert) Serialize(w io.Writer, pver uint32) error {
|
||||
count := len(alert.SetCancel)
|
||||
if count > maxCountSetCancel {
|
||||
str := fmt.Sprintf("too many cancel alert IDs for alert "+
|
||||
"[count %v, max %v]", count, maxCountSetCancel)
|
||||
"[count %d, max %d]", count, maxCountSetCancel)
|
||||
return messageError("Alert.Serialize", str)
|
||||
}
|
||||
err = WriteVarInt(w, pver, uint64(count))
|
||||
@ -180,7 +180,7 @@ func (alert *Alert) Serialize(w io.Writer, pver uint32) error {
|
||||
count = len(alert.SetSubVer)
|
||||
if count > maxCountSetSubVer {
|
||||
str := fmt.Sprintf("too many sub versions for alert "+
|
||||
"[count %v, max %v]", count, maxCountSetSubVer)
|
||||
"[count %d, max %d]", count, maxCountSetSubVer)
|
||||
return messageError("Alert.Serialize", str)
|
||||
}
|
||||
err = WriteVarInt(w, pver, uint64(count))
|
||||
@ -227,7 +227,7 @@ func (alert *Alert) Deserialize(r io.Reader, pver uint32) error {
|
||||
}
|
||||
if count > maxCountSetCancel {
|
||||
str := fmt.Sprintf("too many cancel alert IDs for alert "+
|
||||
"[count %v, max %v]", count, maxCountSetCancel)
|
||||
"[count %d, max %d]", count, maxCountSetCancel)
|
||||
return messageError("Alert.Deserialize", str)
|
||||
}
|
||||
alert.SetCancel = make([]int32, count)
|
||||
@ -251,7 +251,7 @@ func (alert *Alert) Deserialize(r io.Reader, pver uint32) error {
|
||||
}
|
||||
if count > maxCountSetSubVer {
|
||||
str := fmt.Sprintf("too many sub versions for alert "+
|
||||
"[count %v, max %v]", count, maxCountSetSubVer)
|
||||
"[count %d, max %d]", count, maxCountSetSubVer)
|
||||
return messageError("Alert.Deserialize", str)
|
||||
}
|
||||
alert.SetSubVer = make([]string, count)
|
||||
|
@ -36,7 +36,7 @@ type MsgCFHeaders struct {
|
||||
// AddCFHash adds a new filter hash to the message.
|
||||
func (msg *MsgCFHeaders) AddCFHash(hash *daghash.Hash) error {
|
||||
if len(msg.FilterHashes)+1 > MaxCFHeadersPerMsg {
|
||||
str := fmt.Sprintf("too many block headers in message [max %v]",
|
||||
str := fmt.Sprintf("too many block headers in message [max %d]",
|
||||
MaxBlockHeadersPerMsg)
|
||||
return messageError("MsgCFHeaders.AddCFHash", str)
|
||||
}
|
||||
@ -75,7 +75,7 @@ func (msg *MsgCFHeaders) BtcDecode(r io.Reader, pver uint32) error {
|
||||
// Limit to max committed filter headers per message.
|
||||
if count > MaxCFHeadersPerMsg {
|
||||
str := fmt.Sprintf("too many committed filter headers for "+
|
||||
"message [count %v, max %v]", count,
|
||||
"message [count %d, max %d]", count,
|
||||
MaxBlockHeadersPerMsg)
|
||||
return messageError("MsgCFHeaders.BtcDecode", str)
|
||||
}
|
||||
@ -120,7 +120,7 @@ func (msg *MsgCFHeaders) BtcEncode(w io.Writer, pver uint32) error {
|
||||
count := len(msg.FilterHashes)
|
||||
if count > MaxCFHeadersPerMsg {
|
||||
str := fmt.Sprintf("too many committed filter headers for "+
|
||||
"message [count %v, max %v]", count,
|
||||
"message [count %d, max %d]", count,
|
||||
MaxBlockHeadersPerMsg)
|
||||
return messageError("MsgCFHeaders.BtcEncode", str)
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ func (msg *MsgCFilter) BtcEncode(w io.Writer, pver uint32) error {
|
||||
size := len(msg.Data)
|
||||
if size > MaxCFilterDataSize {
|
||||
str := fmt.Sprintf("cfilter size too large for message "+
|
||||
"[size %v, max %v]", size, MaxCFilterDataSize)
|
||||
"[size %d, max %d]", size, MaxCFilterDataSize)
|
||||
return messageError("MsgCFilter.BtcEncode", str)
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ func (msg *MsgFilterAdd) BtcEncode(w io.Writer, pver uint32) error {
|
||||
size := len(msg.Data)
|
||||
if size > MaxFilterAddDataSize {
|
||||
str := fmt.Sprintf("filteradd size too large for message "+
|
||||
"[size %v, max %v]", size, MaxFilterAddDataSize)
|
||||
"[size %d, max %d]", size, MaxFilterAddDataSize)
|
||||
return messageError("MsgFilterAdd.BtcEncode", str)
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,7 @@ func (msg *MsgFilterLoad) BtcDecode(r io.Reader, pver uint32) error {
|
||||
|
||||
if msg.HashFuncs > MaxFilterLoadHashFuncs {
|
||||
str := fmt.Sprintf("too many filter hash functions for message "+
|
||||
"[count %v, max %v]", msg.HashFuncs, MaxFilterLoadHashFuncs)
|
||||
"[count %d, max %d]", msg.HashFuncs, MaxFilterLoadHashFuncs)
|
||||
return messageError("MsgFilterLoad.BtcDecode", str)
|
||||
}
|
||||
|
||||
@ -79,13 +79,13 @@ func (msg *MsgFilterLoad) BtcEncode(w io.Writer, pver uint32) error {
|
||||
size := len(msg.Filter)
|
||||
if size > MaxFilterLoadFilterSize {
|
||||
str := fmt.Sprintf("filterload filter size too large for message "+
|
||||
"[size %v, max %v]", size, MaxFilterLoadFilterSize)
|
||||
"[size %d, max %d]", size, MaxFilterLoadFilterSize)
|
||||
return messageError("MsgFilterLoad.BtcEncode", str)
|
||||
}
|
||||
|
||||
if msg.HashFuncs > MaxFilterLoadHashFuncs {
|
||||
str := fmt.Sprintf("too many filter hash functions for message "+
|
||||
"[count %v, max %v]", msg.HashFuncs, MaxFilterLoadHashFuncs)
|
||||
"[count %d, max %d]", msg.HashFuncs, MaxFilterLoadHashFuncs)
|
||||
return messageError("MsgFilterLoad.BtcEncode", str)
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ type MsgGetBlocks struct {
|
||||
// AddBlockLocatorHash adds a new block locator hash to the message.
|
||||
func (msg *MsgGetBlocks) AddBlockLocatorHash(hash *daghash.Hash) error {
|
||||
if len(msg.BlockLocatorHashes)+1 > MaxBlockLocatorsPerMsg {
|
||||
str := fmt.Sprintf("too many block locator hashes for message [max %v]",
|
||||
str := fmt.Sprintf("too many block locator hashes for message [max %d]",
|
||||
MaxBlockLocatorsPerMsg)
|
||||
return messageError("MsgGetBlocks.AddBlockLocatorHash", str)
|
||||
}
|
||||
@ -63,7 +63,7 @@ func (msg *MsgGetBlocks) BtcDecode(r io.Reader, pver uint32) error {
|
||||
}
|
||||
if count > MaxBlockLocatorsPerMsg {
|
||||
str := fmt.Sprintf("too many block locator hashes for message "+
|
||||
"[count %v, max %v]", count, MaxBlockLocatorsPerMsg)
|
||||
"[count %d, max %d]", count, MaxBlockLocatorsPerMsg)
|
||||
return messageError("MsgGetBlocks.BtcDecode", str)
|
||||
}
|
||||
|
||||
@ -89,7 +89,7 @@ func (msg *MsgGetBlocks) BtcEncode(w io.Writer, pver uint32) error {
|
||||
count := len(msg.BlockLocatorHashes)
|
||||
if count > MaxBlockLocatorsPerMsg {
|
||||
str := fmt.Sprintf("too many block locator hashes for message "+
|
||||
"[count %v, max %v]", count, MaxBlockLocatorsPerMsg)
|
||||
"[count %d, max %d]", count, MaxBlockLocatorsPerMsg)
|
||||
return messageError("MsgGetBlocks.BtcEncode", str)
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ type MsgGetData struct {
|
||||
// AddInvVect adds an inventory vector to the message.
|
||||
func (msg *MsgGetData) AddInvVect(iv *InvVect) error {
|
||||
if len(msg.InvList)+1 > MaxInvPerMsg {
|
||||
str := fmt.Sprintf("too many invvect in message [max %v]",
|
||||
str := fmt.Sprintf("too many invvect in message [max %d]",
|
||||
MaxInvPerMsg)
|
||||
return messageError("MsgGetData.AddInvVect", str)
|
||||
}
|
||||
@ -45,7 +45,7 @@ func (msg *MsgGetData) BtcDecode(r io.Reader, pver uint32) error {
|
||||
|
||||
// Limit to max inventory vectors per message.
|
||||
if count > MaxInvPerMsg {
|
||||
str := fmt.Sprintf("too many invvect in message [%v]", count)
|
||||
str := fmt.Sprintf("too many invvect in message [%d]", count)
|
||||
return messageError("MsgGetData.BtcDecode", str)
|
||||
}
|
||||
|
||||
@ -71,7 +71,7 @@ func (msg *MsgGetData) BtcEncode(w io.Writer, pver uint32) error {
|
||||
// Limit to max inventory vectors per message.
|
||||
count := len(msg.InvList)
|
||||
if count > MaxInvPerMsg {
|
||||
str := fmt.Sprintf("too many invvect in message [%v]", count)
|
||||
str := fmt.Sprintf("too many invvect in message [%d]", count)
|
||||
return messageError("MsgGetData.BtcEncode", str)
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ type MsgGetHeaders struct {
|
||||
// AddBlockLocatorHash adds a new block locator hash to the message.
|
||||
func (msg *MsgGetHeaders) AddBlockLocatorHash(hash *daghash.Hash) error {
|
||||
if len(msg.BlockLocatorHashes)+1 > MaxBlockLocatorsPerMsg {
|
||||
str := fmt.Sprintf("too many block locator hashes for message [max %v]",
|
||||
str := fmt.Sprintf("too many block locator hashes for message [max %d]",
|
||||
MaxBlockLocatorsPerMsg)
|
||||
return messageError("MsgGetHeaders.AddBlockLocatorHash", str)
|
||||
}
|
||||
@ -60,7 +60,7 @@ func (msg *MsgGetHeaders) BtcDecode(r io.Reader, pver uint32) error {
|
||||
}
|
||||
if count > MaxBlockLocatorsPerMsg {
|
||||
str := fmt.Sprintf("too many block locator hashes for message "+
|
||||
"[count %v, max %v]", count, MaxBlockLocatorsPerMsg)
|
||||
"[count %d, max %d]", count, MaxBlockLocatorsPerMsg)
|
||||
return messageError("MsgGetHeaders.BtcDecode", str)
|
||||
}
|
||||
|
||||
@ -87,7 +87,7 @@ func (msg *MsgGetHeaders) BtcEncode(w io.Writer, pver uint32) error {
|
||||
count := len(msg.BlockLocatorHashes)
|
||||
if count > MaxBlockLocatorsPerMsg {
|
||||
str := fmt.Sprintf("too many block locator hashes for message "+
|
||||
"[count %v, max %v]", count, MaxBlockLocatorsPerMsg)
|
||||
"[count %d, max %d]", count, MaxBlockLocatorsPerMsg)
|
||||
return messageError("MsgGetHeaders.BtcEncode", str)
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ type MsgHeaders struct {
|
||||
// AddBlockHeader adds a new block header to the message.
|
||||
func (msg *MsgHeaders) AddBlockHeader(bh *BlockHeader) error {
|
||||
if len(msg.Headers)+1 > MaxBlockHeadersPerMsg {
|
||||
str := fmt.Sprintf("too many block headers in message [max %v]",
|
||||
str := fmt.Sprintf("too many block headers in message [max %d]",
|
||||
MaxBlockHeadersPerMsg)
|
||||
return messageError("MsgHeaders.AddBlockHeader", str)
|
||||
}
|
||||
@ -45,7 +45,7 @@ func (msg *MsgHeaders) BtcDecode(r io.Reader, pver uint32) error {
|
||||
// Limit to max block headers per message.
|
||||
if count > MaxBlockHeadersPerMsg {
|
||||
str := fmt.Sprintf("too many block headers for message "+
|
||||
"[count %v, max %v]", count, MaxBlockHeadersPerMsg)
|
||||
"[count %d, max %d]", count, MaxBlockHeadersPerMsg)
|
||||
return messageError("MsgHeaders.BtcDecode", str)
|
||||
}
|
||||
|
||||
@ -68,7 +68,7 @@ func (msg *MsgHeaders) BtcDecode(r io.Reader, pver uint32) error {
|
||||
// Ensure the transaction count is zero for headers.
|
||||
if txCount > 0 {
|
||||
str := fmt.Sprintf("block headers may not contain "+
|
||||
"transactions [count %v]", txCount)
|
||||
"transactions [count %d]", txCount)
|
||||
return messageError("MsgHeaders.BtcDecode", str)
|
||||
}
|
||||
msg.AddBlockHeader(bh)
|
||||
@ -84,7 +84,7 @@ func (msg *MsgHeaders) BtcEncode(w io.Writer, pver uint32) error {
|
||||
count := len(msg.Headers)
|
||||
if count > MaxBlockHeadersPerMsg {
|
||||
str := fmt.Sprintf("too many block headers for message "+
|
||||
"[count %v, max %v]", count, MaxBlockHeadersPerMsg)
|
||||
"[count %d, max %d]", count, MaxBlockHeadersPerMsg)
|
||||
return messageError("MsgHeaders.BtcEncode", str)
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ type MsgInv struct {
|
||||
// AddInvVect adds an inventory vector to the message.
|
||||
func (msg *MsgInv) AddInvVect(iv *InvVect) error {
|
||||
if len(msg.InvList)+1 > MaxInvPerMsg {
|
||||
str := fmt.Sprintf("too many invvect in message [max %v]",
|
||||
str := fmt.Sprintf("too many invvect in message [max %d]",
|
||||
MaxInvPerMsg)
|
||||
return messageError("MsgInv.AddInvVect", str)
|
||||
}
|
||||
@ -53,7 +53,7 @@ func (msg *MsgInv) BtcDecode(r io.Reader, pver uint32) error {
|
||||
|
||||
// Limit to max inventory vectors per message.
|
||||
if count > MaxInvPerMsg {
|
||||
str := fmt.Sprintf("too many invvect in message [%v]", count)
|
||||
str := fmt.Sprintf("too many invvect in message [%d]", count)
|
||||
return messageError("MsgInv.BtcDecode", str)
|
||||
}
|
||||
|
||||
@ -79,7 +79,7 @@ func (msg *MsgInv) BtcEncode(w io.Writer, pver uint32) error {
|
||||
// Limit to max inventory vectors per message.
|
||||
count := len(msg.InvList)
|
||||
if count > MaxInvPerMsg {
|
||||
str := fmt.Sprintf("too many invvect in message [%v]", count)
|
||||
str := fmt.Sprintf("too many invvect in message [%d]", count)
|
||||
return messageError("MsgInv.BtcEncode", str)
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ type MsgMerkleBlock struct {
|
||||
// AddTxHash adds a new transaction hash to the message.
|
||||
func (msg *MsgMerkleBlock) AddTxHash(hash *daghash.Hash) error {
|
||||
if len(msg.Hashes)+1 > maxTxPerBlock {
|
||||
str := fmt.Sprintf("too many tx hashes for message [max %v]",
|
||||
str := fmt.Sprintf("too many tx hashes for message [max %d]",
|
||||
maxTxPerBlock)
|
||||
return messageError("MsgMerkleBlock.AddTxHash", str)
|
||||
}
|
||||
@ -60,7 +60,7 @@ func (msg *MsgMerkleBlock) BtcDecode(r io.Reader, pver uint32) error {
|
||||
}
|
||||
if count > maxTxPerBlock {
|
||||
str := fmt.Sprintf("too many transaction hashes for message "+
|
||||
"[count %v, max %v]", count, maxTxPerBlock)
|
||||
"[count %d, max %d]", count, maxTxPerBlock)
|
||||
return messageError("MsgMerkleBlock.BtcDecode", str)
|
||||
}
|
||||
|
||||
@ -89,13 +89,13 @@ func (msg *MsgMerkleBlock) BtcEncode(w io.Writer, pver uint32) error {
|
||||
numHashes := len(msg.Hashes)
|
||||
if numHashes > maxTxPerBlock {
|
||||
str := fmt.Sprintf("too many transaction hashes for message "+
|
||||
"[count %v, max %v]", numHashes, maxTxPerBlock)
|
||||
"[count %d, max %d]", numHashes, maxTxPerBlock)
|
||||
return messageError("MsgMerkleBlock.BtcDecode", str)
|
||||
}
|
||||
numFlagBytes := len(msg.Flags)
|
||||
if numFlagBytes > maxFlagsPerMerkleBlock {
|
||||
str := fmt.Sprintf("too many flag bytes for message [count %v, "+
|
||||
"max %v]", numFlagBytes, maxFlagsPerMerkleBlock)
|
||||
str := fmt.Sprintf("too many flag bytes for message [count %d, "+
|
||||
"max %d]", numFlagBytes, maxFlagsPerMerkleBlock)
|
||||
return messageError("MsgMerkleBlock.BtcDecode", str)
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ type MsgNotFound struct {
|
||||
// AddInvVect adds an inventory vector to the message.
|
||||
func (msg *MsgNotFound) AddInvVect(iv *InvVect) error {
|
||||
if len(msg.InvList)+1 > MaxInvPerMsg {
|
||||
str := fmt.Sprintf("too many invvect in message [max %v]",
|
||||
str := fmt.Sprintf("too many invvect in message [max %d]",
|
||||
MaxInvPerMsg)
|
||||
return messageError("MsgNotFound.AddInvVect", str)
|
||||
}
|
||||
@ -42,7 +42,7 @@ func (msg *MsgNotFound) BtcDecode(r io.Reader, pver uint32) error {
|
||||
|
||||
// Limit to max inventory vectors per message.
|
||||
if count > MaxInvPerMsg {
|
||||
str := fmt.Sprintf("too many invvect in message [%v]", count)
|
||||
str := fmt.Sprintf("too many invvect in message [%d]", count)
|
||||
return messageError("MsgNotFound.BtcDecode", str)
|
||||
}
|
||||
|
||||
@ -68,7 +68,7 @@ func (msg *MsgNotFound) BtcEncode(w io.Writer, pver uint32) error {
|
||||
// Limit to max inventory vectors per message.
|
||||
count := len(msg.InvList)
|
||||
if count > MaxInvPerMsg {
|
||||
str := fmt.Sprintf("too many invvect in message [%v]", count)
|
||||
str := fmt.Sprintf("too many invvect in message [%d]", count)
|
||||
return messageError("MsgNotFound.BtcEncode", str)
|
||||
}
|
||||
|
||||
|
@ -545,7 +545,7 @@ func (msg *MsgTx) BtcDecode(r io.Reader, pver uint32) error {
|
||||
}
|
||||
|
||||
if msg.SubnetworkID == SubnetworkIDSupportsAll {
|
||||
str := fmt.Sprintf("%v is a reserved sub network and cannot be used as part of a transaction", msg.SubnetworkID)
|
||||
str := fmt.Sprintf("%s is a reserved sub network and cannot be used as part of a transaction", msg.SubnetworkID)
|
||||
return messageError("MsgTx.BtcDecode", str)
|
||||
}
|
||||
|
||||
@ -687,7 +687,7 @@ func (msg *MsgTx) encode(w io.Writer, pver uint32, encodingFlags txEncoding) err
|
||||
|
||||
if msg.SubnetworkID != SubnetworkIDNative {
|
||||
if msg.SubnetworkID == SubnetworkIDRegistry && msg.Gas != 0 {
|
||||
str := fmt.Sprintf("Transactions from subnetwork %v should have 0 gas", msg.SubnetworkID)
|
||||
str := fmt.Sprintf("Transactions from subnetwork %s should have 0 gas", msg.SubnetworkID)
|
||||
return messageError("MsgTx.BtcEncode", str)
|
||||
}
|
||||
|
||||
@ -706,10 +706,10 @@ func (msg *MsgTx) encode(w io.Writer, pver uint32, encodingFlags txEncoding) err
|
||||
return err
|
||||
}
|
||||
} else if msg.Payload != nil {
|
||||
str := fmt.Sprintf("Transactions from subnetwork %v should have <nil> payload", msg.SubnetworkID)
|
||||
str := fmt.Sprintf("Transactions from subnetwork %s should have <nil> payload", msg.SubnetworkID)
|
||||
return messageError("MsgTx.BtcEncode", str)
|
||||
} else if msg.Gas != 0 {
|
||||
str := fmt.Sprintf("Transactions from subnetwork %v should have 0 gas", msg.SubnetworkID)
|
||||
str := fmt.Sprintf("Transactions from subnetwork %s should have 0 gas", msg.SubnetworkID)
|
||||
return messageError("MsgTx.BtcEncode", str)
|
||||
}
|
||||
|
||||
|
@ -254,7 +254,7 @@ func NewMsgVersion(me *NetAddress, you *NetAddress, nonce uint64,
|
||||
// validateUserAgent checks userAgent length against MaxUserAgentLen
|
||||
func validateUserAgent(userAgent string) error {
|
||||
if len(userAgent) > MaxUserAgentLen {
|
||||
str := fmt.Sprintf("user agent too long [len %v, max %v]",
|
||||
str := fmt.Sprintf("user agent too long [len %d, max %d]",
|
||||
len(userAgent), MaxUserAgentLen)
|
||||
return messageError("MsgVersion", str)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user