watchtower/multi: embed TxPolicy in wtpolicy.Policy
This commit splits out the parameters that shape the justice transaction into their own struct, which then embedded within the overarching wtpolicy.Policy which may have additional parameters describing operation of the session. This is done as a preliminary step to support comparison of sessions based on matching TxPolicy configurations. This prevents otherwise identical Policies from being counted as different if operational parameters like MaxUpdates differ, even if it has no material difference to the justice transaction.
This commit is contained in:
parent
9b365567b6
commit
98c2d329e5
@ -156,9 +156,11 @@ func testJusticeDescriptor(t *testing.T, blobType blob.Type) {
|
|||||||
// parameters that should be used in constructing the justice
|
// parameters that should be used in constructing the justice
|
||||||
// transaction.
|
// transaction.
|
||||||
policy := wtpolicy.Policy{
|
policy := wtpolicy.Policy{
|
||||||
BlobType: blobType,
|
TxPolicy: wtpolicy.TxPolicy{
|
||||||
SweepFeeRate: 2000,
|
BlobType: blobType,
|
||||||
RewardRate: 900000,
|
SweepFeeRate: 2000,
|
||||||
|
RewardRate: 900000,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
sessionInfo := &wtdb.SessionInfo{
|
sessionInfo := &wtdb.SessionInfo{
|
||||||
Policy: policy,
|
Policy: policy,
|
||||||
|
@ -96,7 +96,9 @@ func TestLookoutBreachMatching(t *testing.T) {
|
|||||||
sessionInfo1 := &wtdb.SessionInfo{
|
sessionInfo1 := &wtdb.SessionInfo{
|
||||||
ID: makeArray33(1),
|
ID: makeArray33(1),
|
||||||
Policy: wtpolicy.Policy{
|
Policy: wtpolicy.Policy{
|
||||||
BlobType: rewardAndCommitType,
|
TxPolicy: wtpolicy.TxPolicy{
|
||||||
|
BlobType: rewardAndCommitType,
|
||||||
|
},
|
||||||
MaxUpdates: 10,
|
MaxUpdates: 10,
|
||||||
},
|
},
|
||||||
RewardAddress: makeAddrSlice(22),
|
RewardAddress: makeAddrSlice(22),
|
||||||
@ -104,7 +106,9 @@ func TestLookoutBreachMatching(t *testing.T) {
|
|||||||
sessionInfo2 := &wtdb.SessionInfo{
|
sessionInfo2 := &wtdb.SessionInfo{
|
||||||
ID: makeArray33(2),
|
ID: makeArray33(2),
|
||||||
Policy: wtpolicy.Policy{
|
Policy: wtpolicy.Policy{
|
||||||
BlobType: rewardAndCommitType,
|
TxPolicy: wtpolicy.TxPolicy{
|
||||||
|
BlobType: rewardAndCommitType,
|
||||||
|
},
|
||||||
MaxUpdates: 10,
|
MaxUpdates: 10,
|
||||||
},
|
},
|
||||||
RewardAddress: makeAddrSlice(22),
|
RewardAddress: makeAddrSlice(22),
|
||||||
|
@ -207,9 +207,11 @@ func genTaskTest(
|
|||||||
expRewardScript: rewardScript,
|
expRewardScript: rewardScript,
|
||||||
session: &wtdb.ClientSessionBody{
|
session: &wtdb.ClientSessionBody{
|
||||||
Policy: wtpolicy.Policy{
|
Policy: wtpolicy.Policy{
|
||||||
BlobType: blobType,
|
TxPolicy: wtpolicy.TxPolicy{
|
||||||
SweepFeeRate: sweepFeeRate,
|
BlobType: blobType,
|
||||||
RewardRate: 10000,
|
SweepFeeRate: sweepFeeRate,
|
||||||
|
RewardRate: 10000,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
RewardPkScript: rewardScript,
|
RewardPkScript: rewardScript,
|
||||||
},
|
},
|
||||||
|
@ -785,9 +785,11 @@ var clientTests = []clientTest{
|
|||||||
localBalance: localBalance,
|
localBalance: localBalance,
|
||||||
remoteBalance: remoteBalance,
|
remoteBalance: remoteBalance,
|
||||||
policy: wtpolicy.Policy{
|
policy: wtpolicy.Policy{
|
||||||
BlobType: blob.TypeDefault,
|
TxPolicy: wtpolicy.TxPolicy{
|
||||||
MaxUpdates: 20000,
|
BlobType: blob.TypeDefault,
|
||||||
SweepFeeRate: 1,
|
SweepFeeRate: 1,
|
||||||
|
},
|
||||||
|
MaxUpdates: 20000,
|
||||||
},
|
},
|
||||||
noRegisterChan0: true,
|
noRegisterChan0: true,
|
||||||
},
|
},
|
||||||
@ -817,9 +819,11 @@ var clientTests = []clientTest{
|
|||||||
localBalance: localBalance,
|
localBalance: localBalance,
|
||||||
remoteBalance: remoteBalance,
|
remoteBalance: remoteBalance,
|
||||||
policy: wtpolicy.Policy{
|
policy: wtpolicy.Policy{
|
||||||
BlobType: blob.TypeDefault,
|
TxPolicy: wtpolicy.TxPolicy{
|
||||||
MaxUpdates: 20000,
|
BlobType: blob.TypeDefault,
|
||||||
SweepFeeRate: 1,
|
SweepFeeRate: 1,
|
||||||
|
},
|
||||||
|
MaxUpdates: 20000,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
fn: func(h *testHarness) {
|
fn: func(h *testHarness) {
|
||||||
@ -850,9 +854,11 @@ var clientTests = []clientTest{
|
|||||||
localBalance: localBalance,
|
localBalance: localBalance,
|
||||||
remoteBalance: remoteBalance,
|
remoteBalance: remoteBalance,
|
||||||
policy: wtpolicy.Policy{
|
policy: wtpolicy.Policy{
|
||||||
BlobType: blob.TypeDefault,
|
TxPolicy: wtpolicy.TxPolicy{
|
||||||
MaxUpdates: 5,
|
BlobType: blob.TypeDefault,
|
||||||
SweepFeeRate: 1,
|
SweepFeeRate: 1,
|
||||||
|
},
|
||||||
|
MaxUpdates: 5,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
fn: func(h *testHarness) {
|
fn: func(h *testHarness) {
|
||||||
@ -884,9 +890,11 @@ var clientTests = []clientTest{
|
|||||||
localBalance: localBalance,
|
localBalance: localBalance,
|
||||||
remoteBalance: remoteBalance,
|
remoteBalance: remoteBalance,
|
||||||
policy: wtpolicy.Policy{
|
policy: wtpolicy.Policy{
|
||||||
BlobType: blob.TypeDefault,
|
TxPolicy: wtpolicy.TxPolicy{
|
||||||
MaxUpdates: 20000,
|
BlobType: blob.TypeDefault,
|
||||||
SweepFeeRate: 1000000, // high sweep fee creates dust
|
SweepFeeRate: 1000000, // high sweep fee creates dust
|
||||||
|
},
|
||||||
|
MaxUpdates: 20000,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
fn: func(h *testHarness) {
|
fn: func(h *testHarness) {
|
||||||
@ -913,9 +921,11 @@ var clientTests = []clientTest{
|
|||||||
localBalance: localBalance,
|
localBalance: localBalance,
|
||||||
remoteBalance: remoteBalance,
|
remoteBalance: remoteBalance,
|
||||||
policy: wtpolicy.Policy{
|
policy: wtpolicy.Policy{
|
||||||
BlobType: blob.TypeDefault,
|
TxPolicy: wtpolicy.TxPolicy{
|
||||||
MaxUpdates: 20000,
|
BlobType: blob.TypeDefault,
|
||||||
SweepFeeRate: 1,
|
SweepFeeRate: 1,
|
||||||
|
},
|
||||||
|
MaxUpdates: 20000,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
fn: func(h *testHarness) {
|
fn: func(h *testHarness) {
|
||||||
@ -993,9 +1003,11 @@ var clientTests = []clientTest{
|
|||||||
localBalance: localBalance,
|
localBalance: localBalance,
|
||||||
remoteBalance: remoteBalance,
|
remoteBalance: remoteBalance,
|
||||||
policy: wtpolicy.Policy{
|
policy: wtpolicy.Policy{
|
||||||
BlobType: blob.TypeDefault,
|
TxPolicy: wtpolicy.TxPolicy{
|
||||||
MaxUpdates: 5,
|
BlobType: blob.TypeDefault,
|
||||||
SweepFeeRate: 1,
|
SweepFeeRate: 1,
|
||||||
|
},
|
||||||
|
MaxUpdates: 5,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
fn: func(h *testHarness) {
|
fn: func(h *testHarness) {
|
||||||
@ -1049,9 +1061,11 @@ var clientTests = []clientTest{
|
|||||||
localBalance: 10000001, // ensure (% amt != 0)
|
localBalance: 10000001, // ensure (% amt != 0)
|
||||||
remoteBalance: 20000001, // ensure (% amt != 0)
|
remoteBalance: 20000001, // ensure (% amt != 0)
|
||||||
policy: wtpolicy.Policy{
|
policy: wtpolicy.Policy{
|
||||||
BlobType: blob.TypeDefault,
|
TxPolicy: wtpolicy.TxPolicy{
|
||||||
MaxUpdates: 1000,
|
BlobType: blob.TypeDefault,
|
||||||
SweepFeeRate: 1,
|
SweepFeeRate: 1,
|
||||||
|
},
|
||||||
|
MaxUpdates: 1000,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
fn: func(h *testHarness) {
|
fn: func(h *testHarness) {
|
||||||
@ -1091,9 +1105,11 @@ var clientTests = []clientTest{
|
|||||||
localBalance: localBalance,
|
localBalance: localBalance,
|
||||||
remoteBalance: remoteBalance,
|
remoteBalance: remoteBalance,
|
||||||
policy: wtpolicy.Policy{
|
policy: wtpolicy.Policy{
|
||||||
BlobType: blob.TypeDefault,
|
TxPolicy: wtpolicy.TxPolicy{
|
||||||
MaxUpdates: 5,
|
BlobType: blob.TypeDefault,
|
||||||
SweepFeeRate: 1,
|
SweepFeeRate: 1,
|
||||||
|
},
|
||||||
|
MaxUpdates: 5,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
fn: func(h *testHarness) {
|
fn: func(h *testHarness) {
|
||||||
@ -1139,9 +1155,11 @@ var clientTests = []clientTest{
|
|||||||
localBalance: localBalance,
|
localBalance: localBalance,
|
||||||
remoteBalance: remoteBalance,
|
remoteBalance: remoteBalance,
|
||||||
policy: wtpolicy.Policy{
|
policy: wtpolicy.Policy{
|
||||||
BlobType: blob.TypeDefault,
|
TxPolicy: wtpolicy.TxPolicy{
|
||||||
MaxUpdates: 5,
|
BlobType: blob.TypeDefault,
|
||||||
SweepFeeRate: 1,
|
SweepFeeRate: 1,
|
||||||
|
},
|
||||||
|
MaxUpdates: 5,
|
||||||
},
|
},
|
||||||
noAckCreateSession: true,
|
noAckCreateSession: true,
|
||||||
},
|
},
|
||||||
@ -1195,9 +1213,11 @@ var clientTests = []clientTest{
|
|||||||
localBalance: localBalance,
|
localBalance: localBalance,
|
||||||
remoteBalance: remoteBalance,
|
remoteBalance: remoteBalance,
|
||||||
policy: wtpolicy.Policy{
|
policy: wtpolicy.Policy{
|
||||||
BlobType: blob.TypeDefault,
|
TxPolicy: wtpolicy.TxPolicy{
|
||||||
MaxUpdates: 5,
|
BlobType: blob.TypeDefault,
|
||||||
SweepFeeRate: 1,
|
SweepFeeRate: 1,
|
||||||
|
},
|
||||||
|
MaxUpdates: 5,
|
||||||
},
|
},
|
||||||
noAckCreateSession: true,
|
noAckCreateSession: true,
|
||||||
},
|
},
|
||||||
@ -1256,9 +1276,11 @@ var clientTests = []clientTest{
|
|||||||
localBalance: localBalance,
|
localBalance: localBalance,
|
||||||
remoteBalance: remoteBalance,
|
remoteBalance: remoteBalance,
|
||||||
policy: wtpolicy.Policy{
|
policy: wtpolicy.Policy{
|
||||||
BlobType: blob.TypeDefault,
|
TxPolicy: wtpolicy.TxPolicy{
|
||||||
MaxUpdates: 5,
|
BlobType: blob.TypeDefault,
|
||||||
SweepFeeRate: 1,
|
SweepFeeRate: 1,
|
||||||
|
},
|
||||||
|
MaxUpdates: 5,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
fn: func(h *testHarness) {
|
fn: func(h *testHarness) {
|
||||||
|
@ -49,28 +49,28 @@ var (
|
|||||||
// used by clients or servers.
|
// used by clients or servers.
|
||||||
func DefaultPolicy() Policy {
|
func DefaultPolicy() Policy {
|
||||||
return Policy{
|
return Policy{
|
||||||
BlobType: blob.TypeDefault,
|
TxPolicy: TxPolicy{
|
||||||
|
BlobType: blob.TypeDefault,
|
||||||
|
RewardRate: DefaultRewardRate,
|
||||||
|
SweepFeeRate: lnwallet.SatPerKWeight(
|
||||||
|
DefaultSweepFeeRate,
|
||||||
|
),
|
||||||
|
},
|
||||||
MaxUpdates: DefaultMaxUpdates,
|
MaxUpdates: DefaultMaxUpdates,
|
||||||
RewardRate: DefaultRewardRate,
|
|
||||||
SweepFeeRate: lnwallet.SatPerKWeight(
|
|
||||||
DefaultSweepFeeRate,
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Policy defines the negotiated parameters for a session between a client and
|
// TxPolicy defines the negotiate parameters that determine the form of the
|
||||||
// server. The parameters specify the format of encrypted blobs sent to the
|
// justice transaction for a given breached state. Thus, for any given revoked
|
||||||
// tower, the reward schedule for the tower, and the number of encrypted blobs a
|
// state, an identical key will result in an identical justice transaction
|
||||||
// client can send in one session.
|
// (barring signatures). The parameters specify the format of encrypted blobs
|
||||||
type Policy struct {
|
// sent to the tower, the reward schedule for the tower, and the number of
|
||||||
|
// encrypted blobs a client can send in one session.
|
||||||
|
type TxPolicy struct {
|
||||||
// BlobType specifies the blob format that must be used by all updates sent
|
// BlobType specifies the blob format that must be used by all updates sent
|
||||||
// under the session key used to negotiate this session.
|
// under the session key used to negotiate this session.
|
||||||
BlobType blob.Type
|
BlobType blob.Type
|
||||||
|
|
||||||
// MaxUpdates is the maximum number of updates the watchtower will honor
|
|
||||||
// for this session.
|
|
||||||
MaxUpdates uint16
|
|
||||||
|
|
||||||
// RewardBase is the fixed amount allocated to the tower when the
|
// RewardBase is the fixed amount allocated to the tower when the
|
||||||
// policy's blob type specifies a reward for the tower. This is taken
|
// policy's blob type specifies a reward for the tower. This is taken
|
||||||
// before adding the proportional reward.
|
// before adding the proportional reward.
|
||||||
@ -88,6 +88,18 @@ type Policy struct {
|
|||||||
SweepFeeRate lnwallet.SatPerKWeight
|
SweepFeeRate lnwallet.SatPerKWeight
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Policy defines the negotiated parameters for a session between a client and
|
||||||
|
// server. In addition to the TxPolicy that governs the shape of the justice
|
||||||
|
// transaction, the Policy also includes features which only affect the
|
||||||
|
// operation of the session.
|
||||||
|
type Policy struct {
|
||||||
|
TxPolicy
|
||||||
|
|
||||||
|
// MaxUpdates is the maximum number of updates the watchtower will honor
|
||||||
|
// for this session.
|
||||||
|
MaxUpdates uint16
|
||||||
|
}
|
||||||
|
|
||||||
// String returns a human-readable description of the current policy.
|
// String returns a human-readable description of the current policy.
|
||||||
func (p Policy) String() string {
|
func (p Policy) String() string {
|
||||||
return fmt.Sprintf("(blob-type=%b max-updates=%d reward-rate=%d "+
|
return fmt.Sprintf("(blob-type=%b max-updates=%d reward-rate=%d "+
|
||||||
|
@ -89,11 +89,13 @@ func (s *Server) handleCreateSession(peer Peer, id *wtdb.SessionID,
|
|||||||
info := wtdb.SessionInfo{
|
info := wtdb.SessionInfo{
|
||||||
ID: *id,
|
ID: *id,
|
||||||
Policy: wtpolicy.Policy{
|
Policy: wtpolicy.Policy{
|
||||||
BlobType: req.BlobType,
|
TxPolicy: wtpolicy.TxPolicy{
|
||||||
MaxUpdates: req.MaxUpdates,
|
BlobType: req.BlobType,
|
||||||
RewardBase: req.RewardBase,
|
RewardBase: req.RewardBase,
|
||||||
RewardRate: req.RewardRate,
|
RewardRate: req.RewardRate,
|
||||||
SweepFeeRate: req.SweepFeeRate,
|
SweepFeeRate: req.SweepFeeRate,
|
||||||
|
},
|
||||||
|
MaxUpdates: req.MaxUpdates,
|
||||||
},
|
},
|
||||||
RewardAddress: rewardScript,
|
RewardAddress: rewardScript,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user