mirror of
https://github.com/Blockstream/satellite-api.git
synced 2025-02-22 13:42:33 +01:00
use floating point arithmetic to compute the message size with overhead and use the size overhead in the computation of bid_per_byte
This commit is contained in:
parent
c94451c680
commit
9753a3cd9f
2 changed files with 7 additions and 5 deletions
6
main.rb
6
main.rb
|
@ -140,10 +140,8 @@ post '/order' do
|
||||||
order.message_size = message_size
|
order.message_size = message_size
|
||||||
order.message_digest = sha256.to_s
|
order.message_digest = sha256.to_s
|
||||||
|
|
||||||
message_size_with_overhead = message_size + FRAMING_OVERHEAD_PER_FRAGMENT * (message_size / FRAGMENT_SIZE).ceil
|
if bid.to_f / order.message_size_with_overhead < MIN_PER_BYTE_BID
|
||||||
|
bid_too_small_error(order.message_size_with_overhead * MIN_PER_BYTE_BID)
|
||||||
if bid.to_f / message_size_with_overhead.to_f < MIN_PER_BYTE_BID
|
|
||||||
bid_too_small_error(message_size_with_overhead * MIN_PER_BYTE_BID)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
invoice = new_invoice(order, bid)
|
invoice = new_invoice(order, bid)
|
||||||
|
|
|
@ -68,7 +68,7 @@ class Order < ActiveRecord::Base
|
||||||
|
|
||||||
def adjust_bids
|
def adjust_bids
|
||||||
self.bid = paid_invoices_total
|
self.bid = paid_invoices_total
|
||||||
self.bid_per_byte = (self.bid.to_f / self.message_size.to_f).round(2)
|
self.bid_per_byte = (self.bid.to_f / self.message_size_with_overhead).round(2)
|
||||||
self.unpaid_bid = unpaid_invoices_total
|
self.unpaid_bid = unpaid_invoices_total
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -81,6 +81,10 @@ class Order < ActiveRecord::Base
|
||||||
self.bid_per_byte >= MIN_PER_BYTE_BID
|
self.bid_per_byte >= MIN_PER_BYTE_BID
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def message_size_with_overhead
|
||||||
|
self.message_size.to_f + FRAMING_OVERHEAD_PER_FRAGMENT * (self.message_size.to_f / FRAGMENT_SIZE).ceil
|
||||||
|
end
|
||||||
|
|
||||||
def paid_invoices_total
|
def paid_invoices_total
|
||||||
self.invoices.where(status: :paid).pluck(:amount).reduce(:+) || 0
|
self.invoices.where(status: :paid).pluck(:amount).reduce(:+) || 0
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue