satellite/orders: check for expired orders first

there are a subset of storagenodes hammering the satellite with
expired orders. if we check for expiration first, we don't have
to do a bunch of pointless signature verification. since a && b
is equal to b && a, we can order these checks in any way we want
and have it still be correct.

Change-Id: I6ffc8025c8b0d54949a1daf5f5ea1fed9e213372
This commit is contained in:
Jeff Wendling 2020-04-02 12:35:05 -06:00
parent 6492b13d81
commit a409bd5dec

View File

@ -311,6 +311,15 @@ func (endpoint *Endpoint) doSettlement(stream settlementStream) (err error) {
}
rejectErr := func() error {
// check expiration first before the signatures so that we can throw out the large
// amount of expired orders being sent to us before doing expensive signature
// verification.
if orderLimit.OrderExpiration.Before(time.Now()) {
mon.Event("order_verification_failed_expired")
expirationCount++
return errExpiredOrder.New("order limit expired")
}
// satellite verifies that it signed the order limit
if err := signing.VerifyOrderLimitSignature(ctx, endpoint.satelliteSignee, orderLimit); err != nil {
mon.Event("order_verification_failed_satellite_signature")
@ -328,12 +337,6 @@ func (endpoint *Endpoint) doSettlement(stream settlementStream) (err error) {
mon.Event("order_verification_failed_serial_mismatch")
return Error.New("invalid serial number")
}
if orderLimit.OrderExpiration.Before(time.Now()) {
mon.Event("order_verification_failed_expired")
expirationCount++
return errExpiredOrder.New("order limit expired")
}
return nil
}()
if rejectErr != nil {