Skip to content

Commit

Permalink
separate out tunav2 into its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
MicroProofs committed Mar 17, 2024
1 parent fd0207f commit a83af56
Show file tree
Hide file tree
Showing 4 changed files with 336 additions and 282 deletions.
3 changes: 2 additions & 1 deletion lib/hardfork/hftypes.ak
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ pub type ForkDatum {
HardForkState {
status: HardForkStatus,
fork_block_height: Int,
fortuna_next_validator_hash: ByteArray,
fortuna_next_spend_hash: ByteArray,
fortuna_next_mint_hash: ByteArray,
}
MinerLockState { locked_tuna: Int, block_signals: Int }
LockState { locked_tuna: Int }
Expand Down
4 changes: 3 additions & 1 deletion lib/hardfork/params.ak
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ pub const tuna_hardfork_version = 2

pub const hardfork_block_height = 100

pub const hardfork_next_hash = ""
pub const hardfork_mint_hash = ""

pub const hardfork_spend_hash = ""
31 changes: 19 additions & 12 deletions lib/hardfork_validation.ak
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use hardfork/hftypes.{
MinerLockState, NftState, NotForked, UserLock,
}
use hardfork/params.{
hardfork_block_height, hardfork_next_hash, miner_hardfork_threshold,
tuna_count_blocks_from, tuna_hardfork_threshold_denominator,
tuna_hardfork_threshold_numerator,
hardfork_block_height, hardfork_mint_hash, hardfork_spend_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 Down Expand Up @@ -77,7 +77,8 @@ pub fn initialize(
expect HardForkState {
status: NotForked,
fork_block_height,
fortuna_next_validator_hash,
fortuna_next_spend_hash,
fortuna_next_mint_hash,
}: ForkDatum = get_inline_datum(hfs_datum)

expect MinerLockState { locked_tuna: 0, block_signals: 0 }: ForkDatum =
Expand All @@ -96,7 +97,8 @@ pub fn initialize(
// 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,
fortuna_next_spend_hash == hardfork_spend_hash,
fortuna_next_mint_hash == hardfork_mint_hash,
}
}

Expand Down Expand Up @@ -740,7 +742,8 @@ pub fn hard_fork(
expect HardForkState {
status: NotForked,
fork_block_height,
fortuna_next_validator_hash,
fortuna_next_spend_hash,
fortuna_next_mint_hash,
}: ForkDatum = hardfork_datum

let total_emitted = calculate_emission(fork_block_height)
Expand Down Expand Up @@ -780,7 +783,8 @@ pub fn hard_fork(
expect HardForkState {
status: Forked,
fork_block_height: out_fork_block_height,
fortuna_next_validator_hash: out_fortuna_v2_hash,
fortuna_next_spend_hash: out_fortuna_next_spend_hash,
fortuna_next_mint_hash: out_fortuna_next_mint_hash,
}: ForkDatum = get_inline_datum(out_hfs_datum)

let fortuna_v2 = list_at(outputs, v2_miner_output)
Expand All @@ -794,7 +798,7 @@ pub fn hard_fork(

expect
address == Address {
payment_credential: ScriptCredential(fortuna_next_validator_hash),
payment_credential: ScriptCredential(fortuna_next_spend_hash),
stake_credential: None,
}

Expand All @@ -812,7 +816,7 @@ pub fn hard_fork(
// Fortuna v2 Output value is correct
utils.value_has_nft_and_lovelace(
fortuna_v2_value,
fortuna_next_validator_hash,
fortuna_next_mint_hash,
fortuna.master_token_name,
),
// nft key at output datum has same token name as nft key
Expand All @@ -832,7 +836,8 @@ pub fn hard_fork(
quantity_of(out_miner_lock_value, own_policy, miner_lock_state_token) == 1,
// Hard fork state is updated correctly
out_fork_block_height == fork_block_height,
out_fortuna_v2_hash == fortuna_next_validator_hash,
out_fortuna_next_spend_hash == fortuna_next_spend_hash,
out_fortuna_next_mint_hash == fortuna_next_mint_hash,
utils.value_has_nft_and_lovelace(
out_hfs_value,
own_policy,
Expand Down Expand Up @@ -874,7 +879,8 @@ pub fn failed_fork(
expect HardForkState {
status: NotForked,
fork_block_height,
fortuna_next_validator_hash,
fortuna_next_spend_hash,
fortuna_next_mint_hash,
}: ForkDatum = get_inline_datum(hfs_input.datum)

expect [hfs_output, ..] = outputs
Expand All @@ -886,7 +892,8 @@ pub fn failed_fork(
HardForkState {
status: FailedFork,
fork_block_height,
fortuna_next_validator_hash,
fortuna_next_spend_hash,
fortuna_next_mint_hash,
},
)

Expand Down
Loading

0 comments on commit a83af56

Please sign in to comment.