From 26f413110233e954498aa62c06461b8858938325 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Thu, 31 Jan 2019 18:16:03 -0800 Subject: [PATCH 1/3] watchtower/wtpolicy: add RewardBase to Policy --- watchtower/wtpolicy/policy.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/watchtower/wtpolicy/policy.go b/watchtower/wtpolicy/policy.go index 65e4b4a9..3336b07c 100644 --- a/watchtower/wtpolicy/policy.go +++ b/watchtower/wtpolicy/policy.go @@ -48,6 +48,11 @@ type Policy struct { // for this session. MaxUpdates uint16 + // RewardBase is the fixed amount allocated to the tower when the + // policy's blob type specifies a reward for the tower. This is taken + // before adding the proportional reward. + RewardBase uint32 + // RewardRate is the fraction of the total balance of the revoked // commitment that the watchtower is entitled to. This value is // expressed in millionths of the total balance. From 46a86a863ace3b511c21dcd23f14fd7616fc98ed Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Thu, 31 Jan 2019 18:16:04 -0800 Subject: [PATCH 2/3] wtwire/create_session: add RewardBase field to CreateSession --- watchtower/wtwire/create_session.go | 9 ++++++++- watchtower/wtwire/summary.go | 5 +++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/watchtower/wtwire/create_session.go b/watchtower/wtwire/create_session.go index 6067d25c..338dda83 100644 --- a/watchtower/wtwire/create_session.go +++ b/watchtower/wtwire/create_session.go @@ -20,6 +20,11 @@ type CreateSession struct { // for this session. MaxUpdates uint16 + // RewardBase is the fixed amount allocated to the tower when the + // policy's blob type specifies a reward for the tower. This is taken + // before adding the proportional reward. + RewardBase uint32 + // RewardRate is the fraction of the total balance of the revoked // commitment that the watchtower is entitled to. This value is // expressed in millionths of the total balance. @@ -44,6 +49,7 @@ func (m *CreateSession) Decode(r io.Reader, pver uint32) error { return ReadElements(r, &m.BlobType, &m.MaxUpdates, + &m.RewardBase, &m.RewardRate, &m.SweepFeeRate, ) @@ -57,6 +63,7 @@ func (m *CreateSession) Encode(w io.Writer, pver uint32) error { return WriteElements(w, m.BlobType, m.MaxUpdates, + m.RewardBase, m.RewardRate, m.SweepFeeRate, ) @@ -75,5 +82,5 @@ func (m *CreateSession) MsgType() MessageType { // // This is part of the wtwire.Message interface. func (m *CreateSession) MaxPayloadLength(uint32) uint32 { - return 16 + return 2 + 2 + 4 + 4 + 8 // 20 } diff --git a/watchtower/wtwire/summary.go b/watchtower/wtwire/summary.go index 32f682b7..dbc95201 100644 --- a/watchtower/wtwire/summary.go +++ b/watchtower/wtwire/summary.go @@ -11,8 +11,9 @@ func MessageSummary(msg Message) string { case *CreateSession: return fmt.Sprintf("blob_type=%s, max_updates=%d "+ - "reward_rate=%d sweep_fee_rate=%d", msg.BlobType, - msg.MaxUpdates, msg.RewardRate, msg.SweepFeeRate) + "reward_base=%d reward_rate=%d sweep_fee_rate=%d", + msg.BlobType, msg.MaxUpdates, msg.RewardBase, + msg.RewardRate, msg.SweepFeeRate) case *CreateSessionReply: return fmt.Sprintf("code=%d", msg.Code) From 9fe284923ae6e8c13cf316dd3087aefce142ec3c Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Thu, 31 Jan 2019 18:16:06 -0800 Subject: [PATCH 3/3] watchtower/wtserver: read RewardBase from CreateSession --- watchtower/wtserver/server.go | 1 + watchtower/wtserver/server_test.go | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/watchtower/wtserver/server.go b/watchtower/wtserver/server.go index a30d6f32..957b2202 100644 --- a/watchtower/wtserver/server.go +++ b/watchtower/wtserver/server.go @@ -393,6 +393,7 @@ func (s *Server) handleCreateSession(peer Peer, id *wtdb.SessionID, Policy: wtpolicy.Policy{ BlobType: req.BlobType, MaxUpdates: req.MaxUpdates, + RewardBase: req.RewardBase, RewardRate: req.RewardRate, SweepFeeRate: req.SweepFeeRate, }, diff --git a/watchtower/wtserver/server_test.go b/watchtower/wtserver/server_test.go index d8a8911c..9631f39c 100644 --- a/watchtower/wtserver/server_test.go +++ b/watchtower/wtserver/server_test.go @@ -163,6 +163,7 @@ var createSessionTests = []createSessionTestCase{ createMsg: &wtwire.CreateSession{ BlobType: blob.TypeDefault, MaxUpdates: 1000, + RewardBase: 0, RewardRate: 0, SweepFeeRate: 1, }, @@ -184,6 +185,7 @@ var createSessionTests = []createSessionTestCase{ createMsg: &wtwire.CreateSession{ BlobType: 0, MaxUpdates: 1000, + RewardBase: 0, RewardRate: 0, SweepFeeRate: 1, }, @@ -283,6 +285,7 @@ var stateUpdateTests = []stateUpdateTestCase{ createMsg: &wtwire.CreateSession{ BlobType: blob.TypeDefault, MaxUpdates: 3, + RewardBase: 0, RewardRate: 0, SweepFeeRate: 1, }, @@ -312,6 +315,7 @@ var stateUpdateTests = []stateUpdateTestCase{ createMsg: &wtwire.CreateSession{ BlobType: blob.TypeDefault, MaxUpdates: 4, + RewardBase: 0, RewardRate: 0, SweepFeeRate: 1, }, @@ -335,6 +339,7 @@ var stateUpdateTests = []stateUpdateTestCase{ createMsg: &wtwire.CreateSession{ BlobType: blob.TypeDefault, MaxUpdates: 4, + RewardBase: 0, RewardRate: 0, SweepFeeRate: 1, }, @@ -362,6 +367,7 @@ var stateUpdateTests = []stateUpdateTestCase{ createMsg: &wtwire.CreateSession{ BlobType: blob.TypeDefault, MaxUpdates: 4, + RewardBase: 0, RewardRate: 0, SweepFeeRate: 1, }, @@ -389,6 +395,7 @@ var stateUpdateTests = []stateUpdateTestCase{ createMsg: &wtwire.CreateSession{ BlobType: blob.TypeDefault, MaxUpdates: 4, + RewardBase: 0, RewardRate: 0, SweepFeeRate: 1, }, @@ -418,6 +425,7 @@ var stateUpdateTests = []stateUpdateTestCase{ createMsg: &wtwire.CreateSession{ BlobType: blob.TypeDefault, MaxUpdates: 4, + RewardBase: 0, RewardRate: 0, SweepFeeRate: 1, }, @@ -446,6 +454,7 @@ var stateUpdateTests = []stateUpdateTestCase{ createMsg: &wtwire.CreateSession{ BlobType: blob.TypeDefault, MaxUpdates: 3, + RewardBase: 0, RewardRate: 0, SweepFeeRate: 1, }, @@ -475,6 +484,7 @@ var stateUpdateTests = []stateUpdateTestCase{ createMsg: &wtwire.CreateSession{ BlobType: blob.TypeDefault, MaxUpdates: 3, + RewardBase: 0, RewardRate: 0, SweepFeeRate: 1, },