Merge pull request #542 from wpaulino/bitcoind-client-birthday

chain+wallet: set bitcoind client birthday after wallet init
This commit is contained in:
Olaoluwa Osuntokun 2018-09-12 20:41:30 -07:00 committed by GitHub
commit 421298df22
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 4 deletions

View file

@ -108,6 +108,10 @@ type BitcoindClient struct {
wg sync.WaitGroup wg sync.WaitGroup
} }
// A compile-time check to ensure that BitcoindClient satisfies the
// chain.Interface interface.
var _ Interface = (*BitcoindClient)(nil)
// BackEnd returns the name of the driver. // BackEnd returns the name of the driver.
func (c *BitcoindClient) BackEnd() string { func (c *BitcoindClient) BackEnd() string {
return "bitcoind" return "bitcoind"
@ -596,6 +600,14 @@ func (c *BitcoindClient) ntfnHandler() {
} }
} }
// SetBirthday sets the birthday of the bitcoind rescan client.
//
// NOTE: This should be done before the client has been started in order for it
// to properly carry its duties.
func (c *BitcoindClient) SetBirthday(t time.Time) {
c.birthday = t
}
// 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 (c *BitcoindClient) BlockStamp() (*waddrmgr.BlockStamp, error) { func (c *BitcoindClient) BlockStamp() (*waddrmgr.BlockStamp, error) {

View file

@ -333,15 +333,13 @@ func (c *BitcoindConn) getCurrentNet() (wire.BitcoinNet, error) {
// NewBitcoindClient returns a bitcoind client using the current bitcoind // NewBitcoindClient returns a bitcoind client using the current bitcoind
// connection. This allows us to share the same connection using multiple // connection. This allows us to share the same connection using multiple
// clients. The birthday signifies the earliest time for which we should begin // clients.
// scanning the chain. func (c *BitcoindConn) NewBitcoindClient() *BitcoindClient {
func (c *BitcoindConn) NewBitcoindClient(birthday time.Time) *BitcoindClient {
return &BitcoindClient{ return &BitcoindClient{
quit: make(chan struct{}), quit: make(chan struct{}),
id: atomic.AddUint64(&c.rescanClientCounter, 1), id: atomic.AddUint64(&c.rescanClientCounter, 1),
birthday: birthday,
chainParams: c.chainParams, chainParams: c.chainParams,
chainConn: c, chainConn: c,

View file

@ -173,6 +173,8 @@ func (w *Wallet) SynchronizeRPC(chainClient chain.Interface) {
switch cc := chainClient.(type) { switch cc := chainClient.(type) {
case *chain.NeutrinoClient: case *chain.NeutrinoClient:
cc.SetStartTime(w.Manager.Birthday()) cc.SetStartTime(w.Manager.Birthday())
case *chain.BitcoindClient:
cc.SetBirthday(w.Manager.Birthday())
} }
w.chainClientLock.Unlock() w.chainClientLock.Unlock()