Skip to content

Commit

Permalink
Fix for advance with rewards - now it moves the time forward.
Browse files Browse the repository at this point in the history
`era_length` in HostEnv
  • Loading branch information
kubaplas committed Dec 17, 2024
1 parent e77c8d6 commit 6a7d3d4
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 0 deletions.
10 changes: 10 additions & 0 deletions core/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ pub trait HostContext {
/// Advances the block time by the specified time difference and processes auctions.
fn advance_with_auctions(&self, time_diff: u64);

/// Era length in milliseconds.
fn era_length(&self) -> u64;

/// Returns the current block time.
fn block_time(&self) -> u64;

Expand Down Expand Up @@ -371,6 +374,13 @@ impl HostEnv {
pub fn advance_with_rewards(&self, time_diff: u64) {
let backend = self.backend.borrow();
backend.advance_with_auctions(time_diff);
backend.advance_block_time(time_diff);
}

/// Returns the era length in milliseconds.
pub fn era_length(&self) -> u64 {
let backend = self.backend.borrow();
backend.era_length()
}

/// Returns the current block time.
Expand Down
4 changes: 4 additions & 0 deletions odra-casper/livenet-env/src/livenet_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ impl HostContext for LivenetHost {
fn advance_with_auctions(&self, _: u64) {
panic!("advance_with_auctions not supported for LivenetHost")
}

fn era_length(&self) -> u64 {
panic!("era_length not yet implemented for LivenetHost")
}
}

impl LivenetHost {
Expand Down
4 changes: 4 additions & 0 deletions odra-casper/test-vm/src/casper_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ impl HostContext for CasperHost {
fn transfer(&self, to: Address, amount: U512) -> OdraResult<()> {
self.vm.borrow_mut().transfer(to, amount)
}

fn era_length(&self) -> u64 {
self.vm.borrow().era_length()
}
}

impl CasperHost {
Expand Down
5 changes: 5 additions & 0 deletions odra-casper/test-vm/src/vm/casper_vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ impl CasperVm {
let remaining_time = time_diff % time_between_auctions;
}

/// Gets the era length in milliseconds.
pub fn era_length(&self) -> u64 {
self.context.chainspec().core_config.era_duration.millis()
}

/// Gets the current block time.
pub fn block_time(&self) -> u64 {
self.block_time
Expand Down
4 changes: 4 additions & 0 deletions odra-vm/src/odra_vm_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ impl HostContext for OdraVmHost {
.borrow()
.checked_transfer_tokens(&caller, &to, &amount)
}

fn era_length(&self) -> u64 {
1_000u64
}
}

impl OdraVmHost {
Expand Down

0 comments on commit 6a7d3d4

Please sign in to comment.