multi: convert the existing channeldb.ChannelType uint8 into a bit field

In this commit, we convert the existing `channeldb.ChannelType` type
into a _bit field_. This doesn't require us to change the current
serialization or interpretation or the type as it is, since all the
current defined values us a distinct bit. This PR lays the ground work
for any future changes that may introduce new channel types (like anchor
outputs), and also any changes that may modify the existing invariants
around channels (if we're the initiator, we always have the funding
transaction).
This commit is contained in:
Olaoluwa Osuntokun committed 2019-10-31 16:34:37 -07:00
1 parent fcf81ed8ff
commit a73ee28e46
14 files changed
+42 -39

No files matched your search

+1 -2
View File
@@ -868,8 +868,7 @@ func (lc *LightningChannel) diskCommitToMemCommit(isLocal bool,
// If this commit is tweakless, then it'll affect the way we derive our
// keys, which will affect the commitment transaction reconstruction.
// So we'll determine this first, before we do anything else.
tweaklessCommit := (lc.channelState.ChanType ==
channeldb.SingleFunderTweakless)
tweaklessCommit := lc.channelState.ChanType.IsTweakless()
// First, we'll need to re-derive the commitment key ring for each
// party used within this particular state. If this is a pending commit
+4 -4
View File
@@ -511,7 +511,7 @@ func testDualFundingReservationWorkflow(miner *rpctest.Harness,
if !bytes.Equal(aliceChannels[0].FundingOutpoint.Hash[:], fundingSha[:]) {
t.Fatalf("channel state not properly saved")
}
if aliceChannels[0].ChanType != channeldb.DualFunder {
if !aliceChannels[0].ChanType.IsDualFunder() {
t.Fatalf("channel not detected as dual funder")
}
bobChannels, err := bob.Cfg.Database.FetchOpenChannels(alicePub)
@@ -521,7 +521,7 @@ func testDualFundingReservationWorkflow(miner *rpctest.Harness,
if !bytes.Equal(bobChannels[0].FundingOutpoint.Hash[:], fundingSha[:]) {
t.Fatalf("channel state not properly saved")
}
if bobChannels[0].ChanType != channeldb.DualFunder {
if !bobChannels[0].ChanType.IsDualFunder() {
t.Fatalf("channel not detected as dual funder")
}
@@ -971,7 +971,7 @@ func testSingleFunderReservationWorkflow(miner *rpctest.Harness,
}
if !aliceChannels[0].ChanType.IsSingleFunder() {
t.Fatalf("channel type is incorrect, expected %v instead got %v",
channeldb.SingleFunder, aliceChannels[0].ChanType)
channeldb.SingleFunderBit, aliceChannels[0].ChanType)
}
bobChannels, err := bob.Cfg.Database.FetchOpenChannels(alicePub)
@@ -991,7 +991,7 @@ func testSingleFunderReservationWorkflow(miner *rpctest.Harness,
}
if !bobChannels[0].ChanType.IsSingleFunder() {
t.Fatalf("channel type is incorrect, expected %v instead got %v",
channeldb.SingleFunder, bobChannels[0].ChanType)
channeldb.SingleFunderBit, bobChannels[0].ChanType)
}
// Let Alice publish the funding transaction.
+3 -3
View File
@@ -215,15 +215,15 @@ func NewChannelReservation(capacity, localFundingAmt btcutil.Amount,
// a single-funder channel.
if ourBalance == 0 || theirBalance == 0 || pushMSat != 0 {
if tweaklessCommit {
chanType = channeldb.SingleFunderTweakless
chanType |= channeldb.SingleFunderTweaklessBit
} else {
chanType = channeldb.SingleFunder
chanType |= channeldb.SingleFunderBit
}
} else {
// Otherwise, this is a dual funder channel, and no side is
// technically the "initiator"
initiator = false
chanType = channeldb.DualFunder
chanType |= channeldb.DualFunderBit
}
return &ChannelReservation{
+4 -4
View File
@@ -274,7 +274,7 @@ func CreateTestChannels(tweaklessCommits bool) (
IdentityPub: aliceKeys[0].PubKey(),
FundingOutpoint: *prevOut,
ShortChannelID: shortChanID,
ChanType: channeldb.SingleFunderTweakless,
ChanType: channeldb.SingleFunderTweaklessBit,
IsInitiator: true,
Capacity: channelCapacity,
RemoteCurrentRevocation: bobCommitPoint,
@@ -292,7 +292,7 @@ func CreateTestChannels(tweaklessCommits bool) (
IdentityPub: bobKeys[0].PubKey(),
FundingOutpoint: *prevOut,
ShortChannelID: shortChanID,
ChanType: channeldb.SingleFunderTweakless,
ChanType: channeldb.SingleFunderTweaklessBit,
IsInitiator: false,
Capacity: channelCapacity,
RemoteCurrentRevocation: aliceCommitPoint,
@@ -305,8 +305,8 @@ func CreateTestChannels(tweaklessCommits bool) (
}
if !tweaklessCommits {
aliceChannelState.ChanType = channeldb.SingleFunder
bobChannelState.ChanType = channeldb.SingleFunder
aliceChannelState.ChanType = channeldb.SingleFunderBit
bobChannelState.ChanType = channeldb.SingleFunderBit
}
aliceSigner := &input.MockSigner{Privkeys: aliceKeys}
+1 -1
View File
@@ -370,7 +370,7 @@ func TestCommitmentAndHTLCTransactions(t *testing.T) {
// Manually construct a new LightningChannel.
channelState := channeldb.OpenChannel{
ChanType: channeldb.SingleFunderTweakless,
ChanType: channeldb.SingleFunderTweaklessBit,
ChainHash: *tc.netParams.GenesisHash,
FundingOutpoint: tc.fundingOutpoint,
ShortChannelID: tc.shortChanID,