Skip to content

Commit f2270ba

Browse files
author
Manoranjith
committed
💥 Replace proposal ID method with a struct field
- Proposal ID is now a static, random value generated when creating a channel proposal. - Hence, remove the ProposalID method and make the proposal ID field exported. Signed-off-by: Manoranjith <ponraj.manoranjitha@in.bosch.com>
1 parent fcf1b7a commit f2270ba

File tree

2 files changed

+11
-21
lines changed

2 files changed

+11
-21
lines changed

client/proposal.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ func (c *Client) handleChannelProposalRej(
280280
req ChannelProposal, reason string,
281281
) error {
282282
msgReject := &ChannelProposalRejMsg{
283-
ProposalID: req.ProposalID(),
283+
ProposalID: req.Base().ProposalID,
284284
Reason: reason,
285285
}
286286
if err := c.conn.pubMsg(ctx, msgReject, p); err != nil {
@@ -305,7 +305,7 @@ func (c *Client) proposeTwoPartyChannel(
305305
pred := enableVer0Cache(c.conn)
306306
defer c.conn.ReleaseCache(pred)
307307

308-
proposalID := proposal.ProposalID()
308+
proposalID := proposal.Base().ProposalID
309309
isResponse := func(e *wire.Envelope) bool {
310310
acc, isAcc := e.Msg.(ChannelProposalAccept)
311311
return (isAcc && acc.Base().ProposalID == proposalID) ||
@@ -467,7 +467,7 @@ func (c *Client) validChannelProposalAcc(
467467
return errors.Errorf("Received invalid accept message %T to proposal %T", response, proposal)
468468
}
469469

470-
propID := proposal.ProposalID()
470+
propID := proposal.Base().ProposalID
471471
accID := response.Base().ProposalID
472472
if !bytes.Equal(propID[:], accID[:]) {
473473
return errors.Errorf("mismatched proposal ID %b and accept ID %b", propID, accID)

client/proposalmsgs.go

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,6 @@ type (
9494

9595
// Valid checks whether a channel proposal is valid.
9696
Valid() error
97-
98-
// ProposalID calculates the proposal's unique identifier.
99-
ProposalID() ProposalID
10097
}
10198

10299
// BaseChannelProposal contains all data necessary to propose a new
@@ -105,7 +102,7 @@ type (
105102
// BaseChannelProposal implements the channel proposal messages from the
106103
// Multi-Party Channel Proposal Protocol (MPCPP).
107104
BaseChannelProposal struct {
108-
proposalID ProposalID // Unique ID for the proposal.
105+
ProposalID ProposalID // Unique ID for the proposal.
109106
ChallengeDuration uint64 // Dispute challenge duration.
110107
NonceShare NonceShare // Proposer's channel nonce share.
111108
App channel.App // App definition, or nil.
@@ -183,11 +180,6 @@ func makeBaseChannelProposal(
183180
}, nil
184181
}
185182

186-
// ProposalID returns the proposal id for this channel proposal.
187-
func (p *BaseChannelProposal) ProposalID() ProposalID {
188-
return p.proposalID
189-
}
190-
191183
// Base returns the channel proposal's common values.
192184
func (p *BaseChannelProposal) Base() *BaseChannelProposal {
193185
return p
@@ -201,7 +193,7 @@ func (p BaseChannelProposal) NumPeers() int {
201193
// Encode encodes the BaseChannelProposal into an io.Writer.
202194
func (p BaseChannelProposal) Encode(w io.Writer) error {
203195
optAppAndDataEnc := channel.OptAppAndDataEnc{App: p.App, Data: p.InitData}
204-
return perunio.Encode(w, p.ProposalID(), p.ChallengeDuration, p.NonceShare,
196+
return perunio.Encode(w, p.ProposalID, p.ChallengeDuration, p.NonceShare,
205197
optAppAndDataEnc, p.InitBals, p.FundingAgreement)
206198
}
207199

@@ -211,7 +203,7 @@ func (p *BaseChannelProposal) Decode(r io.Reader) (err error) {
211203
p.InitBals = new(channel.Allocation)
212204
}
213205
optAppAndDataDec := channel.OptAppAndDataDec{App: &p.App, Data: &p.InitData}
214-
return perunio.Decode(r, &p.proposalID, &p.ChallengeDuration, &p.NonceShare,
206+
return perunio.Decode(r, &p.ProposalID, &p.ChallengeDuration, &p.NonceShare,
215207
optAppAndDataDec, p.InitBals, &p.FundingAgreement)
216208
}
217209

@@ -242,12 +234,12 @@ func (p LedgerChannelProposalMsg) Accept(
242234
nonceShare ProposalOpts,
243235
) *LedgerChannelProposalAccMsg {
244236
if !nonceShare.isNonce() {
245-
log.WithField("proposal", p.ProposalID()).
237+
log.WithField("proposal", p.ProposalID).
246238
Panic("LedgerChannelProposal.Accept: nonceShare has no configured nonce")
247239
}
248240
return &LedgerChannelProposalAccMsg{
249241
BaseChannelProposalAcc: makeBaseChannelProposalAcc(
250-
p.ProposalID(), nonceShare.nonce()),
242+
p.ProposalID, nonceShare.nonce()),
251243
Participant: participant,
252244
}
253245
}
@@ -370,14 +362,13 @@ func (SubChannelProposalMsg) Type() wire.Type {
370362
func (p SubChannelProposalMsg) Accept(
371363
nonceShare ProposalOpts,
372364
) *SubChannelProposalAccMsg {
373-
propID := p.ProposalID()
374365
if !nonceShare.isNonce() {
375-
log.WithField("proposal", propID).
366+
log.WithField("proposal", p.ProposalID).
376367
Panic("SubChannelProposal.Accept: nonceShare has no configured nonce")
377368
}
378369
return &SubChannelProposalAccMsg{
379370
BaseChannelProposalAcc: makeBaseChannelProposalAcc(
380-
propID, nonceShare.nonce()),
371+
p.ProposalID, nonceShare.nonce()),
381372
}
382373
}
383374

@@ -600,10 +591,9 @@ func (p VirtualChannelProposalMsg) Accept(
600591
responder wallet.Address,
601592
opts ...ProposalOpts,
602593
) *VirtualChannelProposalAccMsg {
603-
propID := p.ProposalID()
604594
_opts := union(opts...)
605595
return &VirtualChannelProposalAccMsg{
606-
BaseChannelProposalAcc: makeBaseChannelProposalAcc(propID, _opts.nonce()),
596+
BaseChannelProposalAcc: makeBaseChannelProposalAcc(p.ProposalID, _opts.nonce()),
607597
Responder: responder,
608598
}
609599
}

0 commit comments

Comments
 (0)