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

@ -45,9 +45,15 @@ func (f Flag) String() string {
// of the blob itself.
type Type uint16
// TypeDefault sweeps only commitment outputs to a sweep address controlled by
// the user, and does not give the tower a reward.
const TypeDefault = Type(FlagCommitOutputs)
const (
// TypeAltruistCommit sweeps only commitment outputs to a sweep address
// 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.
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
// package.
var supportedTypes = map[Type]struct{}{
FlagCommitOutputs.Type(): {},
(FlagCommitOutputs | FlagReward).Type(): {},
TypeAltruistCommit: {},
TypeRewardCommit: {},
}
// IsSupportedType returns true if the given type is supported by the package.

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

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

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

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