contract/dao: Avoid unnecessary db key serialization

This commit is contained in:
parazyd
2023-12-19 17:10:57 +01:00
parent 8690575c43
commit 349fd7a854
4 changed files with 9 additions and 13 deletions

View File

@@ -83,7 +83,7 @@ fn init_contract(cid: ContractId, _ix: &[u8]) -> ContractResult {
};
// Set up the entries in the header table
match db_get(dao_info_db, &serialize(&DAO_CONTRACT_KEY_DAO_MERKLE_TREE))? {
match db_get(dao_info_db, DAO_CONTRACT_KEY_DAO_MERKLE_TREE)? {
Some(bytes) => {
// We found some bytes, try to deserialize into a tree.
// For now, if this doesn't work, we bail.
@@ -99,7 +99,7 @@ fn init_contract(cid: ContractId, _ix: &[u8]) -> ContractResult {
tree_data.write_u32(0)?;
tree.encode(&mut tree_data)?;
db_set(dao_info_db, &serialize(&DAO_CONTRACT_KEY_DAO_MERKLE_TREE), &tree_data)?;
db_set(dao_info_db, DAO_CONTRACT_KEY_DAO_MERKLE_TREE, &tree_data)?;
}
}
@@ -130,11 +130,7 @@ fn init_contract(cid: ContractId, _ix: &[u8]) -> ContractResult {
};
// Update db version
db_set(
dao_info_db,
&serialize(&DAO_CONTRACT_KEY_DB_VERSION),
&serialize(&env!("CARGO_PKG_VERSION")),
)?;
db_set(dao_info_db, DAO_CONTRACT_KEY_DB_VERSION, &serialize(&env!("CARGO_PKG_VERSION")))?;
Ok(())
}

View File

@@ -103,8 +103,8 @@ pub(crate) fn dao_mint_process_update(cid: ContractId, update: DaoMintUpdate) ->
merkle_add(
info_db,
roots_db,
&serialize(&DAO_CONTRACT_KEY_LATEST_DAO_ROOT),
&serialize(&DAO_CONTRACT_KEY_DAO_MERKLE_TREE),
DAO_CONTRACT_KEY_LATEST_DAO_ROOT,
DAO_CONTRACT_KEY_DAO_MERKLE_TREE,
&dao,
)?;

View File

@@ -134,7 +134,7 @@ pub(crate) fn dao_propose_process_instruction(
// Snapshot the latest Money Mekrle tree
let money_info_db = db_lookup(*MONEY_CONTRACT_ID, MONEY_CONTRACT_INFO_TREE)?;
let Some(data) = db_get(money_info_db, &serialize(&MONEY_CONTRACT_LATEST_COIN_ROOT))? else {
let Some(data) = db_get(money_info_db, MONEY_CONTRACT_LATEST_COIN_ROOT)? else {
msg!("[Dao::Propose] Error: Failed to fetch latest Money Merkle root");
return Err(ContractError::Internal)
};

View File

@@ -66,9 +66,9 @@ pub const DAO_CONTRACT_DB_PROPOSAL_BULLAS: &str = "dao_proposals";
pub const DAO_CONTRACT_DB_VOTE_NULLIFIERS: &str = "dao_vote_nullifiers";
// These are keys inside the info tree
pub const DAO_CONTRACT_KEY_DB_VERSION: &str = "db_version";
pub const DAO_CONTRACT_KEY_DAO_MERKLE_TREE: &str = "dao_merkle_tree";
pub const DAO_CONTRACT_KEY_LATEST_DAO_ROOT: &str = "dao_last_root";
pub const DAO_CONTRACT_KEY_DB_VERSION: &[u8] = b"db_version";
pub const DAO_CONTRACT_KEY_DAO_MERKLE_TREE: &[u8] = b"dao_merkle_tree";
pub const DAO_CONTRACT_KEY_LATEST_DAO_ROOT: &[u8] = b"dao_last_root";
/// zkas dao mint circuit namespace
pub const DAO_CONTRACT_ZKAS_DAO_MINT_NS: &str = "DaoMint";