Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PoS integration #677

Closed
wants to merge 136 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
136 commits
Select commit Hold shift + click to select a range
3afcc1a
add native_token to genesis config
tzemanovic Oct 11, 2022
858b5e9
add native_token to Shell and cli::Context and use it
tzemanovic Oct 11, 2022
78d9860
add native_token to storage and `StorageRead::get_native_token`
tzemanovic Oct 25, 2022
4416df6
PoS: replace hard-coded staking token address
tzemanovic Oct 25, 2022
4c9e727
gov: replace hard-coded nam with native token
tzemanovic Oct 25, 2022
3880c61
slash_fund: replace hard-coded nam with native_token
tzemanovic Oct 25, 2022
e0c02c3
tests: update for native_token
tzemanovic Oct 25, 2022
f1a6799
[ci] wasm checksums update
github-actions[bot] Oct 25, 2022
922f3b9
use address string encoding for WASM FFI and add native_token to VpEnv
tzemanovic Oct 26, 2022
c37ecf4
replace floating point arithm from token module with rust_decimal
brentstone Aug 30, 2022
4c59b99
[ci] wasm checksums update
github-actions[bot] Oct 26, 2022
072c44f
changelog: #436
tzemanovic Oct 26, 2022
40af102
remove staking reward address from all code
brentstone Oct 25, 2022
a084c96
remove staking reward address from genesis toml files
brentstone Oct 26, 2022
c2f4dcd
[ci] wasm checksums update
github-actions[bot] Oct 26, 2022
77ae81b
client: remove staking rewards address from init-validator result
tzemanovic Oct 26, 2022
df0b168
wallet: remove validator rewards key
tzemanovic Oct 26, 2022
8ed508c
remove staking rewards address from cli strings and docs strings
tzemanovic Oct 26, 2022
cce7f18
changelog: #687
tzemanovic Oct 26, 2022
22d845b
replace floating point arithm from token module with rust_decimal
brentstone Aug 30, 2022
97523f4
[ci] wasm checksums update
github-actions[bot] Oct 26, 2022
d08da6e
changelog: #436
tzemanovic Oct 26, 2022
29eb68f
remove staking reward address from all code
brentstone Oct 25, 2022
020f6bf
remove staking reward address from genesis toml files
brentstone Oct 26, 2022
3eb21f7
client: remove staking rewards address from init-validator result
tzemanovic Oct 26, 2022
b54b5c0
wallet: remove validator rewards key
tzemanovic Oct 26, 2022
9852d28
remove staking rewards address from cli strings and docs strings
tzemanovic Oct 26, 2022
70fa58b
changelog: #687
tzemanovic Oct 26, 2022
da7bffc
introduce validator commission rate and changes
brentstone Sep 21, 2022
3fbc30e
require commission rate input data for new validators
brentstone Sep 23, 2022
4b88573
epoched commission rate and tx for validator to change their rate
brentstone Sep 27, 2022
4ff76d8
commission rate: query + refactor validator change tx
brentstone Sep 28, 2022
77dfff4
add missing commission rate-related instances
brentstone Oct 26, 2022
5b6565e
include and update `rust_decimal`
brentstone Oct 26, 2022
288bf33
bug fix from splitting this PR off of #388
brentstone Oct 26, 2022
3704ef6
cleaning: incl fmt + clippy
brentstone Oct 26, 2022
0e097d8
init validator: add commission rate required args for tests
brentstone Oct 26, 2022
80283b2
fix commission rate validation on validator initialization
brentstone Oct 28, 2022
9d8a0d0
improve docs
brentstone Oct 28, 2022
629e1c5
[ci] wasm checksums update
github-actions[bot] Oct 31, 2022
70702a1
[ci] wasm checksums update
github-actions[bot] Oct 31, 2022
34af207
fix: rename native token in e2e genesis file
Nov 2, 2022
54a5baa
governance: refactor with storage api
Oct 31, 2022
7bfd932
governance: more refactor
Nov 2, 2022
079cffa
governance: more refactor
Nov 2, 2022
cff984c
shared: implement PosReadOnly for Storage
tzemanovic Oct 7, 2022
8adbfa2
RPC: add PoS is_validator and bond_amount queries
tzemanovic Oct 7, 2022
9974c1e
queries: add more PoS queries and use them for gov
tzemanovic Oct 11, 2022
6b8e378
queries/router: rm dbg prints
tzemanovic Nov 2, 2022
8ba2812
queries/shell: refactor to single def
tzemanovic Nov 2, 2022
fa7ef5c
governance: more refactor
Nov 2, 2022
1eb7f1e
chore: rebuild wasm for test
Nov 2, 2022
bea1e36
wasm: update checksums
tzemanovic Nov 2, 2022
62bb69c
Merge branch 'tomas/rpc-sub-vp-pos' (#570)
tzemanovic Nov 2, 2022
e2a77a2
Merge remote-tracking branch 'origin/brent/remove-f64' into pos-integ…
tzemanovic Nov 2, 2022
b16f850
governance: more refactor
Nov 2, 2022
69c0fa7
Merge branch 'brent/remove-staking-address' (#687)
tzemanovic Nov 2, 2022
74ce017
[ci] wasm checksums update
github-actions[bot] Nov 2, 2022
9d13339
test/storage: add a test for reading from arbitrary block heights
tzemanovic Oct 27, 2022
2662024
rocksdb: fix read_subspace_val_with_height
tzemanovic Oct 27, 2022
2827deb
rocksdb: fix delete_subspace_val diff write
tzemanovic Oct 27, 2022
8d26dc5
storage: fix block heights used in read, write and delete
tzemanovic Oct 27, 2022
cb352ae
config: add `shell.storage_read_past_height_limit`, use it for queries
tzemanovic Oct 28, 2022
109ed6e
changelog: add #706
tzemanovic Oct 28, 2022
a4419ea
rocksdb: refactor to use pattern match
tzemanovic Nov 4, 2022
258b910
wasm tx test for changing validator commission rate
brentstone Nov 4, 2022
6610a65
fix error convention
brentstone Nov 4, 2022
563d218
commission change wasm tx test: fix and update validation
brentstone Nov 4, 2022
7d652e3
bug fix: consensus key validation error
brentstone Nov 4, 2022
9b4f2be
fix get of epoched commission rate before pipeline
brentstone Nov 4, 2022
6778fd0
add max change info to query of validator commission rate
brentstone Nov 4, 2022
b900354
fix pos state machine test
brentstone Nov 7, 2022
7b6de40
[ci] wasm checksums update
github-actions[bot] Nov 7, 2022
302a08c
changes in response to review comments
brentstone Nov 8, 2022
dcfd6af
validator VP that checks source and signature for a commission rate c…
brentstone Nov 9, 2022
9068938
add max commission rate info to validation and pos state machine test
brentstone Nov 9, 2022
9b175c4
fix: critical flaw in pos VP that was prematurely returning true
brentstone Nov 9, 2022
fea59bd
add vp validator to wasms
brentstone Nov 9, 2022
feead24
changelog: add #582
tzemanovic Nov 9, 2022
de37901
Merge branch 'tomas/native-token-param' (#582)
tzemanovic Nov 9, 2022
05b97e2
Merge branch 'tomas/storage-read-height-bug' (#706)
tzemanovic Nov 9, 2022
757ba1d
async tx to change validator commission rate
brentstone Nov 9, 2022
42b0bfa
addressing 2nd round of review comments
brentstone Nov 10, 2022
dabbec4
Merge branch 'fraccaman+grarco/refactor-governance-storage-api' (#719)
tzemanovic Nov 10, 2022
476877e
[ci] wasm checksums update
github-actions[bot] Nov 10, 2022
6b92f2c
changelog: add #695
tzemanovic Nov 10, 2022
1ffd8ff
Merge branch 'brent/validator-commission-rates' (#695)
tzemanovic Nov 10, 2022
862d840
clarify+rename 'epoch_storage_key' as 'epoch_duration_storage_key'
brentstone Aug 29, 2022
d953ee6
add max_staking_reward_rate to PosParams
brentstone Aug 29, 2022
a5897bd
add new parameters needed for rewards PD controller to the Parameters…
brentstone Sep 8, 2022
9ad5b56
rename `votes_per_token` to `tm_votes_per_token` since this will only…
brentstone Sep 9, 2022
32588d5
update max inflation rate in params (formerly max_staking_rewards_rate)
brentstone Sep 9, 2022
9bb70f4
add target_staked_ratio to PoS params
brentstone Sep 9, 2022
4b1eb5f
specify read or write intentions for parameters storage keys
brentstone Sep 12, 2022
e3994dc
rename reward_rate -> inflation_rate for pos
brentstone Sep 18, 2022
8ba80cb
documentation updates + unused imports removal
brentstone Sep 20, 2022
f16ec20
remove BasisPoints and change relevant parameters to Decimal type
brentstone Sep 8, 2022
9683b44
add fns to multiply Decimal and integer type, return truncated integer
brentstone Sep 8, 2022
f7ae3ce
more decimal_mult function uses
brentstone Sep 8, 2022
4f89a63
fix correct inner type of ValidationError::TotalVotingPowerTooLarge
brentstone Sep 12, 2022
9d904df
clean comments and toml files of basis points
brentstone Oct 26, 2022
1ba6ee2
update rust_decimal version + fmt
brentstone Oct 26, 2022
265b071
fix initial staked ratio parameter at genesis
brentstone Oct 21, 2022
0d0f394
fix: write all fields in Parameters storage in `init_storage`
brentstone Sep 30, 2022
2fd4ed5
storage change: last inflation rate -> last inflation token amount
brentstone Oct 18, 2022
b5ae9bb
fix arb_amount to max out at max tm voting power (fix wasm test bug)
brentstone Oct 27, 2022
6ed8bce
update toml files with latest parameters and values
brentstone Sep 21, 2022
0a8b491
Update rewards parameters and distribution
brentstone Sep 20, 2022
a079234
updates to accommodate `tm_votes_per_token` relative to namnam
brentstone Oct 28, 2022
9e7088f
fmt and includes
brentstone Oct 28, 2022
6e51bc4
[ci] wasm checksums update
github-actions[bot] Nov 8, 2022
c34c33b
update comments
brentstone Nov 9, 2022
9ca0546
remove `staked_ratio` and `pos_inflation_amount` from `ParametersConfig`
brentstone Nov 9, 2022
52e6f09
remove `min_duration` from `ParametersConfig`
brentstone Nov 10, 2022
c6cc0f5
changelog: add #708
brentstone Nov 11, 2022
4e76c28
[ci] wasm checksums update
github-actions[bot] Nov 11, 2022
7c610ba
refactor out VotingPower(Delta) in pos crate, distinguish total and v…
brentstone Sep 14, 2022
b491647
continue refactoring away VotingPower
brentstone Sep 16, 2022
6936e9b
refactor VotingPower out of PoS VP
brentstone Sep 16, 2022
edcea79
Update wasm tx_(un)bond with VotingPower removal
brentstone Sep 20, 2022
1a8ed03
change `validator_total_deltas` -> `validator_deltas`
brentstone Sep 20, 2022
9e17233
keep voting_power as a possible client query
brentstone Sep 20, 2022
69adeeb
more voting_power removal and accurate variable renaming
brentstone Sep 20, 2022
2d3a6e5
fmt + cleanup after cherrypicking commits from #388
brentstone Oct 30, 2022
b7db0f7
clippy: suppress unused validation vars (may need later)
brentstone Oct 30, 2022
c8bd374
fix `TendermintValidator::power`
brentstone Oct 30, 2022
adc6602
fix client voting power query
brentstone Oct 30, 2022
d07f47e
clean up naming of "validator total deltas" -> "validator deltas"
brentstone Nov 7, 2022
a1bc0eb
fix pos state machine test
brentstone Nov 7, 2022
dcea2da
client: replace voting power with bonded stake in queries, etc
brentstone Nov 9, 2022
661506d
convert to tm voting power in `update_epoch`
brentstone Nov 9, 2022
4c7af18
remove comments to self
brentstone Nov 10, 2022
decb52f
changelog: add #707
brentstone Nov 11, 2022
b7a2b86
[ci] wasm checksums update
github-actions[bot] Nov 11, 2022
d296442
Merge branch 'brent/update-pos-params' (#708)
tzemanovic Nov 14, 2022
e28bd81
Merge branch 'brent/refactor-voting-power' (#707)
tzemanovic Nov 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/src/lib/node/ledger/shell/init_chain.rs
Original file line number Diff line number Diff line change
@@ -222,7 +222,7 @@ where
// Account balance (tokens no staked in PoS)
self.storage
.write(
&token::balance_key(&self.native_token, addr),
&token::balance_key(&self.storage.native_token, addr),
validator
.non_staked_balance
.try_to_vec()
6 changes: 2 additions & 4 deletions apps/src/lib/node/ledger/shell/mod.rs
Original file line number Diff line number Diff line change
@@ -193,8 +193,6 @@ where
/// The id of the current chain
#[allow(dead_code)]
chain_id: ChainId,
/// The address of the native token
native_token: Address,
/// The persistent storage
pub(super) storage: Storage<D, H>,
/// Gas meter for the current block
@@ -245,7 +243,8 @@ where
.expect("Creating directory for Anoma should not fail");
}
// load last state from storage
let mut storage = Storage::open(db_path, chain_id.clone(), db_cache);
let mut storage =
Storage::open(db_path, chain_id.clone(), native_token, db_cache);
storage
.load_last_state()
.map_err(|e| {
@@ -308,7 +307,6 @@ where

Self {
chain_id,
native_token,
storage,
gas_meter: BlockGasMeter::default(),
write_log: WriteLog::default(),
8 changes: 8 additions & 0 deletions shared/src/ledger/native_vp.rs
Original file line number Diff line number Diff line change
@@ -228,6 +228,10 @@ where
fn get_block_epoch(&self) -> Result<Epoch, storage_api::Error> {
self.ctx.get_block_epoch()
}

fn get_native_token(&self) -> Result<Address, storage_api::Error> {
Ok(self.ctx.storage.native_token.clone())
}
}

impl<'view, 'a, DB, H, CA> StorageRead<'view>
@@ -309,6 +313,10 @@ where
fn get_block_epoch(&self) -> Result<Epoch, storage_api::Error> {
self.ctx.get_block_epoch()
}

fn get_native_token(&self) -> Result<Address, storage_api::Error> {
Ok(self.ctx.storage.native_token.clone())
}
}

impl<'view, 'a: 'view, DB, H, CA> VpEnv<'view> for Ctx<'a, DB, H, CA>
13 changes: 13 additions & 0 deletions shared/src/ledger/storage/mod.rs
Original file line number Diff line number Diff line change
@@ -52,6 +52,9 @@ where
pub db: D,
/// The ID of the chain
pub chain_id: ChainId,
/// The address of the native token - this is not stored in DB, but read
/// from genesis
pub native_token: Address,
/// The storage for the current (yet to be committed) block
pub block: BlockStorage<H>,
/// The latest block header
@@ -279,6 +282,7 @@ where
pub fn open(
db_path: impl AsRef<std::path::Path>,
chain_id: ChainId,
native_token: Address,
cache: Option<&D::Cache>,
) -> Self {
let block = BlockStorage {
@@ -302,6 +306,7 @@ where
),
#[cfg(feature = "ferveo-tpke")]
tx_queue: TxQueue::default(),
native_token,
}
}

@@ -789,6 +794,12 @@ where
) -> std::result::Result<Epoch, storage_api::Error> {
Ok(self.block.epoch)
}

fn get_native_token(
&self,
) -> std::result::Result<Address, storage_api::Error> {
Ok(self.native_token.clone())
}
}

impl<D, H> StorageWrite for Storage<D, H>
@@ -879,6 +890,7 @@ pub mod testing {
use super::mockdb::MockDB;
use super::*;
use crate::ledger::storage::traits::Sha256Hasher;
use crate::types::address;
/// Storage with a mock DB for testing
pub type TestStorage = Storage<MockDB, Sha256Hasher>;

@@ -907,6 +919,7 @@ pub mod testing {
),
#[cfg(feature = "ferveo-tpke")]
tx_queue: TxQueue::default(),
native_token: address::nam(),
}
}
}
4 changes: 4 additions & 0 deletions shared/src/ledger/storage_api/mod.rs
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ pub mod validation;
use borsh::{BorshDeserialize, BorshSerialize};
pub use error::{CustomError, Error, OptionExt, Result, ResultExt};

use crate::types::address::Address;
use crate::types::storage::{self, BlockHash, BlockHeight, Epoch};

/// Common storage read interface
@@ -96,6 +97,9 @@ pub trait StorageRead<'iter> {
/// Getting the block epoch. The epoch is that of the block to which the
/// current transaction is being applied.
fn get_block_epoch(&self) -> Result<Epoch>;

/// Get the native token address
fn get_native_token(&self) -> Result<Address>;
}

/// Common storage write interface
14 changes: 14 additions & 0 deletions shared/src/ledger/vp_env.rs
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ use crate::ledger::gas::VpGasMeter;
use crate::ledger::storage::write_log::WriteLog;
use crate::ledger::storage::{self, write_log, Storage, StorageHasher};
use crate::proto::Tx;
use crate::types::address::Address;
use crate::types::hash::Hash;
use crate::types::key::common;
use crate::types::storage::{BlockHash, BlockHeight, Epoch, Key};
@@ -434,6 +435,19 @@ where
Ok(epoch)
}

/// Getting the chain ID.
pub fn get_native_token<DB, H>(
gas_meter: &mut VpGasMeter,
storage: &Storage<DB, H>,
) -> EnvResult<Address>
where
DB: storage::DB + for<'iter> storage::DBIter<'iter>,
H: StorageHasher,
{
add_gas(gas_meter, MIN_STORAGE_GAS)?;
Ok(storage.native_token.clone())
}

/// Storage prefix iterator, ordered by storage keys. It will try to get an
/// iterator from the storage.
pub fn iter_prefix<'a, DB, H>(
47 changes: 46 additions & 1 deletion shared/src/vm/host_env.rs
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ use super::wasm::TxCache;
#[cfg(feature = "wasm-runtime")]
use super::wasm::VpCache;
use super::WasmCacheAccess;
use crate::ledger::gas::{self, BlockGasMeter, VpGasMeter};
use crate::ledger::gas::{self, BlockGasMeter, VpGasMeter, MIN_STORAGE_GAS};
use crate::ledger::storage::write_log::{self, WriteLog};
use crate::ledger::storage::{self, Storage, StorageHasher};
use crate::ledger::vp_env;
@@ -1555,6 +1555,28 @@ where
Ok(epoch.0)
}

/// Get the native token's address
pub fn tx_get_native_token<MEM, DB, H, CA>(
env: &TxVmEnv<MEM, DB, H, CA>,
result_ptr: u64,
) -> TxResult<()>
where
MEM: VmMemory,
DB: storage::DB + for<'iter> storage::DBIter<'iter>,
H: StorageHasher,
CA: WasmCacheAccess,
{
let storage = unsafe { env.ctx.storage.get() };
tx_add_gas(env, MIN_STORAGE_GAS)?;
let native_token = storage.native_token.clone();
let native_token_bytes = native_token.try_to_vec().unwrap();
let gas = env
.memory
.write_bytes(result_ptr, native_token_bytes)
.map_err(|e| TxRuntimeError::MemoryError(Box::new(e)))?;
tx_add_gas(env, gas)
}

/// Getting the chain ID function exposed to the wasm VM VP environment.
pub fn vp_get_chain_id<MEM, DB, H, EVAL, CA>(
env: &VpVmEnv<MEM, DB, H, EVAL, CA>,
@@ -1804,6 +1826,29 @@ where
.to_i64())
}

/// Get the native token's address
pub fn vp_get_native_token<MEM, DB, H, EVAL, CA>(
env: &VpVmEnv<MEM, DB, H, EVAL, CA>,
result_ptr: u64,
) -> vp_env::EnvResult<()>
where
MEM: VmMemory,
DB: storage::DB + for<'iter> storage::DBIter<'iter>,
H: StorageHasher,
EVAL: VpEvaluator,
CA: WasmCacheAccess,
{
let gas_meter = unsafe { env.ctx.gas_meter.get() };
let storage = unsafe { env.ctx.storage.get() };
let native_token = vp_env::get_native_token(gas_meter, storage)?;
let native_token_bytes = native_token.try_to_vec().unwrap();
let gas = env
.memory
.write_bytes(result_ptr, native_token_bytes)
.map_err(|e| vp_env::RuntimeError::MemoryError(Box::new(e)))?;
vp_env::add_gas(gas_meter, gas)
}

/// Log a string from exposed to the wasm VM VP environment. The message will be
/// printed at the [`tracing::Level::INFO`]. This function is for development
/// only.
2 changes: 2 additions & 0 deletions shared/src/vm/wasm/host_env.rs
Original file line number Diff line number Diff line change
@@ -78,6 +78,7 @@ where
"anoma_tx_get_block_time" => Function::new_native_with_env(wasm_store, env.clone(), host_env::tx_get_block_time),
"anoma_tx_get_block_hash" => Function::new_native_with_env(wasm_store, env.clone(), host_env::tx_get_block_hash),
"anoma_tx_get_block_epoch" => Function::new_native_with_env(wasm_store, env.clone(), host_env::tx_get_block_epoch),
"anoma_tx_get_native_token" => Function::new_native_with_env(wasm_store, env.clone(), host_env::tx_get_native_token),
"anoma_tx_log_string" => Function::new_native_with_env(wasm_store, env.clone(), host_env::tx_log_string),
},
}
@@ -118,6 +119,7 @@ where
"anoma_vp_get_block_epoch" => Function::new_native_with_env(wasm_store, env.clone(), host_env::vp_get_block_epoch),
"anoma_vp_verify_tx_signature" => Function::new_native_with_env(wasm_store, env.clone(), host_env::vp_verify_tx_signature),
"anoma_vp_eval" => Function::new_native_with_env(wasm_store, env.clone(), host_env::vp_eval),
"anoma_vp_get_native_token" => Function::new_native_with_env(wasm_store, env.clone(), host_env::vp_get_native_token),
"anoma_vp_log_string" => Function::new_native_with_env(wasm_store, env.clone(), host_env::vp_log_string),
},
}
13 changes: 13 additions & 0 deletions tx_prelude/src/lib.rs
Original file line number Diff line number Diff line change
@@ -168,6 +168,19 @@ impl StorageRead<'_> for Ctx {
Ok(Epoch(unsafe { anoma_tx_get_block_epoch() }))
}

/// Get the native token address
fn get_native_token(&self) -> Result<Address, Error> {
let result = Vec::with_capacity(address::ADDRESS_LEN);
unsafe {
anoma_tx_get_native_token(result.as_ptr() as _);
}
let slice = unsafe {
slice::from_raw_parts(result.as_ptr(), address::ADDRESS_LEN)
};
Ok(Address::try_from_slice(slice)
.expect("Cannot decode native address"))
}

fn iter_prefix(
&self,
prefix: &namada::types::storage::Key,
6 changes: 6 additions & 0 deletions vm_env/src/lib.rs
Original file line number Diff line number Diff line change
@@ -101,6 +101,9 @@ pub mod tx {
// Get the current block epoch
pub fn anoma_tx_get_block_epoch() -> u64;

// Get the native token address
pub fn anoma_tx_get_native_token(result_ptr: u64);

// Requires a node running with "Info" log level
pub fn anoma_tx_log_string(str_ptr: u64, str_len: u64);
}
@@ -181,6 +184,9 @@ pub mod vp {
// Get the current block epoch
pub fn anoma_vp_get_block_epoch() -> u64;

// Get the native token address
pub fn anoma_vp_get_native_token(result_ptr: u64);

// Verify a transaction signature
pub fn anoma_vp_verify_tx_signature(
pk_ptr: u64,
18 changes: 18 additions & 0 deletions vp_prelude/src/lib.rs
Original file line number Diff line number Diff line change
@@ -361,6 +361,10 @@ impl StorageRead<'_> for CtxPreStorageRead<'_> {
fn get_block_epoch(&self) -> Result<Epoch, Error> {
get_block_epoch()
}

fn get_native_token(&self) -> Result<Address, Error> {
get_native_token()
}
}

impl StorageRead<'_> for CtxPostStorageRead<'_> {
@@ -422,6 +426,10 @@ impl StorageRead<'_> for CtxPostStorageRead<'_> {
fn get_block_epoch(&self) -> Result<Epoch, Error> {
get_block_epoch()
}

fn get_native_token(&self) -> Result<Address, Error> {
get_native_token()
}
}

fn iter_prefix_impl(
@@ -474,3 +482,13 @@ fn get_block_hash() -> Result<BlockHash, Error> {
fn get_block_epoch() -> Result<Epoch, Error> {
Ok(Epoch(unsafe { anoma_vp_get_block_epoch() }))
}

fn get_native_token() -> Result<Address, Error> {
let result = Vec::with_capacity(address::ADDRESS_LEN);
unsafe {
anoma_vp_get_native_token(result.as_ptr() as _);
}
let slice =
unsafe { slice::from_raw_parts(result.as_ptr(), address::ADDRESS_LEN) };
Ok(Address::try_from_slice(slice).expect("Cannot decode native address"))
}