Skip to content
This repository has been archived by the owner on Apr 1, 2024. It is now read-only.

Commit

Permalink
Release v0.1.5 (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
AurevoirXavier authored Jun 30, 2023
1 parent f4b5561 commit d28e93e
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "GPL-3.0"
name = "slothunter"
readme = "README.md"
repository = "https://github.com/hack-ink/slothunter"
version = "0.1.4"
version = "0.1.5"

[features]
node-test = []
Expand Down
21 changes: 6 additions & 15 deletions src/hunter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,21 +355,12 @@ impl Hunter {
}

fn check_leases(&self, first_lease_period: u32) {
const E_INVALID_LEASES: &str = "invalid leases configuration";

let c_first = self.configuration.bid.leases.0;
let c_last = self.configuration.bid.leases.1;
let first = first_lease_period;
let last = first_lease_period + C_RANGE_COUNT - 1;

assert!(
c_first >= first,
"{E_INVALID_LEASES}, available range(#{first}, #{last}) but found range(#{c_first}, #{c_last})"
);
assert!(
c_last <= last,
"{E_INVALID_LEASES}, available range(#{first}, #{last}) but found range(#{c_first}, #{c_last})"
);
let a @ (first, last) = util::range_of(first_lease_period);
let b @ (c_first, c_last) = self.configuration.bid.leases;

if !util::check_leases(&a, &b) {
panic!("invalid leases configuration, available range(#{first}, #{last}) but found range(#{c_first}, #{c_last})")
}
}

async fn analyze_bidders(
Expand Down
54 changes: 54 additions & 0 deletions src/hunter/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,60 @@ fn crowdloan_id_of_should_work() {
);
}

pub fn range_of(first_lease_period: u32) -> SlotRange {
(first_lease_period, first_lease_period + C_RANGE_COUNT - 1)
}
#[test]
fn range_of_should_work() {
assert_eq!(range_of(10), (10, 17));
}

pub fn check_leases(a: &SlotRange, b: &SlotRange) -> bool {
(a.0 <= b.0) && (a.1 >= b.1)
}
#[test]
fn check_leases_should_work() {
// Test when a completely overlaps b.
let a = (5, 10);
let b = (7, 8);
assert!(check_leases(&a, &b));

// Test when b completely overlaps a.
let a = (5, 10);
let b = (3, 12);
assert!(!check_leases(&a, &b));

// Test when a starts before b and ends before b.
let a = (5, 10);
let b = (7, 12);
assert!(!check_leases(&a, &b));

// Test when a starts before b and ends after b.
let a = (5, 15);
let b = (7, 12);
assert!(check_leases(&a, &b));

// Test when a starts after b and ends after b.
let a = (7, 12);
let b = (5, 10);
assert!(!check_leases(&a, &b));

// Test when a starts after b and ends before b.
let a = (7, 8);
let b = (5, 10);
assert!(!check_leases(&a, &b));

// Test when a and b are the same.
let a = (5, 10);
let b = (5, 10);
assert!(check_leases(&a, &b));

// Test when a and b do not overlap.
let a = (5, 10);
let b = (12, 15);
assert!(!check_leases(&a, &b));
}

pub fn winning_offset_of(
block_number: BlockNumber,
ending_period_start_at: BlockNumber,
Expand Down
5 changes: 2 additions & 3 deletions src/primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ pub struct AuctionDetail {
impl AuctionDetail {
pub fn fmt(&self, now: BlockNumber, end_at: BlockNumber) -> String {
let remain_blocks = end_at.saturating_sub(now);
let (first, last) = util::range_of(self.first_lease_period);

format!(
"auction(#{}) for leases[#{}, #{}) has been activated for block range[#{}, #{end_at}], remain {remain_blocks} block(s) approximately {}",
"auction(#{}) for leases(#{first}, #{last}) has been activated for block range(#{}, #{end_at}), remain {remain_blocks} block(s) approximately {}",
self.index,
self.first_lease_period,
self.first_lease_period + C_RANGE_COUNT,
self.ending_period_start_at,
util::blocks2time(remain_blocks)
)
Expand Down

0 comments on commit d28e93e

Please sign in to comment.