Skip to content

Commit

Permalink
multi: Remove some unused code
Browse files Browse the repository at this point in the history
Found via golangci-lint --enable=unused
  • Loading branch information
matheusd committed Nov 2, 2022
1 parent 183083d commit 566eff8
Show file tree
Hide file tree
Showing 9 changed files with 1 addition and 208 deletions.
9 changes: 0 additions & 9 deletions chain/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,6 @@ func (s *Syncer) synced() {
}
}

// unsynced checks the atomic that controls wallet syncness and if previously
// synced, updates to unsynced and notifies the callback, if set.
func (s *Syncer) unsynced() {
swapped := atomic.CompareAndSwapUint32(&s.atomicWalletSynced, 1, 0)
if swapped && s.cb != nil && s.cb.Synced != nil {
s.cb.Synced(false)
}
}

func (s *Syncer) fetchMissingCfiltersStart() {
if s.cb != nil && s.cb.FetchMissingCFiltersStarted != nil {
s.cb.FetchMissingCFiltersStarted()
Expand Down
9 changes: 0 additions & 9 deletions p2p/peering.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ const minPver = wire.CFilterV2Version
// Pver is the maximum protocol version implemented by the LocalPeer.
const Pver = wire.InitStateVersion

const maxOutboundConns = 8

// connectTimeout is the amount of time allowed before connecting, peering
// handshake, and protocol negotiation is aborted.
const connectTimeout = 30 * time.Second
Expand Down Expand Up @@ -1449,15 +1447,8 @@ type filterProof = struct {
// Note: returning a []func() is an ugly hack to prevent a cyclical dependency
// between the rpc package and the wallet package.
func (rp *RemotePeer) CFiltersV2(ctx context.Context, blockHashes []*chainhash.Hash) ([]filterProof, error) {
const opf = "remotepeer(%v).CFiltersV2"

// TODO: this is spammy and would be better implemented with a single
// request/response.
type result struct {
filter *gcs.FilterV2
proofIndex uint32
proof []chainhash.Hash
}
filters := make([]filterProof, len(blockHashes))
g, ctx := errgroup.WithContext(ctx)
for i := range blockHashes {
Expand Down
69 changes: 0 additions & 69 deletions wallet/addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -630,75 +630,6 @@ func (w *Wallet) nextAddress(ctx context.Context, op errors.Op, persist persistR
}
}

func (w *Wallet) nextImportedXpubAddress(ctx context.Context, op errors.Op,
maybeDBTX walletdb.ReadWriteTx, accountName string, account uint32, branch uint32,
callOpts ...NextAddressCallOption) (addr stdaddr.Address, err error) {

dbtx := maybeDBTX
if dbtx == nil {
dbtx, err = w.db.BeginReadWriteTx()
if err != nil {
return nil, err
}
defer func() {
if err == nil {
err = dbtx.Commit()
} else {
dbtx.Rollback()
}
}()
}

ns := dbtx.ReadWriteBucket(waddrmgrNamespaceKey)
xpub, err := w.manager.AccountExtendedPubKey(dbtx, account)
if err != nil {
return nil, errors.E(op, err)
}
props, err := w.manager.AccountProperties(ns, account)
branchKey, err := xpub.Child(branch)
if err != nil {
return nil, errors.E(op, err)
}
var childKey *hdkeychain.ExtendedKey
var child uint32
switch branch {
case 0:
child = props.LastReturnedExternalIndex + 1
case 1:
child = props.LastReturnedInternalIndex + 1
default:
return nil, errors.E(op, "branch is required to be 0 or 1")
}
for {
childKey, err = branchKey.Child(child)
if err == hdkeychain.ErrInvalidChild {
child++
continue
}
if err != nil {
return nil, errors.E(op, err)
}
break
}
pkh := dcrutil.Hash160(childKey.SerializedPubKey())
apkh, err := stdaddr.NewAddressPubKeyHashEcdsaSecp256k1V0(pkh, w.chainParams)
if err != nil {
return nil, errors.E(op, err)
}
addr = &xpubAddress{
AddressPubKeyHashEcdsaSecp256k1V0: apkh,
xpub: xpub,
account: account,
branch: branch,
child: child,
}
err = w.manager.MarkReturnedChildIndex(dbtx, account, branch, child)
if err != nil {
return nil, errors.E(op, err)
}
return addr, nil
}

func minUint32(a, b uint32) uint32 {
if a < b {
return a
Expand Down
78 changes: 0 additions & 78 deletions wallet/createtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -2120,12 +2120,6 @@ func (w *Wallet) signVote(addrmgrNs walletdb.ReadBucket, ticketPurchase, vote *w
return w.signVoteOrRevocation(addrmgrNs, ticketPurchase, vote, true)
}

// signRevocation signs a revocation transaction. This modifes the input
// scripts pointed to by the revocation transaction.
func (w *Wallet) signRevocation(addrmgrNs walletdb.ReadBucket, ticketPurchase, revocation *wire.MsgTx) error {
return w.signVoteOrRevocation(addrmgrNs, ticketPurchase, revocation, false)
}

// newVoteScript generates a voting script from the passed VoteBits, for
// use in a vote.
func newVoteScript(voteBits stake.VoteBits) ([]byte, error) {
Expand Down Expand Up @@ -2217,75 +2211,3 @@ func createUnsignedVote(ticketHash *chainhash.Hash, ticketPurchase *wire.MsgTx,

return vote, nil
}

// createUnsignedRevocation creates an unsigned revocation transaction that
// revokes a missed or expired ticket. Revocations must carry a relay fee and
// this function can error if the revocation contains no suitable output to
// decrease the estimated relay fee from.
func createUnsignedRevocation(ticketHash *chainhash.Hash, ticketPurchase *wire.MsgTx,
feePerKB dcrutil.Amount, params *chaincfg.Params) (*wire.MsgTx, error) {

// Parse the ticket purchase transaction to determine the required output
// destinations for vote rewards or revocations.
ticketPayKinds, ticketHash160s, ticketValues, _, _, _ :=
stake.TxSStxStakeOutputInfo(ticketPurchase)

// Calculate the output values for the revocation. Revocations do not
// contain any subsidy.
revocationValues := stake.CalculateRewards(ticketValues,
ticketPurchase.TxOut[0].Value, 0)

// Begin constructing the revocation transaction.
revocation := wire.NewMsgTx()

// Revocations reference the ticket purchase with the first (and only)
// input.
ticketOutPoint := wire.NewOutPoint(ticketHash, 0, wire.TxTreeStake)
ticketInput := wire.NewTxIn(ticketOutPoint,
ticketPurchase.TxOut[ticketOutPoint.Index].Value, nil)
revocation.AddTxIn(ticketInput)
scriptSizes := []int{txsizes.RedeemP2SHSigScriptSize}

// All remaining outputs pay to the output destinations and amounts tagged
// by the ticket purchase.
for i, hash160 := range ticketHash160s {
var addr stdaddr.StakeAddress
var err error
if ticketPayKinds[i] { // P2SH
addr, err = stdaddr.NewAddressScriptHashV0FromHash(hash160, params)
} else { // P2PKH
addr, err = stdaddr.NewAddressPubKeyHashEcdsaSecp256k1V0(hash160, params)
}
if err != nil {
return nil, err
}
vers, script := addr.PayRevokeCommitmentScript()
revocation.AddTxOut(&wire.TxOut{
Value: revocationValues[i],
Version: vers,
PkScript: script,
})
}

// Revocations must pay a fee but do so by decreasing one of the output
// values instead of increasing the input value and using a change output.
// Calculate the estimated signed serialize size.
sizeEstimate := txsizes.EstimateSerializeSize(scriptSizes, revocation.TxOut, 0)
feeEstimate := txrules.FeeForSerializeSize(feePerKB, sizeEstimate)

// Reduce the output value of one of the outputs to accommodate for the relay
// fee. To avoid creating dust outputs, a suitable output value is reduced
// by the fee estimate only if it is large enough to not create dust. This
// code does not currently handle reducing the output values of multiple
// commitment outputs to accommodate for the fee.
for _, output := range revocation.TxOut {
if dcrutil.Amount(output.Value) > feeEstimate {
amount := dcrutil.Amount(output.Value) - feeEstimate
if !txrules.IsDustAmount(amount, len(output.PkScript), feePerKB) {
output.Value = int64(amount)
return revocation, nil
}
}
}
return nil, errors.New("missing suitable revocation output to pay relay fee")
}
7 changes: 0 additions & 7 deletions wallet/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ func UseLogger(logger slog.Logger) {
log = logger
}

type infoLogger struct{}

var infoLog infoLogger

func (infoLogger) Print(args ...interface{}) { log.Info(args...) }
func (infoLogger) Printf(format string, args ...interface{}) { log.Infof(format, args...) }

type debugLogger struct{}

var debugLog debugLogger
Expand Down
7 changes: 0 additions & 7 deletions wallet/udb/addressmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -1877,13 +1877,6 @@ func (m *Manager) accountHasPassphrase(ns walletdb.ReadBucket, account uint32) (
return
}

func maxUint32(a, b uint32) uint32 {
if a > b {
return a
}
return b
}

// MarkUsed updates usage statistics of a BIP0044 account address so that the
// last used address index can be tracked. There is no effect when called on
// P2SH addresses or any imported addresses.
Expand Down
7 changes: 0 additions & 7 deletions wallet/udb/txmined.go
Original file line number Diff line number Diff line change
Expand Up @@ -2783,13 +2783,6 @@ func ticketMatured(params *chaincfg.Params, txHeight, curHeight int32) bool {
return txHeight >= 0 && curHeight-txHeight > int32(params.TicketMaturity)
}

// ticketExpired returns whether a ticket mined at txHeight has
// reached ticket expiry in a chain with a tip height curHeight.
func ticketExpired(params *chaincfg.Params, txHeight, curHeight int32) bool {
// Ticket maturity off-by-one extends to the expiry depth as well.
return txHeight >= 0 && curHeight-txHeight > int32(params.TicketMaturity)+int32(params.TicketExpiry)
}

func (s *Store) fastCreditPkScriptLookup(ns walletdb.ReadBucket, credKey []byte, unminedCredKey []byte) ([]byte, error) {
// It has to exists as a credit or an unmined credit.
// Look both of these up. If it doesn't, throw an
Expand Down
2 changes: 0 additions & 2 deletions wallet/udb/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,6 @@ func verifyV6Upgrade(ctx context.Context, t *testing.T, db walletdb.DB) {
decodeHash("bca8c2649860585f10b27d774b354ea7b80007e9ad79c090ea05596d63995cf5"),
}

const dbVersion = 6

c := ns.NestedReadBucket(bucketTickets).ReadCursor()
found := 0
for k, v := c.First(); k != nil; k, v = c.Next() {
Expand Down
21 changes: 1 addition & 20 deletions wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -1490,25 +1490,6 @@ func (w *Wallet) FetchMissingCFiltersWithProgress(ctx context.Context, p Peer, p
}
}

// createHeaderData creates the header data to process from hex-encoded
// serialized block headers.
func createHeaderData(headers []*wire.BlockHeader) ([]udb.BlockHeaderData, error) {
data := make([]udb.BlockHeaderData, len(headers))
var buf bytes.Buffer
for i, header := range headers {
var headerData udb.BlockHeaderData
headerData.BlockHash = header.BlockHash()
buf.Reset()
err := header.Serialize(&buf)
if err != nil {
return nil, err
}
copy(headerData.SerializedHeader[:], buf.Bytes())
data[i] = headerData
}
return data, nil
}

// log2 calculates an integer approximation of log2(x). This is used to
// approximate the cap to use when allocating memory for the block locators.
func log2(x int) int {
Expand Down Expand Up @@ -3863,7 +3844,7 @@ func votingXprivFromSeed(seed []byte, params *chaincfg.Params) (*hdkeychain.Exte

seedSize := len(seed)
if seedSize < hdkeychain.MinSeedBytes || seedSize > hdkeychain.MaxSeedBytes {
return nil, errors.E(errors.Invalid, errors.New("invalid seed length"))
return nil, errors.E(op, errors.Invalid, errors.New("invalid seed length"))
}

// Generate the BIP0044 HD key structure to ensure the provided seed
Expand Down

0 comments on commit 566eff8

Please sign in to comment.