Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speculative execution support #2249

Merged
merged 85 commits into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
224ea25
time cursor vm prototype
damip Feb 4, 2022
0bf8bf8
move get_time_until_next_active_slot to a function
damip Feb 4, 2022
f1d3e9b
improve timing system
damip Feb 4, 2022
1aafc85
minor changes
damip Feb 7, 2022
182f794
update ledger
damip Feb 7, 2022
be9de11
time cursor updates
damip Feb 8, 2022
a483aff
Merge branch 'main' into time_curor_vm
damip Feb 15, 2022
47c858d
improve speculative execution prototype
damip Feb 16, 2022
52ac8a8
time cursor vm progress
damip Feb 16, 2022
6b8020b
reorganization and safety
damip Feb 16, 2022
891d914
fmt and error corrections
damip Feb 16, 2022
a36a436
improve code organization and execution primitives
damip Feb 17, 2022
fd66040
SCE ledger access
damip Feb 17, 2022
585e505
add event extraction
damip Feb 18, 2022
380fec4
reorganize code, split crates
damip Feb 18, 2022
2d2fe0e
correct errors
damip Feb 18, 2022
5e422ee
make things compile
damip Feb 18, 2022
d9fb41e
integration
damip Feb 18, 2022
bbe705b
Merge branch 'main' into time_curor_vm
damip Feb 18, 2022
bc45b2d
merge main
damip Feb 18, 2022
26321e3
integrate with consensus
damip Feb 18, 2022
2abd640
serializatin and bootstrap
damip Feb 18, 2022
98a7c2e
implement api read only calls
damip Feb 19, 2022
369aa3e
make API compile
damip Feb 19, 2022
9c63282
make the whole program compile
damip Feb 19, 2022
18294e5
update config
damip Feb 19, 2022
262336f
testing apparatus
damip Feb 20, 2022
09b6244
test progress
damip Feb 20, 2022
ad637b3
repair bootsrap test
damip Feb 20, 2022
c75ba39
repair consensus tests
damip Feb 21, 2022
dd18dab
debug config
damip Feb 21, 2022
619fc3a
repair readonly API and client
damip Feb 21, 2022
57706ae
make the client readonly call work
damip Feb 21, 2022
52cd0ca
fmt and resolver
damip Feb 21, 2022
858caac
improve documentation
damip Feb 21, 2022
b8572af
progress on documentation
damip Feb 21, 2022
11f4968
improve documentation
damip Feb 22, 2022
b410f79
add documentation
damip Feb 22, 2022
d2f5a30
first full documentation
damip Feb 22, 2022
e36fc7e
clippy lints
damip Feb 22, 2022
cb744da
Merge branch 'main' into time_curor_vm
damip Feb 22, 2022
934feee
remove indentations confusing cargo
damip Feb 22, 2022
1dbbe66
minimiz lock time
damip Feb 23, 2022
99c87d1
rename exclusive to shared
damip Feb 23, 2022
aed41c2
added a comment on unsized_fn_params
damip Feb 23, 2022
51e96d0
switch to parking_lot
damip Feb 23, 2022
a130764
make controller clonable
damip Feb 23, 2022
4f5bb8f
update doc
damip Feb 23, 2022
e5c8cb4
Merge branch 'main' into time_curor_vm
damip Feb 23, 2022
a8dba46
clippy in tests
damip Feb 23, 2022
b6c49b6
Update massa-execution-exports/src/types.rs
damip Feb 23, 2022
c80433f
Update massa-execution-worker/src/interface_impl.rs
damip Feb 23, 2022
4b6155e
correct fmt
damip Feb 23, 2022
ad0b961
Merge branch 'time_curor_vm' of https://github.com/massalabs/massa in…
damip Feb 23, 2022
4e0da23
Update massa-execution-worker/src/controller.rs
damip Feb 23, 2022
d979c06
Update massa-execution-worker/src/controller.rs
damip Feb 23, 2022
55446b2
elude contet constructor name
damip Feb 23, 2022
d1cb98d
Update massa-execution-worker/src/controller.rs
damip Feb 23, 2022
776656b
rename get_final_and_active_ledger_entry
damip Feb 23, 2022
ec40b1f
Merge branch 'time_curor_vm' of https://github.com/massalabs/massa in…
damip Feb 23, 2022
424c8c9
Update massa-execution-worker/src/execution.rs
damip Feb 23, 2022
e30e47b
issue refs
damip Feb 23, 2022
5d19be6
Merge branch 'time_curor_vm' of https://github.com/massalabs/massa in…
damip Feb 23, 2022
74bdf53
Update massa-execution-worker/src/interface_impl.rs
damip Feb 23, 2022
4299a31
force access check
damip Feb 23, 2022
a8ce1be
Merge branch 'main' into time_curor_vm
damip Feb 23, 2022
3a68687
link issue
damip Feb 23, 2022
664efb6
Update massa-execution-worker/src/execution.rs
damip Feb 24, 2022
0d7a720
remove rolls
damip Feb 24, 2022
372e58b
Merge branch 'main' into time_curor_vm
damip Feb 24, 2022
b1cae68
copyright update
damip Feb 24, 2022
b66b360
restart loop on readonly execution
damip Feb 24, 2022
b852ae3
improve execution loop
damip Feb 24, 2022
dcc0900
simplify structure
damip Feb 24, 2022
efea7d9
improve execution loop
damip Feb 25, 2022
808a67e
Merge branch 'main' into time_curor_vm
damip Feb 25, 2022
21eb23b
error formulation
damip Feb 25, 2022
34077fa
Merge branch 'main' into time_curor_vm
damip Feb 25, 2022
dcd6e78
typo
damip Feb 25, 2022
711a345
link TODOs to issues
damip Feb 25, 2022
d71d32a
more accurate error type
damip Feb 25, 2022
04b7699
add execution sink
damip Mar 1, 2022
5f4b91b
Merge branch 'main' into time_curor_vm
damip Mar 1, 2022
f89a6eb
update tests
damip Mar 1, 2022
68c6eb2
clippy
damip Mar 1, 2022
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
302 changes: 219 additions & 83 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ members = [
"massa-client",
"massa-consensus-exports",
"massa-consensus-worker",
"massa-execution",
"massa-execution-exports",
"massa-execution-worker",
"massa-graph",
"massa-hash",
"massa-logging",
Expand All @@ -19,6 +20,7 @@ members = [
"massa-signature",
"massa-time",
"massa-wallet",
"massa-ledger"
]
resolver = "2"

Expand Down
4 changes: 2 additions & 2 deletions massa-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ tokio = { version = "1.15", features = ["full"] }
tracing = "0.1"
# custom modules
massa_consensus_exports = { path = "../massa-consensus-exports" }
massa_execution = { path = "../massa-execution" }
massa_execution_exports = { path = "../massa-execution-exports" }
massa_graph = { path = "../massa-graph" }
massa_hash = { path = "../massa-hash" }
massa_models = { path = "../massa-models" }
Expand All @@ -27,4 +27,4 @@ massa_signature = { path = "../massa-signature" }
massa_time = { path = "../massa-time" }

[features]
instrument = ["tokio/tracing", "massa_consensus_exports/instrument", "massa_execution/instrument", "massa_graph/instrument", "massa_models/instrument", "massa_network/instrument", "massa_pool/instrument", "massa_protocol_exports/instrument", "massa_time/instrument"]
instrument = ["tokio/tracing", "massa_consensus_exports/instrument", "massa_graph/instrument", "massa_models/instrument", "massa_network/instrument", "massa_pool/instrument", "massa_protocol_exports/instrument", "massa_time/instrument"]
2 changes: 1 addition & 1 deletion massa-api/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use displaydoc::Display;
use massa_consensus_exports::error::ConsensusError;
use massa_execution::ExecutionError;
use massa_execution_exports::ExecutionError;
use massa_hash::MassaHashError;
use massa_models::ModelsError;
use massa_network::NetworkError;
Expand Down
10 changes: 5 additions & 5 deletions massa-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use jsonrpc_core::{BoxFuture, IoHandler, Value};
use jsonrpc_derive::rpc;
use jsonrpc_http_server::{CloseHandle, ServerBuilder};
use massa_consensus_exports::{ConsensusCommandSender, ConsensusConfig};
use massa_execution::ExecutionCommandSender;
use massa_execution_exports::ExecutionController;
use massa_models::api::{
APISettings, AddressInfo, BlockInfo, BlockSummary, EndorsementInfo, EventFilter, NodeStatus,
OperationInfo, ReadOnlyExecution, TimeInterval,
Expand Down Expand Up @@ -36,7 +36,7 @@ mod public;

pub struct Public {
pub consensus_command_sender: ConsensusCommandSender,
pub execution_command_sender: ExecutionCommandSender,
pub execution_controller: Box<dyn ExecutionController>,
pub pool_command_sender: PoolCommandSender,
pub consensus_config: ConsensusConfig,
pub api_settings: &'static APISettings,
Expand All @@ -50,7 +50,7 @@ pub struct Public {
pub struct Private {
pub consensus_command_sender: ConsensusCommandSender,
pub network_command_sender: NetworkCommandSender,
execution_command_sender: ExecutionCommandSender,
pub execution_controller: Box<dyn ExecutionController>,
pub consensus_config: ConsensusConfig,
pub api_settings: &'static APISettings,
pub stop_node_channel: mpsc::Sender<()>,
Expand Down Expand Up @@ -116,8 +116,8 @@ pub trait Endpoints {
#[rpc(name = "execute_read_only_request")]
fn execute_read_only_request(
&self,
_: ReadOnlyExecution,
) -> BoxFuture<Result<ExecuteReadOnlyResponse, ApiError>>;
_: Vec<ReadOnlyExecution>,
) -> BoxFuture<Result<Vec<ExecuteReadOnlyResponse>, ApiError>>;

/// Remove a vec of addresses used to stake.
/// No confirmation to expect.
Expand Down
23 changes: 6 additions & 17 deletions massa-api/src/private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{Endpoints, Private, RpcServer, StopHandle, API};
use jsonrpc_core::BoxFuture;
use jsonrpc_http_server::tokio::sync::mpsc;
use massa_consensus_exports::{ConsensusCommandSender, ConsensusConfig};
use massa_execution::ExecutionCommandSender;
use massa_execution_exports::ExecutionController;
use massa_models::api::{
APISettings, AddressInfo, BlockInfo, BlockSummary, EndorsementInfo, EventFilter, NodeStatus,
OperationInfo, ReadOnlyExecution, TimeInterval,
Expand All @@ -24,7 +24,7 @@ impl API<Private> {
pub fn new(
consensus_command_sender: ConsensusCommandSender,
network_command_sender: NetworkCommandSender,
execution_command_sender: ExecutionCommandSender,
execution_controller: Box<dyn ExecutionController>,
api_settings: &'static APISettings,
consensus_settings: ConsensusConfig,
) -> (Self, mpsc::Receiver<()>) {
Expand All @@ -33,7 +33,7 @@ impl API<Private> {
API(Private {
consensus_command_sender,
network_command_sender,
execution_command_sender,
execution_controller,
consensus_config: consensus_settings,
api_settings,
stop_node_channel,
Expand Down Expand Up @@ -76,20 +76,9 @@ impl Endpoints for API<Private> {

fn execute_read_only_request(
&self,
ReadOnlyExecution {
max_gas,
simulated_gas_price,
bytecode,
address,
}: ReadOnlyExecution,
) -> BoxFuture<Result<ExecuteReadOnlyResponse, ApiError>> {
let cmd_sender = self.0.execution_command_sender.clone();
let closure = async move || {
Ok(cmd_sender
.execute_read_only_request(max_gas, simulated_gas_price, bytecode, address)
.await?)
};
Box::pin(closure())
_: Vec<ReadOnlyExecution>,
AureliaDolo marked this conversation as resolved.
Show resolved Hide resolved
) -> BoxFuture<Result<Vec<ExecuteReadOnlyResponse>, ApiError>> {
crate::wrong_api::<Vec<ExecuteReadOnlyResponse>>()
}

fn remove_staking_addresses(&self, keys: Vec<Address>) -> BoxFuture<Result<(), ApiError>> {
Expand Down
136 changes: 109 additions & 27 deletions massa-api/src/public.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ use crate::{Endpoints, Public, RpcServer, StopHandle, API};
use futures::{stream::FuturesUnordered, StreamExt};
use jsonrpc_core::BoxFuture;
use massa_consensus_exports::{ConsensusCommandSender, ConsensusConfig};
use massa_execution::ExecutionCommandSender;
use massa_execution_exports::{
ExecutionController, ExecutionStackElement, ReadOnlyExecutionRequest,
};
use massa_graph::{DiscardReason, ExportBlockStatus};
use massa_models::api::SCELedgerInfo;
use massa_models::execution::ReadOnlyResult;
use massa_models::{
api::{
APISettings, AddressInfo, BlockInfo, BlockInfoContent, BlockSummary, EndorsementInfo,
Expand All @@ -23,14 +27,14 @@ use massa_models::{
};
use massa_network::{NetworkCommandSender, NetworkSettings};
use massa_pool::PoolCommandSender;
use massa_signature::PrivateKey;
use massa_signature::{derive_public_key, generate_random_private_key, PrivateKey};
use massa_time::MassaTime;
use std::net::{IpAddr, SocketAddr};

impl API<Public> {
pub fn new(
consensus_command_sender: ConsensusCommandSender,
execution_command_sender: ExecutionCommandSender,
execution_controller: Box<dyn ExecutionController>,
api_settings: &'static APISettings,
consensus_settings: ConsensusConfig,
pool_command_sender: PoolCommandSender,
Expand All @@ -50,7 +54,7 @@ impl API<Public> {
network_command_sender,
compensation_millis,
node_id,
execution_command_sender,
execution_controller,
})
}
}
Expand All @@ -77,9 +81,63 @@ impl Endpoints for API<Public> {

fn execute_read_only_request(
&self,
_: ReadOnlyExecution,
) -> BoxFuture<Result<ExecuteReadOnlyResponse, ApiError>> {
crate::wrong_api::<ExecuteReadOnlyResponse>()
reqs: Vec<ReadOnlyExecution>,
) -> BoxFuture<Result<Vec<ExecuteReadOnlyResponse>, ApiError>> {
if reqs.len() > self.0.api_settings.max_arguments as usize {
let closure =
async move || Err(ApiError::TooManyArguments("too many arguments".into()));
return Box::pin(closure());
}

let mut res: Vec<ExecuteReadOnlyResponse> = Vec::with_capacity(reqs.len());
for ReadOnlyExecution {
max_gas,
address,
simulated_gas_price,
bytecode,
} in reqs
{
let address = address.unwrap_or_else(|| {
// if no addr provided, use a random one
Address::from_public_key(&derive_public_key(&generate_random_private_key()))
});

// TODO:
// * set a maximum gas value for read-only executions to prevent attacks
AureliaDolo marked this conversation as resolved.
Show resolved Hide resolved
// * stop mapping request and result, reuse execution's structures
// * remove async stuff

// translate request
let req = ReadOnlyExecutionRequest {
max_gas,
simulated_gas_price,
bytecode,
call_stack: vec![ExecutionStackElement {
address,
coins: Default::default(),
owned_addresses: vec![address],
}],
};

// run
let result = self.0.execution_controller.execute_readonly_request(req);

// map result
let result = ExecuteReadOnlyResponse {
executed_at: result.as_ref().map_or_else(|_| Slot::new(0, 0), |v| v.slot),
result: result.as_ref().map_or_else(
|err| ReadOnlyResult::Error(format!("readonly call failed: {}", err)),
|_| ReadOnlyResult::Ok,
),
output_events: result.map_or_else(|_| Default::default(), |v| v.events.export()),
};

res.push(result);
}

// return result
let closure = async move || Ok(res);
Box::pin(closure())
}

fn remove_staking_addresses(&self, _: Vec<Address>) -> BoxFuture<Result<(), ApiError>> {
Expand Down Expand Up @@ -356,11 +414,37 @@ impl Endpoints for API<Public> {
let api_cfg = self.0.api_settings;
let pool_command_sender = self.0.pool_command_sender.clone();
let compensation_millis = self.0.compensation_millis;
let sce_command_sender = self.0.execution_command_sender.clone();
let closure = async move || {
if addresses.len() as u64 > api_cfg.max_arguments {
return Err(ApiError::TooManyArguments("too many arguments".into()));

// todo make better use of SCE ledger info
AureliaDolo marked this conversation as resolved.
Show resolved Hide resolved

// map SCE ledger info and check for address length
let sce_ledger_info = if addresses.len() as u64 > api_cfg.max_arguments {
Err(ApiError::TooManyArguments("too many arguments".into()))
} else {
// get SCE ledger info
let mut sce_ledger_info: Map<Address, SCELedgerInfo> =
Map::with_capacity_and_hasher(addresses.len(), BuildMap::default());
for addr in &addresses {
let active_entry = match self
.0
.execution_controller
.get_final_and_active_ledger_entry(addr)
.1
{
None => continue,
Some(v) => SCELedgerInfo {
balance: v.parallel_balance,
module: Some(v.bytecode),
datastore: v.datastore.into_iter().collect(),
},
};
sce_ledger_info.insert(*addr, active_entry);
}
Ok(sce_ledger_info)
};

let closure = async move || {
let sce_ledger_info = sce_ledger_info?;

let mut res = Vec::with_capacity(addresses.len());

Expand All @@ -383,11 +467,10 @@ impl Endpoints for API<Public> {

// roll and balance info
let states = cmd_sender.get_addresses_info(addresses.iter().copied().collect());
let sce_info = sce_command_sender.get_sce_ledger_for_addresses(addresses.clone());

// wait for both simultaneously
let (next_draws, states, sce_info) = tokio::join!(next_draws, states, sce_info);
let (next_draws, mut states, sce_info) = (next_draws?, states?, sce_info?);
let (next_draws, states) = tokio::join!(next_draws, states);
let (next_draws, mut states) = (next_draws?, states?);

// operations block and endorsement info
let mut operations: Map<Address, Set<OperationId>> =
Expand Down Expand Up @@ -469,7 +552,7 @@ impl Endpoints for API<Public> {
.remove(&address)
.ok_or(ApiError::NotFound)?,
production_stats: state.production_stats,
sce_ledger_info: sce_info.get(&address).cloned().unwrap_or_default(),
sce_ledger_info: sce_ledger_info.get(&address).cloned().unwrap_or_default(),
})
}
Ok(res)
Expand Down Expand Up @@ -514,18 +597,17 @@ impl Endpoints for API<Public> {
original_operation_id,
}: EventFilter,
) -> BoxFuture<Result<Vec<SCOutputEvent>, ApiError>> {
let execution_command_sender = self.0.execution_command_sender.clone();
let closure = async move || {
Ok(execution_command_sender
.get_filtered_sc_output_event(
start,
end,
emitter_address,
original_caller_address,
original_operation_id,
)
.await?)
};
// get events
let events = self.0.execution_controller.get_filtered_sc_output_event(
start,
end,
emitter_address,
original_caller_address,
original_operation_id,
);

// TODO get rid of the async part
AureliaDolo marked this conversation as resolved.
Show resolved Hide resolved
let closure = async move || Ok(events);
Box::pin(closure())
}
}
13 changes: 8 additions & 5 deletions massa-bootstrap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ rand = "0.8"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
thiserror = "1.0"
tokio = { version = "1.15", features = ["full"] }
tracing = "0.1"
# custom modules
parking_lot = "0.12"
tokio = { version = "1.11", features = ["full"] }
tracing = "0.1"# custom modules
massa_consensus_exports = { path = "../massa-consensus-exports" }
massa_execution = { path = "../massa-execution" }
massa_ledger = { path = "../massa-ledger" }
# custom modules
massa_graph = { path = "../massa-graph" }
massa_hash = { path = "../massa-hash" }
massa_logging = { path = "../massa-logging" }
Expand All @@ -33,6 +34,8 @@ massa_time = { path = "../massa-time" }
bitvec = { version = "0.22", features = ["serde"] }
pretty_assertions = "1.0"
serial_test = "0.5"
massa_ledger = { path = "../massa-ledger", features=["testing"] }


[features]
instrument = ["tokio/tracing", "massa_consensus_exports/instrument", "massa_execution/instrument", "massa_graph/instrument", "massa_models/instrument", "massa_network/instrument", "massa_proof_of_stake_exports/instrument", "massa_time/instrument"]
instrument = ["tokio/tracing", "massa_consensus_exports/instrument", "massa_graph/instrument", "massa_models/instrument", "massa_network/instrument", "massa_proof_of_stake_exports/instrument", "massa_time/instrument"]
6 changes: 3 additions & 3 deletions massa-bootstrap/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
use crate::messages::BootstrapMessage;
use displaydoc::Display;
use massa_consensus_exports::error::ConsensusError;
use massa_execution::ExecutionError;
use massa_hash::MassaHashError;
use massa_ledger::LedgerError;
use massa_network::NetworkError;
use massa_time::TimeError;
use thiserror::Error;
Expand All @@ -30,8 +30,8 @@ pub enum BootstrapError {
ConsensusError(#[from] ConsensusError),
/// network error: {0}
NetworkError(#[from] NetworkError),
/// execution error: {0}
ExecutionError(#[from] ExecutionError),
/// ledger error: {0}
LedgerError(#[from] LedgerError),
/// join error: {0}
JoinError(#[from] tokio::task::JoinError),
/// missing private key file
Expand Down
Loading