Skip to content
Permalink
Browse files
Updated libra version (#167, DFI-578)
* Updated libra version.

* Change dvm-proto rev.

* fix ipc test (there's depends on OS's impl, so speed of shutting down and closing (unlinking) channel can be so much various).

Co-authored-by: Alexander Koz <a@koz.email>
  • Loading branch information
RIg410 and boozook committed Aug 7, 2020
1 parent cd6b176 commit 4dabc195820fe8c3deb572eab17cd497823b9858
Show file tree
Hide file tree
Showing 11 changed files with 268 additions and 433 deletions.

Large diffs are not rendered by default.

@@ -31,7 +31,6 @@ use dvm_cli::init;
use futures::join;
use dvm_info::config::InfoServiceConfig;
use dvm_cli::info_service::create_info_service;
use dvm_net::api::grpc::vm_grpc::vm_access_vector_server::VmAccessVectorServer;

const MODULE_CACHE: usize = 1000;

@@ -118,8 +117,7 @@ async fn main_internal(options: Options) -> Result<()> {
// comp services
.add_service(VmCompilerServer::new(compiler_service.clone()))
.add_service(VmMultipleSourcesCompilerServer::new(compiler_service))
.add_service(VmScriptMetadataServer::new(metadata_service.clone()))
.add_service(VmAccessVectorServer::new(metadata_service))
.add_service(VmScriptMetadataServer::new(metadata_service))
// serve
.serve_ext_with_shutdown(options.address, serv_term_rx.map(|_| ()))
.map(|res| {
@@ -9,16 +9,16 @@ authors = [
edition = "2018"

[dependencies]
move-lang = { git = "https://github.com/dfinance/libra.git", branch = "29.07.2020" }
move-vm-types = { git = "https://github.com/dfinance/libra.git", branch = "29.07.2020" }
move-core-types = { git = "https://github.com/dfinance/libra.git", branch = "29.07.2020" }
libra-state-view = { git = "https://github.com/dfinance/libra.git", branch = "29.07.2020" }
libra-types = { git = "https://github.com/dfinance/libra.git", branch = "29.07.2020" }
lcs = { git = "https://github.com/dfinance/libra.git", package = "libra-canonical-serialization", branch = "09.07.2020" }
compiler = { git = "https://github.com/dfinance/libra.git", branch = "29.07.2020" }
libra-logger = { git = "https://github.com/dfinance/libra.git", branch = "29.07.2020" }
vm = { git = "https://github.com/dfinance/libra.git", branch = "29.07.2020" }
libra-vm = { git = "https://github.com/dfinance/libra.git", branch = "29.07.2020" }
move-vm-runtime = { git = "https://github.com/dfinance/libra.git", branch = "29.07.2020" }
move-vm-natives = { git = "https://github.com/dfinance/libra.git", branch = "29.07.2020" }
bytecode-verifier = { git = "https://github.com/dfinance/libra.git", branch = "29.07.2020" }
move-lang = { git = "https://github.com/dfinance/libra.git", branch = "05.08.2020" }
move-vm-types = { git = "https://github.com/dfinance/libra.git", branch = "05.08.2020" }
move-core-types = { git = "https://github.com/dfinance/libra.git", branch = "05.08.2020" }
libra-state-view = { git = "https://github.com/dfinance/libra.git", branch = "05.08.2020" }
libra-types = { git = "https://github.com/dfinance/libra.git", branch = "05.08.2020" }
lcs = { git = "https://github.com/dfinance/libra.git", package = "libra-canonical-serialization", branch = "05.08.2020" }
compiler = { git = "https://github.com/dfinance/libra.git", branch = "05.08.2020" }
libra-logger = { git = "https://github.com/dfinance/libra.git", branch = "05.08.2020" }
vm = { git = "https://github.com/dfinance/libra.git", branch = "05.08.2020" }
libra-vm = { git = "https://github.com/dfinance/libra.git", branch = "05.08.2020" }
move-vm-runtime = { git = "https://github.com/dfinance/libra.git", branch = "05.08.2020" }
move-vm-natives = { git = "https://github.com/dfinance/libra.git", branch = "05.08.2020" }
bytecode-verifier = { git = "https://github.com/dfinance/libra.git", branch = "05.08.2020" }
@@ -30,7 +30,9 @@ pub mod account {
}

pub mod result {
pub use move_core_types::vm_status::{StatusCode, VMStatus, DiscardedVMStatus, KeptVMStatus};
pub use move_core_types::vm_status::{
StatusCode, VMStatus, DiscardedVMStatus, KeptVMStatus, AbortLocation as AbortLoc,
};
pub use vm::errors::{Location, VMResult, PartialVMResult, PartialVMError, VMError};
}

@@ -19,7 +19,7 @@ log = "0.4.8"

[dependencies.dvm-api]
git = "https://github.com/dfinance/dvm-proto.git"
rev = "bfdcef619a2694c73585be6be5a5665ab23dae92"
rev = "06b76cf8c1830d6381ea4de3267d1bfc88fd0fb0"

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["winbase", "winnt", "accctrl", "aclapi", "securitybaseapi", "minwinbase", "winbase"] }
@@ -253,7 +253,7 @@ mod ipc {
{
let (cl, errs) = client(URI);
cl.join().expect("client should not crash");
assert_eq!(1, errs.load(Ordering::Acquire));
assert!(errs.load(Ordering::Acquire) >= 1);
}
}

@@ -78,3 +78,45 @@ pub fn time_metadata() -> StructTag {
type_params: vec![],
}
}

#[cfg(test)]
mod tests {
use crate::resources::{time_metadata, block_metadata, oracle_metadata};

#[test]
pub fn test_oracle_metadata() {
let vector = oracle_metadata("DFI", "BTC").access_vector();
assert_eq!(
vector,
hex::decode("01b1a724361d17c9866b12e199ecdb17eb5cb16630b647bbc997fe65362920e3bb")
.unwrap()
);

let vector = oracle_metadata("BTC", "ETH").access_vector();
assert_eq!(
vector,
hex::decode("01a7183ec0c4d32fd9a2705e1e6844035c5238598bf45167742e9db3735af96cc1")
.unwrap()
);
}

#[test]
pub fn test_time_metadata() {
let vector = time_metadata().access_vector();
assert_eq!(
vector,
hex::decode("01bb4980dfba817aaa64cb4b3a75ee1e1d8352111dead64c5c4f05fb7b4c85bb3e")
.unwrap()
);
}

#[test]
pub fn test_block_metadata() {
let vector = block_metadata().access_vector();
assert_eq!(
vector,
hex::decode("01ada6f79e8eddfdf986687174de1000df3c5fa45e9965ece812fed33332ec543a")
.unwrap()
);
}
}
@@ -1,15 +1,11 @@
use libra::{prelude::*, vm::*};
use libra::prelude::*;
use lang::bytecode::extract_script_params;
use crate::{tonic, api};
use tonic::{Request, Response, Status};
use api::grpc::vm_grpc::vm_script_metadata_server::VmScriptMetadata;
use api::grpc::vm_grpc::vm_access_vector_server::VmAccessVector;
use api::grpc::vm_grpc::{Signature, VmScript, VmTypeTag};
use info::metrics::meter::ScopeMeter;
use info::metrics::execution::ExecutionResult;
use dvm_net::api::grpc::vm_grpc::{AccessVector, StructIdent, LcsTag, LcsType};
use std::convert::TryFrom;
use anyhow::Error;

/// Metadata service.
/// Provides a function to retrieve metadata for the script.
@@ -61,105 +57,3 @@ impl VmScriptMetadata for MetadataService {
Ok(Response::new(Signature::new(&arg_types)))
}
}

#[tonic::async_trait]
impl VmAccessVector for MetadataService {
async fn get_access_vector(
&self,
request: Request<StructIdent>,
) -> Result<Response<AccessVector>, Status> {
let mut meter = ScopeMeter::new("get_access_vector");
match Ident::try_from(request.into_inner()) {
Ok(ident) => {
meter.set_result(ExecutionResult::new(true, 200, 0));
Ok(Response::new(AccessVector {
access_vector: ident.as_ref().access_vector(),
}))
}
Err(err) => {
meter.set_result(ExecutionResult::new(false, 400, 0));
Err(Status::unimplemented(format!(
"Unsupported struct signature. {}",
err
)))
}
}
}
}

/// StructTag wrapper.
struct Ident(StructTag);

impl AsRef<StructTag> for Ident {
fn as_ref(&self) -> &StructTag {
&self.0
}
}

impl Into<StructTag> for Ident {
fn into(self) -> StructTag {
self.0
}
}

impl TryFrom<StructIdent> for Ident {
type Error = Error;

fn try_from(value: StructIdent) -> Result<Self, Self::Error> {
let type_params = value
.type_params
.into_iter()
.map(|p| TypeIdent::try_from(p).map(|t| t.into()))
.collect::<Result<Vec<TypeTag>, Error>>()?;

Ok(Ident(StructTag {
address: AccountAddress::try_from(value.address)?,
module: Identifier::new(value.module)?,
name: Identifier::new(value.name)?,
type_params,
}))
}
}

/// TypeTag wrapper.
struct TypeIdent(TypeTag);

impl Into<TypeTag> for TypeIdent {
fn into(self) -> TypeTag {
self.0
}
}

impl TryFrom<LcsTag> for TypeIdent {
type Error = Error;

fn try_from(value: LcsTag) -> Result<Self, Self::Error> {
let lcs_type =
LcsType::from_i32(value.type_tag).ok_or_else(|| anyhow!("Invalid type tag."))?;

let tag = match lcs_type {
LcsType::LcsBool => TypeTag::Bool,
LcsType::LcsU64 => TypeTag::U64,
LcsType::LcsVector => {
let vec_type = value
.vector_type
.ok_or_else(|| anyhow!("Vector_Type is required for LcsType::LcsVector."))?;
TypeTag::Vector(Box::new(
TypeIdent::try_from(vec_type.as_ref().clone())?.into(),
))
}
LcsType::LcsAddress => TypeTag::Address,
LcsType::LcsU8 => TypeTag::U8,
LcsType::LcsU128 => TypeTag::U128,
LcsType::LcsSigner => TypeTag::Signer,
LcsType::LcsStruct => {
let struct_ident = value
.struct_ident
.ok_or_else(|| anyhow!("StructIdent is required for LcsType::LcsStruct."))?;
TypeTag::Struct(Ident::try_from(struct_ident)?.into())
}
};

Ok(TypeIdent(tag))
}
}

0 comments on commit 4dabc19

Please sign in to comment.