diff --git a/contractcourt/channel_arbitrator_test.go b/contractcourt/channel_arbitrator_test.go index 1fce269fd..34c6122fd 100644 --- a/contractcourt/channel_arbitrator_test.go +++ b/contractcourt/channel_arbitrator_test.go @@ -187,6 +187,10 @@ func (*mockChainIO) GetBlock(blockHash *chainhash.Hash) (*wire.MsgBlock, error) return nil, nil } +func (*mockChainIO) GetBlockHeader(*chainhash.Hash) (*wire.BlockHeader, error) { + return nil, nil +} + type chanArbTestCtx struct { t *testing.T diff --git a/lntest/mock/chainio.go b/lntest/mock/chainio.go index 1f07056f0..4dd0868b2 100644 --- a/lntest/mock/chainio.go +++ b/lntest/mock/chainio.go @@ -32,3 +32,10 @@ func (c *ChainIO) GetBlockHash(blockHeight int64) (*chainhash.Hash, error) { func (c *ChainIO) GetBlock(blockHash *chainhash.Hash) (*wire.MsgBlock, error) { return nil, nil } + +// GetBlockHeader currently returns dummy values. +func (c *ChainIO) GetBlockHeader(blockHash *chainhash.Hash) (*wire.BlockHeader, + error) { + + return nil, nil +} diff --git a/lntest/rpc/chain_kit.go b/lntest/rpc/chain_kit.go index c668b3a0f..453de276a 100644 --- a/lntest/rpc/chain_kit.go +++ b/lntest/rpc/chain_kit.go @@ -45,6 +45,24 @@ func (h *HarnessRPC) GetBlock( return resp } +// GetBlockHeader makes an RPC call to chain kit client's GetBlockHeader and +// asserts. +func (h *HarnessRPC) GetBlockHeader( + req *chainrpc.GetBlockHeaderRequest) *chainrpc.GetBlockHeaderResponse { + + if req == nil { + req = &chainrpc.GetBlockHeaderRequest{} + } + + ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout) + defer cancel() + + resp, err := h.ChainKit.GetBlockHeader(ctxt, req) + h.NoError(err, "GetBlockHeader") + + return resp +} + // GetBlockHash makes an RPC call to chain kit client's GetBlockHash and // asserts. func (h *HarnessRPC) GetBlockHash( diff --git a/lnwallet/btcwallet/blockchain.go b/lnwallet/btcwallet/blockchain.go index 5cb0886f0..25b51d5e0 100644 --- a/lnwallet/btcwallet/blockchain.go +++ b/lnwallet/btcwallet/blockchain.go @@ -149,6 +149,15 @@ func (b *BtcWallet) GetBlock(blockHash *chainhash.Hash) (*wire.MsgBlock, error) return b.chain.GetBlock(blockHash) } +// GetBlockHeader returns a block header for the block with the given hash. +// +// This method is a part of the lnwallet.BlockChainIO interface. +func (b *BtcWallet) GetBlockHeader( + blockHash *chainhash.Hash) (*wire.BlockHeader, error) { + + return b.chain.GetBlockHeader(blockHash) +} + // GetBlockHash returns the hash of the block in the best blockchain at the // given height. // diff --git a/lnwallet/interface.go b/lnwallet/interface.go index d8dc9d5b8..e8dd72dc0 100644 --- a/lnwallet/interface.go +++ b/lnwallet/interface.go @@ -562,6 +562,9 @@ type BlockChainIO interface { // GetBlock returns the block in the main chain identified by the given // hash. GetBlock(blockHash *chainhash.Hash) (*wire.MsgBlock, error) + + // GetBlockHeader returns the block header for the given block hash. + GetBlockHeader(blockHash *chainhash.Hash) (*wire.BlockHeader, error) } // MessageSigner represents an abstract object capable of signing arbitrary diff --git a/lnwallet/mock.go b/lnwallet/mock.go index 597be6618..6d382a58e 100644 --- a/lnwallet/mock.go +++ b/lnwallet/mock.go @@ -364,3 +364,9 @@ func (*mockChainIO) GetBlock(blockHash *chainhash.Hash) (*wire.MsgBlock, return nil, nil } + +func (*mockChainIO) GetBlockHeader( + blockHash *chainhash.Hash) (*wire.BlockHeader, error) { + + return nil, nil +} diff --git a/routing/notifications_test.go b/routing/notifications_test.go index 658df5423..00bc29f6b 100644 --- a/routing/notifications_test.go +++ b/routing/notifications_test.go @@ -228,6 +228,20 @@ func (m *mockChain) GetBlock(blockHash *chainhash.Hash) (*wire.MsgBlock, error) return block, nil } +func (m *mockChain) GetBlockHeader( + blockHash *chainhash.Hash) (*wire.BlockHeader, error) { + + m.RLock() + defer m.RUnlock() + + block, ok := m.blocks[*blockHash] + if !ok { + return nil, fmt.Errorf("block not found") + } + + return &block.Header, nil +} + type mockChainView struct { sync.RWMutex