Trait ckb_vm::snapshot2::DataSource
source · pub trait DataSource<I: Clone + PartialEq> {
// Required method
fn load_data(
&self,
id: &I,
offset: u64,
length: u64,
) -> Option<(Bytes, u64)>;
}
Expand description
DataSource represents data source that can stay stable and possibly
immutable for the entire lifecycle duration of a VM instance. One example
can be the enclosing transaction when using CKB-VM in CKB’s environment,
no matter where and when we run the CKB smart contract, the enclosing
transaction will always be the same down to every last byte. As a result,
we can leverage DataSource for snapshot optimizations: data that is already
locatable in the DataSource will not need to be included in the snapshot
again, all we need is an id to locate it, together with a pair of
offset / length to cut in to the correct slices. Just like CKB’s syscall design,
an extra u64 value is included here to return the remaining full length of data
starting from offset, without considering length
parameter