Skip to content

Commit

Permalink
adds convenience function to check remaining seconds in epoch, and im…
Browse files Browse the repository at this point in the history
…plements the reveal window
  • Loading branch information
0o-de-lally committed Sep 18, 2024
1 parent 8cb3604 commit 7d2f804
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
24 changes: 24 additions & 0 deletions framework/libra-framework/sources/block.move
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,30 @@ module diem_framework::block {
borrow_global<BlockResource>(@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(
Expand Down
10 changes: 8 additions & 2 deletions framework/libra-framework/sources/ol_sources/secret_bid.move
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 7d2f804

Please sign in to comment.