-
Notifications
You must be signed in to change notification settings - Fork 659
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
feat: expose validator information as host functions #2504
Changes from 3 commits
cf8f564
b19654e
668aca7
7d54e92
cb2b9cb
01bf462
634be5f
26a800d
f1891f2
17aa971
8c899a3
5372d4c
a2a3c73
555cd31
26d542a
d371471
94974db
9c8d0eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "near-vm-logic" | ||
version = "0.8.0" | ||
version = "0.9.0" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please update version of all crates in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see |
||
authors = ["Near Inc <hello@nearprotocol.com>"] | ||
edition = "2018" | ||
license = "Apache-2.0" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -609,6 +609,37 @@ impl<'a> VMLogic<'a> { | |
Ok(self.context.epoch_height) | ||
} | ||
|
||
/// Returns the stake of an account, if the account is currently a validator. Otherwise returns 0. | ||
bowenwang1996 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// | ||
/// # Cost | ||
/// | ||
/// For not nul-terminated account id: | ||
/// `base + read_memory_base + read_memory_byte * num_bytes + utf8_decoding_base + utf8_decoding_byte * num_bytes + memory_write_base + memory_write_size * 16` | ||
/// | ||
/// For nul-terminated account id : | ||
/// `base + (read_memory_base + read_memory_byte) * num_bytes + utf8_decoding_base + utf8_decoding_byte * num_bytes + memory_write_base + memory_write_size * 16` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why? How do we end up in this weird state? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is related to how There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's just reference |
||
pub fn validator_stake( | ||
frol marked this conversation as resolved.
Show resolved
Hide resolved
|
||
&mut self, | ||
account_len: u64, | ||
account_ptr: u64, | ||
stake_ptr: u64, | ||
) -> Result<()> { | ||
self.gas_counter.pay_base(base)?; | ||
let account_id = self.get_utf8_string(account_len, account_ptr)?; | ||
bowenwang1996 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let balance = *self.context.validators.get(&account_id).unwrap_or(&0); | ||
self.memory_set_u128(stake_ptr, balance) | ||
} | ||
|
||
/// Returns the total validator stake of the current epoch. | ||
/// | ||
/// # Cost | ||
/// | ||
/// `base + memory_write_base + memory_write_size * 16` | ||
pub fn validator_total_stake(&mut self, stake_ptr: u64) -> Result<()> { | ||
self.gas_counter.pay_base(base)?; | ||
self.memory_set_u128(stake_ptr, self.context.epoch_total_stake) | ||
} | ||
|
||
/// Returns the number of bytes used by the contract if it was saved to the trie as of the | ||
/// invocation. This includes: | ||
/// * The data written with storage_* functions during current and previous execution; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update after #2574