Skip to content

Commit

Permalink
remove vp_token
Browse files Browse the repository at this point in the history
  • Loading branch information
yito88 committed Jul 12, 2023
1 parent 079d5c1 commit e65ffeb
Show file tree
Hide file tree
Showing 12 changed files with 179 additions and 463 deletions.
22 changes: 0 additions & 22 deletions apps/src/lib/config/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,27 +392,13 @@ pub mod genesis_config {

fn load_token(
config: &TokenAccountConfig,
wasm: &HashMap<String, WasmConfig>,
validators: &HashMap<String, Validator>,
established_accounts: &HashMap<String, EstablishedAccount>,
implicit_accounts: &HashMap<String, ImplicitAccount>,
) -> TokenAccount {
let token_vp_name = config.vp.as_ref().unwrap();
let token_vp_config = wasm.get(token_vp_name).unwrap();

TokenAccount {
address: Address::decode(config.address.as_ref().unwrap()).unwrap(),
denom: config.denom,
vp_code_path: token_vp_config.filename.to_owned(),
vp_sha256: token_vp_config
.sha256
.clone()
.unwrap_or_else(|| {
eprintln!("Unknown token VP WASM sha256");
cli::safe_exit(1);
})
.to_sha256_bytes()
.unwrap(),
balances: config
.balances
.as_ref()
Expand Down Expand Up @@ -579,7 +565,6 @@ pub mod genesis_config {
.map(|(_name, cfg)| {
load_token(
cfg,
&wasm,
&validators,
&established_accounts,
&implicit_accounts,
Expand Down Expand Up @@ -814,10 +799,6 @@ pub struct TokenAccount {
pub address: Address,
/// The number of decimal places amounts of this token has
pub denom: Denomination,
/// Validity predicate code WASM
pub vp_code_path: String,
/// Expected SHA-256 hash of the validity predicate wasm
pub vp_sha256: [u8; 32],
/// Accounts' balances of this token
#[derivative(PartialOrd = "ignore", Ord = "ignore")]
pub balances: HashMap<Address, token::Amount>,
Expand Down Expand Up @@ -903,7 +884,6 @@ pub fn genesis(num_validators: u64) -> Genesis {
use crate::wallet;

let vp_implicit_path = "vp_implicit.wasm";
let vp_token_path = "vp_token.wasm";
let vp_user_path = "vp_user.wasm";

// NOTE When the validator's key changes, tendermint must be reset with
Expand Down Expand Up @@ -1081,8 +1061,6 @@ pub fn genesis(num_validators: u64) -> Genesis {
.map(|(address, (_, denom))| TokenAccount {
address,
denom,
vp_code_path: vp_token_path.into(),
vp_sha256: Default::default(),
balances: balances.clone(),
})
.collect();
Expand Down
34 changes: 1 addition & 33 deletions apps/src/lib/node/ledger/shell/init_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,7 @@ where
self.initialize_implicit_accounts(genesis.implicit_accounts);

// Initialize genesis token accounts
self.initialize_token_accounts(
genesis.token_accounts,
&implicit_vp_code_path,
);
self.initialize_token_accounts(genesis.token_accounts);

// Initialize genesis validator accounts
let staking_token = staking_token_address(&self.wl_storage);
Expand Down Expand Up @@ -342,45 +339,16 @@ where
fn initialize_token_accounts(
&mut self,
accounts: Vec<genesis::TokenAccount>,
implicit_vp_code_path: &str,
) {
// Initialize genesis token accounts
for genesis::TokenAccount {
address,
denom,
vp_code_path,
vp_sha256,
balances,
} in accounts
{
// associate a token with its denomination.
write_denom(&mut self.wl_storage, &address, denom).unwrap();
let vp_code_hash =
read_wasm_hash(&self.wl_storage, vp_code_path.clone())
.unwrap()
.ok_or(Error::LoadingWasm(format!(
"Unknown vp code path: {}",
implicit_vp_code_path
)))
.expect("Reading wasms should succeed");

// In dev, we don't check the hash
#[cfg(feature = "dev")]
let _ = vp_sha256;
#[cfg(not(feature = "dev"))]
{
assert_eq!(
vp_code_hash.0.as_slice(),
&vp_sha256,
"Invalid token account's VP sha256 hash for {}",
vp_code_path
);
}

self.wl_storage
.write_bytes(&Key::validity_predicate(&address), vp_code_hash)
.unwrap();

for (owner, amount) in balances {
credit_tokens(&mut self.wl_storage, &address, &owner, amount)
.unwrap();
Expand Down
45 changes: 30 additions & 15 deletions core/src/ledger/storage/write_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ use thiserror::Error;
use crate::ledger;
use crate::ledger::storage::traits::StorageHasher;
use crate::ledger::storage::Storage;
use crate::types::address::{Address, EstablishedAddressGen};
use crate::types::address::{Address, EstablishedAddressGen, InternalAddress};
use crate::types::hash::Hash;
use crate::types::ibc::IbcEvent;
use crate::types::storage;
use crate::types::token::{
is_any_minted_balance_key, is_any_minter_key, is_any_token_balance_key,
};

#[allow(missing_docs)]
#[derive(Error, Debug)]
Expand Down Expand Up @@ -470,21 +473,33 @@ impl WriteLog {

// get changed keys grouped by the address
for key in changed_keys.iter() {
for addr in &key.find_addresses() {
if verifiers_from_tx.contains(addr)
|| initialized_accounts.contains(addr)
{
// We can skip this when the address has been added from the
// Tx above.
// Also skip if it's an address of a newly initialized
// account, because anything can be written into an
// account's storage in the same tx in which it's
// initialized (there is no VP in the state prior to tx
// execution).
continue;
// for token keys, trigger Multitoken VP and the owner's VP
if let Some([_, owner]) = is_any_token_balance_key(key) {
verifiers
.insert(Address::Internal(InternalAddress::Multitoken));
verifiers.insert(owner.clone());
} else if is_any_minted_balance_key(key).is_some()
|| is_any_minter_key(key).is_some()
{
verifiers
.insert(Address::Internal(InternalAddress::Multitoken));
} else {
for addr in &key.find_addresses() {
if verifiers_from_tx.contains(addr)
|| initialized_accounts.contains(addr)
{
// We can skip this when the address has been added from
// the Tx above.
// Also skip if it's an address of a newly initialized
// account, because anything can be written into an
// account's storage in the same tx in which it's
// initialized (there is no VP in the state prior to tx
// execution).
continue;
}
// Add the address as a verifier
verifiers.insert(addr.clone());
}
// Add the address as a verifier
verifiers.insert(addr.clone());
}
}
(verifiers, changed_keys)
Expand Down
12 changes: 0 additions & 12 deletions genesis/dev.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ net_address = "127.0.0.1:26656"
[token.NAM]
address = "atest1v4ehgw36x3prswzxggunzv6pxqmnvdj9xvcyzvpsggeyvs3cg9qnywf589qnwvfsg5erg3fkl09rg5"
denom = 8
vp = "vp_token"
[token.NAM.balances]
# In token balances, we can use:
# 1. An address any account
Expand All @@ -45,7 +44,6 @@ Bertha = "1000000"
[token.BTC]
address = "atest1v4ehgw36xdzryve5gsc52veeg5cnsv2yx5eygvp38qcrvd29xy6rys6p8yc5xvp4xfpy2v694wgwcp"
denom = 8
vp = "vp_token"
[token.BTC.balances]
atest1v4ehgw368ycryv2z8qcnxv3cxgmrgvjpxs6yg333gym5vv2zxepnj334g4rryvj9xucrgve4x3xvr4 = 1000000
atest1v4ehgw36x3qng3jzggu5yvpsxgcngv2xgguy2dpkgvu5x33kx3pr2w2zgep5xwfkxscrxs2pj8075p = 1000000
Expand All @@ -55,7 +53,6 @@ a1qyqzsqqqqqcyvvf5xcu5vd6rg4z5233hg9pn23pjgdryzdjy8pz52wzxxscnvvjxx3rryvzz8y5p6m
[token.ETH]
address = "atest1v4ehgw36xqmr2d3nx3ryvd2xxgmrq33j8qcns33sxezrgv6zxdzrydjrxveygd2yxumrsdpsf9jc2p"
denom = 18
vp = "vp_token"
[token.ETH.balances]
atest1v4ehgw368ycryv2z8qcnxv3cxgmrgvjpxs6yg333gym5vv2zxepnj334g4rryvj9xucrgve4x3xvr4 = 1000000
atest1v4ehgw36x3qng3jzggu5yvpsxgcngv2xgguy2dpkgvu5x33kx3pr2w2zgep5xwfkxscrxs2pj8075p = 1000000
Expand All @@ -65,7 +62,6 @@ a1qyqzsqqqqqcyvvf5xcu5vd6rg4z5233hg9pn23pjgdryzdjy8pz52wzxxscnvvjxx3rryvzz8y5p6m
[token.DOT]
address = "atest1v4ehgw36gg6nvs2zgfpyxsfjgc65yv6pxy6nwwfsxgungdzrggeyzv35gveyxsjyxymyz335hur2jn"
denom = 10
vp = "vp_token"
[token.DOT.balances]
atest1v4ehgw368ycryv2z8qcnxv3cxgmrgvjpxs6yg333gym5vv2zxepnj334g4rryvj9xucrgve4x3xvr4 = 1000000
atest1v4ehgw36x3qng3jzggu5yvpsxgcngv2xgguy2dpkgvu5x33kx3pr2w2zgep5xwfkxscrxs2pj8075p = 1000000
Expand All @@ -75,7 +71,6 @@ a1qyqzsqqqqqcyvvf5xcu5vd6rg4z5233hg9pn23pjgdryzdjy8pz52wzxxscnvvjxx3rryvzz8y5p6m
[token.schnitzel]
address = "atest1v4ehgw36xue5xvf5xvuyzvpjx5un2v3k8qeyvd3cxdqns32p89rrxd6xx9zngvpegccnzs699rdnnt"
denom = 6
vp = "vp_token"
[token.schnitzel.balances]
atest1v4ehgw368ycryv2z8qcnxv3cxgmrgvjpxs6yg333gym5vv2zxepnj334g4rryvj9xucrgve4x3xvr4 = 1000000
atest1v4ehgw36x3qng3jzggu5yvpsxgcngv2xgguy2dpkgvu5x33kx3pr2w2zgep5xwfkxscrxs2pj8075p = 1000000
Expand All @@ -85,7 +80,6 @@ a1qyqzsqqqqqcyvvf5xcu5vd6rg4z5233hg9pn23pjgdryzdjy8pz52wzxxscnvvjxx3rryvzz8y5p6m
[token.apfel]
address = "atest1v4ehgw36gfryydj9g3p5zv3kg9znyd358ycnzsfcggc5gvecgc6ygs2rxv6ry3zpg4zrwdfeumqcz9"
denom = 6
vp = "vp_token"
[token.apfel.balances]
atest1v4ehgw368ycryv2z8qcnxv3cxgmrgvjpxs6yg333gym5vv2zxepnj334g4rryvj9xucrgve4x3xvr4 = 1000000
atest1v4ehgw36x3qng3jzggu5yvpsxgcngv2xgguy2dpkgvu5x33kx3pr2w2zgep5xwfkxscrxs2pj8075p = 1000000
Expand All @@ -96,7 +90,6 @@ a1qyqzsqqqqqcyvvf5xcu5vd6rg4z5233hg9pn23pjgdryzdjy8pz52wzxxscnvvjxx3rryvzz8y5p6m
address = "atest1v4ehgw36gep5ysecxq6nyv3jg3zygv3e89qn2vp48pryxsf4xpznvve5gvmy23fs89pryvf5a6ht90"
denom = 6
public_key = ""
vp = "vp_token"
[token.kartoffel.balances]
atest1v4ehgw368ycryv2z8qcnxv3cxgmrgvjpxs6yg333gym5vv2zxepnj334g4rryvj9xucrgve4x3xvr4 = 1000000
atest1v4ehgw36x3qng3jzggu5yvpsxgcngv2xgguy2dpkgvu5x33kx3pr2w2zgep5xwfkxscrxs2pj8075p = 1000000
Expand Down Expand Up @@ -140,11 +133,6 @@ sha256 = "dc7b97f0448f2369bd2401c3c1d8898f53cac8c464a8c1b1f7f81415a658625d"
# filename (relative to wasm path used by the node)
filename = "vp_validator.wasm"

# Token VP
[wasm.vp_token]
filename = "vp_token.wasm"
sha256 = "e428a11f570d21dd3c871f5d35de6fe18098eb8ee0456b3e11a72ccdd8685cd0"

# General protocol parameters.
[parameters]
# Minimum number of blocks in an epoch.
Expand Down
11 changes: 0 additions & 11 deletions genesis/e2e-tests-single-node.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ net_address = "127.0.0.1:27656"
[token.NAM]
address = "atest1v4ehgw36x3prswzxggunzv6pxqmnvdj9xvcyzvpsggeyvs3cg9qnywf589qnwvfsg5erg3fkl09rg5"
denom = 6
vp = "vp_token"
[token.NAM.balances]
Albert = "1000000"
"Albert.public_key" = "100"
Expand All @@ -45,7 +44,6 @@ faucet = "9223372036854"
[token.BTC]
address = "atest1v4ehgw36xdzryve5gsc52veeg5cnsv2yx5eygvp38qcrvd29xy6rys6p8yc5xvp4xfpy2v694wgwcp"
denom = 8
vp = "vp_token"
[token.BTC.balances]
Albert = "1000000"
Bertha = "1000000"
Expand All @@ -57,7 +55,6 @@ faucet = "9223372036854"
[token.ETH]
address = "atest1v4ehgw36xqmr2d3nx3ryvd2xxgmrq33j8qcns33sxezrgv6zxdzrydjrxveygd2yxumrsdpsf9jc2p"
denom = 18
vp = "vp_token"
[token.ETH.balances]
Albert = "1000000"
Bertha = "1000000"
Expand All @@ -69,7 +66,6 @@ faucet = "9223372036854"
[token.DOT]
address = "atest1v4ehgw36gg6nvs2zgfpyxsfjgc65yv6pxy6nwwfsxgungdzrggeyzv35gveyxsjyxymyz335hur2jn"
denom = 10
vp = "vp_token"
[token.DOT.balances]
Albert = "1000000"
Bertha = "1000000"
Expand All @@ -81,7 +77,6 @@ faucet = "9223372036854"
[token.Schnitzel]
address = "atest1v4ehgw36xue5xvf5xvuyzvpjx5un2v3k8qeyvd3cxdqns32p89rrxd6xx9zngvpegccnzs699rdnnt"
denom = 6
vp = "vp_token"
[token.Schnitzel.balances]
Albert = "1000000"
Bertha = "1000000"
Expand All @@ -93,7 +88,6 @@ faucet = "9223372036854"
[token.Apfel]
address = "atest1v4ehgw36gfryydj9g3p5zv3kg9znyd358ycnzsfcggc5gvecgc6ygs2rxv6ry3zpg4zrwdfeumqcz9"
denom = 6
vp = "vp_token"
[token.Apfel.balances]
Albert = "1000000"
Bertha = "1000000"
Expand All @@ -106,7 +100,6 @@ faucet = "9223372036854"
address = "atest1v4ehgw36gep5ysecxq6nyv3jg3zygv3e89qn2vp48pryxsf4xpznvve5gvmy23fs89pryvf5a6ht90"
public_key = ""
denom = 6
vp = "vp_token"
[token.Kartoffel.balances]
Albert = "1000000"
Bertha = "1000000"
Expand Down Expand Up @@ -151,10 +144,6 @@ filename = "vp_user.wasm"
# filename (relative to wasm path used by the node)
filename = "vp_validator.wasm"

# Token VP
[wasm.vp_token]
filename = "vp_token.wasm"

# Faucet VP
[wasm.vp_testnet_faucet]
filename = "vp_testnet_faucet.wasm"
Expand Down
Loading

0 comments on commit e65ffeb

Please sign in to comment.