watchtower/multi: define blob TypeAltruistCommit and TypeRewardCommit

This commit is contained in:
Conner Fromknecht 2019-06-12 16:59:56 -07:00
parent 2d47618055
commit a246d8216a
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7
6 changed files with 54 additions and 54 deletions

@ -56,15 +56,11 @@ type descriptorTest struct {
decErr error decErr error
} }
var rewardAndCommitType = blob.TypeFromFlags(
blob.FlagReward, blob.FlagCommitOutputs,
)
var descriptorTests = []descriptorTest{ var descriptorTests = []descriptorTest{
{ {
name: "to-local only", name: "to-local only",
encVersion: blob.TypeDefault, encVersion: blob.TypeAltruistCommit,
decVersion: blob.TypeDefault, decVersion: blob.TypeAltruistCommit,
sweepAddr: makeAddr(22), sweepAddr: makeAddr(22),
revPubKey: makePubKey(0), revPubKey: makePubKey(0),
delayPubKey: makePubKey(1), delayPubKey: makePubKey(1),
@ -73,8 +69,8 @@ var descriptorTests = []descriptorTest{
}, },
{ {
name: "to-local and p2wkh", name: "to-local and p2wkh",
encVersion: rewardAndCommitType, encVersion: blob.TypeRewardCommit,
decVersion: rewardAndCommitType, decVersion: blob.TypeRewardCommit,
sweepAddr: makeAddr(22), sweepAddr: makeAddr(22),
revPubKey: makePubKey(0), revPubKey: makePubKey(0),
delayPubKey: makePubKey(1), delayPubKey: makePubKey(1),
@ -87,7 +83,7 @@ var descriptorTests = []descriptorTest{
{ {
name: "unknown encrypt version", name: "unknown encrypt version",
encVersion: 0, encVersion: 0,
decVersion: blob.TypeDefault, decVersion: blob.TypeAltruistCommit,
sweepAddr: makeAddr(34), sweepAddr: makeAddr(34),
revPubKey: makePubKey(0), revPubKey: makePubKey(0),
delayPubKey: makePubKey(1), delayPubKey: makePubKey(1),
@ -97,7 +93,7 @@ var descriptorTests = []descriptorTest{
}, },
{ {
name: "unknown decrypt version", name: "unknown decrypt version",
encVersion: blob.TypeDefault, encVersion: blob.TypeAltruistCommit,
decVersion: 0, decVersion: 0,
sweepAddr: makeAddr(34), sweepAddr: makeAddr(34),
revPubKey: makePubKey(0), revPubKey: makePubKey(0),
@ -108,8 +104,8 @@ var descriptorTests = []descriptorTest{
}, },
{ {
name: "sweep addr length zero", name: "sweep addr length zero",
encVersion: blob.TypeDefault, encVersion: blob.TypeAltruistCommit,
decVersion: blob.TypeDefault, decVersion: blob.TypeAltruistCommit,
sweepAddr: makeAddr(0), sweepAddr: makeAddr(0),
revPubKey: makePubKey(0), revPubKey: makePubKey(0),
delayPubKey: makePubKey(1), delayPubKey: makePubKey(1),
@ -118,8 +114,8 @@ var descriptorTests = []descriptorTest{
}, },
{ {
name: "sweep addr max size", name: "sweep addr max size",
encVersion: blob.TypeDefault, encVersion: blob.TypeAltruistCommit,
decVersion: blob.TypeDefault, decVersion: blob.TypeAltruistCommit,
sweepAddr: makeAddr(blob.MaxSweepAddrSize), sweepAddr: makeAddr(blob.MaxSweepAddrSize),
revPubKey: makePubKey(0), revPubKey: makePubKey(0),
delayPubKey: makePubKey(1), delayPubKey: makePubKey(1),
@ -128,8 +124,8 @@ var descriptorTests = []descriptorTest{
}, },
{ {
name: "sweep addr too long", name: "sweep addr too long",
encVersion: blob.TypeDefault, encVersion: blob.TypeAltruistCommit,
decVersion: blob.TypeDefault, decVersion: blob.TypeAltruistCommit,
sweepAddr: makeAddr(blob.MaxSweepAddrSize + 1), sweepAddr: makeAddr(blob.MaxSweepAddrSize + 1),
revPubKey: makePubKey(0), revPubKey: makePubKey(0),
delayPubKey: makePubKey(1), delayPubKey: makePubKey(1),

@ -45,9 +45,15 @@ func (f Flag) String() string {
// of the blob itself. // of the blob itself.
type Type uint16 type Type uint16
// TypeDefault sweeps only commitment outputs to a sweep address controlled by const (
// the user, and does not give the tower a reward. // TypeAltruistCommit sweeps only commitment outputs to a sweep address
const TypeDefault = Type(FlagCommitOutputs) // controlled by the user, and does not give the tower a reward.
TypeAltruistCommit = Type(FlagCommitOutputs)
// TypeRewardCommit sweeps only commitment outputs to a sweep address
// controlled by the user, and pays a negotiated reward to the tower.
TypeRewardCommit = Type(FlagCommitOutputs | FlagReward)
)
// Has returns true if the Type has the passed flag enabled. // Has returns true if the Type has the passed flag enabled.
func (t Type) Has(flag Flag) bool { func (t Type) Has(flag Flag) bool {
@ -114,8 +120,8 @@ func (t Type) String() string {
// supportedTypes is the set of all configurations known to be supported by the // supportedTypes is the set of all configurations known to be supported by the
// package. // package.
var supportedTypes = map[Type]struct{}{ var supportedTypes = map[Type]struct{}{
FlagCommitOutputs.Type(): {}, TypeAltruistCommit: {},
(FlagCommitOutputs | FlagReward).Type(): {}, TypeRewardCommit: {},
} }
// IsSupportedType returns true if the given type is supported by the package. // IsSupportedType returns true if the given type is supported by the package.

@ -17,12 +17,12 @@ type typeStringTest struct {
var typeStringTests = []typeStringTest{ var typeStringTests = []typeStringTest{
{ {
name: "commit no-reward", name: "commit no-reward",
typ: blob.TypeDefault, typ: blob.TypeAltruistCommit,
expStr: "[FlagCommitOutputs|No-FlagReward]", expStr: "[FlagCommitOutputs|No-FlagReward]",
}, },
{ {
name: "commit reward", name: "commit reward",
typ: (blob.FlagCommitOutputs | blob.FlagReward).Type(), typ: blob.TypeRewardCommit,
expStr: "[FlagCommitOutputs|FlagReward]", expStr: "[FlagCommitOutputs|FlagReward]",
}, },
{ {
@ -75,7 +75,7 @@ var typeFromFlagTests = []typeFromFlagTest{
{ {
name: "multiple flags", name: "multiple flags",
flags: []blob.Flag{blob.FlagReward, blob.FlagCommitOutputs}, flags: []blob.Flag{blob.FlagReward, blob.FlagCommitOutputs},
expType: blob.Type(blob.FlagReward | blob.FlagCommitOutputs), expType: blob.TypeRewardCommit,
}, },
{ {
name: "duplicate flag", name: "duplicate flag",
@ -119,8 +119,8 @@ func TestTypeFromFlags(t *testing.T) {
// blob.DefaultType returns true. // blob.DefaultType returns true.
func TestSupportedTypes(t *testing.T) { func TestSupportedTypes(t *testing.T) {
// Assert that the package's default type is supported. // Assert that the package's default type is supported.
if !blob.IsSupportedType(blob.TypeDefault) { if !blob.IsSupportedType(blob.TypeAltruistCommit) {
t.Fatalf("default type %s is not supported", blob.TypeDefault) t.Fatalf("default type %s is not supported", blob.TypeAltruistCommit)
} }
// Assert that all claimed supported types are actually supported. // Assert that all claimed supported types are actually supported.

@ -786,7 +786,7 @@ var clientTests = []clientTest{
remoteBalance: remoteBalance, remoteBalance: remoteBalance,
policy: wtpolicy.Policy{ policy: wtpolicy.Policy{
TxPolicy: wtpolicy.TxPolicy{ TxPolicy: wtpolicy.TxPolicy{
BlobType: blob.TypeDefault, BlobType: blob.TypeAltruistCommit,
SweepFeeRate: 1, SweepFeeRate: 1,
}, },
MaxUpdates: 20000, MaxUpdates: 20000,
@ -820,7 +820,7 @@ var clientTests = []clientTest{
remoteBalance: remoteBalance, remoteBalance: remoteBalance,
policy: wtpolicy.Policy{ policy: wtpolicy.Policy{
TxPolicy: wtpolicy.TxPolicy{ TxPolicy: wtpolicy.TxPolicy{
BlobType: blob.TypeDefault, BlobType: blob.TypeAltruistCommit,
SweepFeeRate: 1, SweepFeeRate: 1,
}, },
MaxUpdates: 20000, MaxUpdates: 20000,
@ -855,7 +855,7 @@ var clientTests = []clientTest{
remoteBalance: remoteBalance, remoteBalance: remoteBalance,
policy: wtpolicy.Policy{ policy: wtpolicy.Policy{
TxPolicy: wtpolicy.TxPolicy{ TxPolicy: wtpolicy.TxPolicy{
BlobType: blob.TypeDefault, BlobType: blob.TypeAltruistCommit,
SweepFeeRate: 1, SweepFeeRate: 1,
}, },
MaxUpdates: 5, MaxUpdates: 5,
@ -891,7 +891,7 @@ var clientTests = []clientTest{
remoteBalance: remoteBalance, remoteBalance: remoteBalance,
policy: wtpolicy.Policy{ policy: wtpolicy.Policy{
TxPolicy: wtpolicy.TxPolicy{ TxPolicy: wtpolicy.TxPolicy{
BlobType: blob.TypeDefault, BlobType: blob.TypeAltruistCommit,
SweepFeeRate: 1000000, // high sweep fee creates dust SweepFeeRate: 1000000, // high sweep fee creates dust
}, },
MaxUpdates: 20000, MaxUpdates: 20000,
@ -922,7 +922,7 @@ var clientTests = []clientTest{
remoteBalance: remoteBalance, remoteBalance: remoteBalance,
policy: wtpolicy.Policy{ policy: wtpolicy.Policy{
TxPolicy: wtpolicy.TxPolicy{ TxPolicy: wtpolicy.TxPolicy{
BlobType: blob.TypeDefault, BlobType: blob.TypeAltruistCommit,
SweepFeeRate: 1, SweepFeeRate: 1,
}, },
MaxUpdates: 20000, MaxUpdates: 20000,
@ -1004,7 +1004,7 @@ var clientTests = []clientTest{
remoteBalance: remoteBalance, remoteBalance: remoteBalance,
policy: wtpolicy.Policy{ policy: wtpolicy.Policy{
TxPolicy: wtpolicy.TxPolicy{ TxPolicy: wtpolicy.TxPolicy{
BlobType: blob.TypeDefault, BlobType: blob.TypeAltruistCommit,
SweepFeeRate: 1, SweepFeeRate: 1,
}, },
MaxUpdates: 5, MaxUpdates: 5,
@ -1062,7 +1062,7 @@ var clientTests = []clientTest{
remoteBalance: 20000001, // ensure (% amt != 0) remoteBalance: 20000001, // ensure (% amt != 0)
policy: wtpolicy.Policy{ policy: wtpolicy.Policy{
TxPolicy: wtpolicy.TxPolicy{ TxPolicy: wtpolicy.TxPolicy{
BlobType: blob.TypeDefault, BlobType: blob.TypeAltruistCommit,
SweepFeeRate: 1, SweepFeeRate: 1,
}, },
MaxUpdates: 1000, MaxUpdates: 1000,
@ -1106,7 +1106,7 @@ var clientTests = []clientTest{
remoteBalance: remoteBalance, remoteBalance: remoteBalance,
policy: wtpolicy.Policy{ policy: wtpolicy.Policy{
TxPolicy: wtpolicy.TxPolicy{ TxPolicy: wtpolicy.TxPolicy{
BlobType: blob.TypeDefault, BlobType: blob.TypeAltruistCommit,
SweepFeeRate: 1, SweepFeeRate: 1,
}, },
MaxUpdates: 5, MaxUpdates: 5,
@ -1156,7 +1156,7 @@ var clientTests = []clientTest{
remoteBalance: remoteBalance, remoteBalance: remoteBalance,
policy: wtpolicy.Policy{ policy: wtpolicy.Policy{
TxPolicy: wtpolicy.TxPolicy{ TxPolicy: wtpolicy.TxPolicy{
BlobType: blob.TypeDefault, BlobType: blob.TypeAltruistCommit,
SweepFeeRate: 1, SweepFeeRate: 1,
}, },
MaxUpdates: 5, MaxUpdates: 5,
@ -1214,7 +1214,7 @@ var clientTests = []clientTest{
remoteBalance: remoteBalance, remoteBalance: remoteBalance,
policy: wtpolicy.Policy{ policy: wtpolicy.Policy{
TxPolicy: wtpolicy.TxPolicy{ TxPolicy: wtpolicy.TxPolicy{
BlobType: blob.TypeDefault, BlobType: blob.TypeAltruistCommit,
SweepFeeRate: 1, SweepFeeRate: 1,
}, },
MaxUpdates: 5, MaxUpdates: 5,
@ -1278,7 +1278,7 @@ var clientTests = []clientTest{
remoteBalance: remoteBalance, remoteBalance: remoteBalance,
policy: wtpolicy.Policy{ policy: wtpolicy.Policy{
TxPolicy: wtpolicy.TxPolicy{ TxPolicy: wtpolicy.TxPolicy{
BlobType: blob.TypeDefault, BlobType: blob.TypeAltruistCommit,
SweepFeeRate: 1, SweepFeeRate: 1,
}, },
MaxUpdates: 10, MaxUpdates: 10,
@ -1338,7 +1338,7 @@ var clientTests = []clientTest{
remoteBalance: remoteBalance, remoteBalance: remoteBalance,
policy: wtpolicy.Policy{ policy: wtpolicy.Policy{
TxPolicy: wtpolicy.TxPolicy{ TxPolicy: wtpolicy.TxPolicy{
BlobType: blob.TypeDefault, BlobType: blob.TypeAltruistCommit,
SweepFeeRate: 1, SweepFeeRate: 1,
}, },
MaxUpdates: 5, MaxUpdates: 5,

@ -50,7 +50,7 @@ var (
func DefaultPolicy() Policy { func DefaultPolicy() Policy {
return Policy{ return Policy{
TxPolicy: TxPolicy{ TxPolicy: TxPolicy{
BlobType: blob.TypeDefault, BlobType: blob.TypeAltruistCommit,
RewardRate: DefaultRewardRate, RewardRate: DefaultRewardRate,
SweepFeeRate: lnwallet.SatPerKWeight( SweepFeeRate: lnwallet.SatPerKWeight(
DefaultSweepFeeRate, DefaultSweepFeeRate,

@ -27,8 +27,6 @@ var (
addrScript, _ = txscript.PayToAddrScript(addr) addrScript, _ = txscript.PayToAddrScript(addr)
testnetChainHash = *chaincfg.TestNet3Params.GenesisHash testnetChainHash = *chaincfg.TestNet3Params.GenesisHash
rewardType = (blob.FlagCommitOutputs | blob.FlagReward).Type()
) )
// randPubKey generates a new secp keypair, and returns the public key. // randPubKey generates a new secp keypair, and returns the public key.
@ -168,7 +166,7 @@ var createSessionTests = []createSessionTestCase{
testnetChainHash, testnetChainHash,
), ),
createMsg: &wtwire.CreateSession{ createMsg: &wtwire.CreateSession{
BlobType: blob.TypeDefault, BlobType: blob.TypeAltruistCommit,
MaxUpdates: 1000, MaxUpdates: 1000,
RewardBase: 0, RewardBase: 0,
RewardRate: 0, RewardRate: 0,
@ -190,7 +188,7 @@ var createSessionTests = []createSessionTestCase{
testnetChainHash, testnetChainHash,
), ),
createMsg: &wtwire.CreateSession{ createMsg: &wtwire.CreateSession{
BlobType: blob.TypeDefault, BlobType: blob.TypeAltruistCommit,
MaxUpdates: 1000, MaxUpdates: 1000,
RewardBase: 0, RewardBase: 0,
RewardRate: 0, RewardRate: 0,
@ -214,7 +212,7 @@ var createSessionTests = []createSessionTestCase{
testnetChainHash, testnetChainHash,
), ),
createMsg: &wtwire.CreateSession{ createMsg: &wtwire.CreateSession{
BlobType: rewardType, BlobType: blob.TypeRewardCommit,
MaxUpdates: 1000, MaxUpdates: 1000,
RewardBase: 0, RewardBase: 0,
RewardRate: 0, RewardRate: 0,
@ -350,7 +348,7 @@ var stateUpdateTests = []stateUpdateTestCase{
testnetChainHash, testnetChainHash,
), ),
createMsg: &wtwire.CreateSession{ createMsg: &wtwire.CreateSession{
BlobType: blob.TypeDefault, BlobType: blob.TypeAltruistCommit,
MaxUpdates: 3, MaxUpdates: 3,
RewardBase: 0, RewardBase: 0,
RewardRate: 0, RewardRate: 0,
@ -380,7 +378,7 @@ var stateUpdateTests = []stateUpdateTestCase{
testnetChainHash, testnetChainHash,
), ),
createMsg: &wtwire.CreateSession{ createMsg: &wtwire.CreateSession{
BlobType: blob.TypeDefault, BlobType: blob.TypeAltruistCommit,
MaxUpdates: 4, MaxUpdates: 4,
RewardBase: 0, RewardBase: 0,
RewardRate: 0, RewardRate: 0,
@ -404,7 +402,7 @@ var stateUpdateTests = []stateUpdateTestCase{
testnetChainHash, testnetChainHash,
), ),
createMsg: &wtwire.CreateSession{ createMsg: &wtwire.CreateSession{
BlobType: blob.TypeDefault, BlobType: blob.TypeAltruistCommit,
MaxUpdates: 4, MaxUpdates: 4,
RewardBase: 0, RewardBase: 0,
RewardRate: 0, RewardRate: 0,
@ -432,7 +430,7 @@ var stateUpdateTests = []stateUpdateTestCase{
testnetChainHash, testnetChainHash,
), ),
createMsg: &wtwire.CreateSession{ createMsg: &wtwire.CreateSession{
BlobType: blob.TypeDefault, BlobType: blob.TypeAltruistCommit,
MaxUpdates: 4, MaxUpdates: 4,
RewardBase: 0, RewardBase: 0,
RewardRate: 0, RewardRate: 0,
@ -460,7 +458,7 @@ var stateUpdateTests = []stateUpdateTestCase{
testnetChainHash, testnetChainHash,
), ),
createMsg: &wtwire.CreateSession{ createMsg: &wtwire.CreateSession{
BlobType: blob.TypeDefault, BlobType: blob.TypeAltruistCommit,
MaxUpdates: 4, MaxUpdates: 4,
RewardBase: 0, RewardBase: 0,
RewardRate: 0, RewardRate: 0,
@ -490,7 +488,7 @@ var stateUpdateTests = []stateUpdateTestCase{
testnetChainHash, testnetChainHash,
), ),
createMsg: &wtwire.CreateSession{ createMsg: &wtwire.CreateSession{
BlobType: blob.TypeDefault, BlobType: blob.TypeAltruistCommit,
MaxUpdates: 4, MaxUpdates: 4,
RewardBase: 0, RewardBase: 0,
RewardRate: 0, RewardRate: 0,
@ -520,7 +518,7 @@ var stateUpdateTests = []stateUpdateTestCase{
testnetChainHash, testnetChainHash,
), ),
createMsg: &wtwire.CreateSession{ createMsg: &wtwire.CreateSession{
BlobType: blob.TypeDefault, BlobType: blob.TypeAltruistCommit,
MaxUpdates: 4, MaxUpdates: 4,
RewardBase: 0, RewardBase: 0,
RewardRate: 0, RewardRate: 0,
@ -551,7 +549,7 @@ var stateUpdateTests = []stateUpdateTestCase{
testnetChainHash, testnetChainHash,
), ),
createMsg: &wtwire.CreateSession{ createMsg: &wtwire.CreateSession{
BlobType: blob.TypeDefault, BlobType: blob.TypeAltruistCommit,
MaxUpdates: 3, MaxUpdates: 3,
RewardBase: 0, RewardBase: 0,
RewardRate: 0, RewardRate: 0,
@ -581,7 +579,7 @@ var stateUpdateTests = []stateUpdateTestCase{
testnetChainHash, testnetChainHash,
), ),
createMsg: &wtwire.CreateSession{ createMsg: &wtwire.CreateSession{
BlobType: blob.TypeDefault, BlobType: blob.TypeAltruistCommit,
MaxUpdates: 3, MaxUpdates: 3,
RewardBase: 0, RewardBase: 0,
RewardRate: 0, RewardRate: 0,
@ -718,7 +716,7 @@ func TestServerDeleteSession(t *testing.T) {
) )
createSession := &wtwire.CreateSession{ createSession := &wtwire.CreateSession{
BlobType: blob.TypeDefault, BlobType: blob.TypeAltruistCommit,
MaxUpdates: 1000, MaxUpdates: 1000,
RewardBase: 0, RewardBase: 0,
RewardRate: 0, RewardRate: 0,