Skip to content

Commit

Permalink
major surgery to replace secret_bid with pof auction state 16/383 tes…
Browse files Browse the repository at this point in the history
…ts failing
  • Loading branch information
0o-de-lally committed Sep 26, 2024
1 parent 053fbce commit 5125830
Show file tree
Hide file tree
Showing 17 changed files with 276 additions and 231 deletions.
4 changes: 2 additions & 2 deletions framework/drop-user-tools/last_goodbye.test.move
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module ol_framework::test_last_goodbye {

let _vals = mock::genesis_n_vals(framework, 1);
// we are at epoch 0
let epoch = reconfiguration::get_current_epoch();
let epoch = reconfiguration::current_epoch();
assert!(epoch == 0, 7357001);

last_goodbye::danger_test_last_goodby(vm, bob);
Expand All @@ -23,7 +23,7 @@ module ol_framework::test_last_goodbye {
last_goodbye::danger_user_gc(vm, bob);

mock::trigger_epoch(framework); // epoch 1
let epoch = reconfiguration::get_current_epoch();
let epoch = reconfiguration::current_epoch();
assert!(epoch == 1, 7357002);

let vals = stake::get_current_validators();
Expand Down
38 changes: 6 additions & 32 deletions framework/libra-framework/sources/block.move
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ module diem_framework::block {
system_addresses::assert_diem_framework(diem_framework);
assert!(epoch_interval_microsecs > 0, error::invalid_argument(EZERO_EPOCH_INTERVAL));

reconfiguration::set_epoch_interval(diem_framework, epoch_interval_microsecs);

move_to<BlockResource>(
diem_framework,
BlockResource {
Expand All @@ -91,42 +93,14 @@ module diem_framework::block {
let old_epoch_interval = block_resource.epoch_interval;
block_resource.epoch_interval = new_epoch_interval;

reconfiguration::set_epoch_interval(diem_framework, new_epoch_interval);

event::emit_event<UpdateEpochIntervalEvent>(
&mut block_resource.update_epoch_interval_events,
UpdateEpochIntervalEvent { old_epoch_interval, new_epoch_interval },
);
}

#[view]
/// Return epoch interval in seconds.
public fun get_epoch_interval_secs(): u64 acquires BlockResource {
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 Expand Up @@ -271,11 +245,11 @@ module diem_framework::block {
if (testnet::is_testnet()) {
epoch_boundary::epoch_boundary(
vm,
reconfiguration::get_current_epoch(),
reconfiguration::current_epoch(),
round
);
} else {
epoch_boundary::enable_epoch_trigger(vm, reconfiguration::get_current_epoch());
epoch_boundary::enable_epoch_trigger(vm, reconfiguration::current_epoch());
}
}
}
Expand Down
4 changes: 0 additions & 4 deletions framework/libra-framework/sources/block.spec.move
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,6 @@ spec diem_framework::block {
ensures block_resource.epoch_interval == new_epoch_interval;
}

spec get_epoch_interval_secs(): u64 {
aborts_if !exists<BlockResource>(@diem_framework);
}

spec get_current_block_height(): u64 {
aborts_if !exists<BlockResource>(@diem_framework);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ module diem_framework::epoch_boundary {
assert!(state.ready, ETRIGGER_NOT_READY);
// greater than, in case there is an epoch change due to an epoch bump in
// testnet Twin tools, or a rescue operation.
assert!(state.closing_epoch <= reconfiguration::get_current_epoch(),
assert!(state.closing_epoch <= reconfiguration::current_epoch(),
ENOT_SAME_EPOCH);
true
}
Expand Down
33 changes: 17 additions & 16 deletions framework/libra-framework/sources/ol_sources/mock.move
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module ol_framework::mock {
use ol_framework::epoch_helper;
use ol_framework::musical_chairs;
use ol_framework::pledge_accounts;
use ol_framework::secret_bid;

// use diem_std::debug::print;

Expand Down Expand Up @@ -94,43 +95,41 @@ module ol_framework::mock {

//////// PROOF OF FEE ////////
#[test_only]
public fun pof_default(): (vector<address>, vector<u64>, vector<u64>){
public fun pof_default(framework: &signer): (vector<address>, vector<u64>){

let vals = stake::get_current_validators();

let (bids, expiry) = mock_bids(&vals);
let bids = mock_bids(framework, &vals);

// make all validators pay auction fee
// the clearing price in the fibonacci sequence is is 1
let (alice_bid, _) = proof_of_fee::current_bid(*vector::borrow(&vals, 0));
let alice_bid = secret_bid::get_bid_unchecked(*vector::borrow(&vals, 0));

assert!(alice_bid == 1, 03);
(vals, bids, expiry)
(vals, bids)
}

#[test_only]
public fun mock_bids(vals: &vector<address>): (vector<u64>, vector<u64>) {
// system_addresses::assert_ol(vm);
public fun mock_bids(framework: &signer, vals: &vector<address>): vector<u64> {
let bids = vector::empty<u64>();
let expiry = vector::empty<u64>();
let i = 0;
let prev = 0;
let fib = 1;
while (i < vector::length(vals)) {

vector::push_back(&mut expiry, 1000);
let b = prev + fib;
vector::push_back(&mut bids, b);

let a = vector::borrow(vals, i);
let sig = account::create_signer_for_test(*a);
// initialize and set.
proof_of_fee::pof_update_bid(&sig, b, 1000);
let epoch = 0;
secret_bid::mock_revealed_bid(framework, &sig, b, epoch);
prev = fib;
fib = b;
i = i + 1;
};

(bids, expiry)
bids
}

use diem_framework::chain_status;
Expand Down Expand Up @@ -290,6 +289,8 @@ module ol_framework::mock {

i = i + 1;
};

pof_default(root);
}

#[test_only]
Expand All @@ -304,7 +305,7 @@ module ol_framework::mock {
public fun trigger_epoch(root: &signer) {
trigger_epoch_exactly_at(
root,
reconfiguration::get_current_epoch(),
reconfiguration::current_epoch(),
block::get_current_block_height()
);
}
Expand All @@ -314,11 +315,11 @@ module ol_framework::mock {
epoch_boundary::ol_reconfigure_for_test(root, old_epoch, round);

// always advance
assert!(reconfiguration::get_current_epoch() > old_epoch,
assert!(reconfiguration::current_epoch() > old_epoch,
EDID_NOT_ADVANCE_EPOCH);

// epoch helper should always be in sync
assert!(reconfiguration::get_current_epoch() == epoch_helper::get_current_epoch(), 666);
assert!(reconfiguration::current_epoch() == epoch_helper::get_current_epoch(), 666);
}


Expand All @@ -345,7 +346,7 @@ module ol_framework::mock {
// will assert! case_1
mock_case_1(&root, *addr);

pof_default();
pof_default(&root);

// will assert! case_4
mock_case_4(&root, *addr);
Expand Down Expand Up @@ -378,7 +379,7 @@ module ol_framework::mock {
// Scenario: unit testing that pof_default results in a usable auction
let n_vals = 5;
let vals = genesis_n_vals(root, n_vals); // need to include eve to init funds
pof_default();
pof_default(root);

proof_of_fee::fill_seats_and_get_price(root, n_vals, &vals, &vals);

Expand Down
Loading

0 comments on commit 5125830

Please sign in to comment.