From fbb6631ff54e7ef4bef1d453e1168cff5c9d125c Mon Sep 17 00:00:00 2001 From: Yongfeng LI Date: Sun, 8 Apr 2018 17:59:39 +0800 Subject: [PATCH] Remove unused code (#548) * remove unused code in accoun and api * remove unused code in crypto * remove unused code in asset and protocol --- account/accounts.go | 9 ++------- api/api_test.go | 1 - api/metrics.go | 28 ---------------------------- asset/asset.go | 4 ---- crypto/crypto.go | 22 ---------------------- protocol/protocol.go | 2 -- 6 files changed, 2 insertions(+), 64 deletions(-) diff --git a/account/accounts.go b/account/accounts.go index c6837c21..cfa6b233 100755 --- a/account/accounts.go +++ b/account/accounts.go @@ -105,7 +105,6 @@ type Manager struct { delayedACPsMu sync.Mutex delayedACPs map[*txbuilder.TemplateBuilder][]*CtrlProgram - acpIndexCap uint64 // points to end of block accIndexMu sync.Mutex } @@ -292,7 +291,7 @@ func (m *Manager) createAddress(ctx context.Context, account *Account, change bo } func (m *Manager) createP2PKH(ctx context.Context, account *Account, change bool) (*CtrlProgram, error) { - idx := m.nextAccountIndex(account) + idx := m.getNextXpubsIndex(account.Signer.XPubs) path := signers.Path(account.Signer, signers.AccountKeySpace, idx) derivedXPubs := chainkd.DeriveXPubs(account.XPubs, path) derivedPK := derivedXPubs[0].PublicKey() @@ -319,7 +318,7 @@ func (m *Manager) createP2PKH(ctx context.Context, account *Account, change bool } func (m *Manager) createP2SH(ctx context.Context, account *Account, change bool) (*CtrlProgram, error) { - idx := m.nextAccountIndex(account) + idx := m.getNextXpubsIndex(account.Signer.XPubs) path := signers.Path(account.Signer, signers.AccountKeySpace, idx) derivedXPubs := chainkd.DeriveXPubs(account.XPubs, path) derivedPKs := chainkd.XPubKeys(derivedXPubs) @@ -413,10 +412,6 @@ func (m *Manager) GetCoinbaseControlProgram() ([]byte, error) { return program.ControlProgram, nil } -func (m *Manager) nextAccountIndex(account *Account) uint64 { - return m.getNextXpubsIndex(account.Signer.XPubs) -} - // DeleteAccount deletes the account's ID or alias matching accountInfo. func (m *Manager) DeleteAccount(in struct { AccountInfo string `json:"account_info"` diff --git a/api/api_test.go b/api/api_test.go index 188c8ea5..5906f0f6 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -36,7 +36,6 @@ func TestAPIHandler(t *testing.T) { path string request interface{} respWant *Response - respWantErr error }{ { path: "/create-key", diff --git a/api/metrics.go b/api/metrics.go index 3ead8a71..32b7410a 100644 --- a/api/metrics.go +++ b/api/metrics.go @@ -1,13 +1,11 @@ package api import ( - "expvar" "net/http" "sync" "time" "github.com/bytom/metrics" - "github.com/bytom/net/http/reqid" ) var ( @@ -42,29 +40,3 @@ func latency(tab *http.ServeMux, req *http.Request) *metrics.RotatingLatency { } return nil } - -var ( - ncoreMu sync.Mutex - ncore = expvar.NewInt("ncore") - ncoreTime time.Time - coresSeen map[string]bool -) - -func coreCounter(h http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { - countCore(reqid.CoreIDFromContext(req.Context())) - h.ServeHTTP(w, req) - }) -} - -func countCore(id string) { - t := time.Now() - ncoreMu.Lock() - defer ncoreMu.Unlock() - if t.Sub(ncoreTime) > time.Minute { - ncore.Set(int64(len(coresSeen))) - ncoreTime = t - coresSeen = make(map[string]bool) - } - coresSeen[id] = true -} diff --git a/asset/asset.go b/asset/asset.go index d2b53a5d..d8b2ff8f 100755 --- a/asset/asset.go +++ b/asset/asset.go @@ -8,7 +8,6 @@ import ( "sync" "github.com/golang/groupcache/lru" - "github.com/golang/groupcache/singleflight" dbm "github.com/tendermint/tmlibs/db" "golang.org/x/crypto/sha3" @@ -97,9 +96,6 @@ type Registry struct { db dbm.DB chain *protocol.Chain - idGroup singleflight.Group - aliasGroup singleflight.Group - cacheMu sync.Mutex cache *lru.Cache aliasCache *lru.Cache diff --git a/crypto/crypto.go b/crypto/crypto.go index 45111b46..cd330372 100644 --- a/crypto/crypto.go +++ b/crypto/crypto.go @@ -48,25 +48,3 @@ func Ripemd160(data []byte) []byte { return ripemd.Sum(nil) } - -func zeroBytes(bytes []byte) { - for i := range bytes { - bytes[i] = 0 - } -} - -func toInt(bytes []byte) []int { - ints := make([]int, len(bytes)) - for i := range bytes { - ints[i] = int(bytes[i]) - } - return ints -} - -func toBytes(ints []int) []byte { - bytes := make([]byte, len(ints)) - for i := range ints { - bytes[i] = byte(ints[i]) - } - return bytes -} diff --git a/protocol/protocol.go b/protocol/protocol.go index 446d4c03..3e80d8df 100755 --- a/protocol/protocol.go +++ b/protocol/protocol.go @@ -15,9 +15,7 @@ import ( "github.com/bytom/protocol/state" ) -// maxCachedValidatedTxs is the max number of validated txs to cache. const ( - maxCachedValidatedTxs = 1000 maxProcessBlockChSize = 1024 ) -- 2.11.0