From c8d978261b852b147b02123d31b80d55656dfe5c Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 19 Apr 2017 15:03:45 -0700 Subject: [PATCH] lnwire: remove the Validate method from the Message interface This commit revues the Validate method from the Message interface as the method is no longer used and is a relic from an older version of the codebase. --- lnwire/announcement_signatures.go | 8 ------ lnwire/channel_announcement.go | 8 ------ lnwire/channel_update.go | 17 ------------ lnwire/close_complete.go | 9 ------ lnwire/close_request.go | 14 ---------- lnwire/commit_sig.go | 9 ------ lnwire/error.go | 13 --------- lnwire/funding_locked.go | 14 ---------- lnwire/init_message.go | 18 ------------ lnwire/message.go | 1 - lnwire/node_announcement.go | 9 ------ lnwire/ping.go | 8 ------ lnwire/pong.go | 8 ------ lnwire/revoke_and_ack.go | 9 ------ lnwire/single_funding_complete.go | 20 -------------- lnwire/single_funding_request.go | 40 --------------------------- lnwire/single_funding_response.go | 32 --------------------- lnwire/single_funding_signcomplete.go | 13 --------- lnwire/update_add_htlc.go | 15 ---------- lnwire/update_fail_htlc.go | 9 ------ lnwire/update_fulfill_htlc.go | 9 ------ 21 files changed, 283 deletions(-) diff --git a/lnwire/announcement_signatures.go b/lnwire/announcement_signatures.go index 94b8f9ed..a79eebcc 100644 --- a/lnwire/announcement_signatures.go +++ b/lnwire/announcement_signatures.go @@ -40,14 +40,6 @@ type AnnounceSignatures struct { // lnwire.Message interface. var _ Message = (*AnnounceSignatures)(nil) -// Validate performs any necessary sanity checks to ensure all fields present -// on the AnnounceSignatures are valid. -// -// This is part of the lnwire.Message interface. -func (a *AnnounceSignatures) Validate() error { - return nil -} - // Decode deserializes a serialized AnnounceSignatures stored in the passed // io.Reader observing the specified protocol version. // diff --git a/lnwire/channel_announcement.go b/lnwire/channel_announcement.go index 53750492..8e6eb1b9 100644 --- a/lnwire/channel_announcement.go +++ b/lnwire/channel_announcement.go @@ -43,14 +43,6 @@ type ChannelAnnouncement struct { // lnwire.Message interface. var _ Message = (*ChannelAnnouncement)(nil) -// Validate performs any necessary sanity checks to ensure all fields present -// on the ChannelAnnouncement are valid. -// -// This is part of the lnwire.Message interface. -func (a *ChannelAnnouncement) Validate() error { - return nil -} - // Decode deserializes a serialized ChannelAnnouncement stored in the passed // io.Reader observing the specified protocol version. // diff --git a/lnwire/channel_update.go b/lnwire/channel_update.go index 0e4a6d7b..38991218 100644 --- a/lnwire/channel_update.go +++ b/lnwire/channel_update.go @@ -2,7 +2,6 @@ package lnwire import ( "bytes" - "errors" "io" "github.com/roasbeef/btcd/btcec" @@ -51,22 +50,6 @@ type ChannelUpdate struct { // interface. var _ Message = (*ChannelUpdate)(nil) -// Validate performs any necessary sanity checks to ensure all fields present -// on the ChannelUpdate are valid. -// -// This is part of the lnwire.Message interface. -func (a *ChannelUpdate) Validate() error { - // NOTE: As far as we don't have the node id (public key) in this - // message, we can't validate the signature on this stage, it should - // be validated latter - in discovery service handler. - - if a.TimeLockDelta == 0 { - return errors.New("expiry should be greater then zero") - } - - return nil -} - // Decode deserializes a serialized ChannelUpdate stored in the passed // io.Reader observing the specified protocol version. // diff --git a/lnwire/close_complete.go b/lnwire/close_complete.go index 94622be7..5b673a42 100644 --- a/lnwire/close_complete.go +++ b/lnwire/close_complete.go @@ -76,12 +76,3 @@ func (c *CloseComplete) MaxPayloadLength(uint32) uint32 { // 141 + 73 + 32 return 141 } - -// Validate performs any necessary sanity checks to ensure all fields present -// on the CloseComplete are valid. -// -// This is part of the lnwire.Message interface. -func (c *CloseComplete) Validate() error { - // We're good! - return nil -} diff --git a/lnwire/close_request.go b/lnwire/close_request.go index ca844ebf..eb6a6bd0 100644 --- a/lnwire/close_request.go +++ b/lnwire/close_request.go @@ -85,17 +85,3 @@ func (c *CloseRequest) MaxPayloadLength(pver uint32) uint32 { // 36 + 73 + 8 return 117 } - -// Validate performs any necessary sanity checks to ensure all fields present -// on the CloseRequest are valid. -// -// This is part of the lnwire.Message interface. -func (c *CloseRequest) Validate() error { - // Fee must be greater than 0. - if c.Fee < 0 { - return fmt.Errorf("fee must be greater than zero") - } - - // We're good! - return nil -} diff --git a/lnwire/commit_sig.go b/lnwire/commit_sig.go index b268bfe5..e9f0acb3 100644 --- a/lnwire/commit_sig.go +++ b/lnwire/commit_sig.go @@ -76,12 +76,3 @@ func (c *CommitSig) MaxPayloadLength(uint32) uint32 { // 32 + 64 return 96 } - -// Validate performs any necessary sanity checks to ensure all fields present -// on the CommitSig are valid. -// -// This is part of the lnwire.Message interface. -func (c *CommitSig) Validate() error { - // We're good! - return nil -} diff --git a/lnwire/error.go b/lnwire/error.go index f8185cb5..4c296f1e 100644 --- a/lnwire/error.go +++ b/lnwire/error.go @@ -108,16 +108,3 @@ func (c *Error) MaxPayloadLength(uint32) uint32 { // 32 + 2 + 655326 return 65536 } - -// Validate performs any necessary sanity checks to ensure all fields present -// on the Error are valid. -// -// This is part of the lnwire.Message interface. -func (c *Error) Validate() error { - if len(c.Data) > math.MaxUint16 { - return fmt.Errorf("problem string length too long") - } - - // We're good! - return nil -} diff --git a/lnwire/funding_locked.go b/lnwire/funding_locked.go index f8dc1e4f..a4a0202e 100644 --- a/lnwire/funding_locked.go +++ b/lnwire/funding_locked.go @@ -82,17 +82,3 @@ func (c *FundingLocked) MaxPayloadLength(uint32) uint32 { // 65 bytes return length } - -// Validate examines each populated field within the FundingLocked message for -// field sanity. For example, signature fields MUST NOT be nil. -// -// This is part of the lnwire.Message interface. -func (c *FundingLocked) Validate() error { - if c.NextPerCommitmentPoint == nil { - return fmt.Errorf("the next per commitment point must be " + - "non-nil.") - } - - // We're good! - return nil -} diff --git a/lnwire/init_message.go b/lnwire/init_message.go index b9deddd9..327c254d 100644 --- a/lnwire/init_message.go +++ b/lnwire/init_message.go @@ -70,21 +70,3 @@ func (msg *Init) Command() uint32 { func (msg *Init) MaxPayloadLength(uint32) uint32 { return 2 + maxAllowedSize + 2 + maxAllowedSize } - -// Validate performs any necessary sanity checks to ensure all fields present -// on the Init are valid. -// -// This is part of the lnwire.Message interface. -func (msg *Init) Validate() error { - if msg.GlobalFeatures.serializedSize() > maxAllowedSize { - return errors.Errorf("global feature vector exceed max allowed "+ - "size %v", maxAllowedSize) - } - - if msg.LocalFeatures.serializedSize() > maxAllowedSize { - return errors.Errorf("local feature vector exceed max allowed "+ - "size %v", maxAllowedSize) - } - - return nil -} diff --git a/lnwire/message.go b/lnwire/message.go index 41167eaa..b58ebb4f 100644 --- a/lnwire/message.go +++ b/lnwire/message.go @@ -84,7 +84,6 @@ type Message interface { Encode(io.Writer, uint32) error Command() uint32 MaxPayloadLength(uint32) uint32 - Validate() error } // makeEmptyMessage creates a new empty message of the proper concrete type diff --git a/lnwire/node_announcement.go b/lnwire/node_announcement.go index 297a6e5d..a7e12107 100644 --- a/lnwire/node_announcement.go +++ b/lnwire/node_announcement.go @@ -109,15 +109,6 @@ type NodeAnnouncement struct { // lnwire.Message interface. var _ Message = (*NodeAnnouncement)(nil) -// Validate performs any necessary sanity checks to ensure all fields present -// on the NodeAnnouncement are valid. -// -// This is part of the lnwire.Message interface. -func (a *NodeAnnouncement) Validate() error { - // TODO(roasbeef): move validation to discovery service - return nil -} - // Decode deserializes a serialized NodeAnnouncement stored in the passed // io.Reader observing the specified protocol version. // diff --git a/lnwire/ping.go b/lnwire/ping.go index d951e15a..18635346 100644 --- a/lnwire/ping.go +++ b/lnwire/ping.go @@ -65,11 +65,3 @@ func (p *Ping) Command() uint32 { func (p Ping) MaxPayloadLength(uint32) uint32 { return 65532 } - -// Validate performs any necessary sanity checks to ensure all fields present -// on the Ping are valid. -// -// This is part of the lnwire.Message interface. -func (p *Ping) Validate() error { - return nil -} diff --git a/lnwire/pong.go b/lnwire/pong.go index ecc0a11e..e503b71b 100644 --- a/lnwire/pong.go +++ b/lnwire/pong.go @@ -61,11 +61,3 @@ func (p *Pong) Command() uint32 { func (p *Pong) MaxPayloadLength(uint32) uint32 { return 65532 } - -// Validate performs any necessary sanity checks to ensure all fields present -// on the Pong are valid. -// -// This is part of the lnwire.Message interface. -func (p *Pong) Validate() error { - return nil -} diff --git a/lnwire/revoke_and_ack.go b/lnwire/revoke_and_ack.go index da96c34c..87681e42 100644 --- a/lnwire/revoke_and_ack.go +++ b/lnwire/revoke_and_ack.go @@ -94,12 +94,3 @@ func (c *RevokeAndAck) MaxPayloadLength(uint32) uint32 { // 32 + 32 + 33 + 32 return 129 } - -// Validate performs any necessary sanity checks to ensure all fields present -// on the RevokeAndAck are valid. -// -// This is part of the lnwire.Message interface. -func (c *RevokeAndAck) Validate() error { - // We're good! - return nil -} diff --git a/lnwire/single_funding_complete.go b/lnwire/single_funding_complete.go index f74a621a..1e4b90d6 100644 --- a/lnwire/single_funding_complete.go +++ b/lnwire/single_funding_complete.go @@ -103,23 +103,3 @@ func (s *SingleFundingComplete) MaxPayloadLength(uint32) uint32 { // 32 + 36 + 64 + 33 + 6 return 171 } - -// Validate examines each populated field within the SingleFundingComplete for -// field sanity. -// -// This is part of the lnwire.Message interface. -func (s *SingleFundingComplete) Validate() error { - var zeroHash [32]byte - if bytes.Equal(zeroHash[:], s.FundingOutPoint.Hash[:]) { - return fmt.Errorf("funding outpoint hash must be non-zero") - } - - if s.CommitSignature == nil { - return fmt.Errorf("commitment signature must be non-nil") - } - - // TODO(roasbeef): fin validation - - // We're good! - return nil -} diff --git a/lnwire/single_funding_request.go b/lnwire/single_funding_request.go index 50e9e617..2966362e 100644 --- a/lnwire/single_funding_request.go +++ b/lnwire/single_funding_request.go @@ -203,43 +203,3 @@ func (c *SingleFundingRequest) MaxPayloadLength(uint32) uint32 { return length } - -// Validate examines each populated field within the SingleFundingRequest for -// field sanity. For example, all fields MUST NOT be negative, and all pkScripts -// must belong to the allowed set of public key scripts. -// -// This is part of the lnwire.Message interface. -func (c *SingleFundingRequest) Validate() error { - // Negative values is are allowed. - if c.FeePerKb < 0 { - return fmt.Errorf("'MinFeePerKb' cannot be negative") - } - if c.FundingAmount < 0 { - return fmt.Errorf("'FundingAmount' cannot be negative") - } - - // The CSV delay MUST be non-zero. - if c.CsvDelay == 0 { - return fmt.Errorf("commitment transaction must have non-zero" + - " CSV delay") - } - - // The delivery pkScript must be amongst the supported script - // templates. - if !isValidPkScript(c.DeliveryPkScript) { - // TODO(roasbeef): move into actual error - return fmt.Errorf("valid delivery public key scripts MUST " + - "be: P2PKH, P2WKH, P2SH, or P2WSH") - } - - if c.DustLimit <= 0 { - return fmt.Errorf("DustLimit' should be greater than zero") - } - - if c.ConfirmationDepth == 0 { - return fmt.Errorf("ConfirmationDepth must be non-zero") - } - - // We're good! - return nil -} diff --git a/lnwire/single_funding_response.go b/lnwire/single_funding_response.go index 31c78f00..6d2da774 100644 --- a/lnwire/single_funding_response.go +++ b/lnwire/single_funding_response.go @@ -157,35 +157,3 @@ func (c *SingleFundingResponse) MaxPayloadLength(uint32) uint32 { return length } - -// Validate examines each populated field within the SingleFundingResponse for -// field sanity. For example, all fields MUST NOT be negative, and all pkScripts -// must belong to the allowed set of public key scripts. -// -// This is part of the lnwire.Message interface. -func (c *SingleFundingResponse) Validate() error { - // The channel derivation point must be non-nil, and have an odd - // y-coordinate. - if c.ChannelDerivationPoint == nil { - return fmt.Errorf("The channel derivation point must be non-nil") - } - - // The delivery pkScript must be amongst the supported script - // templates. - if !isValidPkScript(c.DeliveryPkScript) { - return fmt.Errorf("Valid delivery public key scripts MUST be: " + - "P2PKH, P2WKH, P2SH, or P2WSH.") - } - - if c.DustLimit <= 0 { - return fmt.Errorf("Dust limit shouldn't be below or equal to " + - "zero.") - } - - if c.ConfirmationDepth == 0 { - return fmt.Errorf("ConfirmationDepth must be non-zero") - } - - // We're good! - return nil -} diff --git a/lnwire/single_funding_signcomplete.go b/lnwire/single_funding_signcomplete.go index 322df896..24645887 100644 --- a/lnwire/single_funding_signcomplete.go +++ b/lnwire/single_funding_signcomplete.go @@ -71,16 +71,3 @@ func (c *SingleFundingSignComplete) MaxPayloadLength(uint32) uint32 { // 32 + 64 return 96 } - -// Validate examines each populated field within the SingleFundingSignComplete -// for field sanity. -// -// This is part of the lnwire.Message interface. -func (c *SingleFundingSignComplete) Validate() error { - if c.CommitSignature == nil { - return fmt.Errorf("commitment signature must be non-nil") - } - - // We're good! - return nil -} diff --git a/lnwire/update_add_htlc.go b/lnwire/update_add_htlc.go index 435a0272..44b11cac 100644 --- a/lnwire/update_add_htlc.go +++ b/lnwire/update_add_htlc.go @@ -110,18 +110,3 @@ func (c *UpdateAddHTLC) MaxPayloadLength(uint32) uint32 { // 1338 return 32 + 8 + 4 + 8 + 32 + 1254 } - -// Validate performs any necessary sanity checks to ensure all fields present -// on the UpdateAddHTLC are valid. -// -// This is part of the lnwire.Message interface. -func (c *UpdateAddHTLC) Validate() error { - if c.Amount < 0 { - // While fees can be negative, it's too confusing to allow - // negative payments. Maybe for some wallets, but not this one! - return fmt.Errorf("amount paid cannot be negative") - } - - // We're good! - return nil -} diff --git a/lnwire/update_fail_htlc.go b/lnwire/update_fail_htlc.go index cb6275d7..5e0f8547 100644 --- a/lnwire/update_fail_htlc.go +++ b/lnwire/update_fail_htlc.go @@ -136,12 +136,3 @@ func (c *UpdateFailHTLC) MaxPayloadLength(uint32) uint32 { // 32 + 8 + 154 return 194 } - -// Validate performs any necessary sanity checks to ensure all fields present -// on the UpdateFailHTLC are valid. -// -// This is part of the lnwire.Message interface. -func (c *UpdateFailHTLC) Validate() error { - // We're good! - return nil -} diff --git a/lnwire/update_fulfill_htlc.go b/lnwire/update_fulfill_htlc.go index c33cd75c..e5ae0c89 100644 --- a/lnwire/update_fulfill_htlc.go +++ b/lnwire/update_fulfill_htlc.go @@ -76,12 +76,3 @@ func (c *UpdateFufillHTLC) MaxPayloadLength(uint32) uint32 { // 32 + 8 + 32 return 72 } - -// Validate performs any necessary sanity checks to ensure all fields present -// on the UpdateFufillHTLC are valid. -// -// This is part of the lnwire.Message interface. -func (c *UpdateFufillHTLC) Validate() error { - // We're good! - return nil -}