routing: add Reset() method to mockChainView
In this commit, we add a Reset() method to the mockChainView struct. With this new method tests are able to fully simulate a restart of the ChannelRouter. This is necessary as the FilteredChainView instances are assumed to be stateless, and don’t write their state to disk before a restart.
This commit is contained in:
parent
fea8cbf920
commit
cdf2f43432
@ -212,6 +212,8 @@ type mockChainView struct {
|
|||||||
newBlocks chan *chainview.FilteredBlock
|
newBlocks chan *chainview.FilteredBlock
|
||||||
staleBlocks chan *chainview.FilteredBlock
|
staleBlocks chan *chainview.FilteredBlock
|
||||||
|
|
||||||
|
chain lnwallet.BlockChainIO
|
||||||
|
|
||||||
filter map[wire.OutPoint]struct{}
|
filter map[wire.OutPoint]struct{}
|
||||||
|
|
||||||
quit chan struct{}
|
quit chan struct{}
|
||||||
@ -221,8 +223,9 @@ type mockChainView struct {
|
|||||||
// chainview.FilteredChainView.
|
// chainview.FilteredChainView.
|
||||||
var _ chainview.FilteredChainView = (*mockChainView)(nil)
|
var _ chainview.FilteredChainView = (*mockChainView)(nil)
|
||||||
|
|
||||||
func newMockChainView() *mockChainView {
|
func newMockChainView(chain lnwallet.BlockChainIO) *mockChainView {
|
||||||
return &mockChainView{
|
return &mockChainView{
|
||||||
|
chain: chain,
|
||||||
newBlocks: make(chan *chainview.FilteredBlock, 10),
|
newBlocks: make(chan *chainview.FilteredBlock, 10),
|
||||||
staleBlocks: make(chan *chainview.FilteredBlock, 10),
|
staleBlocks: make(chan *chainview.FilteredBlock, 10),
|
||||||
filter: make(map[wire.OutPoint]struct{}),
|
filter: make(map[wire.OutPoint]struct{}),
|
||||||
@ -230,6 +233,13 @@ func newMockChainView() *mockChainView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *mockChainView) Reset() {
|
||||||
|
m.filter = make(map[wire.OutPoint]struct{})
|
||||||
|
m.quit = make(chan struct{})
|
||||||
|
m.newBlocks = make(chan *chainview.FilteredBlock, 10)
|
||||||
|
m.staleBlocks = make(chan *chainview.FilteredBlock, 10)
|
||||||
|
}
|
||||||
|
|
||||||
func (m *mockChainView) UpdateFilter(ops []wire.OutPoint, updateHeight uint32) error {
|
func (m *mockChainView) UpdateFilter(ops []wire.OutPoint, updateHeight uint32) error {
|
||||||
m.Lock()
|
m.Lock()
|
||||||
defer m.Unlock()
|
defer m.Unlock()
|
||||||
@ -316,6 +326,7 @@ func (m *mockChainView) Start() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockChainView) Stop() error {
|
func (m *mockChainView) Stop() error {
|
||||||
|
close(m.quit)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user