From 0122dda88a96f558c04dc747208a25d1689ea9c1 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Fri, 6 Sep 2019 13:14:38 +0200 Subject: [PATCH] channeldb/channel: remove unused FullSync method The exported FullSync method is only used by test code, so we remove it and instead use SyncPending. --- channeldb/channel.go | 15 ++------------- channeldb/channel_test.go | 14 ++++++++++++-- channeldb/db_test.go | 7 ++++++- lnwallet/test_utils.go | 15 +++++++++++++-- 4 files changed, 33 insertions(+), 18 deletions(-) diff --git a/channeldb/channel.go b/channeldb/channel.go index 2b1ec9494..b11e09e88 100644 --- a/channeldb/channel.go +++ b/channeldb/channel.go @@ -514,16 +514,6 @@ type OpenChannel struct { sync.RWMutex } -// FullSync serializes, and writes to disk the *full* channel state, using -// both the active channel bucket to store the prefixed column fields, and the -// remote node's ID to store the remainder of the channel state. -func (c *OpenChannel) FullSync() error { - c.Lock() - defer c.Unlock() - - return c.Db.Update(c.fullSync) -} - // ShortChanID returns the current ShortChannelID of this channel. func (c *OpenChannel) ShortChanID() lnwire.ShortChannelID { c.RLock() @@ -648,9 +638,8 @@ func fetchChanBucket(tx *bbolt.Tx, nodeKey *btcec.PublicKey, return chanBucket, nil } -// fullSync is an internal version of the FullSync method which allows callers -// to sync the contents of an OpenChannel while re-using an existing database -// transaction. +// fullSync syncs the contents of an OpenChannel while re-using an existing +// database transaction. func (c *OpenChannel) fullSync(tx *bbolt.Tx) error { // First fetch the top level bucket which stores all data related to // current, active channels. diff --git a/channeldb/channel_test.go b/channeldb/channel_test.go index 770f6f35d..46ac311cc 100644 --- a/channeldb/channel_test.go +++ b/channeldb/channel_test.go @@ -263,7 +263,12 @@ func TestOpenChannelPutGetDelete(t *testing.T) { OnionBlob: []byte("onionblob"), }, } - if err := state.FullSync(); err != nil { + + addr := &net.TCPAddr{ + IP: net.ParseIP("127.0.0.1"), + Port: 18556, + } + if err := state.SyncPending(addr, 101); err != nil { t.Fatalf("unable to save and serialize channel state: %v", err) } @@ -363,7 +368,12 @@ func TestChannelStateTransition(t *testing.T) { if err != nil { t.Fatalf("unable to create channel state: %v", err) } - if err := channel.FullSync(); err != nil { + + addr := &net.TCPAddr{ + IP: net.ParseIP("127.0.0.1"), + Port: 18556, + } + if err := channel.SyncPending(addr, 101); err != nil { t.Fatalf("unable to save and serialize channel state: %v", err) } diff --git a/channeldb/db_test.go b/channeldb/db_test.go index 43b626194..198f6e2b2 100644 --- a/channeldb/db_test.go +++ b/channeldb/db_test.go @@ -110,7 +110,12 @@ func TestFetchClosedChannelForID(t *testing.T) { for i := uint32(0); i < numChans; i++ { // Save the open channel to disk. state.FundingOutpoint.Index = i - if err := state.FullSync(); err != nil { + + addr := &net.TCPAddr{ + IP: net.ParseIP("127.0.0.1"), + Port: 18556, + } + if err := state.SyncPending(addr, 101); err != nil { t.Fatalf("unable to save and serialize channel "+ "state: %v", err) } diff --git a/lnwallet/test_utils.go b/lnwallet/test_utils.go index 4dee6ccb0..37f13c552 100644 --- a/lnwallet/test_utils.go +++ b/lnwallet/test_utils.go @@ -7,6 +7,7 @@ import ( "encoding/hex" "io" "io/ioutil" + "net" "os" "github.com/btcsuite/btcd/btcec" @@ -334,10 +335,20 @@ func CreateTestChannels() (*LightningChannel, *LightningChannel, func(), error) return nil, nil, nil, err } - if err := channelAlice.channelState.FullSync(); err != nil { + addr := &net.TCPAddr{ + IP: net.ParseIP("127.0.0.1"), + Port: 18556, + } + if err := channelAlice.channelState.SyncPending(addr, 101); err != nil { return nil, nil, nil, err } - if err := channelBob.channelState.FullSync(); err != nil { + + addr = &net.TCPAddr{ + IP: net.ParseIP("127.0.0.1"), + Port: 18555, + } + + if err := channelBob.channelState.SyncPending(addr, 101); err != nil { return nil, nil, nil, err }