contract/*: renamed all slot references to block height

This commit is contained in:
skoupidi
2024-01-30 21:27:46 +02:00
parent 07b47fd521
commit f64c4e5750
32 changed files with 317 additions and 263 deletions

View File

@@ -65,8 +65,8 @@ fn integration_test() -> Result<()> {
// The tokens we want to send via the proposal
const PROPOSAL_AMOUNT: u64 = 250_000_000;
// Slot to verify against
let current_slot = 0;
// Block height to verify against
let current_block_height = 0;
// DAO parameters
let dao_keypair = th.holders.get(&Holder::Dao).unwrap().keypair;
@@ -91,7 +91,8 @@ fn integration_test() -> Result<()> {
for holder in &HOLDERS {
info!("[{holder:?}] Executing DAO Mint tx");
th.execute_dao_mint_tx(holder, &dao_mint_tx, &dao_mint_params, current_slot).await?;
th.execute_dao_mint_tx(holder, &dao_mint_tx, &dao_mint_params, current_block_height)
.await?;
}
th.assert_trees(&HOLDERS);
@@ -111,8 +112,13 @@ fn integration_test() -> Result<()> {
for holder in &HOLDERS {
info!("[{holder:?}] Executing DAO airdrop tx");
th.execute_airdrop_native_tx(holder, &airdrop_tx, &airdrop_params, current_slot)
.await?;
th.execute_airdrop_native_tx(
holder,
&airdrop_tx,
&airdrop_params,
current_block_height,
)
.await?;
}
th.assert_trees(&HOLDERS);
@@ -131,8 +137,13 @@ fn integration_test() -> Result<()> {
for holder in &HOLDERS {
info!("[{holder:?}] Executing governance token mint tx for Alice");
th.execute_token_mint_tx(holder, &a_token_mint_tx, &a_token_mint_params, current_slot)
.await?;
th.execute_token_mint_tx(
holder,
&a_token_mint_tx,
&a_token_mint_params,
current_block_height,
)
.await?;
}
th.assert_trees(&HOLDERS);
@@ -146,8 +157,13 @@ fn integration_test() -> Result<()> {
for holder in &HOLDERS {
info!("[{holder:?}] Executing governance token mint tx for Bob");
th.execute_token_mint_tx(holder, &b_token_mint_tx, &b_token_mint_params, current_slot)
.await?;
th.execute_token_mint_tx(
holder,
&b_token_mint_tx,
&b_token_mint_params,
current_block_height,
)
.await?;
}
th.assert_trees(&HOLDERS);
@@ -161,8 +177,13 @@ fn integration_test() -> Result<()> {
for holder in &HOLDERS {
info!("[{holder:?}] Executing governance token mint tx for Charlie");
th.execute_token_mint_tx(holder, &c_token_mint_tx, &c_token_mint_params, current_slot)
.await?;
th.execute_token_mint_tx(
holder,
&c_token_mint_tx,
&c_token_mint_params,
current_block_height,
)
.await?;
}
th.assert_trees(&HOLDERS);
@@ -204,7 +225,8 @@ fn integration_test() -> Result<()> {
for holder in &HOLDERS {
info!("[{holder:?}] Executing DAO proposal tx");
th.execute_dao_propose_tx(holder, &propose_tx, &propose_params, current_slot).await?;
th.execute_dao_propose_tx(holder, &propose_tx, &propose_params, current_block_height)
.await?;
}
th.assert_trees(&HOLDERS);
@@ -247,13 +269,24 @@ fn integration_test() -> Result<()> {
for holder in &HOLDERS {
info!("[{holder:?}] Executing Alice vote tx");
th.execute_dao_vote_tx(holder, &alice_vote_tx, &alice_vote_params, current_slot)
.await?;
th.execute_dao_vote_tx(
holder,
&alice_vote_tx,
&alice_vote_params,
current_block_height,
)
.await?;
info!("[{holder:?}] Executing Bob vote tx");
th.execute_dao_vote_tx(holder, &bob_vote_tx, &bob_vote_params, current_slot).await?;
info!("[{holder:?}] Executing Charlie vote tx");
th.execute_dao_vote_tx(holder, &charlie_vote_tx, &charlie_vote_params, current_slot)
th.execute_dao_vote_tx(holder, &bob_vote_tx, &bob_vote_params, current_block_height)
.await?;
info!("[{holder:?}] Executing Charlie vote tx");
th.execute_dao_vote_tx(
holder,
&charlie_vote_tx,
&charlie_vote_params,
current_block_height,
)
.await?;
}
// Gather and decrypt all vote notes
@@ -343,8 +376,14 @@ fn integration_test() -> Result<()> {
for holder in &HOLDERS {
info!("[{holder:?}] Executing Dao::Exec tx");
th.execute_dao_exec_tx(holder, &exec_tx, &xfer_params, &exec_params, current_slot)
.await?;
th.execute_dao_exec_tx(
holder,
&exec_tx,
&xfer_params,
&exec_params,
current_block_height,
)
.await?;
}
th.assert_trees(&HOLDERS);

View File

@@ -25,8 +25,8 @@ fn deploy_integration() -> Result<()> {
smol::block_on(async {
init_logger();
// Slot to verify against
let current_slot = 0;
// Block height to verify against
let current_block_height = 0;
// Initialize harness
let mut th =
@@ -40,7 +40,8 @@ fn deploy_integration() -> Result<()> {
th.deploy_contract(&Holder::Alice, wasm_bincode.to_vec())?;
info!("[Alice] Executing deploy tx");
th.execute_deploy_tx(&Holder::Alice, &deploy_tx, &deploy_params, current_slot).await?;
th.execute_deploy_tx(&Holder::Alice, &deploy_tx, &deploy_params, current_block_height)
.await?;
// Thanks for reading
Ok(())

View File

@@ -81,7 +81,7 @@ impl GenesisMintCallBuilder {
assert!(self.amount != 0);
// In this call, we will build one clear input and one anonymous output.
// Only DARK_TOKEN_ID can be minted on genesis slot.
// Only DARK_TOKEN_ID can be minted on genesis block.
let token_id = *DARK_TOKEN_ID;
let input = TransferCallClearInput {

View File

@@ -69,7 +69,7 @@ pub struct PoWRewardCallBuilder {
pub secret: SecretKey,
/// Reward recipient's public key
pub recipient: PublicKey,
/// Rewarded block height(slot)
/// Rewarded block height
pub block_height: u64,
/// Extending fork last proposal/block nonce
pub last_nonce: pallas::Base,

View File

@@ -87,13 +87,13 @@ pub(crate) fn money_genesis_mint_process_instruction_v1(
let verifying_block_height = get_verifying_block_height();
if verifying_block_height != 0 {
msg!(
"[GenesisMintV1] Error: Call is executed for slot {}, not genesis",
"[GenesisMintV1] Error: Call is executed for block {}, not genesis",
verifying_block_height
);
return Err(MoneyError::GenesisCallNonGenesisBlock.into())
}
// Only DARK_TOKEN_ID can be minted on genesis slot.
// Only DARK_TOKEN_ID can be minted on genesis block
if params.input.token_id != *DARK_TOKEN_ID {
msg!("[GenesisMintV1] Error: Clear input used non-native token");
return Err(MoneyError::TransferClearInputNonNativeToken.into())

View File

@@ -126,7 +126,7 @@ pub(crate) fn money_pow_reward_process_instruction_v1(
return Err(MoneyError::TransferClearInputNonNativeToken.into())
}
// Verify reward value matches the expected one for this block height(slot)
// Verify reward value matches the expected one for this block height
let expected_reward = expected_reward(verifying_block_height);
if params.input.value != expected_reward {
msg!(

View File

@@ -91,9 +91,6 @@ pub enum MoneyError {
#[error("Call is not executed on genesis block")]
GenesisCallNonGenesisBlock,
#[error("Call is not executed on genesis slot")]
GenesisCallNonGenesisSlot,
#[error("Missing nullifier in set")]
MissingNullifier,
@@ -146,15 +143,14 @@ impl From<MoneyError> for ContractError {
MoneyError::ChildCallFunctionMismatch => Self::Custom(21),
MoneyError::ChildCallInputMismatch => Self::Custom(22),
MoneyError::GenesisCallNonGenesisBlock => Self::Custom(23),
MoneyError::GenesisCallNonGenesisSlot => Self::Custom(24),
MoneyError::MissingNullifier => Self::Custom(25),
MoneyError::PoWRewardCallOnGenesisBlock => Self::Custom(26),
MoneyError::PoWRewardRetrieveLastBlockError => Self::Custom(27),
MoneyError::PoWRewardCallNotOnNextBlockHeight => Self::Custom(28),
MoneyError::PoWRewardErroneousVrfProof => Self::Custom(29),
MoneyError::FeeMissingInputs => Self::Custom(30),
MoneyError::InsufficientFee => Self::Custom(31),
MoneyError::CoinMerkleRootNotFound => Self::Custom(32),
MoneyError::MissingNullifier => Self::Custom(24),
MoneyError::PoWRewardCallOnGenesisBlock => Self::Custom(25),
MoneyError::PoWRewardRetrieveLastBlockError => Self::Custom(26),
MoneyError::PoWRewardCallNotOnNextBlockHeight => Self::Custom(27),
MoneyError::PoWRewardErroneousVrfProof => Self::Custom(28),
MoneyError::FeeMissingInputs => Self::Custom(29),
MoneyError::InsufficientFee => Self::Custom(30),
MoneyError::CoinMerkleRootNotFound => Self::Custom(31),
}
}
}

View File

@@ -18,7 +18,7 @@
//! Test for genesis transaction verification correctness between Alice and Bob.
//!
//! We first mint Alice some native tokens on genesis slot, and then she send
//! We first mint Alice some native tokens on genesis block, and then she send
//! some of them to Bob.
//!
//! With this test, we want to confirm the genesis transactions execution works
@@ -49,8 +49,8 @@ fn genesis_mint() -> Result<()> {
// Bob = 50
const BOB_SEND: u64 = BOB_INITIAL - 20;
// Slot to verify against
let current_slot = 0;
// Block height to verify against
let current_block_height = 0;
// Initialize harness
let mut th = TestHarness::new(&["money".to_string()], false).await?;
@@ -73,19 +73,19 @@ fn genesis_mint() -> Result<()> {
TxAction::MoneyGenesisMint,
&Holder::Alice,
&[genesis_mint_tx.clone(), genesis_mint_tx.clone()],
current_slot,
current_block_height,
1,
)
.await?;
info!(target: "money", "[Malicious] ============================================");
info!(target: "money", "[Malicious] Checking genesis mint tx not on genesis slot");
info!(target: "money", "[Malicious] ============================================");
info!(target: "money", "[Malicious] =============================================");
info!(target: "money", "[Malicious] Checking genesis mint tx not on genesis block");
info!(target: "money", "[Malicious] =============================================");
th.execute_erroneous_txs(
TxAction::MoneyGenesisMint,
&Holder::Alice,
&[genesis_mint_tx.clone()],
current_slot + 1,
current_block_height + 1,
1,
)
.await?;
@@ -98,7 +98,7 @@ fn genesis_mint() -> Result<()> {
holder,
&genesis_mint_tx,
&genesis_mint_params,
current_slot,
current_block_height,
)
.await?;
}
@@ -122,7 +122,7 @@ fn genesis_mint() -> Result<()> {
holder,
&genesis_mint_tx,
&genesis_mint_params,
current_slot,
current_block_height,
)
.await?;
}
@@ -151,8 +151,14 @@ fn genesis_mint() -> Result<()> {
info!(target: "money", "[{holder:?}] ==============================");
info!(target: "money", "[{holder:?}] Executing Alice2Bob payment tx");
info!(target: "money", "[{holder:?}] ==============================");
th.execute_transfer_tx(holder, &transfer_tx, &transfer_params, current_slot, true)
.await?;
th.execute_transfer_tx(
holder,
&transfer_tx,
&transfer_params,
current_block_height,
true,
)
.await?;
}
th.assert_trees(&HOLDERS);
@@ -186,8 +192,14 @@ fn genesis_mint() -> Result<()> {
info!(target: "money", "[{holder:?}] ==============================");
info!(target: "money", "[{holder:?}] Executing Bob2Alice payment tx");
info!(target: "money", "[{holder:?}] ==============================");
th.execute_transfer_tx(holder, &transfer_tx, &transfer_params, current_slot, true)
.await?;
th.execute_transfer_tx(
holder,
&transfer_tx,
&transfer_params,
current_block_height,
true,
)
.await?;
}
th.assert_trees(&HOLDERS);

View File

@@ -32,14 +32,13 @@ fn money_integration() -> Result<()> {
// Initialize harness
let mut th = TestHarness::new(&["money".to_string()], true).await?;
// Current verification slot
let mut verification_slot = 1;
th.generate_slot(verification_slot).await?;
// Block height to verify against
let mut current_block_height = 1;
// Drop some money to Alice
info!("[Alice] Building block proposal");
let (alice_proposal_tx, alice_proposal_params) =
th.pow_reward(&Holder::Alice, None, verification_slot, None)?;
th.pow_reward(&Holder::Alice, None, current_block_height, None)?;
for holder in HOLDERS {
info!("[{holder:?}] Executing Alice's block proposal");
@@ -47,23 +46,22 @@ fn money_integration() -> Result<()> {
&holder,
&alice_proposal_tx,
&alice_proposal_params,
verification_slot,
current_block_height,
)
.await?;
}
let alice_owncoin =
th.gather_owncoin(&Holder::Alice, &alice_proposal_params.output, None)?;
assert!(alice_owncoin.note.value == expected_reward(verification_slot));
assert!(alice_owncoin.note.value == expected_reward(current_block_height));
th.assert_trees(&HOLDERS);
verification_slot += 1;
th.generate_slot(verification_slot).await?;
current_block_height += 1;
// And some to Bob
info!("[Bob] Building block proposal");
let (bob_proposal_tx, bob_proposal_params) =
th.pow_reward(&Holder::Bob, None, verification_slot, None)?;
th.pow_reward(&Holder::Bob, None, current_block_height, None)?;
for holder in HOLDERS {
info!("[{holder:?}] Executing Alice's block proposal");
@@ -71,7 +69,7 @@ fn money_integration() -> Result<()> {
&holder,
&bob_proposal_tx,
&bob_proposal_params,
verification_slot,
current_block_height,
)
.await?;
}
@@ -79,8 +77,6 @@ fn money_integration() -> Result<()> {
let _ = th.gather_owncoin(&Holder::Bob, &bob_proposal_params.output, None)?;
th.assert_trees(&HOLDERS);
verification_slot += 1;
th.generate_slot(verification_slot).await?;
// Alice sends a payment of some DRK to Bob.

View File

@@ -50,8 +50,8 @@ fn mint_pay_swap() -> Result<()> {
// Bob = 20 BOB + 50 ALICE
const BOB_FIRST_SEND: u64 = BOB_INITIAL - 20;
// Slot to verify against
let current_slot = 0;
// Block height to verify against
let current_block_height = 0;
// Initialize harness
let mut th = TestHarness::new(&["money".to_string()], false).await?;
@@ -69,7 +69,7 @@ fn mint_pay_swap() -> Result<()> {
info!(target: "money", "[{holder:?}] ==============================");
info!(target: "money", "[{holder:?}] Executing Alice token mint tx");
info!(target: "money", "[{holder:?}] ==============================");
th.execute_token_mint_tx(holder, &mint_tx, &params, current_slot).await?;
th.execute_token_mint_tx(holder, &mint_tx, &params, current_block_height).await?;
}
th.assert_trees(&HOLDERS);
@@ -89,7 +89,7 @@ fn mint_pay_swap() -> Result<()> {
info!(target: "money", "[{holder:?}] ===========================");
info!(target: "money", "[{holder:?}] Executing Bob token mint tx");
info!(target: "money", "[{holder:?}] ===========================");
th.execute_token_mint_tx(holder, &mint_tx, &params, current_slot).await?;
th.execute_token_mint_tx(holder, &mint_tx, &params, current_block_height).await?;
}
th.assert_trees(&HOLDERS);
@@ -123,8 +123,14 @@ fn mint_pay_swap() -> Result<()> {
info!(target: "money", "[{holder:?}] Executing Alice2Bob payment tx");
info!(target: "money", "[{holder:?}] ==============================");
let write = holder == &Holder::Faucet;
th.execute_transfer_tx(holder, &transfer_tx, &transfer_params, current_slot, write)
.await?;
th.execute_transfer_tx(
holder,
&transfer_tx,
&transfer_params,
current_block_height,
write,
)
.await?;
}
// Bob should now have a new OwnCoin.
@@ -166,8 +172,14 @@ fn mint_pay_swap() -> Result<()> {
info!(target: "money", "[{holder:?}] Executing Bob2Alice payment tx");
info!(target: "money", "[{holder:?}] ==============================");
let write = holder == &Holder::Faucet;
th.execute_transfer_tx(holder, &transfer_tx, &transfer_params, current_slot, write)
.await?;
th.execute_transfer_tx(
holder,
&transfer_tx,
&transfer_params,
current_block_height,
write,
)
.await?;
}
// Alice should now have two OwnCoins
@@ -213,8 +225,14 @@ fn mint_pay_swap() -> Result<()> {
info!(target: "money", "[{holder:?}] Executing AliceBob swap tx");
info!(target: "money", "[{holder:?}] ==========================");
let write = holder == &Holder::Faucet;
th.execute_otc_swap_tx(holder, &otc_swap_tx, &otc_swap_params, current_slot, write)
.await?;
th.execute_otc_swap_tx(
holder,
&otc_swap_tx,
&otc_swap_params,
current_block_height,
write,
)
.await?;
}
// Alice should now have two OwnCoins with the same token ID (ALICE)
@@ -258,7 +276,7 @@ fn mint_pay_swap() -> Result<()> {
info!(target: "money", "[{holder:?}] ================================");
info!(target: "money", "[{holder:?}] Executing Alice2Alice payment tx");
info!(target: "money", "[{holder:?}] ================================");
th.execute_transfer_tx(holder, &tx, &params, current_slot, true).await?;
th.execute_transfer_tx(holder, &tx, &params, current_block_height, true).await?;
}
th.assert_trees(&HOLDERS);
@@ -289,7 +307,7 @@ fn mint_pay_swap() -> Result<()> {
info!(target: "money", "[{holder:?}] ============================");
info!(target: "money", "[{holder:?}] Executing Bob2Bob payment tx");
info!(target: "money", "[{holder:?}] ============================");
th.execute_transfer_tx(holder, &tx, &params, current_slot, true).await?;
th.execute_transfer_tx(holder, &tx, &params, current_block_height, true).await?;
}
th.assert_trees(&HOLDERS);
@@ -321,8 +339,14 @@ fn mint_pay_swap() -> Result<()> {
info!(target: "money", "[{holder:?}] Executing AliceBob swap tx");
info!(target: "money", "[{holder:?}] ==========================");
let write = holder == &Holder::Faucet;
th.execute_otc_swap_tx(holder, &otc_swap_tx, &otc_swap_params, current_slot, write)
.await?;
th.execute_otc_swap_tx(
holder,
&otc_swap_tx,
&otc_swap_params,
current_block_height,
write,
)
.await?;
}
assert_eq!(otc_swap_params.outputs.len(), 2);

View File

@@ -37,8 +37,8 @@ fn pow_reward() -> Result<()> {
// Holders this test will use
const HOLDERS: [Holder; 3] = [Holder::Faucet, Holder::Alice, Holder::Bob];
// Block height(slot) to verify against
let mut current_height = 0;
// Block height to verify against
let mut current_block_height = 0;
// Initialize harness
let mut th = TestHarness::new(&["money".to_string()], false).await?;
@@ -48,44 +48,58 @@ fn pow_reward() -> Result<()> {
// We are going to generate some erroneous transactions to
// test some malicious cases.
info!(target: "money", "[Malicious] =======================================");
info!(target: "money", "[Malicious] Building PoW reward tx for genesis slot");
info!(target: "money", "[Malicious] =======================================");
let (pow_reward_tx, _) = th.pow_reward(&Holder::Alice, None, current_height, Some(0))?;
info!(target: "money", "[Malicious] ========================================");
info!(target: "money", "[Malicious] Building PoW reward tx for genesis block");
info!(target: "money", "[Malicious] ========================================");
let (pow_reward_tx, _) =
th.pow_reward(&Holder::Alice, None, current_block_height, Some(0))?;
info!(target: "money", "[Malicious] =======================================");
info!(target: "money", "[Malicious] Checking PoW reward tx for genesis slot");
info!(target: "money", "[Malicious] =======================================");
th.execute_erroneous_pow_reward_tx(&Holder::Alice, &pow_reward_tx.clone(), current_height)
.await?;
info!(target: "money", "[Malicious] ========================================");
info!(target: "money", "[Malicious] Checking PoW reward tx for genesis block");
info!(target: "money", "[Malicious] ========================================");
th.execute_erroneous_pow_reward_tx(
&Holder::Alice,
&pow_reward_tx.clone(),
current_block_height,
)
.await?;
current_height += 1;
current_block_height += 1;
let alice_reward = expected_reward(current_height);
let alice_reward = expected_reward(current_block_height);
info!(target: "money", "[Malicious] ================================");
info!(target: "money", "[Malicious] Building erroneous PoW reward tx");
info!(target: "money", "[Malicious] ================================");
let (pow_reward_tx, _) =
th.pow_reward(&Holder::Alice, None, current_height, Some(alice_reward + 1))?;
th.pow_reward(&Holder::Alice, None, current_block_height, Some(alice_reward + 1))?;
info!(target: "money", "[Malicious] =======================================");
info!(target: "money", "[Malicious] Checking erroneous amount PoW reward tx");
info!(target: "money", "[Malicious] =======================================");
th.execute_erroneous_pow_reward_tx(&Holder::Alice, &pow_reward_tx.clone(), current_height)
.await?;
th.execute_erroneous_pow_reward_tx(
&Holder::Alice,
&pow_reward_tx.clone(),
current_block_height,
)
.await?;
info!(target: "money", "[Alice] ======================");
info!(target: "money", "[Alice] Building PoW reward tx");
info!(target: "money", "[Alice] ======================");
let (pow_reward_tx, pow_reward_params) =
th.pow_reward(&Holder::Alice, None, current_height, None)?;
th.pow_reward(&Holder::Alice, None, current_block_height, None)?;
for holder in &HOLDERS {
info!(target: "money", "[{holder:?}] =============================");
info!(target: "money", "[{holder:?}] Executing Alice PoW reward tx");
info!(target: "money", "[{holder:?}] =============================");
th.execute_pow_reward_tx(holder, &pow_reward_tx, &pow_reward_params, current_height)
.await?;
th.execute_pow_reward_tx(
holder,
&pow_reward_tx,
&pow_reward_params,
current_block_height,
)
.await?;
}
th.assert_trees(&HOLDERS);
@@ -113,8 +127,14 @@ fn pow_reward() -> Result<()> {
info!(target: "money", "[{holder:?}] ==============================");
info!(target: "money", "[{holder:?}] Executing Alice2Bob payment tx");
info!(target: "money", "[{holder:?}] ==============================");
th.execute_transfer_tx(holder, &transfer_tx, &transfer_params, current_height, true)
.await?;
th.execute_transfer_tx(
holder,
&transfer_tx,
&transfer_params,
current_block_height,
true,
)
.await?;
}
th.assert_trees(&HOLDERS);
@@ -132,14 +152,19 @@ fn pow_reward() -> Result<()> {
info!(target: "money", "[Alice] Building PoW reward tx for Bob");
info!(target: "money", "[Alice] ==============================");
let (pow_reward_tx, pow_reward_params) =
th.pow_reward(&Holder::Alice, Some(&Holder::Bob), current_height, None)?;
th.pow_reward(&Holder::Alice, Some(&Holder::Bob), current_block_height, None)?;
for holder in &HOLDERS {
info!(target: "money", "[{holder:?}] =====================================");
info!(target: "money", "[{holder:?}] Executing Alice PoW reward tx for Bob");
info!(target: "money", "[{holder:?}] =====================================");
th.execute_pow_reward_tx(holder, &pow_reward_tx, &pow_reward_params, current_height)
.await?;
th.execute_pow_reward_tx(
holder,
&pow_reward_tx,
&pow_reward_params,
current_block_height,
)
.await?;
}
th.assert_trees(&HOLDERS);

View File

@@ -31,8 +31,8 @@ fn token_mint() -> Result<()> {
// Some numbers we want to assert
const BOB_SUPPLY: u64 = 2000000000; // 10 BOB
// Slot to verify against
let current_slot = 0;
// Block height to verify against
let current_block_height = 0;
// Initialize harness
let mut th = TestHarness::new(&["money".to_string()], false).await?;
@@ -43,8 +43,13 @@ fn token_mint() -> Result<()> {
for holder in &HOLDERS {
info!("[{holder:?}] Executing BOB token mint tx");
th.execute_token_mint_tx(holder, &token_mint_tx, &token_mint_params, current_slot)
.await?;
th.execute_token_mint_tx(
holder,
&token_mint_tx,
&token_mint_params,
current_block_height,
)
.await?;
}
th.assert_trees(&HOLDERS);
@@ -57,8 +62,13 @@ fn token_mint() -> Result<()> {
for holder in &HOLDERS {
info!("[{holder:?}] Executing BOB token freeze tx");
th.execute_token_freeze_tx(holder, &token_frz_tx, &token_frz_params, current_slot)
.await?;
th.execute_token_freeze_tx(
holder,
&token_frz_tx,
&token_frz_params,
current_block_height,
)
.await?;
}
th.assert_trees(&HOLDERS);

View File

@@ -43,8 +43,8 @@ fn txs_verification() -> Result<()> {
// Bob = 50 ALICE
const ALICE_SEND: u64 = ALICE_INITIAL - 50;
// Slot to verify against
let current_slot = 0;
// Block height to verify against
let current_block_height = 0;
// Initialize harness
let mut th = TestHarness::new(&["money".to_string()], false).await?;
@@ -62,8 +62,13 @@ fn txs_verification() -> Result<()> {
info!(target: "money", "[{holder:?}] =============================");
info!(target: "money", "[{holder:?}] Executing Alice token mint tx");
info!(target: "money", "[{holder:?}] =============================");
th.execute_token_mint_tx(holder, &token_mint_tx, &token_mint_params, current_slot)
.await?;
th.execute_token_mint_tx(
holder,
&token_mint_tx,
&token_mint_params,
current_block_height,
)
.await?;
}
th.assert_trees(&HOLDERS);
@@ -101,7 +106,7 @@ fn txs_verification() -> Result<()> {
info!(target: "money", "[{holder:?}] ==================================");
info!(target: "money", "[{holder:?}] Verifying Alice2Bob payment tx {i}");
info!(target: "money", "[{holder:?}] ==================================");
th.verify_transfer_tx(holder, &transfer_tx, current_slot).await?;
th.verify_transfer_tx(holder, &transfer_tx, current_block_height).await?;
}
transactions.push(transfer_tx);
@@ -122,12 +127,18 @@ fn txs_verification() -> Result<()> {
TxAction::MoneyTransfer,
holder,
&transactions,
current_slot,
current_block_height,
duplicates - 1,
)
.await?;
th.execute_transfer_tx(holder, &transactions[0], &txs_params[0], current_slot, true)
.await?;
th.execute_transfer_tx(
holder,
&transactions[0],
&txs_params[0],
current_block_height,
true,
)
.await?;
}
th.assert_trees(&HOLDERS);

View File

@@ -34,8 +34,8 @@ fn alice2alice_random_amounts() -> Result<()> {
const ALICE_AIRDROP: u64 = 1000;
// Slot to verify against
let current_slot = 0;
// Block height to verify against
let current_block_height = 0;
// n transactions to loop
let mut n = 3;
@@ -62,8 +62,13 @@ fn alice2alice_random_amounts() -> Result<()> {
info!(target: "money", "[{holder:?}] ==========================");
info!(target: "money", "[{holder:?}] Executing Alice airdrop tx");
info!(target: "money", "[{holder:?}] ==========================");
th.execute_airdrop_native_tx(holder, &airdrop_tx, &airdrop_params, current_slot)
.await?;
th.execute_airdrop_native_tx(
holder,
&airdrop_tx,
&airdrop_params,
current_block_height,
)
.await?;
}
th.assert_trees(&HOLDERS);
@@ -97,12 +102,14 @@ fn alice2alice_random_amounts() -> Result<()> {
info!(target: "money", "[Faucet] ================================");
info!(target: "money", "[Faucet] Executing Alice2Alice payment tx");
info!(target: "money", "[Faucet] ================================");
th.execute_transfer_tx(&Holder::Faucet, &tx, &params, current_slot, true).await?;
th.execute_transfer_tx(&Holder::Faucet, &tx, &params, current_block_height, true)
.await?;
info!(target: "money", "[Alice] ================================");
info!(target: "money", "[Alice] Executing Alice2Alice payment tx");
info!(target: "money", "[Alice] ================================");
th.execute_transfer_tx(&Holder::Alice, &tx, &params, current_slot, false).await?;
th.execute_transfer_tx(&Holder::Alice, &tx, &params, current_block_height, false)
.await?;
// Gather new owncoins
owncoins.append(&mut th.gather_multiple_owncoins(&Holder::Alice, &params.outputs)?);
@@ -127,8 +134,8 @@ fn alice2alice_multiplecoins_random_amounts() -> Result<()> {
// Holders this test will use
const HOLDERS: [Holder; 2] = [Holder::Faucet, Holder::Alice];
// Slot to verify against
let current_slot = 0;
// Block height to verify against
let current_block_height = 0;
// N blocks to simulate
let mut n = 3;
@@ -161,7 +168,8 @@ fn alice2alice_multiplecoins_random_amounts() -> Result<()> {
info!(target: "money", "[{holder:?}] =======================");
info!(target: "money", "[{holder:?}] Executing Alice mint tx");
info!(target: "money", "[{holder:?}] =======================");
th.execute_token_mint_tx(holder, &mint_tx, &mint_params, current_slot).await?;
th.execute_token_mint_tx(holder, &mint_tx, &mint_params, current_block_height)
.await?;
}
th.assert_trees(&HOLDERS);
@@ -226,7 +234,7 @@ fn alice2alice_multiplecoins_random_amounts() -> Result<()> {
&Holder::Faucet,
&txs,
&txs_params,
current_slot,
current_block_height,
true,
)
.await?;
@@ -238,7 +246,7 @@ fn alice2alice_multiplecoins_random_amounts() -> Result<()> {
&Holder::Alice,
&txs,
&txs_params,
current_slot,
current_block_height,
false,
)
.await?;

View File

@@ -68,11 +68,11 @@ impl TestHarness {
holder: &Holder,
tx: &Transaction,
_params: &DeployParamsV1,
slot: u64,
block_height: u64,
) -> Result<()> {
let wallet = self.holders.get_mut(holder).unwrap();
wallet.validator.add_transactions(&[tx.clone()], slot, true).await?;
wallet.validator.add_transactions(&[tx.clone()], block_height, true).await?;
Ok(())
}

View File

@@ -238,13 +238,13 @@ impl TestHarness {
tx: &Transaction,
xfer_params: &MoneyTransferParamsV1,
_exec_params: &DaoExecParams,
slot: u64,
block_height: u64,
) -> Result<()> {
let wallet = self.holders.get_mut(holder).unwrap();
let tx_action_benchmark = self.tx_action_benchmarks.get_mut(&TxAction::DaoExec).unwrap();
let timer = Instant::now();
wallet.validator.add_transactions(&[tx.clone()], slot, true).await?;
wallet.validator.add_transactions(&[tx.clone()], block_height, true).await?;
for output in &xfer_params.outputs {
wallet.money_merkle_tree.append(MerkleNode::from(output.coin.inner()));

View File

@@ -76,13 +76,13 @@ impl TestHarness {
holder: &Holder,
tx: &Transaction,
params: &DaoMintParams,
slot: u64,
block_height: u64,
) -> Result<()> {
let wallet = self.holders.get_mut(holder).unwrap();
let tx_action_benchmark = self.tx_action_benchmarks.get_mut(&TxAction::DaoMint).unwrap();
let timer = Instant::now();
wallet.validator.add_transactions(&[tx.clone()], slot, true).await?;
wallet.validator.add_transactions(&[tx.clone()], block_height, true).await?;
wallet.dao_merkle_tree.append(MerkleNode::from(params.dao_bulla.inner()));
let leaf_pos = wallet.dao_merkle_tree.mark().unwrap();
wallet.dao_leafs.insert(params.dao_bulla, leaf_pos);

View File

@@ -99,7 +99,7 @@ impl TestHarness {
];
let creation_day =
blockheight_to_day(wallet.validator.consensus.time_keeper.verifying_slot);
blockheight_to_day(wallet.validator.consensus.time_keeper.verifying_block_height);
let proposal = DaoProposal {
auth_calls,
creation_day,
@@ -153,13 +153,13 @@ impl TestHarness {
holder: &Holder,
tx: &Transaction,
params: &DaoProposeParams,
slot: u64,
block_height: u64,
) -> Result<()> {
let wallet = self.holders.get_mut(holder).unwrap();
let tx_action_benchmark = self.tx_action_benchmarks.get_mut(&TxAction::DaoPropose).unwrap();
let timer = Instant::now();
wallet.validator.add_transactions(&[tx.clone()], slot, true).await?;
wallet.validator.add_transactions(&[tx.clone()], block_height, true).await?;
wallet.dao_proposals_tree.append(MerkleNode::from(params.proposal_bulla.inner()));
let prop_leaf_pos = wallet.dao_proposals_tree.mark().unwrap();

View File

@@ -78,7 +78,8 @@ impl TestHarness {
signature_secret,
};
let current_day = blockheight_to_day(wallet.validator.consensus.time_keeper.verifying_slot);
let current_day =
blockheight_to_day(wallet.validator.consensus.time_keeper.verifying_block_height);
let call = DaoVoteCall {
inputs: vec![input],
vote_option,
@@ -120,13 +121,13 @@ impl TestHarness {
holder: &Holder,
tx: &Transaction,
_params: &DaoVoteParams,
slot: u64,
block_height: u64,
) -> Result<()> {
let wallet = self.holders.get_mut(holder).unwrap();
let tx_action_benchmark = self.tx_action_benchmarks.get_mut(&TxAction::DaoVote).unwrap();
let timer = Instant::now();
wallet.validator.add_transactions(&[tx.clone()], slot, true).await?;
wallet.validator.add_transactions(&[tx.clone()], block_height, true).await?;
tx_action_benchmark.verify_times.push(timer.elapsed());

View File

@@ -36,7 +36,6 @@ use darkfi_money_contract::{
model::Output,
};
use darkfi_sdk::{
blockchain::{PidOutput, PreviousSlot, Slot},
bridgetree,
crypto::{
pasta_prelude::Field, poseidon_hash, ContractId, Keypair, MerkleNode, MerkleTree,
@@ -266,7 +265,7 @@ impl TestHarness {
action: TxAction,
holder: &Holder,
txs: &[Transaction],
slot: u64,
block_height: u64,
erroneous: usize,
) -> Result<()> {
let wallet = self.holders.get(holder).unwrap();
@@ -275,7 +274,7 @@ impl TestHarness {
let erroneous_txs = wallet
.validator
.add_transactions(txs, slot, false)
.add_transactions(txs, block_height, false)
.await
.err()
.unwrap()
@@ -383,30 +382,6 @@ impl TestHarness {
Ok(owncoin.unwrap())
}
pub async fn get_slot_by_slot(&self, slot: u64) -> Result<Slot> {
let faucet = self.holders.get(&Holder::Faucet).unwrap();
let slot = faucet.validator.blockchain.get_slots_by_id(&[slot])?[0].clone().unwrap();
Ok(slot)
}
pub async fn generate_slot(&self, id: u64) -> Result<Slot> {
// We grab the genesis slot to generate slot
// using same consensus parameters
let genesis_block = self.genesis_block.hash()?;
let genesis_slot = self.get_slot_by_slot(0).await?;
let previous = PreviousSlot::new(0, vec![genesis_block], vec![genesis_block], 0.0);
let pid = PidOutput::new(0.0, 0.0, genesis_slot.pid.sigma1, genesis_slot.pid.sigma2);
let slot = Slot::new(id, previous, pid, genesis_slot.last_nonce, 0, 0);
// Store generated slot
for wallet in self.holders.values() {
wallet.validator.receive_test_slot(&slot).await?;
}
Ok(slot)
}
pub fn assert_trees(&self, holders: &[Holder]) {
assert!(holders.len() > 1);
// Gather wallets

View File

@@ -110,14 +110,14 @@ impl TestHarness {
holder: &Holder,
tx: &Transaction,
params: &MoneyTransferParamsV1,
slot: u64,
block_height: u64,
) -> Result<()> {
let wallet = self.holders.get_mut(holder).unwrap();
let tx_action_benchmark =
self.tx_action_benchmarks.get_mut(&TxAction::MoneyAirdrop).unwrap();
let timer = Instant::now();
wallet.validator.add_transactions(&[tx.clone()], slot, true).await?;
wallet.validator.add_transactions(&[tx.clone()], block_height, true).await?;
wallet.money_merkle_tree.append(MerkleNode::from(params.outputs[0].coin.inner()));
tx_action_benchmark.verify_times.push(timer.elapsed());
@@ -130,7 +130,7 @@ impl TestHarness {
holders: &[Holder],
holder: &Holder,
value: u64,
current_slot: u64,
block_height: u64,
) -> Result<OwnCoin> {
info!(target: "consensus", "[Faucet] ==============================");
info!(target: "consensus", "[Faucet] Building {holder:?} airdrop tx");
@@ -141,7 +141,7 @@ impl TestHarness {
info!(target: "consensus", "[{h:?}] ===============================");
info!(target: "consensus", "[{h:?}] Executing {holder:?} airdrop tx");
info!(target: "consensus", "[{h:?}] ===============================");
self.execute_airdrop_native_tx(h, &airdrop_tx, &airdrop_params, current_slot).await?;
self.execute_airdrop_native_tx(h, &airdrop_tx, &airdrop_params, block_height).await?;
}
self.assert_trees(holders);

View File

@@ -93,14 +93,14 @@ impl TestHarness {
holder: &Holder,
tx: &Transaction,
params: &MoneyTokenMintParamsV1,
slot: u64,
block_height: u64,
) -> Result<()> {
let wallet = self.holders.get_mut(holder).unwrap();
let tx_action_benchmark =
self.tx_action_benchmarks.get_mut(&TxAction::MoneyGenesisMint).unwrap();
let timer = Instant::now();
wallet.validator.add_transactions(&[tx.clone()], slot, true).await?;
wallet.validator.add_transactions(&[tx.clone()], block_height, true).await?;
wallet.money_merkle_tree.append(MerkleNode::from(params.output.coin.inner()));
tx_action_benchmark.verify_times.push(timer.elapsed());

View File

@@ -166,7 +166,7 @@ impl TestHarness {
holder: &Holder,
tx: &Transaction,
params: &MoneyTransferParamsV1,
slot: u64,
block_height: u64,
append: bool,
) -> Result<()> {
let wallet = self.holders.get_mut(holder).unwrap();
@@ -174,7 +174,7 @@ impl TestHarness {
self.tx_action_benchmarks.get_mut(&TxAction::MoneyOtcSwap).unwrap();
let timer = Instant::now();
wallet.validator.add_transactions(&[tx.clone()], slot, true).await?;
wallet.validator.add_transactions(&[tx.clone()], block_height, true).await?;
if append {
for output in &params.outputs {
wallet.money_merkle_tree.append(MerkleNode::from(output.coin.inner()));

View File

@@ -98,14 +98,14 @@ impl TestHarness {
holder: &Holder,
tx: &Transaction,
params: &MoneyTokenMintParamsV1,
slot: u64,
block_height: u64,
) -> Result<()> {
let wallet = self.holders.get_mut(holder).unwrap();
let tx_action_benchmark =
self.tx_action_benchmarks.get_mut(&TxAction::MoneyTokenMint).unwrap();
let timer = Instant::now();
wallet.validator.add_transactions(&[tx.clone()], slot, true).await?;
wallet.validator.add_transactions(&[tx.clone()], block_height, true).await?;
wallet.money_merkle_tree.append(MerkleNode::from(params.output.coin.inner()));
tx_action_benchmark.verify_times.push(timer.elapsed());
@@ -161,14 +161,14 @@ impl TestHarness {
holder: &Holder,
tx: &Transaction,
_params: &MoneyTokenFreezeParamsV1,
slot: u64,
block_height: u64,
) -> Result<()> {
let wallet = self.holders.get_mut(holder).unwrap();
let tx_action_benchmark =
self.tx_action_benchmarks.get_mut(&TxAction::MoneyTokenFreeze).unwrap();
let timer = Instant::now();
wallet.validator.add_transactions(&[tx.clone()], slot, true).await?;
wallet.validator.add_transactions(&[tx.clone()], block_height, true).await?;
tx_action_benchmark.verify_times.push(timer.elapsed());
Ok(())

View File

@@ -98,7 +98,7 @@ impl TestHarness {
holder: &Holder,
tx: &Transaction,
params: &MoneyTransferParamsV1,
slot: u64,
block_height: u64,
append: bool,
) -> Result<()> {
let wallet = self.holders.get_mut(holder).unwrap();
@@ -106,7 +106,7 @@ impl TestHarness {
self.tx_action_benchmarks.get_mut(&TxAction::MoneyTransfer).unwrap();
let timer = Instant::now();
wallet.validator.add_transactions(&[tx.clone()], slot, true).await?;
wallet.validator.add_transactions(&[tx.clone()], block_height, true).await?;
if append {
for output in &params.outputs {
wallet.money_merkle_tree.append(MerkleNode::from(output.coin.inner()));
@@ -122,7 +122,7 @@ impl TestHarness {
holder: &Holder,
txs: &[Transaction],
txs_params: &Vec<MoneyTransferParamsV1>,
slot: u64,
block_height: u64,
append: bool,
) -> Result<()> {
let wallet = self.holders.get_mut(holder).unwrap();
@@ -130,7 +130,7 @@ impl TestHarness {
self.tx_action_benchmarks.get_mut(&TxAction::MoneyTransfer).unwrap();
let timer = Instant::now();
wallet.validator.add_transactions(txs, slot, true).await?;
wallet.validator.add_transactions(txs, block_height, true).await?;
if append {
for params in txs_params {
for output in &params.outputs {
@@ -147,14 +147,14 @@ impl TestHarness {
&mut self,
holder: &Holder,
tx: &Transaction,
slot: u64,
block_height: u64,
) -> Result<()> {
let wallet = self.holders.get(holder).unwrap();
let tx_action_benchmark =
self.tx_action_benchmarks.get_mut(&TxAction::MoneyTransfer).unwrap();
let timer = Instant::now();
wallet.validator.add_transactions(&[tx.clone()], slot, false).await?;
wallet.validator.add_transactions(&[tx.clone()], block_height, false).await?;
tx_action_benchmark.verify_times.push(timer.elapsed());
Ok(())

View File

@@ -240,26 +240,14 @@ pub(crate) fn get_current_slot(ctx: FunctionEnvMut<Env>) -> u64 {
/// which is equivalent to verifying slot number.
pub(crate) fn get_verifying_block_height(ctx: FunctionEnvMut<Env>) -> u64 {
// TODO: Gas cost
ctx.data().time_keeper.verifying_slot
}
/// Will return current runtime configured verifying slot number.
pub(crate) fn get_verifying_slot(ctx: FunctionEnvMut<Env>) -> u64 {
// TODO: Gas cost
ctx.data().time_keeper.verifying_slot
ctx.data().time_keeper.verifying_block_height
}
/// Will return current runtime configured verifying block height epoch number,
/// which is equivalent to verifying slot epoch number.
pub(crate) fn get_verifying_block_height_epoch(ctx: FunctionEnvMut<Env>) -> u64 {
// TODO: Gas cost
ctx.data().time_keeper.verifying_slot_epoch()
}
/// Will return current runtime configured verifying slot epoch number.
pub(crate) fn get_verifying_slot_epoch(ctx: FunctionEnvMut<Env>) -> u64 {
// TODO: Gas cost
ctx.data().time_keeper.verifying_slot_epoch()
ctx.data().time_keeper.verifying_block_height_epoch()
}
/// Grabs last block from the `Blockchain` overlay and then copies its

View File

@@ -301,24 +301,12 @@ impl Runtime {
import::util::get_verifying_block_height,
),
"get_verifying_slot_" => Function::new_typed_with_env(
&mut store,
&ctx,
import::util::get_verifying_slot,
),
"get_verifying_block_height_epoch_" => Function::new_typed_with_env(
&mut store,
&ctx,
import::util::get_verifying_block_height_epoch,
),
"get_verifying_slot_epoch_" => Function::new_typed_with_env(
&mut store,
&ctx,
import::util::get_verifying_slot_epoch,
),
"get_slot_" => Function::new_typed_with_env(
&mut store,
&ctx,

View File

@@ -114,16 +114,6 @@ pub fn get_verifying_block_height() -> u64 {
unsafe { get_verifying_block_height_() }
}
/// Everyone can call this. Will return runtime configured
/// verifying slot.
///
/// ```
/// slot = get_verifying_slot();
/// ```
pub fn get_verifying_slot() -> u64 {
unsafe { get_verifying_slot_() }
}
/// Everyone can call this. Will return runtime configured
/// verifying block height epoch.
///
@@ -134,16 +124,6 @@ pub fn get_verifying_block_height_epoch() -> u64 {
unsafe { get_verifying_block_height_epoch_() }
}
/// Everyone can call this. Will return runtime configured
/// verifying slot epoch.
///
/// ```
/// epoch = get_verifying_slot_epoch();
/// ```
pub fn get_verifying_slot_epoch() -> u64 {
unsafe { get_verifying_slot_epoch_() }
}
/// Everyone can call this. Will return requested slot from `SlotStore`.
///
/// ```
@@ -183,9 +163,7 @@ extern "C" {
fn get_current_block_height_() -> u64;
fn get_current_slot_() -> u64;
fn get_verifying_block_height_() -> u64;
fn get_verifying_slot_() -> u64;
fn get_verifying_block_height_epoch_() -> u64;
fn get_verifying_slot_epoch_() -> u64;
fn get_slot_(slot: u64) -> i64;
fn get_blockchain_time_() -> u64;
fn get_last_block_info_() -> i64;

View File

@@ -44,8 +44,8 @@ pub struct TimeKeeper {
pub epoch_length: u64,
/// Currently configured slot duration
pub slot_time: u64,
/// Slot number runtime can access to verify against
pub verifying_slot: u64,
/// Block height(slot) number runtime can access to verify against
pub verifying_block_height: u64,
}
impl TimeKeeper {
@@ -53,9 +53,9 @@ impl TimeKeeper {
genesis_ts: Timestamp,
epoch_length: u64,
slot_time: u64,
verifying_slot: u64,
verifying_block_height: u64,
) -> Self {
Self { genesis_ts, epoch_length, slot_time, verifying_slot }
Self { genesis_ts, epoch_length, slot_time, verifying_block_height }
}
/// Generate a TimeKeeper for current slot
@@ -64,7 +64,7 @@ impl TimeKeeper {
genesis_ts: self.genesis_ts,
epoch_length: self.epoch_length,
slot_time: self.slot_time,
verifying_slot: self.current_slot(),
verifying_block_height: self.current_slot(),
}
}
@@ -99,8 +99,8 @@ impl TimeKeeper {
}
/// Calculates the epoch of the verifying slot.
pub fn verifying_slot_epoch(&self) -> u64 {
self.slot_epoch(self.verifying_slot)
pub fn verifying_block_height_epoch(&self) -> u64 {
self.slot_epoch(self.verifying_block_height)
}
/// Calculates seconds until next Nth slot starting time.
@@ -148,7 +148,7 @@ impl TimeKeeperSafe {
genesis_ts: Timestamp,
epoch_length: u64,
slot_time: u64,
verifying_slot: u64,
verifying_block_height: u64,
) -> Self {
// TimeKeeper uses epoch_length and slot_time as divisors so they should
// never be zero in this struct.
@@ -158,7 +158,9 @@ impl TimeKeeperSafe {
if slot_time == 0 {
panic!("Slot time cannot be zero");
}
Self { timekeeper: TimeKeeper { genesis_ts, epoch_length, slot_time, verifying_slot } }
Self {
timekeeper: TimeKeeper { genesis_ts, epoch_length, slot_time, verifying_block_height },
}
}
/// Generate a TimeKeeperSafe for current slot
pub fn current(&self) -> TimeKeeperSafe {
@@ -166,7 +168,7 @@ impl TimeKeeperSafe {
self.timekeeper.genesis_ts,
self.timekeeper.epoch_length,
self.timekeeper.slot_time,
self.timekeeper.verifying_slot,
self.timekeeper.verifying_block_height,
)
}
@@ -205,8 +207,8 @@ impl TimeKeeperSafe {
}
/// Calculates the epoch of the verifying slot.
pub fn verifying_slot_epoch(&self) -> u64 {
self.timekeeper.verifying_slot_epoch()
pub fn verifying_block_height_epoch(&self) -> u64 {
self.timekeeper.verifying_block_height_epoch()
}
/// Calculates seconds until next Nth slot starting time.

View File

@@ -147,7 +147,7 @@ impl Consensus {
// Generate a time keeper for next/current slot
let time_keeper = if slot.id < POS_START {
let mut t = self.time_keeper.current();
t.verifying_slot = slot.id;
t.verifying_block_height = slot.id;
t
} else {
self.time_keeper.current()
@@ -312,10 +312,10 @@ impl Consensus {
// Validate and insert each block
for block in blocks {
// Use block slot in time keeper
time_keeper.verifying_slot = block.header.height;
time_keeper.verifying_block_height = block.header.height;
// Retrieve expected reward
let expected_reward = expected_reward(time_keeper.verifying_slot);
let expected_reward = expected_reward(time_keeper.verifying_block_height);
// Verify block
if verify_block(
@@ -348,7 +348,7 @@ impl Consensus {
if proposal.block.header.height < POS_START {
fork.generate_pow_slot()?;
} else {
let id = time_keeper.verifying_slot;
let id = time_keeper.verifying_block_height;
let (producers, last_hashes, second_to_last_hashes) =
previous_slot_info(&forks, id - 1)?;
fork.generate_pos_slot(id, producers, &last_hashes, &second_to_last_hashes)?;

View File

@@ -407,10 +407,10 @@ impl Validator {
// Validate and insert each block
for block in blocks {
// Use block height in time keeper
time_keeper.verifying_slot = block.header.height;
time_keeper.verifying_block_height = block.header.height;
// Retrieve expected reward
let expected_reward = expected_reward(time_keeper.verifying_slot);
let expected_reward = expected_reward(time_keeper.verifying_block_height);
// Verify block
if verify_block(
@@ -474,7 +474,7 @@ impl Validator {
pub async fn add_transactions(
&self,
txs: &[Transaction],
verifying_slot: u64,
verifying_block_height: u64,
write: bool,
) -> Result<()> {
debug!(target: "validator::add_transactions", "Instantiating BlockchainOverlay");
@@ -486,7 +486,7 @@ impl Validator {
current_time_keeper.genesis_ts,
current_time_keeper.epoch_length,
current_time_keeper.slot_time,
verifying_slot,
verifying_block_height,
);
// Verify all transactions and get erroneous ones
@@ -527,7 +527,7 @@ impl Validator {
pub async fn add_test_producer_transaction(
&self,
tx: &Transaction,
verifying_slot: u64,
verifying_block_height: u64,
write: bool,
) -> Result<()> {
debug!(target: "validator::add_test_producer_transaction", "Instantiating BlockchainOverlay");
@@ -539,7 +539,7 @@ impl Validator {
current_time_keeper.genesis_ts,
current_time_keeper.epoch_length,
current_time_keeper.slot_time,
verifying_slot,
verifying_block_height,
);
// Verify transaction
@@ -606,10 +606,10 @@ impl Validator {
// Validate and insert each block
for block in &blocks[1..] {
// Use block height in time keeper
time_keeper.verifying_slot = block.header.height;
time_keeper.verifying_block_height = block.header.height;
// Retrieve expected reward
let expected_reward = expected_reward(time_keeper.verifying_slot);
let expected_reward = expected_reward(time_keeper.verifying_block_height);
// Verify block
if verify_block(

View File

@@ -70,7 +70,7 @@ pub async fn verify_genesis_block(
}
// Block height must be the same as the time keeper verifying slot
if block.header.height != time_keeper.verifying_slot {
if block.header.height != time_keeper.verifying_block_height {
return Err(Error::VerifyingSlotMissmatch())
}
@@ -145,7 +145,7 @@ pub async fn verify_block(
}
// Block height must be the same as the time keeper verifying slot
if block.header.height != time_keeper.verifying_slot {
if block.header.height != time_keeper.verifying_block_height {
return Err(Error::VerifyingSlotMissmatch())
}
@@ -680,7 +680,7 @@ pub async fn verify_pow_proposal(
// Generate a time keeper for proposal block leight
let mut time_keeper = consensus.time_keeper.current();
time_keeper.verifying_slot = proposal.block.header.height;
time_keeper.verifying_block_height = proposal.block.header.height;
// Verify proposal block (4)
if verify_block(
@@ -721,7 +721,7 @@ pub async fn verify_pos_proposal(
let time_keeper = consensus.time_keeper.current();
// Node have already checked for finalization in this slot (1)
if time_keeper.verifying_slot <= *consensus.checked_finalization.read().await {
if time_keeper.verifying_block_height <= *consensus.checked_finalization.read().await {
warn!(target: "validator::verification::verify_pos_proposal", "Proposal received after finalization sync period.");
return Err(Error::ProposalAfterFinalizationError)
}
@@ -730,7 +730,7 @@ pub async fn verify_pos_proposal(
let hdr = &proposal.block.header;
// Ignore proposal if not for current slot (2)
if hdr.height != time_keeper.verifying_slot {
if hdr.height != time_keeper.verifying_block_height {
return Err(Error::ProposalNotForCurrentSlotError)
}
@@ -771,7 +771,7 @@ pub async fn verify_pos_proposal(
let previous = fork.overlay.lock().unwrap().last_block()?;
// Retrieve expected reward
let expected_reward = expected_reward(time_keeper.verifying_slot);
let expected_reward = expected_reward(time_keeper.verifying_block_height);
// Verify proposal block (6)
if verify_block(