pub(crate) struct SpeculativeLedger {
final_state: Arc<RwLock<dyn FinalStateController>>,
active_history: Arc<RwLock<ActiveHistory>>,
pub added_changes: LedgerChanges,
max_datastore_key_length: u8,
max_datastore_value_size: u64,
max_bytecode_size: u64,
storage_costs_constants: StorageCostsConstants,
transfers_history: Arc<RwLock<Vec<TransferInfo>>>,
}Expand description
The SpeculativeLedger contains an thread-safe shared reference to the final ledger (read-only),
a list of existing changes that happened o the ledger since its finality,
as well as an extra list of “added” changes.
The SpeculativeLedger makes it possible to transparently manipulate a virtual ledger
that takes into account all those ledger changes and allows adding more
while keeping track of all the newly added changes, and never writing in the final ledger.
Fields§
§final_state: Arc<RwLock<dyn FinalStateController>>Thread-safe shared access to the final state. For reading only.
active_history: Arc<RwLock<ActiveHistory>>History of the outputs of recently executed slots. Slots should be consecutive, newest at the back.
added_changes: LedgerChangeslist of ledger changes that were applied to this SpeculativeLedger since its creation
max_datastore_key_length: u8max datastore key length
max_datastore_value_size: u64Max datastore value size
max_bytecode_size: u64Max bytecode size
storage_costs_constants: StorageCostsConstantsstorage cost constants
transfers_history: Arc<RwLock<Vec<TransferInfo>>>Implementations§
source§impl SpeculativeLedger
impl SpeculativeLedger
sourcepub fn new(
final_state: Arc<RwLock<dyn FinalStateController>>,
active_history: Arc<RwLock<ActiveHistory>>,
max_datastore_key_length: u8,
max_bytecode_size: u64,
max_datastore_value_size: u64,
storage_costs_constants: StorageCostsConstants,
transfers_history: Arc<RwLock<Vec<TransferInfo>>>,
) -> Self
pub fn new( final_state: Arc<RwLock<dyn FinalStateController>>, active_history: Arc<RwLock<ActiveHistory>>, max_datastore_key_length: u8, max_bytecode_size: u64, max_datastore_value_size: u64, storage_costs_constants: StorageCostsConstants, transfers_history: Arc<RwLock<Vec<TransferInfo>>>, ) -> Self
creates a new SpeculativeLedger
§Arguments
final_state: thread-safe shared access to the final state (for reading only)active_history: thread-safe shared access the speculative execution history
sourcepub fn take(&mut self) -> LedgerChanges
pub fn take(&mut self) -> LedgerChanges
Returns the changes caused to the SpeculativeLedger since its creation,
and resets their local value to nothing.
sourcepub fn get_snapshot(&self) -> LedgerChanges
pub fn get_snapshot(&self) -> LedgerChanges
Takes a snapshot (clone) of the changes caused to the SpeculativeLedger since its creation
sourcepub fn reset_to_snapshot(&mut self, snapshot: LedgerChanges)
pub fn reset_to_snapshot(&mut self, snapshot: LedgerChanges)
Resets the SpeculativeLedger to a snapshot (see get_snapshot method)
sourcepub fn get_balance(&self, addr: &Address) -> Option<Amount>
pub fn get_balance(&self, addr: &Address) -> Option<Amount>
sourcepub fn get_bytecode(&self, addr: &Address) -> Option<Bytecode>
pub fn get_bytecode(&self, addr: &Address) -> Option<Bytecode>
sourcepub fn transfer_coins(
&mut self,
from_addr: Option<Address>,
to_addr: Option<Address>,
amount: Amount,
_context: TransferContext,
) -> Result<(), ExecutionError>
pub fn transfer_coins( &mut self, from_addr: Option<Address>, to_addr: Option<Address>, amount: Amount, _context: TransferContext, ) -> Result<(), ExecutionError>
Transfers coins from one address to another. No changes are retained in case of failure. The spending address, if defined, must exist.
§Parameters:
from_addr: optional spending address (use None for pure coin creation)to_addr: optional crediting address (use None for pure coin destruction)amount: amount of coins to transfer
sourcepub fn entry_exists(&self, addr: &Address) -> bool
pub fn entry_exists(&self, addr: &Address) -> bool
sourcepub fn create_new_sc_address(
&mut self,
creator_address: Address,
addr: Address,
bytecode: Bytecode,
) -> Result<(), ExecutionError>
pub fn create_new_sc_address( &mut self, creator_address: Address, addr: Address, bytecode: Bytecode, ) -> Result<(), ExecutionError>
Creates a new smart contract address with initial bytecode.
§Arguments
creator_address: address that asked for this creation. Will pay the storage costs.addr: address to createbytecode: bytecode to set in the new ledger entry
sourcepub fn set_bytecode(
&mut self,
caller_addr: &Address,
addr: &Address,
bytecode: Bytecode,
) -> Result<(), ExecutionError>
pub fn set_bytecode( &mut self, caller_addr: &Address, addr: &Address, bytecode: Bytecode, ) -> Result<(), ExecutionError>
Sets the bytecode associated to an address in the ledger. Fails if the address doesn’t exist.
§Arguments
caller_addr: address of the caller. Will pay the storage costs.addr: target addressbytecode: bytecode to set for that address
sourcepub fn get_keys(
&self,
addr: &Address,
prefix: &[u8],
start_key: Bound<Vec<u8>>,
end_key: Bound<Vec<u8>>,
count: Option<u32>,
) -> Option<BTreeSet<Vec<u8>>>
pub fn get_keys( &self, addr: &Address, prefix: &[u8], start_key: Bound<Vec<u8>>, end_key: Bound<Vec<u8>>, count: Option<u32>, ) -> Option<BTreeSet<Vec<u8>>>
sourcepub fn has_data_entry(&self, addr: &Address, key: &[u8]) -> bool
pub fn has_data_entry(&self, addr: &Address, key: &[u8]) -> bool
sourcefn get_storage_cost_datastore_entry(
&self,
key: &[u8],
value: &[u8],
) -> Result<Amount, ExecutionError>
fn get_storage_cost_datastore_entry( &self, key: &[u8], value: &[u8], ) -> Result<Amount, ExecutionError>
Compute the storage costs of a full datastore entry
sourcefn charge_datastore_entry_change_storage(
&mut self,
caller_addr: &Address,
old_key_value: Option<(&[u8], &[u8])>,
new_key_value: Option<(&[u8], &[u8])>,
) -> Result<(), ExecutionError>
fn charge_datastore_entry_change_storage( &mut self, caller_addr: &Address, old_key_value: Option<(&[u8], &[u8])>, new_key_value: Option<(&[u8], &[u8])>, ) -> Result<(), ExecutionError>
Charge the storage costs of a datastore entry change, if any.
sourcepub fn set_data_entry(
&mut self,
caller_addr: &Address,
addr: &Address,
key: Vec<u8>,
value: Vec<u8>,
) -> Result<(), ExecutionError>
pub fn set_data_entry( &mut self, caller_addr: &Address, addr: &Address, key: Vec<u8>, value: Vec<u8>, ) -> Result<(), ExecutionError>
Sets a data set entry for a given address in the ledger. Fails if the address doesn’t exist. If the datastore entry does not exist, it is created.
§Arguments
caller_addr: address of the caller. Will pay the storage costs.addr: target addresskey: datastore keydata: value to associate to the datastore key
sourcepub fn delete_data_entry(
&mut self,
caller_addr: &Address,
addr: &Address,
key: &[u8],
) -> Result<(), ExecutionError>
pub fn delete_data_entry( &mut self, caller_addr: &Address, addr: &Address, key: &[u8], ) -> Result<(), ExecutionError>
Deletes a datastore entry for a given address. Fails if the entry or address does not exist.
§Arguments
caller_addr: address of the caller. Will pay the storage costs.addr: addresskey: key of the entry to delete in the address’ datastore
Auto Trait Implementations§
impl Freeze for SpeculativeLedger
impl !RefUnwindSafe for SpeculativeLedger
impl Send for SpeculativeLedger
impl Sync for SpeculativeLedger
impl Unpin for SpeculativeLedger
impl !UnwindSafe for SpeculativeLedger
Blanket Implementations§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Conv for T
impl<T> Conv for T
§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
§fn deserialize(
&self,
deserializer: &mut D,
) -> Result<With<T, W>, <D as Fallible>::Error>
fn deserialize( &self, deserializer: &mut D, ) -> Result<With<T, W>, <D as Fallible>::Error>
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moresource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.