diff --git a/framework/libra-framework/sources/block.move b/framework/libra-framework/sources/block.move index baaaa667b..a111bd005 100644 --- a/framework/libra-framework/sources/block.move +++ b/framework/libra-framework/sources/block.move @@ -103,6 +103,30 @@ module diem_framework::block { borrow_global(@diem_framework).epoch_interval / 1000000 } + #[view] + /// Return rough remaining seconds in epoch + public fun get_remaining_epoch_secs(): u64 acquires BlockResource { + let now = timestamp::now_seconds(); + let last_epoch_secs = reconfiguration::last_reconfiguration_time() / 1000000; + let interval = get_epoch_interval_secs(); + if (now < last_epoch_secs) { // impossible underflow, some thign bad, or tests + return 0 + }; + + let deadline = last_epoch_secs + interval; + + if (now > deadline) { // we've run over the deadline + return 0 + }; + + // belt and suspenders + if (deadline > now) { + return deadline - now + }; + + return 0 + + } /// Set the metadata for the current block. /// The runtime always runs this before executing the transactions in a block. fun block_prologue( diff --git a/framework/libra-framework/sources/ol_sources/secret_bid.move b/framework/libra-framework/sources/ol_sources/secret_bid.move index 485bde793..b2928bb23 100644 --- a/framework/libra-framework/sources/ol_sources/secret_bid.move +++ b/framework/libra-framework/sources/ol_sources/secret_bid.move @@ -11,6 +11,8 @@ module ol_framework::secret_bid { use diem_std::ed25519; use diem_framework::account; use diem_framework::epoch_helper; + use diem_framework::block; + // use diem_framework::debug::print; @@ -42,8 +44,12 @@ module ol_framework::secret_bid { /// allow reveal transaction to be submitted fun in_reveal_window(): bool { // get the timestamp - // get the epoch ending timestamp - // get 5 mins prior + // NOTE: this might cause a dependency cycle issue in the future + let remaining_secs = block::get_remaining_epoch_secs(); + let five_mins = 60*5; + if (remaining_secs > five_mins) { + return false + }; true }