The constraints on compute power a program can consume is limited only to its instruction count (bp #11717) (#11800)

* The constraints on compute power a program can consume is limited only to its instruction count (#11717)

(cherry picked from commit 8d362f682b)

# Conflicts:
#	programs/bpf/Cargo.toml
#	programs/bpf_loader/Cargo.toml
#	programs/bpf_loader/src/lib.rs
#	programs/bpf_loader/src/syscalls.rs
#	runtime/src/bank.rs
#	sdk/src/instruction.rs

* Resolve conflicts

* nudge

Co-authored-by: Jack May <jack@solana.com>
This commit is contained in:
mergify[bot]
2020-08-24 17:27:40 +00:00
committed by GitHub
parent 79a2ccabb4
commit 0dcbc6d4d1
17 changed files with 355 additions and 137 deletions

View File

@@ -199,6 +199,16 @@ pub trait InvokeContext {
fn get_logger(&self) -> Rc<RefCell<dyn Logger>>;
/// Are cross program invocations supported
fn is_cross_program_supported(&self) -> bool;
/// Get this invocation's compute meter
fn get_compute_meter(&self) -> Rc<RefCell<dyn ComputeMeter>>;
}
/// Compute meter
pub trait ComputeMeter {
/// Consume compute units
fn consume(&mut self, amount: u64) -> Result<(), InstructionError>;
/// Get the number of remaining compute units
fn get_remaining(&self) -> u64;
}
/// Log messages

View File

@@ -159,6 +159,14 @@ pub enum InstructionError {
/// Provided seeds do not result in a valid address
#[error("Provided seeds do not result in a valid address")]
InvalidSeeds,
/// Failed to reallocate account data of this length
#[error("Failed to reallocate account data")]
InvalidRealloc,
/// Computational budget exceeded
#[error("Computational budget exceeded")]
ComputationalBudgetExceeded,
}
impl InstructionError {