Skip to content

Commit

Permalink
chore: some minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
MicroProofs committed Dec 18, 2023
1 parent a616961 commit b17ab28
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
20 changes: 17 additions & 3 deletions lib/hardfork.ak
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ use hardfork/hftypes.{
LockState, MinerLockInit, MinerLockMore, MinerLockState, NftState, NotForked,
}
use hardfork/params.{
miner_hardfork_threshold, tuna_count_blocks_from,
tuna_hardfork_threshold_denominator, tuna_hardfork_threshold_numerator,
hardfork_block_height, hardfork_next_hash, miner_hardfork_threshold,
tuna_count_blocks_from, tuna_hardfork_threshold_denominator,
tuna_hardfork_threshold_numerator,
}

pub const miner_lock_state_token: ByteArray = "miner_lock_state"
Expand All @@ -25,8 +26,11 @@ pub const lock_state_token: ByteArray = "lock_state"
pub const hard_fork_state_token: ByteArray = "hfs"

pub fn initialize(
// Input
initializer_input: OutputReference,
// Tx
transaction: Transaction,
// Purpose
own_policy: ByteArray,
) -> Bool {
let Transaction { inputs, outputs, mint, .. } = transaction
Expand Down Expand Up @@ -71,7 +75,12 @@ pub fn initialize(
expect InlineDatum(miner_state_datum) = miner_state_datum
expect InlineDatum(lock_state_datum) = lock_state_datum

expect HardForkState { status: NotForked, .. }: ForkDatum = hfs_datum
// The values are chosen by the
expect HardForkState {
status: NotForked,
fork_block_height,
fortuna_next_validator_hash,
}: ForkDatum = hfs_datum

expect MinerLockState { locked_tuna: 0, block_signals: 0 }: ForkDatum =
miner_state_datum
Expand All @@ -85,7 +94,10 @@ pub fn initialize(
quantity_of(hfs_value, own_policy, hard_fork_state_token) == 1,
quantity_of(miner_state_value, own_policy, miner_lock_state_token) == 1,
quantity_of(lock_state_value, own_policy, lock_state_token) == 1,
// Needed to prevent removal of genesis input check
genesis_input == genesis_input,
fork_block_height == hardfork_block_height,
fortuna_next_validator_hash == hardfork_next_hash,
}
}

Expand All @@ -106,10 +118,12 @@ pub fn lock_not_forked(
stake_credential: None,
}

// Needed to ensure all validator spends from this script hash are accounted for
let script_inputs =
list.filter(inputs, fn(input) { input.output.address == own_address })

when lock_action is {
// TODO: refactor some the shared parts in code
MinerLockInit { fortuna_v1_output } -> {
// Use blake hash since it's faster and this is unrelated to Proof of Work
let own_token_name =
Expand Down
4 changes: 4 additions & 0 deletions lib/hardfork/params.ak
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ pub const tuna_hardfork_threshold_denominator = 3
pub const tuna_count_blocks_from = 1000

pub const tuna_hardfork_version = 2

pub const hardfork_block_height = 100

pub const hardfork_next_hash = ""
10 changes: 6 additions & 4 deletions validators/hard_fork.ak
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ validator(

let mint = value.from_minted_value(mint)

// We reference the locked v1 tuan NFTState that we have the NFT key for.
let own_input =
utils.resolve_output_reference(reference_inputs, locked_tokens_ref)

Expand Down Expand Up @@ -128,9 +129,9 @@ validator(
}
}

fn mine(datum: State, redeemer: MineAction, ctx: ScriptContext) -> Bool {
fn mine(datum: Data, redeemer: MineAction, ctx: ScriptContext) -> Bool {
// Access transaction information
let State {
expect State {
block_number,
current_hash,
leading_zeros,
Expand All @@ -139,7 +140,7 @@ validator(
current_posix_time,
interlink,
..
} = datum
}: State = datum

let ScriptContext { transaction, purpose } = ctx

Expand Down Expand Up @@ -253,7 +254,8 @@ validator(
let halving_exponent = block_number / halving_number

let expected_quantity =
if halving_exponent > 29 {
// This should be 32 not 29
if halving_exponent > 32 {
0
} else {
initial_payout / math.pow2(halving_exponent)
Expand Down

0 comments on commit b17ab28

Please sign in to comment.