Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion crates/modules-interfaces/src/abi_stub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ pub struct MessageData {

pub chain_id: num_bigint::BigInt,
pub value: num_bigint::BigInt,
pub is_init: bool,
/// Deprecated; the executor derives it from the presence of code and refuses a mismatch
#[serde(default)]
#[calldata(default = Option::default)]
pub is_init: Option<bool>,
/// Transaction timestamp
#[serde(default = "default_transaction_timestamp")]
#[calldata(
Expand Down
2 changes: 1 addition & 1 deletion crates/modules-interfaces/src/nested.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ pub struct NestedRunEnvelope {
/// Host-minted routing data, opaque to both executor lines.
pub routing_payload: Bytes,
pub calldata: Bytes,
/// The caller sets `value` to zero and `is_init` to false.
/// The caller sets `value` to zero and `is_init` to null.
pub message: MessageData,
/// View-call stack with the caller's contract address appended.
pub stack: Vec<genlayer_calldata::Address>,
Expand Down
16 changes: 9 additions & 7 deletions docs/website/src/impl-spec/appendix/manager-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,6 @@ components:
- signer_address
- chain_id
- value
- is_init
properties:
contract_address:
$ref: '#/components/schemas/Address'
Expand All @@ -737,7 +736,9 @@ components:
example: 0
is_init:
type: boolean
description: Whether this is a contract initialization call
nullable: true
deprecated: true
description: Leave out; when sent, must equal whether `code` is present
transaction_timestamp:
type: string
format: date-time
Expand Down Expand Up @@ -790,7 +791,6 @@ components:
- is_sync
- bucket_totals
- host_data
- timestamp
- host
- calldata
- code
Expand Down Expand Up @@ -840,7 +840,9 @@ components:
timestamp:
type: string
format: date-time
description: Execution timestamp
nullable: true
deprecated: true
description: Leave out; when sent, must equal `message.transaction_timestamp`
host:
type: string
description: Address of host connection 0, `unix://<path>` or a TCP `host:port`
Expand All @@ -859,8 +861,8 @@ components:
format: binary
nullable: true
description: |
Contract bytecode for a deployment, or null for a call. From v0.4,
must be null when `is_init` is false
Contract bytecode for a deployment, or null for a call; its presence
is what makes the run a deployment
leader_public_data:
type: string
format: binary
Expand Down Expand Up @@ -1028,7 +1030,7 @@ components:
nullable: true
default: null
description: |
Network of the chainforks schedule whose forks, active at `timestamp`,
Network of the chainforks schedule whose forks, active at `message.transaction_timestamp`,
decide which executor lines and runners are available. Null means the
manager's `default_network`. An unknown network, or none when the manager
has no `default_network`, fails the run with `failed_to_start` before an
Expand Down
4 changes: 2 additions & 2 deletions docs/website/src/impl-spec/appendix/manager-socket.rst
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ the calls entirely when the blobs are empty
"network_hash": bytes } }

Answers which forks ``network`` has active at ``timestamp``, exactly as a
``run`` with that ``network`` and ``timestamp`` resolves them. ``timestamp``
has the format of ``run``'s ``timestamp``. The request needs no run, so it is
``run`` with that ``network`` and ``message.transaction_timestamp`` resolves
them, and in the same format. The request needs no run, so it is
valid on any connection, including one that never sends ``run``. ``network``
is required: ``default_network`` does not apply. Response::

Expand Down
18 changes: 9 additions & 9 deletions docs/website/src/spec/03-vm/01-startup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ Before executing the root :term:`sub-VM`, :term:`GenVM`:
with node-granted VM permissions.
#. Creates a deterministic root VM with the initial message described below.

If code is supplied with the execution request, that code is the runner source
for the deployment execution. Otherwise, the runner source is the contract code
resolved from storage; a deployment without code on an empty address therefore
finds no runner.
An execution request is a deployment exactly when it supplies code, and that
code is the runner source. Otherwise, the runner source is the contract code
resolved from storage. A host-supplied ``is_init`` that contradicts this is a
host error.

.. _gvm-vm-startup-entry-validation:

Expand Down Expand Up @@ -164,11 +164,11 @@ The child is read-only.

- :ref:`gvm_vm_field_state_mode` is the requested storage view (*param*
``state``); a request of :ref:`gvm-def-enum-value-storage-view-default`
keeps the parent's value (the plain copy rule), so by default the callee
observes a view at least as recent as its caller's. Because the child
cannot write, its :ref:`gvm-def-enum-value-storage-view-default` view is
the decided state: it never includes the calling transaction's uncommitted
writes (see :ref:`contract-execution-flow`).
keeps the parent's value, and a parent value of
:ref:`gvm-def-enum-value-storage-view-default` becomes
:ref:`gvm-def-enum-value-storage-view-latest-decided`, so by default the
callee observes a view at least as recent as its caller's and never the
calling transaction's uncommitted writes (see :ref:`contract-execution-flow`).
- :ref:`gvm_vm_field_topmost_runner_id` is the callee's contract runner.
- :ref:`gvm_vm_field_granted_custom` is the caller's entire loaded
custom-runner set (see `Custom-Runner Grants`_). A call the host delegates to
Expand Down
3 changes: 2 additions & 1 deletion docs/website/src/spec/03-vm/05-result.rst
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ with the following keys (in this order):

#. ``backtrace``
#. ``data`` — the contract result value
#. ``data_fees_consumed``
#. ``data_fees_consumed`` — ``U256`` consumed per fee kind; a kind that charges
several buckets reports only its first
#. ``data_fees_remaining`` — map from each fee-bucket name to its remaining
``U256`` balance
#. ``emissions`` — emitted messages and events, in emission order
Expand Down
2 changes: 1 addition & 1 deletion executors/v0.4.x
Submodule v0.4.x updated 380 files
44 changes: 32 additions & 12 deletions implementation/src/manager/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -881,13 +881,24 @@ pub(super) fn decode_datetime_rfc3339(
}
}

fn encode_datetime_rfc3339<W: calldata::Writer>(
dt: &chrono::DateTime<chrono::Utc>,
fn decode_optional_datetime_rfc3339(
val: calldata::Value,
) -> std::result::Result<Option<chrono::DateTime<chrono::Utc>>, calldata::codec::DecodeError> {
match val {
calldata::Value::Null => Ok(None),
val => decode_datetime_rfc3339(val).map(Some),
}
}

fn encode_optional_datetime_rfc3339<W: calldata::Writer>(
dt: &Option<chrono::DateTime<chrono::Utc>>,
enc: &mut calldata::Encoder<W>,
) -> std::result::Result<(), W::Error> {
use chrono::SecondsFormat;
let s = dt.to_rfc3339_opts(SecondsFormat::AutoSi, true);
enc.push_str(&s)
match dt {
Some(dt) => enc.push_str(&dt.to_rfc3339_opts(SecondsFormat::AutoSi, true)),
None => enc.push_null(),
}
}

fn default_extra_args() -> Vec<String> {
Expand Down Expand Up @@ -972,8 +983,14 @@ pub struct Request {
pub max_execution_minutes: u64,
pub bucket_totals: std::collections::BTreeMap<String, num_bigint::BigInt>,
pub host_data: String,
#[calldata(serialize_with = encode_datetime_rfc3339, deserialize_with = decode_datetime_rfc3339)]
pub timestamp: chrono::DateTime<chrono::Utc>,
/// Deprecated; when present, must equal `message.transaction_timestamp`
#[serde(default)]
#[calldata(
default = Option::default,
serialize_with = encode_optional_datetime_rfc3339,
deserialize_with = decode_optional_datetime_rfc3339
)]
pub timestamp: Option<chrono::DateTime<chrono::Utc>>,
pub host: String,
#[serde(default)]
#[calldata(default = default_extra_args)]
Expand Down Expand Up @@ -2151,10 +2168,6 @@ impl Ctx {
envelope: genvm_modules_interfaces::NestedRunEnvelope,
caller_stream: Arc<ManagerHostStreamState>,
) -> anyhow::Result<genvm_modules_interfaces::NestedRunReply> {
anyhow::ensure!(
!envelope.message.is_init,
"nested CallContract message cannot be an init"
);
anyhow::ensure!(
envelope.message.value == num_bigint::BigInt::from(0),
"nested CallContract message value must be zero"
Expand Down Expand Up @@ -2196,7 +2209,7 @@ impl Ctx {
max_execution_minutes: parent_req.max_execution_minutes,
bucket_totals: std::collections::BTreeMap::new(),
host_data: parent_req.host_data.clone(),
timestamp: envelope.message.transaction_timestamp,
timestamp: None,
host: parent_req.host.clone(),
extra_args: Vec::new(),
calldata: envelope.calldata.clone(),
Expand Down Expand Up @@ -2269,6 +2282,11 @@ fn check_top_level_request(req: &Request, has_modules_lock: bool) -> anyhow::Res
.is_none_or(|data| data.is_empty()),
"host_hello_data for manager-owned host index 1 is not allowed"
);
anyhow::ensure!(
req.timestamp
.is_none_or(|t| t == req.message.transaction_timestamp),
"timestamp differs from message.transaction_timestamp"
);
Ok(())
}

Expand Down Expand Up @@ -2462,7 +2480,9 @@ async fn run_genvm_process(
resources: RunResources,
) -> anyhow::Result<std::process::ExitStatus> {
let network = full_ctx.config.network(req.network.as_deref())?.to_owned();
let forks = full_ctx.ver_ctx.active_forks(&network, req.timestamp)?;
let forks = full_ctx
.ver_ctx
.active_forks(&network, req.message.transaction_timestamp)?;
req.network = Some(network);

let is_top_level = resources.is_top_level();
Expand Down
23 changes: 21 additions & 2 deletions implementation/src/manager/run_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn module_request() -> Request {
signer_address: calldata::Address::from([0; 20]),
chain_id: 0.into(),
value: 0.into(),
is_init: false,
is_init: None,
transaction_timestamp: chrono::Utc::now(),
};
serde_json::from_value(serde_json::json!({
Expand All @@ -73,7 +73,6 @@ fn module_request() -> Request {
"is_sync": false,
"bucket_totals": {},
"host_data": "",
"timestamp": message.transaction_timestamp,
"host": "",
"calldata": [],
"initial_time_units_allocation": 0,
Expand Down Expand Up @@ -146,6 +145,26 @@ fn fake_execution_with_host_id(
exec
}

#[test]
fn top_level_timestamp_may_be_absent_or_equal() {
let mut req = module_request();
check_top_level_request(&req, true).unwrap();

req.timestamp = Some(req.message.transaction_timestamp);
check_top_level_request(&req, true).unwrap();
}

#[test]
fn top_level_timestamp_must_match_the_message() {
let mut req = module_request();
req.timestamp = Some(req.message.transaction_timestamp + chrono::Duration::seconds(1));
let err = check_top_level_request(&req, true).unwrap_err();
assert!(
err.to_string().contains("timestamp"),
"unexpected error: {err}"
);
}

#[test]
fn duration_strings_parse_with_units() {
assert_eq!(
Expand Down
Loading