contract/money: Faucet cleanup

This removes clear inputs from Money::Transfer, and removes all faucet
references in the code.

Additionally, in src/validator/ we use the ValidatorConfig struct
directly, rather than using the ValidatorConfig::new() function.
This commit is contained in:
parazyd
2024-02-08 11:59:33 +01:00
parent 0957973ff6
commit 00aefdded5
16 changed files with 57 additions and 182 deletions

View File

@@ -18,7 +18,6 @@
use std::sync::Arc;
use darkfi_sdk::crypto::{MerkleTree, PublicKey};
use darkfi_serial::serialize_async;
use log::{debug, error, info, warn};
use num_bigint::BigUint;
@@ -67,32 +66,10 @@ pub struct ValidatorConfig {
pub pow_fixed_difficulty: Option<BigUint>,
/// Genesis block
pub genesis_block: BlockInfo,
/// Whitelisted faucet pubkeys (testnet stuff)
pub faucet_pubkeys: Vec<PublicKey>,
/// Flag to enable tx fee verification
pub verify_fees: bool,
}
impl ValidatorConfig {
pub fn new(
finalization_threshold: usize,
pow_target: usize,
pow_fixed_difficulty: Option<BigUint>,
genesis_block: BlockInfo,
faucet_pubkeys: Vec<PublicKey>,
verify_fees: bool,
) -> Self {
Self {
finalization_threshold,
pow_target,
pow_fixed_difficulty,
genesis_block,
faucet_pubkeys,
verify_fees,
}
}
}
/// Atomic pointer to validator.
pub type ValidatorPtr = Arc<Validator>;
@@ -119,7 +96,7 @@ impl Validator {
let overlay = BlockchainOverlay::new(&blockchain)?;
// Deploy native wasm contracts
deploy_native_contracts(&overlay, &config.faucet_pubkeys).await?;
deploy_native_contracts(&overlay).await?;
// Add genesis block if blockchain is empty
if blockchain.genesis().is_err() {
@@ -536,7 +513,6 @@ impl Validator {
/// Be careful as this will try to load everything in memory.
pub async fn validate_blockchain(
&self,
faucet_pubkeys: Vec<PublicKey>,
pow_target: usize,
pow_fixed_difficulty: Option<BigUint>,
) -> Result<()> {
@@ -559,7 +535,7 @@ impl Validator {
let mut module = PoWModule::new(blockchain.clone(), pow_target, pow_fixed_difficulty)?;
// Deploy native wasm contracts
deploy_native_contracts(&overlay, &faucet_pubkeys).await?;
deploy_native_contracts(&overlay).await?;
// Validate genesis block
verify_genesis_block(&overlay, previous).await?;

View File

@@ -18,12 +18,12 @@
use darkfi_sdk::{
crypto::{
ecvrf::VrfProof, pasta_prelude::PrimeField, PublicKey, DAO_CONTRACT_ID,
DEPLOYOOOR_CONTRACT_ID, MONEY_CONTRACT_ID,
ecvrf::VrfProof, pasta_prelude::PrimeField, DAO_CONTRACT_ID, DEPLOYOOOR_CONTRACT_ID,
MONEY_CONTRACT_ID,
},
pasta::{group::ff::FromUniformBytes, pallas},
};
use darkfi_serial::{serialize_async, AsyncDecodable};
use darkfi_serial::AsyncDecodable;
use log::info;
use smol::io::Cursor;
@@ -44,15 +44,11 @@ use crate::{
/// touch anything, or just potentially update the db schemas or whatever
/// is necessary. This logic should be handled in the init function of
/// the actual contract, so make sure the native contracts handle this well.
pub async fn deploy_native_contracts(
overlay: &BlockchainOverlayPtr,
faucet_pubkeys: &Vec<PublicKey>,
) -> Result<()> {
pub async fn deploy_native_contracts(overlay: &BlockchainOverlayPtr) -> Result<()> {
info!(target: "validator::utils::deploy_native_contracts", "Deploying native WASM contracts");
// The faucet pubkeys are pubkeys which are allowed to create clear inputs
// in the Money contract.
let money_contract_deploy_payload = serialize_async(faucet_pubkeys).await;
// The Money contract uses an empty payload to deploy itself.
let money_contract_deploy_payload = vec![];
// The DAO contract uses an empty payload to deploy itself.
let dao_contract_deploy_payload = vec![];