chain+wallet: rename SPVChain to NeutrinoClient

This commit is contained in:
Alex 2017-05-24 18:52:46 -06:00 committed by Olaoluwa Osuntokun
parent 578e95c4ec
commit 3f12fa3c6c
4 changed files with 26 additions and 25 deletions

View file

@ -179,10 +179,10 @@ func rpcClientConnectLoop(legacyRPCServer *legacyrpc.Server, loader *wallet.Load
log.Errorf("Couldn't create Neutrino ChainService: %s", err) log.Errorf("Couldn't create Neutrino ChainService: %s", err)
continue continue
} }
chainClient = chain.NewSPVChain(chainService) chainClient = chain.NewNeutrinoClient(chainService)
err = chainClient.Start() err = chainClient.Start()
if err != nil { if err != nil {
log.Errorf("Couldn't start SPVChain: %s", err) log.Errorf("Couldn't start Neutrino client: %s", err)
} }
} else { } else {
chainClient, err = startChainRPC(certs) chainClient, err = startChainRPC(certs)

View file

@ -15,8 +15,8 @@ import (
"github.com/lightninglabs/neutrino" "github.com/lightninglabs/neutrino"
) )
// SPVChain is an implementation of the btcwalet chain.Interface interface. // NeutrinoClient is an implementation of the btcwalet chain.Interface interface.
type SPVChain struct { type NeutrinoClient struct {
CS *neutrino.ChainService CS *neutrino.ChainService
// We currently support one rescan/notifiction goroutine per client // We currently support one rescan/notifiction goroutine per client
@ -37,13 +37,14 @@ type SPVChain struct {
clientMtx sync.Mutex clientMtx sync.Mutex
} }
// NewSPVChain creates a new SPVChain struct with a backing ChainService // NewNeutrinoClient creates a new NeutrinoClient struct with a backing
func NewSPVChain(chainService *neutrino.ChainService) *SPVChain { // ChainService.
return &SPVChain{CS: chainService} func NewNeutrinoClient(chainService *neutrino.ChainService) *NeutrinoClient {
return &NeutrinoClient{CS: chainService}
} }
// Start replicates the RPC client's Start method. // Start replicates the RPC client's Start method.
func (s *SPVChain) Start() error { func (s *NeutrinoClient) Start() error {
s.CS.Start() s.CS.Start()
s.clientMtx.Lock() s.clientMtx.Lock()
defer s.clientMtx.Unlock() defer s.clientMtx.Unlock()
@ -67,7 +68,7 @@ func (s *SPVChain) Start() error {
} }
// Stop replicates the RPC client's Stop method. // Stop replicates the RPC client's Stop method.
func (s *SPVChain) Stop() { func (s *NeutrinoClient) Stop() {
s.clientMtx.Lock() s.clientMtx.Lock()
defer s.clientMtx.Unlock() defer s.clientMtx.Unlock()
if !s.started { if !s.started {
@ -78,12 +79,12 @@ func (s *SPVChain) Stop() {
} }
// WaitForShutdown replicates the RPC client's WaitForShutdown method. // WaitForShutdown replicates the RPC client's WaitForShutdown method.
func (s *SPVChain) WaitForShutdown() { func (s *NeutrinoClient) WaitForShutdown() {
s.wg.Wait() s.wg.Wait()
} }
// GetBlock replicates the RPC client's GetBlock command. // GetBlock replicates the RPC client's GetBlock command.
func (s *SPVChain) GetBlock(hash *chainhash.Hash) (*wire.MsgBlock, error) { func (s *NeutrinoClient) GetBlock(hash *chainhash.Hash) (*wire.MsgBlock, error) {
// TODO(roasbeef): add a block cache? // TODO(roasbeef): add a block cache?
// * which evication strategy? depends on use case // * which evication strategy? depends on use case
// Should the block cache be INSIDE neutrino instead of in btcwallet? // Should the block cache be INSIDE neutrino instead of in btcwallet?
@ -98,7 +99,7 @@ func (s *SPVChain) GetBlock(hash *chainhash.Hash) (*wire.MsgBlock, error) {
// replacement for the use of GetBlockVerboseTxAsync for the wallet package // replacement for the use of GetBlockVerboseTxAsync for the wallet package
// since we can't actually return a FutureGetBlockVerboseResult because the // since we can't actually return a FutureGetBlockVerboseResult because the
// underlying type is private to btcrpcclient. // underlying type is private to btcrpcclient.
func (s *SPVChain) GetBlockHeight(hash *chainhash.Hash) (int32, error) { func (s *NeutrinoClient) GetBlockHeight(hash *chainhash.Hash) (int32, error) {
_, height, err := s.CS.GetBlockByHash(*hash) _, height, err := s.CS.GetBlockByHash(*hash)
if err != nil { if err != nil {
return 0, err return 0, err
@ -107,7 +108,7 @@ func (s *SPVChain) GetBlockHeight(hash *chainhash.Hash) (int32, error) {
} }
// GetBestBlock replicates the RPC client's GetBestBlock command. // GetBestBlock replicates the RPC client's GetBestBlock command.
func (s *SPVChain) GetBestBlock() (*chainhash.Hash, int32, error) { func (s *NeutrinoClient) GetBestBlock() (*chainhash.Hash, int32, error) {
header, height, err := s.CS.LatestBlock() header, height, err := s.CS.LatestBlock()
if err != nil { if err != nil {
return nil, 0, err return nil, 0, err
@ -118,7 +119,7 @@ func (s *SPVChain) GetBestBlock() (*chainhash.Hash, int32, error) {
// BlockStamp returns the latest block notified by the client, or an error // BlockStamp returns the latest block notified by the client, or an error
// if the client has been shut down. // if the client has been shut down.
func (s *SPVChain) BlockStamp() (*waddrmgr.BlockStamp, error) { func (s *NeutrinoClient) BlockStamp() (*waddrmgr.BlockStamp, error) {
select { select {
case bs := <-s.currentBlock: case bs := <-s.currentBlock:
return bs, nil return bs, nil
@ -128,7 +129,7 @@ func (s *SPVChain) BlockStamp() (*waddrmgr.BlockStamp, error) {
} }
// SendRawTransaction replicates the RPC client's SendRawTransaction command. // SendRawTransaction replicates the RPC client's SendRawTransaction command.
func (s *SPVChain) SendRawTransaction(tx *wire.MsgTx, allowHighFees bool) ( func (s *NeutrinoClient) SendRawTransaction(tx *wire.MsgTx, allowHighFees bool) (
*chainhash.Hash, error) { *chainhash.Hash, error) {
err := s.CS.SendTransaction(tx) err := s.CS.SendTransaction(tx)
if err != nil { if err != nil {
@ -139,7 +140,7 @@ func (s *SPVChain) SendRawTransaction(tx *wire.MsgTx, allowHighFees bool) (
} }
// Rescan replicates the RPC client's Rescan command. // Rescan replicates the RPC client's Rescan command.
func (s *SPVChain) Rescan(startHash *chainhash.Hash, addrs []btcutil.Address, func (s *NeutrinoClient) Rescan(startHash *chainhash.Hash, addrs []btcutil.Address,
outPoints []*wire.OutPoint) error { outPoints []*wire.OutPoint) error {
s.clientMtx.Lock() s.clientMtx.Lock()
defer s.clientMtx.Unlock() defer s.clientMtx.Unlock()
@ -191,7 +192,7 @@ func (s *SPVChain) Rescan(startHash *chainhash.Hash, addrs []btcutil.Address,
} }
// NotifyBlocks replicates the RPC client's NotifyBlocks command. // NotifyBlocks replicates the RPC client's NotifyBlocks command.
func (s *SPVChain) NotifyBlocks() error { func (s *NeutrinoClient) NotifyBlocks() error {
s.clientMtx.Lock() s.clientMtx.Lock()
// If we're scanning, we're already notifying on blocks. Otherwise, // If we're scanning, we're already notifying on blocks. Otherwise,
// start a rescan without watching any addresses. // start a rescan without watching any addresses.
@ -204,7 +205,7 @@ func (s *SPVChain) NotifyBlocks() error {
} }
// NotifyReceived replicates the RPC client's NotifyReceived command. // NotifyReceived replicates the RPC client's NotifyReceived command.
func (s *SPVChain) NotifyReceived(addrs []btcutil.Address) error { func (s *NeutrinoClient) NotifyReceived(addrs []btcutil.Address) error {
// If we have a rescan running, we just need to add the appropriate // If we have a rescan running, we just need to add the appropriate
// addresses to the watch list. // addresses to the watch list.
s.clientMtx.Lock() s.clientMtx.Lock()
@ -231,13 +232,13 @@ func (s *SPVChain) NotifyReceived(addrs []btcutil.Address) error {
} }
// Notifications replicates the RPC client's Notifications method. // Notifications replicates the RPC client's Notifications method.
func (s *SPVChain) Notifications() <-chan interface{} { func (s *NeutrinoClient) Notifications() <-chan interface{} {
return s.dequeueNotification return s.dequeueNotification
} }
// onFilteredBlockConnected sends appropriate notifications to the notification // onFilteredBlockConnected sends appropriate notifications to the notification
// channel. // channel.
func (s *SPVChain) onFilteredBlockConnected(height int32, func (s *NeutrinoClient) onFilteredBlockConnected(height int32,
header *wire.BlockHeader, relevantTxs []*btcutil.Tx) { header *wire.BlockHeader, relevantTxs []*btcutil.Tx) {
ntfn := FilteredBlockConnected{ ntfn := FilteredBlockConnected{
Block: &wtxmgr.BlockMeta{ Block: &wtxmgr.BlockMeta{
@ -296,7 +297,7 @@ func (s *SPVChain) onFilteredBlockConnected(height int32,
// onBlockDisconnected sends appropriate notifications to the notification // onBlockDisconnected sends appropriate notifications to the notification
// channel. // channel.
func (s *SPVChain) onBlockDisconnected(hash *chainhash.Hash, height int32, func (s *NeutrinoClient) onBlockDisconnected(hash *chainhash.Hash, height int32,
t time.Time) { t time.Time) {
select { select {
case s.enqueueNotification <- BlockDisconnected{ case s.enqueueNotification <- BlockDisconnected{
@ -314,7 +315,7 @@ func (s *SPVChain) onBlockDisconnected(hash *chainhash.Hash, height int32,
// notificationHandler queues and dequeues notifications. There are currently // notificationHandler queues and dequeues notifications. There are currently
// no bounds on the queue, so the dequeue channel should be read continually to // no bounds on the queue, so the dequeue channel should be read continually to
// avoid running out of memory. // avoid running out of memory.
func (s *SPVChain) notificationHandler() { func (s *NeutrinoClient) notificationHandler() {
hash, height, err := s.GetBestBlock() hash, height, err := s.GetBestBlock()
if err != nil { if err != nil {
log.Errorf("Failed to get best block from chain service: %s", log.Errorf("Failed to get best block from chain service: %s",

2
glide.lock generated
View file

@ -97,7 +97,7 @@ imports:
- name: github.com/kkdai/bstream - name: github.com/kkdai/bstream
version: f391b8402d23024e7c0f624b31267a89998fca95 version: f391b8402d23024e7c0f624b31267a89998fca95
- name: github.com/lightninglabs/neutrino - name: github.com/lightninglabs/neutrino
version: 45154447f8d2b1080982b28457e0f270b5993805 version: 113c35bb7044bb5a12c1484a5c089f13267026ed
repo: git@github.com:lightninglabs/neutrino repo: git@github.com:lightninglabs/neutrino
- name: golang.org/x/crypto - name: golang.org/x/crypto
version: 0fe963104e9d1877082f8fb38f816fcd97eb1d10 version: 0fe963104e9d1877082f8fb38f816fcd97eb1d10

View file

@ -1352,7 +1352,7 @@ func (w *Wallet) GetTransactions(startBlock, endBlock *BlockIdentifier, cancel <
switch client := chainClient.(type) { switch client := chainClient.(type) {
case *chain.RPCClient: case *chain.RPCClient:
startResp = client.GetBlockVerboseTxAsync(startBlock.hash) startResp = client.GetBlockVerboseTxAsync(startBlock.hash)
case *chain.SPVChain: case *chain.NeutrinoClient:
var err error var err error
start, err = client.GetBlockHeight(startBlock.hash) start, err = client.GetBlockHeight(startBlock.hash)
if err != nil { if err != nil {
@ -1371,7 +1371,7 @@ func (w *Wallet) GetTransactions(startBlock, endBlock *BlockIdentifier, cancel <
switch client := chainClient.(type) { switch client := chainClient.(type) {
case *chain.RPCClient: case *chain.RPCClient:
endResp = client.GetBlockVerboseTxAsync(endBlock.hash) endResp = client.GetBlockVerboseTxAsync(endBlock.hash)
case *chain.SPVChain: case *chain.NeutrinoClient:
var err error var err error
end, err = client.GetBlockHeight(endBlock.hash) end, err = client.GetBlockHeight(endBlock.hash)
if err != nil { if err != nil {