multi: move block epochs dependency from links to switch

In this commit, we move the block height dependency from the links in
the switch to the switch itself. This is possible due to a recent change
on the links no longer depending on the block height to update their
commitment fees.

We'll now only have the switch be alerted of new blocks coming in and
links will retrieve the height from it atomically.
This commit is contained in:
Wilmer Paulino
2018-05-31 20:31:40 -07:00
parent 4cc60493d2
commit 8198466972
9 changed files with 128 additions and 171 deletions

View File

@@ -1,19 +1,17 @@
package htlcswitch
import (
"bytes"
"crypto/sha256"
"encoding/binary"
"fmt"
"io"
"io/ioutil"
"sync"
"sync/atomic"
"testing"
"time"
"io"
"sync/atomic"
"bytes"
"github.com/btcsuite/fastsha256"
"github.com/go-errors/errors"
"github.com/lightningnetwork/lightning-onion"
@@ -122,7 +120,7 @@ type mockServer struct {
var _ lnpeer.Peer = (*mockServer)(nil)
func initSwitchWithDB(db *channeldb.DB) (*Switch, error) {
func initSwitchWithDB(startingHeight uint32, db *channeldb.DB) (*Switch, error) {
if db == nil {
tempPath, err := ioutil.TempDir("", "switchdb")
if err != nil {
@@ -135,7 +133,7 @@ func initSwitchWithDB(db *channeldb.DB) (*Switch, error) {
}
}
return New(Config{
cfg := Config{
DB: db,
SwitchPackager: channeldb.NewSwitchPackager(),
FwdingLog: &mockForwardingLog{
@@ -144,15 +142,20 @@ func initSwitchWithDB(db *channeldb.DB) (*Switch, error) {
FetchLastChannelUpdate: func(lnwire.ShortChannelID) (*lnwire.ChannelUpdate, error) {
return nil, nil
},
})
Notifier: &mockNotifier{},
}
return New(cfg, startingHeight)
}
func newMockServer(t testing.TB, name string, db *channeldb.DB) (*mockServer, error) {
func newMockServer(t testing.TB, name string, startingHeight uint32,
db *channeldb.DB) (*mockServer, error) {
var id [33]byte
h := sha256.Sum256([]byte(name))
copy(id[:], h[:])
htlcSwitch, err := initSwitchWithDB(db)
htlcSwitch, err := initSwitchWithDB(startingHeight, db)
if err != nil {
return nil, err
}