-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: progress in quoting land #2498
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ use ant_protocol::{ | |
}; | ||
use ant_registers::SignedRegister; | ||
use libp2p::kad::{Record, RecordKey}; | ||
use std::time::{Duration, UNIX_EPOCH}; | ||
use std::time::{Duration, SystemTime, UNIX_EPOCH}; | ||
use xor_name::XorName; | ||
|
||
impl Node { | ||
|
@@ -614,24 +614,30 @@ impl Node { | |
// verify quote timestamp | ||
let quote_timestamp = payment.quote.timestamp; | ||
let quote_expiration_time = quote_timestamp + Duration::from_secs(QUOTE_EXPIRATION_SECS); | ||
let quote_expiration_time_in_secs = quote_expiration_time | ||
let _quote_expiration_time_in_secs = quote_expiration_time | ||
.duration_since(UNIX_EPOCH) | ||
.map_err(|e| { | ||
Error::InvalidRequest(format!( | ||
"Payment quote timestamp is invalid for record {pretty_key}: {e}" | ||
)) | ||
})? | ||
.as_secs(); | ||
// NB TODO @mick: can we check if the quote has expired with block time in evmlib? Or should nodes do it manually here? Else keep the block below | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can't really couple a transaction to a quote anymore since we no longer use the transaction's event logs to verify payments. So we'd have to do it manually. |
||
// manually check if the quote has expired | ||
if quote_expiration_time < SystemTime::now() { | ||
warn!("Payment quote has expired for record {pretty_key}"); | ||
return Err(Error::InvalidRequest(format!( | ||
"Payment quote has expired for record {pretty_key}" | ||
))); | ||
} | ||
|
||
// check if payment is valid on chain | ||
debug!("Verifying payment for record {pretty_key}"); | ||
let reward_amount = self.evm_network() | ||
.verify_data_payment( | ||
payment.tx_hash, | ||
payment.quote.hash(), | ||
payment.quote.quoting_metrics, | ||
*self.reward_address(), | ||
quote_expiration_time_in_secs, | ||
) | ||
.await | ||
.map_err(|e| Error::EvmNetwork(format!("Failed to verify chunk payment: {e}")))?; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to avoid malicious attacke, better at least have
2
holders.for
close_nodes.len() = 5
,enough_peers_already_have_it
will have a value of1
, which is somehow vulunerable.maybe make it
std::cmp::max(2, close_nodes.len()/3)
orclose_nodes.len() / 2
instead.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sense let's go with:
close_nodes.len() / 2