Skip to content
This repository has been archived by the owner on Oct 22, 2023. It is now read-only.

oasis_invoke: wait until block is indexed #809

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
183 changes: 91 additions & 92 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions api/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub struct ExecutionResult {
pub log_bloom: Bloom,
pub logs: Vec<LogEntry>,
pub status_code: u8,
pub block_number: u64,
#[serde(with = "serde_bytes")]
pub output: Vec<u8>,
}
Expand Down
2 changes: 1 addition & 1 deletion gateway/src/impls/oasis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl Oasis for OasisClient {

Box::new(
self.translator
.send_raw_transaction(raw.into())
.invoke(raw.into())
.map_err(execution_error)
.then(move |maybe_result| {
drop(timer);
Expand Down
27 changes: 27 additions & 0 deletions gateway/src/translator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,33 @@ impl Translator {
txn
}

/// Submit a raw Ethereum transaction to the chain and wait for the block to be indexed.
pub fn invoke(
&self,
raw: Vec<u8>,
) -> impl Future<Item = (H256, ExecutionResult), Error = Error> {
let client = self.client.clone();

future::lazy(move || -> BoxFuture<(H256, ExecutionResult)> {
// TODO: Perform more checks.
let decoded: UnverifiedTransaction = match rlp::decode(&raw) {
Ok(decoded) => decoded,
Err(err) => return Box::new(future::err(err.into())),
};

Box::new(
client
.ethereum_transaction(ByteBuf::from(raw))
.and_then(move |result| {
client
.txn_client()
.wait_block_indexed(result.block_number)
.and_then(move |_| future::ok((decoded.hash(), result)))
}),
)
})
}

/// Submit a raw Ethereum transaction to the chain.
pub fn send_raw_transaction(
&self,
Expand Down
1 change: 0 additions & 1 deletion resources/genesis/genesis_testing.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"instantSeal": null
},
"params": {
"benchmarking": true,
"gasLimitBoundDivisor": "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"registrar" : "0xc6d9d2cd449a754c494264e1809c50e34d64562b",
"accountStartNonce": "0x00",
Expand Down
3 changes: 3 additions & 0 deletions src/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ pub mod execute {
let gas_used = outcome.receipt.gas_used - ectx.env_info.gas_used;
ectx.env_info.gas_used = outcome.receipt.gas_used;

let block_number = ectx.env_info.number;

// Emit the Ekiden transaction hash so that we can query it.
#[cfg(not(feature = "test"))]
{
Expand Down Expand Up @@ -120,6 +122,7 @@ pub mod execute {
TransactionOutcome::StatusCode(code) => code,
_ => unreachable!("we always use EIP-658 semantics"),
},
block_number: block_number,
output: outcome.output.into(),
})
}
Expand Down