Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

multi: various cleanups #1019

Merged
merged 1 commit into from
Feb 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions blockchain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -626,11 +626,7 @@ func (b *BlockChain) fetchBlockByHash(hash *chainhash.Hash) (*dcrutil.Block, err
}

block, err = dcrutil.NewBlockFromBytes(blockBytes)
if err != nil {
return err
}

return nil
return err
})
if err == nil && block != nil {
return block, nil
Expand Down
6 changes: 6 additions & 0 deletions blockchain/reorganization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ func reorgTestForced(t *testing.T, params *chaincfg.Params) {
// Load up the rest of the blocks up to HEAD.
filename := filepath.Join("testdata/", "reorgto179.bz2")
fi, err := os.Open(filename)
if err != nil {
t.Errorf("Failed to open %s: %v", filename, err)
}
bcStream := bzip2.NewReader(fi)
defer fi.Close()

Expand Down Expand Up @@ -305,6 +308,9 @@ func reorgTestForced(t *testing.T, params *chaincfg.Params) {
// Load up the rest of the blocks up to HEAD.
filename = filepath.Join("testdata/", "reorgto180.bz2")
fi, err = os.Open(filename)
if err != nil {
t.Errorf("Failed to open %s: %v", filename, err)
}
bcStream = bzip2.NewReader(fi)
defer fi.Close()

Expand Down
3 changes: 3 additions & 0 deletions blockchain/stake/tickets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,9 @@ func TestTicketDBGeneral(t *testing.T) {
testBCHeight := int64(168)
filename := filepath.Join("..", "/../blockchain/testdata", "blocks0to168.bz2")
fi, err := os.Open(filename)
if err != nil {
t.Errorf("Failed to open %s: %v", filename, err)
}
bcStream := bzip2.NewReader(fi)
defer fi.Close()

Expand Down
6 changes: 6 additions & 0 deletions blockchain/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ func TestBlockValidationRules(t *testing.T) {
// Load up the rest of the blocks up to HEAD~1.
filename := filepath.Join("testdata/", "blocks0to168.bz2")
fi, err := os.Open(filename)
if err != nil {
t.Errorf("Failed to open %s: %v", filename, err)
}
bcStream := bzip2.NewReader(fi)
defer fi.Close()

Expand Down Expand Up @@ -1921,6 +1924,9 @@ func TestBlockchainSpendJournal(t *testing.T) {
// Load up the rest of the blocks up to HEAD.
filename := filepath.Join("testdata/", "reorgto179.bz2")
fi, err := os.Open(filename)
if err != nil {
t.Errorf("Failed to open %s: %v", filename, err)
}
bcStream := bzip2.NewReader(fi)
defer fi.Close()

Expand Down
40 changes: 0 additions & 40 deletions rpcwebsocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,42 +442,6 @@ func (f *wsClientFilter) existsAddress(a dcrutil.Address) bool {
return ok
}

func (f *wsClientFilter) removeAddress(a dcrutil.Address) {
switch a := a.(type) {
case *dcrutil.AddressPubKeyHash:
delete(f.pubKeyHashes, *a.Hash160())
return
case *dcrutil.AddressScriptHash:
delete(f.scriptHashes, *a.Hash160())
return
case *dcrutil.AddressSecpPubKey:
serializedPubKey := a.ScriptAddress()
switch len(serializedPubKey) {
case 33: // compressed
var compressedPubKey [33]byte
copy(compressedPubKey[:], serializedPubKey)
delete(f.compressedPubKeys, compressedPubKey)
return
case 65: // uncompressed
var uncompressedPubKey [65]byte
copy(uncompressedPubKey[:], serializedPubKey)
delete(f.uncompressedPubKeys, uncompressedPubKey)
return
}
}

delete(f.otherAddresses, a.EncodeAddress())
}

func (f *wsClientFilter) removeAddressStr(s string) {
a, err := dcrutil.DecodeAddress(s)
if err == nil {
f.removeAddress(a)
} else {
delete(f.otherAddresses, s)
}
}

func (f *wsClientFilter) addUnspentOutPoint(op *wire.OutPoint) {
f.unspent[*op] = struct{}{}
}
Expand All @@ -487,10 +451,6 @@ func (f *wsClientFilter) existsUnspentOutPoint(op *wire.OutPoint) bool {
return ok
}

func (f *wsClientFilter) removeUnspentOutPoint(op *wire.OutPoint) {
delete(f.unspent, *op)
}

// Notification types
type notificationBlockConnected dcrutil.Block
type notificationBlockDisconnected dcrutil.Block
Expand Down
25 changes: 14 additions & 11 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1291,7 +1291,7 @@ func (s *server) handleAddPeerMsg(state *peerState, sp *serverPeer) bool {
srvrLog.Infof("Max peers reached [%d] - disconnecting peer %s",
cfg.MaxPeers, sp)
sp.Disconnect()
// TODO(oga) how to handle permanent peers here?
// TODO: how to handle permanent peers here?
// they should be rescheduled.
return false
}
Expand Down Expand Up @@ -1495,7 +1495,7 @@ func (s *server) handleQuery(state *peerState, querymsg interface{}) {
msg.reply <- peers

case connectNodeMsg:
// XXX(oga) duplicate oneshots?
// XXX duplicate oneshots?
// Limit max number of total peers.
if state.Count() >= cfg.MaxPeers {
msg.reply <- errors.New("max peers reached")
Expand All @@ -1518,7 +1518,7 @@ func (s *server) handleQuery(state *peerState, querymsg interface{}) {
return
}

// TODO(oga) if too many, nuke a non-perm peer.
// TODO: if too many, nuke a non-perm peer.
go s.connManager.Connect(&connmgr.ConnReq{
Addr: netAddr,
Permanent: msg.permanent,
Expand Down Expand Up @@ -2165,9 +2165,9 @@ out:
for {
select {
case <-timer.C:
// TODO(oga) pick external port more cleverly
// TODO(oga) know which ports we are listening to on an external net.
// TODO(oga) if specific listen port doesn't work then ask for wildcard
// TODO: pick external port more cleverly
// TODO: know which ports we are listening to on an external net.
// TODO: if specific listen port doesn't work then ask for wildcard
// listen port?
// XXX this assumes timeout is in seconds.
listenPort, err := s.nat.AddPortMapping("tcp", int(lport), int(lport),
Expand All @@ -2176,7 +2176,7 @@ out:
srvrLog.Warnf("can't add UPnP port mapping: %v", err)
}
if first && err == nil {
// TODO(oga): look this up periodically to see if upnp domain changed
// TODO: look this up periodically to see if upnp domain changed
// and so did ip.
externalip, err := s.nat.GetExternalAddress()
if err != nil {
Expand All @@ -2187,10 +2187,13 @@ out:
s.services)
err = s.addrManager.AddLocalAddress(na, addrmgr.UpnpPrio)
if err != nil {
// XXX DeletePortMapping?
srvrLog.Warnf("Failed to add UPnP local address %s: %v",
na.IP.String(), err)
} else {
srvrLog.Warnf("Successfully bound via UPnP to %s",
addrmgr.NetAddressKey(na))
first = false
}
srvrLog.Warnf("Successfully bound via UPnP to %s", addrmgr.NetAddressKey(na))
first = false
}
timer.Reset(time.Minute * 15)
case <-s.quit:
Expand Down Expand Up @@ -2294,7 +2297,7 @@ func newServer(listenAddrs []string, db database.DB, chainParams *chaincfg.Param
// nil nat here is fine, just means no upnp on network.
}

// TODO(oga) nonstandard port...
// TODO: nonstandard port...
if wildcard {
port, err :=
strconv.ParseUint(activeNetParams.DefaultPort,
Expand Down
Loading