diff --git a/channeldb/channel.go b/channeldb/channel.go index 803f7992..f51c737b 100644 --- a/channeldb/channel.go +++ b/channeldb/channel.go @@ -147,6 +147,11 @@ type OpenChannel struct { // The outpoint of the final funding transaction. // ChanType denotes which type of channel this is. ChanType ChannelType + + // IsInitiator is a bool which indicates if we were the original + // initiator for the channel. This value may affect how higher levels + // negotiate fees, or close the channel. + IsInitiator bool FundingOutpoint *wire.OutPoint OurMultiSigKey *btcec.PublicKey @@ -1134,6 +1139,16 @@ func putChanFundingInfo(nodeChanBucket *bolt.Bucket, channel *OpenChannel) error return err } + var boolByte [1]byte + if channel.IsInitiator { + boolByte[0] = 1 + } else { + boolByte[0] = 0 + } + if _, err := b.Write(boolByte[:]); err != nil { + return err + } + if _, err := b.Write([]byte{uint8(channel.ChanType)}); err != nil { return err } @@ -1195,6 +1210,16 @@ func fetchChanFundingInfo(nodeChanBucket *bolt.Bucket, channel *OpenChannel) err unixSecs := byteOrder.Uint64(scratch) channel.CreationTime = time.Unix(int64(unixSecs), 0) + var boolByte [1]byte + if _, err := io.ReadFull(infoBytes, boolByte[:]); err != nil { + return err + } + if boolByte[0] == 1 { + channel.IsInitiator = true + } else { + channel.IsInitiator = false + } + var chanType [1]byte if _, err := io.ReadFull(infoBytes, chanType[:]); err != nil { return err diff --git a/channeldb/channel_test.go b/channeldb/channel_test.go index b1238632..ce3a2e64 100644 --- a/channeldb/channel_test.go +++ b/channeldb/channel_test.go @@ -133,6 +133,7 @@ func createTestChannelState(cdb *DB) (*OpenChannel, error) { } return &OpenChannel{ + IsInitiator: true, ChanType: SingleFunder, IdentityPub: pubKey, ChanID: id, @@ -207,17 +208,20 @@ func TestOpenChannelPutGetDelete(t *testing.T) { } if state.MinFeePerKb != newState.MinFeePerKb { t.Fatalf("fee/kb doens't match") + if state.IsInitiator != newState.IsInitiator { + t.Fatalf("initiator status doesn't match") + } if state.ChanType != newState.ChanType { t.Fatalf("channel type doesn't match") } if !bytes.Equal(state.OurCommitKey.SerializeCompressed(), newState.OurCommitKey.SerializeCompressed()) { - t.Fatalf("our commit key dont't match") + t.Fatalf("our commit key doesn't match") } if !bytes.Equal(state.TheirCommitKey.SerializeCompressed(), newState.TheirCommitKey.SerializeCompressed()) { - t.Fatalf("their commit key dont't match") + t.Fatalf("their commit key doesn't match") } if state.Capacity != newState.Capacity { @@ -343,7 +347,7 @@ func TestOpenChannelPutGetDelete(t *testing.T) { func TestChannelStateTransition(t *testing.T) { cdb, cleanUp, err := makeTestDB() if err != nil { - t.Fatalf("uanble to make test database: %v", err) + t.Fatalf("unable to make test database: %v", err) } defer cleanUp()